@voxgig/sdkgen 0.25.0 → 0.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/bin/voxgig-sdkgen +6 -6
  2. package/dist/action/action.js +1 -2
  3. package/dist/action/action.js.map +1 -1
  4. package/dist/action/feature.js +4 -2
  5. package/dist/action/feature.js.map +1 -1
  6. package/dist/action/target.js +4 -2
  7. package/dist/action/target.js.map +1 -1
  8. package/dist/cmp/Entity.js +2 -1
  9. package/dist/cmp/Entity.js.map +1 -1
  10. package/dist/cmp/FeatureHook.js +2 -1
  11. package/dist/cmp/FeatureHook.js.map +1 -1
  12. package/dist/cmp/Main.js.map +1 -1
  13. package/dist/cmp/ReadmeEntity.js +2 -1
  14. package/dist/cmp/ReadmeEntity.js.map +1 -1
  15. package/dist/cmp/Test.d.ts +2 -0
  16. package/dist/cmp/Test.js +17 -0
  17. package/dist/cmp/Test.js.map +1 -0
  18. package/dist/sdkgen.d.ts +2 -1
  19. package/dist/sdkgen.js +17 -28
  20. package/dist/sdkgen.js.map +1 -1
  21. package/dist/tsconfig.tsbuildinfo +1 -1
  22. package/dist/types.d.ts +3 -1
  23. package/dist/types.js +4 -0
  24. package/dist/types.js.map +1 -1
  25. package/model/sdkgen.jsonic +8 -8
  26. package/package.json +8 -6
  27. package/project/.sdk/model/feature/log.jsonic +2 -2
  28. package/project/.sdk/model/feature/test.jsonic +7 -2
  29. package/project/.sdk/model/target/js.jsonic +2 -2
  30. package/project/.sdk/model/target/ts.jsonic +2 -2
  31. package/project/.sdk/src/cmp/js/Main_js.ts +3 -3
  32. package/project/.sdk/src/cmp/js/Quick_js.ts +1 -1
  33. package/project/.sdk/src/cmp/ts/Config_ts.ts +53 -6
  34. package/project/.sdk/src/cmp/ts/EntityOperation_ts.ts +3 -21
  35. package/project/.sdk/src/cmp/ts/Entity_ts.ts +3 -5
  36. package/project/.sdk/src/cmp/ts/Main_ts.ts +22 -12
  37. package/project/.sdk/src/cmp/ts/Package_ts.ts +30 -11
  38. package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +341 -2
  39. package/project/.sdk/src/cmp/ts/TestMain_ts.ts +0 -3
  40. package/project/.sdk/src/cmp/ts/Test_ts.ts +21 -3
  41. package/project/.sdk/src/cmp/ts/fragment/Config.fragment.ts +38 -5
  42. package/project/.sdk/src/cmp/ts/fragment/Entity.fragment.ts +50 -38
  43. package/project/.sdk/src/cmp/ts/fragment/Entity.test.fragment.ts +9 -7
  44. package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +47 -31
  45. package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +49 -31
  46. package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +50 -33
  47. package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +50 -31
  48. package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +51 -31
  49. package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +70 -34
  50. package/project/.sdk/src/cmp/ts/tsconfig.json +15 -0
  51. package/project/.sdk/src/cmp/ts/utility_ts.ts +55 -1
  52. package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +158 -104
  53. package/project/.sdk/tm/ts/src/types.ts +164 -34
  54. package/project/.sdk/tm/ts/src/utility/AuthUtility.ts +8 -2
  55. package/project/.sdk/tm/ts/src/utility/BodyUtility.ts +9 -6
  56. package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +17 -31
  57. package/project/.sdk/tm/ts/src/utility/ContextUtility.ts +14 -54
  58. package/project/.sdk/tm/ts/src/utility/DoneUtility.ts +1 -1
  59. package/project/.sdk/tm/ts/src/utility/ErrorUtility.ts +7 -3
  60. package/project/.sdk/tm/ts/src/utility/FeaturehookUtility.ts +8 -5
  61. package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +18 -2
  62. package/project/.sdk/tm/ts/src/utility/FindparamUtility.ts +12 -5
  63. package/project/.sdk/tm/ts/src/utility/FullurlUtility.ts +21 -5
  64. package/project/.sdk/tm/ts/src/utility/InitfeatureUtility.ts +3 -1
  65. package/project/.sdk/tm/ts/src/utility/OperationUtility.ts +23 -0
  66. package/project/.sdk/tm/ts/src/utility/OptionsUtility.ts +25 -3
  67. package/project/.sdk/tm/ts/src/utility/ParamsUtility.ts +10 -10
  68. package/project/.sdk/tm/ts/src/utility/PreparePathUtility.ts +18 -0
  69. package/project/.sdk/tm/ts/src/utility/QueryUtility.ts +2 -2
  70. package/project/.sdk/tm/ts/src/utility/ReqformUtility.ts +2 -2
  71. package/project/.sdk/tm/ts/src/utility/RequestUtility.ts +20 -3
  72. package/project/.sdk/tm/ts/src/utility/ResbasicUtility.ts +1 -1
  73. package/project/.sdk/tm/ts/src/utility/ResbodyUtility.ts +5 -3
  74. package/project/.sdk/tm/ts/src/utility/ResformUtility.ts +3 -3
  75. package/project/.sdk/tm/ts/src/utility/ResheadersUtility.ts +9 -7
  76. package/project/.sdk/tm/ts/src/utility/ResponseUtility.ts +35 -4
  77. package/project/.sdk/tm/ts/src/utility/ResultUtility.ts +24 -4
  78. package/project/.sdk/tm/ts/src/utility/SelectionUtility.ts +78 -0
  79. package/project/.sdk/tm/ts/src/utility/SpecUtility.ts +34 -27
  80. package/project/.sdk/tm/ts/src/utility/StructUtility.ts +1113 -525
  81. package/project/.sdk/tm/ts/src/utility/Utility.ts +10 -8
  82. package/project/.sdk/tm/ts/test/exists.test.ts +0 -1
  83. package/project/.sdk/tm/ts/test/runner.ts +12 -10
  84. package/project/.sdk/tm/ts/test/utility/Custom.test.ts +30 -29
  85. package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +53 -47
  86. package/project/.sdk/tm/ts/test/utility/StructUtility.test.ts +433 -189
  87. package/src/action/action.ts +1 -2
  88. package/src/action/feature.ts +7 -2
  89. package/src/action/target.ts +7 -7
  90. package/src/cmp/Entity.ts +7 -1
  91. package/src/cmp/FeatureHook.ts +6 -1
  92. package/src/cmp/Main.ts +4 -0
  93. package/src/cmp/ReadmeEntity.ts +6 -1
  94. package/src/cmp/Test.ts +31 -0
  95. package/src/sdkgen.ts +19 -34
  96. package/src/types.ts +10 -1
  97. package/project/.sdk/src/cmp/ts/EntityTest_ts.ts +0 -180
  98. package/project/.sdk/tm/ts/src/utility/OperatorUtility.ts +0 -90
