shinkansen-transmission 2.3.3 → 2.3.5
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.
- package/index.d.mts +82 -102
- package/package.json +2 -2
- package/src/transmission/common/index.d.mts +7 -4
- package/src/transmission/common/index.mjs +58 -60
- package/src/transmission/from-document-to-hash/array/index.mjs +1 -1
- package/src/transmission/from-document-to-hash/boolean/index.mjs +11 -8
- package/src/transmission/from-document-to-hash/index.d.mts +4 -4
- package/src/transmission/from-document-to-hash/index.mjs +25 -53
- package/src/transmission/from-document-to-hash/null/index.mjs +11 -8
- package/src/transmission/from-document-to-hash/number/index.mjs +11 -8
- package/src/transmission/from-document-to-hash/string/index.mjs +17 -8
- package/src/transmission/from-hash-to-document/array/index.mjs +1 -1
- package/src/transmission/from-hash-to-document/index.mjs +34 -10
- package/src/transmission/from-hash-to-document/object/index.mjs +1 -1
- package/src/transmission/to-zashiki/params/index.mjs +0 -24
- package/src/transmission/to-zashiki/render/array/index.mjs +6 -18
- package/src/transmission/to-zashiki/render/boolean/index.mjs +6 -18
- package/src/transmission/to-zashiki/render/null/index.mjs +6 -18
- package/src/transmission/to-zashiki/render/number/index.mjs +6 -18
- package/src/transmission/to-zashiki/render/object/index.mjs +6 -18
- package/src/transmission/to-zashiki/render/string/index.mjs +6 -18
- package/src/transmission/to-zashiki/render-params/root-schema/index.mjs +0 -2
- package/src/transmission/to-zashiki/render-params/schema/index.mjs +0 -24
- package/src/transmission/to-zashiki/transform-schema.mjs +0 -14
package/index.d.mts
CHANGED
@@ -73,17 +73,29 @@ declare global {
|
|
73
73
|
pattern?: RegExp
|
74
74
|
}
|
75
75
|
|
76
|
-
export interface StringSchemaType extends SchemaType {
|
76
|
+
export interface StringSchemaType extends SchemaType {
|
77
|
+
type?: 'string'
|
78
|
+
}
|
77
79
|
|
78
|
-
export interface NumberSchemaType extends SchemaType {
|
80
|
+
export interface NumberSchemaType extends SchemaType {
|
81
|
+
type?: 'number'
|
82
|
+
}
|
79
83
|
|
80
|
-
export interface ArraySchemaType extends SchemaType {
|
84
|
+
export interface ArraySchemaType extends SchemaType {
|
85
|
+
type?: 'array'
|
86
|
+
}
|
81
87
|
|
82
|
-
export interface ObjectSchemaType extends SchemaType {
|
88
|
+
export interface ObjectSchemaType extends SchemaType {
|
89
|
+
type?: 'object'
|
90
|
+
}
|
83
91
|
|
84
|
-
export interface BooleanSchemaType extends SchemaType {
|
92
|
+
export interface BooleanSchemaType extends SchemaType {
|
93
|
+
type?: 'boolean'
|
94
|
+
}
|
85
95
|
|
86
|
-
export interface NullSchemaType extends SchemaType {
|
96
|
+
export interface NullSchemaType extends SchemaType {
|
97
|
+
type?: 'null'
|
98
|
+
}
|
87
99
|
|
88
100
|
/**
|
89
101
|
* String keys with string or string array values
|
@@ -93,9 +105,16 @@ declare global {
|
|
93
105
|
interface MetaType extends ObjectType {
|
94
106
|
parentUri?: string
|
95
107
|
uri?: string
|
108
|
+
schema?: SchemaType
|
109
|
+
rootSchema?: SchemaType
|
110
|
+
value?: string
|
111
|
+
defaultValue?: string
|
112
|
+
item?: number
|
113
|
+
name?: string
|
96
114
|
selectedItems?: SelectedItemsType
|
97
115
|
items?: ItemsType
|
98
|
-
|
116
|
+
isRequired?: boolean
|
117
|
+
component?: string
|
99
118
|
}
|
100
119
|
|
101
120
|
interface ElementsType extends ObjectType {
|
@@ -104,14 +123,26 @@ declare global {
|
|
104
123
|
}
|
105
124
|
|
106
125
|
export namespace Transmission {
|
107
|
-
|
126
|
+
interface TransmissionMetaType extends MetaType {}
|
127
|
+
|
128
|
+
interface TransmissionElementsType extends ElementsType {
|
129
|
+
field?: FieldType
|
130
|
+
enum?: EnumType
|
131
|
+
anyOf?: AnyOfType
|
132
|
+
oneOf?: OneOfType
|
133
|
+
fields?: Array<{
|
134
|
+
meta?: TransmissionMetaType
|
135
|
+
elements?: TransmissionElementsType
|
136
|
+
}>
|
137
|
+
}
|
138
|
+
|
139
|
+
export interface StringMetaType extends TransmissionMetaType {
|
108
140
|
minLength?: number
|
109
141
|
maxLength?: number
|
110
142
|
pattern?: RegExp
|
111
|
-
defaultValue?: string
|
112
143
|
}
|
113
144
|
|
114
|
-
export interface NumberMetaType extends
|
145
|
+
export interface NumberMetaType extends TransmissionMetaType {
|
115
146
|
min?: number
|
116
147
|
max?: number
|
117
148
|
step?: number
|
@@ -119,59 +150,34 @@ declare global {
|
|
119
150
|
isExclusiveMax?: boolean
|
120
151
|
}
|
121
152
|
|
122
|
-
export interface ArrayMetaType extends
|
153
|
+
export interface ArrayMetaType extends TransmissionMetaType {
|
154
|
+
minItems?: number
|
155
|
+
maxItems?: number
|
156
|
+
hasUniqueItems?: boolean
|
157
|
+
minContains?: number
|
158
|
+
maxContains?: number
|
159
|
+
}
|
123
160
|
|
124
|
-
export interface ObjectMetaType extends
|
161
|
+
export interface ObjectMetaType extends TransmissionMetaType {
|
162
|
+
minProperties?: number
|
163
|
+
maxProperties?: number
|
164
|
+
}
|
125
165
|
|
126
|
-
export interface BooleanMetaType extends
|
166
|
+
export interface BooleanMetaType extends TransmissionMetaType {}
|
127
167
|
|
128
|
-
export interface NullMetaType extends
|
168
|
+
export interface NullMetaType extends TransmissionMetaType {}
|
129
169
|
|
130
|
-
export interface StringElementsType extends
|
131
|
-
field?: FieldType
|
132
|
-
enum?: EnumType
|
133
|
-
anyOf?: AnyOfType
|
134
|
-
oneOf?: OneOfType
|
135
|
-
}
|
170
|
+
export interface StringElementsType extends TransmissionElementsType {}
|
136
171
|
|
137
|
-
export interface NumberElementsType extends
|
138
|
-
field?: FieldType
|
139
|
-
enum?: EnumType
|
140
|
-
anyOf?: AnyOfType
|
141
|
-
oneOf?: OneOfType
|
142
|
-
}
|
172
|
+
export interface NumberElementsType extends TransmissionElementsType {}
|
143
173
|
|
144
|
-
export interface ArrayElementsType extends
|
145
|
-
field?: FieldType
|
146
|
-
fields?: Array<{
|
147
|
-
meta?: MetaType
|
148
|
-
elements?: ElementsType
|
149
|
-
}>
|
150
|
-
enum?: EnumType
|
151
|
-
anyOf?: AnyOfType
|
152
|
-
oneOf?: OneOfType
|
153
|
-
}
|
174
|
+
export interface ArrayElementsType extends TransmissionElementsType {}
|
154
175
|
|
155
|
-
export interface ObjectElementsType extends
|
156
|
-
field?: FieldType
|
157
|
-
enum?: EnumType
|
158
|
-
anyOf?: AnyOfType
|
159
|
-
oneOf?: OneOfType
|
160
|
-
}
|
176
|
+
export interface ObjectElementsType extends TransmissionElementsType {}
|
161
177
|
|
162
|
-
export interface BooleanElementsType extends
|
163
|
-
field?: FieldType
|
164
|
-
enum?: EnumType
|
165
|
-
anyOf?: AnyOfType
|
166
|
-
oneOf?: OneOfType
|
167
|
-
}
|
178
|
+
export interface BooleanElementsType extends TransmissionElementsType {}
|
168
179
|
|
169
|
-
export interface NullElementsType extends
|
170
|
-
field?: FieldType
|
171
|
-
enum?: EnumType
|
172
|
-
anyOf?: AnyOfType
|
173
|
-
oneOf?: OneOfType
|
174
|
-
}
|
180
|
+
export interface NullElementsType extends TransmissionElementsType {}
|
175
181
|
|
176
182
|
interface TransmissionType {
|
177
183
|
meta?: StringMetaType
|
@@ -212,21 +218,20 @@ declare global {
|
|
212
218
|
export namespace Zashiki {
|
213
219
|
interface ZashikiMetaType extends MetaType {
|
214
220
|
type?: string
|
215
|
-
schema?: SchemaType
|
216
|
-
value?: string
|
217
|
-
component?: string
|
218
221
|
}
|
219
222
|
|
220
223
|
interface ZashikiElementsType extends ElementsType {
|
221
|
-
|
222
|
-
|
224
|
+
field?: FieldType
|
225
|
+
fields?: Array<{
|
226
|
+
meta?: ZashikiMetaType
|
227
|
+
elements?: ZashikiElementsType
|
228
|
+
}>
|
223
229
|
}
|
224
230
|
|
225
231
|
export interface StringMetaType extends ZashikiMetaType {
|
226
232
|
minLength?: number
|
227
233
|
maxLength?: number
|
228
234
|
pattern?: RegExp
|
229
|
-
defaultValue?: string
|
230
235
|
}
|
231
236
|
|
232
237
|
export interface NumberMetaType extends ZashikiMetaType {
|
@@ -237,59 +242,34 @@ declare global {
|
|
237
242
|
isExclusiveMax?: boolean
|
238
243
|
}
|
239
244
|
|
240
|
-
export interface ArrayMetaType extends ZashikiMetaType {
|
245
|
+
export interface ArrayMetaType extends ZashikiMetaType {
|
246
|
+
minItems?: number
|
247
|
+
maxItems?: number
|
248
|
+
hasUniqueItems?: boolean
|
249
|
+
minContains?: number
|
250
|
+
maxContains?: number
|
251
|
+
}
|
241
252
|
|
242
|
-
export interface ObjectMetaType extends ZashikiMetaType {
|
253
|
+
export interface ObjectMetaType extends ZashikiMetaType {
|
254
|
+
minProperties?: number
|
255
|
+
maxProperties?: number
|
256
|
+
}
|
243
257
|
|
244
258
|
export interface BooleanMetaType extends ZashikiMetaType {}
|
245
259
|
|
246
260
|
export interface NullMetaType extends ZashikiMetaType {}
|
247
261
|
|
248
|
-
export interface StringElementsType extends ZashikiElementsType {
|
249
|
-
field?: FieldType
|
250
|
-
enum?: EnumType
|
251
|
-
anyOf?: AnyOfType
|
252
|
-
oneOf?: OneOfType
|
253
|
-
}
|
262
|
+
export interface StringElementsType extends ZashikiElementsType {}
|
254
263
|
|
255
|
-
export interface NumberElementsType extends ZashikiElementsType {
|
256
|
-
field?: FieldType
|
257
|
-
enum?: EnumType
|
258
|
-
anyOf?: AnyOfType
|
259
|
-
oneOf?: OneOfType
|
260
|
-
}
|
264
|
+
export interface NumberElementsType extends ZashikiElementsType {}
|
261
265
|
|
262
|
-
export interface ArrayElementsType extends ZashikiElementsType {
|
263
|
-
field?: FieldType
|
264
|
-
fields?: Array<{
|
265
|
-
meta?: ZashikiMetaType
|
266
|
-
elements?: ZashikiElementsType
|
267
|
-
}>
|
268
|
-
enum?: EnumType
|
269
|
-
anyOf?: AnyOfType
|
270
|
-
oneOf?: OneOfType
|
271
|
-
}
|
266
|
+
export interface ArrayElementsType extends ZashikiElementsType {}
|
272
267
|
|
273
|
-
export interface ObjectElementsType extends ZashikiElementsType {
|
274
|
-
field?: FieldType
|
275
|
-
enum?: EnumType
|
276
|
-
anyOf?: AnyOfType
|
277
|
-
oneOf?: OneOfType
|
278
|
-
}
|
268
|
+
export interface ObjectElementsType extends ZashikiElementsType {}
|
279
269
|
|
280
|
-
export interface BooleanElementsType extends ZashikiElementsType {
|
281
|
-
field?: FieldType
|
282
|
-
enum?: EnumType
|
283
|
-
anyOf?: AnyOfType
|
284
|
-
oneOf?: OneOfType
|
285
|
-
}
|
270
|
+
export interface BooleanElementsType extends ZashikiElementsType {}
|
286
271
|
|
287
|
-
export interface NullElementsType extends ZashikiElementsType {
|
288
|
-
field?: FieldType
|
289
|
-
enum?: EnumType
|
290
|
-
anyOf?: AnyOfType
|
291
|
-
oneOf?: OneOfType
|
292
|
-
}
|
272
|
+
export interface NullElementsType extends ZashikiElementsType {}
|
293
273
|
|
294
274
|
interface ZashikiType {
|
295
275
|
meta?: ZashikiMetaType
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "shinkansen-transmission",
|
3
|
-
"version": "2.3.
|
3
|
+
"version": "2.3.5",
|
4
4
|
"description": "Shinkansen Transmission",
|
5
5
|
"keywords": [
|
6
6
|
"Shinkansen",
|
@@ -19,7 +19,7 @@
|
|
19
19
|
},
|
20
20
|
"license": "ISC",
|
21
21
|
"engines": {
|
22
|
-
"node": ">=
|
22
|
+
"node": ">=23.0.0"
|
23
23
|
},
|
24
24
|
"repository": {
|
25
25
|
"type": "git",
|
@@ -63,10 +63,10 @@ export function getMetaValue (values?: ValuesType, uri?: string, schema?: Schema
|
|
63
63
|
|
64
64
|
export function transformToValue (schema?: string | number | object | boolean | null): string | number | object | boolean | null | undefined
|
65
65
|
|
66
|
-
export function
|
67
|
-
export function
|
68
|
-
export function
|
69
|
-
export function
|
66
|
+
export function getFindByKey (parentUri: string, uri: string): (key: string | number) => boolean
|
67
|
+
export function getFindByIndex (parentUri: string, uri: string): (item: SchemaType, index: number) => boolean
|
68
|
+
export function getFindByValue (value?: string | number | object | boolean | null): (item?: string | number | object | boolean | null | string[] | number[] | object[] | boolean[] | null[]) => boolean
|
69
|
+
export function getFindByEqual (value?: string | number | object | boolean | null): (item?: string | number | object | boolean | null | string[] | number[] | object[] | boolean[] | null[]) => boolean
|
70
70
|
|
71
71
|
export function toString (value?: string | number | object | boolean | null): string
|
72
72
|
|
@@ -97,6 +97,9 @@ export { getSchema }
|
|
97
97
|
export function transformValueIndexFor (array: string[] | number[] | object[] | boolean[] | null[], value?: string | number | object | boolean | null): string
|
98
98
|
export function transformEqualIndexFor (array: string[] | number[] | object[] | boolean[] | null[], value?: string | number | object | boolean | null): string
|
99
99
|
|
100
|
+
export function getIndexByValue (array: string[] | number[] | object[] | boolean[] | null[], value?: string | number | object | boolean | null): number
|
101
|
+
export function getIndexByEqual (array: string[] | number[] | object[] | boolean[] | null[], value?: string | number | object | boolean | null): number
|
102
|
+
|
100
103
|
export function hasValue (values?: ValuesType, uri?: string, schema?: SchemaType): boolean
|
101
104
|
export function getValue (values?: ValuesType, uri?: string, schema?: SchemaType): string
|
102
105
|
|
@@ -308,8 +308,12 @@ export function getMetaValue (values = {}, uri = '#', schema = {}) {
|
|
308
308
|
* @returns {string | number | object | boolean | null | undefined}
|
309
309
|
*/
|
310
310
|
export function transformToValue (item) {
|
311
|
+
if (item === undefined) return item
|
312
|
+
|
311
313
|
if (isPrimitive(item)) return item
|
312
314
|
|
315
|
+
if (isArray(item)) return item // .map(transformToValue)
|
316
|
+
|
313
317
|
if (isObject(item)) {
|
314
318
|
if (hasConst(item)) {
|
315
319
|
return getConst(item)
|
@@ -318,9 +322,9 @@ export function transformToValue (item) {
|
|
318
322
|
return getDefault(item)
|
319
323
|
}
|
320
324
|
}
|
321
|
-
}
|
322
325
|
|
323
|
-
|
326
|
+
return item
|
327
|
+
}
|
324
328
|
}
|
325
329
|
|
326
330
|
/**
|
@@ -328,15 +332,14 @@ export function transformToValue (item) {
|
|
328
332
|
* @param {string} uri
|
329
333
|
* @returns {(key: string | number) => boolean}
|
330
334
|
*/
|
331
|
-
export function
|
335
|
+
export function getFindByKey (parentUri, uri) {
|
332
336
|
/*
|
333
|
-
* log('
|
337
|
+
* log('getFindByKey')
|
334
338
|
*/
|
335
339
|
return function find (key) {
|
336
340
|
/*
|
337
341
|
* log('find')
|
338
342
|
*/
|
339
|
-
|
340
343
|
return (
|
341
344
|
getUri(parentUri, key) === uri
|
342
345
|
)
|
@@ -346,51 +349,16 @@ export function findByKey (parentUri, uri) {
|
|
346
349
|
/**
|
347
350
|
* @param {string} parentUri
|
348
351
|
* @param {string} uri
|
349
|
-
* @returns {(
|
352
|
+
* @returns {(schema: SchemaType, index: number) => boolean}
|
350
353
|
*/
|
351
|
-
export function
|
354
|
+
export function getFindByIndex (parentUri, uri) {
|
352
355
|
/*
|
353
|
-
* log('
|
356
|
+
* log('getFindByIndex')
|
354
357
|
*/
|
355
|
-
return function find (
|
358
|
+
return function find (schema, index) {
|
356
359
|
/*
|
357
360
|
* log('find')
|
358
361
|
*/
|
359
|
-
|
360
|
-
/**
|
361
|
-
* It's a schema not a value
|
362
|
-
*/
|
363
|
-
|
364
|
-
if (hasEnum(item)) {
|
365
|
-
/**
|
366
|
-
* Do the `parentUri` and `uri` match?
|
367
|
-
*/
|
368
|
-
|
369
|
-
return (
|
370
|
-
getUri(parentUri, index) === uri
|
371
|
-
)
|
372
|
-
} else {
|
373
|
-
if (hasAnyOf(item)) {
|
374
|
-
const array = getAnyOf(item)
|
375
|
-
|
376
|
-
return (
|
377
|
-
array.filter(isObject).some(findByIndex(parentUri, uri))
|
378
|
-
)
|
379
|
-
} else {
|
380
|
-
if (hasOneOf(item)) {
|
381
|
-
const array = getOneOf(item)
|
382
|
-
|
383
|
-
return (
|
384
|
-
array.filter(isObject).some(findByIndex(parentUri, uri))
|
385
|
-
)
|
386
|
-
}
|
387
|
-
}
|
388
|
-
}
|
389
|
-
|
390
|
-
/**
|
391
|
-
* It's any other kind of schema/sub-schema
|
392
|
-
*/
|
393
|
-
|
394
362
|
return (
|
395
363
|
getUri(parentUri, index) === uri
|
396
364
|
)
|
@@ -401,15 +369,14 @@ export function findByIndex (parentUri, uri) {
|
|
401
369
|
* @param {string | number | object | boolean | null} [value]
|
402
370
|
* @returns {(item?: string | number | object | boolean | null | string[] | number[] | object[] | boolean[] | null[]) => boolean}
|
403
371
|
*/
|
404
|
-
export function
|
372
|
+
export function getFindByValue (value) {
|
405
373
|
/*
|
406
|
-
* log('
|
374
|
+
* log('getFindByValue')
|
407
375
|
*/
|
408
376
|
return function find (item) {
|
409
377
|
/*
|
410
378
|
* log('find')
|
411
379
|
*/
|
412
|
-
|
413
380
|
return (
|
414
381
|
value === transformToValue(item)
|
415
382
|
)
|
@@ -420,9 +387,9 @@ export function findByValue (value) {
|
|
420
387
|
* @param {string | number | object | boolean | null} [value]
|
421
388
|
* @returns {(item?: string | number | object | boolean | null | string[] | number[] | object[] | boolean[] | null[]) => boolean}
|
422
389
|
*/
|
423
|
-
export function
|
390
|
+
export function getFindByEqual (value) {
|
424
391
|
/*
|
425
|
-
* log('
|
392
|
+
* log('getFindByEqual')
|
426
393
|
*/
|
427
394
|
return function find (item) {
|
428
395
|
/*
|
@@ -455,15 +422,17 @@ export function getArray ({ items /* array or object */ } = {}, parentUri = '',
|
|
455
422
|
*/
|
456
423
|
|
457
424
|
if (isArray(items)) {
|
458
|
-
const find = findByIndex(parentUri, uri)
|
459
|
-
|
460
425
|
return (
|
461
|
-
items.find(
|
426
|
+
items.find(getFindByIndex(parentUri, uri))
|
462
427
|
)
|
428
|
+
} else {
|
429
|
+
if (isObject(items)) {
|
430
|
+
return (
|
431
|
+
items
|
432
|
+
)
|
433
|
+
}
|
463
434
|
}
|
464
435
|
|
465
|
-
if (isObject(items)) return items
|
466
|
-
|
467
436
|
return undefined
|
468
437
|
}
|
469
438
|
|
@@ -479,8 +448,7 @@ export function getObject ({ properties /* object */ } = {}, parentUri = '', uri
|
|
479
448
|
*/
|
480
449
|
|
481
450
|
if (isObject(properties)) {
|
482
|
-
const
|
483
|
-
const key = Object.keys(properties).find(find)
|
451
|
+
const key = Object.keys(properties).find(getFindByKey(parentUri, uri))
|
484
452
|
|
485
453
|
if (key) {
|
486
454
|
return (
|
@@ -543,14 +511,14 @@ export function transformValueIndexFor (array, value) {
|
|
543
511
|
* log('transformEqualIndexFor')
|
544
512
|
*/
|
545
513
|
|
546
|
-
const find =
|
514
|
+
const find = getFindByValue(value)
|
547
515
|
|
548
516
|
if (array.some(find)) {
|
549
517
|
const index = array.findIndex(find)
|
550
518
|
|
551
519
|
/*
|
552
|
-
|
553
|
-
|
520
|
+
* Transform a number to a string
|
521
|
+
*/
|
554
522
|
return String(index)
|
555
523
|
}
|
556
524
|
|
@@ -560,6 +528,21 @@ export function transformValueIndexFor (array, value) {
|
|
560
528
|
return toString(value)
|
561
529
|
}
|
562
530
|
|
531
|
+
/**
|
532
|
+
* @param {string[] | number[] | object[] | boolean[] | null[]} array
|
533
|
+
* @param {string | number | object | boolean | null} [value]
|
534
|
+
* @returns {number}
|
535
|
+
*/
|
536
|
+
export function getIndexByValue (array, value) {
|
537
|
+
/*
|
538
|
+
* log('transformEqualIndexFor')
|
539
|
+
*/
|
540
|
+
|
541
|
+
return (
|
542
|
+
array.findIndex(getFindByValue(value))
|
543
|
+
)
|
544
|
+
}
|
545
|
+
|
563
546
|
/**
|
564
547
|
* @param {string[] | number[] | object[] | boolean[] | null[]} array
|
565
548
|
* @param {string | number | object | boolean | null} [value]
|
@@ -570,7 +553,7 @@ export function transformEqualIndexFor (array, value) {
|
|
570
553
|
* log('transformEqualIndexFor')
|
571
554
|
*/
|
572
555
|
|
573
|
-
const find =
|
556
|
+
const find = getFindByEqual(value)
|
574
557
|
|
575
558
|
if (array.some(find)) {
|
576
559
|
const index = array.findIndex(find)
|
@@ -587,6 +570,21 @@ export function transformEqualIndexFor (array, value) {
|
|
587
570
|
return toString(value)
|
588
571
|
}
|
589
572
|
|
573
|
+
/**
|
574
|
+
* @param {string[] | number[] | object[] | boolean[] | null[]} array
|
575
|
+
* @param {string | number | object | boolean | null} [value]
|
576
|
+
* @returns {string}
|
577
|
+
*/
|
578
|
+
export function getIndexByEqual (array, value) {
|
579
|
+
/*
|
580
|
+
* log('transformEqualIndexFor')
|
581
|
+
*/
|
582
|
+
|
583
|
+
return (
|
584
|
+
array.findIndex(getFindByEqual(value))
|
585
|
+
)
|
586
|
+
}
|
587
|
+
|
590
588
|
/**
|
591
589
|
* @param {ValuesType} [values]
|
592
590
|
* @param {string} [uri]
|
@@ -15,7 +15,7 @@ import {
|
|
15
15
|
hasOneOf,
|
16
16
|
getOneOf,
|
17
17
|
getUri,
|
18
|
-
|
18
|
+
getIndexByValue
|
19
19
|
} from '#transmission/transmission/common'
|
20
20
|
|
21
21
|
const log = debug('shinkansen-transmission/from-document-to-hash/boolean')
|
@@ -23,7 +23,7 @@ const log = debug('shinkansen-transmission/from-document-to-hash/boolean')
|
|
23
23
|
log('`shinkansen` is awake')
|
24
24
|
|
25
25
|
/**
|
26
|
-
*
|
26
|
+
* Document can be `undefined`
|
27
27
|
*
|
28
28
|
* @param {DocumentType} [document]
|
29
29
|
* @param {SchemaType} [schema]
|
@@ -36,23 +36,26 @@ export default function transformBooleanSchema (document, schema = {}, hash = {}
|
|
36
36
|
log('transformBooleanSchema')
|
37
37
|
|
38
38
|
if (hasEnum(schema)) {
|
39
|
-
const
|
39
|
+
const array = getEnum(schema)
|
40
|
+
const index = getIndexByValue(array, document)
|
40
41
|
|
41
|
-
hash[uri] =
|
42
|
+
hash[uri] = String(index)
|
42
43
|
|
43
44
|
return hash
|
44
45
|
} else {
|
45
46
|
if (hasAnyOf(schema)) {
|
46
|
-
const
|
47
|
+
const array = getAnyOf(schema)
|
48
|
+
const index = getIndexByValue(array, document)
|
47
49
|
|
48
|
-
hash[uri] =
|
50
|
+
hash[uri] = String(index)
|
49
51
|
|
50
52
|
return hash
|
51
53
|
} else {
|
52
54
|
if (hasOneOf(schema)) {
|
53
|
-
const
|
55
|
+
const array = getOneOf(schema)
|
56
|
+
const index = getIndexByValue(array, document)
|
54
57
|
|
55
|
-
hash[uri] =
|
58
|
+
hash[uri] = String(index)
|
56
59
|
|
57
60
|
return hash
|
58
61
|
}
|
@@ -2,10 +2,10 @@ export type DocumentType = TransmissionTypes.DocumentType
|
|
2
2
|
export type SchemaType = TransmissionTypes.SchemaType
|
3
3
|
export type HashType = TransmissionTypes.HashType
|
4
4
|
|
5
|
-
export function transformArrayFor (document: DocumentType[], schema:
|
6
|
-
export function transformObjectFor (document: Record<string, DocumentType>, schema:
|
5
|
+
export function transformArrayFor (document: DocumentType[], schema: SchemaType, hash: HashType, parentUri: string): HashType
|
6
|
+
export function transformObjectFor (document: Record<string, DocumentType>, schema: SchemaType, hash: HashType, parentUri: string): HashType
|
7
7
|
|
8
|
-
export function transformArray (document: DocumentType[], schema:
|
9
|
-
export function transformObject (document: Record<string, DocumentType>, schema:
|
8
|
+
export function transformArray (document: DocumentType[], schema: SchemaType, hash: HashType, parentUri: string, uri: string): HashType
|
9
|
+
export function transformObject (document: Record<string, DocumentType>, schema: SchemaType, hash: HashType, parentUri: string, uri: string): HashType
|
10
10
|
|
11
11
|
export default function transform (document?: DocumentType, schema?: SchemaType, hash?: HashType, parentUri?: string, uri?: string): HashType
|