shinkansen-transmission 2.2.23 → 2.2.25
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/package.json +14 -4
- package/src/transmission/common/index.mjs +154 -0
- package/src/transmission/from-document-to-hash/array/index.mjs +36 -0
- package/src/transmission/from-document-to-hash/boolean/index.mjs +52 -0
- package/src/transmission/from-document-to-hash/index.mjs +16 -166
- package/src/transmission/from-document-to-hash/null/index.mjs +52 -0
- package/src/transmission/from-document-to-hash/number/index.mjs +52 -0
- package/src/transmission/from-document-to-hash/object/index.mjs +36 -0
- package/src/transmission/from-document-to-hash/string/index.mjs +52 -0
- package/src/transmission/from-hash-to-document/array/index.mjs +31 -0
- package/src/transmission/from-hash-to-document/boolean/index.mjs +30 -0
- package/src/transmission/from-hash-to-document/null/index.mjs +30 -0
- package/src/transmission/from-hash-to-document/number/index.mjs +30 -0
- package/src/transmission/from-hash-to-document/object/index.mjs +31 -0
- package/src/transmission/from-hash-to-document/string/index.mjs +30 -0
- package/src/transmission/to-zashiki/transform-root-schema.mjs +1 -1
- package/src/transmission/from-hash-to-document/transform-array-schema.mjs +0 -102
- package/src/transmission/from-hash-to-document/transform-object-schema.mjs +0 -102
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "shinkansen-transmission",
|
3
|
-
"version": "2.2.
|
3
|
+
"version": "2.2.25",
|
4
4
|
"description": "Shinkansen Transmission",
|
5
5
|
"keywords": [
|
6
6
|
"Shinkansen",
|
@@ -41,7 +41,7 @@
|
|
41
41
|
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
|
42
42
|
"@babel/preset-env": "^7.21.5",
|
43
43
|
"@babel/register": "^7.21.0",
|
44
|
-
"@modernpoacher/hooks": "^1.0.
|
44
|
+
"@modernpoacher/hooks": "^1.0.397",
|
45
45
|
"babel-loader": "^9.1.2",
|
46
46
|
"babel-plugin-module-resolver": "^5.0.0",
|
47
47
|
"c8": "^7.13.0",
|
@@ -64,10 +64,20 @@
|
|
64
64
|
"import": "./src/index.mjs"
|
65
65
|
},
|
66
66
|
"./transmission/common": "./src/transmission/common/index.mjs",
|
67
|
+
"./transmission/from-document-to-hash/string": "./src/transmission/from-document-to-hash/string/index.mjs",
|
68
|
+
"./transmission/from-document-to-hash/number": "./src/transmission/from-document-to-hash/number/index.mjs",
|
69
|
+
"./transmission/from-document-to-hash/array": "./src/transmission/from-document-to-hash/array/index.mjs",
|
70
|
+
"./transmission/from-document-to-hash/object": "./src/transmission/from-document-to-hash/object/index.mjs",
|
71
|
+
"./transmission/from-document-to-hash/boolean": "./src/transmission/from-document-to-hash/boolean/index.mjs",
|
72
|
+
"./transmission/from-document-to-hash/null": "./src/transmission/from-hash-to-document/null/index.mjs",
|
67
73
|
"./transmission/from-document-to-hash": "./src/transmission/from-document-to-hash/index.mjs",
|
74
|
+
"./transmission/from-hash-to-document/string": "./src/transmission/from-hash-to-document/string/index.mjs",
|
75
|
+
"./transmission/from-hash-to-document/number": "./src/transmission/from-hash-to-document/number/index.mjs",
|
76
|
+
"./transmission/from-hash-to-document/array": "./src/transmission/from-hash-to-document/array/index.mjs",
|
77
|
+
"./transmission/from-hash-to-document/object": "./src/transmission/from-hash-to-document/object/index.mjs",
|
78
|
+
"./transmission/from-hash-to-document/boolean": "./src/transmission/from-hash-to-document/boolean/index.mjs",
|
79
|
+
"./transmission/from-hash-to-document/null": "./src/transmission/from-hash-to-document/null/index.mjs",
|
68
80
|
"./transmission/from-hash-to-document": "./src/transmission/from-hash-to-document/index.mjs",
|
69
|
-
"./transmission/from-hash-to-document/transform-array-schema": "./src/transmission/from-hash-to-document/transform-array-schema.mjs",
|
70
|
-
"./transmission/from-hash-to-document/transform-object-schema": "./src/transmission/from-hash-to-document/transform-object-schema.mjs",
|
71
81
|
"./transmission/to-zashiki/transform-root-schema": "./src/transmission/to-zashiki/transform-root-schema.mjs",
|
72
82
|
"./transmission/to-zashiki/transform-schema": "./src/transmission/to-zashiki/transform-schema.mjs",
|
73
83
|
"./transmission/to-zashiki": "./src/transmission/to-zashiki/index.mjs",
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import debug from 'debug'
|
2
2
|
|
3
|
+
import equal from 'fast-deep-equal'
|
4
|
+
|
3
5
|
const log = debug('shinkansen-transmission/transmission/common')
|
4
6
|
|
5
7
|
log('`shinkansen` is awake')
|
@@ -161,6 +163,158 @@ export function transformValue (schema) {
|
|
161
163
|
)
|
162
164
|
}
|
163
165
|
|
166
|
+
export function findByKey (parentUri, uri) {
|
167
|
+
/*
|
168
|
+
* log('findByKey')
|
169
|
+
*/
|
170
|
+
return function find (key) {
|
171
|
+
/*
|
172
|
+
* log('find')
|
173
|
+
*/
|
174
|
+
return getUri(parentUri, key) === uri
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
export function findByIndex (parentUri, uri) {
|
179
|
+
/*
|
180
|
+
* log('findByIndex')
|
181
|
+
*/
|
182
|
+
return function find (schema, index) {
|
183
|
+
/*
|
184
|
+
* log('find')
|
185
|
+
*/
|
186
|
+
if (hasEnum(schema)) {
|
187
|
+
return getUri(parentUri, index) === uri
|
188
|
+
} else {
|
189
|
+
if (hasAnyOf(schema)) {
|
190
|
+
const array = getAnyOf(schema)
|
191
|
+
|
192
|
+
return array.find(findByIndex(parentUri, uri))
|
193
|
+
} else {
|
194
|
+
if (hasOneOf(schema)) {
|
195
|
+
const array = getOneOf(schema)
|
196
|
+
|
197
|
+
return array.find(findByIndex(parentUri, uri))
|
198
|
+
}
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
return getUri(parentUri, index) === uri
|
203
|
+
}
|
204
|
+
}
|
205
|
+
|
206
|
+
export function findByValue (value) {
|
207
|
+
/*
|
208
|
+
* log('findByValue')
|
209
|
+
*/
|
210
|
+
return function find (schema) {
|
211
|
+
/*
|
212
|
+
* log('find')
|
213
|
+
*/
|
214
|
+
return value === transformValue(schema)
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
export function findByEqual (value) {
|
219
|
+
/*
|
220
|
+
* log('findByEqual')
|
221
|
+
*/
|
222
|
+
return function find (schema) {
|
223
|
+
/*
|
224
|
+
* log('find')
|
225
|
+
*/
|
226
|
+
return equal(value, transformValue(schema))
|
227
|
+
}
|
228
|
+
}
|
229
|
+
|
230
|
+
export function toString (value) {
|
231
|
+
/*
|
232
|
+
* log('toString')
|
233
|
+
*/
|
234
|
+
return (value !== undefined) ? String(value) : ''
|
235
|
+
}
|
236
|
+
|
237
|
+
export function getObject ({ properties = {} /* object */ } = {}, parentUri = '', uri = '') {
|
238
|
+
/*
|
239
|
+
* log('getObject')
|
240
|
+
*/
|
241
|
+
return (
|
242
|
+
Reflect.get(properties, (
|
243
|
+
Object.keys(properties)
|
244
|
+
.find(findByKey(parentUri, uri))
|
245
|
+
))
|
246
|
+
)
|
247
|
+
}
|
248
|
+
|
249
|
+
export function getArray ({ items = {} /* array or object */ } = {}, parentUri = '', uri = '') {
|
250
|
+
/*
|
251
|
+
* log('getArray')
|
252
|
+
*/
|
253
|
+
return (isArray(items))
|
254
|
+
? items.find(findByIndex(parentUri, uri))
|
255
|
+
: items
|
256
|
+
}
|
257
|
+
|
258
|
+
export function getSchema (schema = {}, parentUri = '', uri = '') {
|
259
|
+
/*
|
260
|
+
* log('getSchema')
|
261
|
+
*/
|
262
|
+
const { type } = schema
|
263
|
+
|
264
|
+
switch (type) {
|
265
|
+
case 'object':
|
266
|
+
return getObject(schema, parentUri, uri)
|
267
|
+
|
268
|
+
case 'array':
|
269
|
+
return getArray(schema, parentUri, uri)
|
270
|
+
|
271
|
+
default:
|
272
|
+
return schema
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
export function transformValueIndexFor (array, value) {
|
277
|
+
/*
|
278
|
+
* log('transformValueIndexFor')
|
279
|
+
*/
|
280
|
+
const find = findByValue(value)
|
281
|
+
|
282
|
+
if (array.some(find)) {
|
283
|
+
const index = array.findIndex(find)
|
284
|
+
|
285
|
+
/*
|
286
|
+
* Transform a number to a string
|
287
|
+
*/
|
288
|
+
return String(index)
|
289
|
+
}
|
290
|
+
|
291
|
+
/*
|
292
|
+
* Takes the place of `toString(document)` in `transform()`
|
293
|
+
*/
|
294
|
+
return toString(value)
|
295
|
+
}
|
296
|
+
|
297
|
+
export function transformEqualIndexFor (array, value) {
|
298
|
+
/*
|
299
|
+
* log('transformEqualIndexFor')
|
300
|
+
*/
|
301
|
+
const find = findByEqual(value)
|
302
|
+
|
303
|
+
if (array.some(find)) {
|
304
|
+
const index = array.findIndex(find)
|
305
|
+
|
306
|
+
/*
|
307
|
+
* Transform a number to a string
|
308
|
+
*/
|
309
|
+
return String(index)
|
310
|
+
}
|
311
|
+
|
312
|
+
/*
|
313
|
+
* Takes the place of `toString(document)` in `transform()`
|
314
|
+
*/
|
315
|
+
return toString(value)
|
316
|
+
}
|
317
|
+
|
164
318
|
export function hasValue (values = {}, uri = '#', schema = {}) {
|
165
319
|
if (Reflect.has(values, uri)) {
|
166
320
|
const value = Reflect.get(values, uri)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import debug from 'debug'
|
2
|
+
|
3
|
+
import {
|
4
|
+
toString,
|
5
|
+
isArray,
|
6
|
+
getUri
|
7
|
+
} from 'shinkansen-transmission/transmission/common'
|
8
|
+
|
9
|
+
import {
|
10
|
+
transformArray
|
11
|
+
} from 'shinkansen-transmission/transmission/from-document-to-hash'
|
12
|
+
|
13
|
+
const log = debug('shinkansen-transmission/from-document-to-hash/array')
|
14
|
+
|
15
|
+
log('`shinkansen` is awake')
|
16
|
+
|
17
|
+
export default function transformArraySchema (document, schema = {}, values = {}, parentUri = '#', uri = getUri(parentUri)) {
|
18
|
+
log('transformArraySchema')
|
19
|
+
|
20
|
+
/*
|
21
|
+
* Is `document` an array?
|
22
|
+
*/
|
23
|
+
if (isArray(document)) {
|
24
|
+
/*
|
25
|
+
* Yes, `document` is an array
|
26
|
+
*/
|
27
|
+
return transformArray(document, schema, values, parentUri, uri)
|
28
|
+
}
|
29
|
+
|
30
|
+
/*
|
31
|
+
* The hash should contain only strings
|
32
|
+
*/
|
33
|
+
values[uri] = toString(document)
|
34
|
+
|
35
|
+
return values
|
36
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import debug from 'debug'
|
2
|
+
|
3
|
+
import {
|
4
|
+
toString,
|
5
|
+
hasEnum,
|
6
|
+
getEnum,
|
7
|
+
hasAnyOf,
|
8
|
+
getAnyOf,
|
9
|
+
hasOneOf,
|
10
|
+
getOneOf,
|
11
|
+
getUri,
|
12
|
+
transformValueIndexFor
|
13
|
+
} from 'shinkansen-transmission/transmission/common'
|
14
|
+
|
15
|
+
const log = debug('shinkansen-transmission/from-document-to-hash/boolean')
|
16
|
+
|
17
|
+
log('`shinkansen` is awake')
|
18
|
+
|
19
|
+
export default function transformBooleanSchema (document, schema = {}, values = {}, parentUri = '#', uri = getUri(parentUri)) {
|
20
|
+
log('transformBooleanSchema')
|
21
|
+
|
22
|
+
if (hasEnum(schema)) {
|
23
|
+
const items = getEnum(schema)
|
24
|
+
|
25
|
+
values[uri] = transformValueIndexFor(items, document)
|
26
|
+
|
27
|
+
return values
|
28
|
+
} else {
|
29
|
+
if (hasAnyOf(schema)) {
|
30
|
+
const items = getAnyOf(schema)
|
31
|
+
|
32
|
+
values[uri] = transformValueIndexFor(items, document)
|
33
|
+
|
34
|
+
return values
|
35
|
+
} else {
|
36
|
+
if (hasOneOf(schema)) {
|
37
|
+
const items = getOneOf(schema)
|
38
|
+
|
39
|
+
values[uri] = transformValueIndexFor(items, document)
|
40
|
+
|
41
|
+
return values
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
/*
|
47
|
+
* The hash should contain only strings
|
48
|
+
*/
|
49
|
+
values[uri] = toString(document)
|
50
|
+
|
51
|
+
return values
|
52
|
+
}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import debug from 'debug'
|
2
2
|
|
3
|
-
import equal from 'fast-deep-equal'
|
4
|
-
|
5
3
|
import {
|
4
|
+
toString,
|
5
|
+
getSchema,
|
6
6
|
isObject,
|
7
7
|
isArray,
|
8
8
|
hasEnum,
|
@@ -12,6 +12,8 @@ import {
|
|
12
12
|
hasOneOf,
|
13
13
|
getOneOf,
|
14
14
|
getUri,
|
15
|
+
transformValueIndexFor,
|
16
|
+
transformEqualIndexFor,
|
15
17
|
transformValue
|
16
18
|
} from 'shinkansen-transmission/transmission/common'
|
17
19
|
|
@@ -19,163 +21,11 @@ const log = debug('shinkansen-transmission/from-document-to-hash')
|
|
19
21
|
|
20
22
|
log('`shinkansen` is awake')
|
21
23
|
|
22
|
-
function findByKey (parentUri, uri) {
|
23
|
-
/*
|
24
|
-
* log('findByKey')
|
25
|
-
*/
|
26
|
-
return function find (key) {
|
27
|
-
/*
|
28
|
-
* log('find')
|
29
|
-
*/
|
30
|
-
return getUri(parentUri, key) === uri
|
31
|
-
}
|
32
|
-
}
|
33
|
-
|
34
|
-
function findByIndex (parentUri, uri) {
|
35
|
-
/*
|
36
|
-
* log('findByIndex')
|
37
|
-
*/
|
38
|
-
return function find (schema, index) {
|
39
|
-
/*
|
40
|
-
* log('find')
|
41
|
-
*/
|
42
|
-
if (hasEnum(schema)) {
|
43
|
-
return getUri(parentUri, index) === uri
|
44
|
-
} else {
|
45
|
-
if (hasAnyOf(schema)) {
|
46
|
-
const array = getAnyOf(schema)
|
47
|
-
|
48
|
-
return array.find(findByIndex(parentUri, uri))
|
49
|
-
} else {
|
50
|
-
if (hasOneOf(schema)) {
|
51
|
-
const array = getOneOf(schema)
|
52
|
-
|
53
|
-
return array.find(findByIndex(parentUri, uri))
|
54
|
-
}
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
return getUri(parentUri, index) === uri
|
59
|
-
}
|
60
|
-
}
|
61
|
-
|
62
|
-
function findByValue (value) {
|
63
|
-
/*
|
64
|
-
* log('findByValue')
|
65
|
-
*/
|
66
|
-
return function find (schema) {
|
67
|
-
/*
|
68
|
-
* log('find')
|
69
|
-
*/
|
70
|
-
return value === transformValue(schema)
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
function findByEqual (value) {
|
75
|
-
/*
|
76
|
-
* log('findByEqual')
|
77
|
-
*/
|
78
|
-
return function find (schema) {
|
79
|
-
/*
|
80
|
-
* log('find')
|
81
|
-
*/
|
82
|
-
return equal(value, transformValue(schema))
|
83
|
-
}
|
84
|
-
}
|
85
|
-
|
86
|
-
function toString (value) {
|
87
|
-
/*
|
88
|
-
* log('toString')
|
89
|
-
*/
|
90
|
-
return (value !== undefined) ? String(value) : ''
|
91
|
-
}
|
92
|
-
|
93
|
-
export function getObject ({ properties = {} /* object */ } = {}, parentUri = '', uri = '') {
|
94
|
-
/*
|
95
|
-
* log('getObject')
|
96
|
-
*/
|
97
|
-
return (
|
98
|
-
Reflect.get(properties, (
|
99
|
-
Object.keys(properties)
|
100
|
-
.find(findByKey(parentUri, uri))
|
101
|
-
))
|
102
|
-
)
|
103
|
-
}
|
104
|
-
|
105
|
-
export function getArray ({ items = {} /* array or object */ } = {}, parentUri = '', uri = '') {
|
106
|
-
/*
|
107
|
-
* log('getArray')
|
108
|
-
*/
|
109
|
-
return (isArray(items))
|
110
|
-
? items.find(findByIndex(parentUri, uri))
|
111
|
-
: items
|
112
|
-
}
|
113
|
-
|
114
|
-
export function getSchema (schema = {}, parentUri = '', uri = '') {
|
115
|
-
/*
|
116
|
-
* log('getSchema')
|
117
|
-
*/
|
118
|
-
const { type } = schema
|
119
|
-
|
120
|
-
switch (type) {
|
121
|
-
case 'object':
|
122
|
-
return getObject(schema, parentUri, uri)
|
123
|
-
|
124
|
-
case 'array':
|
125
|
-
return getArray(schema, parentUri, uri)
|
126
|
-
|
127
|
-
default:
|
128
|
-
return schema
|
129
|
-
}
|
130
|
-
}
|
131
|
-
|
132
24
|
export {
|
133
25
|
transformValue
|
134
26
|
}
|
135
27
|
|
136
|
-
export function
|
137
|
-
/*
|
138
|
-
* log('transformValueIndexFor')
|
139
|
-
*/
|
140
|
-
const find = findByValue(value)
|
141
|
-
|
142
|
-
if (array.some(find)) {
|
143
|
-
const index = array.findIndex(find)
|
144
|
-
|
145
|
-
/*
|
146
|
-
* Transform a number to a string
|
147
|
-
*/
|
148
|
-
return String(index)
|
149
|
-
}
|
150
|
-
|
151
|
-
/*
|
152
|
-
* Takes the place of `toString(document)` in `transform()`
|
153
|
-
*/
|
154
|
-
return toString(value)
|
155
|
-
}
|
156
|
-
|
157
|
-
export function transformEqualIndexFor (array, value) {
|
158
|
-
/*
|
159
|
-
* log('transformEqualIndexFor')
|
160
|
-
*/
|
161
|
-
const find = findByEqual(value)
|
162
|
-
|
163
|
-
if (array.some(find)) {
|
164
|
-
const index = array.findIndex(find)
|
165
|
-
|
166
|
-
/*
|
167
|
-
* Transform a number to a string
|
168
|
-
*/
|
169
|
-
return String(index)
|
170
|
-
}
|
171
|
-
|
172
|
-
/*
|
173
|
-
* Takes the place of `toString(document)` in `transform()`
|
174
|
-
*/
|
175
|
-
return toString(value)
|
176
|
-
}
|
177
|
-
|
178
|
-
export function transformArrayFor (document, schema, values, params, parentUri, uri) {
|
28
|
+
export function transformArrayFor (document, schema, values, parentUri) { // }, uri) {
|
179
29
|
/*
|
180
30
|
* log('transformArrayFor')
|
181
31
|
*/
|
@@ -184,12 +34,12 @@ export function transformArrayFor (document, schema, values, params, parentUri,
|
|
184
34
|
.reduce((values, value, index) => {
|
185
35
|
const schemaUri = getUri(parentUri, index)
|
186
36
|
|
187
|
-
return transform(value, getSchema(schema, parentUri, schemaUri), values,
|
37
|
+
return transform(value, getSchema(schema, parentUri, schemaUri), values, schemaUri, schemaUri)
|
188
38
|
}, values)
|
189
39
|
)
|
190
40
|
}
|
191
41
|
|
192
|
-
export function transformObjectFor (document, schema, values,
|
42
|
+
export function transformObjectFor (document, schema, values, parentUri) { // }, uri) {
|
193
43
|
/*
|
194
44
|
* log('transformObjectFor')
|
195
45
|
*/
|
@@ -198,12 +48,12 @@ export function transformObjectFor (document, schema, values, params, parentUri,
|
|
198
48
|
.reduce((values, [key, value]) => {
|
199
49
|
const schemaUri = getUri(parentUri, key)
|
200
50
|
|
201
|
-
return transform(value, getSchema(schema, parentUri, schemaUri), values,
|
51
|
+
return transform(value, getSchema(schema, parentUri, schemaUri), values, schemaUri, schemaUri)
|
202
52
|
}, values)
|
203
53
|
)
|
204
54
|
}
|
205
55
|
|
206
|
-
export function transformArray (document, schema, values,
|
56
|
+
export function transformArray (document, schema, values, parentUri, uri) {
|
207
57
|
/*
|
208
58
|
* log('transformArray')
|
209
59
|
*/
|
@@ -235,7 +85,7 @@ export function transformArray (document, schema, values, params, parentUri, uri
|
|
235
85
|
/*
|
236
86
|
* Items is an array of schemas
|
237
87
|
*/
|
238
|
-
return transformArrayFor(document, schema, values,
|
88
|
+
return transformArrayFor(document, schema, values, parentUri, uri)
|
239
89
|
} else {
|
240
90
|
if (isObject(items)) {
|
241
91
|
/*
|
@@ -273,10 +123,10 @@ export function transformArray (document, schema, values, params, parentUri, uri
|
|
273
123
|
/*
|
274
124
|
* Transform schema
|
275
125
|
*/
|
276
|
-
return transformArrayFor(document, schema, values,
|
126
|
+
return transformArrayFor(document, schema, values, parentUri, uri) // schema not items
|
277
127
|
}
|
278
128
|
|
279
|
-
export function transformObject (document, schema, values,
|
129
|
+
export function transformObject (document, schema, values, parentUri, uri) {
|
280
130
|
/*
|
281
131
|
* log('transformObject')
|
282
132
|
*/
|
@@ -308,10 +158,10 @@ export function transformObject (document, schema, values, params, parentUri, ur
|
|
308
158
|
/*
|
309
159
|
* Transform schema
|
310
160
|
*/
|
311
|
-
return transformObjectFor(document, schema, values,
|
161
|
+
return transformObjectFor(document, schema, values, parentUri) // , uri)
|
312
162
|
}
|
313
163
|
|
314
|
-
export default function transform (document, schema = {}, values = {},
|
164
|
+
export default function transform (document, schema = {}, values = {}, parentUri = '#', uri = getUri(parentUri)) {
|
315
165
|
log('fromDocumentToHash')
|
316
166
|
|
317
167
|
/*
|
@@ -321,7 +171,7 @@ export default function transform (document, schema = {}, values = {}, params =
|
|
321
171
|
/*
|
322
172
|
* Yes, `document` is an array
|
323
173
|
*/
|
324
|
-
return transformArray(document, schema, values,
|
174
|
+
return transformArray(document, schema, values, parentUri, uri)
|
325
175
|
} else {
|
326
176
|
/*
|
327
177
|
* Is `document` an object?
|
@@ -330,7 +180,7 @@ export default function transform (document, schema = {}, values = {}, params =
|
|
330
180
|
/*
|
331
181
|
* Yes, `document` is an object
|
332
182
|
*/
|
333
|
-
return transformObject(document, schema, values,
|
183
|
+
return transformObject(document, schema, values, parentUri, uri)
|
334
184
|
} else {
|
335
185
|
if (hasEnum(schema)) {
|
336
186
|
const items = getEnum(schema)
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import debug from 'debug'
|
2
|
+
|
3
|
+
import {
|
4
|
+
toString,
|
5
|
+
hasEnum,
|
6
|
+
getEnum,
|
7
|
+
hasAnyOf,
|
8
|
+
getAnyOf,
|
9
|
+
hasOneOf,
|
10
|
+
getOneOf,
|
11
|
+
getUri,
|
12
|
+
transformValueIndexFor
|
13
|
+
} from 'shinkansen-transmission/transmission/common'
|
14
|
+
|
15
|
+
const log = debug('shinkansen-transmission/from-document-to-hash/null')
|
16
|
+
|
17
|
+
log('`shinkansen` is awake')
|
18
|
+
|
19
|
+
export default function transformNullSchema (document, schema = {}, values = {}, parentUri = '#', uri = getUri(parentUri)) {
|
20
|
+
log('transformNullSchema')
|
21
|
+
|
22
|
+
if (hasEnum(schema)) {
|
23
|
+
const items = getEnum(schema)
|
24
|
+
|
25
|
+
values[uri] = transformValueIndexFor(items, document)
|
26
|
+
|
27
|
+
return values
|
28
|
+
} else {
|
29
|
+
if (hasAnyOf(schema)) {
|
30
|
+
const items = getAnyOf(schema)
|
31
|
+
|
32
|
+
values[uri] = transformValueIndexFor(items, document)
|
33
|
+
|
34
|
+
return values
|
35
|
+
} else {
|
36
|
+
if (hasOneOf(schema)) {
|
37
|
+
const items = getOneOf(schema)
|
38
|
+
|
39
|
+
values[uri] = transformValueIndexFor(items, document)
|
40
|
+
|
41
|
+
return values
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
/*
|
47
|
+
* The hash should contain only strings
|
48
|
+
*/
|
49
|
+
values[uri] = toString(document)
|
50
|
+
|
51
|
+
return values
|
52
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import debug from 'debug'
|
2
|
+
|
3
|
+
import {
|
4
|
+
toString,
|
5
|
+
hasEnum,
|
6
|
+
getEnum,
|
7
|
+
hasAnyOf,
|
8
|
+
getAnyOf,
|
9
|
+
hasOneOf,
|
10
|
+
getOneOf,
|
11
|
+
getUri,
|
12
|
+
transformValueIndexFor
|
13
|
+
} from 'shinkansen-transmission/transmission/common'
|
14
|
+
|
15
|
+
const log = debug('shinkansen-transmission/from-document-to-hash/number')
|
16
|
+
|
17
|
+
log('`shinkansen` is awake')
|
18
|
+
|
19
|
+
export default function transformNumberSchema (document, schema = {}, values = {}, parentUri = '#', uri = getUri(parentUri)) {
|
20
|
+
log('transformNumberSchema')
|
21
|
+
|
22
|
+
if (hasEnum(schema)) {
|
23
|
+
const items = getEnum(schema)
|
24
|
+
|
25
|
+
values[uri] = transformValueIndexFor(items, document)
|
26
|
+
|
27
|
+
return values
|
28
|
+
} else {
|
29
|
+
if (hasAnyOf(schema)) {
|
30
|
+
const items = getAnyOf(schema)
|
31
|
+
|
32
|
+
values[uri] = transformValueIndexFor(items, document)
|
33
|
+
|
34
|
+
return values
|
35
|
+
} else {
|
36
|
+
if (hasOneOf(schema)) {
|
37
|
+
const items = getOneOf(schema)
|
38
|
+
|
39
|
+
values[uri] = transformValueIndexFor(items, document)
|
40
|
+
|
41
|
+
return values
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
/*
|
47
|
+
* The hash should contain only strings
|
48
|
+
*/
|
49
|
+
values[uri] = toString(document)
|
50
|
+
|
51
|
+
return values
|
52
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import debug from 'debug'
|
2
|
+
|
3
|
+
import {
|
4
|
+
toString,
|
5
|
+
isObject,
|
6
|
+
getUri
|
7
|
+
} from 'shinkansen-transmission/transmission/common'
|
8
|
+
|
9
|
+
import {
|
10
|
+
transformObject
|
11
|
+
} from 'shinkansen-transmission/transmission/from-document-to-hash'
|
12
|
+
|
13
|
+
const log = debug('shinkansen-transmission/from-document-to-hash/object')
|
14
|
+
|
15
|
+
log('`shinkansen` is awake')
|
16
|
+
|
17
|
+
export default function transformObjectSchema (document, schema = {}, values = {}, parentUri = '#', uri = getUri(parentUri)) {
|
18
|
+
log('transformObjectSchema')
|
19
|
+
|
20
|
+
/*
|
21
|
+
* Is `document` an object?
|
22
|
+
*/
|
23
|
+
if (isObject(document)) {
|
24
|
+
/*
|
25
|
+
* Yes, `document` is an object
|
26
|
+
*/
|
27
|
+
return transformObject(document, schema, values, parentUri, uri)
|
28
|
+
}
|
29
|
+
|
30
|
+
/*
|
31
|
+
* The hash should contain only strings
|
32
|
+
*/
|
33
|
+
values[uri] = toString(document)
|
34
|
+
|
35
|
+
return values
|
36
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import debug from 'debug'
|
2
|
+
|
3
|
+
import {
|
4
|
+
toString,
|
5
|
+
hasEnum,
|
6
|
+
getEnum,
|
7
|
+
hasAnyOf,
|
8
|
+
getAnyOf,
|
9
|
+
hasOneOf,
|
10
|
+
getOneOf,
|
11
|
+
getUri,
|
12
|
+
transformValueIndexFor
|
13
|
+
} from 'shinkansen-transmission/transmission/common'
|
14
|
+
|
15
|
+
const log = debug('shinkansen-transmission/from-document-to-hash/string')
|
16
|
+
|
17
|
+
log('`shinkansen` is awake')
|
18
|
+
|
19
|
+
export default function transformStringSchema (document, schema = {}, values = {}, parentUri = '#', uri = getUri(parentUri)) {
|
20
|
+
log('transformStringSchema')
|
21
|
+
|
22
|
+
if (hasEnum(schema)) {
|
23
|
+
const items = getEnum(schema)
|
24
|
+
|
25
|
+
values[uri] = transformValueIndexFor(items, document)
|
26
|
+
|
27
|
+
return values
|
28
|
+
} else {
|
29
|
+
if (hasAnyOf(schema)) {
|
30
|
+
const items = getAnyOf(schema)
|
31
|
+
|
32
|
+
values[uri] = transformValueIndexFor(items, document)
|
33
|
+
|
34
|
+
return values
|
35
|
+
} else {
|
36
|
+
if (hasOneOf(schema)) {
|
37
|
+
const items = getOneOf(schema)
|
38
|
+
|
39
|
+
values[uri] = transformValueIndexFor(items, document)
|
40
|
+
|
41
|
+
return values
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
/*
|
47
|
+
* The hash should contain only strings
|
48
|
+
*/
|
49
|
+
values[uri] = toString(document)
|
50
|
+
|
51
|
+
return values
|
52
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import debug from 'debug'
|
2
|
+
|
3
|
+
import {
|
4
|
+
getUri
|
5
|
+
} from 'shinkansen-transmission/transmission/common'
|
6
|
+
|
7
|
+
import {
|
8
|
+
transformArray
|
9
|
+
} from 'shinkansen-transmission/transmission/from-hash-to-document'
|
10
|
+
|
11
|
+
const log = debug('shinkansen-transmission/from-hash-to-document/array')
|
12
|
+
|
13
|
+
log('`shinkansen` is awake')
|
14
|
+
|
15
|
+
export default function transformArraySchema (values = {}, schema = {}, params = {}) {
|
16
|
+
log('transformArraySchema')
|
17
|
+
|
18
|
+
const { type } = schema
|
19
|
+
|
20
|
+
// https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.2.1
|
21
|
+
if (type === 'array') {
|
22
|
+
const {
|
23
|
+
uri: parentUri,
|
24
|
+
index: arrayIndex
|
25
|
+
} = params
|
26
|
+
|
27
|
+
return transformArray(values, schema, parentUri, getUri(parentUri, arrayIndex))
|
28
|
+
}
|
29
|
+
|
30
|
+
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')
|
31
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import debug from 'debug'
|
2
|
+
|
3
|
+
import {
|
4
|
+
getUri
|
5
|
+
} from 'shinkansen-transmission/transmission/common'
|
6
|
+
|
7
|
+
import {
|
8
|
+
transformBoolean
|
9
|
+
} from 'shinkansen-transmission/transmission/from-hash-to-document'
|
10
|
+
|
11
|
+
const log = debug('shinkansen-transmission/from-hash-to-document/boolean')
|
12
|
+
|
13
|
+
log('`shinkansen` is awake')
|
14
|
+
|
15
|
+
export default function transformBooleanSchema (values = {}, schema = {}, params = {}) {
|
16
|
+
log('transformBooleanSchema')
|
17
|
+
|
18
|
+
const { type } = schema
|
19
|
+
|
20
|
+
// https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.2.1
|
21
|
+
if (type === 'boolean') {
|
22
|
+
const {
|
23
|
+
uri: parentUri
|
24
|
+
} = params
|
25
|
+
|
26
|
+
return transformBoolean(values, schema, parentUri, getUri(parentUri))
|
27
|
+
}
|
28
|
+
|
29
|
+
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')
|
30
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import debug from 'debug'
|
2
|
+
|
3
|
+
import {
|
4
|
+
getUri
|
5
|
+
} from 'shinkansen-transmission/transmission/common'
|
6
|
+
|
7
|
+
import {
|
8
|
+
transformNull
|
9
|
+
} from 'shinkansen-transmission/transmission/from-hash-to-document'
|
10
|
+
|
11
|
+
const log = debug('shinkansen-transmission/from-hash-to-document/null')
|
12
|
+
|
13
|
+
log('`shinkansen` is awake')
|
14
|
+
|
15
|
+
export default function transformNullSchema (values = {}, schema = {}, params = {}) {
|
16
|
+
log('transformNullSchema')
|
17
|
+
|
18
|
+
const { type } = schema
|
19
|
+
|
20
|
+
// https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.2.1
|
21
|
+
if (type === 'null') {
|
22
|
+
const {
|
23
|
+
uri: parentUri
|
24
|
+
} = params
|
25
|
+
|
26
|
+
return transformNull(values, schema, parentUri, getUri(parentUri))
|
27
|
+
}
|
28
|
+
|
29
|
+
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')
|
30
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import debug from 'debug'
|
2
|
+
|
3
|
+
import {
|
4
|
+
getUri
|
5
|
+
} from 'shinkansen-transmission/transmission/common'
|
6
|
+
|
7
|
+
import {
|
8
|
+
transformNumber
|
9
|
+
} from 'shinkansen-transmission/transmission/from-hash-to-document'
|
10
|
+
|
11
|
+
const log = debug('shinkansen-transmission/from-hash-to-document/number')
|
12
|
+
|
13
|
+
log('`shinkansen` is awake')
|
14
|
+
|
15
|
+
export default function transformNumberSchema (values = {}, schema = {}, params = {}) {
|
16
|
+
log('transformNumberSchema')
|
17
|
+
|
18
|
+
const { type } = schema
|
19
|
+
|
20
|
+
// https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.2.1
|
21
|
+
if (type === 'number') {
|
22
|
+
const {
|
23
|
+
uri: parentUri
|
24
|
+
} = params
|
25
|
+
|
26
|
+
return transformNumber(values, schema, parentUri, getUri(parentUri))
|
27
|
+
}
|
28
|
+
|
29
|
+
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')
|
30
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import debug from 'debug'
|
2
|
+
|
3
|
+
import {
|
4
|
+
getUri
|
5
|
+
} from 'shinkansen-transmission/transmission/common'
|
6
|
+
|
7
|
+
import {
|
8
|
+
transformObject
|
9
|
+
} from 'shinkansen-transmission/transmission/from-hash-to-document'
|
10
|
+
|
11
|
+
const log = debug('shinkansen-transmission/from-hash-to-document/object')
|
12
|
+
|
13
|
+
log('`shinkansen` is awake')
|
14
|
+
|
15
|
+
export default function transformObjectSchema (values = {}, schema = {}, params = {}) {
|
16
|
+
log('transformObjectSchema')
|
17
|
+
|
18
|
+
const { type } = schema
|
19
|
+
|
20
|
+
// https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.2.1
|
21
|
+
if (type === 'object') {
|
22
|
+
const {
|
23
|
+
uri: parentUri,
|
24
|
+
key: fieldKey
|
25
|
+
} = params
|
26
|
+
|
27
|
+
return transformObject(values, schema, parentUri, getUri(parentUri, fieldKey))
|
28
|
+
}
|
29
|
+
|
30
|
+
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')
|
31
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import debug from 'debug'
|
2
|
+
|
3
|
+
import {
|
4
|
+
getUri
|
5
|
+
} from 'shinkansen-transmission/transmission/common'
|
6
|
+
|
7
|
+
import {
|
8
|
+
transformString
|
9
|
+
} from 'shinkansen-transmission/transmission/from-hash-to-document'
|
10
|
+
|
11
|
+
const log = debug('shinkansen-transmission/from-hash-to-document/string')
|
12
|
+
|
13
|
+
log('`shinkansen` is awake')
|
14
|
+
|
15
|
+
export default function transformStringSchema (values = {}, schema = {}, params = {}) {
|
16
|
+
log('transformStringSchema')
|
17
|
+
|
18
|
+
const { type } = schema
|
19
|
+
|
20
|
+
// https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.2.1
|
21
|
+
if (type === 'string') {
|
22
|
+
const {
|
23
|
+
uri: parentUri
|
24
|
+
} = params
|
25
|
+
|
26
|
+
return transformString(values, schema, parentUri, getUri(parentUri))
|
27
|
+
}
|
28
|
+
|
29
|
+
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')
|
30
|
+
}
|
@@ -1,102 +0,0 @@
|
|
1
|
-
import debug from 'debug'
|
2
|
-
|
3
|
-
import {
|
4
|
-
getUri
|
5
|
-
} from 'shinkansen-transmission/transmission/common'
|
6
|
-
|
7
|
-
import {
|
8
|
-
transformNull,
|
9
|
-
transformBoolean,
|
10
|
-
transformObject,
|
11
|
-
transformArray,
|
12
|
-
transformNumber,
|
13
|
-
transformString
|
14
|
-
} from 'shinkansen-transmission/transmission/from-hash-to-document'
|
15
|
-
|
16
|
-
const log = debug('shinkansen-transmission/from-hash-to-document/transform-array-schema')
|
17
|
-
|
18
|
-
log('`shinkansen` is awake')
|
19
|
-
|
20
|
-
// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6
|
21
|
-
export function transformArraySchemaNull (values, schema, { uri: parentUri, index: arrayIndex }, uri = getUri(parentUri, arrayIndex)) {
|
22
|
-
/*
|
23
|
-
* log('transformArraySchemaNull')
|
24
|
-
*/
|
25
|
-
|
26
|
-
return transformNull(values, schema, parentUri, uri)
|
27
|
-
}
|
28
|
-
|
29
|
-
// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6
|
30
|
-
export function transformArraySchemaBoolean (values, schema, { uri: parentUri, index: arrayIndex }, uri = getUri(parentUri, arrayIndex)) {
|
31
|
-
/*
|
32
|
-
* log('transformArraySchemaBoolean')
|
33
|
-
*/
|
34
|
-
|
35
|
-
return transformBoolean(values, schema, parentUri, uri)
|
36
|
-
}
|
37
|
-
|
38
|
-
// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.5
|
39
|
-
export function transformArraySchemaObject (values, schema, { uri: parentUri, index: arrayIndex }, uri = getUri(parentUri, arrayIndex)) {
|
40
|
-
/*
|
41
|
-
* log('transformArraySchemaObject')
|
42
|
-
*/
|
43
|
-
|
44
|
-
return transformObject(values, schema, uri, uri) // uri is parentUri and uri
|
45
|
-
}
|
46
|
-
|
47
|
-
// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.4
|
48
|
-
export function transformArraySchemaArray (values, schema, { uri: parentUri, index: arrayIndex }, uri = getUri(parentUri, arrayIndex)) {
|
49
|
-
/*
|
50
|
-
* log('transformArraySchemaArray')
|
51
|
-
*/
|
52
|
-
|
53
|
-
return transformArray(values, schema, uri, uri) // uri is parentUri and uri
|
54
|
-
}
|
55
|
-
|
56
|
-
// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.2
|
57
|
-
export function transformArraySchemaNumber (values, schema, { uri: parentUri, index: arrayIndex }, uri = getUri(parentUri, arrayIndex)) {
|
58
|
-
/*
|
59
|
-
* log('transformArraySchemaNumber')
|
60
|
-
*/
|
61
|
-
|
62
|
-
return transformNumber(values, schema, parentUri, uri)
|
63
|
-
}
|
64
|
-
|
65
|
-
// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.3
|
66
|
-
export function transformArraySchemaString (values, schema, { uri: parentUri, index: arrayIndex }, uri = getUri(parentUri, arrayIndex)) {
|
67
|
-
/*
|
68
|
-
* log('transformArraySchemaString')
|
69
|
-
*/
|
70
|
-
|
71
|
-
return transformString(values, schema, parentUri, uri)
|
72
|
-
}
|
73
|
-
|
74
|
-
export default function transformArraySchema (values = {}, schema = {}, params = {}) {
|
75
|
-
log('transformArraySchema')
|
76
|
-
|
77
|
-
const { type } = schema
|
78
|
-
|
79
|
-
// https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.2.1
|
80
|
-
switch (type) {
|
81
|
-
case 'null':
|
82
|
-
return transformArraySchemaNull(values, schema, params)
|
83
|
-
|
84
|
-
case 'boolean':
|
85
|
-
return transformArraySchemaBoolean(values, schema, params)
|
86
|
-
|
87
|
-
case 'object':
|
88
|
-
return transformArraySchemaObject(values, schema, params)
|
89
|
-
|
90
|
-
case 'array':
|
91
|
-
return transformArraySchemaArray(values, schema, params)
|
92
|
-
|
93
|
-
case 'number':
|
94
|
-
return transformArraySchemaNumber(values, schema, params)
|
95
|
-
|
96
|
-
case 'string':
|
97
|
-
return transformArraySchemaString(values, schema, params)
|
98
|
-
|
99
|
-
default:
|
100
|
-
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')
|
101
|
-
}
|
102
|
-
}
|
@@ -1,102 +0,0 @@
|
|
1
|
-
import debug from 'debug'
|
2
|
-
|
3
|
-
import {
|
4
|
-
getUri
|
5
|
-
} from 'shinkansen-transmission/transmission/common'
|
6
|
-
|
7
|
-
import {
|
8
|
-
transformNull,
|
9
|
-
transformBoolean,
|
10
|
-
transformObject,
|
11
|
-
transformArray,
|
12
|
-
transformNumber,
|
13
|
-
transformString
|
14
|
-
} from 'shinkansen-transmission/transmission/from-hash-to-document'
|
15
|
-
|
16
|
-
const log = debug('shinkansen-transmission/from-hash-to-document/transform-object-schema')
|
17
|
-
|
18
|
-
log('`shinkansen` is awake')
|
19
|
-
|
20
|
-
// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6
|
21
|
-
export function transformObjectSchemaNull (values, schema, { uri: parentUri, key: fieldKey }, uri = getUri(parentUri, fieldKey)) {
|
22
|
-
/*
|
23
|
-
* log('transformObjectSchemaNull')
|
24
|
-
*/
|
25
|
-
|
26
|
-
return transformNull(values, schema, parentUri, uri)
|
27
|
-
}
|
28
|
-
|
29
|
-
// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6
|
30
|
-
export function transformObjectSchemaBoolean (values, schema, { uri: parentUri, key: fieldKey }, uri = getUri(parentUri, fieldKey)) {
|
31
|
-
/*
|
32
|
-
* log('transformObjectSchemaBoolean')
|
33
|
-
*/
|
34
|
-
|
35
|
-
return transformBoolean(values, schema, parentUri, uri)
|
36
|
-
}
|
37
|
-
|
38
|
-
// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.5
|
39
|
-
export function transformObjectSchemaObject (values, schema, { uri: parentUri, key: fieldKey }, uri = getUri(parentUri, fieldKey)) {
|
40
|
-
/*
|
41
|
-
* log('transformObjectSchemaObject')
|
42
|
-
*/
|
43
|
-
|
44
|
-
return transformObject(values, schema, uri, uri) // uri is parentUri and uri
|
45
|
-
}
|
46
|
-
|
47
|
-
// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.4
|
48
|
-
export function transformObjectSchemaArray (values, schema, { uri: parentUri, key: fieldKey }, uri = getUri(parentUri, fieldKey)) {
|
49
|
-
/*
|
50
|
-
* log('transformObjectSchemaArray')
|
51
|
-
*/
|
52
|
-
|
53
|
-
return transformArray(values, schema, uri, uri) // uri is parentUri and uri
|
54
|
-
}
|
55
|
-
|
56
|
-
// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.2
|
57
|
-
export function transformObjectSchemaNumber (values, schema, { uri: parentUri, key: fieldKey }, uri = getUri(parentUri, fieldKey)) {
|
58
|
-
/*
|
59
|
-
* log('transformObjectSchemaNumber')
|
60
|
-
*/
|
61
|
-
|
62
|
-
return transformNumber(values, schema, parentUri, uri)
|
63
|
-
}
|
64
|
-
|
65
|
-
// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.3
|
66
|
-
export function transformObjectSchemaString (values, schema, { uri: parentUri, key: fieldKey }, uri = getUri(parentUri, fieldKey)) {
|
67
|
-
/*
|
68
|
-
* log('transformObjectSchemaString')
|
69
|
-
*/
|
70
|
-
|
71
|
-
return transformString(values, schema, parentUri, uri)
|
72
|
-
}
|
73
|
-
|
74
|
-
export default function transformObjectSchema (values = {}, schema = {}, params = {}) {
|
75
|
-
log('transformObjectSchema')
|
76
|
-
|
77
|
-
const { type } = schema
|
78
|
-
|
79
|
-
// https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.2.1
|
80
|
-
switch (type) {
|
81
|
-
case 'null':
|
82
|
-
return transformObjectSchemaNull(values, schema, params)
|
83
|
-
|
84
|
-
case 'boolean':
|
85
|
-
return transformObjectSchemaBoolean(values, schema, params)
|
86
|
-
|
87
|
-
case 'object':
|
88
|
-
return transformObjectSchemaObject(values, schema, params)
|
89
|
-
|
90
|
-
case 'array':
|
91
|
-
return transformObjectSchemaArray(values, schema, params)
|
92
|
-
|
93
|
-
case 'number':
|
94
|
-
return transformObjectSchemaNumber(values, schema, params)
|
95
|
-
|
96
|
-
case 'string':
|
97
|
-
return transformObjectSchemaString(values, schema, params)
|
98
|
-
|
99
|
-
default:
|
100
|
-
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')
|
101
|
-
}
|
102
|
-
}
|