@json-layout/core 1.13.0 → 1.14.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 +2 -2
- package/src/compile/options.js +1 -4
- package/src/compile/serialize.js +27 -1
- package/src/compile/skeleton-node.js +10 -8
- package/src/compile/types.ts +0 -1
- package/types/compile/options.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/compile/types.d.ts +0 -1
- package/types/compile/types.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@json-layout/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.1",
|
|
4
4
|
"description": "Compilation and state management utilities for JSON Layout.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
},
|
|
77
77
|
"homepage": "https://github.com/json-layout/json-layout#readme",
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"@json-layout/vocabulary": "^2.
|
|
79
|
+
"@json-layout/vocabulary": "^2.8.0"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
82
|
"ajv": "^8.17.1",
|
package/src/compile/options.js
CHANGED
|
@@ -23,9 +23,7 @@ export const fillOptions = (partialOptions) => {
|
|
|
23
23
|
let ajv = partialOptions.ajv
|
|
24
24
|
if (!ajv) {
|
|
25
25
|
/** @type {import('ajv').Options} */
|
|
26
|
-
const ajvOpts = { allErrors: true, strict: false, verbose: true }
|
|
27
|
-
if (partialOptions.ajvOptions) Object.assign(ajvOpts, partialOptions.ajvOptions)
|
|
28
|
-
if (partialOptions.code) ajvOpts.code = { source: true, esm: true, lines: true }
|
|
26
|
+
const ajvOpts = { allErrors: true, strict: false, verbose: true, ...partialOptions.ajvOptions }
|
|
29
27
|
const newAjv = new Ajv(ajvOpts)
|
|
30
28
|
addFormats.default(newAjv)
|
|
31
29
|
ajvErrors.default(newAjv)
|
|
@@ -61,7 +59,6 @@ export const fillOptions = (partialOptions) => {
|
|
|
61
59
|
|
|
62
60
|
return {
|
|
63
61
|
ajv,
|
|
64
|
-
code: false,
|
|
65
62
|
markdown,
|
|
66
63
|
useDescription: ['help', 'subtitle'],
|
|
67
64
|
useDefault: 'data',
|
package/src/compile/serialize.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
// import Debug from 'debug'
|
|
2
|
+
import ajvModule from 'ajv/dist/2019.js'
|
|
3
|
+
import addFormats from 'ajv-formats'
|
|
4
|
+
import ajvErrors from 'ajv-errors'
|
|
2
5
|
import { ok } from 'assert/strict'
|
|
3
6
|
import standaloneCode from 'ajv/dist/standalone/index.js'
|
|
4
7
|
import { parseModule, generateCode, builders } from 'magicast'
|
|
5
8
|
import { clone } from '../utils/clone.js'
|
|
6
9
|
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
const Ajv = /** @type {typeof ajvModule.default} */ (ajvModule)
|
|
12
|
+
|
|
7
13
|
/**
|
|
8
14
|
* @param {import('./index.js').CompiledLayout} compiledLayout
|
|
9
15
|
* @returns {string}
|
|
@@ -11,7 +17,27 @@ import { clone } from '../utils/clone.js'
|
|
|
11
17
|
export function serialize (compiledLayout) {
|
|
12
18
|
ok(compiledLayout.schema)
|
|
13
19
|
ok(compiledLayout.options)
|
|
14
|
-
|
|
20
|
+
|
|
21
|
+
// we get the schemas that were extended by makeSleletonNode
|
|
22
|
+
/** @type {Record<string, any>} */
|
|
23
|
+
const schemas = {}
|
|
24
|
+
for (const [key, value] of Object.entries(compiledLayout.options.ajv.schemas)) {
|
|
25
|
+
if (key.startsWith('https://json-schema.org/')) continue
|
|
26
|
+
schemas[key] = value?.schema
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** @type {import('ajv').Options} */
|
|
30
|
+
const ajvOpts = {
|
|
31
|
+
allErrors: true,
|
|
32
|
+
strict: false,
|
|
33
|
+
verbose: true,
|
|
34
|
+
...compiledLayout.options.ajvOptions,
|
|
35
|
+
code: { source: true, esm: true, lines: true },
|
|
36
|
+
schemas
|
|
37
|
+
}
|
|
38
|
+
const ajv = new Ajv(ajvOpts)
|
|
39
|
+
addFormats.default(ajv)
|
|
40
|
+
ajvErrors.default(ajv)
|
|
15
41
|
|
|
16
42
|
/** @type {Record<string, string>} */
|
|
17
43
|
const validatesExports = {}
|
|
@@ -65,6 +65,8 @@ export function makeSkeletonNode (
|
|
|
65
65
|
if (pointer === refPointer) pointer = schema.__pointer
|
|
66
66
|
refPointer = schema.__pointer
|
|
67
67
|
}
|
|
68
|
+
const refPointerPrefix = (refPointer === schema.$id) ? refPointer += '#' : refPointer
|
|
69
|
+
|
|
68
70
|
const resolvedSchema = partialResolveRefs(schema, schemaId, getJSONRef)
|
|
69
71
|
let { type, nullable } = getSchemaFragmentType(resolvedSchema)
|
|
70
72
|
if (knownType) type = knownType
|
|
@@ -207,7 +209,7 @@ export function makeSkeletonNode (
|
|
|
207
209
|
node.propertyKeys.push(propertyKey)
|
|
208
210
|
if (schema.properties[propertyKey].readOnly) node.roPropertyKeys.push(propertyKey)
|
|
209
211
|
const dependent = schema.dependentRequired && Object.values(schema.dependentRequired).some(dependentProperties => dependentProperties.includes(propertyKey))
|
|
210
|
-
const childPointer = `${
|
|
212
|
+
const childPointer = `${refPointerPrefix}/properties/${propertyKey}`
|
|
211
213
|
if (!skeletonNodes[childPointer]) {
|
|
212
214
|
// @ts-ignore
|
|
213
215
|
skeletonNodes[childPointer] = 'recursing'
|
|
@@ -233,7 +235,7 @@ export function makeSkeletonNode (
|
|
|
233
235
|
|
|
234
236
|
if (schema.dependentSchemas?.[propertyKey] || (schema.dependencies?.[propertyKey] && !Array.isArray(schema.dependencies[propertyKey]))) {
|
|
235
237
|
const dependentSchema = schema.dependentSchemas?.[propertyKey] ?? schema.dependencies[propertyKey]
|
|
236
|
-
const dependentPointer = schema.dependentSchemas?.[propertyKey] ? `${
|
|
238
|
+
const dependentPointer = schema.dependentSchemas?.[propertyKey] ? `${refPointerPrefix}/dependentSchemas/${propertyKey}` : `${refPointerPrefix}/dependencies/${propertyKey}`
|
|
237
239
|
if (!skeletonNodes[dependentPointer]) {
|
|
238
240
|
// @ts-ignore
|
|
239
241
|
skeletonNodes[dependentPointer] = 'recursing'
|
|
@@ -263,7 +265,7 @@ export function makeSkeletonNode (
|
|
|
263
265
|
}
|
|
264
266
|
if (schema.allOf) {
|
|
265
267
|
for (let i = 0; i < schema.allOf.length; i++) {
|
|
266
|
-
const childPointer = `${
|
|
268
|
+
const childPointer = `${refPointerPrefix}/allOf/${i}`
|
|
267
269
|
if (!skeletonNodes[childPointer]) {
|
|
268
270
|
// @ts-ignore
|
|
269
271
|
skeletonNodes[childPointer] = 'recursing'
|
|
@@ -296,7 +298,7 @@ export function makeSkeletonNode (
|
|
|
296
298
|
/** @type {string | undefined} */
|
|
297
299
|
let discriminator
|
|
298
300
|
if (schema.discriminator?.propertyName) discriminator = schema.discriminator?.propertyName
|
|
299
|
-
const oneOfPointer = `${
|
|
301
|
+
const oneOfPointer = `${refPointerPrefix}/oneOf`
|
|
300
302
|
if (!normalizedLayouts[oneOfPointer]) {
|
|
301
303
|
const normalizationResult = normalizeLayoutFragment(
|
|
302
304
|
'',
|
|
@@ -420,7 +422,7 @@ export function makeSkeletonNode (
|
|
|
420
422
|
if (schema.if) {
|
|
421
423
|
validatePointers.push(`${pointer}/if`)
|
|
422
424
|
if (schema.then) {
|
|
423
|
-
const childPointer = `${
|
|
425
|
+
const childPointer = `${refPointerPrefix}/then`
|
|
424
426
|
if (!skeletonNodes[childPointer]) {
|
|
425
427
|
// @ts-ignore
|
|
426
428
|
skeletonNodes[childPointer] = 'recursing'
|
|
@@ -447,7 +449,7 @@ export function makeSkeletonNode (
|
|
|
447
449
|
node.children.push(childPointer)
|
|
448
450
|
}
|
|
449
451
|
if (schema.else) {
|
|
450
|
-
const childPointer = `${
|
|
452
|
+
const childPointer = `${refPointerPrefix}/else`
|
|
451
453
|
if (!skeletonNodes[childPointer]) {
|
|
452
454
|
// @ts-ignore
|
|
453
455
|
skeletonNodes[childPointer] = 'recursing'
|
|
@@ -492,7 +494,7 @@ export function makeSkeletonNode (
|
|
|
492
494
|
for (let i = 0; i < schema.items.length; i++) {
|
|
493
495
|
/** @type {any} */
|
|
494
496
|
const itemSchema = schema.items[i]
|
|
495
|
-
const childPointer = `${
|
|
497
|
+
const childPointer = `${refPointerPrefix}/items/${i}`
|
|
496
498
|
if (!skeletonNodes[childPointer]) {
|
|
497
499
|
// @ts-ignore
|
|
498
500
|
skeletonNodes[childPointer] = 'recursing'
|
|
@@ -515,7 +517,7 @@ export function makeSkeletonNode (
|
|
|
515
517
|
node.children.push(childPointer)
|
|
516
518
|
}
|
|
517
519
|
} else {
|
|
518
|
-
const childTreePointer = `${
|
|
520
|
+
const childTreePointer = `${refPointerPrefix}/items`
|
|
519
521
|
if (!skeletonTrees[childTreePointer]) {
|
|
520
522
|
// @ts-ignore
|
|
521
523
|
skeletonTrees[childTreePointer] = 'recursing'
|
package/src/compile/types.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/compile/options.js"],"names":[],"mappings":"AAqBO,4CAHI,qBAAqB,GACnB,cAAc,
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/compile/options.js"],"names":[],"mappings":"AAqBO,4CAHI,qBAAqB,GACnB,cAAc,CAwD1B;AAGD,yGAAyG;AACzG,oCADW,CAAC,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,qBAAqB,KAAK,qBAAqB,CAiBnG;6BArFW,OAAO,YAAY,EAAE,cAAc;oCACnC,OAAO,YAAY,EAAE,qBAAqB"}
|
|
@@ -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":"AAYA;;;GAGG;AACH,0CAHW,OAAO,YAAY,EAAE,cAAc,GACjC,MAAM,CA6FlB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skeleton-node.d.ts","sourceRoot":"","sources":["../../src/compile/skeleton-node.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;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":"AAMA;;;;;;;;;;;;;;;;;;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,CAuhB7C"}
|
package/types/compile/types.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ export type CompiledExpression = (data: any, dataAlias: any, options: StateNodeO
|
|
|
12
12
|
export type CompileOptions = NormalizeOptions & {
|
|
13
13
|
ajv: ajvModule.default;
|
|
14
14
|
ajvOptions?: ajvModule.Options;
|
|
15
|
-
code: boolean;
|
|
16
15
|
markedOptions?: MarkedOptions;
|
|
17
16
|
locale: string;
|
|
18
17
|
defaultLocale: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/compile/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAC3C,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,KAAK,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,KAAK,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC3K,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,YAAY,EAAoB,MAAM,kBAAkB,CAAA;AAC7F,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEtD,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,OAAO,CAAA;IACb,MAAM,EAAE,uBA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