@fgv/ts-json 4.6.0 → 5.0.0-10

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.
Files changed (33) hide show
  1. package/CHANGELOG.json +15 -0
  2. package/CHANGELOG.md +9 -1
  3. package/dist/ts-json.d.ts +739 -28
  4. package/lib/index.d.ts +2 -0
  5. package/lib/index.d.ts.map +1 -1
  6. package/lib/index.js +25 -0
  7. package/lib/index.js.map +1 -1
  8. package/lib/packlets/diff/detailedDiff.d.ts +375 -0
  9. package/lib/packlets/diff/detailedDiff.d.ts.map +1 -0
  10. package/lib/packlets/diff/detailedDiff.js +342 -0
  11. package/lib/packlets/diff/detailedDiff.js.map +1 -0
  12. package/lib/packlets/diff/index.d.ts +3 -0
  13. package/lib/packlets/diff/index.d.ts.map +1 -0
  14. package/lib/packlets/diff/index.js +40 -0
  15. package/lib/packlets/diff/index.js.map +1 -0
  16. package/lib/packlets/diff/threeWayDiff.d.ts +263 -0
  17. package/lib/packlets/diff/threeWayDiff.d.ts.map +1 -0
  18. package/lib/packlets/diff/threeWayDiff.js +261 -0
  19. package/lib/packlets/diff/threeWayDiff.js.map +1 -0
  20. package/lib/packlets/diff/utils.d.ts +6 -0
  21. package/lib/packlets/diff/utils.d.ts.map +1 -0
  22. package/lib/packlets/diff/utils.js +62 -0
  23. package/lib/packlets/diff/utils.js.map +1 -0
  24. package/lib/packlets/editor/common.d.ts +24 -0
  25. package/lib/packlets/editor/common.d.ts.map +1 -1
  26. package/lib/packlets/editor/common.js.map +1 -1
  27. package/lib/packlets/editor/jsonEditor.d.ts +57 -28
  28. package/lib/packlets/editor/jsonEditor.d.ts.map +1 -1
  29. package/lib/packlets/editor/jsonEditor.js +119 -31
  30. package/lib/packlets/editor/jsonEditor.js.map +1 -1
  31. package/lib/packlets/editor/jsonEditorState.js +1 -1
  32. package/lib/packlets/editor/jsonEditorState.js.map +1 -1
  33. package/package.json +6 -6
