@fgv/ts-json 5.0.0-2 → 5.0.0-21
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/.vscode/launch.json +16 -0
- package/.vscode/settings.json +32 -0
- package/config/api-extractor.json +343 -0
- package/config/rig.json +16 -0
- package/dist/ts-json.d.ts +719 -28
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +25 -0
- package/lib/packlets/diff/detailedDiff.d.ts +375 -0
- package/lib/packlets/diff/detailedDiff.js +342 -0
- package/lib/packlets/diff/index.d.ts +3 -0
- package/lib/packlets/diff/index.js +40 -0
- package/lib/packlets/diff/threeWayDiff.d.ts +263 -0
- package/lib/packlets/diff/threeWayDiff.js +261 -0
- package/lib/packlets/diff/utils.d.ts +6 -0
- package/lib/packlets/diff/utils.js +62 -0
- package/lib/packlets/editor/common.d.ts +6 -0
- package/lib/packlets/editor/jsonEditor.d.ts +57 -28
- package/lib/packlets/editor/jsonEditor.js +101 -32
- package/lib/test/legacy/jsonConverter.conditional.test.d.ts +2 -0
- package/lib/test/legacy/jsonEditor/rules/conditional.test.d.ts +2 -0
- package/lib/test/legacy/jsonEditor/rules/multivalue.test.d.ts +2 -0
- package/lib/test/legacy/jsonEditor/rules/references.test.d.ts +2 -0
- package/lib/test/legacy/jsonEditor/rules/templates.test.d.ts +2 -0
- package/lib/test/unit/contextHelpers.test.d.ts +2 -0
- package/lib/test/unit/converters.test.d.ts +2 -0
- package/lib/test/unit/diff/jsonDiff.test.d.ts +2 -0
- package/lib/test/unit/jsonConverter.test.d.ts +2 -0
- package/lib/test/unit/jsonEditor/jsonEditor.test.d.ts +2 -0
- package/lib/test/unit/jsonEditor/templateContext.test.d.ts +2 -0
- package/lib/test/unit/jsonReferenceMap.test.d.ts +2 -0
- package/package.json +11 -11
- package/src/index.ts +29 -0
- package/src/packlets/context/compositeJsonMap.ts +120 -0
- package/src/packlets/context/contextHelpers.ts +221 -0
- package/src/packlets/context/index.ts +33 -0
- package/src/packlets/context/jsonContext.ts +133 -0
- package/src/packlets/converters/converters.ts +117 -0
- package/src/packlets/converters/index.ts +26 -0
- package/src/packlets/converters/jsonConverter.ts +476 -0
- package/src/packlets/diff/detailedDiff.ts +585 -0
- package/src/packlets/diff/index.ts +24 -0
- package/src/packlets/diff/threeWayDiff.ts +420 -0
- package/src/packlets/diff/utils.ts +66 -0
- package/src/packlets/editor/common.ts +125 -0
- package/src/packlets/editor/index.ts +36 -0
- package/src/packlets/editor/jsonEditor.ts +523 -0
- package/src/packlets/editor/jsonEditorRule.ts +117 -0
- package/src/packlets/editor/jsonEditorState.ts +225 -0
- package/src/packlets/editor/jsonReferenceMap.ts +516 -0
- package/src/packlets/editor/rules/conditional.ts +222 -0
- package/src/packlets/editor/rules/index.ts +25 -0
- package/src/packlets/editor/rules/multivalue.ts +206 -0
- package/src/packlets/editor/rules/references.ts +177 -0
- package/src/packlets/editor/rules/templates.ts +159 -0
- package/CHANGELOG.md +0 -115
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/packlets/context/compositeJsonMap.d.ts.map +0 -1
- package/lib/packlets/context/compositeJsonMap.js.map +0 -1
- package/lib/packlets/context/contextHelpers.d.ts.map +0 -1
- package/lib/packlets/context/contextHelpers.js.map +0 -1
- package/lib/packlets/context/index.d.ts.map +0 -1
- package/lib/packlets/context/index.js.map +0 -1
- package/lib/packlets/context/jsonContext.d.ts.map +0 -1
- package/lib/packlets/context/jsonContext.js.map +0 -1
- package/lib/packlets/converters/converters.d.ts.map +0 -1
- package/lib/packlets/converters/converters.js.map +0 -1
- package/lib/packlets/converters/index.d.ts.map +0 -1
- package/lib/packlets/converters/index.js.map +0 -1
- package/lib/packlets/converters/jsonConverter.d.ts.map +0 -1
- package/lib/packlets/converters/jsonConverter.js.map +0 -1
- package/lib/packlets/editor/common.d.ts.map +0 -1
- package/lib/packlets/editor/common.js.map +0 -1
- package/lib/packlets/editor/index.d.ts.map +0 -1
- package/lib/packlets/editor/index.js.map +0 -1
- package/lib/packlets/editor/jsonEditor.d.ts.map +0 -1
- package/lib/packlets/editor/jsonEditor.js.map +0 -1
- package/lib/packlets/editor/jsonEditorRule.d.ts.map +0 -1
- package/lib/packlets/editor/jsonEditorRule.js.map +0 -1
- package/lib/packlets/editor/jsonEditorState.d.ts.map +0 -1
- package/lib/packlets/editor/jsonEditorState.js.map +0 -1
- package/lib/packlets/editor/jsonReferenceMap.d.ts.map +0 -1
- package/lib/packlets/editor/jsonReferenceMap.js.map +0 -1
- package/lib/packlets/editor/rules/conditional.d.ts.map +0 -1
- package/lib/packlets/editor/rules/conditional.js.map +0 -1
- package/lib/packlets/editor/rules/index.d.ts.map +0 -1
- package/lib/packlets/editor/rules/index.js.map +0 -1
- package/lib/packlets/editor/rules/multivalue.d.ts.map +0 -1
- package/lib/packlets/editor/rules/multivalue.js.map +0 -1
- package/lib/packlets/editor/rules/references.d.ts.map +0 -1
- package/lib/packlets/editor/rules/references.js.map +0 -1
- package/lib/packlets/editor/rules/templates.d.ts.map +0 -1
- package/lib/packlets/editor/rules/templates.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
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,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H,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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jsonReferenceMap.d.ts","sourceRoot":"","sources":["../../../src/packlets/editor/jsonReferenceMap.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,cAAc,EACd,MAAM,EAQP,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAgB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC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AAC,SAAS,KAAK,KAAK,EAAE,CAAC,CAAC;IACrG,CAAC;CACF;AAzED,0CAyEC","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 {\n DetailedResult,\n Result,\n captureResult,\n fail,\n failWithDetail,\n mapResults,\n recordToMap,\n succeed,\n succeedWithDetail\n} from '@fgv/ts-utils';\n\nimport { JsonObject, JsonValue, isJsonObject } from '@fgv/ts-json-base';\nimport { IJsonContext, IJsonReferenceMap, JsonReferenceMapFailureReason } from '../context';\nimport { JsonEditor } from './jsonEditor';\n\n/**\n * Options for creating a {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy} object.\n * @public\n */\nexport interface IReferenceMapKeyPolicyValidateOptions {\n /**\n * If `true`, the validator coerces keys to some valid value.\n * If `false`, invalid keys cause an error.\n */\n makeValid?: boolean;\n}\n\n/**\n * Policy object responsible for validating or correcting\n * keys in a {@link IJsonReferenceMap | reference map}.\n * @public\n */\nexport class ReferenceMapKeyPolicy<T> {\n /**\n * @internal\n */\n protected readonly _defaultOptions?: IReferenceMapKeyPolicyValidateOptions;\n\n /**\n * @internal\n */\n protected readonly _isValid: (key: string, item?: T) => boolean;\n\n /**\n * Constructs a new {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy}.\n * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options}\n * used to construct the {@link ReferenceMapKeyPolicy}.\n * @param isValid - An optional predicate to test a supplied key for validity.\n */\n public constructor(\n options?: IReferenceMapKeyPolicyValidateOptions,\n isValid?: (key: string, item?: T) => boolean\n ) {\n this._defaultOptions = options;\n this._isValid = isValid ?? ReferenceMapKeyPolicy.defaultKeyPredicate;\n }\n\n /**\n * The static default key name validation predicate rejects keys that contain\n * mustache templates or which start with the default conditional prefix\n * `'?'`.\n * @param key - The key to test.\n * @returns `true` if the key is valid, `false` otherwise.\n */\n public static defaultKeyPredicate(key: string): boolean {\n return key.length > 0 && !key.includes('{{') && !key.startsWith('?');\n }\n\n /**\n * Determines if a supplied key and item are valid according to the current policy.\n * @param key - The key to be tested.\n * @param item - The item to be tested.\n * @returns `true` if the key and value are valid, `false` otherwise.\n */\n public isValid(key: string, item?: T): boolean {\n return this._isValid(key, item);\n }\n\n /**\n * Determines if a supplied key and item are valid according to the current policy.\n * @param key - The key to be tested.\n * @param item - The item to be tested.\n * @returns `Success` with the key if valid, `Failure` with an error message if invalid.\n */\n public validate(key: string, item?: T, __options?: IReferenceMapKeyPolicyValidateOptions): Result<string> {\n return this.isValid(key, item) ? succeed(key) : fail(`${key}: invalid key`);\n }\n\n /**\n * Validates an array of entries using the validation rules for this policy.\n * @param items - The array of entries to be validated.\n * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to control\n * validation.\n * @returns `Success` with an array of validated entries, or `Failure` with an error message\n * if validation fails.\n */\n public validateItems(\n items: [string, T][],\n options?: IReferenceMapKeyPolicyValidateOptions\n ): Result<[string, T][]> {\n return mapResults(\n items.map((item) => {\n return this.validate(...item, options).onSuccess((valid) => {\n return succeed([valid, item[1]]);\n });\n })\n );\n }\n\n /**\n * Validates a `Map\\<string, T\\>` using the validation rules for this policy.\n * @param items - The `Map\\<string, T\\>` to be validated.\n * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to control\n * validation.\n * @returns `Success` with a new `Map\\<string, T\\>`, or `Failure` with an error message\n * if validation fails.\n */\n public validateMap(\n map: Map<string, T>,\n options?: IReferenceMapKeyPolicyValidateOptions\n ): Result<Map<string, T>> {\n return this.validateItems(Array.from(map.entries()), options).onSuccess((valid) => {\n return captureResult(() => new Map(valid));\n });\n }\n}\n\n/**\n * A {@link PrefixKeyPolicy | PrefixKeyPolicy} enforces that all keys start with a supplied\n * prefix, optionally adding the prefix as necessary.\n * @public\n */\nexport class PrefixKeyPolicy<T> extends ReferenceMapKeyPolicy<T> {\n /**\n * The string prefix to be enforced by this policy.\n */\n public readonly prefix: string;\n\n /**\n * Constructs a new {@link PrefixKeyPolicy | PrefixKeyPolicy}.\n * @param prefix - The string prefix to be enforced or applied.\n * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to\n * configure the policy.\n */\n public constructor(prefix: string, options?: IReferenceMapKeyPolicyValidateOptions) {\n super(options);\n this.prefix = prefix;\n }\n\n /**\n * Determines if a key is valid according to policy.\n * @param key - The key to be tested.\n * @param __item - The item to be tested.\n * @returns `true` if the key starts with the expected prefix, `false` otherwise.\n */\n public isValid(key: string, __item?: T): boolean {\n return (\n key.startsWith(this.prefix) && key !== this.prefix && ReferenceMapKeyPolicy.defaultKeyPredicate(key)\n );\n }\n\n /**\n * Determines if a key is valid according to policy, optionally coercing to a valid value by\n * adding the required prefix.\n * @param key - The key to be tested.\n * @param item - The item which corresponds to the key.\n * @param options - Optional {@link IReferenceMapKeyPolicyValidateOptions | options} to guide\n * validation.\n * @returns `Success` with a valid key name if the supplied key is valid or if `makeValid` is set\n * in the policy options. Returns `Failure` with an error message if an error occurs.\n */\n public validate(key: string, item?: T, options?: IReferenceMapKeyPolicyValidateOptions): Result<string> {\n /* c8 ignore next */\n const makeValid = (options ?? this._defaultOptions)?.makeValid === true;\n if (this.isValid(key, item)) {\n return succeed(key);\n } else if (makeValid && ReferenceMapKeyPolicy.defaultKeyPredicate(key)) {\n return succeed(`${this.prefix}${key}`);\n }\n return fail(`${key}: invalid key`);\n }\n}\n\n/**\n * Type representing either a `Map\\<string, T\\>` or a `Record\\<string, T\\>`.\n * @public\n */\nexport type MapOrRecord<T> = Map<string, T> | Record<string, T>;\n\n/**\n * Abstract base class with common functionality for simple\n * {@link IJsonReferenceMap | reference map} implementations.\n * @public\n */\nexport abstract class SimpleJsonMapBase<T> implements IJsonReferenceMap {\n /**\n * The {@link ReferenceMapKeyPolicy | key policy} in effect for this map.\n * @internal\n */\n protected readonly _keyPolicy: ReferenceMapKeyPolicy<T>;\n\n /**\n * A map containing keys and values already present in this map.\n * @internal\n */\n protected readonly _values: Map<string, T>;\n\n /**\n * An optional {@link IJsonContext | IJsonContext} used for any conversions\n * involving items in this map.\n * @internal\n */\n protected readonly _context?: IJsonContext;\n\n /**\n * Constructs a new {@link SimpleJsonMap | SimpleJsonMap}.\n * @param values - Initial values for the map.\n * @param context - An optional {@link IJsonContext | IJsonContext} used for any conversions\n * involving items in this map.\n * @param keyPolicy - The {@link ReferenceMapKeyPolicy | key policy} to use for this map.\n * @internal\n */\n protected constructor(\n values?: MapOrRecord<T>,\n context?: IJsonContext,\n keyPolicy?: ReferenceMapKeyPolicy<T>\n ) {\n values = SimpleJsonMapBase._toMap(values).orThrow();\n this._keyPolicy = keyPolicy ?? new ReferenceMapKeyPolicy();\n this._values = this._keyPolicy.validateMap(values).orThrow();\n this._context = context;\n }\n\n /**\n * Returns a `Map\\<string, T\\>` derived from a supplied {@link MapOrRecord | MapOrRecord}\n * @param values - The {@link MapOrRecord | MapOrRecord} to be returned as a map.\n * @returns `Success` with the corresponding `Map\\<string, T\\>` or `Failure` with a\n * message if an error occurs.\n * @internal\n */\n protected static _toMap<T>(values?: MapOrRecord<T>): Result<Map<string, T>> {\n if (values === undefined) {\n return captureResult(() => new Map<string, T>());\n } else if (!(values instanceof Map)) {\n return recordToMap(values, (__k, v) => succeed(v));\n }\n return succeed(values);\n }\n\n /**\n * Determine if a key might be valid for this map but does not determine if key actually\n * exists. Allows key range to be constrained.\n * @param key - key to be tested\n * @returns `true` if the key is in the valid range, `false` otherwise.\n */\n public keyIsInRange(key: string): boolean {\n return this._keyPolicy.isValid(key);\n }\n\n /**\n * Determines if an entry with the specified key actually exists in the map.\n * @param key - key to be tested\n * @returns `true` if an object with the specified key exists, `false` otherwise.\n */\n public has(key: string): boolean {\n return this._values.has(key);\n }\n\n /**\n * Gets a `JsonObject` specified by key.\n * @param key - key of the object to be retrieved\n * @param context - optional {@link IJsonContext | JSON context} used to format the\n * returned object.\n * @returns {@link ts-utils#Success | `Success`} with the formatted object if successful.\n * {@link ts-utils#Failure | `Failure`} with detail 'unknown' if no such object exists,\n * or {@link ts-utils#Failure | `Failure`} with detail 'error' if the object was found\n * but could not be formatted.\n */\n public getJsonObject(\n key: string,\n context?: IJsonContext\n ): DetailedResult<JsonObject, JsonReferenceMapFailureReason> {\n return this.getJsonValue(key, context).onSuccess((jv) => {\n if (!isJsonObject(jv)) {\n return failWithDetail(`${key}: not an object`, 'error');\n }\n return succeedWithDetail(jv);\n });\n }\n\n /**\n * Gets a `JsonValue` specified by key.\n * @param key - key of the value to be retrieved\n * @param context - Optional {@link IJsonContext | JSON context} used to format the value\n * @returns Success with the formatted object if successful. Failure with detail 'unknown'\n * if no such object exists, or failure with detail 'error' if the object was found but\n * could not be formatted.\n */\n // eslint-disable-next-line no-use-before-define\n public abstract getJsonValue(\n key: string,\n context?: IJsonContext\n ): DetailedResult<JsonValue, JsonReferenceMapFailureReason>;\n}\n\n/**\n * Initialization options for a {@link SimpleJsonMap | SimpleJsonMap}.\n * @public\n */\nexport interface ISimpleJsonMapOptions {\n keyPolicy?: ReferenceMapKeyPolicy<JsonValue>;\n editor?: JsonEditor;\n}\n\n/**\n * A {@link SimpleJsonMap | SimpleJsonMap } presents a view of a simple map\n * of JSON values.\n * @public\n */\nexport class SimpleJsonMap extends SimpleJsonMapBase<JsonValue> {\n /**\n * @internal\n */\n protected _editor?: JsonEditor;\n\n /**\n * Constructs a new {@link SimpleJsonMap | SimpleJsonMap} from the supplied objects\n * @param values - A string-keyed `Map` or `Record` of the `JsonValue`\n * to be returned.\n * @param context - Optional {@link IJsonContext | IJsonContext} used to format returned values.\n * @param options - Optional {@link ISimpleJsonMapOptions | ISimpleJsonMapOptions} for initialization.\n * @public\n */\n protected constructor(\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n options?: ISimpleJsonMapOptions\n ) {\n super(values, context, options?.keyPolicy);\n this._editor = options?.editor;\n }\n\n /**\n * Creates a new {@link SimpleJsonMap | SimpleJsonMap} from the supplied objects\n * @param values - A string-keyed `Map` or `Record` of the `JsonValue`\n * to be returned.\n * @param context - Optional {@link IJsonContext | IJsonContext} used to format returned values.\n * @param options - Optional {@link ISimpleJsonMapOptions | ISimpleJsonMapOptions} for initialization.\n * @returns `Success` with a {@link SimpleJsonMap | SimpleJsonMap} or `Failure` with a message if\n * an error occurs.\n */\n public static createSimple(\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n options?: ISimpleJsonMapOptions\n ): Result<SimpleJsonMap> {\n return captureResult(() => new SimpleJsonMap(values, context, options));\n }\n\n /**\n * Gets a `JsonValue` specified by key.\n * @param key - key of the value to be retrieved\n * @param context - Optional {@link IJsonContext | JSON context} used to format the value\n * @returns Success with the formatted object if successful. Failure with detail 'unknown'\n * if no such object exists, or failure with detail 'error' if the object was found but\n * could not be formatted.\n */\n public getJsonValue(\n key: string,\n context?: IJsonContext\n ): DetailedResult<JsonValue, JsonReferenceMapFailureReason> {\n context = context ?? this._context;\n const value = this._values.get(key);\n if (!value) {\n return failWithDetail(`${key}: JSON value not found`, 'unknown');\n }\n return this._clone(value, context);\n }\n\n /**\n * @internal\n */\n protected _clone(\n value: JsonValue,\n context?: IJsonContext\n ): DetailedResult<JsonValue, JsonReferenceMapFailureReason> {\n if (!this._editor) {\n const result = JsonEditor.create();\n /* c8 ignore next 3 - nearly impossible to reproduce */\n if (result.isFailure()) {\n return failWithDetail(result.message, 'error');\n }\n this._editor = result.value;\n }\n return this._editor.clone(value, context).withFailureDetail('error');\n }\n}\n\n/**\n * Initialization options for a {@link PrefixedJsonMap | PrefixedJsonMap}\n * @public\n */\nexport interface IKeyPrefixOptions {\n /**\n * Indicates whether the prefix should be added automatically as needed (default true)\n */\n addPrefix?: boolean;\n\n /**\n * The prefix to be enforced\n */\n prefix: string;\n}\n\n/**\n * A {@link PrefixedJsonMap | PrefixedJsonMap} enforces a supplied prefix for all contained values,\n * optionally adding the prefix as necessary (default `true`).\n * @public\n */\nexport class PrefixedJsonMap extends SimpleJsonMap {\n /**\n * Constructs a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values\n * @param prefix - A string prefix to be enforced for and added to key names as necessary\n * @param values - A string-keyed Map or Record of the `JsonValue` to be returned\n * @param context - Optional {@link IJsonContext | JSON Context} used to format returned values\n * @param editor - Optional {@link JsonEditor | JsonEditor} used to format returned values\n * @public\n */\n protected constructor(\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n options?: ISimpleJsonMapOptions\n ) {\n super(values, context, options);\n }\n\n /**\n * Creates a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values\n * @param prefix - A string prefix to be enforced for and added to key names as necessary\n * @param values - A string-keyed Map or Record of the `JsonValue` to be returned\n * @param context - Optional {@link IJsonContext | JSON Context} used to format returned values\n * @param editor - Optional {@link JsonEditor | JsonEditor} used to format returned values\n * @returns `Success` with a {@link PrefixedJsonMap | PrefixedJsonMap} or `Failure` with a message\n * if an error occurs.\n */\n public static createPrefixed(\n prefix: string,\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n editor?: JsonEditor\n ): Result<PrefixedJsonMap>;\n\n /**\n * Creates a new {@link PrefixedJsonMap | PrefixedJsonMap} from the supplied values\n * @param prefixOptions - A KeyPrefixOptions indicating the prefix to enforce and whether that prefix should\n * be added automatically if necessary (default true)\n * @param values - A string-keyed Map or record of the `JsonValue` to be returned\n * @param context - Optional {@link IJsonContext | JSON Context} used to format returned values\n * @param editor - Optional {@link JsonEditor | JsonEditor} used to format returned values\n */\n public static createPrefixed(\n prefixOptions: IKeyPrefixOptions,\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n editor?: JsonEditor\n ): Result<PrefixedJsonMap>;\n public static createPrefixed(\n prefixOptions: string | IKeyPrefixOptions,\n values?: MapOrRecord<JsonValue>,\n context?: IJsonContext,\n editor?: JsonEditor\n ): Result<PrefixedJsonMap> {\n return captureResult(\n () => new PrefixedJsonMap(values, context, { keyPolicy: this._toPolicy(prefixOptions), editor })\n );\n }\n\n /**\n * Constructs a new {@link PrefixKeyPolicy | PrefixKeyPolicy} from a supplied prefix\n * or set of {@link IKeyPrefixOptions | prefix options}.\n * @param prefixOptions - The prefix or {@link IKeyPrefixOptions | prefix options} or options\n * for the new policy.\n * @returns A new {@link ReferenceMapKeyPolicy | ReferenceMapKeyPolicy} which enforces the\n * supplied prefix or options.\n * @internal\n */\n protected static _toPolicy(prefixOptions: string | IKeyPrefixOptions): ReferenceMapKeyPolicy<JsonValue> {\n if (typeof prefixOptions === 'string') {\n return new PrefixKeyPolicy(prefixOptions, { makeValid: true });\n }\n return new PrefixKeyPolicy(prefixOptions.prefix, { makeValid: prefixOptions.addPrefix !== false });\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"conditional.d.ts","sourceRoot":"","sources":["../../../../src/packlets/editor/rules/conditional.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAgB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAoD,MAAM,eAAe,CAAC;AAC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cAAc,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;IAED;;;;;;;OAOG;IACO,QAAQ,CAAC,IAAY,EAAE,KAAa,EAAE,QAAgB;QAC9D,QAAQ,QAAQ,EAAE,CAAC;YACjB,KAAK,GAAG;gBACN,OAAO,IAAI,KAAK,KAAK,CAAC;YACxB,KAAK,GAAG;gBACN,OAAO,IAAI,GAAG,KAAK,CAAC;YACtB,KAAK,GAAG;gBACN,OAAO,IAAI,GAAG,KAAK,CAAC;YACtB,KAAK,IAAI;gBACP,OAAO,IAAI,IAAI,KAAK,CAAC;YACvB,KAAK,IAAI;gBACP,OAAO,IAAI,IAAI,KAAK,CAAC;YACvB,KAAK,IAAI;gBACP,OAAO,IAAI,KAAK,KAAK,CAAC;QAC1B,CAAC;QACD,oCAAoC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAvJD,8DAuJC","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, JsonValue, isJsonObject } from '@fgv/ts-json-base';\nimport { DetailedResult, Result, captureResult, failWithDetail, succeedWithDetail } from '@fgv/ts-utils';\nimport { IJsonEditorOptions, JsonEditFailureReason, JsonPropertyEditFailureReason } from '../common';\nimport { JsonEditorRuleBase } from '../jsonEditorRule';\nimport { JsonEditorState } from '../jsonEditorState';\n\n/**\n * Returned by {@link EditorRules.ConditionalJsonEditorRule._tryParseCondition | ConditionalJsonEditorRule._tryParseCondition}\n * to indicate whether a successful match was due to a matching condition or a default value.\n * @public\n */\nexport interface IConditionalJsonKeyResult extends JsonObject {\n matchType: 'default' | 'match' | 'unconditional';\n}\n\n/**\n * On a successful match, the {@link EditorRules.ConditionalJsonEditorRule | ConditionalJsonEditorRule}\n * stores a {@link EditorRules.IConditionalJsonDeferredObject | IConditionalJsonDeferredObject} describing the\n * matching result, to be resolved at finalization time.\n * @public\n */\nexport interface IConditionalJsonDeferredObject extends IConditionalJsonKeyResult {\n value: JsonValue;\n}\n\n/**\n * Configuration options for the {@link EditorRules.ConditionalJsonEditorRule | ConditionalJsonEditorRule}.\n * @public\n */\nexport interface IConditionalJsonRuleOptions extends Partial<IJsonEditorOptions> {\n /**\n * If true (default) then properties with unconditional names\n * (which start with !) are flattened.\n */\n flattenUnconditionalValues?: boolean;\n}\n\n/**\n * The {@link EditorRules.ConditionalJsonEditorRule | ConditionalJsonEditorRule} evaluates\n * properties with conditional keys, omitting non-matching keys and merging keys that match,\n * or default keys only if no other keys match.\n *\n * The default syntax for a conditional key is:\n * \"?value1=value2\" - matches if value1 and value2 are the same, is ignored otherwise.\n * \"?value\" - matches if value is a non-empty, non-whitespace string. Is ignored otherwise.\n * \"?default\" - matches only if no other conditional blocks in the same object were matched.\n * @public\n */\nexport class ConditionalJsonEditorRule extends JsonEditorRuleBase {\n /**\n * Stored fully-resolved {@link EditorRules.IConditionalJsonRuleOptions | options} for this\n * rule.\n * @public\n */\n protected _options?: IConditionalJsonRuleOptions;\n\n /**\n * Creates a new {@link EditorRules.ConditionalJsonEditorRule | ConditionalJsonEditorRule}.\n * @param options - Optional {@link EditorRules.IConditionalJsonRuleOptions | configuration options}\n * used for this rule.\n */\n public constructor(options?: IConditionalJsonRuleOptions) {\n super();\n this._options = options;\n }\n\n /**\n * Creates a new {@link EditorRules.ConditionalJsonEditorRule | ConditionalJsonEditorRule}.\n * @param options - Optional {@link EditorRules.IConditionalJsonRuleOptions | configuration options}\n * used for this rule.\n */\n public static create(options?: IConditionalJsonRuleOptions): Result<ConditionalJsonEditorRule> {\n return captureResult(() => new ConditionalJsonEditorRule(options));\n }\n\n /**\n * Evaluates a property for conditional application.\n * @param key - The key of the property to be considered\n * @param value - The `JsonValue` of the property to be considered.\n * @param state - The {@link JsonEditorState | editor state} for the object being edited.\n * @returns Returns `Success` with detail `'deferred'` and a\n * {@link EditorRules.IConditionalJsonDeferredObject | IConditionalJsonDeferredObject}.\n * for a matching, default or unconditional key. Returns `Failure` with detail `'ignore'` for\n * a non-matching conditional, or with detail `'error'` if an error occurs. Otherwise\n * fails with detail `'inapplicable'`.\n */\n public editProperty(\n key: string,\n value: JsonValue,\n state: JsonEditorState\n ): DetailedResult<JsonObject, JsonPropertyEditFailureReason> {\n const result = this._tryParseCondition(key, state).onSuccess((deferred) => {\n if (isJsonObject(value)) {\n const rtrn: IConditionalJsonDeferredObject = { ...deferred, value };\n return succeedWithDetail(rtrn, 'deferred');\n }\n return failWithDetail<JsonObject, JsonPropertyEditFailureReason>(\n `${key}: conditional body must be object`,\n 'error'\n );\n });\n\n if (result.isFailure() && result.detail === 'error') {\n return state.failValidation('invalidPropertyName', result.message, this._options?.validation);\n }\n\n return result;\n }\n\n /**\n * Finalizes any deferred conditional properties. If the only deferred property is\n * default, that property is emitted. Otherwise all matching properties are emitted.\n * @param finalized - The deferred properties to be considered for merge.\n * @param __state - The {@link JsonEditorState | editor state} for the object\n * being edited.\n */\n public finalizeProperties(\n finalized: JsonObject[],\n __state: JsonEditorState\n ): DetailedResult<JsonObject[], JsonEditFailureReason> {\n let toMerge = finalized;\n if (finalized.length > 1) {\n if (finalized.find((o) => o.matchType === 'match') !== undefined) {\n toMerge = finalized.filter((o) => o.matchType === 'match' || o.matchType === 'unconditional');\n }\n }\n return succeedWithDetail(toMerge.map((o) => o.value).filter(isJsonObject), 'edited');\n }\n\n /**\n * Determines if a given property key is conditional. Derived classes can override this\n * method to use a different format for conditional properties.\n * @param value - The `JsonValue` of the property to be considered.\n * @param state - The {@link JsonEditorState | editor state} for the object being edited.\n * @returns `Success` with detail `'deferred'` and a\n * {@link EditorRules.IConditionalJsonKeyResult | IConditionalJsonKeyResult} describing the\n * match for a default or matching conditional property. Returns `Failure` with detail `'ignore'`\n * for a non-matching conditional property. Fails with detail `'error'` if an error occurs\n * or with detail `'inapplicable'` if the key does not represent a conditional property.\n * @public\n */\n protected _tryParseCondition(\n key: string,\n state: JsonEditorState\n ): DetailedResult<IConditionalJsonKeyResult, JsonPropertyEditFailureReason> {\n if (key.startsWith('?')) {\n // ignore everything after any #\n key = key.split('#')[0].trim();\n\n if (key === '?default') {\n return succeedWithDetail({ matchType: 'default' }, 'deferred');\n }\n\n const parts = key.substring(1).split(/(=|>=|<=|>|<|!=)/);\n if (parts.length === 3) {\n if (!this._compare(parts[0].trim(), parts[2].trim(), parts[1])) {\n return failWithDetail(`Condition ${key} does not match`, 'ignore');\n }\n return succeedWithDetail({ matchType: 'match' }, 'deferred');\n } else if (parts.length === 1) {\n if (parts[0].trim().length === 0) {\n return failWithDetail(`Condition ${key} does not match`, 'ignore');\n }\n return succeedWithDetail({ matchType: 'match' }, 'deferred');\n }\n const message = `Malformed condition token ${key}`;\n return state.failValidation('invalidPropertyName', message, this._options?.validation);\n } else if (this._options?.flattenUnconditionalValues !== false && key.startsWith('!')) {\n return succeedWithDetail({ matchType: 'unconditional' }, 'deferred');\n }\n return failWithDetail('inapplicable', 'inapplicable');\n }\n\n /**\n * Compares two strings using a supplied operator.\n * @param left - The first string to be compared.\n * @param right - The second string to be compared.\n * @param operator - The operator to be applied.\n * @returns `true` if the condition is met, `false` otherwise.\n * @internal\n */\n protected _compare(left: string, right: string, operator: string): boolean {\n switch (operator) {\n case '=':\n return left === right;\n case '>':\n return left > right;\n case '<':\n return left < right;\n case '>=':\n return left >= right;\n case '<=':\n return left <= right;\n case '!=':\n return left !== right;\n }\n /* c8 ignore next 2 - unreachable */\n return false;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/packlets/editor/rules/index.ts"],"names":[],"mappings":"AAqBA,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/packlets/editor/rules/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,gDAA8B;AAC9B,+CAA6B;AAC7B,+CAA6B;AAC7B,8CAA4B","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 */\nexport * from './conditional';\nexport * from './multivalue';\nexport * from './references';\nexport * from './templates';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"multivalue.d.ts","sourceRoot":"","sources":["../../../../src/packlets/editor/rules/multivalue.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EACL,cAAc,EACd,MAAM,EAMP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,MAAM,WAAW,CAAC;AAErG,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB;;;;OAIG;IACH,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAElC;;OAEG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;IAElC;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,wBAAyB,SAAQ,kBAAkB;IAC9D;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAExC;;;OAGG;gBACgB,OAAO,CAAC,EAAE,kBAAkB;IAK/C;;;OAGG;WACW,MAAM,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,MAAM,CAAC,wBAAwB,CAAC;IAI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AAA,4BAAiB,EAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC,CAAC;IACjF,CAAC;CACF;AA7HD,4DA6HC","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, JsonValue } from '@fgv/ts-json-base';\nimport {\n DetailedResult,\n Result,\n allSucceed,\n captureResult,\n failWithDetail,\n succeed,\n succeedWithDetail\n} from '@fgv/ts-utils';\nimport { IJsonContext, VariableValue } from '../../context';\nimport { IJsonEditorOptions, JsonEditFailureReason, JsonPropertyEditFailureReason } from '../common';\n\nimport { JsonEditorRuleBase } from '../jsonEditorRule';\nimport { JsonEditorState } from '../jsonEditorState';\n\n/**\n * Represents the parts of a multi-value property key.\n * @public\n */\nexport interface IMultiValuePropertyParts {\n /**\n * The original matched token.\n */\n readonly token: string;\n\n /**\n * The name of the variable used to project each possible\n * property value into the child values or objects being\n * resolved.\n */\n readonly propertyVariable: string;\n\n /**\n * The set of property values to be expanded.\n */\n readonly propertyValues: string[];\n\n /**\n * If `true`, the resolved values are added as an array\n * with the name of the {@link EditorRules.IMultiValuePropertyParts.propertyVariable | propertyVariable}.\n * If false, values are added as individual properties with names that correspond the value.\n */\n readonly asArray: boolean;\n}\n\n/**\n * The {@link EditorRules.MultiValueJsonEditorRule | Multi-Value JSON editor rule}\n * expands matching keys multiple times, projecting the value into the template\n * context for any child objects rendered by the rule.\n *\n * The default syntax for a multi-value key is:\n * \"[[var]]=value1,value2,value3\"\n * Where \"var\" is the name of the variable that will be passed to\n * child template resolution, and \"value1,value2,value3\" is a\n * comma-separated list of values to be expanded.\n * @public\n */\nexport class MultiValueJsonEditorRule extends JsonEditorRuleBase {\n /**\n * Stored fully-resolved {@link IJsonEditorOptions | editor options}\n * for this rule.\n * @public\n */\n protected _options?: IJsonEditorOptions;\n\n /**\n * Creates a new {@link EditorRules.MultiValueJsonEditorRule | MultiValueJsonEditorRule}.\n * @param options - Optional {@link IJsonEditorOptions | configuration options}.\n */\n public constructor(options?: IJsonEditorOptions) {\n super();\n this._options = options;\n }\n\n /**\n * Creates a new {@link EditorRules.MultiValueJsonEditorRule | MultiValueJsonEditorRule}.\n * @param options - Optional {@link IJsonEditorOptions | configuration options}.\n */\n public static create(options?: IJsonEditorOptions): Result<MultiValueJsonEditorRule> {\n return captureResult(() => new MultiValueJsonEditorRule(options));\n }\n\n /**\n * Evaluates a property for multi-value expansion.\n * @param key - The key of the property to be considered\n * @param value - The `JsonValue` of the property to be considered.\n * @param state - The {@link JsonEditorState | editor state} for the object being edited.\n * @returns `Success` with an object containing the fully-resolved child values to be merged for\n * matching multi-value property. Returns `Failure` with detail `'error'` if an error occurs or\n * with detail `'inapplicable'` if the property key is not a conditional property.\n */\n public editProperty(\n key: string,\n value: JsonValue,\n state: JsonEditorState\n ): DetailedResult<JsonObject, JsonPropertyEditFailureReason> {\n const json: JsonObject = {};\n const result = this._tryParse(key, state).onSuccess((parts) => {\n return allSucceed(\n parts.propertyValues.map((pv) => {\n return this._deriveContext(state, [parts.propertyVariable, pv]).onSuccess((ctx) => {\n return state.editor.clone(value, ctx).onSuccess((cloned) => {\n json[pv] = cloned;\n return succeedWithDetail(cloned);\n });\n });\n }),\n json\n )\n .onSuccess(() => {\n if (parts.asArray) {\n const arrayRtrn: JsonObject = {};\n arrayRtrn[parts.propertyVariable] = Array.from(Object.values(json));\n return succeed(arrayRtrn);\n }\n return succeed(json);\n })\n .withFailureDetail('error');\n });\n\n if (result.isFailure() && result.detail === 'error') {\n return state.failValidation('invalidPropertyName', result.message);\n }\n return result;\n }\n\n /**\n * Extends the {@link IJsonContext | current context} with a supplied state and values.\n * @param state - The {@link JsonEditorState | editor state} for the object being edited.\n * @param values - An array of {@link VariableValue | VariableValue} to be added to the\n * context.\n * @returns The extended {@link IJsonContext | context}.\n * @public\n */\n protected _deriveContext(\n state: JsonEditorState,\n ...values: VariableValue[]\n ): Result<IJsonContext | undefined> {\n return state.extendContext(this._options?.context, { vars: values });\n }\n\n /**\n * Determines if a given property key is multi-value. Derived classes can override this\n * method to use a different format for multi-value properties.\n * @param value - The `JsonValue` of the property to be considered.\n * @param state - The {@link JsonEditorState | editor state} for the object being edited.\n * @returns `Success` with detail `'deferred'` and an\n * {@link EditorRules.IMultiValuePropertyParts | IMultiValuePropertyParts}\n * describing the match for matching multi-value property. Returns `Failure` with detail `'error'` if an error occurs\n * or with detail `'inapplicable'` if the key does not represent a multi-value property.\n * @public\n */\n protected _tryParse(\n token: string,\n state: JsonEditorState\n ): DetailedResult<IMultiValuePropertyParts, JsonEditFailureReason> {\n let parts: string[] = [];\n let asArray = false;\n\n if (token.startsWith('[[')) {\n parts = token.substring(2).split(']]=');\n asArray = true;\n } else if (token.startsWith('*')) {\n parts = token.substring(1).split('=');\n asArray = false;\n } else {\n return failWithDetail(token, 'inapplicable');\n }\n\n if (parts.length !== 2) {\n const message = `Malformed multi-value property: ${token}`;\n return state.failValidation('invalidPropertyName', message, this._options?.validation);\n }\n\n if (parts[1].includes('{{')) {\n return failWithDetail('unresolved template', 'inapplicable');\n }\n\n const propertyVariable = parts[0];\n const propertyValues = parts[1].split(',');\n return succeedWithDetail({ token, propertyVariable, propertyValues, asArray });\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../../../../src/packlets/editor/rules/references.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAgC,MAAM,mBAAmB,CAAC;AACxF,OAAO,EACL,cAAc,EACd,MAAM,EAKP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,MAAM,WAAW,CAAC;AACrG,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,uBAAwB,SAAQ,kBAAkB;IAC7D;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAExC;;;OAGG;gBACgB,OAAO,CAAC,EAAE,kBAAkB;IAK/C;;;OAGG;WACW,MAAM,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,MAAM,CAAC,uBAAuB,CAAC;IAInF;;;;;;;;OAQG;IACI,YAAY,CACjB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,eAAe,GACrB,cAAc,CAAC,UAAU,EAAE,6BAA6B,CAAC;IAyC5D;;;;OAIG;IACI,SAAS,CACd,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,eAAe,GACrB,cAAc,CAAC,SAAS,EAAE,qBAAqB,CAAC;IAiBnD;;;;;;OAMG;IACH,SAAS,CAAC,cAAc,CAAC,KAAK,EA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C3B,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;aAAM,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACxC,OAAO,IAAA,eAAI,EAAC,sCAAsC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACjF,CAAC;QACD,OAAO,KAAK,CAAC,aAAa,CAAC,MAAA,IAAI,CAAC,QAAQ,0CAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IAC1D,CAAC;CACF;AAvHD,0DAuHC","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, JsonValue, isJsonObject, pickJsonObject } from '@fgv/ts-json-base';\nimport {\n DetailedResult,\n Result,\n captureResult,\n fail,\n failWithDetail,\n succeedWithDetail\n} from '@fgv/ts-utils';\nimport { IJsonContext } from '../../context';\nimport { IJsonEditorOptions, JsonEditFailureReason, JsonPropertyEditFailureReason } from '../common';\nimport { JsonEditorRuleBase } from '../jsonEditorRule';\nimport { JsonEditorState } from '../jsonEditorState';\n\n/**\n * The {@link EditorRules.ReferenceJsonEditorRule | Reference JSON editor rule} replaces property\n * keys or values that match some known object with a copy of that referenced object, formatted\n * according to the current context.\n *\n * A property key is matched if it matches any known referenced value.\n * - If the value of the matched key is `'default'`, then the entire object is formatted\n * with the current context, flattened and merged into the current object.\n * - If the value of the matched key is some other string, then the entire\n * object is formatted with the current context, and the child of the resulting\n * object at the specified path is flattened and merged into the current object.\n * - If the value of the matched key is an object, then the entire object is\n * formatted with the current context extended to include any properties of\n * that object, flattened, and merged into the current object.\n * - It is an error if the referenced value is not an object.\n *\n * Any property, array or literal value is matched if it matches any known\n * value reference. The referenced value is replaced by the referenced\n * value, formatted using the current editor context.\n * @public\n */\nexport class ReferenceJsonEditorRule extends JsonEditorRuleBase {\n /**\n * Stored fully-resolved {@link IJsonEditorOptions | editor options} for this rule.\n * @public\n */\n protected _options?: IJsonEditorOptions;\n\n /**\n * Creates a new {@link EditorRules.ReferenceJsonEditorRule | ReferenceJsonEditorRule}.\n * @param options - Optional {@link IJsonEditorOptions | configuration options} for this rule.\n */\n public constructor(options?: IJsonEditorOptions) {\n super();\n this._options = options;\n }\n\n /**\n * Creates a new {@link EditorRules.ReferenceJsonEditorRule | ReferenceJsonEditorRule}.\n * @param options - Optional {@link IJsonEditorOptions | configuration options} for this rule.\n */\n public static create(options?: IJsonEditorOptions): Result<ReferenceJsonEditorRule> {\n return captureResult(() => new ReferenceJsonEditorRule(options));\n }\n\n /**\n * Evaluates a property for reference expansion.\n * @param key - The key of the property to be considered.\n * @param value - The `JsonValue` of the property to be considered.\n * @param state - The {@link JsonEditorState | editor state} for the object being edited.\n * @returns If the reference is successful, returns `Success` with a `JsonObject`\n * to be flattened and merged into the current object. Returns `Failure` with detail `'inapplicable'`\n * for non-reference keys or with detail `'error'` if an error occurs.\n */\n public editProperty(\n key: string,\n value: JsonValue,\n state: JsonEditorState\n ): DetailedResult<JsonObject, JsonPropertyEditFailureReason> {\n /* c8 ignore next 2 */\n const validation = this._options?.validation;\n const refs = state.getRefs(this._options?.context);\n if (refs?.has(key)) {\n // need to apply any rules to the value before we evaluate it\n const cloneResult = state.editor.clone(value, state.context);\n if (cloneResult.isSuccess()) {\n value = cloneResult.value;\n } else {\n const message = `${key}: ${cloneResult.message}`;\n return state.failValidation('invalidPropertyName', message, validation);\n }\n\n const contextResult = this._extendContext(state, value);\n if (contextResult.isSuccess()) {\n const objResult = refs.getJsonObject(key, contextResult.value);\n // guarded by the has above so should never happen\n /* c8 ignore else */\n if (objResult.isSuccess()) {\n if (typeof value !== 'string' || value === 'default') {\n return succeedWithDetail<JsonObject, JsonEditFailureReason>(objResult.value, 'edited');\n }\n const pickResult = pickJsonObject(objResult.value, value);\n if (pickResult.isFailure()) {\n const message = `${key}: ${pickResult.message}`;\n return state.failValidation('invalidPropertyName', message, validation);\n }\n return pickResult.withDetail('edited');\n } else if (objResult.detail !== 'unknown') {\n const message = `${key}: ${objResult.message}`;\n return state.failValidation('invalidPropertyName', message, validation);\n }\n } else {\n const message = `${key}: ${contextResult.message}`;\n return state.failValidation('invalidPropertyName', message, validation);\n }\n }\n return failWithDetail('inapplicable', 'inapplicable');\n }\n\n /**\n * Evaluates a property, array or literal value for reference replacement.\n * @param value - The `JsonValue` of the property to be considered.\n * @param state - The {@link JsonEditorState | editor state} for the object being edited.\n */\n public editValue(\n value: JsonValue,\n state: JsonEditorState\n ): DetailedResult<JsonValue, JsonEditFailureReason> {\n /* c8 ignore next */\n const refs = state.getRefs(this._options?.context);\n\n if (refs && typeof value === 'string') {\n /* c8 ignore next */\n const context = state.getContext(this._options?.context);\n const result = refs.getJsonValue(value, context);\n if (result.isSuccess()) {\n return succeedWithDetail(result.value, 'edited');\n } else if (result.detail === 'error') {\n return state.failValidation('invalidPropertyValue', result.message, this._options?.validation);\n }\n }\n return failWithDetail('inapplicable', 'inapplicable');\n }\n\n /**\n * Gets the template variables to use given the value of some property whose name matched a\n * resource plus the base template context.\n * @param state - The {@link JsonEditorState | editor state} to be extended.\n * @param supplied - The string or object supplied in the source json.\n * @internal\n */\n protected _extendContext(state: JsonEditorState, supplied: JsonValue): Result<IJsonContext | undefined> {\n const add: Record<string, unknown> = {};\n if (isJsonObject(supplied)) {\n add.vars = Object.entries(supplied);\n } else if (typeof supplied !== 'string') {\n return fail(`Invalid template path or context: \"${JSON.stringify(supplied)}\"`);\n }\n return state.extendContext(this._options?.context, add);\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../../src/packlets/editor/rules/templates.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,EAAoD,MAAM,eAAe,CAAC;AACzG,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,MAAM,WAAW,CAAC;AACrG,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAIrD;;;GAGG;AACH,MAAM,WAAW,yBAA0B,SAAQ,OAAO,CAAC,kBAAkB,CAAC;IAC5E;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,kBAAkB;IAC7D;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,EAAE,yBAAyB,CAAC;IAE/C;;;;OAIG;gBACgB,OAAO,CAAC,EAAE,yBAAyB;IAKtD;;;;OAIG;WACW,MAAM,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,MAAM,CAAC,uBAAuB,CAAC;IAI1F;;;;;;;;;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YAAY,CAAC,SAAS,EAAE,IAAI,YAAY,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;gBAChE,MAAM,OAAO,GAAG,wBAAwB,YAAY,CAAC,OAAO,EAAE,CAAC;gBAC/D,oBAAoB;gBACpB,OAAO,KAAK,CAAC,cAAc,CAAC,sBAAsB,EAAE,OAAO,EAAE,MAAA,IAAI,CAAC,QAAQ,0CAAE,UAAU,CAAC,CAAC;YAC1F,CAAC;YACD,OAAO,YAAY,CAAC;QACtB,CAAC;QACD,OAAO,IAAA,yBAAc,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;IAED;;;;;;;;OAQG;IACO,OAAO,CAAC,QAAgB,EAAE,KAAsB;;QACxD,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,MAAA,IAAI,CAAC,QAAQ,0CAAE,OAAO,CAAC,CAAC;QACnD,IAAI,IAAI,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACpC,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,kBAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC5F,CAAC;QACD,OAAO,IAAA,yBAAc,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;CACF;AA5GD,0DA4GC","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, JsonValue } from '@fgv/ts-json-base';\nimport { DetailedResult, Result, captureResult, failWithDetail, succeedWithDetail } from '@fgv/ts-utils';\nimport { IJsonEditorOptions, JsonEditFailureReason, JsonPropertyEditFailureReason } from '../common';\nimport { JsonEditorRuleBase } from '../jsonEditorRule';\nimport { JsonEditorState } from '../jsonEditorState';\n\nimport Mustache from 'mustache';\n\n/**\n * Configuration options for the {@link EditorRules.TemplatedJsonEditorRule | Templated JSON editor rule}.\n * @public\n */\nexport interface ITemplatedJsonRuleOptions extends Partial<IJsonEditorOptions> {\n /**\n * If `true` (default) then templates in property names are rendered\n */\n useNameTemplates?: boolean;\n /**\n * If `true` (default) then templates in property values are rendered\n */\n useValueTemplates?: boolean;\n}\n\n/**\n * The {@link EditorRules.TemplatedJsonEditorRule | Templated JSON editor rule} applies mustache rendering as\n * appropriate to any keys or values in the object being edited.\n * @public\n */\nexport class TemplatedJsonEditorRule extends JsonEditorRuleBase {\n /**\n * Fully-resolved {@link EditorRules.ITemplatedJsonRuleOptions | configuration options} for this rule.\n * @public\n */\n protected _options?: ITemplatedJsonRuleOptions;\n\n /**\n * Creates a new {@link EditorRules.TemplatedJsonEditorRule | TemplatedJsonEditorRule}.\n * @param options - Optional {@link EditorRules.ITemplatedJsonRuleOptions | configuration options}\n * for this rule.\n */\n public constructor(options?: ITemplatedJsonRuleOptions) {\n super();\n this._options = options;\n }\n\n /**\n * Creates a new {@link EditorRules.TemplatedJsonEditorRule | TemplatedJsonEditorRule}.\n * @param options - Optional {@link EditorRules.ITemplatedJsonRuleOptions | configuration options}\n * for this rule.\n */\n public static create(options?: ITemplatedJsonRuleOptions): Result<TemplatedJsonEditorRule> {\n return captureResult(() => new TemplatedJsonEditorRule(options));\n }\n\n /**\n * Evaluates a property name for template rendering.\n * @param key - The key of the property to be considered.\n * @param value - The `JsonValue` of the property to be considered.\n * @param state - The {@link JsonEditorState | editor state} for the object being edited.\n * @returns `Success` with detail `'edited'` and an `JsonObject` to\n * be flattened and merged if the key contained a template. Returns `Failure` with detail `'error'`\n * if an error occurred or with detail `'inapplicable'` if the property key does not contain\n * a template or if name rendering is disabled.\n */\n public editProperty(\n key: string,\n value: JsonValue,\n state: JsonEditorState\n ): DetailedResult<JsonObject, JsonPropertyEditFailureReason> {\n /* c8 ignore next 2 */\n const validation = this._options?.validation;\n const useNameTemplates = this._options?.useNameTemplates !== false;\n\n if (useNameTemplates !== false) {\n const result = this._render(key, state).onSuccess((newKey) => {\n if (newKey.length < 1) {\n return state.failValidation('invalidPropertyName', `Template \"${key}\" renders empty name.`);\n }\n\n const rtrn: JsonObject = {};\n rtrn[newKey] = value;\n return succeedWithDetail<JsonObject, JsonEditFailureReason>(rtrn, 'edited');\n });\n\n if (result.isFailure() && result.detail === 'error') {\n const message = `Cannot render name ${key}: ${result.message}`;\n return state.failValidation('invalidPropertyName', message, validation);\n }\n return result;\n }\n return failWithDetail('inapplicable', 'inapplicable');\n }\n\n /**\n * Evaluates a property, array or literal value for template rendering.\n * @param value - The `JsonValue` to be edited.\n * @param state - The {@link JsonEditorState | editor state} for the object being edited.\n * @returns `Success` with detail `'edited'` if the value contained a template and was edited.\n * Returns `Failure` with `'ignore'` if the rendered value should be ignored, with `'error'` if\n * an error occurs, or with `'inapplicable'` if the value was not a string with a template.\n */\n public editValue(\n value: JsonValue,\n state: JsonEditorState\n ): DetailedResult<JsonValue, JsonEditFailureReason> {\n if (this._options?.useValueTemplates !== false && typeof value === 'string' && value.includes('{{')) {\n const renderResult = this._render(value, state).onSuccess((newValue) => {\n return succeedWithDetail(newValue, 'edited');\n });\n\n if (renderResult.isFailure() && renderResult.detail === 'error') {\n const message = `Cannot render value: ${renderResult.message}`;\n /* c8 ignore next */\n return state.failValidation('invalidPropertyValue', message, this._options?.validation);\n }\n return renderResult;\n }\n return failWithDetail('inapplicable', 'inapplicable');\n }\n\n /**\n * Renders a single template string for a supplied {@link JsonEditorState | editor state}.\n * @param template - The mustache template to be rendered.\n * @param state - The {@link JsonEditorState | editor state} used to render the template.\n * @returns `Success` if the template is rendered. Returns `Failure` with detail `'error'` if the\n * template could not be rendered (e.g. due to syntax errors) or with detail `'inapplicable'` if the\n * string is not a template.\n * @internal\n */\n protected _render(template: string, state: JsonEditorState): DetailedResult<string, JsonEditFailureReason> {\n const vars = state.getVars(this._options?.context);\n if (vars && template.includes('{{')) {\n return captureResult(() => Mustache.render(template, vars)).withDetail('error', 'edited');\n }\n return failWithDetail('inapplicable', 'inapplicable');\n }\n}\n"]}
|