@json-layout/vocabulary 1.5.0 → 1.5.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 +1 -1
- package/src/index.js +1 -0
- package/src/normalize.js +12 -7
- package/src/utils/clone.js +67 -0
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/normalize.d.ts +1 -1
- package/types/normalize.d.ts.map +1 -1
- package/types/utils/clone.d.ts +3 -0
- package/types/utils/clone.d.ts.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@json-layout/vocabulary",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Main JSON Layout vocabulary as JSON schemas and Typescript types. Also contains some small utility functions to validate and normalize annotations.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
package/src/index.js
CHANGED
package/src/normalize.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { validateLayoutKeyword, isComponentName, isPartialCompObject, isPartialChildren, isPartialSwitch, isPartialGetItemsExpr, isPartialGetItemsObj, isPartialSlotMarkdown, isPartialGetItemsFetch, isPartialChildComposite, isPartialChildSlot, isPartialSlotText, isPartialSlotName } from './layout-keyword/index.js'
|
|
2
2
|
import { validateNormalizedLayout } from './normalized-layout/index.js'
|
|
3
3
|
import { getComponentValidate } from './validate.js'
|
|
4
|
+
import clone from './utils/clone.js'
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @typedef {import('./index.js').Child} Child
|
|
@@ -293,7 +294,7 @@ function getItemsFromSchema (schemaFragment) {
|
|
|
293
294
|
|
|
294
295
|
/**
|
|
295
296
|
* @param {SchemaFragment} schemaFragment
|
|
296
|
-
* @returns {
|
|
297
|
+
* @returns {[SchemaFragment, string] | undefined}
|
|
297
298
|
*/
|
|
298
299
|
export const mergeNullableSubSchema = (schemaFragment) => {
|
|
299
300
|
/** @type {null | 'oneOf' | 'anyOf'} */
|
|
@@ -309,12 +310,16 @@ export const mergeNullableSubSchema = (schemaFragment) => {
|
|
|
309
310
|
delete schemaFragment[subTypesKey]
|
|
310
311
|
} */
|
|
311
312
|
if (subTypes && subTypes.length === 2 && subTypes.some(t => t.type === 'null')) {
|
|
312
|
-
const
|
|
313
|
-
if (
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
313
|
+
const subTypeIndex = subTypes.findIndex(t => t.type !== 'null')
|
|
314
|
+
if (subTypeIndex !== -1) {
|
|
315
|
+
const subType = subTypes[subTypeIndex]
|
|
316
|
+
const nullableType = clone(schemaFragment)
|
|
317
|
+
for (const key in subType) {
|
|
318
|
+
if (!(key in nullableType)) nullableType[key] = subType[key]
|
|
319
|
+
}
|
|
320
|
+
delete nullableType[subTypesKey]
|
|
321
|
+
nullableType.__pointer = nullableType.__pointer + `/${subTypesKey}/${subTypeIndex}`
|
|
322
|
+
return nullableType
|
|
318
323
|
}
|
|
319
324
|
}
|
|
320
325
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/require-jsdoc */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
|
|
4
|
+
// a copy of https://github.com/davidmarkclements/rfdc/blob/master/index.js
|
|
5
|
+
// but lighter and with ESM export
|
|
6
|
+
|
|
7
|
+
function copyBuffer (cur) {
|
|
8
|
+
if (cur instanceof Buffer) {
|
|
9
|
+
return Buffer.from(cur)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return new cur.constructor(cur.buffer.slice(), cur.byteOffset, cur.length)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function rfdc () {
|
|
16
|
+
return clone
|
|
17
|
+
|
|
18
|
+
function cloneArray (a, fn) {
|
|
19
|
+
const keys = Object.keys(a)
|
|
20
|
+
const a2 = new Array(keys.length)
|
|
21
|
+
for (let i = 0; i < keys.length; i++) {
|
|
22
|
+
const k = keys[i]
|
|
23
|
+
const cur = a[k]
|
|
24
|
+
if (typeof cur !== 'object' || cur === null) {
|
|
25
|
+
a2[k] = cur
|
|
26
|
+
} else if (cur instanceof Date) {
|
|
27
|
+
a2[k] = new Date(cur)
|
|
28
|
+
} else if (ArrayBuffer.isView(cur)) {
|
|
29
|
+
a2[k] = copyBuffer(cur)
|
|
30
|
+
} else {
|
|
31
|
+
a2[k] = fn(cur)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return a2
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function clone (o) {
|
|
38
|
+
if (typeof o !== 'object' || o === null) return o
|
|
39
|
+
if (o instanceof Date) return new Date(o)
|
|
40
|
+
if (Array.isArray(o)) return cloneArray(o, clone)
|
|
41
|
+
if (o instanceof Map) return new Map(cloneArray(Array.from(o), clone))
|
|
42
|
+
if (o instanceof Set) return new Set(cloneArray(Array.from(o), clone))
|
|
43
|
+
const o2 = {}
|
|
44
|
+
for (const k in o) {
|
|
45
|
+
if (Object.hasOwnProperty.call(o, k) === false) continue
|
|
46
|
+
const cur = o[k]
|
|
47
|
+
if (typeof cur !== 'object' || cur === null) {
|
|
48
|
+
o2[k] = cur
|
|
49
|
+
} else if (cur instanceof Date) {
|
|
50
|
+
o2[k] = new Date(cur)
|
|
51
|
+
} else if (cur instanceof Map) {
|
|
52
|
+
o2[k] = new Map(cloneArray(Array.from(cur), clone))
|
|
53
|
+
} else if (cur instanceof Set) {
|
|
54
|
+
o2[k] = new Set(cloneArray(Array.from(cur), clone))
|
|
55
|
+
} else if (ArrayBuffer.isView(cur)) {
|
|
56
|
+
o2[k] = copyBuffer(cur)
|
|
57
|
+
} else {
|
|
58
|
+
o2[k] = clone(cur)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return o2
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const clone = rfdc()
|
|
66
|
+
|
|
67
|
+
export default clone
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./layout-keyword/index.js";
|
|
2
2
|
export * from "./normalized-layout/index.js";
|
|
3
3
|
export * from "./components/index.js";
|
|
4
|
+
export * from "./utils/clone.js";
|
|
4
5
|
export type SchemaFragment = import("./types.js").SchemaFragment;
|
|
5
6
|
export type ComponentInfo = import("./types.js").ComponentInfo;
|
|
6
7
|
export { normalizeLayoutFragment, getSchemaFragmentType, mergeNullableSubSchema } from "./normalize.js";
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";;;;6BAAc,OAAO,YAAY,EAAE,cAAc;4BACnC,OAAO,YAAY,EAAE,aAAa"}
|
package/types/normalize.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export function normalizeLayoutFragment(key: string | number, schemaFragment: Sc
|
|
|
15
15
|
layout: NormalizedLayout;
|
|
16
16
|
errors: string[];
|
|
17
17
|
};
|
|
18
|
-
export function mergeNullableSubSchema(schemaFragment: SchemaFragment):
|
|
18
|
+
export function mergeNullableSubSchema(schemaFragment: SchemaFragment): [SchemaFragment, string] | undefined;
|
|
19
19
|
export function getSchemaFragmentType(schemaFragment: SchemaFragment): {
|
|
20
20
|
type: string | undefined;
|
|
21
21
|
nullable: boolean;
|
package/types/normalize.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../src/normalize.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../src/normalize.js"],"names":[],"mappings":"AA6qBA;;;;;;;;;;;;GAYG;AACH,6CAZW,MAAM,GAAG,MAAM,kBACf,cAAc,cACd,MAAM,cACN,MAAM,CAAC,MAAM,EAAE,OAAO,YAAY,EAAE,aAAa,CAAC,aAClD,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,+BACxB,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC,gBACnC,MAAM,EAAE,gBACR,OAAO,GAAG,mBAAmB,cAC7B,MAAM,GAAG,SAAS,kBAClB,OAAO,GACL;IAAC,MAAM,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAC,CAwBxD;AAtaM,uDAHI,cAAc,GACZ,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG,SAAS,CA6BhD;AAMM,sDAHI,cAAc,GACZ;IAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAC,CAkCzD;oBArWY,OAAO,YAAY,EAAE,KAAK;uBAC1B,OAAO,YAAY,EAAE,QAAQ;6BAC7B,OAAO,YAAY,EAAE,cAAc;yBACnC,OAAO,YAAY,EAAE,UAAU;+BAC/B,OAAO,YAAY,EAAE,gBAAgB;4BACrC,OAAO,YAAY,EAAE,aAAa;8BAClC,OAAO,YAAY,EAAE,eAAe;gCACpC,OAAO,YAAY,EAAE,iBAAiB;6BACtC,OAAO,YAAY,EAAE,cAAc"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clone.d.ts","sourceRoot":"","sources":["../../src/utils/clone.js"],"names":[],"mappings":"AAoCE,mCAyBC"}
|