shinkansen-transmission 2.2.133 → 2.2.135

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shinkansen-transmission",
3
- "version": "2.2.133",
3
+ "version": "2.2.135",
4
4
  "description": "Shinkansen Transmission",
5
5
  "keywords": [
6
6
  "Shinkansen",
@@ -43,18 +43,18 @@
43
43
  "@babel/eslint-parser": "^7.23.10",
44
44
  "@babel/preset-env": "^7.23.9",
45
45
  "@babel/register": "^7.23.7",
46
- "@modernpoacher/hooks": "^1.0.465",
47
- "@typescript-eslint/eslint-plugin": "5.61.0",
48
- "@typescript-eslint/parser": "5.61.0",
46
+ "@modernpoacher/hooks": "^1.0.466",
47
+ "@typescript-eslint/eslint-plugin": "^7.0.2",
48
+ "@typescript-eslint/parser": "^7.0.2",
49
49
  "babel-loader": "^9.1.3",
50
50
  "babel-plugin-module-resolver": "^5.0.0",
51
51
  "c8": "^9.1.0",
52
52
  "chai": "^5.1.0",
53
53
  "core-js": "^3.36.0",
54
54
  "cross-env": "^7.0.3",
55
- "eslint": "^8.56.0",
55
+ "eslint": "^8.57.0",
56
56
  "eslint-config-standard": "^17.1.0",
57
- "eslint-config-standard-with-typescript": "35.0.0",
57
+ "eslint-config-standard-with-typescript": "^43.0.1",
58
58
  "eslint-import-resolver-babel-module": "^5.3.2",
59
59
  "husky": "^9.0.11",
60
60
  "mocha": "^10.3.0",
package/src/index.d.cts CHANGED
@@ -1,17 +1,224 @@
1
+ declare namespace Zashiki {
2
+ export type ObjectLiteralType = Record<PropertyKey, never>
3
+ export type ObjectType = Record<PropertyKey, unknown>
4
+ export type ArrayLiteralType = never[]
5
+ export type ArrayType = unknown[]
6
+
7
+ export interface SchemaType {
8
+ type: string
9
+ title?: string
10
+ description?: string
11
+ readOnly?: boolean
12
+ writeOnly?: boolean
13
+ const?: unknown
14
+ default?: unknown
15
+ enum?: ObjectType | ObjectLiteralType | ArrayType | ArrayLiteralType
16
+ anyOf?: ObjectType | ObjectLiteralType | ArrayType | ArrayLiteralType
17
+ oneOf?: ObjectType | ObjectLiteralType | ArrayType | ArrayLiteralType
18
+ allOf: ObjectType | ObjectLiteralType | ArrayType | ArrayLiteralType
19
+ minimum?: number
20
+ maximum?: number
21
+ minLength?: number
22
+ maxLength?: number
23
+ minItems?: number
24
+ maxItems?: number
25
+ hasUniqueItems?: boolean
26
+ minContains?: number
27
+ maxContains?: number
28
+ minProperties?: number
29
+ maxProperties?: number
30
+ isExclusiveMin?: boolean
31
+ isExclusiveMax?: boolean
32
+ multipleOf?: number
33
+ }
34
+
35
+ export type DocumentType = string | number | boolean | null | ObjectType | ObjectLiteralType | ArrayType | ArrayLiteralType | ObjectLiteralType | undefined
36
+ export type HashType = Record<PropertyKey, string> | Record<PropertyKey, never>
37
+
38
+ export interface ZashikiType {
39
+ meta: ObjectType | ObjectLiteralType
40
+ elements: ObjectType | ObjectLiteralType
41
+ }
42
+ }
43
+
1
44
  declare module 'shinkansen-transmission/transmission/common' {
2
- export * from './transmission/common/index.mjs'
45
+ type ObjectLiteralType = Zashiki.ObjectLiteralType
46
+ type ObjectType = Zashiki.ObjectType
47
+ type ArrayLiteralType = Zashiki.ArrayLiteralType
48
+ type ArrayType = Zashiki.ArrayType
49
+
50
+ type SchemaType = Zashiki.SchemaType
51
+
52
+ export function isObject (v: unknown): boolean
53
+ export function isArray (v: unknown): boolean
54
+ export function isPrimitive (v: unknown): boolean
55
+ export function isSchema (v: SchemaType | undefined): boolean
56
+ export function isStringSchema (schema: SchemaType | undefined): boolean
57
+ export function isNumberSchema (schema: SchemaType | undefined): boolean
58
+ export function isArraySchema (schema: SchemaType | undefined): boolean
59
+ export function isObjectSchema (schema: SchemaType | undefined): boolean
60
+ export function isBooleanSchema (schema: SchemaType | undefined): boolean
61
+ export function isNullSchema (schema: SchemaType | undefined): boolean
62
+
63
+ export function getTitle (schema: SchemaType | undefined): { title: string } | ObjectLiteralType
64
+ export function getDescription (schema: SchemaType | undefined): { description: string } | ObjectLiteralType
65
+ export function getIsReadOnly (schema: SchemaType | undefined): { readOnly: boolean } | ObjectLiteralType
66
+ export function getIsWriteOnly (schema: SchemaType | undefined): { writeOnly: boolean } | ObjectLiteralType
67
+
68
+ export function getSelectedItems (values: ObjectType | ObjectLiteralType, uri: string | undefined): ArrayType
69
+
70
+ export function isParentUri (parentUri: string | undefined, uri: string | undefined): boolean
71
+
72
+ export function getMetaProps (params: ObjectType | ObjectLiteralType, uri: string | undefined): ObjectType
73
+ export function getMetaDefaultValue (schema: SchemaType | undefined): { defaultValue: string } | ObjectLiteralType
74
+ export function hasMetaValue (values: ObjectType | ObjectLiteralType, uri: string | undefined, schema: SchemaType | undefined): boolean
75
+ export function getMetaValue (values: ObjectType | ObjectLiteralType, uri: string | undefined, schema: SchemaType | undefined): { value: string } | ObjectLiteralType
76
+
77
+ export function transformValue (schema: SchemaType): SchemaType | unknown
78
+
79
+ export function findByKey (parentUri: string | undefined, uri: string | undefined): (key: string) => boolean
80
+ export function findByIndex (parentUri: string | undefined, uri: string | undefined): (schema: SchemaType, index: number) => boolean
81
+ export function findByValue (value: unknown): (schema: SchemaType) => boolean
82
+ export function findByEqual (value: unknown): (schema: SchemaType) => boolean
83
+
84
+ export function toString (value: unknown): string
85
+
86
+ export function getObject (value: { properties: ObjectType /* object */ }, parentUri: string | undefined, uri: string | undefined): ObjectType
87
+ export function getArray (value: { items: ObjectType | ObjectLiteralType | ArrayType | ArrayLiteralType /* array or object */ }, parentUri: string | undefined, uri: string | undefined): ArrayType
88
+ export function getSchema (schema: SchemaType | ObjectType, parentUri: string | undefined, uri: string | undefined): ObjectType | ObjectLiteralType | ArrayType | ArrayLiteralType | SchemaType
89
+
90
+ export function transformValueIndexFor (array: ArrayType, value: unknown): string
91
+ export function transformEqualIndexFor (array: ArrayType, value: unknown): string
92
+
93
+ export function hasValue (values: ObjectType | ObjectLiteralType, uri: string | undefined, schema: SchemaType | undefined): boolean
94
+ export function getValue (values: ObjectType | ObjectLiteralType, uri: string | undefined, schema: SchemaType | undefined): string
95
+
96
+ export function getValueForEnum (v: string | number, schema: SchemaType): string
97
+ export function getIndexForEnum (values: ObjectType | ObjectLiteralType, parentUri: string | undefined, uri: string | undefined, schema: SchemaType | undefined): number
98
+
99
+ export function getValueForAnyOf (v: string | number, schema: SchemaType): string
100
+ export function getIndexForAnyOf (values: ObjectType | ObjectLiteralType, parentUri: string | undefined, uri: string | undefined, schema: SchemaType | undefined): number
101
+
102
+ export function getValueForOneOf (v: string | number, schema: SchemaType): string
103
+ export function getIndexForOneOf (values: ObjectType | ObjectLiteralType, parentUri: string | undefined, uri: string | undefined, schema: SchemaType | undefined): number
104
+
105
+ export function getElementsProps (params: ObjectType | ObjectLiteralType, uri: string | undefined): ObjectType | ObjectLiteralType
106
+ export function getElementsTitleProps (params: ObjectType | ObjectLiteralType, uri: string | undefined): ObjectType | ObjectLiteralType
107
+ export function getElementsDescriptionProps (params: ObjectType | ObjectLiteralType, uri: string | undefined): ObjectType | ObjectLiteralType
108
+
109
+ export function getElementsFieldPropsForEnum (params: ObjectType | ObjectLiteralType, uri: string | undefined): ObjectType | ObjectLiteralType
110
+ export function getElementsFieldPropsForOneOf (params: ObjectType | ObjectLiteralType, uri: string | undefined): ObjectType | ObjectLiteralType
111
+ export function getElementsFieldPropsForAnyOf (params: ObjectType | ObjectLiteralType, uri: string | undefined): ObjectType | ObjectLiteralType
112
+ export function getElementsFieldPropsForAllOf (params: ObjectType | ObjectLiteralType, uri: string | undefined): ObjectType | ObjectLiteralType
113
+
114
+ export function getElementsFieldProps (params: ObjectType | ObjectLiteralType, uri: string | undefined): ObjectType | ObjectLiteralType
115
+ export function getElementsFieldValue (values: ObjectType | ObjectLiteralType, uri: string | undefined, schema: SchemaType | undefined): { value: string } | ObjectLiteralType
116
+
117
+ export function hasEnum (schema: SchemaType | undefined): boolean
118
+ export function getEnum (schema: SchemaType | undefined): ObjectType | ObjectLiteralType | ArrayType | ArrayLiteralType
119
+
120
+ export function hasConst (schema: SchemaType | undefined): boolean
121
+ export function getConst (schema: SchemaType | undefined): unknown
122
+
123
+ export function hasDefault (schema: SchemaType | undefined): boolean
124
+ export function getDefault (schema: SchemaType | undefined): unknown
125
+
126
+ export function hasAnyOf (schema: SchemaType | undefined): boolean
127
+ export function getAnyOf (schema: SchemaType | undefined): ObjectType | ObjectLiteralType | ArrayType | ArrayLiteralType
128
+
129
+ export function hasOneOf (schema: SchemaType | undefined): boolean
130
+ export function getOneOf (schema: SchemaType | undefined): ObjectType | ObjectLiteralType | ArrayType | ArrayLiteralType
131
+
132
+ export function hasAllOf (schema: SchemaType | undefined): boolean
133
+ export function getAllOf (schema: SchemaType | undefined): ObjectType | ObjectLiteralType | ArrayType | ArrayLiteralType
134
+
135
+ export function getUri (uri: string | undefined, resource: string | undefined): string
136
+
137
+ export function normaliseUri (uri: string | undefined): string
138
+
139
+ export function getMin (schema: SchemaType | undefined): { min: number } | ObjectLiteralType
140
+ export function getMax (schema: SchemaType | undefined): { max: number } | ObjectLiteralType
141
+
142
+ export function getMinLength (schema: SchemaType | undefined): { minLength: number } | ObjectLiteralType
143
+ export function getMaxLength (schema: SchemaType | undefined): { maxLength: number } | ObjectLiteralType
144
+
145
+ export function getMinItems (schema: SchemaType | undefined): { minItems: number } | ObjectLiteralType
146
+ export function getMaxItems (schema: SchemaType | undefined): { maxItems: number } | ObjectLiteralType
147
+
148
+ export function getHasUniqueItems (schema: SchemaType | undefined): { hasUniqueItems: boolean } | ObjectLiteralType
149
+
150
+ export function getMinContains (schema: SchemaType | undefined): { minContains: number } | ObjectLiteralType
151
+ export function getMaxContains (schema: SchemaType | undefined): { maxContains: number } | ObjectLiteralType
152
+
153
+ export function getMinProperties (schema: SchemaType | undefined): { minProperties: number } | ObjectLiteralType
154
+ export function getMaxProperties (schema: SchemaType | undefined): { maxProperties: number } | ObjectLiteralType
155
+
156
+ export function getIsExclusiveMin (schema: SchemaType | undefined): { isExclusiveMin: boolean } | ObjectLiteralType
157
+ export function getIsExclusiveMax (schema: SchemaType | undefined): { isExclusiveMax: boolean } | ObjectLiteralType
158
+
159
+ export function getPattern (schema: SchemaType | undefined): { pattern: string } | ObjectLiteralType
160
+
161
+ export function getStep (schema: SchemaType | undefined): { step: number } | ObjectLiteralType
3
162
  }
4
163
 
5
164
  declare module 'shinkansen-transmission/transmission/from-document-to-hash' {
6
- export * from './transmission/from-document-to-hash/index.mjs'
165
+ type ObjectLiteralType = Zashiki.ObjectLiteralType
166
+ type ObjectType = Zashiki.ObjectType
167
+
168
+ type SchemaType = Zashiki.SchemaType
169
+
170
+ type DocumentType = Zashiki.DocumentType
171
+ type HashType = Zashiki.HashType
172
+
173
+ export function transformArrayFor (document: DocumentType | undefined, schema: SchemaType | undefined, values: ObjectType | ObjectLiteralType | undefined, parentUri: string | undefined, uri: string | undefined): HashType | undefined
174
+ export function transformObjectFor (document: DocumentType | undefined, schema: SchemaType | undefined, values: ObjectType | ObjectLiteralType | undefined, parentUri: string | undefined, uri: string | undefined): HashType | undefined
175
+
176
+ export function transformArray (document: DocumentType | undefined, schema: SchemaType | undefined, values: ObjectType | ObjectLiteralType | undefined, parentUri: string | undefined, uri: string | undefined): HashType | undefined
177
+ export function transformObject (document: DocumentType | undefined, schema: SchemaType | undefined, values: ObjectType | ObjectLiteralType | undefined, parentUri: string | undefined, uri: string | undefined): HashType | undefined
178
+
179
+ export default function transform (document: DocumentType | undefined, schema: SchemaType | undefined, values: ObjectType | ObjectLiteralType | undefined, parentUri: string | undefined, uri: string | undefined): HashType | undefined
7
180
  }
8
181
 
9
182
  declare module 'shinkansen-transmission/transmission/from-hash-to-document' {
10
- export * from './transmission/from-hash-to-document.mjs'
183
+ type ObjectLiteralType = Zashiki.ObjectLiteralType
184
+ type ObjectType = Zashiki.ObjectType
185
+ type ArrayLiteralType = Zashiki.ArrayLiteralType
186
+ type ArrayType = Zashiki.ArrayType
187
+
188
+ type SchemaType = Zashiki.SchemaType
189
+
190
+ type DocumentType = Zashiki.DocumentType
191
+ type HashType = Zashiki.HashType
192
+
193
+ export function transformValueFor (document: DocumentType, array: ArrayType | ArrayLiteralType | undefined): DocumentType
194
+
195
+ export function getArrayFor (hash: HashType, array: ArrayType | ArrayLiteralType | undefined, uri: string | undefined): ArrayType | ArrayLiteralType
196
+
197
+ export function transformArrayFor (hash: HashType, schema: SchemaType, parentUri: string | undefined, uri: string | undefined): ArrayType | ArrayLiteralType
198
+ export function transformObjectFor (hash: HashType, schema: SchemaType, parentUri: string | undefined, uri: string | undefined): ObjectType | ObjectLiteralType
199
+
200
+ export function transformItemsArrayFor (hash: HashType, items: ArrayType | ArrayLiteralType | undefined, parentUri: string | undefined, uri: string | undefined): ArrayType | ArrayLiteralType | undefined
201
+ export function transformItemsObjectFor (hash: HashType, items: ObjectType | ObjectLiteralType | undefined, parentUri: string | undefined, uri: string | undefined): ArrayType | ArrayLiteralType | undefined
202
+
203
+ export function transformNull (hash: HashType, schema: SchemaType, parentUri: string, uri: string): null | undefined
204
+ export function transformBoolean (hash: HashType, schema: SchemaType, parentUri: string, uri: string): boolean | undefined
205
+ export function transformObject (hash: HashType, schema: SchemaType, parentUri: string, uri: string): ObjectType | ObjectLiteralType
206
+ export function transformArray (hash: HashType, schema: SchemaType, parentUri: string, uri: string): ArrayType | ArrayLiteralType
207
+ export function transformNumber (hash: HashType, schema: SchemaType, parentUri: string, uri: string): number | undefined
208
+ export function transformString (hash: HashType, schema: SchemaType, parentUri: string, uri: string): string | undefined
209
+
210
+ export default function transform (hash: HashType | undefined, rootSchema: SchemaType | undefined, parentUri: string | undefined, uri: string | undefined): DocumentType | undefined
11
211
  }
12
212
 
13
213
  declare module 'shinkansen-transmission/transmission/to-zashiki' {
14
- export * from './transmission/to-zashiki/index.mjs'
214
+ type SchemaType = Zashiki.SchemaType
215
+
216
+ type ObjectLiteralType = Zashiki.ObjectLiteralType
217
+ type ObjectType = Zashiki.ObjectType
218
+
219
+ type ZashikiType = Zashiki.ZashikiType
220
+
221
+ export default function toZashiki (rootSchema: SchemaType | undefined, values: ObjectType | ObjectLiteralType | undefined, params: ObjectType | ObjectLiteralType | undefined): ZashikiType | undefined
15
222
  }
16
223
 
17
224
  declare module 'shinkansen-transmission/transmission' {
@@ -10,6 +10,8 @@ export const isObject = (v) => (v || false) instanceof Object && !isArray(v)
10
10
 
11
11
  export const isArray = (v) => Array.isArray(v)
12
12
 
13
+ export const isPrimitive = (v) => !isObject(v) && !isArray(v)
14
+
13
15
  export const isSchema = (v = {}) => Reflect.has(v, 'type')
14
16
 
15
17
  export const isStringSchema = ({ type } = {}) => type === 'string'
@@ -24,8 +26,6 @@ export const isBooleanSchema = ({ type } = {}) => type === 'boolean'
24
26
 
25
27
  export const isNullSchema = ({ type } = {}) => type === 'null'
26
28
 
27
- export const isPrimitive = (v) => !isObject(v) && !isArray(v)
28
-
29
29
  export const getTitle = ({ title } = {}) => (title ? { title } : {})
30
30
 
31
31
  export const getDescription = ({ description } = {}) => (description ? { description } : {})
@@ -25,35 +25,35 @@ export {
25
25
  transformValue
26
26
  }
27
27
 
28
- export function transformArrayFor (document, schema, values, parentUri) { // }, uri) {
28
+ export function transformArrayFor (document, schema, hash, parentUri) { // }, uri) {
29
29
  /*
30
30
  * log('transformArrayFor')
31
31
  */
32
32
  return (
33
33
  document
34
- .reduce((values, value, index) => {
34
+ .reduce((hash, value, index) => {
35
35
  const schemaUri = getUri(parentUri, index)
36
36
 
37
- return transform(value, getSchema(schema, parentUri, schemaUri), values, schemaUri, schemaUri)
38
- }, values)
37
+ return transform(value, getSchema(schema, parentUri, schemaUri), hash, schemaUri, schemaUri)
38
+ }, hash)
39
39
  )
40
40
  }
41
41
 
42
- export function transformObjectFor (document, schema, values, parentUri) { // }, uri) {
42
+ export function transformObjectFor (document, schema, hash, parentUri) { // }, uri) {
43
43
  /*
44
44
  * log('transformObjectFor')
45
45
  */
46
46
  return (
47
47
  Object.entries(document)
48
- .reduce((values, [key, value]) => {
48
+ .reduce((hash, [key, value]) => {
49
49
  const schemaUri = getUri(parentUri, key)
50
50
 
51
- return transform(value, getSchema(schema, parentUri, schemaUri), values, schemaUri, schemaUri)
52
- }, values)
51
+ return transform(value, getSchema(schema, parentUri, schemaUri), hash, schemaUri, schemaUri)
52
+ }, hash)
53
53
  )
54
54
  }
55
55
 
56
- export function transformArray (document, schema, values, parentUri, uri) {
56
+ export function transformArray (document, schema, hash, parentUri, uri) {
57
57
  /*
58
58
  * log('transformArray')
59
59
  */
@@ -61,23 +61,23 @@ export function transformArray (document, schema, values, parentUri, uri) {
61
61
  if (hasEnum(schema)) {
62
62
  const array = getEnum(schema)
63
63
 
64
- values[uri] = document.map((value) => transformValueIndexFor(array, value))
64
+ hash[uri] = document.map((value) => transformValueIndexFor(array, value))
65
65
 
66
- return values
66
+ return hash
67
67
  } else {
68
68
  if (hasAnyOf(schema)) {
69
69
  const array = getAnyOf(schema)
70
70
 
71
- values[uri] = document.map((value) => transformValueIndexFor(array, value))
71
+ hash[uri] = document.map((value) => transformValueIndexFor(array, value))
72
72
 
73
- return values
73
+ return hash
74
74
  } else {
75
75
  if (hasOneOf(schema)) {
76
76
  const array = getOneOf(schema)
77
77
 
78
- values[uri] = document.map((value) => transformValueIndexFor(array, value))
78
+ hash[uri] = document.map((value) => transformValueIndexFor(array, value))
79
79
 
80
- return values
80
+ return hash
81
81
  } else {
82
82
  const { items = {} } = schema
83
83
 
@@ -85,7 +85,7 @@ export function transformArray (document, schema, values, parentUri, uri) {
85
85
  /*
86
86
  * Items is an array of schemas
87
87
  */
88
- return transformArrayFor(document, schema, values, parentUri, uri)
88
+ return transformArrayFor(document, schema, hash, parentUri, uri)
89
89
  } else {
90
90
  if (isObject(items)) {
91
91
  /*
@@ -94,23 +94,23 @@ export function transformArray (document, schema, values, parentUri, uri) {
94
94
  if (hasEnum(items)) {
95
95
  const array = getEnum(items)
96
96
 
97
- values[uri] = document.map((value) => transformValueIndexFor(array, value))
97
+ hash[uri] = document.map((value) => transformValueIndexFor(array, value))
98
98
 
99
- return values
99
+ return hash
100
100
  } else {
101
101
  if (hasAnyOf(items)) {
102
102
  const array = getAnyOf(items)
103
103
 
104
- values[uri] = document.map((value) => transformValueIndexFor(array, value))
104
+ hash[uri] = document.map((value) => transformValueIndexFor(array, value))
105
105
 
106
- return values
106
+ return hash
107
107
  } else {
108
108
  if (hasOneOf(items)) {
109
109
  const array = getOneOf(items)
110
110
 
111
- values[uri] = document.map((value) => transformValueIndexFor(array, value))
111
+ hash[uri] = document.map((value) => transformValueIndexFor(array, value))
112
112
 
113
- return values
113
+ return hash
114
114
  }
115
115
  }
116
116
  }
@@ -123,10 +123,10 @@ export function transformArray (document, schema, values, parentUri, uri) {
123
123
  /*
124
124
  * Transform schema
125
125
  */
126
- return transformArrayFor(document, schema, values, parentUri, uri) // schema not items
126
+ return transformArrayFor(document, schema, hash, parentUri, uri) // schema not items
127
127
  }
128
128
 
129
- export function transformObject (document, schema, values, parentUri, uri) {
129
+ export function transformObject (document, schema, hash, parentUri, uri) {
130
130
  /*
131
131
  * log('transformObject')
132
132
  */
@@ -134,23 +134,23 @@ export function transformObject (document, schema, values, parentUri, uri) {
134
134
  if (hasEnum(schema)) {
135
135
  const array = getEnum(schema)
136
136
 
137
- values[uri] = transformEqualIndexFor(array, document)
137
+ hash[uri] = transformEqualIndexFor(array, document)
138
138
 
139
- return values
139
+ return hash
140
140
  } else {
141
141
  if (hasAnyOf(schema)) {
142
142
  const array = getAnyOf(schema)
143
143
 
144
- values[uri] = transformEqualIndexFor(array, document)
144
+ hash[uri] = transformEqualIndexFor(array, document)
145
145
 
146
- return values
146
+ return hash
147
147
  } else {
148
148
  if (hasOneOf(schema)) {
149
149
  const array = getOneOf(schema)
150
150
 
151
- values[uri] = transformEqualIndexFor(array, document)
151
+ hash[uri] = transformEqualIndexFor(array, document)
152
152
 
153
- return values
153
+ return hash
154
154
  }
155
155
  }
156
156
  }
@@ -158,10 +158,10 @@ export function transformObject (document, schema, values, parentUri, uri) {
158
158
  /*
159
159
  * Transform schema
160
160
  */
161
- return transformObjectFor(document, schema, values, parentUri) // , uri)
161
+ return transformObjectFor(document, schema, hash, parentUri) // , uri)
162
162
  }
163
163
 
164
- export default function transform (document, schema = {}, values = {}, parentUri = '#', uri = getUri(parentUri)) {
164
+ export default function transform (document, schema = {}, hash = {}, parentUri = '#', uri = getUri(parentUri)) {
165
165
  log('fromDocumentToHash')
166
166
 
167
167
  /*
@@ -171,7 +171,7 @@ export default function transform (document, schema = {}, values = {}, parentUri
171
171
  /*
172
172
  * Yes, `document` is an array
173
173
  */
174
- return transformArray(document, schema, values, parentUri, uri)
174
+ return transformArray(document, schema, hash, parentUri, uri)
175
175
  } else {
176
176
  /*
177
177
  * Is `document` an object?
@@ -180,28 +180,28 @@ export default function transform (document, schema = {}, values = {}, parentUri
180
180
  /*
181
181
  * Yes, `document` is an object
182
182
  */
183
- return transformObject(document, schema, values, parentUri, uri)
183
+ return transformObject(document, schema, hash, parentUri, uri)
184
184
  } else {
185
185
  if (hasEnum(schema)) {
186
186
  const items = getEnum(schema)
187
187
 
188
- values[uri] = transformValueIndexFor(items, document)
188
+ hash[uri] = transformValueIndexFor(items, document)
189
189
 
190
- return values
190
+ return hash
191
191
  } else {
192
192
  if (hasAnyOf(schema)) {
193
193
  const items = getAnyOf(schema)
194
194
 
195
- values[uri] = transformValueIndexFor(items, document)
195
+ hash[uri] = transformValueIndexFor(items, document)
196
196
 
197
- return values
197
+ return hash
198
198
  } else {
199
199
  if (hasOneOf(schema)) {
200
200
  const items = getOneOf(schema)
201
201
 
202
- values[uri] = transformValueIndexFor(items, document)
202
+ hash[uri] = transformValueIndexFor(items, document)
203
203
 
204
- return values
204
+ return hash
205
205
  }
206
206
  }
207
207
  }
@@ -211,7 +211,7 @@ export default function transform (document, schema = {}, values = {}, parentUri
211
211
  /*
212
212
  * The hash should contain only strings
213
213
  */
214
- values[uri] = toString(document)
214
+ hash[uri] = toString(document)
215
215
 
216
- return values
216
+ return hash
217
217
  }
@@ -62,19 +62,19 @@ export {
62
62
  transformValue
63
63
  }
64
64
 
65
- export function transformValueFor (value, array) {
65
+ export function transformValueFor (document, array) {
66
66
  /*
67
67
  * log('transformValueFor')
68
68
  */
69
69
 
70
70
  try {
71
- const i = toNumber(value)
71
+ const i = toNumber(document)
72
72
 
73
73
  if (Reflect.has(array, i)) {
74
74
  const v = Reflect.get(array, i)
75
75
 
76
76
  /*
77
- * Return the value given from the schema
77
+ * Return the document given from the schema
78
78
  */
79
79
  return transformValue(v)
80
80
  }
@@ -83,18 +83,18 @@ export function transformValueFor (value, array) {
83
83
  }
84
84
 
85
85
  /*
86
- * Return the value given
86
+ * Return the document given
87
87
  */
88
- return value
88
+ return document
89
89
  }
90
90
 
91
- export function getArrayFor (values, array = [], uri = '#') {
91
+ export function getArrayFor (hash, array = [], uri = '#') {
92
92
  /*
93
93
  * log('getArrayFor')
94
94
  */
95
95
 
96
- if (Reflect.has(values, uri)) {
97
- const v = Reflect.get(values, uri)
96
+ if (Reflect.has(hash, uri)) {
97
+ const v = Reflect.get(hash, uri)
98
98
  const i = Number(v)
99
99
 
100
100
  if (!isNaN(i)) return array[i]
@@ -103,23 +103,23 @@ export function getArrayFor (values, array = [], uri = '#') {
103
103
  return []
104
104
  }
105
105
 
106
- export function transformArrayFor (values, { items = null } = {}, parentUri = '#', uri = getUri(parentUri)) {
106
+ export function transformArrayFor (hash, { items = null } = {}, parentUri = '#', uri = getUri(parentUri)) {
107
107
  /*
108
108
  * log('transformArrayFor')
109
109
  */
110
110
 
111
111
  if (isArray(items)) {
112
- return transformItemsArrayFor(values, items, parentUri, uri)
112
+ return transformItemsArrayFor(hash, items, parentUri, uri)
113
113
  } else {
114
114
  if (isObject(items)) {
115
- return transformItemsObjectFor(values, items, parentUri, uri)
115
+ return transformItemsObjectFor(hash, items, parentUri, uri)
116
116
  }
117
117
  }
118
118
 
119
119
  return []
120
120
  }
121
121
 
122
- export function transformObjectFor (values, { properties = null } = {}, parentUri = '#', uri = getUri(parentUri)) {
122
+ export function transformObjectFor (hash, { properties = null } = {}, parentUri = '#', uri = getUri(parentUri)) {
123
123
  /*
124
124
  * log('transformObjectFor')
125
125
  */
@@ -131,7 +131,7 @@ export function transformObjectFor (values, { properties = null } = {}, parentUr
131
131
  .reduce((accumulator, [key, schema]) => {
132
132
  const schemaUri = getUri(parentUri, key)
133
133
 
134
- accumulator[key] = transform(values, schema, schemaUri, schemaUri)
134
+ accumulator[key] = transform(hash, schema, schemaUri, schemaUri)
135
135
 
136
136
  return accumulator
137
137
  }, {})
@@ -141,22 +141,22 @@ export function transformObjectFor (values, { properties = null } = {}, parentUr
141
141
  return {}
142
142
  }
143
143
 
144
- export function transformItemsArrayFor (values, items = [], parentUri = '#', uri = getUri(parentUri)) {
144
+ export function transformItemsArrayFor (hash, items = [], parentUri = '#', uri = getUri(parentUri)) {
145
145
  /*
146
146
  * log('transformItemsArrayFor')
147
147
  */
148
148
 
149
- if (Reflect.has(values, uri)) {
150
- const value = Reflect.get(values, uri)
149
+ if (Reflect.has(hash, uri)) {
150
+ const document = Reflect.get(hash, uri)
151
151
 
152
- if (isArray(value)) {
153
- return transform(values, items, uri, uri)
152
+ if (isArray(document)) {
153
+ return transform(hash, items, uri, uri)
154
154
  }
155
155
  }
156
156
 
157
157
  return (
158
158
  Object
159
- .keys(values)
159
+ .keys(hash)
160
160
  .filter((key) => key.startsWith(uri))
161
161
  .reduce((accumulator, key) => {
162
162
  const v = uri.endsWith('/') ? key.slice(uri.length) : key.slice(uri.length + 1)
@@ -165,7 +165,7 @@ export function transformItemsArrayFor (values, items = [], parentUri = '#', uri
165
165
  if (!isNaN(i)) {
166
166
  const schemaUri = getUri(parentUri, i)
167
167
 
168
- accumulator[i] = transform(values, items[i], schemaUri, schemaUri) // items[i]
168
+ accumulator[i] = transform(hash, items[i], schemaUri, schemaUri) // items[i]
169
169
  }
170
170
 
171
171
  return accumulator
@@ -173,22 +173,22 @@ export function transformItemsArrayFor (values, items = [], parentUri = '#', uri
173
173
  )
174
174
  }
175
175
 
176
- export function transformItemsObjectFor (values, items = {}, parentUri = '#', uri = getUri(parentUri)) {
176
+ export function transformItemsObjectFor (hash, items = {}, parentUri = '#', uri = getUri(parentUri)) {
177
177
  /*
178
178
  * log('transformItemsObjectFor')
179
179
  */
180
180
 
181
- if (Reflect.has(values, uri)) {
182
- const value = Reflect.get(values, uri)
181
+ if (Reflect.has(hash, uri)) {
182
+ const document = Reflect.get(hash, uri)
183
183
 
184
- if (isArray(value)) {
185
- return transform(values, items, uri, uri)
184
+ if (isArray(document)) {
185
+ return transform(hash, items, uri, uri)
186
186
  }
187
187
  }
188
188
 
189
189
  return (
190
190
  Object
191
- .keys(values)
191
+ .keys(hash)
192
192
  .filter((key) => key.startsWith(uri))
193
193
  .reduce((accumulator, key) => {
194
194
  const v = uri.endsWith('/') ? key.slice(uri.length) : key.slice(uri.length + 1)
@@ -197,7 +197,7 @@ export function transformItemsObjectFor (values, items = {}, parentUri = '#', ur
197
197
  if (!isNaN(i)) {
198
198
  const schemaUri = getUri(parentUri, i)
199
199
 
200
- accumulator[i] = transform(values, items, schemaUri, schemaUri) // items
200
+ accumulator[i] = transform(hash, items, schemaUri, schemaUri) // items
201
201
  }
202
202
 
203
203
  return accumulator
@@ -205,87 +205,87 @@ export function transformItemsObjectFor (values, items = {}, parentUri = '#', ur
205
205
  )
206
206
  }
207
207
 
208
- export function transformNull (values, schema, parentUri, uri) {
208
+ export function transformNull (hash, schema, parentUri, uri) {
209
209
  /*
210
210
  * log('transformNull')
211
211
  */
212
212
 
213
- if (Reflect.has(values, uri)) {
214
- const value = Reflect.get(values, uri)
213
+ if (Reflect.has(hash, uri)) {
214
+ const document = Reflect.get(hash, uri)
215
215
 
216
216
  if (hasEnum(schema)) {
217
217
  const array = getEnum(schema)
218
218
 
219
- if (isArray(value)) return value.map((v) => transformValueFor(v, array))
220
- return transformValueFor(value, array)
219
+ if (isArray(document)) return document.map((v) => transformValueFor(v, array))
220
+ return transformValueFor(document, array)
221
221
  } else {
222
222
  if (hasAnyOf(schema)) {
223
223
  const array = getAnyOf(schema)
224
224
 
225
- if (isArray(value)) return value.map((v) => transformValueFor(v, array))
226
- return transformValueFor(value, array)
225
+ if (isArray(document)) return document.map((v) => transformValueFor(v, array))
226
+ return transformValueFor(document, array)
227
227
  } else {
228
228
  if (hasOneOf(schema)) {
229
229
  const array = getOneOf(schema)
230
230
 
231
- if (isArray(value)) return value.map((v) => transformValueFor(v, array))
232
- return transformValueFor(value, array)
231
+ if (isArray(document)) return document.map((v) => transformValueFor(v, array))
232
+ return transformValueFor(document, array)
233
233
  }
234
234
  }
235
235
  }
236
236
 
237
237
  try {
238
- if (isArray(value)) return value.map(toNull)
239
- return toNull(value)
238
+ if (isArray(document)) return document.map(toNull)
239
+ return toNull(document)
240
240
  } catch (e) {
241
241
  handleError(e)
242
242
  }
243
243
 
244
- return value
244
+ return document
245
245
  }
246
246
  }
247
247
 
248
- export function transformBoolean (values, schema, parentUri, uri) {
248
+ export function transformBoolean (hash, schema, parentUri, uri) {
249
249
  /*
250
250
  * log('transformBoolean')
251
251
  */
252
252
 
253
- if (Reflect.has(values, uri)) {
254
- const value = Reflect.get(values, uri)
253
+ if (Reflect.has(hash, uri)) {
254
+ const document = Reflect.get(hash, uri)
255
255
 
256
256
  if (hasEnum(schema)) {
257
257
  const array = getEnum(schema)
258
258
 
259
- if (isArray(value)) return value.map((v) => transformValueFor(v, array))
260
- return transformValueFor(value, array)
259
+ if (isArray(document)) return document.map((v) => transformValueFor(v, array))
260
+ return transformValueFor(document, array)
261
261
  } else {
262
262
  if (hasAnyOf(schema)) {
263
263
  const array = getAnyOf(schema)
264
264
 
265
- if (isArray(value)) return value.map((v) => transformValueFor(v, array))
266
- return transformValueFor(value, array)
265
+ if (isArray(document)) return document.map((v) => transformValueFor(v, array))
266
+ return transformValueFor(document, array)
267
267
  } else {
268
268
  if (hasOneOf(schema)) {
269
269
  const array = getOneOf(schema)
270
270
 
271
- if (isArray(value)) return value.map((v) => transformValueFor(v, array))
272
- return transformValueFor(value, array)
271
+ if (isArray(document)) return document.map((v) => transformValueFor(v, array))
272
+ return transformValueFor(document, array)
273
273
  }
274
274
  }
275
275
  }
276
276
 
277
277
  try {
278
- if (isArray(value)) return value.map(toBoolean)
279
- return toBoolean(value)
278
+ if (isArray(document)) return document.map(toBoolean)
279
+ return toBoolean(document)
280
280
  } catch (e) {
281
281
  handleError(e)
282
282
  }
283
283
 
284
- return value
284
+ return document
285
285
  }
286
286
  }
287
287
 
288
- export function transformObject (values, schema, parentUri, uri) {
288
+ export function transformObject (hash, schema, parentUri, uri) {
289
289
  /*
290
290
  * log('transformObject')
291
291
  */
@@ -293,25 +293,25 @@ export function transformObject (values, schema, parentUri, uri) {
293
293
  if (hasEnum(schema)) {
294
294
  const array = getEnum(schema)
295
295
 
296
- return getArrayFor(values, array, uri)
296
+ return getArrayFor(hash, array, uri)
297
297
  } else {
298
298
  if (hasAnyOf(schema)) {
299
299
  const array = getAnyOf(schema)
300
300
 
301
- return getArrayFor(values, array, uri)
301
+ return getArrayFor(hash, array, uri)
302
302
  } else {
303
303
  if (hasOneOf(schema)) {
304
304
  const array = getOneOf(schema)
305
305
 
306
- return getArrayFor(values, array, uri)
306
+ return getArrayFor(hash, array, uri)
307
307
  }
308
308
  }
309
309
  }
310
310
 
311
- return transformObjectFor(values, schema, parentUri, uri)
311
+ return transformObjectFor(hash, schema, parentUri, uri)
312
312
  }
313
313
 
314
- export function transformArray (values, schema, parentUri, uri) {
314
+ export function transformArray (hash, schema, parentUri, uri) {
315
315
  /*
316
316
  * log('transformArray')
317
317
  */
@@ -319,105 +319,105 @@ export function transformArray (values, schema, parentUri, uri) {
319
319
  if (hasEnum(schema)) {
320
320
  const array = getEnum(schema)
321
321
 
322
- return getArrayFor(values, array, uri)
322
+ return getArrayFor(hash, array, uri)
323
323
  } else {
324
324
  if (hasAnyOf(schema)) {
325
325
  const array = getAnyOf(schema)
326
326
 
327
- return getArrayFor(values, array, uri)
327
+ return getArrayFor(hash, array, uri)
328
328
  } else {
329
329
  if (hasOneOf(schema)) {
330
330
  const array = getOneOf(schema)
331
331
 
332
- return getArrayFor(values, array, uri)
332
+ return getArrayFor(hash, array, uri)
333
333
  }
334
334
  }
335
335
  }
336
336
 
337
- return transformArrayFor(values, schema, parentUri, uri)
337
+ return transformArrayFor(hash, schema, parentUri, uri)
338
338
  }
339
339
 
340
- export function transformNumber (values, schema, parentUri, uri) {
340
+ export function transformNumber (hash, schema, parentUri, uri) {
341
341
  /*
342
342
  * log('transformNumber')
343
343
  */
344
344
 
345
- if (Reflect.has(values, uri)) {
346
- const value = Reflect.get(values, uri)
345
+ if (Reflect.has(hash, uri)) {
346
+ const document = Reflect.get(hash, uri)
347
347
 
348
348
  if (hasEnum(schema)) {
349
349
  const array = getEnum(schema)
350
350
 
351
- if (isArray(value)) return value.map((v) => transformValueFor(v, array))
352
- return transformValueFor(value, array)
351
+ if (isArray(document)) return document.map((v) => transformValueFor(v, array))
352
+ return transformValueFor(document, array)
353
353
  } else {
354
354
  if (hasAnyOf(schema)) {
355
355
  const array = getAnyOf(schema)
356
356
 
357
- if (isArray(value)) return value.map((v) => transformValueFor(v, array))
358
- return transformValueFor(value, array)
357
+ if (isArray(document)) return document.map((v) => transformValueFor(v, array))
358
+ return transformValueFor(document, array)
359
359
  } else {
360
360
  if (hasOneOf(schema)) {
361
361
  const array = getOneOf(schema)
362
362
 
363
- if (isArray(value)) return value.map((v) => transformValueFor(v, array))
364
- return transformValueFor(value, array)
363
+ if (isArray(document)) return document.map((v) => transformValueFor(v, array))
364
+ return transformValueFor(document, array)
365
365
  }
366
366
  }
367
367
  }
368
368
 
369
369
  try {
370
- if (isArray(value)) return value.map(toNumber)
371
- return toNumber(value)
370
+ if (isArray(document)) return document.map(toNumber)
371
+ return toNumber(document)
372
372
  } catch (e) {
373
373
  handleError(e)
374
374
  }
375
375
 
376
- return value
376
+ return document
377
377
  }
378
378
  }
379
379
 
380
- export function transformString (values, schema, parentUri, uri) {
380
+ export function transformString (hash, schema, parentUri, uri) {
381
381
  /*
382
382
  * log('transformString')
383
383
  */
384
384
 
385
- if (Reflect.has(values, uri)) {
386
- const value = Reflect.get(values, uri)
385
+ if (Reflect.has(hash, uri)) {
386
+ const document = Reflect.get(hash, uri)
387
387
 
388
388
  if (hasEnum(schema)) {
389
389
  const array = getEnum(schema)
390
390
 
391
- if (isArray(value)) return value.map((v) => transformValueFor(v, array))
392
- return transformValueFor(value, array)
391
+ if (isArray(document)) return document.map((v) => transformValueFor(v, array))
392
+ return transformValueFor(document, array)
393
393
  } else {
394
394
  if (hasAnyOf(schema)) {
395
395
  const array = getAnyOf(schema)
396
396
 
397
- if (isArray(value)) return value.map((v) => transformValueFor(v, array))
398
- return transformValueFor(value, array)
397
+ if (isArray(document)) return document.map((v) => transformValueFor(v, array))
398
+ return transformValueFor(document, array)
399
399
  } else {
400
400
  if (hasOneOf(schema)) {
401
401
  const array = getOneOf(schema)
402
402
 
403
- if (isArray(value)) return value.map((v) => transformValueFor(v, array))
404
- return transformValueFor(value, array)
403
+ if (isArray(document)) return document.map((v) => transformValueFor(v, array))
404
+ return transformValueFor(document, array)
405
405
  }
406
406
  }
407
407
  }
408
408
 
409
409
  try {
410
- if (isArray(value)) return value.map(toString)
411
- return toString(value)
410
+ if (isArray(document)) return document.map(toString)
411
+ return toString(document)
412
412
  } catch (e) {
413
413
  handleError(e)
414
414
  }
415
415
 
416
- return value
416
+ return document
417
417
  }
418
418
  }
419
419
 
420
- export default function transform (values = {}, rootSchema = {}, parentUri = '#', uri = getUri(parentUri)) {
420
+ export default function transform (hash = {}, rootSchema = {}, parentUri = '#', uri = getUri(parentUri)) {
421
421
  log('fromHashToDocument')
422
422
 
423
423
  const { type } = rootSchema
@@ -425,22 +425,22 @@ export default function transform (values = {}, rootSchema = {}, parentUri = '#'
425
425
  // https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.2.1
426
426
  switch (type) {
427
427
  case 'null':
428
- return transformNull(values, rootSchema, parentUri, uri)
428
+ return transformNull(hash, rootSchema, parentUri, uri)
429
429
 
430
430
  case 'boolean':
431
- return transformBoolean(values, rootSchema, parentUri, uri)
431
+ return transformBoolean(hash, rootSchema, parentUri, uri)
432
432
 
433
433
  case 'object':
434
- return transformObject(values, rootSchema, parentUri, uri)
434
+ return transformObject(hash, rootSchema, parentUri, uri)
435
435
 
436
436
  case 'array':
437
- return transformArray(values, rootSchema, parentUri, uri)
437
+ return transformArray(hash, rootSchema, parentUri, uri)
438
438
 
439
439
  case 'number':
440
- return transformNumber(values, rootSchema, parentUri, uri)
440
+ return transformNumber(hash, rootSchema, parentUri, uri)
441
441
 
442
442
  case 'string':
443
- return transformString(values, rootSchema, parentUri, uri)
443
+ return transformString(hash, rootSchema, parentUri, uri)
444
444
 
445
445
  default:
446
446
  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')
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "NodeNext",
4
+ "target": "ESNext",
5
+ "moduleResolution": "NodeNext",
6
+ "noEmit": true,
7
+ "strict": true,
8
+ "isolatedModules": true,
9
+ "baseUrl": "."
10
+ }
11
+ }