@fluidframework/tree 2.12.0 → 2.13.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/CHANGELOG.md +136 -0
- package/api-report/tree.alpha.api.md +86 -10
- package/api-report/tree.beta.api.md +22 -10
- package/api-report/tree.legacy.alpha.api.md +22 -10
- package/api-report/tree.legacy.public.api.md +22 -10
- package/api-report/tree.public.api.md +22 -10
- package/dist/alpha.d.ts +11 -0
- package/dist/beta.d.ts +2 -0
- package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts +10 -0
- package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
- package/dist/feature-libraries/default-schema/defaultEditBuilder.js +3 -0
- package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
- package/dist/feature-libraries/index.d.ts +0 -1
- package/dist/feature-libraries/index.d.ts.map +1 -1
- package/dist/feature-libraries/index.js +2 -4
- package/dist/feature-libraries/index.js.map +1 -1
- package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts +1 -1
- package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/crossFieldQueries.js +8 -2
- package/dist/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
- package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts +12 -5
- package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
- package/dist/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/genericFieldKind.js +2 -1
- package/dist/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
- package/dist/feature-libraries/modular-schema/index.d.ts +1 -1
- package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/index.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts +1 -0
- package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFamily.js +89 -25
- package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts +12 -0
- package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
- package/dist/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
- package/dist/feature-libraries/optional-field/optionalField.js +24 -4
- package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
- package/dist/feature-libraries/sequence-field/utils.d.ts +2 -2
- package/dist/feature-libraries/sequence-field/utils.d.ts.map +1 -1
- package/dist/feature-libraries/sequence-field/utils.js +14 -5
- package/dist/feature-libraries/sequence-field/utils.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/legacy.d.ts +2 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/public.d.ts +2 -0
- package/dist/shared-tree/index.d.ts +2 -1
- package/dist/shared-tree/index.d.ts.map +1 -1
- package/dist/shared-tree/index.js +2 -1
- package/dist/shared-tree/index.js.map +1 -1
- package/dist/shared-tree/schematizingTreeView.d.ts +10 -1
- package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/dist/shared-tree/schematizingTreeView.js +43 -0
- package/dist/shared-tree/schematizingTreeView.js.map +1 -1
- package/dist/shared-tree/sharedTree.d.ts +6 -3
- package/dist/shared-tree/sharedTree.d.ts.map +1 -1
- package/dist/shared-tree/sharedTree.js +3 -1
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/shared-tree/transactionTypes.d.ts +105 -0
- package/dist/shared-tree/transactionTypes.d.ts.map +1 -0
- package/dist/shared-tree/transactionTypes.js +13 -0
- package/dist/shared-tree/transactionTypes.js.map +1 -0
- package/dist/shared-tree/treeApi.d.ts +1 -25
- package/dist/shared-tree/treeApi.d.ts.map +1 -1
- package/dist/shared-tree/treeApi.js +4 -8
- package/dist/shared-tree/treeApi.js.map +1 -1
- package/dist/shared-tree/treeCheckout.d.ts +4 -1
- package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
- package/dist/shared-tree/treeCheckout.js +130 -15
- package/dist/shared-tree/treeCheckout.js.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.js +1 -1
- package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/dist/simple-tree/api/index.d.ts +1 -0
- package/dist/simple-tree/api/index.d.ts.map +1 -1
- package/dist/simple-tree/api/index.js +3 -1
- package/dist/simple-tree/api/index.js.map +1 -1
- package/dist/simple-tree/api/jsonSchema.d.ts +6 -0
- package/dist/simple-tree/api/jsonSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/jsonSchema.js.map +1 -1
- package/dist/simple-tree/api/schemaFactory.d.ts +21 -12
- package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactory.js +5 -2
- package/dist/simple-tree/api/schemaFactory.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +83 -0
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -0
- package/dist/simple-tree/api/schemaFactoryAlpha.js +90 -0
- package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -0
- package/dist/simple-tree/api/simpleSchema.d.ts +5 -1
- package/dist/simple-tree/api/simpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/simpleSchema.js.map +1 -1
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +13 -10
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/dist/simple-tree/api/testRecursiveDomain.d.ts +5 -5
- package/dist/simple-tree/api/tree.d.ts +60 -0
- package/dist/simple-tree/api/tree.d.ts.map +1 -1
- package/dist/simple-tree/api/tree.js.map +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js +11 -11
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/dist/simple-tree/arrayNode.d.ts +2 -2
- package/dist/simple-tree/arrayNode.d.ts.map +1 -1
- package/dist/simple-tree/arrayNode.js +2 -1
- package/dist/simple-tree/arrayNode.js.map +1 -1
- package/dist/simple-tree/core/treeNodeSchema.d.ts +10 -6
- package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
- package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
- package/dist/simple-tree/index.d.ts +2 -2
- package/dist/simple-tree/index.d.ts.map +1 -1
- package/dist/simple-tree/index.js +3 -2
- package/dist/simple-tree/index.js.map +1 -1
- package/dist/simple-tree/leafNodeSchema.d.ts +5 -5
- package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/dist/simple-tree/mapNode.d.ts +2 -2
- package/dist/simple-tree/mapNode.d.ts.map +1 -1
- package/dist/simple-tree/mapNode.js +2 -1
- package/dist/simple-tree/mapNode.js.map +1 -1
- package/dist/simple-tree/objectNode.d.ts +2 -2
- package/dist/simple-tree/objectNode.d.ts.map +1 -1
- package/dist/simple-tree/objectNode.js +2 -1
- package/dist/simple-tree/objectNode.js.map +1 -1
- package/dist/simple-tree/objectNodeTypes.d.ts +2 -2
- package/dist/simple-tree/objectNodeTypes.d.ts.map +1 -1
- package/dist/simple-tree/objectNodeTypes.js.map +1 -1
- package/dist/simple-tree/schemaTypes.d.ts +47 -1
- package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
- package/dist/simple-tree/schemaTypes.js.map +1 -1
- package/dist/util/index.d.ts +2 -2
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +3 -5
- package/dist/util/index.js.map +1 -1
- package/dist/util/rangeMap.d.ts +72 -42
- package/dist/util/rangeMap.d.ts.map +1 -1
- package/dist/util/rangeMap.js +161 -151
- package/dist/util/rangeMap.js.map +1 -1
- package/dist/util/utils.d.ts +22 -1
- package/dist/util/utils.d.ts.map +1 -1
- package/dist/util/utils.js +10 -1
- package/dist/util/utils.js.map +1 -1
- package/lib/alpha.d.ts +11 -0
- package/lib/beta.d.ts +2 -0
- package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts +10 -0
- package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
- package/lib/feature-libraries/default-schema/defaultEditBuilder.js +3 -0
- package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
- package/lib/feature-libraries/index.d.ts +0 -1
- package/lib/feature-libraries/index.d.ts.map +1 -1
- package/lib/feature-libraries/index.js +0 -1
- package/lib/feature-libraries/index.js.map +1 -1
- package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts +1 -1
- package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/crossFieldQueries.js +9 -3
- package/lib/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
- package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts +12 -5
- package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
- package/lib/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/genericFieldKind.js +2 -1
- package/lib/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
- package/lib/feature-libraries/modular-schema/index.d.ts +1 -1
- package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/index.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts +1 -0
- package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFamily.js +89 -25
- package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts +12 -0
- package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
- package/lib/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
- package/lib/feature-libraries/optional-field/optionalField.js +24 -4
- package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
- package/lib/feature-libraries/sequence-field/utils.d.ts +2 -2
- package/lib/feature-libraries/sequence-field/utils.d.ts.map +1 -1
- package/lib/feature-libraries/sequence-field/utils.js +14 -5
- package/lib/feature-libraries/sequence-field/utils.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/legacy.d.ts +2 -0
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/public.d.ts +2 -0
- package/lib/shared-tree/index.d.ts +2 -1
- package/lib/shared-tree/index.d.ts.map +1 -1
- package/lib/shared-tree/index.js +2 -1
- package/lib/shared-tree/index.js.map +1 -1
- package/lib/shared-tree/schematizingTreeView.d.ts +10 -1
- package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/lib/shared-tree/schematizingTreeView.js +46 -3
- package/lib/shared-tree/schematizingTreeView.js.map +1 -1
- package/lib/shared-tree/sharedTree.d.ts +6 -3
- package/lib/shared-tree/sharedTree.d.ts.map +1 -1
- package/lib/shared-tree/sharedTree.js +3 -1
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/shared-tree/transactionTypes.d.ts +105 -0
- package/lib/shared-tree/transactionTypes.d.ts.map +1 -0
- package/lib/shared-tree/transactionTypes.js +10 -0
- package/lib/shared-tree/transactionTypes.js.map +1 -0
- package/lib/shared-tree/treeApi.d.ts +1 -25
- package/lib/shared-tree/treeApi.d.ts.map +1 -1
- package/lib/shared-tree/treeApi.js +1 -5
- package/lib/shared-tree/treeApi.js.map +1 -1
- package/lib/shared-tree/treeCheckout.d.ts +4 -1
- package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
- package/lib/shared-tree/treeCheckout.js +130 -15
- package/lib/shared-tree/treeCheckout.js.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.js +1 -1
- package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/lib/simple-tree/api/index.d.ts +1 -0
- package/lib/simple-tree/api/index.d.ts.map +1 -1
- package/lib/simple-tree/api/index.js +1 -0
- package/lib/simple-tree/api/index.js.map +1 -1
- package/lib/simple-tree/api/jsonSchema.d.ts +6 -0
- package/lib/simple-tree/api/jsonSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/jsonSchema.js.map +1 -1
- package/lib/simple-tree/api/schemaFactory.d.ts +21 -12
- package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactory.js +5 -2
- package/lib/simple-tree/api/schemaFactory.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +83 -0
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -0
- package/lib/simple-tree/api/schemaFactoryAlpha.js +86 -0
- package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -0
- package/lib/simple-tree/api/simpleSchema.d.ts +5 -1
- package/lib/simple-tree/api/simpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/simpleSchema.js.map +1 -1
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +14 -11
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/lib/simple-tree/api/testRecursiveDomain.d.ts +5 -5
- package/lib/simple-tree/api/tree.d.ts +60 -0
- package/lib/simple-tree/api/tree.d.ts.map +1 -1
- package/lib/simple-tree/api/tree.js.map +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js +12 -12
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/lib/simple-tree/arrayNode.d.ts +2 -2
- package/lib/simple-tree/arrayNode.d.ts.map +1 -1
- package/lib/simple-tree/arrayNode.js +2 -1
- package/lib/simple-tree/arrayNode.js.map +1 -1
- package/lib/simple-tree/core/treeNodeSchema.d.ts +10 -6
- package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
- package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
- package/lib/simple-tree/index.d.ts +2 -2
- package/lib/simple-tree/index.d.ts.map +1 -1
- package/lib/simple-tree/index.js +1 -1
- package/lib/simple-tree/index.js.map +1 -1
- package/lib/simple-tree/leafNodeSchema.d.ts +5 -5
- package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/lib/simple-tree/mapNode.d.ts +2 -2
- package/lib/simple-tree/mapNode.d.ts.map +1 -1
- package/lib/simple-tree/mapNode.js +2 -1
- package/lib/simple-tree/mapNode.js.map +1 -1
- package/lib/simple-tree/objectNode.d.ts +2 -2
- package/lib/simple-tree/objectNode.d.ts.map +1 -1
- package/lib/simple-tree/objectNode.js +2 -1
- package/lib/simple-tree/objectNode.js.map +1 -1
- package/lib/simple-tree/objectNodeTypes.d.ts +2 -2
- package/lib/simple-tree/objectNodeTypes.d.ts.map +1 -1
- package/lib/simple-tree/objectNodeTypes.js.map +1 -1
- package/lib/simple-tree/schemaTypes.d.ts +47 -1
- package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
- package/lib/simple-tree/schemaTypes.js.map +1 -1
- package/lib/util/index.d.ts +2 -2
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +2 -2
- package/lib/util/index.js.map +1 -1
- package/lib/util/rangeMap.d.ts +72 -42
- package/lib/util/rangeMap.d.ts.map +1 -1
- package/lib/util/rangeMap.js +159 -146
- package/lib/util/rangeMap.js.map +1 -1
- package/lib/util/utils.d.ts +22 -1
- package/lib/util/utils.d.ts.map +1 -1
- package/lib/util/utils.js +8 -0
- package/lib/util/utils.js.map +1 -1
- package/package.json +22 -22
- package/src/feature-libraries/default-schema/defaultEditBuilder.ts +14 -1
- package/src/feature-libraries/index.ts +0 -1
- package/src/feature-libraries/modular-schema/crossFieldQueries.ts +9 -9
- package/src/feature-libraries/modular-schema/fieldChangeHandler.ts +13 -9
- package/src/feature-libraries/modular-schema/genericFieldKind.ts +4 -2
- package/src/feature-libraries/modular-schema/index.ts +1 -0
- package/src/feature-libraries/modular-schema/modularChangeFamily.ts +124 -31
- package/src/feature-libraries/modular-schema/modularChangeTypes.ts +12 -0
- package/src/feature-libraries/optional-field/optionalField.ts +34 -5
- package/src/feature-libraries/sequence-field/utils.ts +18 -7
- package/src/index.ts +11 -0
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/index.ts +12 -2
- package/src/shared-tree/schematizingTreeView.ts +91 -2
- package/src/shared-tree/sharedTree.ts +9 -4
- package/src/shared-tree/transactionTypes.ts +125 -0
- package/src/shared-tree/treeApi.ts +1 -28
- package/src/shared-tree/treeCheckout.ts +147 -13
- package/src/shared-tree-core/sharedTreeCore.ts +1 -1
- package/src/simple-tree/api/index.ts +1 -0
- package/src/simple-tree/api/jsonSchema.ts +7 -0
- package/src/simple-tree/api/schemaFactory.ts +33 -6
- package/src/simple-tree/api/schemaFactoryAlpha.ts +253 -0
- package/src/simple-tree/api/simpleSchema.ts +6 -1
- package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +22 -12
- package/src/simple-tree/api/tree.ts +76 -4
- package/src/simple-tree/api/viewSchemaToSimpleSchema.ts +19 -13
- package/src/simple-tree/arrayNode.ts +7 -1
- package/src/simple-tree/core/treeNodeSchema.ts +51 -7
- package/src/simple-tree/index.ts +3 -0
- package/src/simple-tree/mapNode.ts +7 -1
- package/src/simple-tree/objectNode.ts +7 -1
- package/src/simple-tree/objectNodeTypes.ts +4 -1
- package/src/simple-tree/schemaTypes.ts +50 -1
- package/src/util/index.ts +2 -6
- package/src/util/rangeMap.ts +199 -189
- package/src/util/utils.ts +47 -1
- package/dist/feature-libraries/memoizedIdRangeAllocator.d.ts +0 -38
- package/dist/feature-libraries/memoizedIdRangeAllocator.d.ts.map +0 -1
- package/dist/feature-libraries/memoizedIdRangeAllocator.js +0 -74
- package/dist/feature-libraries/memoizedIdRangeAllocator.js.map +0 -1
- package/lib/feature-libraries/memoizedIdRangeAllocator.d.ts +0 -38
- package/lib/feature-libraries/memoizedIdRangeAllocator.d.ts.map +0 -1
- package/lib/feature-libraries/memoizedIdRangeAllocator.js +0 -71
- package/lib/feature-libraries/memoizedIdRangeAllocator.js.map +0 -1
- package/src/feature-libraries/memoizedIdRangeAllocator.ts +0 -112
|
@@ -73,6 +73,7 @@ import type {
|
|
|
73
73
|
UnsafeUnknownSchema,
|
|
74
74
|
ViewableTree,
|
|
75
75
|
TreeBranch,
|
|
76
|
+
TreeChangeEvents,
|
|
76
77
|
} from "../simple-tree/index.js";
|
|
77
78
|
import { getCheckout, SchematizingSimpleTreeView } from "./schematizingTreeView.js";
|
|
78
79
|
|
|
@@ -271,6 +272,7 @@ export function createTreeCheckout(
|
|
|
271
272
|
chunkCompressionStrategy?: TreeCompressionStrategy;
|
|
272
273
|
logger?: ITelemetryLoggerExt;
|
|
273
274
|
breaker?: Breakable;
|
|
275
|
+
disposeForksAfterTransaction?: boolean;
|
|
274
276
|
},
|
|
275
277
|
): TreeCheckout {
|
|
276
278
|
const forest = args?.forest ?? buildForest();
|
|
@@ -310,6 +312,7 @@ export function createTreeCheckout(
|
|
|
310
312
|
args?.removedRoots,
|
|
311
313
|
args?.logger,
|
|
312
314
|
args?.breaker,
|
|
315
|
+
args?.disposeForksAfterTransaction,
|
|
313
316
|
);
|
|
314
317
|
}
|
|
315
318
|
|
|
@@ -342,6 +345,8 @@ export interface RevertMetrics {
|
|
|
342
345
|
export class TreeCheckout implements ITreeCheckoutFork {
|
|
343
346
|
public disposed = false;
|
|
344
347
|
|
|
348
|
+
private readonly editLock: EditLock;
|
|
349
|
+
|
|
345
350
|
private readonly views = new Set<TreeView<ImplicitFieldSchema>>();
|
|
346
351
|
|
|
347
352
|
/**
|
|
@@ -386,6 +391,7 @@ export class TreeCheckout implements ITreeCheckoutFork {
|
|
|
386
391
|
/** Optional logger for telemetry. */
|
|
387
392
|
private readonly logger?: ITelemetryLoggerExt,
|
|
388
393
|
private readonly breaker: Breakable = new Breakable("TreeCheckout"),
|
|
394
|
+
private readonly disposeForksAfterTransaction = true,
|
|
389
395
|
) {
|
|
390
396
|
this.#transaction = new SquashingTransactionStack(
|
|
391
397
|
branch,
|
|
@@ -400,14 +406,9 @@ export class TreeCheckout implements ITreeCheckoutFork {
|
|
|
400
406
|
return tagChange(change, revision);
|
|
401
407
|
},
|
|
402
408
|
() => {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
const onDisposeUnSubscribes: (() => void)[] = [];
|
|
407
|
-
const onForkUnSubscribe = onForkTransitive(this, (fork) => {
|
|
408
|
-
forks.add(fork);
|
|
409
|
-
onDisposeUnSubscribes.push(fork.events.on("dispose", () => forks.delete(fork)));
|
|
410
|
-
});
|
|
409
|
+
const disposeForks = this.disposeForksAfterTransaction
|
|
410
|
+
? trackForksForDisposal(this)
|
|
411
|
+
: undefined;
|
|
411
412
|
// When each transaction is started, take a snapshot of the current state of removed roots
|
|
412
413
|
const removedRootsSnapshot = this.removedRoots.clone();
|
|
413
414
|
return (result) => {
|
|
@@ -424,14 +425,13 @@ export class TreeCheckout implements ITreeCheckoutFork {
|
|
|
424
425
|
default:
|
|
425
426
|
unreachableCase(result);
|
|
426
427
|
}
|
|
427
|
-
|
|
428
|
-
forks.forEach((fork) => fork.dispose());
|
|
429
|
-
onDisposeUnSubscribes.forEach((unsubscribe) => unsubscribe());
|
|
430
|
-
onForkUnSubscribe();
|
|
428
|
+
disposeForks?.();
|
|
431
429
|
};
|
|
432
430
|
},
|
|
433
431
|
);
|
|
434
432
|
|
|
433
|
+
this.editLock = new EditLock(this.#transaction.activeBranchEditor);
|
|
434
|
+
|
|
435
435
|
branch.events.on("afterChange", (event) => {
|
|
436
436
|
// The following logic allows revertibles to be generated for the change.
|
|
437
437
|
// Currently only appends (including merges and transaction commits) are supported.
|
|
@@ -484,6 +484,7 @@ export class TreeCheckout implements ITreeCheckoutFork {
|
|
|
484
484
|
}
|
|
485
485
|
|
|
486
486
|
private readonly onAfterChange = (event: SharedTreeBranchChange<SharedTreeChange>): void => {
|
|
487
|
+
this.editLock.lock();
|
|
487
488
|
this.#events.emit("beforeBatch", event);
|
|
488
489
|
if (event.change !== undefined) {
|
|
489
490
|
const revision =
|
|
@@ -521,6 +522,7 @@ export class TreeCheckout implements ITreeCheckoutFork {
|
|
|
521
522
|
}
|
|
522
523
|
}
|
|
523
524
|
this.#events.emit("afterBatch");
|
|
525
|
+
this.editLock.unlock();
|
|
524
526
|
if (event.type === "append") {
|
|
525
527
|
event.newCommits.forEach((commit) => this.validateCommit(commit));
|
|
526
528
|
}
|
|
@@ -665,7 +667,7 @@ export class TreeCheckout implements ITreeCheckoutFork {
|
|
|
665
667
|
|
|
666
668
|
public get editor(): ISharedTreeEditor {
|
|
667
669
|
this.checkNotDisposed();
|
|
668
|
-
return this
|
|
670
|
+
return this.editLock.editor;
|
|
669
671
|
}
|
|
670
672
|
|
|
671
673
|
public locate(anchor: Anchor): AnchorNode | undefined {
|
|
@@ -692,6 +694,7 @@ export class TreeCheckout implements ITreeCheckoutFork {
|
|
|
692
694
|
this.checkNotDisposed(
|
|
693
695
|
"The parent branch has already been disposed and can no longer create new branches.",
|
|
694
696
|
);
|
|
697
|
+
this.editLock.checkUnlocked("Branching");
|
|
695
698
|
const anchors = new AnchorSet();
|
|
696
699
|
const branch = this.#transaction.activeBranch.fork();
|
|
697
700
|
const storedSchema = this.storedSchema.clone();
|
|
@@ -708,6 +711,7 @@ export class TreeCheckout implements ITreeCheckoutFork {
|
|
|
708
711
|
this.removedRoots.clone(),
|
|
709
712
|
this.logger,
|
|
710
713
|
this.breaker,
|
|
714
|
+
this.disposeForksAfterTransaction,
|
|
711
715
|
);
|
|
712
716
|
this.#events.emit("fork", checkout);
|
|
713
717
|
return checkout;
|
|
@@ -720,6 +724,7 @@ export class TreeCheckout implements ITreeCheckoutFork {
|
|
|
720
724
|
checkout.checkNotDisposed(
|
|
721
725
|
"The source of the branch rebase has been disposed and cannot be rebased.",
|
|
722
726
|
);
|
|
727
|
+
this.editLock.checkUnlocked("Rebasing");
|
|
723
728
|
assert(
|
|
724
729
|
!checkout.transaction.isInProgress(),
|
|
725
730
|
0x9af /* A view cannot be rebased while it has a pending transaction */,
|
|
@@ -748,6 +753,7 @@ export class TreeCheckout implements ITreeCheckoutFork {
|
|
|
748
753
|
checkout.checkNotDisposed(
|
|
749
754
|
"The source of the branch merge has been disposed and cannot be merged.",
|
|
750
755
|
);
|
|
756
|
+
this.editLock.checkUnlocked("Merging");
|
|
751
757
|
assert(
|
|
752
758
|
!this.transaction.isInProgress(),
|
|
753
759
|
0x9b0 /* Views cannot be merged into a view while it has a pending transaction */,
|
|
@@ -768,6 +774,7 @@ export class TreeCheckout implements ITreeCheckoutFork {
|
|
|
768
774
|
}
|
|
769
775
|
|
|
770
776
|
public dispose(): void {
|
|
777
|
+
this.editLock.checkUnlocked("Disposing a view");
|
|
771
778
|
this[disposeSymbol]();
|
|
772
779
|
}
|
|
773
780
|
|
|
@@ -955,3 +962,130 @@ export class TreeCheckout implements ITreeCheckoutFork {
|
|
|
955
962
|
|
|
956
963
|
// #endregion Commit Validation
|
|
957
964
|
}
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* A helper class that assists {@link TreeCheckout} in preventing functionality from being used while the tree is in the middle of being edited.
|
|
968
|
+
*/
|
|
969
|
+
class EditLock {
|
|
970
|
+
/**
|
|
971
|
+
* Edits the tree by calling the methods of the editor passed into the {@link EditLock} constructor.
|
|
972
|
+
* @remarks Edits will throw an error if the lock is currently locked.
|
|
973
|
+
*/
|
|
974
|
+
public editor: ISharedTreeEditor;
|
|
975
|
+
private locked = false;
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* @param editor - an editor which will be used to create a new editor that is monitored to determine if any changes are happening to the tree.
|
|
979
|
+
* Use {@link EditLock.editor} in place of the original editor to ensure that changes are monitored.
|
|
980
|
+
*/
|
|
981
|
+
public constructor(editor: ISharedTreeEditor) {
|
|
982
|
+
const checkLock = (): void => this.checkUnlocked("Editing the tree");
|
|
983
|
+
this.editor = {
|
|
984
|
+
get schema() {
|
|
985
|
+
return editor.schema;
|
|
986
|
+
},
|
|
987
|
+
valueField(...fieldArgs) {
|
|
988
|
+
const valueField = editor.valueField(...fieldArgs);
|
|
989
|
+
return {
|
|
990
|
+
set(...editArgs) {
|
|
991
|
+
checkLock();
|
|
992
|
+
valueField.set(...editArgs);
|
|
993
|
+
},
|
|
994
|
+
};
|
|
995
|
+
},
|
|
996
|
+
optionalField(...fieldArgs) {
|
|
997
|
+
const optionalField = editor.optionalField(...fieldArgs);
|
|
998
|
+
return {
|
|
999
|
+
set(...editArgs) {
|
|
1000
|
+
checkLock();
|
|
1001
|
+
optionalField.set(...editArgs);
|
|
1002
|
+
},
|
|
1003
|
+
};
|
|
1004
|
+
},
|
|
1005
|
+
sequenceField(...fieldArgs) {
|
|
1006
|
+
const sequenceField = editor.sequenceField(...fieldArgs);
|
|
1007
|
+
return {
|
|
1008
|
+
insert(...editArgs) {
|
|
1009
|
+
checkLock();
|
|
1010
|
+
sequenceField.insert(...editArgs);
|
|
1011
|
+
},
|
|
1012
|
+
remove(...editArgs) {
|
|
1013
|
+
checkLock();
|
|
1014
|
+
sequenceField.remove(...editArgs);
|
|
1015
|
+
},
|
|
1016
|
+
};
|
|
1017
|
+
},
|
|
1018
|
+
move(...moveArgs) {
|
|
1019
|
+
checkLock();
|
|
1020
|
+
editor.move(...moveArgs);
|
|
1021
|
+
},
|
|
1022
|
+
addNodeExistsConstraint(path) {
|
|
1023
|
+
editor.addNodeExistsConstraint(path);
|
|
1024
|
+
},
|
|
1025
|
+
addNodeExistsConstraintOnRevert(path) {
|
|
1026
|
+
editor.addNodeExistsConstraintOnRevert(path);
|
|
1027
|
+
},
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* Prevent further changes from being made to {@link EditLock.editor} until {@link EditLock.unlock} is called.
|
|
1033
|
+
* @remarks May only be called when the lock is not already locked.
|
|
1034
|
+
*/
|
|
1035
|
+
public lock(): void {
|
|
1036
|
+
if (this.locked) {
|
|
1037
|
+
debugger;
|
|
1038
|
+
}
|
|
1039
|
+
assert(!this.locked, 0xaa7 /* Checkout has already been locked */);
|
|
1040
|
+
this.locked = true;
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
/**
|
|
1044
|
+
* Throws an error if the lock is currently locked.
|
|
1045
|
+
* @param action - The current action being performed by the user.
|
|
1046
|
+
* This must start with a capital letter, as it shows up as the first part of the error message and we want it to look nice.
|
|
1047
|
+
*/
|
|
1048
|
+
public checkUnlocked<T extends string>(action: T extends Capitalize<T> ? T : never): void {
|
|
1049
|
+
if (this.locked) {
|
|
1050
|
+
// These type assertions ensure that the event name strings used here match the actual event names
|
|
1051
|
+
const nodeChanged: keyof TreeChangeEvents = "nodeChanged";
|
|
1052
|
+
const treeChanged: keyof TreeChangeEvents = "treeChanged";
|
|
1053
|
+
throw new UsageError(
|
|
1054
|
+
`${action} is forbidden during a ${nodeChanged} or ${treeChanged} event`,
|
|
1055
|
+
);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
/**
|
|
1060
|
+
* Allow changes to be made to {@link EditLock.editor} again.
|
|
1061
|
+
* @remarks May only be called when the lock is currently locked.
|
|
1062
|
+
*/
|
|
1063
|
+
public unlock(): void {
|
|
1064
|
+
assert(this.locked, 0xaa8 /* Checkout has not been locked */);
|
|
1065
|
+
this.locked = false;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
/**
|
|
1070
|
+
* Keeps track of all new forks created until the returned function is invoked, which will dispose all of those for.
|
|
1071
|
+
* The returned function may only be called once.
|
|
1072
|
+
*
|
|
1073
|
+
* @param checkout - The tree checkout for which you want to monitor forks for disposal.
|
|
1074
|
+
* @returns a function which can be called to dispose all of the tracked forks.
|
|
1075
|
+
*/
|
|
1076
|
+
function trackForksForDisposal(checkout: TreeCheckout): () => void {
|
|
1077
|
+
const forks = new Set<TreeCheckout>();
|
|
1078
|
+
const onDisposeUnSubscribes: (() => void)[] = [];
|
|
1079
|
+
const onForkUnSubscribe = onForkTransitive(checkout, (fork) => {
|
|
1080
|
+
forks.add(fork);
|
|
1081
|
+
onDisposeUnSubscribes.push(fork.events.on("dispose", () => forks.delete(fork)));
|
|
1082
|
+
});
|
|
1083
|
+
let disposed = false;
|
|
1084
|
+
return () => {
|
|
1085
|
+
assert(!disposed, 0xaa9 /* Forks may only be disposed once */);
|
|
1086
|
+
forks.forEach((fork) => fork.dispose());
|
|
1087
|
+
onDisposeUnSubscribes.forEach((unsubscribe) => unsubscribe());
|
|
1088
|
+
onForkUnSubscribe();
|
|
1089
|
+
disposed = true;
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
@@ -259,7 +259,7 @@ export class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange>
|
|
|
259
259
|
protected async loadCore(services: IChannelStorageService): Promise<void> {
|
|
260
260
|
assert(
|
|
261
261
|
this.editManager.localBranch.getHead() === this.editManager.getTrunkHead(),
|
|
262
|
-
|
|
262
|
+
0xaaa /* All local changes should be applied to the trunk before loading from summary */,
|
|
263
263
|
);
|
|
264
264
|
const [editManagerSummarizer, ...summarizables] = this.summarizables;
|
|
265
265
|
const loadEditManager = this.loadSummarizable(editManagerSummarizer, services);
|
|
@@ -58,6 +58,13 @@ export interface JsonNodeSchemaBase<
|
|
|
58
58
|
* {@inheritDoc JsonSchemaType}
|
|
59
59
|
*/
|
|
60
60
|
readonly type: TJsonSchemaType;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Description of the node schema.
|
|
64
|
+
* @remarks Derived from {@link NodeSchemaMetadata.description}.
|
|
65
|
+
* @see {@link https://json-schema.org/draft/2020-12/json-schema-validation#name-title-and-description}
|
|
66
|
+
*/
|
|
67
|
+
readonly description?: string | undefined;
|
|
61
68
|
}
|
|
62
69
|
|
|
63
70
|
/**
|
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
createFieldSchema,
|
|
41
41
|
type DefaultProvider,
|
|
42
42
|
getDefaultProvider,
|
|
43
|
+
type NodeSchemaOptions,
|
|
43
44
|
} from "../schemaTypes.js";
|
|
44
45
|
import { inPrototypeChain } from "../core/index.js";
|
|
45
46
|
import type {
|
|
@@ -103,11 +104,15 @@ export function schemaFromValue(value: TreeValue): TreeNodeSchema {
|
|
|
103
104
|
|
|
104
105
|
/**
|
|
105
106
|
* Options when declaring an {@link SchemaFactory.object|object node}'s schema
|
|
107
|
+
*
|
|
108
|
+
* @alpha
|
|
106
109
|
*/
|
|
107
|
-
export interface SchemaFactoryObjectOptions
|
|
110
|
+
export interface SchemaFactoryObjectOptions<TCustomMetadata = unknown>
|
|
111
|
+
extends NodeSchemaOptions<TCustomMetadata> {
|
|
108
112
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
113
|
+
* Allow nodes typed with this object node schema to contain optional fields that are not present in the schema declaration.
|
|
114
|
+
* Such nodes can come into existence either via import APIs (see remarks) or by way of collaboration with another client
|
|
115
|
+
* that has upgraded the document's schema to include those optional fields.
|
|
111
116
|
*
|
|
112
117
|
* @defaultValue `false`
|
|
113
118
|
* @remarks
|
|
@@ -149,7 +154,9 @@ export interface SchemaFactoryObjectOptions {
|
|
|
149
154
|
allowUnknownOptionalFields?: boolean;
|
|
150
155
|
}
|
|
151
156
|
|
|
152
|
-
export const defaultSchemaFactoryObjectOptions: Required<
|
|
157
|
+
export const defaultSchemaFactoryObjectOptions: Required<
|
|
158
|
+
Omit<SchemaFactoryObjectOptions, "metadata">
|
|
159
|
+
> = {
|
|
153
160
|
allowUnknownOptionalFields: false,
|
|
154
161
|
};
|
|
155
162
|
|
|
@@ -400,6 +407,8 @@ export class SchemaFactory<
|
|
|
400
407
|
/**
|
|
401
408
|
* Define a structurally typed {@link TreeNodeSchema} for a {@link TreeMapNode}.
|
|
402
409
|
*
|
|
410
|
+
* @param allowedTypes - The types that may appear as values in the map.
|
|
411
|
+
*
|
|
403
412
|
* @remarks
|
|
404
413
|
* The unique identifier for this Map is defined as a function of the provided types.
|
|
405
414
|
* It is still scoped to this SchemaBuilder, but multiple calls with the same arguments will return the same schema object, providing somewhat structural typing.
|
|
@@ -436,6 +445,7 @@ export class SchemaFactory<
|
|
|
436
445
|
* Define a {@link TreeNodeSchema} for a {@link TreeMapNode}.
|
|
437
446
|
*
|
|
438
447
|
* @param name - Unique identifier for this schema within this factory's scope.
|
|
448
|
+
* @param allowedTypes - The types that may appear as values in the map.
|
|
439
449
|
*
|
|
440
450
|
* @example
|
|
441
451
|
* ```typescript
|
|
@@ -456,6 +466,8 @@ export class SchemaFactory<
|
|
|
456
466
|
>;
|
|
457
467
|
|
|
458
468
|
/**
|
|
469
|
+
* {@link SchemaFactory.map} implementation.
|
|
470
|
+
*
|
|
459
471
|
* @privateRemarks
|
|
460
472
|
* This should return `TreeNodeSchemaBoth`, however TypeScript gives an error if one of the overloads implicitly up-casts the return type of the implementation.
|
|
461
473
|
* This seems like a TypeScript bug getting variance backwards for overload return types since it's erroring when the relation between the overload
|
|
@@ -530,12 +542,15 @@ export class SchemaFactory<
|
|
|
530
542
|
implicitlyConstructable,
|
|
531
543
|
// The current policy is customizable nodes don't get fake prototypes.
|
|
532
544
|
!customizable,
|
|
545
|
+
undefined,
|
|
533
546
|
);
|
|
534
547
|
}
|
|
535
548
|
|
|
536
549
|
/**
|
|
537
550
|
* Define a structurally typed {@link TreeNodeSchema} for a {@link (TreeArrayNode:interface)}.
|
|
538
551
|
*
|
|
552
|
+
* @param allowedTypes - The types that may appear in the array.
|
|
553
|
+
*
|
|
539
554
|
* @remarks
|
|
540
555
|
* The identifier for this Array is defined as a function of the provided types.
|
|
541
556
|
* It is still scoped to this SchemaFactory, but multiple calls with the same arguments will return the same schema object, providing somewhat structural typing.
|
|
@@ -582,6 +597,7 @@ export class SchemaFactory<
|
|
|
582
597
|
* Define (and add to this library) a {@link TreeNodeSchemaClass} for a {@link (TreeArrayNode:interface)}.
|
|
583
598
|
*
|
|
584
599
|
* @param name - Unique identifier for this schema within this factory's scope.
|
|
600
|
+
* @param allowedTypes - The types that may appear in the array.
|
|
585
601
|
*
|
|
586
602
|
* @example
|
|
587
603
|
* ```typescript
|
|
@@ -604,6 +620,8 @@ export class SchemaFactory<
|
|
|
604
620
|
>;
|
|
605
621
|
|
|
606
622
|
/**
|
|
623
|
+
* {@link SchemaFactory.array} implementation.
|
|
624
|
+
*
|
|
607
625
|
* @privateRemarks
|
|
608
626
|
* This should return TreeNodeSchemaBoth: see note on "map" implementation for details.
|
|
609
627
|
*/
|
|
@@ -787,11 +805,20 @@ export class SchemaFactory<
|
|
|
787
805
|
* `error TS2589: Type instantiation is excessively deep and possibly infinite.`
|
|
788
806
|
* which otherwise gets reported at sometimes incorrect source locations that vary based on incremental builds.
|
|
789
807
|
*/
|
|
790
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
791
808
|
public objectRecursive<
|
|
792
809
|
const Name extends TName,
|
|
793
810
|
const T extends Unenforced<RestrictiveStringRecord<ImplicitFieldSchema>>,
|
|
794
|
-
>(
|
|
811
|
+
>(
|
|
812
|
+
name: Name,
|
|
813
|
+
t: T,
|
|
814
|
+
): TreeNodeSchemaClass<
|
|
815
|
+
ScopedSchemaName<TScope, Name>,
|
|
816
|
+
NodeKind.Object,
|
|
817
|
+
TreeObjectNodeUnsafe<T, ScopedSchemaName<TScope, Name>>,
|
|
818
|
+
object & InsertableObjectFromSchemaRecordUnsafe<T>,
|
|
819
|
+
false,
|
|
820
|
+
T
|
|
821
|
+
> {
|
|
795
822
|
type TScopedName = ScopedSchemaName<TScope, Name>;
|
|
796
823
|
return this.object(
|
|
797
824
|
name,
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
ScopedSchemaName,
|
|
8
|
+
InsertableObjectFromSchemaRecord,
|
|
9
|
+
TreeObjectNodeUnsafe,
|
|
10
|
+
InsertableObjectFromSchemaRecordUnsafe,
|
|
11
|
+
} from "../../internalTypes.js";
|
|
12
|
+
import {
|
|
13
|
+
defaultSchemaFactoryObjectOptions,
|
|
14
|
+
SchemaFactory,
|
|
15
|
+
type SchemaFactoryObjectOptions,
|
|
16
|
+
} from "./schemaFactory.js";
|
|
17
|
+
import type {
|
|
18
|
+
ImplicitAllowedTypes,
|
|
19
|
+
ImplicitFieldSchema,
|
|
20
|
+
InsertableTreeNodeFromImplicitAllowedTypes,
|
|
21
|
+
NodeSchemaOptions,
|
|
22
|
+
} from "../schemaTypes.js";
|
|
23
|
+
import { type TreeObjectNode, objectSchema } from "../objectNode.js";
|
|
24
|
+
import type { RestrictiveStringRecord } from "../../util/index.js";
|
|
25
|
+
import type { NodeKind, TreeNodeSchemaClass, WithType } from "../core/index.js";
|
|
26
|
+
import type {
|
|
27
|
+
InsertableTreeNodeFromImplicitAllowedTypesUnsafe,
|
|
28
|
+
TreeArrayNodeUnsafe,
|
|
29
|
+
TreeMapNodeUnsafe,
|
|
30
|
+
Unenforced,
|
|
31
|
+
} from "./typesUnsafe.js";
|
|
32
|
+
import { mapSchema, type MapNodeInsertableData, type TreeMapNode } from "../mapNode.js";
|
|
33
|
+
import { arraySchema, type TreeArrayNode } from "../arrayNode.js";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* {@link SchemaFactory} with additional alpha APIs.
|
|
37
|
+
*
|
|
38
|
+
* @alpha
|
|
39
|
+
* @privateRemarks
|
|
40
|
+
*
|
|
41
|
+
* Some private methods on `SchemaFactory` are intentionally duplicated here to avoid increasing their exposure to `protected`.
|
|
42
|
+
* If we were to do so, they would be exposed on the public API surface of `SchemaFactory`.
|
|
43
|
+
*/
|
|
44
|
+
export class SchemaFactoryAlpha<
|
|
45
|
+
out TScope extends string | undefined = string | undefined,
|
|
46
|
+
TName extends number | string = string,
|
|
47
|
+
> extends SchemaFactory<TScope, TName> {
|
|
48
|
+
private scoped2<Name extends TName | string>(name: Name): ScopedSchemaName<TScope, Name> {
|
|
49
|
+
return (
|
|
50
|
+
this.scope === undefined ? `${name}` : `${this.scope}.${name}`
|
|
51
|
+
) as ScopedSchemaName<TScope, Name>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Define a {@link TreeNodeSchemaClass} for a {@link TreeObjectNode}.
|
|
56
|
+
*
|
|
57
|
+
* @param name - Unique identifier for this schema within this factory's scope.
|
|
58
|
+
* @param fields - Schema for fields of the object node's schema. Defines what children can be placed under each key.
|
|
59
|
+
* @param options - Additional options for the schema.
|
|
60
|
+
*/
|
|
61
|
+
public override object<
|
|
62
|
+
const Name extends TName,
|
|
63
|
+
const T extends RestrictiveStringRecord<ImplicitFieldSchema>,
|
|
64
|
+
const TCustomMetadata = unknown,
|
|
65
|
+
>(
|
|
66
|
+
name: Name,
|
|
67
|
+
fields: T,
|
|
68
|
+
options?: SchemaFactoryObjectOptions<TCustomMetadata>,
|
|
69
|
+
): TreeNodeSchemaClass<
|
|
70
|
+
ScopedSchemaName<TScope, Name>,
|
|
71
|
+
NodeKind.Object,
|
|
72
|
+
TreeObjectNode<T, ScopedSchemaName<TScope, Name>>,
|
|
73
|
+
object & InsertableObjectFromSchemaRecord<T>,
|
|
74
|
+
true,
|
|
75
|
+
T,
|
|
76
|
+
never,
|
|
77
|
+
TCustomMetadata
|
|
78
|
+
> {
|
|
79
|
+
return objectSchema(
|
|
80
|
+
this.scoped2(name),
|
|
81
|
+
fields,
|
|
82
|
+
true,
|
|
83
|
+
options?.allowUnknownOptionalFields ??
|
|
84
|
+
defaultSchemaFactoryObjectOptions.allowUnknownOptionalFields,
|
|
85
|
+
options?.metadata,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* {@inheritdoc SchemaFactory.objectRecursive}
|
|
91
|
+
*/
|
|
92
|
+
public override objectRecursive<
|
|
93
|
+
const Name extends TName,
|
|
94
|
+
const T extends Unenforced<RestrictiveStringRecord<ImplicitFieldSchema>>,
|
|
95
|
+
const TCustomMetadata = unknown,
|
|
96
|
+
>(
|
|
97
|
+
name: Name,
|
|
98
|
+
t: T,
|
|
99
|
+
options?: SchemaFactoryObjectOptions<TCustomMetadata>,
|
|
100
|
+
): TreeNodeSchemaClass<
|
|
101
|
+
ScopedSchemaName<TScope, Name>,
|
|
102
|
+
NodeKind.Object,
|
|
103
|
+
TreeObjectNodeUnsafe<T, ScopedSchemaName<TScope, Name>>,
|
|
104
|
+
object & InsertableObjectFromSchemaRecordUnsafe<T>,
|
|
105
|
+
false,
|
|
106
|
+
T,
|
|
107
|
+
never,
|
|
108
|
+
TCustomMetadata
|
|
109
|
+
> {
|
|
110
|
+
type TScopedName = ScopedSchemaName<TScope, Name>;
|
|
111
|
+
return this.object(
|
|
112
|
+
name,
|
|
113
|
+
t as T & RestrictiveStringRecord<ImplicitFieldSchema>,
|
|
114
|
+
options,
|
|
115
|
+
) as unknown as TreeNodeSchemaClass<
|
|
116
|
+
TScopedName,
|
|
117
|
+
NodeKind.Object,
|
|
118
|
+
TreeObjectNodeUnsafe<T, TScopedName>,
|
|
119
|
+
object & InsertableObjectFromSchemaRecordUnsafe<T>,
|
|
120
|
+
false,
|
|
121
|
+
T,
|
|
122
|
+
never,
|
|
123
|
+
TCustomMetadata
|
|
124
|
+
>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Define a {@link TreeNodeSchema} for a {@link TreeMapNode}.
|
|
129
|
+
*
|
|
130
|
+
* @param name - Unique identifier for this schema within this factory's scope.
|
|
131
|
+
* @param allowedTypes - The types that may appear as values in the map.
|
|
132
|
+
* @param options - Additional options for the schema.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* class NamedMap extends factory.map("name", factory.number, {
|
|
137
|
+
* metadata: { description: "A map of numbers" }
|
|
138
|
+
* }) {}
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
public mapAlpha<
|
|
142
|
+
Name extends TName,
|
|
143
|
+
const T extends ImplicitAllowedTypes,
|
|
144
|
+
const TCustomMetadata = unknown,
|
|
145
|
+
>(
|
|
146
|
+
name: Name,
|
|
147
|
+
allowedTypes: T,
|
|
148
|
+
options?: NodeSchemaOptions<TCustomMetadata>,
|
|
149
|
+
): TreeNodeSchemaClass<
|
|
150
|
+
ScopedSchemaName<TScope, Name>,
|
|
151
|
+
NodeKind.Map,
|
|
152
|
+
TreeMapNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Map>,
|
|
153
|
+
MapNodeInsertableData<T>,
|
|
154
|
+
true,
|
|
155
|
+
T,
|
|
156
|
+
undefined,
|
|
157
|
+
TCustomMetadata
|
|
158
|
+
> {
|
|
159
|
+
return mapSchema(this.scoped2(name), allowedTypes, true, true, options?.metadata);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* {@inheritDoc SchemaFactory.objectRecursive}
|
|
164
|
+
*/
|
|
165
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
166
|
+
public override mapRecursive<
|
|
167
|
+
Name extends TName,
|
|
168
|
+
const T extends Unenforced<ImplicitAllowedTypes>,
|
|
169
|
+
const TCustomMetadata = unknown,
|
|
170
|
+
>(name: Name, allowedTypes: T, options?: NodeSchemaOptions<TCustomMetadata>) {
|
|
171
|
+
return this.mapAlpha(
|
|
172
|
+
name,
|
|
173
|
+
allowedTypes as T & ImplicitAllowedTypes,
|
|
174
|
+
options,
|
|
175
|
+
) as unknown as TreeNodeSchemaClass<
|
|
176
|
+
ScopedSchemaName<TScope, Name>,
|
|
177
|
+
NodeKind.Map,
|
|
178
|
+
TreeMapNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Map>,
|
|
179
|
+
| {
|
|
180
|
+
[Symbol.iterator](): Iterator<
|
|
181
|
+
[string, InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>]
|
|
182
|
+
>;
|
|
183
|
+
}
|
|
184
|
+
| {
|
|
185
|
+
readonly [P in string]: InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>;
|
|
186
|
+
},
|
|
187
|
+
false,
|
|
188
|
+
T,
|
|
189
|
+
undefined,
|
|
190
|
+
TCustomMetadata
|
|
191
|
+
>;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Define (and add to this library) a {@link TreeNodeSchemaClass} for a {@link (TreeArrayNode:interface)}.
|
|
196
|
+
*
|
|
197
|
+
* @param name - Unique identifier for this schema within this factory's scope.
|
|
198
|
+
* @param allowedTypes - The types that may appear in the array.
|
|
199
|
+
* @param options - Additional options for the schema.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* class NamedArray extends factory.array("name", factory.number) {}
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
public arrayAlpha<
|
|
207
|
+
const Name extends TName,
|
|
208
|
+
const T extends ImplicitAllowedTypes,
|
|
209
|
+
const TCustomMetadata = unknown,
|
|
210
|
+
>(
|
|
211
|
+
name: Name,
|
|
212
|
+
allowedTypes: T,
|
|
213
|
+
options?: NodeSchemaOptions<TCustomMetadata>,
|
|
214
|
+
): TreeNodeSchemaClass<
|
|
215
|
+
ScopedSchemaName<TScope, Name>,
|
|
216
|
+
NodeKind.Array,
|
|
217
|
+
TreeArrayNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Array>,
|
|
218
|
+
Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>,
|
|
219
|
+
true,
|
|
220
|
+
T,
|
|
221
|
+
undefined,
|
|
222
|
+
TCustomMetadata
|
|
223
|
+
> {
|
|
224
|
+
return arraySchema(this.scoped2(name), allowedTypes, true, true, options?.metadata);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* {@inheritDoc SchemaFactory.objectRecursive}
|
|
229
|
+
*/
|
|
230
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
231
|
+
public override arrayRecursive<
|
|
232
|
+
const Name extends TName,
|
|
233
|
+
const T extends Unenforced<ImplicitAllowedTypes>,
|
|
234
|
+
const TCustomMetadata = unknown,
|
|
235
|
+
>(name: Name, allowedTypes: T, options?: NodeSchemaOptions<TCustomMetadata>) {
|
|
236
|
+
return this.arrayAlpha(
|
|
237
|
+
name,
|
|
238
|
+
allowedTypes as T & ImplicitAllowedTypes,
|
|
239
|
+
options,
|
|
240
|
+
) as unknown as TreeNodeSchemaClass<
|
|
241
|
+
ScopedSchemaName<TScope, Name>,
|
|
242
|
+
NodeKind.Array,
|
|
243
|
+
TreeArrayNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Array>,
|
|
244
|
+
{
|
|
245
|
+
[Symbol.iterator](): Iterator<InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>>;
|
|
246
|
+
},
|
|
247
|
+
false,
|
|
248
|
+
T,
|
|
249
|
+
undefined,
|
|
250
|
+
TCustomMetadata
|
|
251
|
+
>;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import type { ValueSchema } from "../../core/index.js";
|
|
7
7
|
import type { NodeKind } from "../core/index.js";
|
|
8
|
-
import type { FieldKind, FieldSchemaMetadata } from "../schemaTypes.js";
|
|
8
|
+
import type { FieldKind, FieldSchemaMetadata, NodeSchemaMetadata } from "../schemaTypes.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Base interface for all {@link SimpleNodeSchema} implementations.
|
|
@@ -20,6 +20,11 @@ export interface SimpleNodeSchemaBase<TNodeKind extends NodeKind> {
|
|
|
20
20
|
* @remarks can be used to type-switch between implementations.
|
|
21
21
|
*/
|
|
22
22
|
readonly kind: TNodeKind;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* {@inheritDoc NodeSchemaMetadata}
|
|
26
|
+
*/
|
|
27
|
+
readonly metadata?: NodeSchemaMetadata | undefined;
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
/**
|