@json-layout/core
Advanced tools
Comparing version 0.10.0 to 0.11.0
{ | ||
"name": "@json-layout/core", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"description": "Compilation and state management utilities for JSON Layout.", | ||
@@ -62,3 +62,3 @@ "type": "module", | ||
"dependencies": { | ||
"@json-layout/vocabulary": "^0.10.0", | ||
"@json-layout/vocabulary": "^0.11.0", | ||
"@types/markdown-it": "^13.0.1", | ||
@@ -65,0 +65,0 @@ "ajv": "^8.12.0", |
@@ -9,2 +9,3 @@ // compileStatic is meant to produce a serializable result | ||
import MarkdownIt from 'markdown-it' | ||
import { produce } from 'immer' | ||
import i18n from '../i18n/index.js' | ||
@@ -33,2 +34,13 @@ import { makeSkeletonTree } from './skeleton-tree.js' | ||
// use Immer for efficient updating with immutability and no-op detection | ||
/** @type {(draft: PartialCompileOptions, newOptions: PartialCompileOptions) => PartialCompileOptions} */ | ||
export const produceCompileOptions = produce((draft, newOptions) => { | ||
for (const key of ['ajv', 'ajvOptions', 'code', 'markdown', 'markdownItOptions', 'locale', 'messages', 'optionsKeys']) { | ||
// @ts-ignore | ||
if (key in newOptions) draft[key] = newOptions[key] | ||
// @ts-ignore | ||
else delete draft[key] | ||
} | ||
}) | ||
/** | ||
@@ -35,0 +47,0 @@ * @param {PartialCompileOptions} partialOptions |
// import Debug from 'debug' | ||
import { normalizeLayoutFragment, isSwitchStruct, isGetItemsExpression, isGetItemsFetch, isItemsLayout } from '@json-layout/vocabulary' | ||
import { normalizeLayoutFragment, isSwitchStruct, isGetItemsExpression, isGetItemsFetch, isItemsLayout, getSchemaFragmentType } from '@json-layout/vocabulary' | ||
import { makeSkeletonTree } from './skeleton-tree.js' | ||
@@ -30,4 +30,3 @@ | ||
) { | ||
// consolidate schema | ||
if (!schema.type && schema.properties) schema.type = 'object' | ||
const { type, nullable } = getSchemaFragmentType(schema) | ||
@@ -53,4 +52,5 @@ // improve on ajv error messages based on ajv-errors (https://ajv.js.org/packages/ajv-errors.html) | ||
else if (required) { | ||
if (schema.type === 'object') defaultData = {} | ||
if (schema.type === 'array') defaultData = [] | ||
if (nullable) defaultData = null | ||
else if (type === 'object') defaultData = {} | ||
else if (type === 'array') defaultData = [] | ||
} | ||
@@ -108,3 +108,3 @@ | ||
const node = { key: key ?? '', pointer, parentPointer, pure, propertyKeys: [], roPropertyKeys: [] } | ||
if (schema.type === 'object') { | ||
if (type === 'object') { | ||
if (schema.properties) { | ||
@@ -172,3 +172,3 @@ node.children = node.children ?? [] | ||
for (let i = 0; i < schema.oneOf.length; i++) { | ||
if (!schema.oneOf[i].type) schema.oneOf[i].type = schema.type | ||
if (!schema.oneOf[i].type) schema.oneOf[i].type = type | ||
const title = schema.oneOf[i].title ?? `option ${i}` | ||
@@ -202,3 +202,3 @@ delete schema.oneOf[i].title | ||
if (schema.type === 'array' && schema.items) { | ||
if (type === 'array' && schema.items) { | ||
if (Array.isArray(schema.items)) { | ||
@@ -205,0 +205,0 @@ node.children = schema.items.map((/** @type {any} */ itemSchema, /** @type {number} */ i) => { |
@@ -8,2 +8,4 @@ /** | ||
export { resolveRefs } from "./utils/resolve-refs.js"; | ||
/** @type {(draft: PartialCompileOptions, newOptions: PartialCompileOptions) => PartialCompileOptions} */ | ||
export const produceCompileOptions: (draft: PartialCompileOptions, newOptions: PartialCompileOptions) => PartialCompileOptions; | ||
export type SkeletonTree = import('./types.js').SkeletonTree; | ||
@@ -10,0 +12,0 @@ export type SkeletonNode = import('./types.js').SkeletonNode; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
127027
2859
+ Added@json-layout/vocabulary@0.11.0(transitive)
- Removed@json-layout/vocabulary@0.10.0(transitive)