shinkansen-transmission 2.3.0 → 2.3.1

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.1",
4
4
  "description": "Shinkansen Transmission",
5
5
  "keywords": [
6
6
  "Shinkansen",
@@ -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
 
@@ -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