@@ -1 +1 @@
1
- {"version":3,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,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;gBAC5E,MAAM;YACR,KAAK,wBAAwB;gBAC3B,MAAM,GAAG,SAAS,CAAC,wBAAwB,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;gBAC7E,oBAAoB;gBACpB,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,kCAAkC,CAAC;gBACxD,MAAM;QACV,CAAC;QACD,oBAAoB;QACpB,OAAO,IAAA,yBAAc,EAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC;;AAzLH,0CA0LC;AAzLC;;;;GAIG;AACc,uBAAO,GAAW,CAAC,AAAZ,CAAa","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { JsonObject } from '@fgv/ts-json-base';\nimport { DetailedFailure, Result, failWithDetail, succeed } from '@fgv/ts-utils';\nimport { IJsonContext, IJsonReferenceMap, JsonContextHelper, TemplateVars, VariableValue } from '../context';\nimport {\n IJsonCloneEditor,\n IJsonEditorOptions,\n IJsonEditorValidationOptions,\n JsonEditFailureReason,\n JsonEditorValidationRules,\n JsonPropertyEditFailureReason\n} from './common';\n\n/**\n * Represents the internal state of a {@link JsonEditor | JsonEditor}.\n * @public\n */\nexport class JsonEditorState {\n /**\n * Static global counter used to assign each {@link JsonEditorState | JsonEditorState}\n * a unique identifier.\n * @internal\n */\n protected static _nextId: number = 0;\n\n /**\n * The {@link IJsonCloneEditor | editor} for which this state applies.\n */\n public readonly editor: IJsonCloneEditor;\n\n /**\n * Fully resolved {@link IJsonEditorOptions | editor options} that apply\n * to the operation for which this state applies.\n */\n public readonly options: IJsonEditorOptions;\n\n /**\n * Any deferred JSON objects to be merged during finalization.\n * @internal\n */\n protected readonly _deferred: JsonObject[] = [];\n\n /**\n * Unique global identifier for this {@link JsonEditorState | state object}.\n * @internal\n */\n protected readonly _id: number;\n\n /**\n * Constructs a new {@link JsonEditorState | JsonEditorState}.\n * @param editor - The {@link IJsonCloneEditor | editor} to which this state\n * applies.\n * @param baseOptions - The {@link IJsonEditorOptions | editor options} that\n * apply to this rule.\n * @param runtimeContext - An optional {@link IJsonContext | JSON context} to be used\n * for json value conversion.\n */\n public constructor(\n editor: IJsonCloneEditor,\n baseOptions: IJsonEditorOptions,\n runtimeContext?: IJsonContext\n ) {\n this.editor = editor;\n this.options = JsonEditorState._getEffectiveOptions(baseOptions, runtimeContext).orThrow();\n this._id = JsonEditorState._nextId++;\n }\n\n /**\n * The optional {@link IJsonContext | JSON context} for this state.\n */\n public get context(): IJsonContext | undefined {\n return this.options.context;\n }\n\n /**\n * An array of JSON objects that were deferred for merge during\n * finalization.\n */\n public get deferred(): JsonObject[] {\n return this._deferred;\n }\n\n /**\n * Merges an optional {@link IJsonContext | JSON context} into a supplied set\n * of {@link IJsonEditorOptions | JSON editor options}.\n * @param options - The {@link IJsonEditorOptions | IJsonEditorOptions} into\n * which the the new context is to be merged.\n * @param context - The {@link IJsonContext | JSON context} to be merged into the\n * editor options.\n * @returns `Success` with the supplied {@link IJsonEditorOptions | options} if\n * there was nothing to merge, or aa new {@link IJsonEditorOptions | IJsonEditorOptions}\n * constructed from the base options merged with the supplied context. Returns `Failure`\n * with more information if an error occurs.\n * @internal\n */\n protected static _getEffectiveOptions(\n options: IJsonEditorOptions,\n context?: IJsonContext\n ): Result<IJsonEditorOptions> {\n if (!context) {\n return succeed(options);\n }\n return JsonContextHelper.mergeContext(options.context, context).onSuccess((merged) => {\n return succeed({ context: merged, validation: options.validation });\n });\n }\n\n /**\n * Adds a supplied `JsonObject` to the deferred list.\n * @param obj - The `JsonObject` to be deferred.\n */\n public defer(obj: JsonObject): void {\n this._deferred.push(obj);\n }\n\n /**\n * Gets a {@link TemplateVars | TemplateVars} from the context of this {@link JsonEditorState | JsonEditorState},\n * or from an optional supplied {@link IJsonContext | IJsonContext} if the current state has no default\n * context.\n * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as `TemplateVars`\n * if the current state does not have context.\n * @returns A {@link TemplateVars | TemplateVars} reflecting the appropriate {@link IJsonContext | JSON context}, or\n * `undefined` if no vars are found.\n */\n public getVars(defaultContext?: IJsonContext): TemplateVars | undefined {\n /* c8 ignore next */ // c8 seems to be struggling atm\n return this.options.context?.vars ?? defaultContext?.vars;\n }\n\n /**\n * Gets an {@link IJsonReferenceMap | reference map} containing any other values\n * referenced during the operation.\n * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as\n * {@link TemplateVars | TemplateVars} if the current state does not have context.\n * @returns An {@link IJsonReferenceMap | IJsonReferenceMap} containing any values referenced\n * during this operation.\n */\n public getRefs(defaultContext?: IJsonContext): IJsonReferenceMap | undefined {\n /* c8 ignore next */ // c8 seems to be struggling atm\n return this.options.context?.refs ?? defaultContext?.refs;\n }\n\n /**\n * Gets the context of this {@link JsonEditorState | JsonEditorState} or an optionally\n * supplied default context if this state has no context.\n * @param defaultContext - The default {@link IJsonContext | JSON context} to use as default\n * if this state has no context.\n * @returns The appropriate {@link IJsonContext | IJsonContext} or `undefined` if no context\n * is available.\n */\n public getContext(defaultContext?: IJsonContext): IJsonContext | undefined {\n return JsonContextHelper.mergeContext(defaultContext, this.options.context).orDefault();\n }\n\n /**\n * Constructs a new {@link IJsonContext | IJsonContext} by merging supplied variables\n * and references into a supplied existing context.\n * @param baseContext - The {@link IJsonContext | IJsonContext} into which variables\n * and references are to be merged, or `undefined` to start with a default empty context.\n * @param add - The {@link VariableValue | variable values} and/or\n * {@link IJsonReferenceMap | JSON entity references} to be merged into the base context.\n * @returns A new {@link IJsonContext | IJsonContext} created by merging the supplied values.\n */\n public extendContext(\n baseContext: IJsonContext | undefined,\n add: { vars?: VariableValue[]; refs?: IJsonReferenceMap[] }\n ): Result<IJsonContext | undefined> {\n const context = this.getContext(baseContext);\n return JsonContextHelper.extendContext(context, add);\n }\n\n /**\n * Helper method to constructs `DetailedFailure` with appropriate details and messaging\n * for various validation failures.\n * @param rule - The {@link JsonEditorValidationRules | validation rule} that failed.\n * @param message - A string message describing the failed validation.\n * @param validation - The {@link IJsonEditorValidationOptions | validation options}\n * in effect.\n * @returns A `DetailedFailure` with appropriate detail and message.\n */\n public failValidation<T = JsonObject>(\n rule: JsonEditorValidationRules,\n message?: string,\n validation?: IJsonEditorValidationOptions\n ): DetailedFailure<T, JsonEditFailureReason> {\n let detail: JsonPropertyEditFailureReason = 'error';\n const effective = validation ?? this.options.validation;\n switch (rule) {\n case 'invalidPropertyName':\n detail = effective.onInvalidPropertyName !== 'ignore' ? 'error' : 'inapplicable';\n break;\n case 'invalidPropertyValue':\n detail = effective.onInvalidPropertyValue !== 'ignore' ? 'error' : 'ignore';\n break;\n case 'undefinedPropertyValue':\n detail = effective.onUndefinedPropertyValue !== 'error' ? 'ignore' : 'error';\n /* c8 ignore next */\n message = message ?? 'Cannot convert undefined to JSON';\n break;\n }\n /* c8 ignore next */\n return failWithDetail(message ?? rule, detail);\n }\n}\n"]}
1
+ {"version":3,"file":"jsonEditorState.js","sourceRoot":"","sources":["../../../src/packlets/editor/jsonEditorState.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAGH,4CAAiF;AACjF,wCAA6G;AAU7G;;;GAGG;AACH,MAAa,eAAe;IA+B1B;;;;;;;;OAQG;IACH,YACE,MAAwB,EACxB,WAA+B,EAC/B,cAA6B;QAxB/B;;;WAGG;QACgB,cAAS,GAAiB,EAAE,CAAC;QAsB9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,eAAe,CAAC,oBAAoB,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3F,IAAI,CAAC,GAAG,GAAG,eAAe,CAAC,OAAO,EAAE,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACH,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;;;;;;;;;;OAYG;IACO,MAAM,CAAC,oBAAoB,CACnC,OAA2B,EAC3B,OAAsB;QAEtB,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,IAAA,kBAAO,EAAC,OAAO,CAAC,CAAC;QAC1B,CAAC;QACD,OAAO,2BAAiB,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE;YACnF,OAAO,IAAA,kBAAO,EAAC,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QAC5F,CAAC,CAAC,CAAC;IACL,CAAC;IAED;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O,CAAC,CAAC,CAAC,cAAc,CAAC;gBACjF,MAAM;YACR,KAAK,sBAAsB;gBACzB,MAAM,GAAG,SAAS,CAAC,sBAAsB,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;gBAC5E,MAAM;YACR,KAAK,wBAAwB;gBAC3B,MAAM,GAAG,SAAS,CAAC,wBAAwB,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;gBAC7E,oBAAoB;gBACpB,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,kCAAkC,CAAC;gBACxD,MAAM;QACV,CAAC;QACD,oBAAoB;QACpB,OAAO,IAAA,yBAAc,EAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC;;AAzLH,0CA0LC;AAzLC;;;;GAIG;AACc,uBAAO,GAAW,CAAC,AAAZ,CAAa","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { JsonObject } from '@fgv/ts-json-base';\nimport { DetailedFailure, Result, failWithDetail, succeed } from '@fgv/ts-utils';\nimport { IJsonContext, IJsonReferenceMap, JsonContextHelper, TemplateVars, VariableValue } from '../context';\nimport {\n IJsonCloneEditor,\n IJsonEditorOptions,\n IJsonEditorValidationOptions,\n JsonEditFailureReason,\n JsonEditorValidationRules,\n JsonPropertyEditFailureReason\n} from './common';\n\n/**\n * Represents the internal state of a {@link JsonEditor | JsonEditor}.\n * @public\n */\nexport class JsonEditorState {\n /**\n * Static global counter used to assign each {@link JsonEditorState | JsonEditorState}\n * a unique identifier.\n * @internal\n */\n protected static _nextId: number = 0;\n\n /**\n * The {@link IJsonCloneEditor | editor} for which this state applies.\n */\n public readonly editor: IJsonCloneEditor;\n\n /**\n * Fully resolved {@link IJsonEditorOptions | editor options} that apply\n * to the operation for which this state applies.\n */\n public readonly options: IJsonEditorOptions;\n\n /**\n * Any deferred JSON objects to be merged during finalization.\n * @internal\n */\n protected readonly _deferred: JsonObject[] = [];\n\n /**\n * Unique global identifier for this {@link JsonEditorState | state object}.\n * @internal\n */\n protected readonly _id: number;\n\n /**\n * Constructs a new {@link JsonEditorState | JsonEditorState}.\n * @param editor - The {@link IJsonCloneEditor | editor} to which this state\n * applies.\n * @param baseOptions - The {@link IJsonEditorOptions | editor options} that\n * apply to this rule.\n * @param runtimeContext - An optional {@link IJsonContext | JSON context} to be used\n * for json value conversion.\n */\n public constructor(\n editor: IJsonCloneEditor,\n baseOptions: IJsonEditorOptions,\n runtimeContext?: IJsonContext\n ) {\n this.editor = editor;\n this.options = JsonEditorState._getEffectiveOptions(baseOptions, runtimeContext).orThrow();\n this._id = JsonEditorState._nextId++;\n }\n\n /**\n * The optional {@link IJsonContext | JSON context} for this state.\n */\n public get context(): IJsonContext | undefined {\n return this.options.context;\n }\n\n /**\n * An array of JSON objects that were deferred for merge during\n * finalization.\n */\n public get deferred(): JsonObject[] {\n return this._deferred;\n }\n\n /**\n * Merges an optional {@link IJsonContext | JSON context} into a supplied set\n * of {@link IJsonEditorOptions | JSON editor options}.\n * @param options - The {@link IJsonEditorOptions | IJsonEditorOptions} into\n * which the the new context is to be merged.\n * @param context - The {@link IJsonContext | JSON context} to be merged into the\n * editor options.\n * @returns `Success` with the supplied {@link IJsonEditorOptions | options} if\n * there was nothing to merge, or aa new {@link IJsonEditorOptions | IJsonEditorOptions}\n * constructed from the base options merged with the supplied context. Returns `Failure`\n * with more information if an error occurs.\n * @internal\n */\n protected static _getEffectiveOptions(\n options: IJsonEditorOptions,\n context?: IJsonContext\n ): Result<IJsonEditorOptions> {\n if (!context) {\n return succeed(options);\n }\n return JsonContextHelper.mergeContext(options.context, context).onSuccess((merged) => {\n return succeed({ context: merged, validation: options.validation, merge: options.merge });\n });\n }\n\n /**\n * Adds a supplied `JsonObject` to the deferred list.\n * @param obj - The `JsonObject` to be deferred.\n */\n public defer(obj: JsonObject): void {\n this._deferred.push(obj);\n }\n\n /**\n * Gets a {@link TemplateVars | TemplateVars} from the context of this {@link JsonEditorState | JsonEditorState},\n * or from an optional supplied {@link IJsonContext | IJsonContext} if the current state has no default\n * context.\n * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as `TemplateVars`\n * if the current state does not have context.\n * @returns A {@link TemplateVars | TemplateVars} reflecting the appropriate {@link IJsonContext | JSON context}, or\n * `undefined` if no vars are found.\n */\n public getVars(defaultContext?: IJsonContext): TemplateVars | undefined {\n /* c8 ignore next */ // c8 seems to be struggling atm\n return this.options.context?.vars ?? defaultContext?.vars;\n }\n\n /**\n * Gets an {@link IJsonReferenceMap | reference map} containing any other values\n * referenced during the operation.\n * @param defaultContext - An optional default {@link IJsonContext | IJsonContext} to use as\n * {@link TemplateVars | TemplateVars} if the current state does not have context.\n * @returns An {@link IJsonReferenceMap | IJsonReferenceMap} containing any values referenced\n * during this operation.\n */\n public getRefs(defaultContext?: IJsonContext): IJsonReferenceMap | undefined {\n /* c8 ignore next */ // c8 seems to be struggling atm\n return this.options.context?.refs ?? defaultContext?.refs;\n }\n\n /**\n * Gets the context of this {@link JsonEditorState | JsonEditorState} or an optionally\n * supplied default context if this state has no context.\n * @param defaultContext - The default {@link IJsonContext | JSON context} to use as default\n * if this state has no context.\n * @returns The appropriate {@link IJsonContext | IJsonContext} or `undefined` if no context\n * is available.\n */\n public getContext(defaultContext?: IJsonContext): IJsonContext | undefined {\n return JsonContextHelper.mergeContext(defaultContext, this.options.context).orDefault();\n }\n\n /**\n * Constructs a new {@link IJsonContext | IJsonContext} by merging supplied variables\n * and references into a supplied existing context.\n * @param baseContext - The {@link IJsonContext | IJsonContext} into which variables\n * and references are to be merged, or `undefined` to start with a default empty context.\n * @param add - The {@link VariableValue | variable values} and/or\n * {@link IJsonReferenceMap | JSON entity references} to be merged into the base context.\n * @returns A new {@link IJsonContext | IJsonContext} created by merging the supplied values.\n */\n public extendContext(\n baseContext: IJsonContext | undefined,\n add: { vars?: VariableValue[]; refs?: IJsonReferenceMap[] }\n ): Result<IJsonContext | undefined> {\n const context = this.getContext(baseContext);\n return JsonContextHelper.extendContext(context, add);\n }\n\n /**\n * Helper method to constructs `DetailedFailure` with appropriate details and messaging\n * for various validation failures.\n * @param rule - The {@link JsonEditorValidationRules | validation rule} that failed.\n * @param message - A string message describing the failed validation.\n * @param validation - The {@link IJsonEditorValidationOptions | validation options}\n * in effect.\n * @returns A `DetailedFailure` with appropriate detail and message.\n */\n public failValidation<T = JsonObject>(\n rule: JsonEditorValidationRules,\n message?: string,\n validation?: IJsonEditorValidationOptions\n ): DetailedFailure<T, JsonEditFailureReason> {\n let detail: JsonPropertyEditFailureReason = 'error';\n const effective = validation ?? this.options.validation;\n switch (rule) {\n case 'invalidPropertyName':\n detail = effective.onInvalidPropertyName !== 'ignore' ? 'error' : 'inapplicable';\n break;\n case 'invalidPropertyValue':\n detail = effective.onInvalidPropertyValue !== 'ignore' ? 'error' : 'ignore';\n break;\n case 'undefinedPropertyValue':\n detail = effective.onUndefinedPropertyValue !== 'error' ? 'ignore' : 'error';\n /* c8 ignore next */\n message = message ?? 'Cannot convert undefined to JSON';\n break;\n }\n /* c8 ignore next */\n return failWithDetail(message ?? rule, detail);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-json",
3
- "version": "4.6.0",
3
+ "version": "5.0.0-10",
4
4
  "description": "Typescript utilities for working with JSON",
5
5
  "main": "lib/index.js",
6
6
  "types": "dist/ts-json.d.ts",
@@ -40,14 +40,14 @@
40
40
  "@microsoft/api-documenter": "^7.26.29",
41
41
  "@rushstack/eslint-config": "~4.4.0",
42
42
  "eslint-plugin-tsdoc": "~0.4.0",
43
- "@fgv/ts-utils": "4.6.0",
44
- "@fgv/ts-utils-jest": "4.6.0",
45
- "@fgv/ts-json-base": "4.6.0"
43
+ "@fgv/ts-utils-jest": "5.0.0-10",
44
+ "@fgv/ts-json-base": "5.0.0-10",
45
+ "@fgv/ts-utils": "5.0.0-10"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "mustache": "^4.2.0",
49
- "@fgv/ts-utils": "4.6.0",
50
- "@fgv/ts-json-base": "4.6.0"
49
+ "@fgv/ts-utils": "5.0.0-10",
50
+ "@fgv/ts-json-base": "5.0.0-10"
51
51
  },
52
52
  "scripts": {
53
53
  "build": "heft build --clean",