@json-layout/core 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@json-layout/core",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Compilation and state management utilities for JSON Layout.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -58,7 +58,7 @@
58
58
  },
59
59
  "homepage": "https://github.com/json-layout/json-layout#readme",
60
60
  "peerDependencies": {
61
- "@json-layout/vocabulary": "^1.5.0"
61
+ "@json-layout/vocabulary": "^1.5.1"
62
62
  },
63
63
  "dependencies": {
64
64
  "ajv": "^8.17.1",
@@ -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 '../utils/clone.js'
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 })
@@ -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 '../utils/clone.js'
6
- import { isSwitchStruct } from '@json-layout/vocabulary'
5
+ import { clone, isSwitchStruct } from '@json-layout/vocabulary'
7
6
 
8
7
  /**
9
8
  * @generator
@@ -51,11 +51,16 @@ export function makeSkeletonNode (
51
51
  schema = { ...rawSchema, ...refFragment }
52
52
  delete schema.$ref
53
53
  }
54
- const knownNullable = mergeNullableSubSchema(schema)
54
+ const nullableType = mergeNullableSubSchema(schema)
55
+ if (nullableType) {
56
+ schema = nullableType
57
+ if (pointer === refPointer) pointer = schema.__pointer
58
+ refPointer = schema.__pointer
59
+ }
55
60
  const resolvedSchema = partialResolveRefs(schema, schemaId, getJSONRef)
56
61
  let { type, nullable } = getSchemaFragmentType(resolvedSchema)
57
62
  if (knownType) type = knownType
58
- if (knownNullable) nullable = knownNullable
63
+ if (nullableType) nullable = true
59
64
 
60
65
  // improve on ajv error messages based on ajv-errors (https://ajv.js.org/packages/ajv-errors.html)
61
66
  rawSchema.errorMessage = rawSchema.errorMessage ?? {}
@@ -1,4 +1,4 @@
1
- import clone from '../../utils/clone.js'
1
+ import { clone } from '@json-layout/vocabulary'
2
2
 
3
3
  /**
4
4
  * @param {Record<string, import('ajv').SchemaObject>} schemas
package/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './compile/index.js'
2
2
  export * from './state/index.js'
3
3
  export { default as i18n } from './i18n/index.js'
4
- export { default as clone } from './utils/clone.js'
4
+ export { clone } from '@json-layout/vocabulary'
@@ -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,CAiG1B;;;;2BAjHY,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
+ {"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":"AAoBA;;;GAGG;AACH,0CAHW,OAAO,YAAY,EAAE,cAAc,GACjC,MAAM,CAmFlB"}
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,CAyf7C"}
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
@@ -1,5 +1,5 @@
1
1
  export * from "./compile/index.js";
2
2
  export * from "./state/index.js";
3
3
  export { default as i18n } from "./i18n/index.js";
4
- export { default as clone } from "./utils/clone.js";
4
+ export { clone } from "@json-layout/vocabulary";
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -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()
@@ -1,3 +0,0 @@
1
- declare function _default(o: any): any;
2
- export default _default;
3
- //# sourceMappingURL=clone.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"clone.d.ts","sourceRoot":"","sources":["../../src/utils/clone.js"],"names":[],"mappings":"AAoCE,uCAyBC"}