shinkansen-transmission 2.2.235 → 2.3.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.
- package/babel.config.cjs +1 -0
- package/eslint.config.mjs +28 -30
- package/index.d.mts +321 -16
- package/package.json +6 -6
- package/src/index.cjs +2 -0
- package/src/index.d.mts +10 -9
- package/src/transmission/common/index.d.mts +153 -87
- package/src/transmission/common/index.mjs +670 -175
- package/src/transmission/from-document-to-hash/array/index.mjs +20 -4
- package/src/transmission/from-document-to-hash/boolean/index.mjs +25 -9
- package/src/transmission/from-document-to-hash/index.d.mts +8 -19
- package/src/transmission/from-document-to-hash/index.mjs +102 -16
- package/src/transmission/from-document-to-hash/null/index.mjs +25 -9
- package/src/transmission/from-document-to-hash/number/index.mjs +25 -9
- package/src/transmission/from-document-to-hash/object/index.mjs +22 -6
- package/src/transmission/from-document-to-hash/string/index.mjs +25 -9
- package/src/transmission/from-hash-to-document/array/index.mjs +22 -5
- package/src/transmission/from-hash-to-document/boolean/index.mjs +21 -4
- package/src/transmission/from-hash-to-document/index.d.mts +24 -26
- package/src/transmission/from-hash-to-document/index.mjs +264 -142
- package/src/transmission/from-hash-to-document/null/index.mjs +21 -4
- package/src/transmission/from-hash-to-document/number/index.mjs +21 -4
- package/src/transmission/from-hash-to-document/object/index.mjs +22 -5
- package/src/transmission/from-hash-to-document/string/index.mjs +26 -4
- package/src/transmission/index.d.mts +4 -10
- package/src/transmission/to-zashiki/index.d.mts +5 -13
- package/src/transmission/to-zashiki/params/index.mjs +430 -0
- package/src/transmission/to-zashiki/render/array/index.mjs +737 -0
- package/src/transmission/to-zashiki/render/boolean/index.mjs +794 -0
- package/src/transmission/to-zashiki/render/index.mjs +157 -0
- package/src/transmission/to-zashiki/render/null/index.mjs +796 -0
- package/src/transmission/to-zashiki/render/number/index.mjs +940 -0
- package/src/transmission/to-zashiki/render/object/index.mjs +653 -0
- package/src/transmission/to-zashiki/render/string/index.mjs +910 -0
- package/src/transmission/to-zashiki/render-params/root-schema/index.mjs +212 -0
- package/src/transmission/to-zashiki/render-params/schema/index.mjs +731 -0
- package/src/transmission/to-zashiki/transform-root-schema.mjs +485 -421
- package/src/transmission/to-zashiki/transform-schema.mjs +1988 -4663
@@ -1,3 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* @typedef {TransmissionTypes.DocumentType} DocumentType
|
3
|
+
* @typedef {TransmissionTypes.SchemaType} SchemaType
|
4
|
+
* @typedef {TransmissionTypes.HashType} HashType
|
5
|
+
*/
|
6
|
+
|
1
7
|
import debug from 'debug'
|
2
8
|
|
3
9
|
import {
|
@@ -14,7 +20,17 @@ const log = debug('shinkansen-transmission/from-document-to-hash/array')
|
|
14
20
|
|
15
21
|
log('`shinkansen` is awake')
|
16
22
|
|
17
|
-
|
23
|
+
/**
|
24
|
+
* Document can be `undefined`
|
25
|
+
*
|
26
|
+
* @param {DocumentType} [document]
|
27
|
+
* @param {SchemaType} [schema]
|
28
|
+
* @param {HashType} [hash]
|
29
|
+
* @param {string} [parentUri]
|
30
|
+
* @param {string} [uri]
|
31
|
+
* @returns {HashType}
|
32
|
+
*/
|
33
|
+
export default function transformArraySchema (document, schema = {}, hash = {}, parentUri = '#', uri = getUri(parentUri)) {
|
18
34
|
log('transformArraySchema')
|
19
35
|
|
20
36
|
/*
|
@@ -24,13 +40,13 @@ export default function transformArraySchema (document, schema = {}, values = {}
|
|
24
40
|
/*
|
25
41
|
* Yes, `document` is an array
|
26
42
|
*/
|
27
|
-
return transformArray(document, schema,
|
43
|
+
return transformArray(document, schema, hash, parentUri, uri)
|
28
44
|
}
|
29
45
|
|
30
46
|
/*
|
31
47
|
* The hash should contain only strings
|
32
48
|
*/
|
33
|
-
|
49
|
+
hash[uri] = toString(document)
|
34
50
|
|
35
|
-
return
|
51
|
+
return hash
|
36
52
|
}
|
@@ -1,3 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* @typedef {TransmissionTypes.DocumentType} DocumentType
|
3
|
+
* @typedef {TransmissionTypes.SchemaType} SchemaType
|
4
|
+
* @typedef {TransmissionTypes.HashType} HashType
|
5
|
+
*/
|
6
|
+
|
1
7
|
import debug from 'debug'
|
2
8
|
|
3
9
|
import {
|
@@ -16,29 +22,39 @@ const log = debug('shinkansen-transmission/from-document-to-hash/boolean')
|
|
16
22
|
|
17
23
|
log('`shinkansen` is awake')
|
18
24
|
|
19
|
-
|
25
|
+
/**
|
26
|
+
* Document can be `undefined`
|
27
|
+
*
|
28
|
+
* @param {DocumentType} [document]
|
29
|
+
* @param {SchemaType} [schema]
|
30
|
+
* @param {HashType} [hash]
|
31
|
+
* @param {string} [parentUri]
|
32
|
+
* @param {string} [uri]
|
33
|
+
* @returns {HashType}
|
34
|
+
*/
|
35
|
+
export default function transformBooleanSchema (document, schema = {}, hash = {}, parentUri = '#', uri = getUri(parentUri)) {
|
20
36
|
log('transformBooleanSchema')
|
21
37
|
|
22
38
|
if (hasEnum(schema)) {
|
23
39
|
const items = getEnum(schema)
|
24
40
|
|
25
|
-
|
41
|
+
hash[uri] = transformValueIndexFor(items, document)
|
26
42
|
|
27
|
-
return
|
43
|
+
return hash
|
28
44
|
} else {
|
29
45
|
if (hasAnyOf(schema)) {
|
30
46
|
const items = getAnyOf(schema)
|
31
47
|
|
32
|
-
|
48
|
+
hash[uri] = transformValueIndexFor(items, document)
|
33
49
|
|
34
|
-
return
|
50
|
+
return hash
|
35
51
|
} else {
|
36
52
|
if (hasOneOf(schema)) {
|
37
53
|
const items = getOneOf(schema)
|
38
54
|
|
39
|
-
|
55
|
+
hash[uri] = transformValueIndexFor(items, document)
|
40
56
|
|
41
|
-
return
|
57
|
+
return hash
|
42
58
|
}
|
43
59
|
}
|
44
60
|
}
|
@@ -46,7 +62,7 @@ export default function transformBooleanSchema (document, schema = {}, values =
|
|
46
62
|
/*
|
47
63
|
* The hash should contain only strings
|
48
64
|
*/
|
49
|
-
|
65
|
+
hash[uri] = toString(document)
|
50
66
|
|
51
|
-
return
|
67
|
+
return hash
|
52
68
|
}
|
@@ -1,22 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
type DocumentType = TransmissionTypes.DocumentType
|
2
|
+
type SchemaType = TransmissionTypes.SchemaType
|
3
|
+
type HashType = TransmissionTypes.HashType
|
4
4
|
|
5
|
-
|
5
|
+
export function transformArrayFor (document: DocumentType[], schema: { type: string }, hash: HashType, parentUri: string): HashType
|
6
|
+
export function transformObjectFor (document: Record<string, DocumentType>, schema: { type: string }, hash: HashType, parentUri: string): HashType
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
export function transformArray (document: DocumentType[], schema: { type: string }, hash: HashType, parentUri: string, uri: string): HashType
|
9
|
+
export function transformObject (document: Record<string, DocumentType>, schema: { type: string }, hash: HashType, parentUri: string, uri: string): HashType
|
9
10
|
|
10
|
-
|
11
|
-
export function transformObjectFor (document: DocumentType | undefined, schema: SchemaType | undefined, values: ObjectType | ObjectLiteralType | undefined, parentUri: string | undefined, uri: string | undefined): HashType | undefined
|
12
|
-
|
13
|
-
export function transformArray (document: DocumentType | undefined, schema: SchemaType | undefined, values: ObjectType | ObjectLiteralType | undefined, parentUri: string | undefined, uri: string | undefined): HashType | undefined
|
14
|
-
export function transformObject (document: DocumentType | undefined, schema: SchemaType | undefined, values: ObjectType | ObjectLiteralType | undefined, parentUri: string | undefined, uri: string | undefined): HashType | undefined
|
15
|
-
|
16
|
-
export default function transform (document: DocumentType | undefined, schema: SchemaType | undefined, values: ObjectType | ObjectLiteralType | undefined, parentUri: string | undefined, uri: string | undefined): HashType | undefined
|
17
|
-
}
|
18
|
-
|
19
|
-
declare module 'shinkansen-transmission/transmission/from-document-to-hash' {
|
20
|
-
export { default } from '#transmission/transmission/from-document-to-hash'
|
21
|
-
export * from '#transmission/transmission/from-document-to-hash'
|
22
|
-
}
|
11
|
+
export default function transform (document?: DocumentType, schema?: SchemaType, hash?: HashType, parentUri?: string, uri?: string): HashType
|
@@ -1,3 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* @typedef {TransmissionTypes.DocumentType} DocumentType
|
3
|
+
* @typedef {TransmissionTypes.SchemaType} SchemaType
|
4
|
+
* @typedef {TransmissionTypes.HashType} HashType
|
5
|
+
*/
|
6
|
+
|
1
7
|
import debug from 'debug'
|
2
8
|
|
3
9
|
import {
|
@@ -14,45 +20,96 @@ import {
|
|
14
20
|
getUri,
|
15
21
|
transformValueIndexFor,
|
16
22
|
transformEqualIndexFor,
|
17
|
-
|
23
|
+
transformToValue
|
18
24
|
} from '#transmission/transmission/common'
|
19
25
|
|
20
26
|
const log = debug('shinkansen-transmission/from-document-to-hash')
|
21
27
|
|
22
28
|
log('`shinkansen` is awake')
|
23
29
|
|
24
|
-
export {
|
25
|
-
|
30
|
+
export { transformToValue }
|
31
|
+
|
32
|
+
/**
|
33
|
+
* @param {SchemaType} schema
|
34
|
+
* @param {string} parentUri
|
35
|
+
* @returns {(hash: HashType, document: DocumentType, index: number) => HashType}
|
36
|
+
*/
|
37
|
+
function getReduceArrayFor (schema, parentUri) {
|
38
|
+
/**
|
39
|
+
* @param {HashType} hash
|
40
|
+
* @param {DocumentType} document
|
41
|
+
* @param {number} index
|
42
|
+
* @returns {HashType}
|
43
|
+
*/
|
44
|
+
return function reduce (hash, document, index) {
|
45
|
+
const schemaUri = getUri(parentUri, index)
|
46
|
+
|
47
|
+
return transform(document, getSchema(schema, parentUri, schemaUri), hash, schemaUri, schemaUri)
|
48
|
+
}
|
26
49
|
}
|
27
50
|
|
51
|
+
/**
|
52
|
+
* @param {SchemaType} schema
|
53
|
+
* @param {string} parentUri
|
54
|
+
* @returns {(hash: HashType, entry: [key: string, document: DocumentType]) => HashType}
|
55
|
+
*/
|
56
|
+
function getReduceObjectFor (schema, parentUri) {
|
57
|
+
/**
|
58
|
+
* @param {HashType} hash
|
59
|
+
* @param {[key: string, document: DocumentType]} entry
|
60
|
+
* @returns {HashType}
|
61
|
+
*/
|
62
|
+
return function reduce (hash, [key, document]) {
|
63
|
+
const schemaUri = getUri(parentUri, key)
|
64
|
+
|
65
|
+
return transform(document, getSchema(schema, parentUri, schemaUri), hash, schemaUri, schemaUri)
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* @param {Array<DocumentType>} document
|
71
|
+
* @param {SchemaType} schema
|
72
|
+
* @param {HashType} hash
|
73
|
+
* @param {string} parentUri
|
74
|
+
* @returns {HashType}
|
75
|
+
*/
|
28
76
|
export function transformArrayFor (document, schema, hash, parentUri) { // }, uri) {
|
29
77
|
/*
|
30
78
|
* log('transformArrayFor')
|
31
79
|
*/
|
80
|
+
|
32
81
|
return (
|
33
82
|
document
|
34
|
-
.reduce((
|
35
|
-
const schemaUri = getUri(parentUri, index)
|
36
|
-
|
37
|
-
return transform(value, getSchema(schema, parentUri, schemaUri), hash, schemaUri, schemaUri)
|
38
|
-
}, hash)
|
83
|
+
.reduce(getReduceArrayFor(schema, parentUri), hash)
|
39
84
|
)
|
40
85
|
}
|
41
86
|
|
87
|
+
/**
|
88
|
+
* @param {Record<string, DocumentType>} document
|
89
|
+
* @param {SchemaType} schema
|
90
|
+
* @param {HashType} hash
|
91
|
+
* @param {string} parentUri
|
92
|
+
* @returns {HashType}
|
93
|
+
*/
|
42
94
|
export function transformObjectFor (document, schema, hash, parentUri) { // }, uri) {
|
43
95
|
/*
|
44
96
|
* log('transformObjectFor')
|
45
97
|
*/
|
98
|
+
|
46
99
|
return (
|
47
100
|
Object.entries(document)
|
48
|
-
.reduce((
|
49
|
-
const schemaUri = getUri(parentUri, key)
|
50
|
-
|
51
|
-
return transform(value, getSchema(schema, parentUri, schemaUri), hash, schemaUri, schemaUri)
|
52
|
-
}, hash)
|
101
|
+
.reduce(getReduceObjectFor(schema, parentUri), hash)
|
53
102
|
)
|
54
103
|
}
|
55
104
|
|
105
|
+
/**
|
106
|
+
* @param {Array<DocumentType>} document
|
107
|
+
* @param {SchemaType} schema
|
108
|
+
* @param {HashType} hash
|
109
|
+
* @param {string} parentUri
|
110
|
+
* @param {string} uri
|
111
|
+
* @returns {HashType}
|
112
|
+
*/
|
56
113
|
export function transformArray (document, schema, hash, parentUri, uri) {
|
57
114
|
/*
|
58
115
|
* log('transformArray')
|
@@ -85,7 +142,7 @@ export function transformArray (document, schema, hash, parentUri, uri) {
|
|
85
142
|
/*
|
86
143
|
* Items is an array of schemas
|
87
144
|
*/
|
88
|
-
return transformArrayFor(document, schema, hash, parentUri, uri)
|
145
|
+
return transformArrayFor(document, schema, hash, parentUri) // , uri)
|
89
146
|
} else {
|
90
147
|
if (isObject(items)) {
|
91
148
|
/*
|
@@ -123,9 +180,17 @@ export function transformArray (document, schema, hash, parentUri, uri) {
|
|
123
180
|
/*
|
124
181
|
* Transform schema
|
125
182
|
*/
|
126
|
-
return transformArrayFor(document, schema, hash, parentUri, uri) // schema not items
|
183
|
+
return transformArrayFor(document, schema, hash, parentUri) // , uri) // schema not items
|
127
184
|
}
|
128
185
|
|
186
|
+
/**
|
187
|
+
* @param {Record<string, DocumentType>} document
|
188
|
+
* @param {SchemaType} schema
|
189
|
+
* @param {HashType} hash
|
190
|
+
* @param {string} parentUri
|
191
|
+
* @param {string} uri
|
192
|
+
* @returns {HashType}
|
193
|
+
*/
|
129
194
|
export function transformObject (document, schema, hash, parentUri, uri) {
|
130
195
|
/*
|
131
196
|
* log('transformObject')
|
@@ -161,6 +226,16 @@ export function transformObject (document, schema, hash, parentUri, uri) {
|
|
161
226
|
return transformObjectFor(document, schema, hash, parentUri) // , uri)
|
162
227
|
}
|
163
228
|
|
229
|
+
/**
|
230
|
+
* Document can be `undefined`
|
231
|
+
*
|
232
|
+
* @param {DocumentType} [document]
|
233
|
+
* @param {SchemaType} [schema]
|
234
|
+
* @param {HashType} [hash]
|
235
|
+
* @param {string} [parentUri]
|
236
|
+
* @param {string} [uri]
|
237
|
+
* @returns {HashType}
|
238
|
+
*/
|
164
239
|
export default function transform (document, schema = {}, hash = {}, parentUri = '#', uri = getUri(parentUri)) {
|
165
240
|
log('fromDocumentToHash')
|
166
241
|
|
@@ -182,6 +257,11 @@ export default function transform (document, schema = {}, hash = {}, parentUri =
|
|
182
257
|
*/
|
183
258
|
return transformObject(document, schema, hash, parentUri, uri)
|
184
259
|
} else {
|
260
|
+
/**
|
261
|
+
* `document` is a primitive or is undefined
|
262
|
+
*
|
263
|
+
* Is the schema an `enum`?
|
264
|
+
*/
|
185
265
|
if (hasEnum(schema)) {
|
186
266
|
const items = getEnum(schema)
|
187
267
|
|
@@ -189,6 +269,9 @@ export default function transform (document, schema = {}, hash = {}, parentUri =
|
|
189
269
|
|
190
270
|
return hash
|
191
271
|
} else {
|
272
|
+
/**
|
273
|
+
* Is the schema an `anyOf`?
|
274
|
+
*/
|
192
275
|
if (hasAnyOf(schema)) {
|
193
276
|
const items = getAnyOf(schema)
|
194
277
|
|
@@ -196,6 +279,9 @@ export default function transform (document, schema = {}, hash = {}, parentUri =
|
|
196
279
|
|
197
280
|
return hash
|
198
281
|
} else {
|
282
|
+
/**
|
283
|
+
* Is the schema an `oneOf`?
|
284
|
+
*/
|
199
285
|
if (hasOneOf(schema)) {
|
200
286
|
const items = getOneOf(schema)
|
201
287
|
|
@@ -209,7 +295,7 @@ export default function transform (document, schema = {}, hash = {}, parentUri =
|
|
209
295
|
}
|
210
296
|
|
211
297
|
/*
|
212
|
-
*
|
298
|
+
* Transform the primitive or undefined `document` to a string
|
213
299
|
*/
|
214
300
|
hash[uri] = toString(document)
|
215
301
|
|
@@ -1,3 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* @typedef {TransmissionTypes.DocumentType} DocumentType
|
3
|
+
* @typedef {TransmissionTypes.SchemaType} SchemaType
|
4
|
+
* @typedef {TransmissionTypes.HashType} HashType
|
5
|
+
*/
|
6
|
+
|
1
7
|
import debug from 'debug'
|
2
8
|
|
3
9
|
import {
|
@@ -16,29 +22,39 @@ const log = debug('shinkansen-transmission/from-document-to-hash/null')
|
|
16
22
|
|
17
23
|
log('`shinkansen` is awake')
|
18
24
|
|
19
|
-
|
25
|
+
/**
|
26
|
+
* Document can be `undefined`
|
27
|
+
*
|
28
|
+
* @param {DocumentType} [document]
|
29
|
+
* @param {SchemaType} [schema]
|
30
|
+
* @param {HashType} [hash]
|
31
|
+
* @param {string} [parentUri]
|
32
|
+
* @param {string} [uri]
|
33
|
+
* @returns {HashType}
|
34
|
+
*/
|
35
|
+
export default function transformNullSchema (document, schema = {}, hash = {}, parentUri = '#', uri = getUri(parentUri)) {
|
20
36
|
log('transformNullSchema')
|
21
37
|
|
22
38
|
if (hasEnum(schema)) {
|
23
39
|
const items = getEnum(schema)
|
24
40
|
|
25
|
-
|
41
|
+
hash[uri] = transformValueIndexFor(items, document)
|
26
42
|
|
27
|
-
return
|
43
|
+
return hash
|
28
44
|
} else {
|
29
45
|
if (hasAnyOf(schema)) {
|
30
46
|
const items = getAnyOf(schema)
|
31
47
|
|
32
|
-
|
48
|
+
hash[uri] = transformValueIndexFor(items, document)
|
33
49
|
|
34
|
-
return
|
50
|
+
return hash
|
35
51
|
} else {
|
36
52
|
if (hasOneOf(schema)) {
|
37
53
|
const items = getOneOf(schema)
|
38
54
|
|
39
|
-
|
55
|
+
hash[uri] = transformValueIndexFor(items, document)
|
40
56
|
|
41
|
-
return
|
57
|
+
return hash
|
42
58
|
}
|
43
59
|
}
|
44
60
|
}
|
@@ -46,7 +62,7 @@ export default function transformNullSchema (document, schema = {}, values = {},
|
|
46
62
|
/*
|
47
63
|
* The hash should contain only strings
|
48
64
|
*/
|
49
|
-
|
65
|
+
hash[uri] = toString(document)
|
50
66
|
|
51
|
-
return
|
67
|
+
return hash
|
52
68
|
}
|
@@ -1,3 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* @typedef {TransmissionTypes.DocumentType} DocumentType
|
3
|
+
* @typedef {TransmissionTypes.SchemaType} SchemaType
|
4
|
+
* @typedef {TransmissionTypes.HashType} HashType
|
5
|
+
*/
|
6
|
+
|
1
7
|
import debug from 'debug'
|
2
8
|
|
3
9
|
import {
|
@@ -16,29 +22,39 @@ const log = debug('shinkansen-transmission/from-document-to-hash/number')
|
|
16
22
|
|
17
23
|
log('`shinkansen` is awake')
|
18
24
|
|
19
|
-
|
25
|
+
/**
|
26
|
+
* Document can be `undefined`
|
27
|
+
*
|
28
|
+
* @param {DocumentType} [document]
|
29
|
+
* @param {SchemaType} [schema]
|
30
|
+
* @param {HashType} [hash]
|
31
|
+
* @param {string} [parentUri]
|
32
|
+
* @param {string} [uri]
|
33
|
+
* @returns {HashType}
|
34
|
+
*/
|
35
|
+
export default function transformNumberSchema (document, schema = {}, hash = {}, parentUri = '#', uri = getUri(parentUri)) {
|
20
36
|
log('transformNumberSchema')
|
21
37
|
|
22
38
|
if (hasEnum(schema)) {
|
23
39
|
const items = getEnum(schema)
|
24
40
|
|
25
|
-
|
41
|
+
hash[uri] = transformValueIndexFor(items, document)
|
26
42
|
|
27
|
-
return
|
43
|
+
return hash
|
28
44
|
} else {
|
29
45
|
if (hasAnyOf(schema)) {
|
30
46
|
const items = getAnyOf(schema)
|
31
47
|
|
32
|
-
|
48
|
+
hash[uri] = transformValueIndexFor(items, document)
|
33
49
|
|
34
|
-
return
|
50
|
+
return hash
|
35
51
|
} else {
|
36
52
|
if (hasOneOf(schema)) {
|
37
53
|
const items = getOneOf(schema)
|
38
54
|
|
39
|
-
|
55
|
+
hash[uri] = transformValueIndexFor(items, document)
|
40
56
|
|
41
|
-
return
|
57
|
+
return hash
|
42
58
|
}
|
43
59
|
}
|
44
60
|
}
|
@@ -46,7 +62,7 @@ export default function transformNumberSchema (document, schema = {}, values = {
|
|
46
62
|
/*
|
47
63
|
* The hash should contain only strings
|
48
64
|
*/
|
49
|
-
|
65
|
+
hash[uri] = toString(document)
|
50
66
|
|
51
|
-
return
|
67
|
+
return hash
|
52
68
|
}
|
@@ -1,3 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* @typedef {TransmissionTypes.DocumentType} DocumentType
|
3
|
+
* @typedef {TransmissionTypes.SchemaType} SchemaType
|
4
|
+
* @typedef {TransmissionTypes.HashType} HashType
|
5
|
+
*/
|
6
|
+
|
1
7
|
import debug from 'debug'
|
2
8
|
|
3
9
|
import {
|
@@ -14,7 +20,17 @@ const log = debug('shinkansen-transmission/from-document-to-hash/object')
|
|
14
20
|
|
15
21
|
log('`shinkansen` is awake')
|
16
22
|
|
17
|
-
|
23
|
+
/**
|
24
|
+
* Document can be `undefined`
|
25
|
+
*
|
26
|
+
* @param {DocumentType} [document]
|
27
|
+
* @param {SchemaType} [schema]
|
28
|
+
* @param {HashType} [hash]
|
29
|
+
* @param {string} [parentUri]
|
30
|
+
* @param {string} [uri]
|
31
|
+
* @returns {HashType}
|
32
|
+
*/
|
33
|
+
export default function transformObjectSchema (document, schema = {}, hash = {}, parentUri = '#', uri = getUri(parentUri)) {
|
18
34
|
log('transformObjectSchema')
|
19
35
|
|
20
36
|
/*
|
@@ -22,15 +38,15 @@ export default function transformObjectSchema (document, schema = {}, values = {
|
|
22
38
|
*/
|
23
39
|
if (isObject(document)) {
|
24
40
|
/*
|
25
|
-
|
26
|
-
|
27
|
-
return transformObject(document, schema,
|
41
|
+
* Yes, `document` is an object
|
42
|
+
*/
|
43
|
+
return transformObject(document, schema, hash, parentUri, uri)
|
28
44
|
}
|
29
45
|
|
30
46
|
/*
|
31
47
|
* The hash should contain only strings
|
32
48
|
*/
|
33
|
-
|
49
|
+
hash[uri] = toString(document)
|
34
50
|
|
35
|
-
return
|
51
|
+
return hash
|
36
52
|
}
|
@@ -1,3 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* @typedef {TransmissionTypes.DocumentType} DocumentType
|
3
|
+
* @typedef {TransmissionTypes.SchemaType} SchemaType
|
4
|
+
* @typedef {TransmissionTypes.HashType} HashType
|
5
|
+
*/
|
6
|
+
|
1
7
|
import debug from 'debug'
|
2
8
|
|
3
9
|
import {
|
@@ -16,29 +22,39 @@ const log = debug('shinkansen-transmission/from-document-to-hash/string')
|
|
16
22
|
|
17
23
|
log('`shinkansen` is awake')
|
18
24
|
|
19
|
-
|
25
|
+
/**
|
26
|
+
* Document can be `undefined`
|
27
|
+
*
|
28
|
+
* @param {DocumentType} [document]
|
29
|
+
* @param {SchemaType} [schema]
|
30
|
+
* @param {HashType} [hash]
|
31
|
+
* @param {string} [parentUri]
|
32
|
+
* @param {string} [uri]
|
33
|
+
* @returns {HashType}
|
34
|
+
*/
|
35
|
+
export default function transformStringSchema (document, schema = {}, hash = {}, parentUri = '#', uri = getUri(parentUri)) {
|
20
36
|
log('transformStringSchema')
|
21
37
|
|
22
38
|
if (hasEnum(schema)) {
|
23
39
|
const items = getEnum(schema)
|
24
40
|
|
25
|
-
|
41
|
+
hash[uri] = transformValueIndexFor(items, document)
|
26
42
|
|
27
|
-
return
|
43
|
+
return hash
|
28
44
|
} else {
|
29
45
|
if (hasAnyOf(schema)) {
|
30
46
|
const items = getAnyOf(schema)
|
31
47
|
|
32
|
-
|
48
|
+
hash[uri] = transformValueIndexFor(items, document)
|
33
49
|
|
34
|
-
return
|
50
|
+
return hash
|
35
51
|
} else {
|
36
52
|
if (hasOneOf(schema)) {
|
37
53
|
const items = getOneOf(schema)
|
38
54
|
|
39
|
-
|
55
|
+
hash[uri] = transformValueIndexFor(items, document)
|
40
56
|
|
41
|
-
return
|
57
|
+
return hash
|
42
58
|
}
|
43
59
|
}
|
44
60
|
}
|
@@ -46,7 +62,7 @@ export default function transformStringSchema (document, schema = {}, values = {
|
|
46
62
|
/*
|
47
63
|
* The hash should contain only strings
|
48
64
|
*/
|
49
|
-
|
65
|
+
hash[uri] = toString(document)
|
50
66
|
|
51
|
-
return
|
67
|
+
return hash
|
52
68
|
}
|
@@ -1,3 +1,10 @@
|
|
1
|
+
/**
|
2
|
+
* @typedef {TransmissionTypes.HashType} HashType
|
3
|
+
* @typedef {TransmissionTypes.SchemaType} SchemaType
|
4
|
+
* @typedef {TransmissionTypes.ParamsType} ParamsType
|
5
|
+
* @typedef {TransmissionTypes.DocumentType} DocumentType
|
6
|
+
*/
|
7
|
+
|
1
8
|
import debug from 'debug'
|
2
9
|
|
3
10
|
import {
|
@@ -12,19 +19,29 @@ const log = debug('shinkansen-transmission/from-hash-to-document/array')
|
|
12
19
|
|
13
20
|
log('`shinkansen` is awake')
|
14
21
|
|
15
|
-
|
22
|
+
/**
|
23
|
+
* Hash can be `undefined`
|
24
|
+
*
|
25
|
+
* @param {HashType} [hash]
|
26
|
+
* @param {SchemaType} [schema]
|
27
|
+
* @param {ParamsType} [params]
|
28
|
+
* @returns {DocumentType | undefined}
|
29
|
+
*/
|
30
|
+
export default function transformArraySchema (hash = {}, schema = {}, params = {}) {
|
16
31
|
log('transformArraySchema')
|
17
32
|
|
18
|
-
const {
|
33
|
+
const {
|
34
|
+
type
|
35
|
+
} = schema
|
19
36
|
|
20
37
|
// https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.2.1
|
21
38
|
if (type === 'array') {
|
22
39
|
const {
|
23
|
-
uri: parentUri,
|
24
|
-
index: arrayIndex
|
40
|
+
uri: parentUri = '#',
|
41
|
+
index: arrayIndex // number | undefined
|
25
42
|
} = params
|
26
43
|
|
27
|
-
return transformArray(
|
44
|
+
return transformArray(hash, schema, parentUri, getUri(parentUri, arrayIndex))
|
28
45
|
}
|
29
46
|
|
30
47
|
throw new Error('Schema does not conform to Instance Data Model, https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.2.1')
|
@@ -1,3 +1,10 @@
|
|
1
|
+
/**
|
2
|
+
* @typedef {TransmissionTypes.HashType} HashType
|
3
|
+
* @typedef {TransmissionTypes.SchemaType} SchemaType
|
4
|
+
* @typedef {TransmissionTypes.ParamsType} ParamsType
|
5
|
+
* @typedef {TransmissionTypes.DocumentType} DocumentType
|
6
|
+
*/
|
7
|
+
|
1
8
|
import debug from 'debug'
|
2
9
|
|
3
10
|
import {
|
@@ -12,18 +19,28 @@ const log = debug('shinkansen-transmission/from-hash-to-document/boolean')
|
|
12
19
|
|
13
20
|
log('`shinkansen` is awake')
|
14
21
|
|
15
|
-
|
22
|
+
/**
|
23
|
+
* Hash can be `undefined`
|
24
|
+
*
|
25
|
+
* @param {HashType} [hash]
|
26
|
+
* @param {SchemaType} [schema]
|
27
|
+
* @param {ParamsType} [params]
|
28
|
+
* @returns {DocumentType | undefined}
|
29
|
+
*/
|
30
|
+
export default function transformBooleanSchema (hash = {}, schema = {}, params = {}) {
|
16
31
|
log('transformBooleanSchema')
|
17
32
|
|
18
|
-
const {
|
33
|
+
const {
|
34
|
+
type
|
35
|
+
} = schema
|
19
36
|
|
20
37
|
// https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.2.1
|
21
38
|
if (type === 'boolean') {
|
22
39
|
const {
|
23
|
-
uri: parentUri
|
40
|
+
uri: parentUri = '#'
|
24
41
|
} = params
|
25
42
|
|
26
|
-
return transformBoolean(
|
43
|
+
return transformBoolean(hash, schema, parentUri, getUri(parentUri))
|
27
44
|
}
|
28
45
|
|
29
46
|
throw new Error('Schema does not conform to Instance Data Model, https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.2.1')
|