@json-layout/core 1.4.4 → 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 +4 -2
- package/src/compile/index.js +2 -1
- package/src/compile/serialize.js +1 -2
- package/src/compile/skeleton-node.js +8 -1
- package/src/compile/utils/resolve-refs.js +1 -1
- package/src/index.js +1 -1
- package/types/compile/index.d.ts.map +1 -1
- package/types/compile/serialize.d.ts.map +1 -1
- package/types/compile/skeleton-node.d.ts.map +1 -1
- package/types/index.d.ts +1 -1
- package/src/utils/clone.js +0 -65
- package/types/utils/clone.d.ts +0 -3
- package/types/utils/clone.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@json-layout/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Compilation and state management utilities for JSON Layout.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -57,8 +57,10 @@
|
|
|
57
57
|
"url": "https://github.com/json-layout/json-layout/issues"
|
|
58
58
|
},
|
|
59
59
|
"homepage": "https://github.com/json-layout/json-layout#readme",
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"@json-layout/vocabulary": "^1.5.1"
|
|
62
|
+
},
|
|
60
63
|
"dependencies": {
|
|
61
|
-
"@json-layout/vocabulary": "~1.4.2",
|
|
62
64
|
"ajv": "^8.17.1",
|
|
63
65
|
"ajv-errors": "^3.0.0",
|
|
64
66
|
"ajv-formats": "^3.0.1",
|
package/src/compile/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import ajvLocalizeModule from 'ajv-i18n'
|
|
|
5
5
|
import { makeSkeletonTree } from './skeleton-tree.js'
|
|
6
6
|
import { resolveLocaleRefs } from './utils/resolve-refs.js'
|
|
7
7
|
import { resolveXI18n } from './utils/x-i18n.js'
|
|
8
|
-
import clone from '
|
|
8
|
+
import { clone } from '@json-layout/vocabulary'
|
|
9
9
|
import { fillOptions } from './options.js'
|
|
10
10
|
|
|
11
11
|
export { resolveLocaleRefs } from './utils/resolve-refs.js'
|
|
@@ -77,6 +77,7 @@ export function compile (_schema, partialOptions = {}) {
|
|
|
77
77
|
const uriResolver = options.ajv.opts.uriResolver
|
|
78
78
|
/** @type {Record<string, import('ajv').ValidateFunction>} */
|
|
79
79
|
const validates = {}
|
|
80
|
+
|
|
80
81
|
for (const pointer of validatePointers) {
|
|
81
82
|
const fullPointer = uriResolver.resolve(schema.$id, pointer)
|
|
82
83
|
validates[pointer] = options.ajv.compile({ $ref: fullPointer })
|
package/src/compile/serialize.js
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
import { ok } from 'assert/strict'
|
|
3
3
|
import standaloneCode from 'ajv/dist/standalone/index.js'
|
|
4
4
|
import { parseModule, generateCode, builders } from 'magicast'
|
|
5
|
-
import clone from '
|
|
6
|
-
import { isSwitchStruct } from '@json-layout/vocabulary'
|
|
5
|
+
import { clone, isSwitchStruct } from '@json-layout/vocabulary'
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* @generator
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// import Debug from 'debug'
|
|
2
|
-
import { normalizeLayoutFragment, isSwitchStruct, isGetItemsExpression, isGetItemsFetch, isItemsLayout, getSchemaFragmentType, isCompositeLayout, childIsCompositeCompObject } from '@json-layout/vocabulary'
|
|
2
|
+
import { normalizeLayoutFragment, mergeNullableSubSchema, isSwitchStruct, isGetItemsExpression, isGetItemsFetch, isItemsLayout, getSchemaFragmentType, isCompositeLayout, childIsCompositeCompObject } from '@json-layout/vocabulary'
|
|
3
3
|
import { makeSkeletonTree } from './skeleton-tree.js'
|
|
4
4
|
import { partialResolveRefs } from './utils/resolve-refs.js'
|
|
5
5
|
|
|
@@ -51,9 +51,16 @@ export function makeSkeletonNode (
|
|
|
51
51
|
schema = { ...rawSchema, ...refFragment }
|
|
52
52
|
delete schema.$ref
|
|
53
53
|
}
|
|
54
|
+
const nullableType = mergeNullableSubSchema(schema)
|
|
55
|
+
if (nullableType) {
|
|
56
|
+
schema = nullableType
|
|
57
|
+
if (pointer === refPointer) pointer = schema.__pointer
|
|
58
|
+
refPointer = schema.__pointer
|
|
59
|
+
}
|
|
54
60
|
const resolvedSchema = partialResolveRefs(schema, schemaId, getJSONRef)
|
|
55
61
|
let { type, nullable } = getSchemaFragmentType(resolvedSchema)
|
|
56
62
|
if (knownType) type = knownType
|
|
63
|
+
if (nullableType) nullable = true
|
|
57
64
|
|
|
58
65
|
// improve on ajv error messages based on ajv-errors (https://ajv.js.org/packages/ajv-errors.html)
|
|
59
66
|
rawSchema.errorMessage = rawSchema.errorMessage ?? {}
|
package/src/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compile/index.js"],"names":[],"mappings":"AA4BA;;;;GAIG;AACH,iCAJW,MAAM,mBACN,qBAAqB,GACnB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compile/index.js"],"names":[],"mappings":"AA4BA;;;;GAIG;AACH,iCAJW,MAAM,mBACN,qBAAqB,GACnB,cAAc,CAkG1B;;;;2BAlHY,OAAO,YAAY,EAAE,YAAY;2BACjC,OAAO,YAAY,EAAE,YAAY;6BACjC,OAAO,YAAY,EAAE,cAAc;6BACnC,OAAO,YAAY,EAAE,cAAc;oCACnC,OAAO,YAAY,EAAE,qBAAqB;iCAC1C,OAAO,YAAY,EAAE,kBAAkB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/compile/serialize.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/compile/serialize.js"],"names":[],"mappings":"AAmBA;;;GAGG;AACH,0CAHW,OAAO,YAAY,EAAE,cAAc,GACjC,MAAM,CAmFlB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skeleton-node.d.ts","sourceRoot":"","sources":["../../src/compile/skeleton-node.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;GAkBG;AACH,4CAlBW,GAAG,kBACH,MAAM,WACN,OAAO,YAAY,EAAE,cAAc,cACnC,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,iBACxD,MAAM,CAAC,MAAM,EAAE,OAAO,YAAY,EAAE,YAAY,CAAC,iBACjD,MAAM,CAAC,MAAM,EAAE,OAAO,YAAY,EAAE,YAAY,CAAC,oBACjD,MAAM,EAAE,oBACR,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,qBACxB,MAAM,CAAC,MAAM,EAAE,OAAO,yBAAyB,EAAE,gBAAgB,CAAC,eAClE,OAAO,yBAAyB,EAAE,UAAU,EAAE,OAC9C,MAAM,GAAG,MAAM,WACf,MAAM,YACN,OAAO,cACP,MAAM,cACN,OAAO,cACP,MAAM,GACJ,OAAO,YAAY,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"skeleton-node.d.ts","sourceRoot":"","sources":["../../src/compile/skeleton-node.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;GAkBG;AACH,4CAlBW,GAAG,kBACH,MAAM,WACN,OAAO,YAAY,EAAE,cAAc,cACnC,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,iBACxD,MAAM,CAAC,MAAM,EAAE,OAAO,YAAY,EAAE,YAAY,CAAC,iBACjD,MAAM,CAAC,MAAM,EAAE,OAAO,YAAY,EAAE,YAAY,CAAC,oBACjD,MAAM,EAAE,oBACR,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,qBACxB,MAAM,CAAC,MAAM,EAAE,OAAO,yBAAyB,EAAE,gBAAgB,CAAC,eAClE,OAAO,yBAAyB,EAAE,UAAU,EAAE,OAC9C,MAAM,GAAG,MAAM,WACf,MAAM,YACN,OAAO,cACP,MAAM,cACN,OAAO,cACP,MAAM,GACJ,OAAO,YAAY,EAAE,YAAY,CA8f7C"}
|
package/types/index.d.ts
CHANGED
package/src/utils/clone.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
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 default rfdc()
|
package/types/utils/clone.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clone.d.ts","sourceRoot":"","sources":["../../src/utils/clone.js"],"names":[],"mappings":"AAoCE,uCAyBC"}
|