@@ -1,9 +1,9 @@
1
- // VERSION: @voxgig/struct 0.0.4
1
+ // VERSION: @voxgig/struct 0.0.10
2
2
  // RUN: npm test
3
3
  // RUN-SOME: npm run test-some --pattern=getpath
4
4
 
5
- import { test, describe } from 'node:test'
6
- import { equal, deepEqual } from 'node:assert'
5
+ import { test, describe, before } from 'node:test'
6
+ import assert from 'node:assert'
7
7
 
8
8
  import {
9
9
  makeRunner,
@@ -18,107 +18,79 @@ import {
18
18
  } from './index'
19
19
 
20
20
 
21
+ const { equal, deepEqual } = assert
22
+
23
+
21
24
  // NOTE: tests are (mostly) in order of increasing dependence.
22
25
  describe('struct', async () => {
23
26
 
24
- const runner = await makeRunner(TEST_JSON_FILE, await SDK.test())
25
-
26
- const { spec, runset, runsetflags, client } = await runner('struct')
27
-
28
- const {
29
- clone,
30
- delprop,
31
- escre,
32
- escurl,
33
- getelem,
34
- getpath,
35
-
36
- getprop,
37
- haskey,
38
- inject,
39
- isempty,
40
- isfunc,
41
-
42
- iskey,
43
- islist,
44
- ismap,
45
- isnode,
46
- items,
47
-
48
- joinurl,
49
- jsonify,
50
- keysof,
51
- merge,
52
- pad,
53
- pathify,
54
-
55
- select,
56
- size,
57
- slice,
58
- setprop,
59
-
60
- strkey,
61
- stringify,
62
- transform,
63
- typify,
64
- validate,
65
-
66
- walk,
67
-
68
- jo,
69
- ja,
70
-
71
- } = client.utility().struct
72
-
73
- const minorSpec = spec.minor
74
- const walkSpec = spec.walk
75
- const mergeSpec = spec.merge
76
- const getpathSpec = spec.getpath
77
- const injectSpec = spec.inject
78
- const transformSpec = spec.transform
79
- const validateSpec = spec.validate
80
- const selectSpec = spec.select
27
+ let spec: any
28
+ let runset: any
29
+ let runsetflags: any
30
+ let client: any
31
+ let struct: any
32
+
33
+ before(async () => {
34
+ const runner = await makeRunner(TEST_JSON_FILE, await SDK.test())
35
+ const runner_struct = await runner('struct')
36
+
37
+ spec = runner_struct.spec
38
+
39
+ runset = runner_struct.runset
40
+ runsetflags = runner_struct.runsetflags
41
+ client = runner_struct.client
42
+
43
+ struct = client.utility().struct
44
+ })
45
+
81
46
 
82
47
 
83
48
  test('exists', () => {
84
- equal('function', typeof clone)
85
- equal('function', typeof delprop)
86
- equal('function', typeof escre)
87
- equal('function', typeof escurl)
88
- equal('function', typeof getelem)
89
- equal('function', typeof getprop)
90
-
91
- equal('function', typeof getpath)
92
- equal('function', typeof haskey)
93
- equal('function', typeof inject)
94
- equal('function', typeof isempty)
95
- equal('function', typeof isfunc)
96
-
97
- equal('function', typeof iskey)
98
- equal('function', typeof islist)
99
- equal('function', typeof ismap)
100
- equal('function', typeof isnode)
101
- equal('function', typeof items)
102
-
103
- equal('function', typeof joinurl)
104
- equal('function', typeof jsonify)
105
- equal('function', typeof keysof)
106
- equal('function', typeof merge)
107
- equal('function', typeof pad)
108
- equal('function', typeof pathify)
109
-
110
- equal('function', typeof select)
111
- equal('function', typeof size)
112
- equal('function', typeof slice)
113
- equal('function', typeof setprop)
114
-
115
- equal('function', typeof strkey)
116
- equal('function', typeof stringify)
117
- equal('function', typeof transform)
118
- equal('function', typeof typify)
119
- equal('function', typeof validate)
120
-
121
- equal('function', typeof walk)
49
+ const s = struct
50
+
51
+ equal('function', typeof s.clone)
52
+ equal('function', typeof s.delprop)
53
+ equal('function', typeof s.escre)
54
+ equal('function', typeof s.escurl)
55
+ equal('function', typeof s.filter)
56
+
57
+ equal('function', typeof s.flatten)
58
+ equal('function', typeof s.getelem)
59
+ equal('function', typeof s.getprop)
60
+
61
+ equal('function', typeof s.getpath)
62
+ equal('function', typeof s.haskey)
63
+ equal('function', typeof s.inject)
64
+ equal('function', typeof s.isempty)
65
+ equal('function', typeof s.isfunc)
66
+
67
+ equal('function', typeof s.iskey)
68
+ equal('function', typeof s.islist)
69
+ equal('function', typeof s.ismap)
70
+ equal('function', typeof s.isnode)
71
+ equal('function', typeof s.items)
72
+
73
+ equal('function', typeof s.join)
74
+ equal('function', typeof s.jsonify)
75
+ equal('function', typeof s.keysof)
76
+ equal('function', typeof s.merge)
77
+ equal('function', typeof s.pad)
78
+ equal('function', typeof s.pathify)
79
+
80
+ equal('function', typeof s.select)
81
+ equal('function', typeof s.setpath)
82
+ equal('function', typeof s.size)
83
+ equal('function', typeof s.slice)
84
+ equal('function', typeof s.setprop)
85
+
86
+ equal('function', typeof s.strkey)
87
+ equal('function', typeof s.stringify)
88
+ equal('function', typeof s.transform)
89
+ equal('function', typeof s.typify)
90
+ equal('function', typeof s.typename)
91
+
92
+ equal('function', typeof s.validate)
93
+ equal('function', typeof s.walk)
122
94
  })
123
95
 
124
96
 
@@ -126,37 +98,38 @@ describe('struct', async () => {
126
98
  // ===========
127
99
 
128
100
  test('minor-isnode', async () => {
129
- await runset(minorSpec.isnode, isnode)
101
+ await runset(spec.minor.isnode, struct.isnode)
130
102
  })
131
103
 
132
104
 
133
105
  test('minor-ismap', async () => {
134
- await runset(minorSpec.ismap, ismap)
106
+ await runset(spec.minor.ismap, struct.ismap)
135
107
  })
136
108
 
137
109
 
138
110
  test('minor-islist', async () => {
139
- await runset(minorSpec.islist, islist)
111
+ await runset(spec.minor.islist, struct.islist)
140
112
  })
141
113
 
142
114
 
143
115
  test('minor-iskey', async () => {
144
- await runsetflags(minorSpec.iskey, { null: false }, iskey)
116
+ await runsetflags(spec.minor.iskey, { null: false }, struct.iskey)
145
117
  })
146
118
 
147
119
 
148
120
  test('minor-strkey', async () => {
149
- await runsetflags(minorSpec.strkey, { null: false }, strkey)
121
+ await runsetflags(spec.minor.strkey, { null: false }, struct.strkey)
150
122
  })
151
123
 
152
124
 
153
125
  test('minor-isempty', async () => {
154
- await runsetflags(minorSpec.isempty, { null: false }, isempty)
126
+ await runsetflags(spec.minor.isempty, { null: false }, struct.isempty)
155
127
  })
156
128
 
157
129
 
158
130
  test('minor-isfunc', async () => {
159
- await runset(minorSpec.isfunc, isfunc)
131
+ const { isfunc } = struct
132
+ await runset(spec.minor.isfunc, isfunc)
160
133
  function f0() { return null }
161
134
  equal(isfunc(f0), true)
162
135
  equal(isfunc(() => null), true)
@@ -164,39 +137,90 @@ describe('struct', async () => {
164
137
 
165
138
 
166
139
  test('minor-clone', async () => {
167
- await runsetflags(minorSpec.clone, { null: false }, clone)
140
+ await runsetflags(spec.minor.clone, { null: false }, struct.clone)
141
+ })
142
+
143
+
144
+ test('minor-edge-clone', async () => {
145
+ const { clone } = struct
146
+
168
147
  const f0 = () => null
169
148
  deepEqual({ a: f0 }, clone({ a: f0 }))
149
+
150
+ const x = { y: 1 }
151
+ let xc = clone(x)
152
+ deepEqual(x, xc)
153
+ assert(x !== xc)
154
+
155
+ class A { x = 1 }
156
+ const a = new A()
157
+ let ac = clone(a)
158
+ deepEqual(a, ac)
159
+ assert(a === ac)
160
+ equal(a.constructor.name, ac.constructor.name)
161
+ })
162
+
163
+
164
+ test('minor-filter', async () => {
165
+ const checkmap: any = {
166
+ gt3: (n: any) => n[1] > 3,
167
+ lt3: (n: any) => n[1] < 3,
168
+ }
169
+ await runset(spec.minor.filter, (vin: any) => struct.filter(vin.val, checkmap[vin.check]))
170
+ })
171
+
172
+
173
+ test('minor-flatten', async () => {
174
+ await runset(spec.minor.flatten, (vin: any) => struct.flatten(vin.val, vin.depth))
170
175
  })
171
176
 
172
177
 
173
178
  test('minor-escre', async () => {
174
- await runset(minorSpec.escre, escre)
179
+ await runset(spec.minor.escre, struct.escre)
175
180
  })
176
181
 
177
182
 
178
183
  test('minor-escurl', async () => {
179
- await runset(minorSpec.escurl, escurl)
184
+ await runset(spec.minor.escurl, struct.escurl)
180
185
  })
181
186
 
182
187
 
183
188
  test('minor-stringify', async () => {
184
- await runset(minorSpec.stringify, (vin: any) =>
185
- stringify((NULLMARK === vin.val ? "null" : vin.val), vin.max))
189
+ await runset(spec.minor.stringify, (vin: any) =>
190
+ struct.stringify((NULLMARK === vin.val ? "null" : vin.val), vin.max))
191
+ })
192
+
193
+
194
+ test('minor-edge-stringify', async () => {
195
+ const { stringify } = struct
196
+ const a: any = {}
197
+ a.a = a
198
+ equal(stringify(a), '__STRINGIFY_FAILED__')
199
+
200
+ equal(stringify({ a: [9] }, -1, true),
201
+ '\x1B[38;5;81m\x1B[38;5;118m{\x1B[38;5;118ma\x1B[38;5;118m:' +
202
+ '\x1B[38;5;213m[\x1B[38;5;213m9\x1B[38;5;213m]\x1B[38;5;118m}\x1B[0m')
186
203
  })
187
204
 
188
205
 
189
206
  test('minor-jsonify', async () => {
190
- await runsetflags(minorSpec.jsonify, { null: false }, jsonify)
207
+ await runsetflags(spec.minor.jsonify, { null: false },
208
+ (vin: any) => struct.jsonify(vin.val, vin.flags))
209
+ })
210
+
211
+
212
+ test('minor-edge-jsonify', async () => {
213
+ const { jsonify } = struct
214
+ equal(jsonify(() => 1), 'null')
191
215
  })
192
216
 
193
217
 
194
218
  test('minor-pathify', async () => {
195
219
  await runsetflags(
196
- minorSpec.pathify, { null: true },
220
+ spec.minor.pathify, { null: true },
197
221
  (vin: any) => {
198
222
  let path = NULLMARK == vin.path ? undefined : vin.path
199
- let pathstr = pathify(path, vin.from).replace('__NULL__.', '')
223
+ let pathstr = struct.pathify(path, vin.from).replace('__NULL__.', '')
200
224
  pathstr = NULLMARK === vin.path ? pathstr.replace('>', ':null>') : pathstr
201
225
  return pathstr
202
226
  })
@@ -204,23 +228,41 @@ describe('struct', async () => {
204
228
 
205
229
 
206
230
  test('minor-items', async () => {
207
- await runset(minorSpec.items, items)
231
+ await runset(spec.minor.items, struct.items)
232
+ })
233
+
234
+
235
+ test('minor-edge-items', async () => {
236
+ const { items } = struct
237
+ const a0: any = [11, 22, 33]
238
+ a0.x = 1
239
+ deepEqual(items(a0), [['0', 11], ['1', 22], ['2', 33]])
208
240
  })
209
241
 
210
242
 
211
243
  test('minor-getelem', async () => {
212
- await runsetflags(minorSpec.getelem, { null: false }, (vin: any) =>
244
+ const { getelem } = struct
245
+ await runsetflags(spec.minor.getelem, { null: false }, (vin: any) =>
213
246
  null == vin.alt ? getelem(vin.val, vin.key) : getelem(vin.val, vin.key, vin.alt))
214
247
  })
215
248
 
216
249
 
250
+ test('minor-edge-getelem', async () => {
251
+ const { getelem } = struct
252
+ equal(getelem([], 1, () => 2), 2)
253
+ })
254
+
255
+
217
256
  test('minor-getprop', async () => {
218
- await runsetflags(minorSpec.getprop, { null: false }, (vin: any) =>
219
- null == vin.alt ? getprop(vin.val, vin.key) : getprop(vin.val, vin.key, vin.alt))
257
+ const { getprop } = struct
258
+ await runsetflags(spec.minor.getprop, { null: false }, (vin: any) =>
259
+ undefined === vin.alt ? getprop(vin.val, vin.key) : getprop(vin.val, vin.key, vin.alt))
220
260
  })
221
261
 
222
262
 
223
263
  test('minor-edge-getprop', async () => {
264
+ const { getprop } = struct
265
+
224
266
  let strarr = ['a', 'b', 'c', 'd', 'e']
225
267
  deepEqual(getprop(strarr, 2), 'c')
226
268
  deepEqual(getprop(strarr, '2'), 'c')
@@ -232,12 +274,14 @@ describe('struct', async () => {
232
274
 
233
275
 
234
276
  test('minor-setprop', async () => {
235
- await runset(minorSpec.setprop, (vin: any) =>
236
- setprop(vin.parent, vin.key, vin.val))
277
+ await runset(spec.minor.setprop, (vin: any) =>
278
+ struct.setprop(vin.parent, vin.key, vin.val))
237
279
  })
238
280
 
239
281
 
240
282
  test('minor-edge-setprop', async () => {
283
+ const { setprop } = struct
284
+
241
285
  let strarr0 = ['a', 'b', 'c', 'd', 'e']
242
286
  let strarr1 = ['a', 'b', 'c', 'd', 'e']
243
287
  deepEqual(setprop(strarr0, 2, 'C'), ['a', 'b', 'C', 'd', 'e'])
@@ -251,12 +295,14 @@ describe('struct', async () => {
251
295
 
252
296
 
253
297
  test('minor-delprop', async () => {
254
- await runset(minorSpec.delprop, (vin: any) =>
255
- delprop(vin.parent, vin.key))
298
+ await runset(spec.minor.delprop, (vin: any) =>
299
+ struct.delprop(vin.parent, vin.key))
256
300
  })
257
301
 
258
302
 
259
303
  test('minor-edge-delprop', async () => {
304
+ const { delprop } = struct
305
+
260
306
  let strarr0 = ['a', 'b', 'c', 'd', 'e']
261
307
  let strarr1 = ['a', 'b', 'c', 'd', 'e']
262
308
  deepEqual(delprop(strarr0, 2), ['a', 'b', 'd', 'e'])
@@ -270,40 +316,85 @@ describe('struct', async () => {
270
316
 
271
317
 
272
318
  test('minor-haskey', async () => {
273
- await runsetflags(minorSpec.haskey, { null: false }, (vin: any) =>
274
- haskey(vin.src, vin.key))
319
+ await runsetflags(spec.minor.haskey, { null: false }, (vin: any) =>
320
+ struct.haskey(vin.src, vin.key))
275
321
  })
276
322
 
277
323
 
278
324
  test('minor-keysof', async () => {
279
- await runset(minorSpec.keysof, keysof)
325
+ await runset(spec.minor.keysof, struct.keysof)
326
+ })
327
+
328
+ test('minor-edge-keysof', async () => {
329
+ const { keysof } = struct
330
+ const a0: any = [11, 22, 33]
331
+ a0.x = 1
332
+ deepEqual(keysof(a0), [0, 1, 2])
280
333
  })
281
334
 
282
335
 
283
- test('minor-joinurl', async () => {
284
- await runsetflags(minorSpec.joinurl, { null: false }, joinurl)
336
+
337
+ test('minor-join', async () => {
338
+ await runsetflags(spec.minor.join, { null: false },
339
+ (vin: any) => struct.join(vin.val, vin.sep, vin.url))
340
+ })
341
+
342
+
343
+ test('minor-typename', async () => {
344
+ await runset(spec.minor.typename, struct.typename)
285
345
  })
286
346
 
287
347
 
288
348
  test('minor-typify', async () => {
289
- await runsetflags(minorSpec.typify, { null: false }, typify)
349
+ await runsetflags(spec.minor.typify, { null: false }, struct.typify)
350
+ })
351
+
352
+
353
+ test('minor-edge-typify', async () => {
354
+ const {
355
+ typify, T_noval, T_scalar, T_function, T_symbol, T_any, T_node, T_instance, T_null
356
+ } = struct
357
+ class X { }
358
+ const x = new X()
359
+ equal(typify(), T_noval)
360
+ equal(typify(undefined), T_noval)
361
+ equal(typify(NaN), T_noval)
362
+ equal(typify(null), T_scalar | T_null)
363
+ equal(typify(() => null), T_scalar | T_function)
364
+ equal(typify(Symbol('S')), T_scalar | T_symbol)
365
+ equal(typify(BigInt(1)), T_any)
366
+ equal(typify(x), T_node | T_instance)
290
367
  })
291
368
 
292
369
 
293
370
  test('minor-size', async () => {
294
- await runsetflags(minorSpec.size, { null: false }, size)
371
+ await runsetflags(spec.minor.size, { null: false }, struct.size)
295
372
  })
296
373
 
297
374
 
298
375
  test('minor-slice', async () => {
299
- await runsetflags(minorSpec.slice, { null: false },
300
- (vin: any) => slice(vin.val, vin.start, vin.end))
376
+ await runsetflags(spec.minor.slice, { null: false },
377
+ (vin: any) => struct.slice(vin.val, vin.start, vin.end))
301
378
  })
302
379
 
303
380
 
304
381
  test('minor-pad', async () => {
305
- await runsetflags(minorSpec.pad, { null: false },
306
- (vin: any) => pad(vin.val, vin.pad, vin.char))
382
+ await runsetflags(spec.minor.pad, { null: false },
383
+ (vin: any) => struct.pad(vin.val, vin.pad, vin.char))
384
+ })
385
+
386
+
387
+ test('minor-setpath', async () => {
388
+ await runsetflags(spec.minor.setpath, { null: false },
389
+ (vin: any) => struct.setpath(vin.store, vin.path, vin.val))
390
+ })
391
+
392
+
393
+ test('minor-edge-setpath', async () => {
394
+ const { setpath, DELETE } = struct
395
+ const x = { y: { z: 1, q: 2 } }
396
+ deepEqual(setpath(x, 'y.q', DELETE), { z: 1 })
397
+ deepEqual(x, { y: { z: 1 } })
307
398
  })
308
399
 
309
400
 
@@ -312,9 +403,11 @@ describe('struct', async () => {
312
403
  // ==========
313
404
 
314
405
  test('walk-log', async () => {
315
- const test = clone(walkSpec.log)
406
+ const { clone, stringify, pathify, walk } = struct
316
407
 
317
- const log: string[] = []
408
+ const test = clone(spec.walk.log)
409
+
410
+ let log: string[] = []
318
411
 
319
412
  function walklog(key: any, val: any, parent: any, path: any) {
320
413
  log.push('k=' + stringify(key) +
@@ -324,8 +417,16 @@ describe('struct', async () => {
324
417
  return val
325
418
  }
326
419
 
420
+ walk(test.in, undefined, walklog)
421
+ deepEqual(log, test.out.after)
422
+
423
+ log = []
327
424
  walk(test.in, walklog)
328
- deepEqual(log, test.out)
425
+ deepEqual(log, test.out.before)
426
+
427
+ log = []
428
+ walk(test.in, walklog, walklog)
429
+ deepEqual(log, test.out.both)
329
430
  })
330
431
 
331
432
 
@@ -334,35 +435,97 @@ describe('struct', async () => {
334
435
  return 'string' === typeof val ? val + '~' + path.join('.') : val
335
436
  }
336
437
 
337
- await runset(walkSpec.basic, (vin: any) => walk(vin, walkpath))
438
+ await runset(spec.walk.basic, (vin: any) => struct.walk(vin, walkpath))
338
439
  })
339
440
 
340
441
 
442
+ test('walk-depth', async () => {
443
+
444
+ await runsetflags(spec.walk.depth, { null: false },
445
+ (vin: any) => {
446
+ let top: any = undefined
447
+ let cur: any = undefined
448
+ function copy(key: any, val: any, _parent: any, _path: any) {
449
+ if (undefined === key || struct.isnode(val)) {
450
+ let child = struct.islist(val) ? [] : {}
451
+ if (undefined === key) {
452
+ top = cur = child
453
+ }
454
+ else {
455
+ cur = cur[key] = child
456
+ }
457
+ }
458
+ else {
459
+ cur[key] = val
460
+ }
461
+ return val
462
+ }
463
+ struct.walk(vin.src, copy, undefined, vin.maxdepth)
464
+ return top
465
+ })
466
+ })
467
+
468
+
469
+ test('walk-copy', async () => {
470
+ const { walk, isnode, ismap, islist, size, setprop } = struct
471
+
472
+ let cur: any[]
473
+ function walkcopy(key: any, val: any, _parent: any, path: any) {
474
+ if (undefined === key) {
475
+ cur = []
476
+ cur[0] = ismap(val) ? {} : islist(val) ? [] : val
477
+ return val
478
+ }
479
+
480
+ let v = val
481
+ let i = size(path)
482
+
483
+ if (isnode(v)) {
484
+ v = cur[i] = ismap(v) ? {} : []
485
+ }
486
+
487
+ setprop(cur[i - 1], key, v)
488
+
489
+ return val
490
+ }
491
+
492
+ await runset(spec.walk.copy, (vin: any) => (walk(vin, walkcopy), cur[0]))
493
+ })
494
+
495
+
496
+
341
497
  // merge tests
342
498
  // ===========
343
499
 
344
500
  test('merge-basic', async () => {
345
- const test = clone(mergeSpec.basic)
501
+ const { clone, merge } = struct
502
+ const test = clone(spec.merge.basic)
346
503
  deepEqual(merge(test.in), test.out)
347
504
  })
348
505
 
349
506
 
350
507
  test('merge-cases', async () => {
351
- await runset(mergeSpec.cases, merge)
508
+ await runset(spec.merge.cases, struct.merge)
352
509
  })
353
510
 
354
511
 
355
512
  test('merge-array', async () => {
356
- await runset(mergeSpec.array, merge)
513
+ await runset(spec.merge.array, struct.merge)
357
514
  })
358
515
 
359
516
 
360
517
  test('merge-integrity', async () => {
361
- await runset(mergeSpec.integrity, merge)
518
+ await runset(spec.merge.integrity, struct.merge)
519
+ })
520
+
521
+
522
+ test('merge-depth', async () => {
523
+ await runset(spec.merge.depth, (vin: any) => struct.merge(vin.val, vin.depth))
362
524
  })
363
525
 
364
526
 
365
527
  test('merge-special', async () => {
528
+ const { merge } = struct
366
529
  const f0 = () => null
367
530
  deepEqual(merge([f0]), f0)
368
531
  deepEqual(merge([null, f0]), f0)
@@ -374,6 +537,34 @@ describe('struct', async () => {
374
537
  deepEqual(merge([{ a: global.fetch }]), { a: global.fetch })
375
538
  deepEqual(merge([[global.fetch]]), [global.fetch])
376
539
  deepEqual(merge([{ a: { b: global.fetch } }]), { a: { b: global.fetch } })
540
+
541
+ class Bar { x = 1 }
542
+ const b0 = new Bar()
543
+ let out
544
+
545
+ equal(merge([{ x: 10 }, b0]), b0)
546
+ equal(b0.x, 1)
547
+ equal(b0 instanceof Bar, true)
548
+
549
+ deepEqual(merge([{ a: b0 }, { a: { x: 11 } }]), { a: { x: 11 } })
550
+ equal(b0.x, 1)
551
+ equal(b0 instanceof Bar, true)
552
+
553
+ deepEqual(merge([b0, { x: 20 }]), { x: 20 })
554
+ equal(b0.x, 1)
555
+ equal(b0 instanceof Bar, true)
556
+
557
+ out = merge([{ a: { x: 21 } }, { a: b0 }])
558
+ deepEqual(out, { a: b0 })
559
+ equal(b0, out.a)
560
+ equal(b0.x, 1)
561
+ equal(b0 instanceof Bar, true)
562
+
563
+ out = merge([{}, { b: b0 }])
564
+ deepEqual(out, { b: b0 })
565
+ equal(b0, out.b)
566
+ equal(b0.x, 1)
567
+ equal(b0 instanceof Bar, true)
377
568
  })
378
569
 
379
570
 
@@ -381,25 +572,26 @@ describe('struct', async () => {
381
572
  // =============
382
573
 
383
574
  test('getpath-basic', async () => {
384
- await runset(getpathSpec.basic, (vin: any) => getpath(vin.store, vin.path))
575
+ await runset(spec.getpath.basic, (vin: any) => struct.getpath(vin.store, vin.path))
385
576
  })
386
577
 
387
578
 
388
579
  test('getpath-relative', async () => {
389
- await runset(getpathSpec.relative, (vin: any) =>
390
- getpath(vin.store, vin.path, { dparent: vin.dparent, dpath: vin.dpath?.split('.') }))
580
+ await runset(spec.getpath.relative, (vin: any) =>
581
+ struct.getpath(vin.store, vin.path,
582
+ { dparent: vin.dparent, dpath: vin.dpath?.split('.') }))
391
583
  })
392
584
 
393
585
 
394
586
  test('getpath-special', async () => {
395
- await runset(getpathSpec.special, (vin: any) =>
396
- getpath(vin.store, vin.path, vin.inj))
587
+ await runset(spec.getpath.special, (vin: any) =>
588
+ struct.getpath(vin.store, vin.path, vin.inj))
397
589
  })
398
590
 
399
591
 
400
592
  test('getpath-handler', async () => {
401
- await runset(getpathSpec.handler, (vin: any) =>
402
- getpath(
593
+ await runset(spec.getpath.handler, (vin: any) =>
594
+ struct.getpath(
403
595
  {
404
596
  $TOP: vin.store,
405
597
  $FOO: () => 'foo',
@@ -418,19 +610,20 @@ describe('struct', async () => {
418
610
  // ============
419
611
 
420
612
  test('inject-basic', async () => {
421
- const test = clone(injectSpec.basic)
613
+ const { clone, inject } = struct
614
+ const test = clone(spec.inject.basic)
422
615
  deepEqual(inject(test.in.val, test.in.store), test.out)
423
616
  })
424
617
 
425
618
 
426
619
  test('inject-string', async () => {
427
- await runset(injectSpec.string, (vin: any) =>
428
- inject(vin.val, vin.store, { modify: nullModifier }))
620
+ await runset(spec.inject.string, (vin: any) =>
621
+ struct.inject(vin.val, vin.store, { modify: nullModifier }))
429
622
  })
430
623
 
431
624
 
432
625
  test('inject-deep', async () => {
433
- await runset(injectSpec.deep, (vin: any) => inject(vin.val, vin.store))
626
+ await runset(spec.inject.deep, (vin: any) => struct.inject(vin.val, vin.store))
434
627
  })
435
628
 
436
629
 
@@ -438,44 +631,63 @@ describe('struct', async () => {
438
631
  // ===============
439
632
 
440
633
  test('transform-basic', async () => {
441
- const test = clone(transformSpec.basic)
634
+ const { clone, transform } = struct
635
+ const test = clone(spec.transform.basic)
442
636
  deepEqual(transform(test.in.data, test.in.spec), test.out)
443
637
  })
444
638
 
445
639
 
446
640
  test('transform-paths', async () => {
447
- await runset(transformSpec.paths, (vin: any) =>
448
- transform(vin.data, vin.spec))
641
+ await runset(spec.transform.paths, (vin: any) =>
642
+ struct.transform(vin.data, vin.spec))
449
643
  })
450
644
 
451
645
 
452
646
  test('transform-cmds', async () => {
453
- await runset(transformSpec.cmds, (vin: any) =>
454
- transform(vin.data, vin.spec))
647
+ await runset(spec.transform.cmds, (vin: any) =>
648
+ struct.transform(vin.data, vin.spec))
455
649
  })
456
650
 
457
651
 
458
652
  test('transform-each', async () => {
459
- await runset(transformSpec.each, (vin: any) =>
460
- transform(vin.data, vin.spec))
653
+ await runset(spec.transform.each, (vin: any) =>
654
+ struct.transform(vin.data, vin.spec))
461
655
  })
462
656
 
463
657
 
464
658
  test('transform-pack', async () => {
465
- await runset(transformSpec.pack, (vin: any) =>
466
- transform(vin.data, vin.spec))
659
+ await runset(spec.transform.pack, (vin: any) =>
660
+ struct.transform(vin.data, vin.spec))
467
661
  })
468
662
 
469
663
 
470
664
  test('transform-ref', async () => {
471
- await runset(transformSpec.ref, (vin: any) =>
472
- transform(vin.data, vin.spec))
665
+ await runset(spec.transform.ref, (vin: any) =>
666
+ struct.transform(vin.data, vin.spec))
473
667
  })
474
668
 
475
669
 
670
+ test('transform-format', async () => {
671
+ await runsetflags(spec.transform.format, { null: false }, (vin: any) =>
672
+ struct.transform(vin.data, vin.spec))
673
+ })
674
+
675
+
676
+ test('transform-apply', async () => {
677
+ await runset(spec.transform.apply, (vin: any) =>
678
+ struct.transform(vin.data, vin.spec))
679
+ })
680
+
681
+ test('transform-edge-apply', async () => {
682
+ const { transform } = struct
683
+ equal(2, transform({}, ['`$APPLY`', (v: any) => 1 + v, 1]))
684
+ })
685
+
686
+
687
+
476
688
  test('transform-modify', async () => {
477
- await runset(transformSpec.modify, (vin: any) =>
478
- transform(
689
+ await runset(spec.transform.modify, (vin: any) =>
690
+ struct.transform(
479
691
  vin.data,
480
692
  vin.spec,
481
693
  {
@@ -490,14 +702,14 @@ describe('struct', async () => {
490
702
 
491
703
 
492
704
  test('transform-extra', async () => {
493
- deepEqual(transform(
705
+ deepEqual(struct.transform(
494
706
  { a: 1 },
495
707
  { x: '`a`', b: '`$COPY`', c: '`$UPPER`' },
496
708
  {
497
709
  extra: {
498
710
  b: 2, $UPPER: (state: any) => {
499
711
  const { path } = state
500
- return ('' + getprop(path, path.length - 1)).toUpperCase()
712
+ return ('' + struct.getprop(path, path.length - 1)).toUpperCase()
501
713
  }
502
714
  }
503
715
  }
@@ -510,6 +722,7 @@ describe('struct', async () => {
510
722
 
511
723
 
512
724
  test('transform-funcval', async () => {
725
+ const { transform } = struct
513
726
  // f0 should never be called (no $ prefix).
514
727
  const f0 = () => 99
515
728
  deepEqual(transform({}, { x: 1 }), { x: 1 })
@@ -523,33 +736,57 @@ describe('struct', async () => {
523
736
  // ===============
524
737
 
525
738
  test('validate-basic', async () => {
526
- await runset(validateSpec.basic, (vin: any) => validate(vin.data, vin.spec))
739
+ await runsetflags(spec.validate.basic, { null: false },
740
+ (vin: any) => struct.validate(vin.data, vin.spec))
527
741
  })
528
742
 
529
743
 
530
744
  test('validate-child', async () => {
531
- await runset(validateSpec.child, (vin: any) => validate(vin.data, vin.spec))
745
+ await runset(spec.validate.child, (vin: any) => struct.validate(vin.data, vin.spec))
532
746
  })
533
747
 
534
748
 
535
749
  test('validate-one', async () => {
536
- await runset(validateSpec.one, (vin: any) => validate(vin.data, vin.spec))
750
+ await runset(spec.validate.one, (vin: any) => struct.validate(vin.data, vin.spec))
537
751
  })
538
752
 
539
753
 
540
754
  test('validate-exact', async () => {
541
- await runset(validateSpec.exact, (vin: any) => validate(vin.data, vin.spec))
755
+ await runset(spec.validate.exact, (vin: any) => struct.validate(vin.data, vin.spec))
542
756
  })
543
757
 
544
758
 
545
759
  test('validate-invalid', async () => {
546
- await runsetflags(validateSpec.invalid, { null: false },
547
- (vin: any) => validate(vin.data, vin.spec))
760
+ await runsetflags(spec.validate.invalid, { null: false },
761
+ (vin: any) => struct.validate(vin.data, vin.spec))
548
762
  })
549
763
 
550
764
 
551
765
  test('validate-special', async () => {
552
- await runset(validateSpec.special, (vin: any) => validate(vin.data, vin.spec, vin.inj))
766
+ await runset(spec.validate.special, (vin: any) =>
767
+ struct.validate(vin.data, vin.spec, vin.inj))
768
+ })
769
+
770
+
771
+ test('validate-edge', async () => {
772
+ const { validate } = struct
773
+ let errs: any[] = []
774
+ validate({ x: 1 }, { x: '`$INSTANCE`' }, { errs })
775
+ equal(errs[0], 'Expected field x to be instance, but found integer: 1.')
776
+
777
+ errs = []
778
+ validate({ x: {} }, { x: '`$INSTANCE`' }, { errs })
779
+ equal(errs[0], 'Expected field x to be instance, but found map: {}.')
780
+
781
+ errs = []
782
+ validate({ x: [] }, { x: '`$INSTANCE`' }, { errs })
783
+ equal(errs[0], 'Expected field x to be instance, but found list: [].')
784
+
785
+ class C { }
786
+ const c = new C()
787
+ errs = []
788
+ validate({ x: c }, { x: '`$INSTANCE`' }, { errs })
789
+ equal(errs.length, 0)
553
790
  })
554
791
 
555
792
 
@@ -559,7 +796,7 @@ describe('struct', async () => {
559
796
  $INTEGER: (inj: any) => {
560
797
  const { key } = inj
561
798
  // let out = getprop(current, key)
562
- let out = getprop(inj.dparent, key)
799
+ let out = struct.getprop(inj.dparent, key)
563
800
 
564
801
  let t = typeof out
565
802
  if ('number' !== t && !Number.isInteger(out)) {
@@ -573,11 +810,11 @@ describe('struct', async () => {
573
810
 
574
811
  const shape = { a: '`$INTEGER`' }
575
812
 
576
- let out = validate({ a: 1 }, shape, { extra, errs })
813
+ let out = struct.validate({ a: 1 }, shape, { extra, errs })
577
814
  deepEqual(out, { a: 1 })
578
815
  equal(errs.length, 0)
579
816
 
580
- out = validate({ a: 'A' }, shape, { extra, errs })
817
+ out = struct.validate({ a: 'A' }, shape, { extra, errs })
581
818
  deepEqual(out, { a: 'A' })
582
819
  deepEqual(errs, ['Not an integer at a: A'])
583
820
  })
@@ -587,17 +824,22 @@ describe('struct', async () => {
587
824
  // ============
588
825
 
589
826
  test('select-basic', async () => {
590
- await runset(selectSpec.basic, (vin: any) => select(vin.obj, vin.query))
827
+ await runset(spec.select.basic, (vin: any) => struct.select(vin.obj, vin.query))
591
828
  })
592
829
 
593
830
 
594
831
  test('select-operators', async () => {
595
- await runset(selectSpec.operators, (vin: any) => select(vin.obj, vin.query))
832
+ await runset(spec.select.operators, (vin: any) => struct.select(vin.obj, vin.query))
596
833
  })
597
834
 
598
835
 
599
836
  test('select-edge', async () => {
600
- await runset(selectSpec.edge, (vin: any) => select(vin.obj, vin.query))
837
+ await runset(spec.select.edge, (vin: any) => struct.select(vin.obj, vin.query))
838
+ })
839
+
840
+
841
+ test('select-alts', async () => {
842
+ await runset(spec.select.alts, (vin: any) => struct.select(vin.obj, vin.query))
601
843
  })
602
844
 
603
845
 
@@ -605,23 +847,24 @@ describe('struct', async () => {
605
847
  // ============
606
848
 
607
849
  test('json-builder', async () => {
608
- equal(jsonify(jo(
850
+ const { jsonify, jm, jt } = struct
851
+ equal(jsonify(jm(
609
852
  'a', 1
610
853
  )), `{
611
854
  "a": 1
612
855
  }`)
613
856
 
614
- equal(jsonify(ja(
857
+ equal(jsonify(jt(
615
858
  'b', 2
616
859
  )), `[
617
860
  "b",
618
861
  2
619
862
  ]`)
620
863
 
621
- equal(jsonify(jo(
864
+ equal(jsonify(jm(
622
865
  'c', 'C',
623
- 'd', jo('x', true),
624
- 'e', ja(null, false)
866
+ 'd', jm('x', true),
867
+ 'e', jt(null, false)
625
868
  )), `{
626
869
  "c": "C",
627
870
  "d": {
@@ -633,13 +876,13 @@ describe('struct', async () => {
633
876
  ]
634
877
  }`)
635
878
 
636
- equal(jsonify(ja(
637
- 3.3, jo(
879
+ equal(jsonify(jt(
880
+ 3.3, jm(
638
881
  'f', true,
639
882
  'g', false,
640
883
  'h', null,
641
- 'i', ja('y', 0),
642
- 'j', jo('z', -1),
884
+ 'i', jt('y', 0),
885
+ 'j', jm('z', -1),
643
886
  'k')
644
887
  )), `[
645
888
  3.3,
@@ -658,7 +901,7 @@ describe('struct', async () => {
658
901
  }
659
902
  ]`)
660
903
 
661
- equal(jsonify(jo(
904
+ equal(jsonify(jm(
662
905
  true, 1,
663
906
  false, 2,
664
907
  null, 3,
@@ -676,3 +919,4 @@ describe('struct', async () => {
676
919
 
677
920
 
678
921
  })
922
+