@fluidframework/core-interfaces 2.23.0 → 2.31.0
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/.eslintrc.cjs +19 -1
- package/CHANGELOG.md +162 -154
- package/api-extractor/api-extractor-lint-bundle.json +1 -1
- package/dist/exposedInternalUtilityTypes.d.ts +547 -0
- package/dist/exposedInternalUtilityTypes.d.ts.map +1 -0
- package/dist/exposedInternalUtilityTypes.js +11 -0
- package/dist/exposedInternalUtilityTypes.js.map +1 -0
- package/dist/exposedUtilityTypes.d.ts +10 -0
- package/dist/exposedUtilityTypes.d.ts.map +1 -0
- package/dist/exposedUtilityTypes.js +7 -0
- package/dist/exposedUtilityTypes.js.map +1 -0
- package/dist/internal.d.ts +34 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +23 -0
- package/dist/internal.js.map +1 -0
- package/dist/jsonDeserialized.d.ts +112 -0
- package/dist/jsonDeserialized.d.ts.map +1 -0
- package/dist/jsonDeserialized.js +7 -0
- package/dist/jsonDeserialized.js.map +1 -0
- package/dist/jsonSerializable.d.ts +126 -0
- package/dist/jsonSerializable.d.ts.map +1 -0
- package/dist/jsonSerializable.js +7 -0
- package/dist/jsonSerializable.js.map +1 -0
- package/dist/jsonSerializationErrors.d.ts +31 -0
- package/dist/jsonSerializationErrors.d.ts.map +1 -0
- package/dist/jsonSerializationErrors.js +7 -0
- package/dist/jsonSerializationErrors.js.map +1 -0
- package/dist/jsonType.d.ts +30 -0
- package/dist/jsonType.d.ts.map +1 -0
- package/dist/jsonType.js +7 -0
- package/dist/jsonType.js.map +1 -0
- package/dist/package.json +16 -1
- package/{prettier.config.cjs → internal/exposedUtilityTypes.d.ts} +1 -3
- package/internal.d.ts +1 -6
- package/lib/exposedInternalUtilityTypes.d.ts +547 -0
- package/lib/exposedInternalUtilityTypes.d.ts.map +1 -0
- package/lib/exposedInternalUtilityTypes.js +10 -0
- package/lib/exposedInternalUtilityTypes.js.map +1 -0
- package/lib/exposedUtilityTypes.d.ts +10 -0
- package/lib/exposedUtilityTypes.d.ts.map +1 -0
- package/lib/exposedUtilityTypes.js +6 -0
- package/lib/exposedUtilityTypes.js.map +1 -0
- package/lib/internal.d.ts +34 -0
- package/lib/internal.d.ts.map +1 -0
- package/lib/internal.js +7 -0
- package/lib/internal.js.map +1 -0
- package/lib/jsonDeserialized.d.ts +112 -0
- package/lib/jsonDeserialized.d.ts.map +1 -0
- package/lib/jsonDeserialized.js +6 -0
- package/lib/jsonDeserialized.js.map +1 -0
- package/lib/jsonSerializable.d.ts +126 -0
- package/lib/jsonSerializable.d.ts.map +1 -0
- package/lib/jsonSerializable.js +6 -0
- package/lib/jsonSerializable.js.map +1 -0
- package/lib/jsonSerializationErrors.d.ts +31 -0
- package/lib/jsonSerializationErrors.d.ts.map +1 -0
- package/lib/jsonSerializationErrors.js +6 -0
- package/lib/jsonSerializationErrors.js.map +1 -0
- package/lib/jsonType.d.ts +30 -0
- package/lib/jsonType.d.ts.map +1 -0
- package/lib/jsonType.js +6 -0
- package/lib/jsonType.js.map +1 -0
- package/lib/tsdoc-metadata.json +1 -1
- package/package.json +51 -13
- package/src/cjs/package.json +19 -0
- package/src/exposedInternalUtilityTypes.ts +1152 -0
- package/src/exposedUtilityTypes.ts +20 -0
- package/src/internal.ts +73 -0
- package/src/jsonDeserialized.ts +118 -0
- package/src/jsonSerializable.ts +133 -0
- package/src/jsonSerializationErrors.ts +34 -0
- package/src/jsonType.ts +37 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exposedInternalUtilityTypes.js","sourceRoot":"","sources":["../src/exposedInternalUtilityTypes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAUH;;GAEG;AACH,MAAM,qBAAqB,GAAkB,MAAM,CAAC,gBAAgB,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @rushstack/no-new-null */\n\nimport type {\n\tSerializationErrorPerNonPublicProperties,\n\tSerializationErrorPerUndefinedArrayElement,\n} from \"./jsonSerializationErrors.js\";\nimport type { JsonTypeWith, NonNullJsonObjectWith } from \"./jsonType.js\";\n\n/**\n * Unique symbol for recursion meta-typing.\n */\nconst RecursionMarkerSymbol: unique symbol = Symbol(\"recursion here\");\n\n/**\n * Collection of utility types that are not intended to be used/imported\n * directly outside of this package.\n *\n * @privateRemarks\n * There are ony three intentional exports from this module:\n * - {@link InternalUtilityTypes.IfSameType | IfSameType}\n * - {@link InternalUtilityTypes.JsonDeserializedImpl | JsonDeserializedImpl }\n * - {@link InternalUtilityTypes.JsonSerializableImpl | JsonSerializableImpl }\n *\n * api-extractor will allow `export` to be removed from others but generates\n * api-report a little oddly with a rogue `{};` floating at end of namespace\n * in api.md file. It will promote all of the support types to appear as\n * exported anyway. All in namespace are left exported to avoid api-extractor\n * potentially failing to validate other modules correctly.\n *\n * @beta\n * @system\n */\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace InternalUtilityTypes {\n\t/**\n\t * Meta-type for controlling filtering utilities.\n\t *\n\t * @system\n\t */\n\texport interface FilterControls {\n\t\t/**\n\t\t * Tuple of exact types that are managed by custom serialization/deserialization\n\t\t * logic (beyond JSON.stringify and JSON.parse without replacers/revivers).\n\t\t * Only exact types matching specification will be preserved unaltered.\n\t\t */\n\t\tAllowExactly: unknown[];\n\n\t\t/**\n\t\t * General types that are managed by custom serialization/deserialization\n\t\t * logic (beyond JSON.stringify and JSON.parse without replacers/revivers).\n\t\t * Any type satisfying specification will be preserved unaltered.\n\t\t */\n\t\tAllowExtensionOf: unknown;\n\t}\n\n\t/**\n\t * Meta-type for controlling filtering utilities that additionally supplies\n\t * a substitute type for degenerate cases.\n\t *\n\t * @system\n\t */\n\tinterface FilterControlsWithSubstitution extends FilterControls {\n\t\t/**\n\t\t * Type to use for degenerate cases like `unknown` or `any`.\n\t\t * Typically this will be `JsonTypeWith<TupleToUnion<AllowExactly> | AllowExtensionOf>`.\n\t\t */\n\t\tDegenerateSubstitute: unknown;\n\t}\n\n\t/**\n\t * Meta-type for controlling deserialized filtering utilities.\n\t *\n\t * @system\n\t */\n\tinterface DeserializedFilterControls extends FilterControlsWithSubstitution {\n\t\t/**\n\t\t * Type to use for degenerate `object` case.\n\t\t * Typically this will be `NonNullJsonObjectWith<TupleToUnion<AllowExactly> | AllowExtensionOf>`.\n\t\t */\n\t\tDegenerateNonNullObjectSubstitute: unknown;\n\t}\n\n\t/**\n\t * Returns non-symbol keys for optional properties of an object type.\n\t * This excludes indexed properties that are inherently _optional_.\n\t *\n\t * For homomorphic mapping use with `as` to filter. Example:\n\t * `[K in keyof T as OptionalNonSymbolKeysOf<T, K>]: ...`\n\t *\n\t * @system\n\t */\n\texport type OptionalNonSymbolKeysOf<\n\t\tT extends object,\n\t\tKeys extends keyof T = keyof T,\n\t> = Exclude<\n\t\t{\n\t\t\t[K in Keys]: T extends Record<K, T[K]> ? never : K;\n\t\t}[Keys],\n\t\tundefined | symbol\n\t>;\n\n\t/**\n\t * Returns non-symbol keys for required properties of an object type.\n\t * This includes indexed properties that are inherently _optional_.\n\t *\n\t * For homomorphic mapping use with `as` to filter. Example:\n\t * `[K in keyof T as RequiredNonSymbolKeysOf<T, K>]: ...`\n\t *\n\t * @system\n\t */\n\texport type RequiredNonSymbolKeysOf<\n\t\tT extends object,\n\t\tKeys extends keyof T = keyof T,\n\t> = Exclude<\n\t\t{\n\t\t\t[K in Keys]: T extends Record<K, T[K]> ? K : never;\n\t\t}[Keys],\n\t\tundefined | symbol\n\t>;\n\n\t/**\n\t * Returns Result.WhenSomethingDeserializable if T is sometimes at least a\n\t * partially deserializable type, otherwise Result.WhenNeverDeserializable.\n\t * Fully not deserializable (bigints, symbols, undefined and functions without\n\t * other properties less overlap with T*Exception) produce Result.WhenNeverDeserializable.\n\t * An object would have a defined result even if parts of its content are\n\t * not deserializable.\n\t *\n\t * @param Result - Result type with two properties. One property must always\n\t * be `never` as `T` maybe a union of never deserializable and at least\n\t * partially deserializable types and the result is a union of Result.*.\n\t *\n\t * @privateRemarks\n\t * If `Result.WhenSomethingDeserializable` was `true` and\n\t * `Result.WhenNeverDeserializable` was `false`, then the return type\n\t * for type `T` would be `boolean` for a sometimes deserializable type.\n\t *\n\t * @system\n\t */\n\texport type TestDeserializabilityOf<\n\t\tT,\n\t\tTExactExceptions extends unknown[],\n\t\tTExtendsException,\n\t\tResult extends\n\t\t\t| { WhenSomethingDeserializable: unknown; WhenNeverDeserializable: never }\n\t\t\t| { WhenSomethingDeserializable: never; WhenNeverDeserializable: unknown },\n\t> = /* ensure working with more than never */ T extends never\n\t\t? /* never => */ Result[\"WhenNeverDeserializable\"]\n\t\t: /* check for extends exception */ T extends TExtendsException\n\t\t\t? /* extends exception => */ Result[\"WhenSomethingDeserializable\"]\n\t\t\t: /* no extends exception => check for exact exception */ IfExactTypeInTuple<\n\t\t\t\t\tT,\n\t\t\t\t\tTExactExceptions,\n\t\t\t\t\t/* exact exception => */ Result[\"WhenSomethingDeserializable\"],\n\t\t\t\t\t/* no exception => check for only non-serializable value types */ T extends\n\t\t\t\t\t\t| bigint\n\t\t\t\t\t\t| symbol\n\t\t\t\t\t\t| undefined\n\t\t\t\t\t\t? /* not serializable => */ Result[\"WhenNeverDeserializable\"]\n\t\t\t\t\t\t: // eslint-disable-next-line @typescript-eslint/ban-types\n\t\t\t\t\t\t\tT extends Function\n\t\t\t\t\t\t\t? ExtractFunctionFromIntersection<T> extends {\n\t\t\t\t\t\t\t\t\tclassification: \"exactly Function\";\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t? /* not serializable => */ Result[\"WhenNeverDeserializable\"]\n\t\t\t\t\t\t\t\t: /* at least partially serializable */ Result[\"WhenSomethingDeserializable\"]\n\t\t\t\t\t\t\t: /* at least partially serializable */ Result[\"WhenSomethingDeserializable\"]\n\t\t\t\t>;\n\n\t/**\n\t * Similar to `Exclude` but only excludes exact `U`s from `T`\n\t * rather than any type that extends `U`.\n\t *\n\t * @system\n\t */\n\texport type ExcludeExactly<T, U> = IfSameType<T, U, never, T>;\n\n\t/**\n\t * Similar to `Exclude` but only excludes exact members of `U` from `T`\n\t * rather than any type that extends members of `U`.\n\t *\n\t * @system\n\t */\n\texport type ExcludeExactlyInTuple<T, TupleOfU extends unknown[]> = IfExactTypeInTuple<\n\t\tT,\n\t\tTupleOfU,\n\t\tnever,\n\t\tT\n\t>;\n\n\t/**\n\t * Similar to `Omit` but operates on tuples.\n\t * Removes elements of `Tuple` that extend `U`.\n\t *\n\t * @system\n\t */\n\texport type OmitFromTuple<\n\t\tTuple extends unknown[],\n\t\tU,\n\t\tAccumulated extends unknown[] = [],\n\t> = Tuple extends [infer First, ...infer Rest]\n\t\t? OmitFromTuple<Rest, U, First extends U ? Accumulated : [...Accumulated, First]>\n\t\t: Accumulated;\n\n\t/**\n\t * Similar to `OmitFromTuple` but removes only exact matches of U.\n\t * Removes elements of `Tuple` that are exactly `U`.\n\t *\n\t * @remarks If `U` is a union, then only exactly matching union elements of `Tuple` are removed.\n\t * @system\n\t */\n\texport type OmitExactlyFromTuple<\n\t\tTuple extends unknown[],\n\t\tU,\n\t\tAccumulated extends unknown[] = [],\n\t> = Tuple extends [infer First, ...infer Rest]\n\t\t? OmitExactlyFromTuple<Rest, U, IfSameType<First, U, Accumulated, [...Accumulated, First]>>\n\t\t: Accumulated;\n\n\t/**\n\t * Returns non-symbol keys for defined, (likely) serializable properties of an\n\t * object type. Keys with fully unsupported properties (undefined, symbol, and\n\t * bigint) and sometimes unsupported (functions) are excluded. An exception to\n\t * that is when there are supported types in union with just bigint.\n\t *\n\t * For homomorphic mapping use with `as` to filter. Example:\n\t * `[K in keyof T as NonSymbolWithDeserializablePropertyOf<T, [], never, K>]: ...`\n\t *\n\t * @system\n\t */\n\texport type NonSymbolWithDeserializablePropertyOf<\n\t\tT extends object,\n\t\tTExactExceptions extends unknown[],\n\t\tTExtendsException,\n\t\tKeys extends keyof T = keyof T,\n\t> = Exclude<\n\t\t{\n\t\t\t[K in Keys]: /* all possible types that aren't already allowed, with the exception of `unknown` */\n\t\t\tExcludeExactlyInTuple<\n\t\t\t\tExclude<T[K], TExtendsException>,\n\t\t\t\tOmitExactlyFromTuple<TExactExceptions, unknown>\n\t\t\t> extends infer PossibleTypeLessAllowed\n\t\t\t\t? IfSameType<\n\t\t\t\t\t\tPossibleTypeLessAllowed,\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t/* value might not be supported => exclude K */ never,\n\t\t\t\t\t\t/* extract types that might lead to missing property */ Extract<\n\t\t\t\t\t\t\tPossibleTypeLessAllowed,\n\t\t\t\t\t\t\t/* types that might lead to missing property, except `bigint` */\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/ban-types\n\t\t\t\t\t\t\tundefined | symbol | Function\n\t\t\t\t\t\t> extends never\n\t\t\t\t\t\t\t? /* all types are supported plus possibly `bigint` => */\n\t\t\t\t\t\t\t\t/* check for only `bigint` remaining */ IfSameType<\n\t\t\t\t\t\t\t\t\tPossibleTypeLessAllowed,\n\t\t\t\t\t\t\t\t\tbigint,\n\t\t\t\t\t\t\t\t\t/* only `bigint` => nothing supported */ never,\n\t\t\t\t\t\t\t\t\t/* exclusively supported types (and maybe `bigint`) or exactly `never` */\n\t\t\t\t\t\t\t\t\t/* => check for `never` */ T[K] extends never ? never : K\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t: /* value might not be supported => exclude K */ never\n\t\t\t\t\t>\n\t\t\t\t: never;\n\t\t}[Keys],\n\t\tundefined | symbol\n\t>;\n\n\t/**\n\t * Returns non-symbol keys for partially supported properties of an object type.\n\t * Keys with only unsupported properties (undefined, symbol, bigint, and\n\t * functions without other properties) are excluded.\n\t *\n\t * For homomorphic mapping use with `as` to filter. Example:\n\t * `[K in keyof T as NonSymbolWithPossiblyDeserializablePropertyOf<T, [], never, K>]: ...`\n\t *\n\t * @system\n\t */\n\texport type NonSymbolWithPossiblyDeserializablePropertyOf<\n\t\tT extends object,\n\t\tTExactExceptions extends unknown[],\n\t\tTExtendsException,\n\t\tKeys extends keyof T = keyof T,\n\t> = Exclude<\n\t\t{\n\t\t\t[K in Keys]: /* all possible types that aren't already allowed, with the exception of `unknown` */\n\t\t\tExcludeExactlyInTuple<\n\t\t\t\tExclude<T[K], TExtendsException>,\n\t\t\t\tOmitExactlyFromTuple<TExactExceptions, unknown>\n\t\t\t> extends infer PossibleTypeLessAllowed\n\t\t\t\t? Extract<\n\t\t\t\t\t\tIfSameType<PossibleTypeLessAllowed, unknown, undefined, PossibleTypeLessAllowed>,\n\t\t\t\t\t\t/* types that might lead to missing property */\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/ban-types\n\t\t\t\t\t\tundefined | symbol | Function\n\t\t\t\t\t> extends never\n\t\t\t\t\t? /* exclusively supported types or exactly `never` */ never\n\t\t\t\t\t: /* at least some unsupported type => check for any supported */ TestDeserializabilityOf<\n\t\t\t\t\t\t\tT[K],\n\t\t\t\t\t\t\tOmitExactlyFromTuple<TExactExceptions, unknown>,\n\t\t\t\t\t\t\tTExtendsException,\n\t\t\t\t\t\t\t{ WhenSomethingDeserializable: K; WhenNeverDeserializable: never }\n\t\t\t\t\t\t>\n\t\t\t\t: never;\n\t\t}[Keys],\n\t\tundefined | symbol\n\t>;\n\n\t/**\n\t * Filters a type `T` for `undefined` that is not viable in an array (or tuple) that\n\t * must go through JSON serialization.\n\t * If `T` is `undefined`, then error type {@link SerializationErrorPerUndefinedArrayElement}\n\t * is returned with hopes of being informative.\n\t *\n\t * @system\n\t */\n\texport type JsonForSerializableArrayItem<\n\t\tT,\n\t\tControls extends FilterControls,\n\t\tTAncestorTypes extends unknown[],\n\t\tTBlessed,\n\t> = /* Some initial filtering must be provided before a test for undefined. */\n\t/* These tests are expected to match those in JsonSerializableImpl. */\n\t/* test for 'any' */ boolean extends (T extends never ? true : false)\n\t\t? /* 'any' => */ TBlessed\n\t\t: /* test for 'unknown' */ unknown extends T\n\t\t\t? /* 'unknown' => */ TBlessed\n\t\t\t: /* test for exact recursion */ IfExactTypeInTuple<\n\t\t\t\t\tT,\n\t\t\t\t\tTAncestorTypes,\n\t\t\t\t\t/* recursion; stop here => */ T,\n\t\t\t\t\t/* test for JSON primitive types or given alternative */ T extends\n\t\t\t\t\t\t| null\n\t\t\t\t\t\t| boolean\n\t\t\t\t\t\t| number\n\t\t\t\t\t\t| string\n\t\t\t\t\t\t| Controls[\"AllowExtensionOf\"]\n\t\t\t\t\t\t? /* primitive types or alternative => */ T\n\t\t\t\t\t\t: /* test for exact alternative */ IfExactTypeInTuple<\n\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\tControls[\"AllowExactly\"],\n\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\t/* test for undefined possibility */ undefined extends T\n\t\t\t\t\t\t\t\t\t? /* undefined | ... => */ SerializationErrorPerUndefinedArrayElement\n\t\t\t\t\t\t\t\t\t: TBlessed\n\t\t\t\t\t\t\t>\n\t\t\t\t>;\n\n\t/**\n\t * Filters a type `T` for types that become null through JSON serialization.\n\t *\n\t * @system\n\t */\n\texport type JsonForDeserializedArrayItem<\n\t\tT,\n\t\tControls extends DeserializedFilterControls,\n\t\tTBlessed,\n\t> = /* Some initial filtering must be provided before a test for undefined, symbol, or function. */\n\t/* These tests are expected to match those in JsonDeserializedImpl. */\n\t/* test for 'any' */ boolean extends (T extends never ? true : false)\n\t\t? /* 'any' => */ TBlessed\n\t\t: /* test for 'unknown' */ unknown extends T\n\t\t\t? /* 'unknown' => */ TBlessed\n\t\t\t: /* test for JSON primitive types or general alternative */ T extends\n\t\t\t\t\t\t| null\n\t\t\t\t\t\t| boolean\n\t\t\t\t\t\t| number\n\t\t\t\t\t\t| string\n\t\t\t\t\t\t| Controls[\"AllowExtensionOf\"]\n\t\t\t\t? /* primitive or replaced types => */ T\n\t\t\t\t: /* test for exact alternative */ IfExactTypeInTuple<\n\t\t\t\t\t\tT,\n\t\t\t\t\t\tControls[\"AllowExactly\"],\n\t\t\t\t\t\t/* exactly replaced => */ T,\n\t\t\t\t\t\t/* test for known types that become null */ T extends undefined | symbol\n\t\t\t\t\t\t\t? /* => */ null\n\t\t\t\t\t\t\t: // eslint-disable-next-line @typescript-eslint/ban-types\n\t\t\t\t\t\t\t\tT extends Function\n\t\t\t\t\t\t\t\t? ExtractFunctionFromIntersection<T> extends {\n\t\t\t\t\t\t\t\t\t\tclassification: \"exactly Function\";\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t? null\n\t\t\t\t\t\t\t\t\t: null | TBlessed\n\t\t\t\t\t\t\t\t: TBlessed\n\t\t\t\t\t>;\n\n\t/**\n\t * Checks for a type that is simple class of number and string indexed types to numbers and strings.\n\t *\n\t * @system\n\t */\n\texport type IfEnumLike<\n\t\tT extends object,\n\t\tEnumLike = never,\n\t\tNotEnumLike = unknown,\n\t> = T extends readonly (infer _)[]\n\t\t? /* array => */ NotEnumLike\n\t\t: // eslint-disable-next-line @typescript-eslint/ban-types\n\t\t\tT extends Function\n\t\t\t? /* function => */ NotEnumLike\n\t\t\t: T extends {\n\t\t\t\t\t\t// all numerical indices should refer to a string\n\t\t\t\t\t\treadonly [i: number]: string;\n\t\t\t\t\t\t// string indices may be string or number\n\t\t\t\t\t\treadonly [p: string]: number | string;\n\t\t\t\t\t\t// no symbol indices are allowed\n\t\t\t\t\t\treadonly [s: symbol]: never;\n\t\t\t\t\t}\n\t\t\t\t? /* test for a never or any property */ true extends {\n\t\t\t\t\t\t[K in keyof T]: T[K] extends never ? true : never;\n\t\t\t\t\t}[keyof T]\n\t\t\t\t\t? NotEnumLike\n\t\t\t\t\t: EnumLike\n\t\t\t\t: NotEnumLike;\n\n\t/**\n\t * Test for type equality\n\t *\n\t * @returns IfSame if identical and IfDifferent otherwise.\n\t *\n\t * Implementation derived from https://github.com/Microsoft/TypeScript/issues/27024#issuecomment-421529650\n\t *\n\t * @remarks Use caution when one of the type might be `{}`. That type is\n\t * special and produces unexpected results. This includes variability\n\t * on past usages.\n\t *\n\t * @system\n\t */\n\texport type IfSameType<X, Y, IfSame = unknown, IfDifferent = never> = (<T>() => T extends X\n\t\t? 1\n\t\t: 2) extends <T>() => T extends Y ? 1 : 2\n\t\t? IfSame\n\t\t: IfDifferent;\n\n\t/**\n\t * Test for type equality with tuple of other types.\n\t *\n\t * @typeParam T - Type to find in Tuple.\n\t * @typeParam Tuple - Tuple of types to test against.\n\t * @typeParam IfMatch - Type to return if match is found.\n\t * @typeParam IfNoMatch - Type to return if no match is found.\n\t *\n\t * @privateRemarks\n\t * Tests for an exact match of `T` in `Tuple[0]`. If not found,\n\t * recurses with the remainder of the tuple.\n\t */\n\texport type IfExactTypeInTuple<\n\t\tT,\n\t\tTuple extends unknown[],\n\t\tIfMatch = unknown,\n\t\tIfNoMatch = never,\n\t> = Tuple extends [infer First, ...infer Rest]\n\t\t? IfSameType<T, First, IfMatch, IfExactTypeInTuple<T, Rest, IfMatch, IfNoMatch>>\n\t\t: IfNoMatch;\n\n\t/**\n\t * Test for type equality with union of other types.\n\t *\n\t * @typeParam T - Type to find in Union. If this is itself a union, then all types must be found in Union.\n\t * @typeParam Union - Union of types to test against.\n\t * @typeParam IfMatch - Type to return if match is found.\n\t * @typeParam IfNoMatch - Type to return if no match is found.\n\t *\n\t * @remarks\n\t * In a recursive context, use {@link InternalUtilityTypes.IfExactTypeInTuple} to manage ancestry.\n\t *\n\t * @privateRemarks\n\t * Perhaps it is a Typescript defect but a simple check that `T` is `never`\n\t * via `T extends never` does not work as expected in this context.\n\t * Workaround using `IfSameType<..., never,...>`.\n\t * @system\n\t */\n\texport type IfExactTypeInUnion<T, Union, IfMatch = unknown, IfNoMatch = never> = IfSameType<\n\t\tT,\n\t\tnever,\n\t\t/* T is never => */ IfSameType<Union, never, IfMatch, IfNoMatch>,\n\t\t/* T is NOT never => */ IfSameType<T, Extract<Union, T>, IfMatch, IfNoMatch>\n\t>;\n\n\t/**\n\t * Test for type equality\n\t *\n\t * @returns `true` if identical and `false` otherwise.\n\t *\n\t * @remarks Use caution when one of the type might be `{}`. That type is\n\t * special and produces unexpected results. This includes variability\n\t * on past usages.\n\t *\n\t * @system\n\t */\n\texport type IsSameType<X, Y> = IfSameType<X, Y, true, false>;\n\n\t/**\n\t * Checks that type is exactly `object`.\n\t *\n\t * @system\n\t */\n\texport type IsExactlyObject<T extends object> = IsSameType<T, object>;\n\n\t/**\n\t * Creates a simple object type from an intersection of multiple.\n\t * @privateRemarks\n\t * `T extends Record` within the implementation encourages tsc to process\n\t * intersections within unions.\n\t *\n\t * @system\n\t */\n\texport type FlattenIntersection<T extends Record<string | number | symbol, unknown>> =\n\t\tT extends Record<string | number | symbol, unknown>\n\t\t\t? {\n\t\t\t\t\t[K in keyof T]: T[K];\n\t\t\t\t}\n\t\t\t: T;\n\n\t/**\n\t * Extracts Function portion from an intersection (&) type returning\n\t * the extracted portion in the `function` property or `unknown` if\n\t * no function is found.\n\t * The returned `classification` property has one of three values:\n\t * - \"no Function\" if the type is not a function.\n\t * - \"exactly Function\" if the type is exactly a function.\n\t * - \"Function and more\" if the type is a function and has other properties.\n\t *\n\t * @system\n\t */\n\texport type ExtractFunctionFromIntersection<T extends object> = (T extends new (\n\t\t...args: infer A\n\t) => infer R\n\t\t? new (\n\t\t\t\t...args: A\n\t\t\t) => R\n\t\t: unknown) &\n\t\t(T extends (...args: infer A) => infer R\n\t\t\t? (...args: A) => R\n\t\t\t: unknown) extends infer Functional\n\t\t? {\n\t\t\t\tclassification: unknown extends Functional\n\t\t\t\t\t? \"no Function\"\n\t\t\t\t\t: Functional extends Required<T>\n\t\t\t\t\t\t? \"exactly Function\"\n\t\t\t\t\t\t: \"Function and more\";\n\t\t\t\tfunction: Functional;\n\t\t\t}\n\t\t: never;\n\n\t/**\n\t * Returns `Filtered` & any Function intersection from `Original`.\n\t * If `Original` is exactly a Function, then `Filtered` is left out\n\t * under the assumption that it is not useful/applicable.\n\t *\n\t * @system\n\t */\n\texport type FilterPreservingFunction<\n\t\tOriginal extends object,\n\t\tFiltered,\n\t> = ExtractFunctionFromIntersection<Original> extends {\n\t\tclassification: infer TClassification;\n\t\tfunction: infer TFunction;\n\t}\n\t\t? TClassification extends \"exactly Function\"\n\t\t\t? TFunction\n\t\t\t: TFunction & Filtered\n\t\t: never;\n\n\t/**\n\t * Replaces any instance where a type T recurses into itself or a portion of\n\t * itself with TRecursionMarker.\n\t *\n\t * @typeParam T - Type to process.\n\t * @typeParam TRecursionMarker - Replacement marker type.\n\t * @typeParam Controls - Allowances are preserved as-is.\n\t * @typeParam TAncestorTypes - Tuple of types that are ancestors of T.\n\t * @typeParam TNextAncestor - Set exactly to T. This is passed separately\n\t * such that T union types remain intact as exact ancestors.\n\t *\n\t * @remarks\n\t * Filtering applied to class instances with non-public properties will not\n\t * preserve the class instance unless those classes are known and listed as\n\t * allowances via `Controls`.\n\t *\n\t * @privateRemarks\n\t * This implementation handles functions including function with properties.\n\t * There are no known cases where replacing recursion under such types make\n\t * a difference. Either the function (whole type) is allowed by the Json\n\t * filters or function is not allowed at all.\n\t * If the function portion is found to be problematic later, then could use\n\t * `T extends Function ? T : ...` to ignore function objects.\n\t *\n\t * @system\n\t */\n\texport type ReplaceRecursionWithMarkerAndPreserveAllowances<\n\t\tT,\n\t\tTRecursionMarker,\n\t\tControls extends FilterControls,\n\t\tTAncestorTypes extends unknown[] = [],\n\t\tTNextAncestor = T,\n\t> = /* test for recursion */\n\tIfExactTypeInTuple<T, TAncestorTypes, true, \"no match\"> extends true\n\t\t? /* recursion => use replacement */ TRecursionMarker\n\t\t: /* force union separation hereafter */ T extends infer _\n\t\t\t? /* test for recursion among union elements */\n\t\t\t\tIfExactTypeInTuple<T, TAncestorTypes, true, \"no match\"> extends true\n\t\t\t\t? TRecursionMarker\n\t\t\t\t: /* test for general allowance */ T extends Controls[\"AllowExtensionOf\"]\n\t\t\t\t\t? /* allowed extension type => */ T\n\t\t\t\t\t: /* test for exact allowance */ IfExactTypeInTuple<\n\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\tControls[\"AllowExactly\"],\n\t\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\t\t\"no match\"\n\t\t\t\t\t\t\t> extends true\n\t\t\t\t\t\t? /* exact allowed type => */ T\n\t\t\t\t\t\t: T extends object\n\t\t\t\t\t\t\t? FilterPreservingFunction<\n\t\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t[K in keyof T]: ReplaceRecursionWithMarkerAndPreserveAllowances<\n\t\t\t\t\t\t\t\t\t\t\tT[K],\n\t\t\t\t\t\t\t\t\t\t\tTRecursionMarker,\n\t\t\t\t\t\t\t\t\t\t\tControls,\n\t\t\t\t\t\t\t\t\t\t\t[TNextAncestor, ...TAncestorTypes]\n\t\t\t\t\t\t\t\t\t\t>;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t: /* non-object => T as is */ T\n\t\t\t: never;\n\n\t/**\n\t * Replaces any instances of \"allowed\" types and recursion within with `never`.\n\t *\n\t * @typeParam T - Type to process.\n\t * @typeParam Controls - Allowances to replace.\n\t * @typeParam TAncestorTypes - Tuple of types that are ancestors of T.\n\t * @typeParam TNextAncestor - Set exactly to T. This is passed separately\n\t * such that T union types remain intact as exact ancestors.\n\t *\n\t * @system\n\t */\n\texport type ReplaceAllowancesAndRecursionWithNever<\n\t\tT,\n\t\tControls extends FilterControls,\n\t\tTAncestorTypes extends unknown[] = [],\n\t\tTNextAncestor = T,\n\t> = /* test for exact recursion first */ IfExactTypeInTuple<\n\t\tT,\n\t\tTAncestorTypes,\n\t\ttrue,\n\t\t\"no match\"\n\t> extends true\n\t\t? /* recursion => */ never\n\t\t: /* test for general allowance (also forces union separation) */ T extends Controls[\"AllowExtensionOf\"]\n\t\t\t? /* allowed extension type => */ never\n\t\t\t: /* test for exact allowance */ IfExactTypeInTuple<\n\t\t\t\t\t\tT,\n\t\t\t\t\t\tControls[\"AllowExactly\"],\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\"no match\"\n\t\t\t\t\t> extends true\n\t\t\t\t? /* exact allowed type => */ never\n\t\t\t\t: /* test for recursion among union elements */ IfExactTypeInTuple<\n\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\tTAncestorTypes,\n\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\t\"no match\"\n\t\t\t\t\t\t> extends true\n\t\t\t\t\t? /* recursion => */ never\n\t\t\t\t\t: T extends object\n\t\t\t\t\t\t? FilterPreservingFunction<\n\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t[K in keyof T]: ReplaceAllowancesAndRecursionWithNever<\n\t\t\t\t\t\t\t\t\t\tT[K],\n\t\t\t\t\t\t\t\t\t\tControls,\n\t\t\t\t\t\t\t\t\t\t[TNextAncestor, ...TAncestorTypes]\n\t\t\t\t\t\t\t\t\t>;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t: /* non-object => T as is */ T;\n\n\t/**\n\t * Test for non-public properties (which can only exist on class instance types).\n\t *\n\t * Returns `HasNonPublic` if `T` deeply may contain a private or protected field\n\t * and `OnlyPublics` otherwise.\n\t *\n\t * @remarks\n\t * Compare original (unprocessed) to filtered case that has `never` where\n\t * recursing or where allowed exception types are used.\n\t *\n\t * Note that this a test of the type and not the actual data. So, if an\n\t * interface is given as `T` where implemented by a class, any private or\n\t * protected fields within the class will not be detected.\n\t *\n\t * @system\n\t */\n\texport type IfNonPublicProperties<\n\t\tT,\n\t\tControls extends FilterControls,\n\t\tHasNonPublic = never,\n\t\tOnlyPublics = unknown,\n\t> = ReplaceAllowancesAndRecursionWithNever<T, Controls> extends T\n\t\t? OnlyPublics\n\t\t: HasNonPublic;\n\n\t/**\n\t * Union of all types in a tuple.\n\t *\n\t * @system\n\t */\n\texport type TupleToUnion<T extends unknown[]> = T[number];\n\n\t// #region JsonSerializable implementation\n\n\t/**\n\t * Outer implementation of {@link JsonSerializable} handling meta cases\n\t * like classes (with non-public properties).\n\t *\n\t * @system\n\t */\n\texport type JsonSerializableImpl<\n\t\tT,\n\t\tOptions extends Partial<FilterControls> & {\n\t\t\tIgnoreInaccessibleMembers?: \"ignore-inaccessible-members\";\n\t\t},\n\t\tTAncestorTypes extends unknown[] = [],\n\t\tTNextAncestor = T,\n\t> = /* Build Controls from Options filling in defaults for any missing properties */\n\t{\n\t\tAllowExactly: Options extends { AllowExactly: unknown[] } ? Options[\"AllowExactly\"] : [];\n\t\tAllowExtensionOf: Options extends { AllowExtensionOf: unknown }\n\t\t\t? Options[\"AllowExtensionOf\"]\n\t\t\t: never;\n\t\t// There Substitute type could be extracted to helper type, but are kept explicit here\n\t\t// to make JsonTypeWith show explicitly in results for users, rather\n\t\t// than either the helper type name or a partially unrolled version.\n\t\tDegenerateSubstitute: JsonTypeWith<\n\t\t\t| (Options extends { AllowExactly: unknown[] }\n\t\t\t\t\t? TupleToUnion<Options[\"AllowExactly\"]>\n\t\t\t\t\t: never)\n\t\t\t| (Options extends { AllowExtensionOf: unknown } ? Options[\"AllowExtensionOf\"] : never)\n\t\t>;\n\t} extends infer Controls\n\t\t? /* Controls should always satisfy FilterControlsWithSubstitution, but Typescript wants a check */\n\t\t\tControls extends FilterControlsWithSubstitution\n\t\t\t? /* test for 'any' */ boolean extends (T extends never ? true : false)\n\t\t\t\t? /* 'any' => */ Controls[\"DegenerateSubstitute\"]\n\t\t\t\t: Options[\"IgnoreInaccessibleMembers\"] extends \"ignore-inaccessible-members\"\n\t\t\t\t\t? JsonSerializableFilter<T, Controls, TAncestorTypes, TNextAncestor>\n\t\t\t\t\t: /* test for non-public properties (class instance type) */\n\t\t\t\t\t\tIfNonPublicProperties<\n\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tAllowExactly: Controls[\"AllowExactly\"];\n\t\t\t\t\t\t\t\t\t// Add in primitives that may be branded to ignore intersection classes\n\t\t\t\t\t\t\t\t\tAllowExtensionOf: Controls[\"AllowExtensionOf\"] | boolean | number | string;\n\t\t\t\t\t\t\t\t\tDegenerateSubstitute: Controls[\"DegenerateSubstitute\"];\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\"found non-publics\",\n\t\t\t\t\t\t\t\t\"only publics\"\n\t\t\t\t\t\t\t> extends \"found non-publics\"\n\t\t\t\t\t\t? /* hidden props => test if it is array properties that are the problem */ T extends readonly (infer _)[]\n\t\t\t\t\t\t\t? /* array => */ {\n\t\t\t\t\t\t\t\t\t/* use homomorphic mapped type to preserve tuple type */\n\t\t\t\t\t\t\t\t\t[K in keyof T]: JsonSerializableImpl<\n\t\t\t\t\t\t\t\t\t\tT[K],\n\t\t\t\t\t\t\t\t\t\tControls,\n\t\t\t\t\t\t\t\t\t\t[TNextAncestor, ...TAncestorTypes]\n\t\t\t\t\t\t\t\t\t>;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: /* test for potentially branded primitive (intersection with a supported primitive) */\n\t\t\t\t\t\t\t\tT extends boolean | number | string\n\t\t\t\t\t\t\t\t? /* assume intersection is branding and allow as-is => */ T\n\t\t\t\t\t\t\t\t: /* not array => error */ SerializationErrorPerNonPublicProperties\n\t\t\t\t\t\t: /* no hidden properties => apply filtering => */ JsonSerializableFilter<\n\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\tControls,\n\t\t\t\t\t\t\t\tTAncestorTypes,\n\t\t\t\t\t\t\t\tTNextAncestor\n\t\t\t\t\t\t\t>\n\t\t\t: never /* FilterControlsWithSubstitution assert else; should never be reached */\n\t\t: never /* unreachable else for infer */;\n\n\t/**\n\t * Essentially a check for a template literal that has $\\{string\\} or\n\t * $\\{number\\} in the pattern. Just `string` and/or `number` also match.\n\t *\n\t * @remarks This works recursively looking at first elements when not\n\t * `string` or `number`. `first` will just be a single character if\n\t * not $\\{string\\} or $\\{number\\}.\n\t *\n\t * @system\n\t */\n\texport type IfIndexKey<T, IfIndex, IfLiteral> = `${string}` extends T\n\t\t? IfIndex\n\t\t: number extends T\n\t\t\t? IfIndex\n\t\t\t: T extends `${infer first}${infer rest}`\n\t\t\t\t? string extends first\n\t\t\t\t\t? IfIndex\n\t\t\t\t\t: `${number}` extends first\n\t\t\t\t\t\t? IfIndex\n\t\t\t\t\t\t: IfIndexKey<rest, IfIndex, IfLiteral>\n\t\t\t\t: IfLiteral;\n\n\t/**\n\t * Helper for {@link JsonSerializableFilter} to determine if a property may\n\t * be `undefined` and selects from options for result.\n\t * Since `unknown` is a superset of `undefined`, it is given a special case.\n\t * Additionally since index signatures are inherently optional, `unknown` typed\n\t * values are treated as not undefined (`Result[\"Otherwise\"]`).\n\t *\n\t * @system\n\t */\n\texport type IfPossiblyUndefinedProperty<\n\t\tTKey,\n\t\tTValue,\n\t\tResult extends {\n\t\t\tIfPossiblyUndefined: unknown;\n\t\t\tIfUnknownNonIndexed: unknown;\n\t\t\tOtherwise: unknown;\n\t\t},\n\t> = undefined extends TValue\n\t\t? unknown extends TValue\n\t\t\t? IfIndexKey<TKey, Result[\"Otherwise\"], Result[\"IfUnknownNonIndexed\"]>\n\t\t\t: Result[\"IfPossiblyUndefined\"]\n\t\t: Result[\"Otherwise\"];\n\n\t/**\n\t * Core implementation of {@link JsonSerializable}.\n\t *\n\t * @privateRemarks\n\t * Filtering through a single layer of recursion is all that is required\n\t * when using in prescribed filter scenario.\n\t *\n\t * @system\n\t */\n\texport type JsonSerializableFilter<\n\t\tT,\n\t\tControls extends FilterControlsWithSubstitution,\n\t\tTAncestorTypes extends unknown[],\n\t\tTNextAncestor = T,\n\t> = /* test for 'any' */ boolean extends (T extends never ? true : false)\n\t\t? /* 'any' => */ Controls[\"DegenerateSubstitute\"]\n\t\t: /* test for 'unknown' */ unknown extends T\n\t\t\t? /* 'unknown' => */ Controls[\"DegenerateSubstitute\"]\n\t\t\t: /* test for recursion */ IfExactTypeInTuple<\n\t\t\t\t\t\tT,\n\t\t\t\t\t\tTAncestorTypes,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\"no match\"\n\t\t\t\t\t> extends true\n\t\t\t\t? /* exact recursion; stop here => */ T\n\t\t\t\t: /* test for JSON Encodable primitive types or given alternate base */ T extends\n\t\t\t\t\t\t\t| null\n\t\t\t\t\t\t\t| boolean\n\t\t\t\t\t\t\t| number\n\t\t\t\t\t\t\t| string\n\t\t\t\t\t\t\t| Controls[\"AllowExtensionOf\"]\n\t\t\t\t\t? /* primitive types or alternate => */ T\n\t\t\t\t\t: /* test for exact alternate */ IfExactTypeInTuple<\n\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\tControls[\"AllowExactly\"],\n\t\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\t\t\"no match\"\n\t\t\t\t\t\t\t> extends true\n\t\t\t\t\t\t? /* exact alternate type => */ T\n\t\t\t\t\t\t: // eslint-disable-next-line @typescript-eslint/ban-types\n\t\t\t\t\t\t\t/* test for not a function */ Extract<T, Function> extends never\n\t\t\t\t\t\t\t? /* not a function => test for object */ T extends object\n\t\t\t\t\t\t\t\t? /* object => test for array */ T extends readonly (infer _)[]\n\t\t\t\t\t\t\t\t\t? /* array => */ {\n\t\t\t\t\t\t\t\t\t\t\t/* array items may not not allow undefined */\n\t\t\t\t\t\t\t\t\t\t\t/* use homomorphic mapped type to preserve tuple type */\n\t\t\t\t\t\t\t\t\t\t\t[K in keyof T]: JsonForSerializableArrayItem<\n\t\t\t\t\t\t\t\t\t\t\t\tT[K],\n\t\t\t\t\t\t\t\t\t\t\t\tControls,\n\t\t\t\t\t\t\t\t\t\t\t\tTAncestorTypes,\n\t\t\t\t\t\t\t\t\t\t\t\tJsonSerializableFilter<\n\t\t\t\t\t\t\t\t\t\t\t\t\tT[K],\n\t\t\t\t\t\t\t\t\t\t\t\t\tControls,\n\t\t\t\t\t\t\t\t\t\t\t\t\t[TNextAncestor, ...TAncestorTypes]\n\t\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t>;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t: /* not an array => test for exactly `object` */ IsExactlyObject<T> extends true\n\t\t\t\t\t\t\t\t\t\t? /* `object` => */ NonNullJsonObjectWith<\n\t\t\t\t\t\t\t\t\t\t\t\tTupleToUnion<Controls[\"AllowExactly\"]> | Controls[\"AllowExtensionOf\"]\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t: /* test for enum like types */ IfEnumLike<T> extends never\n\t\t\t\t\t\t\t\t\t\t\t? /* enum or similar simple type (return as-is) => */ T\n\t\t\t\t\t\t\t\t\t\t\t: /* property bag => */ FlattenIntersection<\n\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* required properties are recursed and may not have undefined values. */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t[K in keyof T as RequiredNonSymbolKeysOf<\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tK\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t>]-?: IfPossiblyUndefinedProperty<\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tK,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tT[K],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tIfPossiblyUndefined: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t[\"error required property may not allow `undefined` value\"]: never;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tIfUnknownNonIndexed: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t[\"error required property may not allow `unknown` value\"]: never;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tOtherwise: JsonSerializableFilter<\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tT[K],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tControls,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t[TNextAncestor, ...TAncestorTypes]\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t>;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t>;\n\t\t\t\t\t\t\t\t\t\t\t\t\t} & {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* optional properties are recursed and, when exactOptionalPropertyTypes is\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t false, are allowed to preserve undefined value type. */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t[K in keyof T as OptionalNonSymbolKeysOf<\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tK\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t>]?: JsonSerializableFilter<\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tT[K],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tControls,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t[TNextAncestor, ...TAncestorTypes]\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t>;\n\t\t\t\t\t\t\t\t\t\t\t\t\t} & {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* symbol properties are rejected */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t[K in keyof T & symbol]: never;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t: /* not an object => */ never\n\t\t\t\t\t\t\t: /* function => */ never;\n\n\t// #endregion\n\n\t// #region JsonDeserialized implementation\n\n\t/**\n\t * Sentinel type for use when marking points of recursion (in a recursive type).\n\t * Type is expected to be unique, though no lengths are taken to ensure that.\n\t *\n\t * @system\n\t */\n\texport interface RecursionMarker {\n\t\t[RecursionMarkerSymbol]: typeof RecursionMarkerSymbol;\n\t}\n\n\t/**\n\t * Recursion limit is the count of `+` that prefix it when string.\n\t *\n\t * @system\n\t */\n\texport type RecursionLimit = `+${string}` | 0;\n\n\t/**\n\t * Outer implementation of {@link JsonDeserialized} handling meta cases\n\t * like recursive types.\n\t *\n\t * @privateRemarks\n\t * This utility is reentrant and will process a type `T` up to RecurseLimit.\n\t *\n\t * @system\n\t */\n\texport type JsonDeserializedImpl<\n\t\tT,\n\t\tOptions extends Partial<FilterControls>,\n\t\tRecurseLimit extends RecursionLimit = \"++++\" /* 4 */,\n\t> = /* Build Controls from Options filling in defaults for any missing properties */\n\t{\n\t\tAllowExactly: Options extends { AllowExactly: unknown[] } ? Options[\"AllowExactly\"] : [];\n\t\tAllowExtensionOf: Options extends { AllowExtensionOf: unknown }\n\t\t\t? Options[\"AllowExtensionOf\"]\n\t\t\t: never;\n\t\t// There Substitute types could be extracted to helper type, but are kept explicit here\n\t\t// to make JsonTypeWith/NonNullJsonObjectWith show explicitly in results for users, rather\n\t\t// than either the helper type name or a partially unrolled version.\n\t\tDegenerateSubstitute: JsonTypeWith<\n\t\t\t| (Options extends { AllowExactly: unknown[] }\n\t\t\t\t\t? TupleToUnion<Options[\"AllowExactly\"]>\n\t\t\t\t\t: never)\n\t\t\t| (Options extends { AllowExtensionOf: unknown } ? Options[\"AllowExtensionOf\"] : never)\n\t\t>;\n\t\tDegenerateNonNullObjectSubstitute: NonNullJsonObjectWith<\n\t\t\t| (Options extends { AllowExactly: unknown[] }\n\t\t\t\t\t? TupleToUnion<Options[\"AllowExactly\"]>\n\t\t\t\t\t: never)\n\t\t\t| (Options extends { AllowExtensionOf: unknown } ? Options[\"AllowExtensionOf\"] : never)\n\t\t>;\n\t} extends infer Controls\n\t\t? /* Controls should always satisfy DeserializedFilterControls, but Typescript wants a check */\n\t\t\tControls extends DeserializedFilterControls\n\t\t\t? /* test for 'any' */ boolean extends (T extends never ? true : false)\n\t\t\t\t? /* 'any' => */ Controls[\"DegenerateSubstitute\"]\n\t\t\t\t: /* infer non-recursive version of T */ ReplaceRecursionWithMarkerAndPreserveAllowances<\n\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\tRecursionMarker,\n\t\t\t\t\t\t\tControls\n\t\t\t\t\t\t> extends infer TNoRecursionAndOnlyPublics\n\t\t\t\t\t? /* test for no change from filtered type */ IsSameType<\n\t\t\t\t\t\t\tTNoRecursionAndOnlyPublics,\n\t\t\t\t\t\t\tJsonDeserializedFilter<\n\t\t\t\t\t\t\t\tTNoRecursionAndOnlyPublics,\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tAllowExactly: [...Controls[\"AllowExactly\"], RecursionMarker];\n\t\t\t\t\t\t\t\t\tAllowExtensionOf: Controls[\"AllowExtensionOf\"];\n\t\t\t\t\t\t\t\t\tDegenerateSubstitute: Controls[\"DegenerateSubstitute\"];\n\t\t\t\t\t\t\t\t\tDegenerateNonNullObjectSubstitute: Controls[\"DegenerateNonNullObjectSubstitute\"];\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t0\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t> extends true\n\t\t\t\t\t\t? /* same (no filtering needed) => test for non-public\n\t\t\t\t\t\t properties (class instance type) */\n\t\t\t\t\t\t\tIfNonPublicProperties<\n\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\t// Note: no extra allowance is made here for possible branded\n\t\t\t\t\t\t\t\t// primitives as JsonDeserializedFilter will allow them as\n\t\t\t\t\t\t\t\t// extensions of the primitives. Should there need a need to\n\t\t\t\t\t\t\t\t// explicit allow them here, see JsonSerializableImpl's use.\n\t\t\t\t\t\t\t\tControls,\n\t\t\t\t\t\t\t\t\"found non-publics\",\n\t\t\t\t\t\t\t\t\"only publics\"\n\t\t\t\t\t\t\t> extends \"found non-publics\"\n\t\t\t\t\t\t\t? /* hidden props => apply filtering to avoid retaining\n\t\t\t\t\t\t\t exact class except for any classes in allowances => */\n\t\t\t\t\t\t\t\tJsonDeserializedFilter<\n\t\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\t\tControls,\n\t\t\t\t\t\t\t\t\t// Note that use of RecurseLimit may not be needed here\n\t\t\t\t\t\t\t\t\t// could have an adverse effect on correctness if there\n\t\t\t\t\t\t\t\t\t// several ancestor types that require modification and\n\t\t\t\t\t\t\t\t\t// are peeling away the limit. In such a case, the limit\n\t\t\t\t\t\t\t\t\t// will be used for the problems and result is already\n\t\t\t\t\t\t\t\t\t// messy; so deferring full understanding of the problems\n\t\t\t\t\t\t\t\t\t// that could arise from a reset and being conservative.\n\t\t\t\t\t\t\t\t\tRecurseLimit\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t: /* no hidden properties => deserialized T is just T */\n\t\t\t\t\t\t\t\tT\n\t\t\t\t\t\t: /* filtering is needed => */ JsonDeserializedFilter<T, Controls, RecurseLimit>\n\t\t\t\t\t: /* unreachable else for infer */ never\n\t\t\t: never /* DeserializedFilterControls assert else; should never be reached */\n\t\t: never /* unreachable else for infer */;\n\n\t/**\n\t * Recurses T applying {@link InternalUtilityTypes.JsonDeserializedFilter} up to RecurseLimit times.\n\t *\n\t * @system\n\t */\n\texport type JsonDeserializedRecursion<\n\t\tT,\n\t\tControls extends DeserializedFilterControls,\n\t\tRecurseLimit extends RecursionLimit,\n\t\tTAncestorTypes,\n\t> = T extends TAncestorTypes\n\t\t? RecurseLimit extends `+${infer RecursionRemainder}`\n\t\t\t? /* Now that specific recursion is found, process that recursive type\n\t\t\t directly to avoid any collateral damage from ancestor type that\n\t\t\t required modification. */\n\t\t\t\tJsonDeserializedImpl<\n\t\t\t\t\tT,\n\t\t\t\t\tControls,\n\t\t\t\t\tRecursionRemainder extends RecursionLimit ? RecursionRemainder : 0\n\t\t\t\t>\n\t\t\t: Controls[\"DegenerateSubstitute\"]\n\t\t: JsonDeserializedFilter<T, Controls, RecurseLimit, TAncestorTypes | T>;\n\n\t/**\n\t * Core implementation of {@link JsonDeserialized}.\n\t *\n\t * @system\n\t */\n\texport type JsonDeserializedFilter<\n\t\tT,\n\t\tControls extends DeserializedFilterControls,\n\t\tRecurseLimit extends RecursionLimit,\n\t\tTAncestorTypes = T /* Always start with self as ancestor; otherwise recursion limit appears one greater */,\n\t> = /* test for 'any' */ boolean extends (T extends never ? true : false)\n\t\t? /* 'any' => */ Controls[\"DegenerateSubstitute\"]\n\t\t: /* test for 'unknown' */ unknown extends T\n\t\t\t? /* 'unknown' => */ Controls[\"DegenerateSubstitute\"]\n\t\t\t: /* test for deserializable primitive types or given alternate base */ T extends\n\t\t\t\t\t\t| null\n\t\t\t\t\t\t| boolean\n\t\t\t\t\t\t| number\n\t\t\t\t\t\t| string\n\t\t\t\t\t\t| Controls[\"AllowExtensionOf\"]\n\t\t\t\t? /* primitive types or alternate => */ T\n\t\t\t\t: /* test for given exact alternate */ IfExactTypeInTuple<\n\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\tControls[\"AllowExactly\"],\n\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\t\"not found\"\n\t\t\t\t\t\t> extends true\n\t\t\t\t\t? /* exact alternate type => */ T\n\t\t\t\t\t: /* test for object */ T extends object\n\t\t\t\t\t\t? /* object => */ ExtractFunctionFromIntersection<T> extends {\n\t\t\t\t\t\t\t\tclassification: \"exactly Function\";\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t? /* exactly function => */ never\n\t\t\t\t\t\t\t: /* not exactly a function (Function portion, if any, is omitted) */\n\t\t\t\t\t\t\t\t/* => test for array */ T extends readonly (infer _)[]\n\t\t\t\t\t\t\t\t? /* array => */ {\n\t\t\t\t\t\t\t\t\t\t/* array items may not not allow undefined */\n\t\t\t\t\t\t\t\t\t\t/* use homomorphic mapped type to preserve tuple type */\n\t\t\t\t\t\t\t\t\t\t[K in keyof T]: JsonForDeserializedArrayItem<\n\t\t\t\t\t\t\t\t\t\t\tT[K],\n\t\t\t\t\t\t\t\t\t\t\tControls,\n\t\t\t\t\t\t\t\t\t\t\tJsonDeserializedRecursion<T[K], Controls, RecurseLimit, TAncestorTypes>\n\t\t\t\t\t\t\t\t\t\t>;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t: /* not an array => test for exactly `object` */ IsExactlyObject<T> extends true\n\t\t\t\t\t\t\t\t\t? /* `object` => */ Controls[\"DegenerateNonNullObjectSubstitute\"]\n\t\t\t\t\t\t\t\t\t: /* test for enum like types */ IfEnumLike<T> extends never\n\t\t\t\t\t\t\t\t\t\t? /* enum or similar simple type (return as-is) => */ T\n\t\t\t\t\t\t\t\t\t\t: /* property bag => */ FlattenIntersection<\n\t\t\t\t\t\t\t\t\t\t\t\t/* properties with symbol keys or wholly unsupported values are removed */\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t/* properties with defined values are recursed */\n\t\t\t\t\t\t\t\t\t\t\t\t\t[K in keyof T as NonSymbolWithDeserializablePropertyOf<\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tControls[\"AllowExactly\"],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tControls[\"AllowExtensionOf\"],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tK\n\t\t\t\t\t\t\t\t\t\t\t\t\t>]: JsonDeserializedRecursion<\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tT[K],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tControls,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tRecurseLimit,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tTAncestorTypes\n\t\t\t\t\t\t\t\t\t\t\t\t\t>;\n\t\t\t\t\t\t\t\t\t\t\t\t} & {\n\t\t\t\t\t\t\t\t\t\t\t\t\t/* properties that may have undefined values are optional */\n\t\t\t\t\t\t\t\t\t\t\t\t\t[K in keyof T as NonSymbolWithPossiblyDeserializablePropertyOf<\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tControls[\"AllowExactly\"],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tControls[\"AllowExtensionOf\"],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tK\n\t\t\t\t\t\t\t\t\t\t\t\t\t>]?: JsonDeserializedRecursion<\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tT[K],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tControls,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tRecurseLimit,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tTAncestorTypes\n\t\t\t\t\t\t\t\t\t\t\t\t\t>;\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t: /* not an object => */ never;\n\n\t// #endregion\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
export type { JsonDeserialized, JsonDeserializedOptions } from "./jsonDeserialized.js";
|
|
6
|
+
export type { JsonSerializable, JsonSerializableOptions } from "./jsonSerializable.js";
|
|
7
|
+
export type { SerializationErrorPerNonPublicProperties, SerializationErrorPerUndefinedArrayElement, } from "./jsonSerializationErrors.js";
|
|
8
|
+
export type { JsonTypeWith, NonNullJsonObjectWith } from "./jsonType.js";
|
|
9
|
+
export type { InternalUtilityTypes } from "./exposedInternalUtilityTypes.js";
|
|
10
|
+
//# sourceMappingURL=exposedUtilityTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exposedUtilityTypes.d.ts","sourceRoot":"","sources":["../src/exposedUtilityTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,YAAY,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACvF,YAAY,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACvF,YAAY,EACX,wCAAwC,EACxC,0CAA0C,GAC1C,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEzE,YAAY,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exposedUtilityTypes.js","sourceRoot":"","sources":["../src/exposedUtilityTypes.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// Usage: Access these types via /internal/exposedUtilityTypes import spec when\n// system level but externally exposed version of utilities are needed.\n// Import via /internal when use is not exposed externally.\n// Should a customer need access to these types, export should be relocated to\n// index.ts and retagged export from internal.ts may be removed.\n\nexport type { JsonDeserialized, JsonDeserializedOptions } from \"./jsonDeserialized.js\";\nexport type { JsonSerializable, JsonSerializableOptions } from \"./jsonSerializable.js\";\nexport type {\n\tSerializationErrorPerNonPublicProperties,\n\tSerializationErrorPerUndefinedArrayElement,\n} from \"./jsonSerializationErrors.js\";\nexport type { JsonTypeWith, NonNullJsonObjectWith } from \"./jsonType.js\";\n\nexport type { InternalUtilityTypes } from \"./exposedInternalUtilityTypes.js\";\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
export * from "./index.js";
|
|
6
|
+
import type { InternalUtilityTypes as ExposedInternalUtilityTypes } from "./exposedInternalUtilityTypes.js";
|
|
7
|
+
import type { JsonDeserialized as ExposedJsonDeserialized, JsonDeserializedOptions } from "./jsonDeserialized.js";
|
|
8
|
+
import type { JsonSerializable as ExposedJsonSerializable, JsonSerializableOptions } from "./jsonSerializable.js";
|
|
9
|
+
import type { JsonTypeWith as ExposedJsonTypeWith } from "./jsonType.js";
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export type JsonDeserialized<T, Options extends JsonDeserializedOptions = {
|
|
14
|
+
AllowExactly: [];
|
|
15
|
+
AllowExtensionOf: never;
|
|
16
|
+
}> = ExposedJsonDeserialized<T, Options>;
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export type JsonSerializable<T, Options extends JsonSerializableOptions = {
|
|
21
|
+
AllowExactly: [];
|
|
22
|
+
AllowExtensionOf: never;
|
|
23
|
+
}> = ExposedJsonSerializable<T, Options>;
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export type JsonTypeWith<T> = ExposedJsonTypeWith<T>;
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export declare namespace InternalUtilityTypes {
|
|
32
|
+
type IfSameType<X, Y, IfSame = unknown, IfDifferent = never> = ExposedInternalUtilityTypes.IfSameType<X, Y, IfSame, IfDifferent>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,YAAY,CAAC;AAU3B,OAAO,KAAK,EAAE,oBAAoB,IAAI,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC5G,OAAO,KAAK,EACX,gBAAgB,IAAI,uBAAuB,EAC3C,uBAAuB,EACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EACX,gBAAgB,IAAI,uBAAuB,EAC3C,uBAAuB,EACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAOzE;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAC3B,CAAC,EACD,OAAO,SAAS,uBAAuB,GAAG;IACzC,YAAY,EAAE,EAAE,CAAC;IACjB,gBAAgB,EAAE,KAAK,CAAC;CACxB,IACE,uBAAuB,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAC3B,CAAC,EACD,OAAO,SAAS,uBAAuB,GAAG;IACzC,YAAY,EAAE,EAAE,CAAC;IACjB,gBAAgB,EAAE,KAAK,CAAC;CACxB,IACE,uBAAuB,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,mBAAmB,CAAC,CAAC,CAAC,CAAC;AAErD;;GAEG;AAEH,yBAAiB,oBAAoB,CAAC;IAErC,KAAY,UAAU,CACrB,CAAC,EACD,CAAC,EACD,MAAM,GAAG,OAAO,EAChB,WAAW,GAAG,KAAK,IAChB,2BAA2B,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;CAEtE"}
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
22
|
+
__exportStar(require("./index.js"), exports);
|
|
23
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;AAEH,gDAAgD;AAChD,6CAA2B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// eslint-disable-next-line no-restricted-syntax\nexport * from \"./index.js\";\n\n// Important: all other exports must be type only exports. In package.json exports,\n// index.js is listed as the runtime file. This is done so that all imports are\n// using the same outer runtime file. (Could be changed if needed.)\n\n// Export set of utility types re-tagged as internal for FF client convenience.\n// These types are not intended for direct use by customers and api-extractor will\n// flag misuse. If an externally visible version of these types is needed, import\n// from via /internal/exposedUtilityTypes rather than /internal.\nimport type { InternalUtilityTypes as ExposedInternalUtilityTypes } from \"./exposedInternalUtilityTypes.js\";\nimport type {\n\tJsonDeserialized as ExposedJsonDeserialized,\n\tJsonDeserializedOptions,\n} from \"./jsonDeserialized.js\";\nimport type {\n\tJsonSerializable as ExposedJsonSerializable,\n\tJsonSerializableOptions,\n} from \"./jsonSerializable.js\";\nimport type { JsonTypeWith as ExposedJsonTypeWith } from \"./jsonType.js\";\n\n// Note: There are no docs for these re-exports. `@inheritdoc` cannot be used as:\n// 1. api-extractor does not support renames.\n// 2. api-extractor does not support package paths. (\"Import paths are not supported\")\n// Also not useful, at least in VS Code, as substitution is not made in place.\n\n/**\n * @internal\n */\nexport type JsonDeserialized<\n\tT,\n\tOptions extends JsonDeserializedOptions = {\n\t\tAllowExactly: [];\n\t\tAllowExtensionOf: never;\n\t},\n> = ExposedJsonDeserialized<T, Options>;\n\n/**\n * @internal\n */\nexport type JsonSerializable<\n\tT,\n\tOptions extends JsonSerializableOptions = {\n\t\tAllowExactly: [];\n\t\tAllowExtensionOf: never;\n\t},\n> = ExposedJsonSerializable<T, Options>;\n\n/**\n * @internal\n */\nexport type JsonTypeWith<T> = ExposedJsonTypeWith<T>;\n\n/**\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace InternalUtilityTypes {\n\t/* eslint-disable jsdoc/require-jsdoc */\n\texport type IfSameType<\n\t\tX,\n\t\tY,\n\t\tIfSame = unknown,\n\t\tIfDifferent = never,\n\t> = ExposedInternalUtilityTypes.IfSameType<X, Y, IfSame, IfDifferent>;\n\t/* eslint-enable jsdoc/require-jsdoc */\n}\n"]}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import type { InternalUtilityTypes } from "./exposedInternalUtilityTypes.js";
|
|
6
|
+
/**
|
|
7
|
+
* Options for {@link JsonDeserialized}.
|
|
8
|
+
*
|
|
9
|
+
* @beta
|
|
10
|
+
*/
|
|
11
|
+
export interface JsonDeserializedOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Tuple of exact types that are managed by custom deserialization logic (beyond
|
|
14
|
+
* {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse|JSON.parse}
|
|
15
|
+
* without a reviver). Only exact types matching specification will be
|
|
16
|
+
* preserved unaltered.
|
|
17
|
+
*
|
|
18
|
+
* The default value is `[]`.
|
|
19
|
+
*/
|
|
20
|
+
AllowExactly?: unknown[];
|
|
21
|
+
/**
|
|
22
|
+
* General types that are managed by custom deserialization logic (beyond
|
|
23
|
+
* {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse|JSON.parse}
|
|
24
|
+
* without a reviver). Any type satisfying specification will be preserved
|
|
25
|
+
* unaltered.
|
|
26
|
+
*
|
|
27
|
+
* The default value is `never`.
|
|
28
|
+
*/
|
|
29
|
+
AllowExtensionOf?: unknown;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Produces a type that results from a type `T` serialized and deserialized
|
|
33
|
+
* through JSON using {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify|JSON.stringify}
|
|
34
|
+
* (without replacer) and {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse|JSON.parse}
|
|
35
|
+
* (without reviver), respectively as base model.
|
|
36
|
+
*
|
|
37
|
+
* @typeParam T - The type that was serialized.
|
|
38
|
+
* @typeParam Options - Options for the filter. See {@link JsonDeserializedOptions}.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* Before adding use of this utility type, consider using a utility like
|
|
42
|
+
* {@link https://github.com/sinclairzx81/typebox#readme | TypeBox} that allows
|
|
43
|
+
* for runtime validation.
|
|
44
|
+
*
|
|
45
|
+
* This filter can be used to derive the expected type of a JSON deserialized
|
|
46
|
+
* value whether or not the type of value serialized meets serialization
|
|
47
|
+
* constraints (see {@link JsonSerializable} including serialization pitfalls).
|
|
48
|
+
*
|
|
49
|
+
* When used as a filter to inferred generic `T`, a compile-time error can be
|
|
50
|
+
* produced trying to assign `JsonDeserialized<T>` to `T`.
|
|
51
|
+
*
|
|
52
|
+
* Simply deserialized JSON never contains `bigint`, `undefined`, `symbol`,
|
|
53
|
+
* or function values. (Object properties which had those types before encoding
|
|
54
|
+
* are omitted during serialization and thus won't be present after
|
|
55
|
+
* deserialization.) Therefore, through this filter, such properties:
|
|
56
|
+
*
|
|
57
|
+
* - become optional with those types excluded (when there are other supported
|
|
58
|
+
* types in union)
|
|
59
|
+
*
|
|
60
|
+
* - are removed (when nothing else in union is supported)
|
|
61
|
+
*
|
|
62
|
+
* - in an array are (1) replaced with `null` if `undefined`, `symbol`, and
|
|
63
|
+
* function values or (2) simply removed (become `never`) if `bigint` value as
|
|
64
|
+
* serialization attempts will throw.
|
|
65
|
+
*
|
|
66
|
+
* Examples results:
|
|
67
|
+
*
|
|
68
|
+
* | Before serialization | After deserialization | After in record | After in array |
|
|
69
|
+
* | --------------------- | --------------------- | ------------------ | --------------------:|
|
|
70
|
+
* | `undefined \| number` | `number` | `prop?: number` | `(number \| null)[]` |
|
|
71
|
+
* | `symbol \| number` | `number` | `prop?: number` | `(number \| null)[]` |
|
|
72
|
+
* | `bigint \| number` | `number` | `prop: number` | `number[]` |
|
|
73
|
+
* | `undefined` | N/A `never` | (prop not present) | `null[]` |
|
|
74
|
+
* | `symbol` | N/A `never` | (prop not present) | `null[]` |
|
|
75
|
+
* | `bigint` | N/A `never` | N/A (prop not present) | N/A `never[]` |
|
|
76
|
+
* | `bigint \| symbol` | N/A `never` | (prop not present) | `null[]` |
|
|
77
|
+
* | `bigint \| number \| symbol` | `number` | `prop?: number` | `(number \| null)[]` |
|
|
78
|
+
*
|
|
79
|
+
* Setter and getter properties become value properties after filtering
|
|
80
|
+
* although no data will be persisted assuming those properties are backed
|
|
81
|
+
* by functions. If an implementation of getter/setter interface uses a
|
|
82
|
+
* simple data member (of supported type), that will persist.
|
|
83
|
+
*
|
|
84
|
+
* Recursive types without any required modification are preserved intact.
|
|
85
|
+
* Recursive types that require modification are unrolled a limited number of
|
|
86
|
+
* times (currently 4) and then further instances of recursion are replaced with
|
|
87
|
+
* {@link JsonTypeWith|JsonTypeWith<Options.AllowExactly[number] "or" Options.AllowExtensionOf>}.
|
|
88
|
+
*
|
|
89
|
+
* Under basic serialization, class instances become simple data objects that
|
|
90
|
+
* lose hidden properties and prototypes that are required for `instanceof`
|
|
91
|
+
* runtime checks. An exception is made for classes that are intersected with
|
|
92
|
+
* primitive types (specifically `boolean`, `string`, and `number`) under the
|
|
93
|
+
* assumption that such classes are present only as type modifiers (as would
|
|
94
|
+
* be the case for branding) and not as require runtime values.
|
|
95
|
+
*
|
|
96
|
+
* The optional 'Options.AllowExactly' and 'Options.AllowExtensionOf'
|
|
97
|
+
* parameters may be used to permit additional leaf types handled by custom
|
|
98
|
+
* serialization/deserialization logic.
|
|
99
|
+
*
|
|
100
|
+
* @example Example usage
|
|
101
|
+
*
|
|
102
|
+
* ```typescript
|
|
103
|
+
* function foo<T>(): JsonDeserialized<T> { ... }
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @beta
|
|
107
|
+
*/
|
|
108
|
+
export type JsonDeserialized<T, Options extends JsonDeserializedOptions = {
|
|
109
|
+
AllowExactly: [];
|
|
110
|
+
AllowExtensionOf: never;
|
|
111
|
+
}> = InternalUtilityTypes.JsonDeserializedImpl<T, Options>;
|
|
112
|
+
//# sourceMappingURL=jsonDeserialized.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonDeserialized.d.ts","sourceRoot":"","sources":["../src/jsonDeserialized.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAE7E;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACvC;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,OAAO,EAAE,CAAC;IAEzB;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AACH,MAAM,MAAM,gBAAgB,CAC3B,CAAC,EACD,OAAO,SAAS,uBAAuB,GAAG;IACzC,YAAY,EAAE,EAAE,CAAC;IACjB,gBAAgB,EAAE,KAAK,CAAC;CACxB,IACE,oBAAoB,CAAC,oBAAoB,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonDeserialized.js","sourceRoot":"","sources":["../src/jsonDeserialized.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { InternalUtilityTypes } from \"./exposedInternalUtilityTypes.js\";\n\n/**\n * Options for {@link JsonDeserialized}.\n *\n * @beta\n */\nexport interface JsonDeserializedOptions {\n\t/**\n\t * Tuple of exact types that are managed by custom deserialization logic (beyond\n\t * {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse|JSON.parse}\n\t * without a reviver). Only exact types matching specification will be\n\t * preserved unaltered.\n\t *\n\t * The default value is `[]`.\n\t */\n\tAllowExactly?: unknown[];\n\n\t/**\n\t * General types that are managed by custom deserialization logic (beyond\n\t * {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse|JSON.parse}\n\t * without a reviver). Any type satisfying specification will be preserved\n\t * unaltered.\n\t *\n\t * The default value is `never`.\n\t */\n\tAllowExtensionOf?: unknown;\n}\n\n/**\n * Produces a type that results from a type `T` serialized and deserialized\n * through JSON using {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify|JSON.stringify}\n * (without replacer) and {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse|JSON.parse}\n * (without reviver), respectively as base model.\n *\n * @typeParam T - The type that was serialized.\n * @typeParam Options - Options for the filter. See {@link JsonDeserializedOptions}.\n *\n * @remarks\n * Before adding use of this utility type, consider using a utility like\n * {@link https://github.com/sinclairzx81/typebox#readme | TypeBox} that allows\n * for runtime validation.\n *\n * This filter can be used to derive the expected type of a JSON deserialized\n * value whether or not the type of value serialized meets serialization\n * constraints (see {@link JsonSerializable} including serialization pitfalls).\n *\n * When used as a filter to inferred generic `T`, a compile-time error can be\n * produced trying to assign `JsonDeserialized<T>` to `T`.\n *\n * Simply deserialized JSON never contains `bigint`, `undefined`, `symbol`,\n * or function values. (Object properties which had those types before encoding\n * are omitted during serialization and thus won't be present after\n * deserialization.) Therefore, through this filter, such properties:\n *\n * - become optional with those types excluded (when there are other supported\n * types in union)\n *\n * - are removed (when nothing else in union is supported)\n *\n * - in an array are (1) replaced with `null` if `undefined`, `symbol`, and\n * function values or (2) simply removed (become `never`) if `bigint` value as\n * serialization attempts will throw.\n *\n * Examples results:\n *\n * | Before serialization | After deserialization | After in record | After in array |\n * | --------------------- | --------------------- | ------------------ | --------------------:|\n * | `undefined \\| number` | `number` | `prop?: number` | `(number \\| null)[]` |\n * | `symbol \\| number` | `number` | `prop?: number` | `(number \\| null)[]` |\n * | `bigint \\| number` | `number` | `prop: number` | `number[]` |\n * | `undefined` | N/A `never` | (prop not present) | `null[]` |\n * | `symbol` | N/A `never` | (prop not present) | `null[]` |\n * | `bigint` | N/A `never` | N/A (prop not present) | N/A `never[]` |\n * | `bigint \\| symbol` | N/A `never` | (prop not present) | `null[]` |\n * | `bigint \\| number \\| symbol` | `number` | `prop?: number` | `(number \\| null)[]` |\n *\n * Setter and getter properties become value properties after filtering\n * although no data will be persisted assuming those properties are backed\n * by functions. If an implementation of getter/setter interface uses a\n * simple data member (of supported type), that will persist.\n *\n * Recursive types without any required modification are preserved intact.\n * Recursive types that require modification are unrolled a limited number of\n * times (currently 4) and then further instances of recursion are replaced with\n * {@link JsonTypeWith|JsonTypeWith<Options.AllowExactly[number] \"or\" Options.AllowExtensionOf>}.\n *\n * Under basic serialization, class instances become simple data objects that\n * lose hidden properties and prototypes that are required for `instanceof`\n * runtime checks. An exception is made for classes that are intersected with\n * primitive types (specifically `boolean`, `string`, and `number`) under the\n * assumption that such classes are present only as type modifiers (as would\n * be the case for branding) and not as require runtime values.\n *\n * The optional 'Options.AllowExactly' and 'Options.AllowExtensionOf'\n * parameters may be used to permit additional leaf types handled by custom\n * serialization/deserialization logic.\n *\n * @example Example usage\n *\n * ```typescript\n * function foo<T>(): JsonDeserialized<T> { ... }\n * ```\n *\n * @beta\n */\nexport type JsonDeserialized<\n\tT,\n\tOptions extends JsonDeserializedOptions = {\n\t\tAllowExactly: [];\n\t\tAllowExtensionOf: never;\n\t},\n> = InternalUtilityTypes.JsonDeserializedImpl<T, Options>;\n"]}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import type { InternalUtilityTypes } from "./exposedInternalUtilityTypes.js";
|
|
6
|
+
/**
|
|
7
|
+
* Options for {@link JsonSerializable}.
|
|
8
|
+
*
|
|
9
|
+
* @beta
|
|
10
|
+
*/
|
|
11
|
+
export interface JsonSerializableOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Tuple of exact types that are managed by custom serialization logic (beyond
|
|
14
|
+
* {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify|JSON.stringify}
|
|
15
|
+
* without a replacer). Only exact types matching specification will be
|
|
16
|
+
* preserved unaltered.
|
|
17
|
+
*
|
|
18
|
+
* The default value is `[]`.
|
|
19
|
+
*/
|
|
20
|
+
AllowExactly?: unknown[];
|
|
21
|
+
/**
|
|
22
|
+
* General types that are managed by custom serialization logic (beyond
|
|
23
|
+
* {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify|JSON.stringify}
|
|
24
|
+
* without a replacer). Any type satisfying specification will be preserved
|
|
25
|
+
* unaltered.
|
|
26
|
+
*
|
|
27
|
+
* The default value is `never`.
|
|
28
|
+
*/
|
|
29
|
+
AllowExtensionOf?: unknown;
|
|
30
|
+
/**
|
|
31
|
+
* When set, inaccessible (protected and private) members throughout type T are
|
|
32
|
+
* ignored as if not present.
|
|
33
|
+
*
|
|
34
|
+
* The default value is not present.
|
|
35
|
+
*/
|
|
36
|
+
IgnoreInaccessibleMembers?: "ignore-inaccessible-members";
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Used to constrain a type `T` to types that are serializable as JSON
|
|
40
|
+
* using {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify|JSON.stringify}
|
|
41
|
+
* (without a replacer) as base model.
|
|
42
|
+
*
|
|
43
|
+
* Under typical use a compile-time error is produced if `T` contains
|
|
44
|
+
* non-JsonSerializable members.
|
|
45
|
+
*
|
|
46
|
+
* @typeParam T - The type to be constrained.
|
|
47
|
+
* @typeParam Options - Options for the filter. See {@link JsonSerializableOptions}.
|
|
48
|
+
*
|
|
49
|
+
* @remarks
|
|
50
|
+
* Before adding use of this utility type, consider using a utility like
|
|
51
|
+
* {@link https://github.com/sinclairzx81/typebox#readme | TypeBox} that allows
|
|
52
|
+
* for runtime validation.
|
|
53
|
+
*
|
|
54
|
+
* Note that this does NOT prevent use of values with non-JSON compatible data,
|
|
55
|
+
* it only prevents using values with types that include non-JSON compatible data.
|
|
56
|
+
* This means that one can, for example, pass in a value typed with JSON compatible
|
|
57
|
+
* interface into this filter, that could actually be a class with lots on non-JSON
|
|
58
|
+
* compatible fields and methods.
|
|
59
|
+
*
|
|
60
|
+
* Important: `T extends JsonSerializable<T>` is incorrect (does not even compile).
|
|
61
|
+
*
|
|
62
|
+
* The optional `Options.Allow*` parameters may be used to permit additional leaf types
|
|
63
|
+
* to support situations where a `replacer` is used to handle special values (e.g.,
|
|
64
|
+
* `JsonSerializable<{ x: IFluidHandle }, { AllowExtensionOf: IFluidHandle }>`).
|
|
65
|
+
*
|
|
66
|
+
* Note that `JsonSerializable<T>` does not protect against the following pitfalls
|
|
67
|
+
* when serializing with JSON.stringify():
|
|
68
|
+
*
|
|
69
|
+
* - Non-finite numbers (`NaN`, `+/-Infinity`) are coerced to `null`.
|
|
70
|
+
*
|
|
71
|
+
* - Prototypes and non-enumerable properties are lost.
|
|
72
|
+
*
|
|
73
|
+
* - `ArrayLike` types that are not arrays and are serialized as `{ length: number }`.
|
|
74
|
+
*
|
|
75
|
+
* - Getter and setters properties are lost. (Though appear supported.)
|
|
76
|
+
*
|
|
77
|
+
* - Functions with properties may be absent or the properties may be preserved
|
|
78
|
+
* depending on the runtime typo of the value. (If built via Object.assign the
|
|
79
|
+
* target member's type is preserved.) typeof =\> 'function' is lost whereas when
|
|
80
|
+
* typeof =\> 'object' the properties are preserved.
|
|
81
|
+
*
|
|
82
|
+
* - Sparse arrays are filled with `null`.
|
|
83
|
+
*
|
|
84
|
+
* Also, `JsonSerializable<T>` does not prevent the construction of circular references.
|
|
85
|
+
*
|
|
86
|
+
* Specifying `JsonSerializable<unknown>` or `JsonSerializable<any>` yields a type
|
|
87
|
+
* alias for {@link JsonTypeWith}`<never>` and should not be used if precise type
|
|
88
|
+
* safety is desired.
|
|
89
|
+
*
|
|
90
|
+
* Class instances are indistinguishable from general objects by type checking
|
|
91
|
+
* unless they have non-public members.
|
|
92
|
+
*
|
|
93
|
+
* - Unless `Option.IgnoreInaccessibleMembers` is used, types with non-public
|
|
94
|
+
* members will result in {@link SerializationErrorPerNonPublicProperties}.
|
|
95
|
+
* When `Option.IgnoreInaccessibleMembers` is `ignore-inaccessible-members`,
|
|
96
|
+
* non-public (non-function) members are preserved without error, but they are
|
|
97
|
+
* filtered away by the type filters and thus produce an incorrectly narrowed
|
|
98
|
+
* type compared to actual data. Though such a result may be customer desired.
|
|
99
|
+
*
|
|
100
|
+
* - An exception is made for classes that are intersected with primitives
|
|
101
|
+
* (specifically `boolean`, `number`, * and `string`). In these cases, it is
|
|
102
|
+
* assumed that the class only exists as a type modifier and not as a value
|
|
103
|
+
* at runtime, and thus the class is permitted as no serialization is required.
|
|
104
|
+
*
|
|
105
|
+
* Perhaps a https://github.com/microsoft/TypeScript/issues/22677 fix will
|
|
106
|
+
* enable better support.
|
|
107
|
+
*
|
|
108
|
+
* @example Typical usage
|
|
109
|
+
*
|
|
110
|
+
* ```typescript
|
|
111
|
+
* function foo<T>(value: JsonSerializable<T>) { ... }
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @privateRemarks
|
|
115
|
+
* Upon recursion, the original type T is preserved intact. This is done to prevent
|
|
116
|
+
* infinite recursion and produces a technically incorrect result type. However, with
|
|
117
|
+
* proper use, that will never be an issue as any filtering of types will happen
|
|
118
|
+
* before T recursion.
|
|
119
|
+
*
|
|
120
|
+
* @beta
|
|
121
|
+
*/
|
|
122
|
+
export type JsonSerializable<T, Options extends JsonSerializableOptions = {
|
|
123
|
+
AllowExactly: [];
|
|
124
|
+
AllowExtensionOf: never;
|
|
125
|
+
}> = InternalUtilityTypes.JsonSerializableImpl<T, Options>;
|
|
126
|
+
//# sourceMappingURL=jsonSerializable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonSerializable.d.ts","sourceRoot":"","sources":["../src/jsonSerializable.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAE7E;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACvC;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,OAAO,EAAE,CAAC;IAEzB;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,6BAA6B,CAAC;CAC1D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmFG;AACH,MAAM,MAAM,gBAAgB,CAC3B,CAAC,EACD,OAAO,SAAS,uBAAuB,GAAG;IACzC,YAAY,EAAE,EAAE,CAAC;IACjB,gBAAgB,EAAE,KAAK,CAAC;CACxB,IACE,oBAAoB,CAAC,oBAAoB,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonSerializable.js","sourceRoot":"","sources":["../src/jsonSerializable.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { InternalUtilityTypes } from \"./exposedInternalUtilityTypes.js\";\n\n/**\n * Options for {@link JsonSerializable}.\n *\n * @beta\n */\nexport interface JsonSerializableOptions {\n\t/**\n\t * Tuple of exact types that are managed by custom serialization logic (beyond\n\t * {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify|JSON.stringify}\n\t * without a replacer). Only exact types matching specification will be\n\t * preserved unaltered.\n\t *\n\t * The default value is `[]`.\n\t */\n\tAllowExactly?: unknown[];\n\n\t/**\n\t * General types that are managed by custom serialization logic (beyond\n\t * {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify|JSON.stringify}\n\t * without a replacer). Any type satisfying specification will be preserved\n\t * unaltered.\n\t *\n\t * The default value is `never`.\n\t */\n\tAllowExtensionOf?: unknown;\n\n\t/**\n\t * When set, inaccessible (protected and private) members throughout type T are\n\t * ignored as if not present.\n\t *\n\t * The default value is not present.\n\t */\n\tIgnoreInaccessibleMembers?: \"ignore-inaccessible-members\";\n}\n\n/**\n * Used to constrain a type `T` to types that are serializable as JSON\n * using {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify|JSON.stringify}\n * (without a replacer) as base model.\n *\n * Under typical use a compile-time error is produced if `T` contains\n * non-JsonSerializable members.\n *\n * @typeParam T - The type to be constrained.\n * @typeParam Options - Options for the filter. See {@link JsonSerializableOptions}.\n *\n * @remarks\n * Before adding use of this utility type, consider using a utility like\n * {@link https://github.com/sinclairzx81/typebox#readme | TypeBox} that allows\n * for runtime validation.\n *\n * Note that this does NOT prevent use of values with non-JSON compatible data,\n * it only prevents using values with types that include non-JSON compatible data.\n * This means that one can, for example, pass in a value typed with JSON compatible\n * interface into this filter, that could actually be a class with lots on non-JSON\n * compatible fields and methods.\n *\n * Important: `T extends JsonSerializable<T>` is incorrect (does not even compile).\n *\n * The optional `Options.Allow*` parameters may be used to permit additional leaf types\n * to support situations where a `replacer` is used to handle special values (e.g.,\n * `JsonSerializable<{ x: IFluidHandle }, { AllowExtensionOf: IFluidHandle }>`).\n *\n * Note that `JsonSerializable<T>` does not protect against the following pitfalls\n * when serializing with JSON.stringify():\n *\n * - Non-finite numbers (`NaN`, `+/-Infinity`) are coerced to `null`.\n *\n * - Prototypes and non-enumerable properties are lost.\n *\n * - `ArrayLike` types that are not arrays and are serialized as `{ length: number }`.\n *\n * - Getter and setters properties are lost. (Though appear supported.)\n *\n * - Functions with properties may be absent or the properties may be preserved\n * depending on the runtime typo of the value. (If built via Object.assign the\n * target member's type is preserved.) typeof =\\> 'function' is lost whereas when\n * typeof =\\> 'object' the properties are preserved.\n *\n * - Sparse arrays are filled with `null`.\n *\n * Also, `JsonSerializable<T>` does not prevent the construction of circular references.\n *\n * Specifying `JsonSerializable<unknown>` or `JsonSerializable<any>` yields a type\n * alias for {@link JsonTypeWith}`<never>` and should not be used if precise type\n * safety is desired.\n *\n * Class instances are indistinguishable from general objects by type checking\n * unless they have non-public members.\n *\n * - Unless `Option.IgnoreInaccessibleMembers` is used, types with non-public\n * members will result in {@link SerializationErrorPerNonPublicProperties}.\n * When `Option.IgnoreInaccessibleMembers` is `ignore-inaccessible-members`,\n * non-public (non-function) members are preserved without error, but they are\n * filtered away by the type filters and thus produce an incorrectly narrowed\n * type compared to actual data. Though such a result may be customer desired.\n *\n * - An exception is made for classes that are intersected with primitives\n * (specifically `boolean`, `number`, * and `string`). In these cases, it is\n * assumed that the class only exists as a type modifier and not as a value\n * at runtime, and thus the class is permitted as no serialization is required.\n *\n * Perhaps a https://github.com/microsoft/TypeScript/issues/22677 fix will\n * enable better support.\n *\n * @example Typical usage\n *\n * ```typescript\n * function foo<T>(value: JsonSerializable<T>) { ... }\n * ```\n *\n * @privateRemarks\n * Upon recursion, the original type T is preserved intact. This is done to prevent\n * infinite recursion and produces a technically incorrect result type. However, with\n * proper use, that will never be an issue as any filtering of types will happen\n * before T recursion.\n *\n * @beta\n */\nexport type JsonSerializable<\n\tT,\n\tOptions extends JsonSerializableOptions = {\n\t\tAllowExactly: [];\n\t\tAllowExtensionOf: never;\n\t},\n> = InternalUtilityTypes.JsonSerializableImpl<T, Options>;\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Type resulting from {@link JsonSerializable} use given an array with
|
|
7
|
+
* `undefined` elements.
|
|
8
|
+
*
|
|
9
|
+
* @privateRemarks type is used over interface; so inspection of type
|
|
10
|
+
* result can be more informative than just the type name.
|
|
11
|
+
*
|
|
12
|
+
* @beta
|
|
13
|
+
* @system
|
|
14
|
+
*/
|
|
15
|
+
export type SerializationErrorPerUndefinedArrayElement = {
|
|
16
|
+
"array serialization error": "undefined elements are not supported";
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Type resulting from {@link JsonSerializable} use given a class with
|
|
20
|
+
* non-public properties.
|
|
21
|
+
*
|
|
22
|
+
* @privateRemarks type is used over interface; so inspection of type
|
|
23
|
+
* result can be more informative than just the type name.
|
|
24
|
+
*
|
|
25
|
+
* @beta
|
|
26
|
+
* @system
|
|
27
|
+
*/
|
|
28
|
+
export type SerializationErrorPerNonPublicProperties = {
|
|
29
|
+
"object serialization error": "non-public properties are not supported";
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=jsonSerializationErrors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonSerializationErrors.d.ts","sourceRoot":"","sources":["../src/jsonSerializationErrors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AAEH,MAAM,MAAM,0CAA0C,GAAG;IACxD,2BAA2B,EAAE,sCAAsC,CAAC;CACpE,CAAC;AAEF;;;;;;;;;GASG;AAEH,MAAM,MAAM,wCAAwC,GAAG;IACtD,4BAA4B,EAAE,yCAAyC,CAAC;CACxE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonSerializationErrors.js","sourceRoot":"","sources":["../src/jsonSerializationErrors.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Type resulting from {@link JsonSerializable} use given an array with\n * `undefined` elements.\n *\n * @privateRemarks type is used over interface; so inspection of type\n * result can be more informative than just the type name.\n *\n * @beta\n * @system\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport type SerializationErrorPerUndefinedArrayElement = {\n\t\"array serialization error\": \"undefined elements are not supported\";\n};\n\n/**\n * Type resulting from {@link JsonSerializable} use given a class with\n * non-public properties.\n *\n * @privateRemarks type is used over interface; so inspection of type\n * result can be more informative than just the type name.\n *\n * @beta\n * @system\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport type SerializationErrorPerNonPublicProperties = {\n\t\"object serialization error\": \"non-public properties are not supported\";\n};\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Type constraint for types that are likely encodable as JSON, deserializable from JSON,
|
|
7
|
+
* or have a custom alternate type.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Use `JsonTypeWith<never>` for just JSON encodable/deserializable types.
|
|
11
|
+
* See {@link JsonSerializable} for encoding pitfalls.
|
|
12
|
+
*
|
|
13
|
+
* @privateRemarks
|
|
14
|
+
* Prefer using `JsonSerializable<unknown>` or `JsonDeserialized<unknown>` over this type that
|
|
15
|
+
* is an implementation detail.
|
|
16
|
+
*
|
|
17
|
+
* @beta
|
|
18
|
+
*/
|
|
19
|
+
export type JsonTypeWith<T> = null | boolean | number | string | T | {
|
|
20
|
+
[key: string | number]: JsonTypeWith<T>;
|
|
21
|
+
} | JsonTypeWith<T>[];
|
|
22
|
+
/**
|
|
23
|
+
* Portion of {@link JsonTypeWith} that is an object (including array) and not null.
|
|
24
|
+
*
|
|
25
|
+
* @beta
|
|
26
|
+
*/
|
|
27
|
+
export type NonNullJsonObjectWith<T> = {
|
|
28
|
+
[key: string | number]: JsonTypeWith<T>;
|
|
29
|
+
} | JsonTypeWith<T>[];
|
|
30
|
+
//# sourceMappingURL=jsonType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonType.d.ts","sourceRoot":"","sources":["../src/jsonType.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAEvB,IAAI,GACJ,OAAO,GACP,MAAM,GACN,MAAM,GACN,CAAC,GACD;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;CAAE,GAC3C,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;AAErB;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,IAChC;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;CAAE,GAC3C,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC"}
|
package/dist/jsonType.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonType.js","sourceRoot":"","sources":["../src/jsonType.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Type constraint for types that are likely encodable as JSON, deserializable from JSON,\n * or have a custom alternate type.\n *\n * @remarks\n * Use `JsonTypeWith<never>` for just JSON encodable/deserializable types.\n * See {@link JsonSerializable} for encoding pitfalls.\n *\n * @privateRemarks\n * Prefer using `JsonSerializable<unknown>` or `JsonDeserialized<unknown>` over this type that\n * is an implementation detail.\n *\n * @beta\n */\nexport type JsonTypeWith<T> =\n\t// eslint-disable-next-line @rushstack/no-new-null\n\t| null\n\t| boolean\n\t| number\n\t| string\n\t| T\n\t| { [key: string | number]: JsonTypeWith<T> }\n\t| JsonTypeWith<T>[];\n\n/**\n * Portion of {@link JsonTypeWith} that is an object (including array) and not null.\n *\n * @beta\n */\nexport type NonNullJsonObjectWith<T> =\n\t| { [key: string | number]: JsonTypeWith<T> }\n\t| JsonTypeWith<T>[];\n"]}
|