shinkansen-transmission 2.3.0 → 2.3.2

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.3.0",
3
+ "version": "2.3.2",
4
4
  "description": "Shinkansen Transmission",
5
5
  "keywords": [
6
6
  "Shinkansen",
@@ -44,8 +44,8 @@
44
44
  "@babel/eslint-parser": "^7.26.8",
45
45
  "@babel/preset-env": "^7.26.9",
46
46
  "@babel/register": "^7.25.9",
47
- "@sequencemedia/eslint-config-standard": "^0.2.29",
48
- "@sequencemedia/eslint-config-typescript": "^0.1.43",
47
+ "@sequencemedia/eslint-config-standard": "^0.2.31",
48
+ "@sequencemedia/eslint-config-typescript": "^0.1.46",
49
49
  "@types/babel__register": "^7.17.3",
50
50
  "@types/chai": "^5.0.1",
51
51
  "@types/debug": "^4.1.12",
package/src/index.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  export type SchemaType = TransmissionTypes.SchemaType
2
-
3
2
  export type DocumentType = TransmissionTypes.DocumentType
4
3
  export type HashType = TransmissionTypes.HashType
5
4
 
@@ -1,38 +1,38 @@
1
- type ObjectLiteralType = TransmissionTypes.ObjectLiteralType
2
- type ObjectType = TransmissionTypes.ObjectType
3
-
4
- type ItemsType = TransmissionTypes.ItemsType
5
-
6
- type TransmissionStringMetaType = TransmissionTypes.Transmission.StringMetaType
7
- type TransmissionNumberMetaType = TransmissionTypes.Transmission.NumberMetaType
8
- type TransmissionArrayMetaType = TransmissionTypes.Transmission.ArrayMetaType
9
- type TransmissionObjectMetaType = TransmissionTypes.Transmission.ObjectMetaType
10
- type TransmissionBooleanMetaType = TransmissionTypes.Transmission.BooleanMetaType
11
- type TransmissionNullMetaType = TransmissionTypes.Transmission.NullMetaType
12
-
13
- type TransmissionStringElementsType = TransmissionTypes.Transmission.StringElementsType
14
- type TransmissionNumberElementsType = TransmissionTypes.Transmission.NumberElementsType
15
- type TransmissionArrayElementsType = TransmissionTypes.Transmission.ArrayElementsType
16
- type TransmissionObjectElementsType = TransmissionTypes.Transmission.ObjectElementsType
17
- type TransmissionBooleanElementsType = TransmissionTypes.Transmission.BooleanElementsType
18
- type TransmissionNullElementsType = TransmissionTypes.Transmission.NullElementsType
19
-
20
- type EnumType = TransmissionTypes.EnumType
21
- type OneOfType = TransmissionTypes.OneOfType
22
- type AnyOfType = TransmissionTypes.AnyOfType
23
- type FieldType = TransmissionTypes.FieldType
24
-
25
- type SchemaType = TransmissionTypes.SchemaType
26
-
27
- type StringSchemaType = TransmissionTypes.StringSchemaType
28
- type NumberSchemaType = TransmissionTypes.NumberSchemaType
29
- type ArraySchemaType = TransmissionTypes.ArraySchemaType
30
- type ObjectSchemaType = TransmissionTypes.ObjectSchemaType
31
- type BooleanSchemaType = TransmissionTypes.BooleanSchemaType
32
- type NullSchemaType = TransmissionTypes.NullSchemaType
33
-
34
- type ValuesType = TransmissionTypes.ValuesType
35
- type ParamsType = TransmissionTypes.ParamsType
1
+ export type ObjectLiteralType = TransmissionTypes.ObjectLiteralType
2
+ export type ObjectType = TransmissionTypes.ObjectType
3
+
4
+ export type ItemsType = TransmissionTypes.ItemsType
5
+
6
+ export type StringMetaType = TransmissionTypes.Transmission.StringMetaType
7
+ export type NumberMetaType = TransmissionTypes.Transmission.NumberMetaType
8
+ export type ArrayMetaType = TransmissionTypes.Transmission.ArrayMetaType
9
+ export type ObjectMetaType = TransmissionTypes.Transmission.ObjectMetaType
10
+ export type BooleanMetaType = TransmissionTypes.Transmission.BooleanMetaType
11
+ export type NullMetaType = TransmissionTypes.Transmission.NullMetaType
12
+
13
+ export type StringElementsType = TransmissionTypes.Transmission.StringElementsType
14
+ export type NumberElementsType = TransmissionTypes.Transmission.NumberElementsType
15
+ export type ArrayElementsType = TransmissionTypes.Transmission.ArrayElementsType
16
+ export type ObjectElementsType = TransmissionTypes.Transmission.ObjectElementsType
17
+ export type BooleanElementsType = TransmissionTypes.Transmission.BooleanElementsType
18
+ export type NullElementsType = TransmissionTypes.Transmission.NullElementsType
19
+
20
+ export type EnumType = TransmissionTypes.EnumType
21
+ export type OneOfType = TransmissionTypes.OneOfType
22
+ export type AnyOfType = TransmissionTypes.AnyOfType
23
+ export type FieldType = TransmissionTypes.FieldType
24
+
25
+ export type SchemaType = TransmissionTypes.SchemaType
26
+
27
+ export type StringSchemaType = TransmissionTypes.StringSchemaType
28
+ export type NumberSchemaType = TransmissionTypes.NumberSchemaType
29
+ export type ArraySchemaType = TransmissionTypes.ArraySchemaType
30
+ export type ObjectSchemaType = TransmissionTypes.ObjectSchemaType
31
+ export type BooleanSchemaType = TransmissionTypes.BooleanSchemaType
32
+ export type NullSchemaType = TransmissionTypes.NullSchemaType
33
+
34
+ export type ValuesType = TransmissionTypes.ValuesType
35
+ export type ParamsType = TransmissionTypes.ParamsType
36
36
 
37
37
  export function isObject (v?: unknown): v is (Record<PropertyKey, string | number | object | boolean | null | string[] | number[] | object[] | boolean[] | null[]> | Record<PropertyKey, never>)
38
38
  export function isArray (v?: unknown): v is (string[] | number[] | object[] | boolean[] | null[])
@@ -55,7 +55,7 @@ export function getSelectedItems (values?: ValuesType, uri?: string): Array<stri
55
55
 
56
56
  export function isParentUri (parentUri?: string, uri?: string): boolean
57
57
 
58
- export function getMetaProps (params?: ParamsType, uri?: string): TransmissionStringMetaType | TransmissionNumberMetaType | TransmissionArrayMetaType | TransmissionObjectMetaType | TransmissionBooleanMetaType | TransmissionNullMetaType | Record<string, never>
58
+ export function getMetaProps (params?: ParamsType, uri?: string): StringMetaType | NumberMetaType | ArrayMetaType | ObjectMetaType | BooleanMetaType | NullMetaType | Record<string, never>
59
59
  export function hasMetaDefaultValue (schema?: SchemaType): boolean
60
60
  export function getMetaDefaultValue (schema?: SchemaType): { defaultValue: string } | ObjectLiteralType
61
61
  export function hasMetaValue (values?: ValuesType, uri?: string, schema?: SchemaType): boolean
@@ -63,7 +63,8 @@ export function getMetaValue (values?: ValuesType, uri?: string, schema?: Schema
63
63
 
64
64
  export function transformToValue (schema?: string | number | object | boolean | null): string | number | object | boolean | null | undefined
65
65
 
66
- export function findByUri (parentUri: string, uri: string): (key: string | number) => boolean
66
+ export function findByKey (parentUri: string, uri: string): (key: string | number) => boolean
67
+ export function findByIndex (parentUri: string, uri: string): (item: SchemaType, index: number) => boolean
67
68
  export function findByValue (value?: string | number | object | boolean | null): (item?: string | number | object | boolean | null | string[] | number[] | object[] | boolean[] | null[]) => boolean
68
69
  export function findByEqual (value?: string | number | object | boolean | null): (item?: string | number | object | boolean | null | string[] | number[] | object[] | boolean[] | null[]) => boolean
69
70
 
@@ -108,7 +109,7 @@ export function getIndexForAnyOf (values?: ValuesType, parentUri?: string, uri?:
108
109
  export function getValueForOneOf (v: string | number, schema?: { oneOf?: ItemsType }): string
109
110
  export function getIndexForOneOf (values: ValuesType, parentUri?: string, uri?: string, schema?: SchemaType): number
110
111
 
111
- export function getElementsProps (params?: ParamsType, uri?: string): TransmissionStringElementsType | TransmissionNumberElementsType | TransmissionArrayElementsType | TransmissionObjectElementsType | TransmissionBooleanElementsType | TransmissionNullElementsType | Record<string, never>
112
+ export function getElementsProps (params?: ParamsType, uri?: string): StringElementsType | NumberElementsType | ArrayElementsType | ObjectElementsType | BooleanElementsType | NullElementsType | Record<string, never>
112
113
 
113
114
  export function getElementsFieldPropsForEnum (params?: ParamsType, uri?: string): EnumType | ObjectLiteralType
114
115
  export function getElementsFieldPropsForOneOf (params?: ParamsType, uri?: string): OneOfType | ObjectLiteralType
@@ -328,9 +328,9 @@ export function transformToValue (item) {
328
328
  * @param {string} uri
329
329
  * @returns {(key: string | number) => boolean}
330
330
  */
331
- export function findByUri (parentUri, uri) {
331
+ export function findByKey (parentUri, uri) {
332
332
  /*
333
- * log('findByUri')
333
+ * log('findByKey')
334
334
  */
335
335
  return function find (key) {
336
336
  /*
@@ -343,6 +343,60 @@ export function findByUri (parentUri, uri) {
343
343
  }
344
344
  }
345
345
 
346
+ /**
347
+ * @param {string} parentUri
348
+ * @param {string} uri
349
+ * @returns {(item: SchemaType, index: number) => boolean}
350
+ */
351
+ export function findByIndex (parentUri, uri) {
352
+ /*
353
+ * log('findByIndex')
354
+ */
355
+ return function find (item, index) {
356
+ /*
357
+ * log('find')
358
+ */
359
+
360
+ /**
361
+ * It's a schema not a value
362
+ */
363
+
364
+ if (hasEnum(item)) {
365
+ /**
366
+ * Do the `parentUri` and `uri` match?
367
+ */
368
+
369
+ return (
370
+ getUri(parentUri, index) === uri
371
+ )
372
+ } else {
373
+ if (hasAnyOf(item)) {
374
+ const array = getAnyOf(item)
375
+
376
+ return (
377
+ array.filter(isObject).some(findByIndex(parentUri, uri))
378
+ )
379
+ } else {
380
+ if (hasOneOf(item)) {
381
+ const array = getOneOf(item)
382
+
383
+ return (
384
+ array.filter(isObject).some(findByIndex(parentUri, uri))
385
+ )
386
+ }
387
+ }
388
+ }
389
+
390
+ /**
391
+ * It's any other kind of schema/sub-schema
392
+ */
393
+
394
+ return (
395
+ getUri(parentUri, index) === uri
396
+ )
397
+ }
398
+ }
399
+
346
400
  /**
347
401
  * @param {string | number | object | boolean | null} [value]
348
402
  * @returns {(item?: string | number | object | boolean | null | string[] | number[] | object[] | boolean[] | null[]) => boolean}
@@ -395,14 +449,17 @@ export function toString (value) {
395
449
  * @param {string} uri
396
450
  * @returns {SchemaType | undefined}
397
451
  */
398
- function getArray ({ items /* array or object */ } = {}, parentUri = '', uri = '') {
452
+ export function getArray ({ items /* array or object */ } = {}, parentUri = '', uri = '') {
453
+ /*
454
+ * log('getArray')
455
+ */
456
+
399
457
  if (isArray(items)) {
400
- const keys = Object.keys(items).map(Number)
401
- const find = findByUri(parentUri, uri)
458
+ const find = findByIndex(parentUri, uri)
402
459
 
403
- const key = keys.find(find)
404
- if (typeof key === 'number') return items[key]
405
- return undefined
460
+ return (
461
+ items.find(find)
462
+ )
406
463
  }
407
464
 
408
465
  if (isObject(items)) return items
@@ -422,11 +479,14 @@ export function getObject ({ properties /* object */ } = {}, parentUri = '', uri
422
479
  */
423
480
 
424
481
  if (isObject(properties)) {
425
- const keys = Object.keys(properties).map(String)
426
- const find = findByUri(parentUri, uri)
482
+ const find = findByKey(parentUri, uri)
483
+ const key = Object.keys(properties).find(find)
427
484
 
428
- const key = keys.find(find)
429
- if (typeof key === 'string') return properties[key]
485
+ if (key) {
486
+ return (
487
+ properties[key]
488
+ )
489
+ }
430
490
  }
431
491
 
432
492
  return undefined
@@ -456,6 +516,7 @@ export function getSchema (schema = {}, parentUri = '', uri = '') {
456
516
  /*
457
517
  * log('getSchema')
458
518
  */
519
+
459
520
  const {
460
521
  type
461
522
  } = schema
@@ -1,6 +1,6 @@
1
- type DocumentType = TransmissionTypes.DocumentType
2
- type SchemaType = TransmissionTypes.SchemaType
3
- type HashType = TransmissionTypes.HashType
1
+ export type DocumentType = TransmissionTypes.DocumentType
2
+ export type SchemaType = TransmissionTypes.SchemaType
3
+ export type HashType = TransmissionTypes.HashType
4
4
 
5
5
  export function transformArrayFor (document: DocumentType[], schema: { type: string }, hash: HashType, parentUri: string): HashType
6
6
  export function transformObjectFor (document: Record<string, DocumentType>, schema: { type: string }, hash: HashType, parentUri: string): HashType
@@ -1,27 +1,26 @@
1
- type ObjectLiteralType = TransmissionTypes.ObjectLiteralType
2
- type ObjectType = TransmissionTypes.ObjectType
3
- type ArrayLiteralType = TransmissionTypes.ArrayLiteralType
4
- type ArrayType = TransmissionTypes.ArrayType
1
+ export type ObjectLiteralType = TransmissionTypes.ObjectLiteralType
2
+ export type ObjectType = TransmissionTypes.ObjectType
3
+ export type ArrayLiteralType = TransmissionTypes.ArrayLiteralType
4
+ export type ArrayType = TransmissionTypes.ArrayType
5
5
 
6
- type SchemaType = TransmissionTypes.SchemaType
7
-
8
- type DocumentType = TransmissionTypes.DocumentType
9
- type HashType = TransmissionTypes.HashType
6
+ export type SchemaType = TransmissionTypes.SchemaType
7
+ export type DocumentType = TransmissionTypes.DocumentType
8
+ export type HashType = TransmissionTypes.HashType
10
9
 
11
10
  export function toNull (v: unknown): null
12
11
  export function toBoolean (v: unknown): boolean
13
12
  export function toString (v: unknown): string
14
13
  export function toNumber (v: unknown): number
15
14
 
16
- export function transformValueFor (document: DocumentType, array: ArrayLiteralType | ArrayType | undefined): DocumentType
15
+ export function transformValueFor (document: DocumentType, array?: ArrayLiteralType | ArrayType): DocumentType
17
16
 
18
- export function getArrayFor (hash: HashType, array: ArrayLiteralType | ArrayType | undefined, uri?: string): ArrayLiteralType | ArrayType
17
+ export function getArrayFor (hash: HashType, array?: ArrayLiteralType | ArrayType, uri?: string): ArrayLiteralType | ArrayType
19
18
 
20
19
  export function transformArrayFor (hash: HashType, schema: SchemaType, parentUri?: string, uri?: string): ArrayLiteralType | ArrayType
21
20
  export function transformObjectFor (hash: HashType, schema: SchemaType, parentUri?: string, uri?: string): ObjectLiteralType | ObjectType
22
21
 
23
- export function transformItemsArrayFor (hash: HashType, items: ArrayLiteralType | ArrayType | undefined, parentUri?: string, uri?: string): ArrayLiteralType | ArrayType | undefined
24
- export function transformItemsObjectFor (hash: HashType, items: ObjectLiteralType | ObjectType | undefined, parentUri?: string, uri?: string): ArrayLiteralType | ArrayType | undefined
22
+ export function transformItemsArrayFor (hash: HashType, items?: ArrayLiteralType | ArrayType, parentUri?: string, uri?: string): ArrayLiteralType | ArrayType | undefined
23
+ export function transformItemsObjectFor (hash: HashType, items?: ObjectLiteralType | ObjectType, parentUri?: string, uri?: string): ArrayLiteralType | ArrayType | undefined
25
24
 
26
25
  export function transformNull (hash: HashType, schema: SchemaType, parentUri: string, uri: string): null | undefined
27
26
  export function transformBoolean (hash: HashType, schema: SchemaType, parentUri: string, uri: string): boolean | undefined
@@ -1,3 +1,9 @@
1
+ export type SchemaType = TransmissionTypes.SchemaType
2
+ export type DocumentType = TransmissionTypes.DocumentType
3
+ export type HashType = TransmissionTypes.HashType
4
+
5
+ export type ZashikiType = TransmissionTypes.Zashiki.ZashikiType
6
+
1
7
  export * as common from '#transmission/transmission/common'
2
8
  export { default as fromDocumentToHash } from '#transmission/transmission/from-document-to-hash'
3
9
  export { default as fromHashToDocument } from '#transmission/transmission/from-hash-to-document'