-
Notifications
You must be signed in to change notification settings - Fork 5
/
HDict.ts
1019 lines (906 loc) · 21.7 KB
/
HDict.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2020, J2 Innovations. All Rights Reserved
*/
/* eslint @typescript-eslint/no-explicit-any: "off" */
import { EvalContext } from '../filter/EvalContext'
import { HFilter } from '../filter/HFilter'
import { Node } from '../filter/Node'
import { HaysonDict, HaysonVal } from './hayson'
import { HDateTime } from './HDateTime'
import { HGrid } from './HGrid'
import { HList } from './HList'
import { HMarker } from './HMarker'
import { HNamespace, Reflection } from './HNamespace'
import { HRemove } from './HRemove'
import {
AXON_NULL,
HVal,
isHVal,
NOT_SUPPORTED_IN_FILTER_MSG,
OptionalHVal,
valueEquals,
valueIsKind,
ZINC_NULL,
} from './HVal'
import { JsonV3Dict, JsonV3Val } from './jsonv3'
import { Kind } from './Kind'
import { makeValue, dictToDis, LocalizedCallback } from './util'
/**
* An object composed of haystack values.
*/
export interface HValObj {
[prop: string]: OptionalHVal
}
/**
* A haystack value row used for iteration.
*/
export interface HValRow {
name: string
value: OptionalHVal
}
/**
* Inner backing data store for a dict.
*/
export interface DictStore {
/**
* Returns a haystack value from the dict or undefined
* if it can't be found.
*
* @param name The name of the value to find.
* @return The value, null or undefined if it can't be found.
*/
get(name: string): OptionalHVal | undefined
/**
* Set a haystack value.
*
* @param name The name to set.
* @param value The haystack value to set.
*/
set(name: string, value: OptionalHVal): void
/**
* Removes a property from the dict.
*
* @param name The property name.
*/
remove(name: string): void
/**
* Clear all entries from the dict.
*/
clear(): void
/**
* @returns All keys used in the dict.
*/
getKeys(): string[]
/**
* @returns The underlying object being managed by the store.
*/
toObj(): HValObj
}
/**
* Type guard to check whether the store is a dict or not.
*
* @param store The dict store.
* @returns true if the object is a dict store.
*/
function isDictStore(store: unknown): store is DictStore {
return !!(store && typeof (store as any).getKeys === 'function')
}
/**
* Implementation of a store with the backing data being held
* in an object.
*/
export class DictObjStore implements DictStore {
readonly #values: HValObj
public constructor(values: HValObj) {
this.#values = values
}
public get(name: string): OptionalHVal | undefined {
return this.#values[name]
}
public set(name: string, value: OptionalHVal): void {
this.#values[name] = value
}
public remove(name: string): void {
delete this.#values[name]
}
public clear(): void {
// Don't overwrite this object completely just in case it's had an
// observable installed on it.
Object.keys(this.#values).forEach((key: string): void => {
delete this.#values[key]
})
}
public getKeys(): string[] {
return Object.keys(this.#values)
}
public toObj(): HValObj {
return this.#values
}
}
/**
* An iterator for a haystack values.
*/
export class DictValueIterator implements Iterator<HValRow> {
private readonly $values: HValObj
private readonly $keys: string[]
private $index = 0
public constructor(dict: HDict) {
// Make a defensive copy so the iterator doesn't screw up
// if the dict is modified.
this.$values = dict.toObj()
this.$keys = Object.keys(this.$values)
}
public next(): IteratorResult<HValRow> {
if (this.$index >= this.$keys.length) {
return {
done: true,
value: undefined,
}
}
const name = this.$keys[this.$index++]
return {
done: false,
value: {
name,
value: this.$values[name],
},
}
}
}
/**
* A mutable haystack dict that also implements the JavaScript Proxy pattern.
*
* ```typescript
* const dict = new HDict({ foo: HStr.make('alpha') })
*
* // Write 'beta'
* dict.set('foo', HStr.make('beta'))
*
* // Read 'beta'
* console.log(dict.get('foo'))
* ```
*
* A dict is also iterable...
* ```typescript
* // Iterate a dict
* for (let row of dict) {
* console.log(row.name)
* console.log(row.value)
* }
*
* // Use a haystack filter to test for properties...
* console.log(dict.matches('foo == "beta"')) // prints true
* ```
*/
export class HDict implements HVal, Iterable<HValRow> {
/**
* The dict values.
*/
private readonly $store: DictStore;
/**
* Readonly key access.
*/
readonly [prop: string]: unknown | undefined
/**
* Readonly numerical index access.
*/
readonly [prop: number]: { name: string; value: OptionalHVal } | undefined
/**
* Create a dict using a set of object values.
*
* There are multiple ways to create a dict...
*
* ```typescript
* // Create an empty dict
* const dict0 = new HDict()
*
* // Create a dict from a bunch of key haystack value pairs
* const dict1 = new HDict({ foo: HStr.make('foovalue;), boo: HNum.make(123) })
*
* // Same but with Hayson
* const dict2 = new HDict({ foo: 'foovalue', boo: 123 })
*
* // Create a grid from any haystack value...
* const dict3 = new HDict(HStr.make('foovalue')) // Create with one row and one column as 'val'.
* ```
*
* @param values dict values to create a dict with.
* @returns A dict.
*/
public constructor(
values?:
| { [prop: string]: OptionalHVal | HaysonVal }
| OptionalHVal
| DictStore
) {
if (isDictStore(values)) {
this.$store = values
} else {
let vals: HValObj = {}
if (isHVal(values) || values === null) {
if (valueIsKind<HDict>(values, Kind.Dict)) {
vals = values.toObj()
} else if (valueIsKind<HGrid>(values, Kind.Grid)) {
for (let i = 0; i < values.length; ++i) {
vals[`row${i}`] = values.get(i) as OptionalHVal
}
} else {
vals = { val: values }
}
} else if (values) {
const hvalObj = values
for (const prop in hvalObj) {
const obj = hvalObj[prop]
if (
obj !== undefined &&
typeof obj !== 'function' &&
typeof obj !== 'symbol'
) {
vals[prop] = makeValue(obj)
}
}
}
this.$store = new DictObjStore(vals)
}
return this.makeProxy()
}
/**
* Implement proxy to make it easy to get and set internal values.
*/
private makeProxy(): HDict {
const handler = {
get: function (target: HDict, prop: string): any {
const anyTarget = target as any
if (typeof prop === 'string' && anyTarget[prop] === undefined) {
// Handle numeric index access for lodash.
if (!target.has(prop) && /^[0-9]+$/.test(prop)) {
const name = target.keys[Number(prop)]
if (name) {
return {
name,
value: target.get(name),
}
}
}
return target.get(prop)
}
return anyTarget[prop] as any
},
set(target: HDict, prop: string, value: any): boolean {
const anyTarget = target as any
if (typeof prop === 'string' && anyTarget[prop] === undefined) {
target.set(prop, value)
} else {
anyTarget[prop] = value
}
return true
},
}
return new Proxy(this, handler)
}
/**
* Make a dict using a set of object values.
*
* @param values dict values to create a dict with.
* @returns A dict.
*/
public static make<T extends HDict>(
values?:
| { [prop: string]: OptionalHVal | HaysonVal }
| OptionalHVal
| DictStore
): T {
return (
valueIsKind<HDict>(values, Kind.Dict) ? values : new HDict(values)
) as T
}
/**
* Make a dict based upon the specified value store.
*
* @private
* @param store The data store for the dict.
* @returns A dict.
*/
public static makeFromStore(store: DictStore): HDict {
return new HDict(store)
}
/**
* @returns The value's kind.
*/
public getKind(): Kind {
return Kind.Dict
}
/**
* Compares the value's kind.
*
* @param kind The kind to compare against.
* @returns True if the kind matches.
*/
public isKind(kind: Kind): boolean {
return valueIsKind<HDict>(this, kind)
}
/**
* Returns a haystack value from the dict or undefined
* if it can't be found.
*
* ```typescript
* // Gets the value as an HVal so cast to an HStr.
* const str = dict.get('foo') as HStr
*
* if (str) {
* // Do something.
* }
*
* // Method is generic to make it easier on the eye for casting.
* const str1 = dict.get<HStr>('foo')
* ```
*
* @param name The name of the value to find.
* @return The value or undefined if it can't be found.
*/
public get<Value extends OptionalHVal>(name: string): Value | undefined {
return this.$store.get(name) as Value | undefined
}
/**
* Set a haystack value.
*
* ```typescript
* dict.set('foo', HStr.make('New value'))
*
* // Set the value using Hayson
* dict.set('foo', 'New value')
* ```
*
* @param name The name to set.
* @param value The haystack value to set.
* @returns The dict instance.
*/
public set(name: string, value: HVal | HaysonVal | null): this {
this.$store.set(name, makeValue(value))
return this
}
/**
* Update a dict from another dict(s) or Hayson dict(s).
*
* ```typescript
* dict.update(otherDict, anotherDict)
*
* // Update using a Hayson object
* dict.update({ dis: 'A new display string', curVal: 20 })
* ```
*
* @param dicts The dicts to update from.
* @returns The dict instance.
*/
public update(...dicts: (HDict | HaysonDict)[]): this {
for (const dict of dicts) {
const updateDict = makeValue(dict) as HDict
for (const name of updateDict.keys) {
const val = updateDict.get(name)
if (val !== undefined) {
this.set(name, val)
}
}
}
return this
}
/**
* Returns true if the dict has the specified key.
*
* ```typescript
* if (dict.has('foo')) {
* // Do something
* }
* ```
*
* @param name The name of the key.
* @returns True if the value exists in the dict.
*/
public has(name: string): boolean {
return this.get(name) !== undefined
}
/**
* Return true if the dict matches the specified filter or if
* the value exists in the dict at least once.
*
* ```typescript
* if (dict.any('site and geoCity == "London"')) {
* ...
* }
* ```
*
* @param filter The haystack value, haystack filter or AST node.
* @param cx Optional haystack filter evaluation context.
* @returns True if the property value exists in the dict.
* @throws An error for a invalid haystack filter.
*/
public any(
filter: string | Node | OptionalHVal,
cx?: Partial<EvalContext>
): boolean {
if (isHVal(filter) || filter === null) {
for (const key of this.keys) {
const val = this.get(key)
if (valueEquals(val, filter)) {
return true
}
}
return false
} else if (
// Skip the full filter check if we just have a property name.
typeof filter === 'string' &&
/^[a-zA-Z0-9_]+$/g.test(filter)
) {
return !!this.get(filter)
} else {
return new HFilter(filter).eval({
dict: this,
namespace: cx?.namespace,
resolve: cx?.resolve,
})
}
}
/**
* Returns true if the haystack filter matches the value.
*
* This method is the same as `any`.
*
* ```typescript
* if (dict.matches('site and geoCity == "London"')) {
* // Do something
* }
* ```
*
* @param filter The filter to test.
* @param cx Optional haystack filter evaluation context.
* @returns True if the filter matches ok.
*/
public matches(filter: string | Node, cx?: Partial<EvalContext>): boolean {
return this.any(filter, cx)
}
/**
* Removes a property from the dict.
*
* ```typescript
* // Removes the tag named foo.
* dict.remove('foo')
* ```
*
* @param name The property name.
*/
public remove(name: string): void {
this.$store.remove(name)
}
/**
* Clear all entries from the dict.
*
* ```typescript
* // Clear all the entries from the dict.
* dict.clear()
* ```
*/
public clear(): void {
this.$store.clear()
}
/**
* ```typescript
* console.log('Size: ' + dict.length)
* ```
*
* @returns The number of entries in the dict.
*/
public get length(): number {
return this.keys.length
}
/**
* ```typescript
* for (let key of dict.keys) {
* console.log(key)
* }
* ```
*
* @returns All keys used in the dict.
*/
public get keys(): string[] {
return this.$store.getKeys()
}
/**
* ```typescript
* for (let value of dict.values) {
* console.log(value.getKind())
* }
* ```
* @returns All values for the dict.
*/
public get values(): OptionalHVal[] {
return this.keys.map(
(key: string): OptionalHVal => this.$store.get(key) as OptionalHVal
)
}
/**
* ```typescript
* if (dict.isEmpty()) {
* // There are no entries in the dict.
* }
* ```
*
* @returns True when there are no entries in the dict.
*/
public isEmpty(): boolean {
return this.$store.getKeys().length === 0
}
/**
* Returns the underlying object being managed by the store.
*
* ```typescript
* // Gets a JS Object with the keys as strings and the values as HVals.
* const obj = dict.toObj()
* ```
*
* @returns A the underlying object.
*/
public toObj(): HValObj {
return this.$store.toObj()
}
/**
* ```typescript
* // Convert the dict to an HList of haystack strings.
* const hlist = dict.toList<HStr>()
* ```
*
* @returns All the dict's values as a haystack list
*/
public toList<Value extends HVal>(): HList<Value> {
return HList.make(this.values as Value[])
}
/**
* ```typescript
* // Convert the dict to an HGrid with one row.
* const hgrid = dict.toGrid()
* ```
* @returns The dict as a grid.
*/
public toGrid(): HGrid {
return HGrid.make({ rows: [this] })
}
/**
* @returns The value as a dict.
*/
public toDict(): HDict {
return this
}
/**
* @returns A JSON reprentation of the object.
*/
public toJSON(): HaysonDict {
const obj: HaysonDict = {}
for (const key of this.keys) {
obj[key] = this.get(key)?.toJSON() ?? null
}
return obj
}
/**
* @returns A JSON v3 representation of the object.
*/
public toJSONv3(): JsonV3Dict {
const obj: Record<string, JsonV3Val> = {}
for (const key of this.keys) {
obj[key] = this.get(key)?.toJSONv3() ?? null
}
return obj
}
/**
* Encodes to an encoded zinc value that can be used
* in a haystack filter string.
*
* A dict isn't supported in filter so throw an error.
*
* @returns The encoded value that can be used in a haystack filter.
*/
public toFilter(): string {
throw new Error(NOT_SUPPORTED_IN_FILTER_MSG)
}
/**
* Encodes to an encoding zinc value.
*
* @returns The encoded zinc string.
*/
public toZinc(): string {
let zinc = '{'
for (const key of this.keys) {
const value = this.get(key)
if (zinc.length > 1) {
zinc += ' '
}
zinc += valueIsKind<HMarker>(value, Kind.Marker)
? key
: `${key}:${value?.toZinc(/*nested*/ true) ?? ZINC_NULL}`
}
zinc += '}'
return zinc
}
/**
* @returns An Axon encoded string.
*/
public toAxon(): string {
let zinc = '{'
for (const key of this.keys) {
const value = this.get(key)
if (zinc.length > 1) {
zinc += ','
}
zinc += valueIsKind<HMarker>(value, Kind.Marker)
? key
: `${key}:${value?.toAxon() ?? AXON_NULL}`
}
zinc += '}'
return zinc
}
/**
* Value equality check.
*
* @param value The value to test.
* @returns True if the value is the same.
*/
public equals(value: unknown): boolean {
if (!valueIsKind<HDict>(value, Kind.Dict)) {
return false
}
const keys0 = this.$store.getKeys().sort()
const keys1 = value.$store.getKeys().sort()
if (keys0.length !== keys1.length) {
return false
}
for (let i = 0; i < keys0.length; ++i) {
if (keys0[i] !== keys1[i]) {
return false
}
const val0 = this.get(keys0[i])
const val1 = value.get(keys1[i])
if (!valueEquals(val0, val1)) {
return false
}
}
return true
}
/**
* Compares two values.
*
* @param value The value to compare against.
* @returns The sort order as negative, 0, or positive.
*/
public compareTo(value: unknown): number {
if (!valueIsKind<HDict>(value, Kind.Dict)) {
return -1
}
const zinc0 = this.toZinc()
const zinc1 = value.toZinc()
if (zinc0 < zinc1) {
return -1
}
if (zinc0 === zinc1) {
return 0
}
return 1
}
/**
* Iterate over a dict.
*
* This enables a 'for ... of' loop to be used directly on an iterator.
*
* @returns A new iterator for a dict.
*
* ```typescript
* // Iterate a dict
* for (let row of dict) {
* console.log(row.name)
* console.log(row.value)
* }
* ```
*/
public [Symbol.iterator](): Iterator<HValRow> {
return new DictValueIterator(this)
}
/**
* @returns The dict as an array like object.
*/
public asArrayLike(): ArrayLike<HValRow> {
return this as unknown as ArrayLike<HValRow>
}
/**
* @returns A string representation of the value.
*/
public toString(): string {
let str = '{'
for (const key of this.keys) {
const value = this.get(key)
if (str.length > 1) {
str += ', '
}
str += valueIsKind(value, Kind.Marker)
? key
: `${key}: ${String(value)}`
}
str += '}'
return str
}
/**
* Get the display string for the dict or the given tag. If 'name'
* is undefined, then return display text for the entire dict. If 'name'
* is non-null then format the tag value. If 'name' is not defined
* by this dict then return 'def'.
*
* ```typescript
* // Returns the record's dis tag string value...
* myDict.toDis()
*
* // Returns the record's tag value string value for foo...
* myDict.toDis({ name: 'foo' })
*
* // Returns a localized string based on `disKey`...
* myDict.toDis({
* i18n: (pod: string, key: string): string | undefined => pods.get(pod)?.key(key)
* })
* ```
*
* @see {@link dictToDis}
*
* @param options.name Optional tag name.
* @param options.def Optional default value.
* @param options.i18n Optional function to get localized strings.
* @param options.short Optional flag to automatically shorten the display name.
* @returns The display string.
*/
public toDis({
name,
def,
i18n,
short,
}: {
name?: string
def?: string
i18n?: LocalizedCallback
short?: boolean
} = {}): string {
return name
? this.get(name)?.toString() ?? def ?? ''
: dictToDis(this, def, i18n, short)
}
/**
* Dump the value to the local console output.
*
* @param message An optional message to display before the value.
* @returns The value instance.
*/
public inspect(message?: string): this {
if (message) {
console.log(String(message))
}
const obj: { [prop: string]: string } = {}
for (const val of this) {
obj[val.name] = String(val.value)
}
console.table(obj)
return this
}
/**
* @returns Returns a copy of the dict.
*/
public newCopy(): HDict {
const obj: HValObj = {}
for (const key of this.keys) {
const val = this.get(key)
obj[key] = val?.newCopy() ?? null
}
return HDict.make(obj)
}
/**
* Iterates through the dict to ensure we have a valid set of haystack values.
*
* As the dict's internals are directly exposed calling this method will ensure all the
* values held in the dict are valid haystack values.
*/
public validate(): void {
for (const key of this.keys) {
const val = this.get(key)
if (val !== undefined && !isHVal(val)) {
this.set(key, makeValue(val))
}
}
}
/**
* Merge multiple dicts into one.
*
* ```typescript
* // The merged dict has all the tags from dict0, dict1 and dict2.
* const mergedDict = HDict.merge(dict0, dict1, dict2)
* ```
*
* @param dicts The dicts to merge.
* @returns A merged dict.
*/
public static merge(...dicts: HDict[]): HDict {
return (
dicts.reduce((acc: HDict, cur: HDict): HDict => {
for (const key of cur.keys) {
const val = cur.get(key)
if (val !== undefined) {
acc.set(key, val)
}
}
return acc
}, HDict.make({})) ?? HDict.make({})
)
}
/**
* Create a diff (difference) dict that can be used in an update.
*
* This will return a new dict with any changed values and
* removed tags having an `HRemove` value.
*
* @param dict The newly updated dict that will be checked for differences.
* These differences will be incorporated into the returned dict.
* @returns A diff dict.
*/
public diff(dict: HDict): HDict {
const diff = new HDict()
for (const name of HDict.merge(this, dict).keys) {
const dictVal = dict.get(name)
const val = this.get(name)
if (!dictVal) {
diff.set(name, HRemove.make())
} else if (!val || !dictVal.equals(val)) {
diff.set(name, dictVal)
}
}
return diff
}
/**
* If this dict is for a def then return its
* name otherwise return an empty string.
*
* @returns The def name or an empty string.
*/
public get defName(): string {
const val = this.get('def')
return val ? String(val) : ''
}
/**
* Analyze this dict and return its implemented defs.
*
* If a namespace isn't specified then the default environment namespace
* will be used.
*
* @param namespace An optional namespace to perform the reflect from.
* @returns An array of dicts.
*/
public reflect(namespace?: HNamespace): Reflection {
const ns = namespace ?? HNamespace.defaultNamespace
return ns.reflect(this)
}
/**
* Return a reflected array of children prototypes.
*
* If a namespace isn't specified then the default environment namespace
* will be used.
*
* @param namespace An optional namespace to perform the protos call from.
* @returns An array of dicts.
*/