shinkansen-transmission 2.3.5 → 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 +2 -2
- 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,8 @@
|
|
1
|
+
export type SchemaType = TransmissionTypes.SchemaType
|
2
|
+
export type ParamsType = TransmissionTypes.ParamsType
|
3
|
+
export type DocumentType = TransmissionTypes.DocumentType
|
4
|
+
export type HashType = TransmissionTypes.HashType
|
5
|
+
|
6
|
+
export function transformNull (hash: HashType, schema: SchemaType, parentUri: string, uri: string): null | undefined
|
7
|
+
|
8
|
+
export default function transformNullSchema (hash?: HashType, schema?: SchemaType, params?: ParamsType): DocumentType | undefined
|
@@ -8,19 +8,100 @@
|
|
8
8
|
import debug from 'debug'
|
9
9
|
|
10
10
|
import {
|
11
|
+
isArray,
|
12
|
+
hasEnum,
|
13
|
+
getEnum,
|
14
|
+
hasAnyOf,
|
15
|
+
getAnyOf,
|
16
|
+
hasOneOf,
|
17
|
+
getOneOf,
|
18
|
+
transformToValue,
|
11
19
|
getUri
|
12
20
|
} from '#transmission/transmission/common'
|
13
21
|
|
14
22
|
import {
|
15
|
-
|
16
|
-
|
23
|
+
fromDocumentToArray,
|
24
|
+
mapToValue,
|
25
|
+
toNull
|
26
|
+
} from '#transmission/transmission/common/transform'
|
17
27
|
|
18
28
|
const log = debug('shinkansen-transmission/from-hash-to-document/null')
|
19
29
|
|
20
30
|
log('`shinkansen` is awake')
|
21
31
|
|
22
32
|
/**
|
23
|
-
*
|
33
|
+
* @overload
|
34
|
+
* @param {unknown} error
|
35
|
+
* @returns {void}
|
36
|
+
*
|
37
|
+
* @param {{ message?: string }} error
|
38
|
+
* @returns {void}
|
39
|
+
*/
|
40
|
+
function handleError ({ message = 'No error message defined' }) { log(message) }
|
41
|
+
|
42
|
+
/**
|
43
|
+
* @param {HashType} hash
|
44
|
+
* @param {SchemaType} schema
|
45
|
+
* @param {string} parentUri
|
46
|
+
* @param {string} uri
|
47
|
+
* @returns {DocumentType | undefined}
|
48
|
+
*/
|
49
|
+
export function transformNull (hash, schema, parentUri, uri) {
|
50
|
+
/*
|
51
|
+
* log('transformNull')
|
52
|
+
*/
|
53
|
+
|
54
|
+
if (uri in hash) { // Reflect.has(hash, uri)) {
|
55
|
+
const document = hash[uri] // Reflect.get(hash, uri)
|
56
|
+
|
57
|
+
if (hasEnum(schema)) {
|
58
|
+
const array = getEnum(schema)
|
59
|
+
|
60
|
+
if (isArray(document)) return document.map(mapToValue(array))
|
61
|
+
return (
|
62
|
+
transformToValue(
|
63
|
+
fromDocumentToArray(document, array)
|
64
|
+
)
|
65
|
+
)
|
66
|
+
} else {
|
67
|
+
if (hasAnyOf(schema)) {
|
68
|
+
const array = getAnyOf(schema)
|
69
|
+
|
70
|
+
if (isArray(document)) return document.map(mapToValue(array))
|
71
|
+
return (
|
72
|
+
transformToValue(
|
73
|
+
fromDocumentToArray(document, array)
|
74
|
+
)
|
75
|
+
)
|
76
|
+
} else {
|
77
|
+
if (hasOneOf(schema)) {
|
78
|
+
const array = getOneOf(schema)
|
79
|
+
|
80
|
+
if (isArray(document)) return document.map(mapToValue(array))
|
81
|
+
return (
|
82
|
+
transformToValue(
|
83
|
+
fromDocumentToArray(document, array)
|
84
|
+
)
|
85
|
+
)
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
try {
|
91
|
+
if (isArray(document)) return document.map(toNull)
|
92
|
+
return (
|
93
|
+
toNull(document)
|
94
|
+
)
|
95
|
+
} catch (e) {
|
96
|
+
handleError(e)
|
97
|
+
}
|
98
|
+
|
99
|
+
return document
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Hash can be `undefined`
|
24
105
|
*
|
25
106
|
* @param {HashType} [hash]
|
26
107
|
* @param {SchemaType} [schema]
|
@@ -0,0 +1,8 @@
|
|
1
|
+
export type SchemaType = TransmissionTypes.SchemaType
|
2
|
+
export type ParamsType = TransmissionTypes.ParamsType
|
3
|
+
export type DocumentType = TransmissionTypes.DocumentType
|
4
|
+
export type HashType = TransmissionTypes.HashType
|
5
|
+
|
6
|
+
export function transformNumber (hash: HashType, schema: SchemaType, parentUri: string, uri: string): number | undefined
|
7
|
+
|
8
|
+
export default function transformNumberSchema (hash?: HashType, schema?: SchemaType, params?: ParamsType): DocumentType | undefined
|
@@ -8,19 +8,100 @@
|
|
8
8
|
import debug from 'debug'
|
9
9
|
|
10
10
|
import {
|
11
|
+
isArray,
|
12
|
+
hasEnum,
|
13
|
+
getEnum,
|
14
|
+
hasAnyOf,
|
15
|
+
getAnyOf,
|
16
|
+
hasOneOf,
|
17
|
+
getOneOf,
|
18
|
+
transformToValue,
|
11
19
|
getUri
|
12
20
|
} from '#transmission/transmission/common'
|
13
21
|
|
14
22
|
import {
|
15
|
-
|
16
|
-
|
23
|
+
fromDocumentToArray,
|
24
|
+
mapToValue,
|
25
|
+
toNumber
|
26
|
+
} from '#transmission/transmission/common/transform'
|
17
27
|
|
18
28
|
const log = debug('shinkansen-transmission/from-hash-to-document/number')
|
19
29
|
|
20
30
|
log('`shinkansen` is awake')
|
21
31
|
|
22
32
|
/**
|
23
|
-
*
|
33
|
+
* @overload
|
34
|
+
* @param {unknown} error
|
35
|
+
* @returns {void}
|
36
|
+
*
|
37
|
+
* @param {{ message?: string }} error
|
38
|
+
* @returns {void}
|
39
|
+
*/
|
40
|
+
function handleError ({ message = 'No error message defined' }) { log(message) }
|
41
|
+
|
42
|
+
/**
|
43
|
+
* @param {HashType} hash
|
44
|
+
* @param {SchemaType} schema
|
45
|
+
* @param {string} parentUri
|
46
|
+
* @param {string} uri
|
47
|
+
* @returns {DocumentType | undefined}
|
48
|
+
*/
|
49
|
+
export function transformNumber (hash, schema, parentUri, uri) {
|
50
|
+
/*
|
51
|
+
* log('transformNumber')
|
52
|
+
*/
|
53
|
+
|
54
|
+
if (uri in hash) { // Reflect.has(hash, uri)) {
|
55
|
+
const document = hash[uri] // Reflect.get(hash, uri)
|
56
|
+
|
57
|
+
if (hasEnum(schema)) {
|
58
|
+
const array = getEnum(schema)
|
59
|
+
|
60
|
+
if (isArray(document)) return document.map(mapToValue(array))
|
61
|
+
return (
|
62
|
+
transformToValue(
|
63
|
+
fromDocumentToArray(document, array)
|
64
|
+
)
|
65
|
+
)
|
66
|
+
} else {
|
67
|
+
if (hasAnyOf(schema)) {
|
68
|
+
const array = getAnyOf(schema)
|
69
|
+
|
70
|
+
if (isArray(document)) return document.map(mapToValue(array))
|
71
|
+
return (
|
72
|
+
transformToValue(
|
73
|
+
fromDocumentToArray(document, array)
|
74
|
+
)
|
75
|
+
)
|
76
|
+
} else {
|
77
|
+
if (hasOneOf(schema)) {
|
78
|
+
const array = getOneOf(schema)
|
79
|
+
|
80
|
+
if (isArray(document)) return document.map(mapToValue(array))
|
81
|
+
return (
|
82
|
+
transformToValue(
|
83
|
+
fromDocumentToArray(document, array)
|
84
|
+
)
|
85
|
+
)
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
try {
|
91
|
+
if (isArray(document)) return document.map(toNumber)
|
92
|
+
return (
|
93
|
+
toNumber(document)
|
94
|
+
)
|
95
|
+
} catch (e) {
|
96
|
+
handleError(e)
|
97
|
+
}
|
98
|
+
|
99
|
+
return document
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Hash can be `undefined`
|
24
105
|
*
|
25
106
|
* @param {HashType} [hash]
|
26
107
|
* @param {SchemaType} [schema]
|
@@ -1,48 +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
|
-
|
8
1
|
import debug from 'debug'
|
9
2
|
|
10
|
-
import {
|
11
|
-
getUri
|
12
|
-
} from '#transmission/transmission/common'
|
13
|
-
|
14
|
-
import {
|
15
|
-
transformObject
|
16
|
-
} from '#transmission/transmission/from-hash-to-document'
|
17
|
-
|
18
3
|
const log = debug('shinkansen-transmission/from-hash-to-document/object')
|
19
4
|
|
20
5
|
log('`shinkansen` is awake')
|
21
6
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
* @param {SchemaType} [schema]
|
27
|
-
* @param {ParamsType} [params]
|
28
|
-
* @returns {DocumentType}
|
29
|
-
*/
|
30
|
-
export default function transformObjectSchema (hash = {}, schema = {}, params = {}) {
|
31
|
-
log('transformObjectSchema')
|
32
|
-
|
33
|
-
const {
|
34
|
-
type
|
35
|
-
} = schema
|
36
|
-
|
37
|
-
// https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.2.1
|
38
|
-
if (type === 'object') {
|
39
|
-
const {
|
40
|
-
uri: parentUri = '#',
|
41
|
-
key: fieldKey // string | undefined
|
42
|
-
} = params
|
43
|
-
|
44
|
-
return transformObject(hash, schema, parentUri, getUri(parentUri, fieldKey))
|
45
|
-
}
|
46
|
-
|
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')
|
48
|
-
}
|
7
|
+
export {
|
8
|
+
transformObject,
|
9
|
+
transformObjectSchema as default
|
10
|
+
} from '#transmission/transmission/from-hash-to-document'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
export type SchemaType = TransmissionTypes.SchemaType
|
2
|
+
export type ParamsType = TransmissionTypes.ParamsType
|
3
|
+
export type DocumentType = TransmissionTypes.DocumentType
|
4
|
+
export type HashType = TransmissionTypes.HashType
|
5
|
+
|
6
|
+
export function transformString (hash: HashType, schema: SchemaType, parentUri: string, uri: string): string | undefined
|
7
|
+
|
8
|
+
export default function transformStringSchema (hash?: HashType, schema?: SchemaType, params?: ParamsType): DocumentType | undefined
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* @typedef {TransmissionTypes.ObjectType} ObjectType
|
3
3
|
* @typedef {TransmissionTypes.ArrayType} ArrayType
|
4
4
|
*
|
5
|
-
* @typedef {TransmissionTypes.
|
5
|
+
* @typedef {TransmissionTypes.MemberArrayType} MemberArrayType
|
6
6
|
*
|
7
7
|
* @typedef {TransmissionTypes.HashType} HashType
|
8
8
|
* @typedef {TransmissionTypes.SchemaType} SchemaType
|
@@ -13,19 +13,100 @@
|
|
13
13
|
import debug from 'debug'
|
14
14
|
|
15
15
|
import {
|
16
|
+
isArray,
|
17
|
+
hasEnum,
|
18
|
+
getEnum,
|
19
|
+
hasAnyOf,
|
20
|
+
getAnyOf,
|
21
|
+
hasOneOf,
|
22
|
+
getOneOf,
|
23
|
+
transformToValue,
|
16
24
|
getUri
|
17
25
|
} from '#transmission/transmission/common'
|
18
26
|
|
19
27
|
import {
|
20
|
-
|
21
|
-
|
28
|
+
fromDocumentToArray,
|
29
|
+
mapToValue,
|
30
|
+
toString
|
31
|
+
} from '#transmission/transmission/common/transform'
|
22
32
|
|
23
33
|
const log = debug('shinkansen-transmission/from-hash-to-document/string')
|
24
34
|
|
25
35
|
log('`shinkansen` is awake')
|
26
36
|
|
27
37
|
/**
|
28
|
-
*
|
38
|
+
* @overload
|
39
|
+
* @param {unknown} error
|
40
|
+
* @returns {void}
|
41
|
+
*
|
42
|
+
* @param {{ message?: string }} error
|
43
|
+
* @returns {void}
|
44
|
+
*/
|
45
|
+
function handleError ({ message = 'No error message defined' }) { log(message) }
|
46
|
+
|
47
|
+
/**
|
48
|
+
* @param {HashType} hash
|
49
|
+
* @param {SchemaType} schema
|
50
|
+
* @param {string} parentUri
|
51
|
+
* @param {string} uri
|
52
|
+
* @returns {DocumentType | undefined}
|
53
|
+
*/
|
54
|
+
export function transformString (hash, schema, parentUri, uri) {
|
55
|
+
/*
|
56
|
+
* log('transformString')
|
57
|
+
*/
|
58
|
+
|
59
|
+
if (uri in hash) { // Reflect.has(hash, uri)) {
|
60
|
+
const document = hash[uri] // Reflect.get(hash, uri)
|
61
|
+
|
62
|
+
if (hasEnum(schema)) {
|
63
|
+
const array = getEnum(schema)
|
64
|
+
|
65
|
+
if (isArray(document)) return document.map(mapToValue(array))
|
66
|
+
return (
|
67
|
+
transformToValue(
|
68
|
+
fromDocumentToArray(document, array)
|
69
|
+
)
|
70
|
+
)
|
71
|
+
} else {
|
72
|
+
if (hasAnyOf(schema)) {
|
73
|
+
const array = getAnyOf(schema)
|
74
|
+
|
75
|
+
if (isArray(document)) return document.map(mapToValue(array))
|
76
|
+
return (
|
77
|
+
transformToValue(
|
78
|
+
fromDocumentToArray(document, array)
|
79
|
+
)
|
80
|
+
)
|
81
|
+
} else {
|
82
|
+
if (hasOneOf(schema)) {
|
83
|
+
const array = getOneOf(schema)
|
84
|
+
|
85
|
+
if (isArray(document)) return document.map(mapToValue(array))
|
86
|
+
return (
|
87
|
+
transformToValue(
|
88
|
+
fromDocumentToArray(document, array)
|
89
|
+
)
|
90
|
+
)
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
try {
|
96
|
+
if (isArray(document)) return document.map(toString)
|
97
|
+
return (
|
98
|
+
toString(document)
|
99
|
+
)
|
100
|
+
} catch (e) {
|
101
|
+
handleError(e)
|
102
|
+
}
|
103
|
+
|
104
|
+
return document
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* Hash can be `undefined`
|
29
110
|
*
|
30
111
|
* @param {HashType} [hash]
|
31
112
|
* @param {SchemaType} [schema]
|