shinkansen-transmission 2.3.6 → 2.4.0
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 +22 -22
- package/package.json +1 -1
- package/src/transmission/common/index.d.mts +30 -38
- package/src/transmission/common/index.mjs +76 -196
- package/src/transmission/common/transform/index.d.mts +18 -0
- package/src/transmission/common/transform/index.mjs +128 -0
- package/src/transmission/from-document-to-hash/array/index.d.mts +1 -0
- package/src/transmission/from-document-to-hash/array/index.mjs +1 -46
- package/src/transmission/from-document-to-hash/boolean/index.d.mts +5 -0
- package/src/transmission/from-document-to-hash/boolean/index.mjs +7 -7
- package/src/transmission/from-document-to-hash/index.d.mts +10 -3
- package/src/transmission/from-document-to-hash/index.mjs +121 -60
- package/src/transmission/from-document-to-hash/null/index.d.mts +5 -0
- package/src/transmission/from-document-to-hash/null/index.mjs +7 -7
- package/src/transmission/from-document-to-hash/number/index.d.mts +5 -0
- package/src/transmission/from-document-to-hash/number/index.mjs +7 -7
- package/src/transmission/from-document-to-hash/object/index.d.mts +1 -0
- package/src/transmission/from-document-to-hash/object/index.mjs +1 -46
- package/src/transmission/from-document-to-hash/string/index.d.mts +5 -0
- package/src/transmission/from-document-to-hash/string/index.mjs +8 -8
- package/src/transmission/from-hash-to-document/array/index.d.mts +4 -0
- package/src/transmission/from-hash-to-document/array/index.mjs +4 -42
- package/src/transmission/from-hash-to-document/boolean/index.d.mts +8 -0
- package/src/transmission/from-hash-to-document/boolean/index.mjs +84 -3
- package/src/transmission/from-hash-to-document/index.d.mts +28 -21
- package/src/transmission/from-hash-to-document/index.mjs +184 -352
- package/src/transmission/from-hash-to-document/null/index.d.mts +8 -0
- package/src/transmission/from-hash-to-document/null/index.mjs +84 -3
- package/src/transmission/from-hash-to-document/number/index.d.mts +8 -0
- package/src/transmission/from-hash-to-document/number/index.mjs +84 -3
- package/src/transmission/from-hash-to-document/object/index.d.mts +4 -0
- package/src/transmission/from-hash-to-document/object/index.mjs +4 -42
- package/src/transmission/from-hash-to-document/string/index.d.mts +8 -0
- package/src/transmission/from-hash-to-document/string/index.mjs +85 -4
@@ -0,0 +1,18 @@
|
|
1
|
+
type MemberArrayType = TransmissionTypes.MemberArrayType
|
2
|
+
type MemberType = TransmissionTypes.MemberType
|
3
|
+
|
4
|
+
type HashType = TransmissionTypes.HashType
|
5
|
+
type SchemaType = TransmissionTypes.SchemaType
|
6
|
+
type ParamsType = TransmissionTypes.ParamsType
|
7
|
+
type DocumentType = TransmissionTypes.DocumentType
|
8
|
+
|
9
|
+
export function toString (v: unknown) : string
|
10
|
+
export function toNumber (v: unknown): number
|
11
|
+
export function toBoolean (v: unknown) : boolean
|
12
|
+
export function toNull (v: unknown): null
|
13
|
+
|
14
|
+
export function mapToValue (array: MemberArrayType): (document: DocumentType | undefined) => MemberType | undefined
|
15
|
+
|
16
|
+
export function fromDocumentToArray (document: DocumentType | undefined, array: MemberArrayType) : MemberType
|
17
|
+
|
18
|
+
export function fromHashToArray (hash: HashType, uri: string, array: MemberArrayType): MemberType
|
@@ -0,0 +1,128 @@
|
|
1
|
+
/**
|
2
|
+
* @typedef {TransmissionTypes.MemberArrayType} MemberArrayType
|
3
|
+
* @typedef {TransmissionTypes.MemberType} MemberType
|
4
|
+
*
|
5
|
+
* @typedef {TransmissionTypes.HashType} HashType
|
6
|
+
* @typedef {TransmissionTypes.SchemaType} SchemaType
|
7
|
+
* @typedef {TransmissionTypes.ParamsType} ParamsType
|
8
|
+
* @typedef {TransmissionTypes.DocumentType} DocumentType
|
9
|
+
*/
|
10
|
+
|
11
|
+
import {
|
12
|
+
isPrimitive,
|
13
|
+
transformToValue
|
14
|
+
} from '#transmission/transmission/common'
|
15
|
+
|
16
|
+
/**
|
17
|
+
* @param {unknown} v
|
18
|
+
* @returns {string}
|
19
|
+
*/
|
20
|
+
export function toString (v) {
|
21
|
+
if (typeof v === 'string') return v
|
22
|
+
if (typeof v === 'number') return String(v)
|
23
|
+
|
24
|
+
return JSON.stringify(v)
|
25
|
+
}
|
26
|
+
|
27
|
+
/**
|
28
|
+
* @param {unknown} v
|
29
|
+
* @returns {number}
|
30
|
+
*/
|
31
|
+
export function toNumber (v) {
|
32
|
+
if (typeof v === 'number') return v
|
33
|
+
if (typeof v === 'boolean') return Number(v)
|
34
|
+
|
35
|
+
if (v) { // excludes zero-length strings
|
36
|
+
const n = (
|
37
|
+
isPrimitive(v) // excludes objects and arrays
|
38
|
+
? Number(v) // +v // unary operator
|
39
|
+
: NaN
|
40
|
+
)
|
41
|
+
|
42
|
+
if (!isNaN(n)) return n
|
43
|
+
}
|
44
|
+
|
45
|
+
throw new Error('Invalid `number`')
|
46
|
+
}
|
47
|
+
|
48
|
+
/**
|
49
|
+
* @param {unknown} v
|
50
|
+
* @returns {boolean}
|
51
|
+
*/
|
52
|
+
export function toBoolean (v) {
|
53
|
+
if (typeof v === 'boolean') return v
|
54
|
+
if (v === 'true') return true
|
55
|
+
if (v === 'false') return false
|
56
|
+
|
57
|
+
throw new Error('Invalid `boolean`')
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* @param {unknown} v
|
62
|
+
* @returns {null}
|
63
|
+
*/
|
64
|
+
export function toNull (v) {
|
65
|
+
if (v === null || v === 'null') return null
|
66
|
+
|
67
|
+
throw new Error('Invalid `null`')
|
68
|
+
}
|
69
|
+
|
70
|
+
/**
|
71
|
+
* @param {MemberArrayType} array
|
72
|
+
* @returns {(document: DocumentType | undefined) => MemberType | undefined}
|
73
|
+
*/
|
74
|
+
export function mapToValue (array) {
|
75
|
+
/**
|
76
|
+
* @param {DocumentType | undefined} document
|
77
|
+
* @returns {MemberType | undefined}
|
78
|
+
*/
|
79
|
+
return function toValue (document) {
|
80
|
+
return (
|
81
|
+
transformToValue(
|
82
|
+
fromDocumentToArray(document, array)
|
83
|
+
)
|
84
|
+
)
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
/**
|
89
|
+
* @param {DocumentType | undefined} document
|
90
|
+
* @param {MemberArrayType} array
|
91
|
+
* @returns {MemberType}
|
92
|
+
*/
|
93
|
+
export function fromDocumentToArray (document, array) {
|
94
|
+
/*
|
95
|
+
* log('fromDocumentToArray')
|
96
|
+
*/
|
97
|
+
|
98
|
+
const i = Number(document)
|
99
|
+
|
100
|
+
/*
|
101
|
+
* Return the the schema at `i`
|
102
|
+
*/
|
103
|
+
if (!isNaN(i)) return array[i]
|
104
|
+
|
105
|
+
throw new Error('Invalid `document`')
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* @param {HashType} hash
|
110
|
+
* @param {string} uri
|
111
|
+
* @param {MemberArrayType} array
|
112
|
+
* @returns {MemberType}
|
113
|
+
*/
|
114
|
+
export function fromHashToArray (hash, uri, array) {
|
115
|
+
/*
|
116
|
+
* log('fromHashToArray')
|
117
|
+
*/
|
118
|
+
|
119
|
+
const v = hash[uri]
|
120
|
+
const i = Number(v)
|
121
|
+
|
122
|
+
/*
|
123
|
+
* Return the the schema at `i`
|
124
|
+
*/
|
125
|
+
if (!isNaN(i)) return array[i]
|
126
|
+
|
127
|
+
throw new Error('Invalid `hash`')
|
128
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export { transformArraySchema as default } from '#transmission/transmission/from-document-to-hash'
|
@@ -1,52 +1,7 @@
|
|
1
|
-
/**
|
2
|
-
* @typedef {TransmissionTypes.DocumentType} DocumentType
|
3
|
-
* @typedef {TransmissionTypes.SchemaType} SchemaType
|
4
|
-
* @typedef {TransmissionTypes.HashType} HashType
|
5
|
-
*/
|
6
|
-
|
7
1
|
import debug from 'debug'
|
8
2
|
|
9
|
-
import {
|
10
|
-
toString,
|
11
|
-
isArray,
|
12
|
-
getUri
|
13
|
-
} from '#transmission/transmission/common'
|
14
|
-
|
15
|
-
import {
|
16
|
-
transformArray
|
17
|
-
} from '#transmission/transmission/from-document-to-hash'
|
18
|
-
|
19
3
|
const log = debug('shinkansen-transmission/from-document-to-hash/array')
|
20
4
|
|
21
5
|
log('`shinkansen` is awake')
|
22
6
|
|
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)) {
|
34
|
-
log('transformArraySchema')
|
35
|
-
|
36
|
-
/*
|
37
|
-
* Is `document` an array?
|
38
|
-
*/
|
39
|
-
if (isArray(document)) {
|
40
|
-
/*
|
41
|
-
* Yes, `document` is an array
|
42
|
-
*/
|
43
|
-
return transformArray(document, schema, hash, parentUri, uri)
|
44
|
-
}
|
45
|
-
|
46
|
-
/*
|
47
|
-
* The hash should contain only strings
|
48
|
-
*/
|
49
|
-
hash[uri] = toString(document)
|
50
|
-
|
51
|
-
return hash
|
52
|
-
}
|
7
|
+
export { transformArraySchema as default } from '#transmission/transmission/from-document-to-hash'
|
@@ -0,0 +1,5 @@
|
|
1
|
+
type DocumentType = TransmissionTypes.DocumentType
|
2
|
+
type SchemaType = TransmissionTypes.SchemaType
|
3
|
+
type HashType = TransmissionTypes.HashType
|
4
|
+
|
5
|
+
export default function transformBooleanSchema (document?: DocumentType, schema?: SchemaType, hash?: HashType, parentUri?: string, uri?: string): HashType
|
@@ -15,7 +15,7 @@ import {
|
|
15
15
|
hasOneOf,
|
16
16
|
getOneOf,
|
17
17
|
getUri,
|
18
|
-
|
18
|
+
transformIndexToValueByFindValue
|
19
19
|
} from '#transmission/transmission/common'
|
20
20
|
|
21
21
|
const log = debug('shinkansen-transmission/from-document-to-hash/boolean')
|
@@ -37,25 +37,25 @@ export default function transformBooleanSchema (document, schema = {}, hash = {}
|
|
37
37
|
|
38
38
|
if (hasEnum(schema)) {
|
39
39
|
const array = getEnum(schema)
|
40
|
-
const
|
40
|
+
const value = transformIndexToValueByFindValue(array, document)
|
41
41
|
|
42
|
-
hash[uri] =
|
42
|
+
hash[uri] = value
|
43
43
|
|
44
44
|
return hash
|
45
45
|
} else {
|
46
46
|
if (hasAnyOf(schema)) {
|
47
47
|
const array = getAnyOf(schema)
|
48
|
-
const
|
48
|
+
const value = transformIndexToValueByFindValue(array, document)
|
49
49
|
|
50
|
-
hash[uri] =
|
50
|
+
hash[uri] = value
|
51
51
|
|
52
52
|
return hash
|
53
53
|
} else {
|
54
54
|
if (hasOneOf(schema)) {
|
55
55
|
const array = getOneOf(schema)
|
56
|
-
const
|
56
|
+
const value = transformIndexToValueByFindValue(array, document)
|
57
57
|
|
58
|
-
hash[uri] =
|
58
|
+
hash[uri] = value
|
59
59
|
|
60
60
|
return hash
|
61
61
|
}
|
@@ -3,9 +3,16 @@ export type SchemaType = TransmissionTypes.SchemaType
|
|
3
3
|
export type HashType = TransmissionTypes.HashType
|
4
4
|
|
5
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
|
-
|
8
6
|
export function transformArray (document: DocumentType[], schema: SchemaType, hash: HashType, parentUri: string, uri: string): HashType
|
7
|
+
export function transformArraySchema (document?: DocumentType, schema?: SchemaType, hash?: HashType, parentUri?: string, uri?: string): HashType
|
8
|
+
|
9
|
+
export function transformObjectFor (document: Record<string, DocumentType>, schema: SchemaType, hash: HashType, parentUri: string): HashType
|
9
10
|
export function transformObject (document: Record<string, DocumentType>, schema: SchemaType, hash: HashType, parentUri: string, uri: string): HashType
|
11
|
+
export function transformObjectSchema (document?: DocumentType, schema?: SchemaType, hash?: HashType, parentUri?: string, uri?: string): HashType
|
12
|
+
|
13
|
+
export { default as transformStringSchema } from './string/index.mjs'
|
14
|
+
export { default as transformNumberSchema } from './number/index.mjs'
|
15
|
+
export { default as transformBooleanSchema } from './boolean/index.mjs'
|
16
|
+
export { default as transformNullSchema } from './null/index.mjs'
|
10
17
|
|
11
|
-
export default function
|
18
|
+
export default function fromDocumentToHash (document?: DocumentType, schema?: SchemaType, hash?: HashType, parentUri?: string, uri?: string): HashType
|
@@ -18,8 +18,8 @@ import {
|
|
18
18
|
hasOneOf,
|
19
19
|
getOneOf,
|
20
20
|
getUri,
|
21
|
-
|
22
|
-
|
21
|
+
transformIndexToValueByFindValue,
|
22
|
+
transformIndexToValueByFindEqual,
|
23
23
|
transformToValue
|
24
24
|
} from '#transmission/transmission/common'
|
25
25
|
|
@@ -44,25 +44,7 @@ function getReduceArrayFor (schema, parentUri) {
|
|
44
44
|
return function reduce (hash, document, index) {
|
45
45
|
const schemaUri = getUri(parentUri, index)
|
46
46
|
|
47
|
-
return
|
48
|
-
}
|
49
|
-
}
|
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)
|
47
|
+
return fromDocumentToHash(document, getSchema(schema, parentUri, schemaUri), hash, schemaUri, schemaUri)
|
66
48
|
}
|
67
49
|
}
|
68
50
|
|
@@ -84,24 +66,6 @@ export function transformArrayFor (document, schema, hash, parentUri) { // }, ur
|
|
84
66
|
)
|
85
67
|
}
|
86
68
|
|
87
|
-
/**
|
88
|
-
* @param {Record<string, DocumentType>} document
|
89
|
-
* @param {SchemaType} schema
|
90
|
-
* @param {HashType} hash
|
91
|
-
* @param {string} parentUri
|
92
|
-
* @returns {HashType}
|
93
|
-
*/
|
94
|
-
export function transformObjectFor (document, schema, hash, parentUri) { // }, uri) {
|
95
|
-
/*
|
96
|
-
* log('transformObjectFor')
|
97
|
-
*/
|
98
|
-
|
99
|
-
return (
|
100
|
-
Object.entries(document)
|
101
|
-
.reduce(getReduceObjectFor(schema, parentUri), hash)
|
102
|
-
)
|
103
|
-
}
|
104
|
-
|
105
69
|
/**
|
106
70
|
* @param {Array<DocumentType>} document
|
107
71
|
* @param {SchemaType} schema
|
@@ -117,22 +81,25 @@ export function transformArray (document, schema, hash, parentUri, uri) {
|
|
117
81
|
|
118
82
|
if (hasEnum(schema)) {
|
119
83
|
const array = getEnum(schema)
|
84
|
+
const value = transformIndexToValueByFindEqual(array, document)
|
120
85
|
|
121
|
-
hash[uri] =
|
86
|
+
hash[uri] = value
|
122
87
|
|
123
88
|
return hash
|
124
89
|
} else {
|
125
90
|
if (hasAnyOf(schema)) {
|
126
91
|
const array = getAnyOf(schema)
|
92
|
+
const value = transformIndexToValueByFindEqual(array, document)
|
127
93
|
|
128
|
-
hash[uri] =
|
94
|
+
hash[uri] = value
|
129
95
|
|
130
96
|
return hash
|
131
97
|
} else {
|
132
98
|
if (hasOneOf(schema)) {
|
133
99
|
const array = getOneOf(schema)
|
100
|
+
const value = transformIndexToValueByFindEqual(array, document)
|
134
101
|
|
135
|
-
hash[uri] =
|
102
|
+
hash[uri] = value
|
136
103
|
|
137
104
|
return hash
|
138
105
|
}
|
@@ -145,6 +112,73 @@ export function transformArray (document, schema, hash, parentUri, uri) {
|
|
145
112
|
return transformArrayFor(document, schema, hash, parentUri) // , uri) // schema not items
|
146
113
|
}
|
147
114
|
|
115
|
+
/**
|
116
|
+
* Document can be `undefined`
|
117
|
+
*
|
118
|
+
* @param {DocumentType} [document]
|
119
|
+
* @param {SchemaType} [schema]
|
120
|
+
* @param {HashType} [hash]
|
121
|
+
* @param {string} [parentUri]
|
122
|
+
* @param {string} [uri]
|
123
|
+
* @returns {HashType}
|
124
|
+
*/
|
125
|
+
export function transformArraySchema (document, schema = {}, hash = {}, parentUri = '#', uri = getUri(parentUri)) {
|
126
|
+
log('transformArraySchema')
|
127
|
+
|
128
|
+
/*
|
129
|
+
* Is `document` an array?
|
130
|
+
*/
|
131
|
+
if (isArray(document)) {
|
132
|
+
/*
|
133
|
+
* Yes, `document` is an array
|
134
|
+
*/
|
135
|
+
return transformArray(document, schema, hash, parentUri, uri)
|
136
|
+
}
|
137
|
+
|
138
|
+
/*
|
139
|
+
* The hash should contain only strings
|
140
|
+
*/
|
141
|
+
hash[uri] = toString(document)
|
142
|
+
|
143
|
+
return hash
|
144
|
+
}
|
145
|
+
|
146
|
+
/**
|
147
|
+
* @param {SchemaType} schema
|
148
|
+
* @param {string} parentUri
|
149
|
+
* @returns {(hash: HashType, entry: [key: string, document: DocumentType]) => HashType}
|
150
|
+
*/
|
151
|
+
function getReduceObjectFor (schema, parentUri) {
|
152
|
+
/**
|
153
|
+
* @param {HashType} hash
|
154
|
+
* @param {[key: string, document: DocumentType]} entry
|
155
|
+
* @returns {HashType}
|
156
|
+
*/
|
157
|
+
return function reduce (hash, [key, document]) {
|
158
|
+
const schemaUri = getUri(parentUri, key)
|
159
|
+
|
160
|
+
return fromDocumentToHash(document, getSchema(schema, parentUri, schemaUri), hash, schemaUri, schemaUri)
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
* @param {Record<string, DocumentType>} document
|
166
|
+
* @param {SchemaType} schema
|
167
|
+
* @param {HashType} hash
|
168
|
+
* @param {string} parentUri
|
169
|
+
* @returns {HashType}
|
170
|
+
*/
|
171
|
+
export function transformObjectFor (document, schema, hash, parentUri) { // }, uri) {
|
172
|
+
/*
|
173
|
+
* log('transformObjectFor')
|
174
|
+
*/
|
175
|
+
|
176
|
+
return (
|
177
|
+
Object.entries(document)
|
178
|
+
.reduce(getReduceObjectFor(schema, parentUri), hash)
|
179
|
+
)
|
180
|
+
}
|
181
|
+
|
148
182
|
/**
|
149
183
|
* @param {Record<string, DocumentType>} document
|
150
184
|
* @param {SchemaType} schema
|
@@ -160,33 +194,29 @@ export function transformObject (document, schema, hash, parentUri, uri) {
|
|
160
194
|
|
161
195
|
if (hasEnum(schema)) {
|
162
196
|
const array = getEnum(schema)
|
163
|
-
const
|
197
|
+
const value = transformIndexToValueByFindEqual(array, document)
|
164
198
|
|
165
|
-
hash[uri] =
|
199
|
+
hash[uri] = value
|
166
200
|
|
167
201
|
return hash
|
168
202
|
} else {
|
169
203
|
if (hasAnyOf(schema)) {
|
170
204
|
const array = getAnyOf(schema)
|
171
|
-
const
|
205
|
+
const value = transformIndexToValueByFindEqual(array, document)
|
172
206
|
|
173
|
-
hash[uri] =
|
207
|
+
hash[uri] = value
|
174
208
|
|
175
209
|
return hash
|
176
210
|
} else {
|
177
211
|
if (hasOneOf(schema)) {
|
178
212
|
const array = getOneOf(schema)
|
179
|
-
const
|
213
|
+
const value = transformIndexToValueByFindEqual(array, document)
|
180
214
|
|
181
|
-
hash[uri] =
|
215
|
+
hash[uri] = value
|
182
216
|
|
183
217
|
return hash
|
184
218
|
}
|
185
219
|
}
|
186
|
-
|
187
|
-
/**
|
188
|
-
* We don't look at `properties` here like we look at `items` in `transformArray`
|
189
|
-
*/
|
190
220
|
}
|
191
221
|
|
192
222
|
/*
|
@@ -205,7 +235,38 @@ export function transformObject (document, schema, hash, parentUri, uri) {
|
|
205
235
|
* @param {string} [uri]
|
206
236
|
* @returns {HashType}
|
207
237
|
*/
|
208
|
-
export
|
238
|
+
export function transformObjectSchema (document, schema = {}, hash = {}, parentUri = '#', uri = getUri(parentUri)) {
|
239
|
+
log('transformObjectSchema')
|
240
|
+
|
241
|
+
/*
|
242
|
+
* Is `document` an object?
|
243
|
+
*/
|
244
|
+
if (isObject(document)) {
|
245
|
+
/*
|
246
|
+
* Yes, `document` is an object
|
247
|
+
*/
|
248
|
+
return transformObject(document, schema, hash, parentUri, uri)
|
249
|
+
}
|
250
|
+
|
251
|
+
/*
|
252
|
+
* The hash should contain only strings
|
253
|
+
*/
|
254
|
+
hash[uri] = toString(document)
|
255
|
+
|
256
|
+
return hash
|
257
|
+
}
|
258
|
+
|
259
|
+
/**
|
260
|
+
* Document can be `undefined`
|
261
|
+
*
|
262
|
+
* @param {DocumentType} [document]
|
263
|
+
* @param {SchemaType} [schema]
|
264
|
+
* @param {HashType} [hash]
|
265
|
+
* @param {string} [parentUri]
|
266
|
+
* @param {string} [uri]
|
267
|
+
* @returns {HashType}
|
268
|
+
*/
|
269
|
+
export default function fromDocumentToHash (document, schema = {}, hash = {}, parentUri = '#', uri = getUri(parentUri)) {
|
209
270
|
log('fromDocumentToHash')
|
210
271
|
|
211
272
|
/*
|
@@ -233,9 +294,9 @@ export default function transform (document, schema = {}, hash = {}, parentUri =
|
|
233
294
|
*/
|
234
295
|
if (hasEnum(schema)) {
|
235
296
|
const array = getEnum(schema)
|
236
|
-
const
|
297
|
+
const value = transformIndexToValueByFindValue(array, document)
|
237
298
|
|
238
|
-
hash[uri] =
|
299
|
+
hash[uri] = value
|
239
300
|
|
240
301
|
return hash
|
241
302
|
} else {
|
@@ -244,20 +305,20 @@ export default function transform (document, schema = {}, hash = {}, parentUri =
|
|
244
305
|
*/
|
245
306
|
if (hasAnyOf(schema)) {
|
246
307
|
const array = getAnyOf(schema)
|
247
|
-
const
|
308
|
+
const value = transformIndexToValueByFindValue(array, document)
|
248
309
|
|
249
|
-
hash[uri] =
|
310
|
+
hash[uri] = value
|
250
311
|
|
251
312
|
return hash
|
252
313
|
} else {
|
253
314
|
/**
|
254
|
-
* Is the schema
|
315
|
+
* Is the schema a `oneOf`?
|
255
316
|
*/
|
256
317
|
if (hasOneOf(schema)) {
|
257
318
|
const array = getOneOf(schema)
|
258
|
-
const
|
319
|
+
const value = transformIndexToValueByFindValue(array, document)
|
259
320
|
|
260
|
-
hash[uri] =
|
321
|
+
hash[uri] = value
|
261
322
|
|
262
323
|
return hash
|
263
324
|
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
type DocumentType = TransmissionTypes.DocumentType
|
2
|
+
type SchemaType = TransmissionTypes.SchemaType
|
3
|
+
type HashType = TransmissionTypes.HashType
|
4
|
+
|
5
|
+
export default function transformNullSchema (document?: DocumentType, schema?: SchemaType, hash?: HashType, parentUri?: string, uri?: string): HashType
|
@@ -15,7 +15,7 @@ import {
|
|
15
15
|
hasOneOf,
|
16
16
|
getOneOf,
|
17
17
|
getUri,
|
18
|
-
|
18
|
+
transformIndexToValueByFindValue
|
19
19
|
} from '#transmission/transmission/common'
|
20
20
|
|
21
21
|
const log = debug('shinkansen-transmission/from-document-to-hash/null')
|
@@ -37,25 +37,25 @@ export default function transformNullSchema (document, schema = {}, hash = {}, p
|
|
37
37
|
|
38
38
|
if (hasEnum(schema)) {
|
39
39
|
const array = getEnum(schema)
|
40
|
-
const
|
40
|
+
const value = transformIndexToValueByFindValue(array, document)
|
41
41
|
|
42
|
-
hash[uri] =
|
42
|
+
hash[uri] = value
|
43
43
|
|
44
44
|
return hash
|
45
45
|
} else {
|
46
46
|
if (hasAnyOf(schema)) {
|
47
47
|
const array = getAnyOf(schema)
|
48
|
-
const
|
48
|
+
const value = transformIndexToValueByFindValue(array, document)
|
49
49
|
|
50
|
-
hash[uri] =
|
50
|
+
hash[uri] = value
|
51
51
|
|
52
52
|
return hash
|
53
53
|
} else {
|
54
54
|
if (hasOneOf(schema)) {
|
55
55
|
const array = getOneOf(schema)
|
56
|
-
const
|
56
|
+
const value = transformIndexToValueByFindValue(array, document)
|
57
57
|
|
58
|
-
hash[uri] =
|
58
|
+
hash[uri] = value
|
59
59
|
|
60
60
|
return hash
|
61
61
|
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
type DocumentType = TransmissionTypes.DocumentType
|
2
|
+
type SchemaType = TransmissionTypes.SchemaType
|
3
|
+
type HashType = TransmissionTypes.HashType
|
4
|
+
|
5
|
+
export default function transformNumberSchema (document?: DocumentType, schema?: SchemaType, hash?: HashType, parentUri?: string, uri?: string): HashType
|
@@ -15,7 +15,7 @@ import {
|
|
15
15
|
hasOneOf,
|
16
16
|
getOneOf,
|
17
17
|
getUri,
|
18
|
-
|
18
|
+
transformIndexToValueByFindValue
|
19
19
|
} from '#transmission/transmission/common'
|
20
20
|
|
21
21
|
const log = debug('shinkansen-transmission/from-document-to-hash/number')
|
@@ -37,25 +37,25 @@ export default function transformNumberSchema (document, schema = {}, hash = {},
|
|
37
37
|
|
38
38
|
if (hasEnum(schema)) {
|
39
39
|
const array = getEnum(schema)
|
40
|
-
const
|
40
|
+
const value = transformIndexToValueByFindValue(array, document)
|
41
41
|
|
42
|
-
hash[uri] =
|
42
|
+
hash[uri] = value
|
43
43
|
|
44
44
|
return hash
|
45
45
|
} else {
|
46
46
|
if (hasAnyOf(schema)) {
|
47
47
|
const array = getAnyOf(schema)
|
48
|
-
const
|
48
|
+
const value = transformIndexToValueByFindValue(array, document)
|
49
49
|
|
50
|
-
hash[uri] =
|
50
|
+
hash[uri] = value
|
51
51
|
|
52
52
|
return hash
|
53
53
|
} else {
|
54
54
|
if (hasOneOf(schema)) {
|
55
55
|
const array = getOneOf(schema)
|
56
|
-
const
|
56
|
+
const value = transformIndexToValueByFindValue(array, document)
|
57
57
|
|
58
|
-
hash[uri] =
|
58
|
+
hash[uri] = value
|
59
59
|
|
60
60
|
return hash
|
61
61
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export { transformObjectSchema as default } from '#transmission/transmission/from-document-to-hash'
|