@fluidframework/tree 2.31.0 → 2.32.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/.vscode/settings.json +1 -1
- package/CHANGELOG.md +44 -0
- package/api-extractor/api-extractor.current.json +5 -1
- package/api-report/tree.alpha.api.md +44 -20
- package/dist/alpha.d.ts +6 -2
- package/dist/feature-libraries/flex-tree/context.d.ts +1 -1
- package/dist/feature-libraries/flex-tree/context.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/context.js +1 -2
- package/dist/feature-libraries/flex-tree/context.js.map +1 -1
- package/dist/feature-libraries/flex-tree/index.d.ts +1 -1
- package/dist/feature-libraries/flex-tree/index.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/index.js +1 -2
- package/dist/feature-libraries/flex-tree/index.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyEntity.d.ts +6 -15
- package/dist/feature-libraries/flex-tree/lazyEntity.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyEntity.js +9 -18
- package/dist/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyField.d.ts +3 -3
- package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyField.js +14 -14
- package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts +4 -4
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.js +12 -12
- package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
- package/dist/feature-libraries/index.d.ts +1 -1
- package/dist/feature-libraries/index.d.ts.map +1 -1
- package/dist/feature-libraries/index.js +1 -2
- package/dist/feature-libraries/index.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/shared-tree/sharedTree.js +2 -2
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/shared-tree/treeApiAlpha.d.ts +6 -6
- package/dist/shared-tree/treeApiAlpha.d.ts.map +1 -1
- package/dist/shared-tree/treeApiAlpha.js.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.d.ts +0 -6
- package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.js +0 -17
- package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/dist/simple-tree/api/conciseTree.d.ts +2 -2
- package/dist/simple-tree/api/conciseTree.d.ts.map +1 -1
- package/dist/simple-tree/api/conciseTree.js.map +1 -1
- package/dist/simple-tree/api/customTree.d.ts +14 -12
- package/dist/simple-tree/api/customTree.d.ts.map +1 -1
- package/dist/simple-tree/api/customTree.js.map +1 -1
- package/dist/simple-tree/api/getJsonSchema.d.ts +21 -7
- package/dist/simple-tree/api/getJsonSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/getJsonSchema.js +8 -16
- package/dist/simple-tree/api/getJsonSchema.js.map +1 -1
- package/dist/simple-tree/api/getSimpleSchema.d.ts +3 -10
- package/dist/simple-tree/api/getSimpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/getSimpleSchema.js +4 -16
- package/dist/simple-tree/api/getSimpleSchema.js.map +1 -1
- package/dist/simple-tree/api/index.d.ts +4 -3
- package/dist/simple-tree/api/index.d.ts.map +1 -1
- package/dist/simple-tree/api/index.js +2 -1
- package/dist/simple-tree/api/index.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +17 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.js +4 -0
- package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
- package/dist/simple-tree/api/schemaFromSimple.d.ts +5 -2
- package/dist/simple-tree/api/schemaFromSimple.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFromSimple.js +24 -8
- package/dist/simple-tree/api/schemaFromSimple.js.map +1 -1
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.d.ts +11 -3
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +40 -28
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/dist/simple-tree/api/tree.d.ts +32 -5
- package/dist/simple-tree/api/tree.d.ts.map +1 -1
- package/dist/simple-tree/api/tree.js +17 -1
- package/dist/simple-tree/api/tree.js.map +1 -1
- package/dist/simple-tree/api/verboseTree.d.ts +4 -28
- package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
- package/dist/simple-tree/api/verboseTree.js.map +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js +7 -3
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
- package/dist/simple-tree/core/treeNodeKernel.js +7 -6
- package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
- package/dist/simple-tree/core/unhydratedFlexTree.js +12 -1
- package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
- package/dist/simple-tree/index.d.ts +1 -1
- 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/simpleSchema.d.ts +4 -11
- package/dist/simple-tree/simpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/simpleSchema.js.map +1 -1
- package/dist/tableSchema.d.ts +227 -0
- package/dist/tableSchema.d.ts.map +1 -0
- package/dist/tableSchema.js +234 -0
- package/dist/tableSchema.js.map +1 -0
- package/dist/treeFactory.d.ts +4 -4
- package/dist/treeFactory.d.ts.map +1 -1
- package/dist/treeFactory.js.map +1 -1
- package/dist/util/breakable.d.ts.map +1 -1
- package/dist/util/breakable.js +9 -7
- package/dist/util/breakable.js.map +1 -1
- package/lib/alpha.d.ts +6 -2
- package/lib/feature-libraries/flex-tree/context.d.ts +1 -1
- package/lib/feature-libraries/flex-tree/context.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/context.js +1 -2
- package/lib/feature-libraries/flex-tree/context.js.map +1 -1
- package/lib/feature-libraries/flex-tree/index.d.ts +1 -1
- package/lib/feature-libraries/flex-tree/index.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/index.js +1 -1
- package/lib/feature-libraries/flex-tree/index.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyEntity.d.ts +6 -15
- package/lib/feature-libraries/flex-tree/lazyEntity.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyEntity.js +8 -17
- package/lib/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyField.d.ts +3 -3
- package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyField.js +15 -15
- package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts +4 -4
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.js +13 -13
- package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
- package/lib/feature-libraries/index.d.ts +1 -1
- package/lib/feature-libraries/index.d.ts.map +1 -1
- package/lib/feature-libraries/index.js +1 -1
- package/lib/feature-libraries/index.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/shared-tree/sharedTree.js +2 -2
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/shared-tree/treeApiAlpha.d.ts +6 -6
- package/lib/shared-tree/treeApiAlpha.d.ts.map +1 -1
- package/lib/shared-tree/treeApiAlpha.js.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.d.ts +0 -6
- package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.js +0 -17
- package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/lib/simple-tree/api/conciseTree.d.ts +2 -2
- package/lib/simple-tree/api/conciseTree.d.ts.map +1 -1
- package/lib/simple-tree/api/conciseTree.js.map +1 -1
- package/lib/simple-tree/api/customTree.d.ts +14 -12
- package/lib/simple-tree/api/customTree.d.ts.map +1 -1
- package/lib/simple-tree/api/customTree.js.map +1 -1
- package/lib/simple-tree/api/getJsonSchema.d.ts +21 -7
- package/lib/simple-tree/api/getJsonSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/getJsonSchema.js +8 -16
- package/lib/simple-tree/api/getJsonSchema.js.map +1 -1
- package/lib/simple-tree/api/getSimpleSchema.d.ts +3 -10
- package/lib/simple-tree/api/getSimpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/getSimpleSchema.js +4 -16
- package/lib/simple-tree/api/getSimpleSchema.js.map +1 -1
- package/lib/simple-tree/api/index.d.ts +4 -3
- package/lib/simple-tree/api/index.d.ts.map +1 -1
- package/lib/simple-tree/api/index.js +1 -1
- package/lib/simple-tree/api/index.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +17 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.js +4 -0
- package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
- package/lib/simple-tree/api/schemaFromSimple.d.ts +5 -2
- package/lib/simple-tree/api/schemaFromSimple.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFromSimple.js +24 -8
- package/lib/simple-tree/api/schemaFromSimple.js.map +1 -1
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.d.ts +11 -3
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +41 -29
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/lib/simple-tree/api/tree.d.ts +32 -5
- package/lib/simple-tree/api/tree.d.ts.map +1 -1
- package/lib/simple-tree/api/tree.js +16 -1
- package/lib/simple-tree/api/tree.js.map +1 -1
- package/lib/simple-tree/api/verboseTree.d.ts +4 -28
- package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
- package/lib/simple-tree/api/verboseTree.js.map +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js +7 -3
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
- package/lib/simple-tree/core/treeNodeKernel.js +8 -7
- package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
- package/lib/simple-tree/core/unhydratedFlexTree.js +12 -1
- package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
- package/lib/simple-tree/index.d.ts +1 -1
- 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/simpleSchema.d.ts +4 -11
- package/lib/simple-tree/simpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/simpleSchema.js.map +1 -1
- package/lib/tableSchema.d.ts +227 -0
- package/lib/tableSchema.d.ts.map +1 -0
- package/lib/tableSchema.js +231 -0
- package/lib/tableSchema.js.map +1 -0
- package/lib/treeFactory.d.ts +4 -4
- package/lib/treeFactory.d.ts.map +1 -1
- package/lib/treeFactory.js.map +1 -1
- package/lib/util/breakable.d.ts.map +1 -1
- package/lib/util/breakable.js +9 -7
- package/lib/util/breakable.js.map +1 -1
- package/package.json +25 -37
- package/src/feature-libraries/flex-tree/context.ts +2 -2
- package/src/feature-libraries/flex-tree/index.ts +0 -1
- package/src/feature-libraries/flex-tree/lazyEntity.ts +11 -21
- package/src/feature-libraries/flex-tree/lazyField.ts +17 -26
- package/src/feature-libraries/flex-tree/lazyNode.ts +13 -19
- package/src/feature-libraries/index.ts +0 -1
- package/src/index.ts +6 -2
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/sharedTree.ts +2 -2
- package/src/shared-tree/treeApiAlpha.ts +17 -15
- package/src/shared-tree-core/sharedTreeCore.ts +0 -23
- package/src/simple-tree/api/conciseTree.ts +4 -4
- package/src/simple-tree/api/customTree.ts +16 -14
- package/src/simple-tree/api/getJsonSchema.ts +25 -16
- package/src/simple-tree/api/getSimpleSchema.ts +4 -18
- package/src/simple-tree/api/index.ts +4 -2
- package/src/simple-tree/api/schemaFactoryAlpha.ts +18 -1
- package/src/simple-tree/api/schemaFromSimple.ts +45 -16
- package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +53 -34
- package/src/simple-tree/api/tree.ts +51 -4
- package/src/simple-tree/api/verboseTree.ts +7 -32
- package/src/simple-tree/api/viewSchemaToSimpleSchema.ts +8 -3
- package/src/simple-tree/core/treeNodeKernel.ts +11 -7
- package/src/simple-tree/core/unhydratedFlexTree.ts +17 -4
- package/src/simple-tree/index.ts +4 -2
- package/src/simple-tree/simpleSchema.ts +4 -12
- package/src/tableSchema.ts +609 -0
- package/src/treeFactory.ts +4 -3
- package/src/util/breakable.ts +9 -6
package/dist/util/breakable.js
CHANGED
|
@@ -147,16 +147,18 @@ function isBreaker(f) {
|
|
|
147
147
|
* Methods already marked as {@link breakingMethod} or {@link throwIfBroken} are unaffected.
|
|
148
148
|
*/
|
|
149
149
|
function breakingClass(target, context) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
// Keep track of what keys we have seen
|
|
153
|
-
//
|
|
154
|
-
|
|
150
|
+
// This could extend target, but doing so adds an extra step in the prototype chain and makes the instances just show up as "DecoratedBreakable" in the debugger.
|
|
151
|
+
const DecoratedBreakable = target;
|
|
152
|
+
// Keep track of what keys we have seen (and already wrapped if needed).
|
|
153
|
+
// Used to avoid rewrapping already wrapped properties.
|
|
154
|
+
// Preloaded with "constructor" to avoid wrapping the constructor as there is no need to set the broken flag when the constructor throws and does not return an object.
|
|
155
|
+
// Avoiding wrapping the constructor also avoids messing up the displayed name in the debugger.
|
|
156
|
+
const doNotWrap = new Set(["constructor"]);
|
|
155
157
|
let prototype = target.prototype;
|
|
156
158
|
while (prototype !== null) {
|
|
157
159
|
for (const key of Reflect.ownKeys(prototype)) {
|
|
158
|
-
if (!
|
|
159
|
-
|
|
160
|
+
if (!doNotWrap.has(key)) {
|
|
161
|
+
doNotWrap.add(key);
|
|
160
162
|
const descriptor = Reflect.getOwnPropertyDescriptor(prototype, key);
|
|
161
163
|
if (descriptor !== undefined) {
|
|
162
164
|
// Method
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"breakable.js","sourceRoot":"","sources":["../../src/util/breakable.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,uEAAsE;AAEtE;;GAEG;AACH,MAAa,SAAS;IAGrB,YAAoC,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;IAEpD;;;;OAIG;IACI,GAAG;QACT,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACjC,MAAM,IAAI,qBAAU,CACnB,kBAAkB,IAAI,CAAC,IAAI,+EAA+E,IAAI,CAAC,QAAQ,EAAE,CACzH,CAAC;QACH,CAAC;IACF,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,QAA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;IACxC,wHAAwH;IACxH,MAAM,cAAc,GAAyB,IAAI,GAAG,EAAE,CAAC;IAEvD,IAAI,SAAS,GAAkB,MAAM,CAAC,SAAS,CAAC;IAChD,OAAO,SAAS,KAAK,IAAI,EAAE,CAAC;QAC3B,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC9B,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBACxB,MAAM,UAAU,GAAG,OAAO,CAAC,wBAAwB,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;gBACpE,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;oBAC9B,SAAS;oBACT,IAAI,OAAO,UAAU,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;wBAC5C,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;4BAClC,gKAAgK;4BAChK,UAAU,CAAC,KAAK,GAAG,cAAc,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;4BACpD,MAAM,CAAC,cAAc,CAAC,kBAAkB,CAAC,SAAS,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;wBACtE,CAAC;oBACF,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QACD,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,kBAAkB,CAAC;AAC3B,CAAC;AAhCD,sCAgCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\n/**\n * An object which can enter a \"broken\" state where trying to use it is a UsageError.\n */\nexport class Breakable {\n\tprivate brokenBy?: Error;\n\n\tpublic constructor(private readonly name: string) {}\n\n\t/**\n\t * Throws if the object is in the broken state.\n\t * @remarks\n\t * Can use {@link throwIfBroken} to apply this to a method.\n\t */\n\tpublic use(): void {\n\t\tif (this.brokenBy !== undefined) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Invalid use of ${this.name} after it was put into an invalid state by another error.\\nOriginal Error:\\n${this.brokenBy}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Puts this object into the broken state, and throws an error.\n\t *\n\t * @throws If already broken by a different error, throws a UsageError, otherwise throws `brokenBy`.\n\t */\n\tpublic break(brokenBy: Error): never {\n\t\t// If already broken by this error, let it bubble up without rethrowing a modified version.\n\t\t// This prevents internal errors like asserts getting rethrown as different errors when wrapped with multiple call to `{@link Breakable.run}` or `{@link breakingMethod}`.\n\t\tif (this.brokenBy !== brokenBy) {\n\t\t\tthis.use();\n\t\t\tthis.brokenBy = brokenBy;\n\t\t}\n\t\tthrow brokenBy;\n\t}\n\n\t/**\n\t * {@link Breakable.break}, except tolerates `unknown` to be more easily used by catch blocks.\n\t * @privateRemarks\n\t * If there is a use-case, this should be made public.\n\t */\n\tpublic rethrowCaught(brokenBy: unknown): never {\n\t\tif (brokenBy instanceof Error) {\n\t\t\tthis.break(brokenBy);\n\t\t}\n\t\tthis.break(\n\t\t\tnew Error(`Non-error thrown breaking ${this.name}. Thrown value: \"${brokenBy}\"`),\n\t\t);\n\t}\n\n\t/**\n\t * Runs code which should break the object if it throws.\n\t * @remarks\n\t * This also throws if already broken like {@link Breakable.use}.\n\t * Any exceptions this catches are re-thrown.\n\t * Can use {@link breakingMethod} to apply this to a method.\n\t */\n\tpublic run<TResult>(breaker: () => TResult): TResult {\n\t\tthis.use();\n\t\ttry {\n\t\t\treturn breaker();\n\t\t} catch (error: unknown) {\n\t\t\tthis.rethrowCaught(error);\n\t\t}\n\t}\n\n\t/**\n\t * Clears the existing broken state.\n\t * @remarks\n\t * This is rarely safe to to: it is only ok when all objects using this breaker are known to not have been left in an invalid state.\n\t * This is pretty much only safe in tests which just were checking a specific error was thrown, and which know that error closepath is actually exception safe.\n\t */\n\tpublic clearError(): void {\n\t\tassert(this.brokenBy !== undefined, 0x9b6 /* No error to clear */);\n\t\tthis.brokenBy = undefined;\n\t}\n}\n\n/**\n * Marks an object as being able to be in a broken state (unknown/unspecified/broken state due to unhandled exception).\n * @remarks\n * See decorators {@link breakingMethod} and {@link throwIfBroken} for ease of use.\n */\nexport interface WithBreakable {\n\treadonly breaker: Breakable;\n}\n\n/**\n * Decorator for methods which should break the object when they throw.\n * @remarks\n * This also throws if already broken like {@link throwIfBroken}.\n * See {@link Breakable.run} for details.\n *\n * This should be used on methods which modify data that could result in an unsupported/broken state if an exception is thrown while modifying.\n * It is ok for breakingMethods to call each-other.\n * @privateRemarks\n * Explicitly capturing the full `Target` type is necessary to make this work with generic methods with unknown numbers of type parameters.\n */\nexport function breakingMethod<\n\tTarget extends ((...args: any[]) => unknown) & ((this: This, ...args: Args) => Return),\n\tThis extends WithBreakable,\n\tArgs extends never[],\n\tReturn,\n>(target: Target, context?: ClassMethodDecoratorContext<This, Target>): Target {\n\tfunction replacementMethod(this: This, ...args: Args): Return {\n\t\tif (this.breaker === undefined) {\n\t\t\t// This case is necessary for when wrapping methods which are invoked inside the constructor of the base class before `breaker` is set.\n\t\t\t// Since the constructor throwing does not return an object, failing to put it into a broken state is not too bad.\n\t\t\t// However when more than just the constructed object should be broken, this can result in missing a break.\n\t\t\treturn target.call(this, ...args);\n\t\t}\n\t\treturn this.breaker.run(() => {\n\t\t\treturn target.call(this, ...args);\n\t\t});\n\t}\n\tmarkBreaker(replacementMethod);\n\tnameFunctionFrom(replacementMethod, target);\n\treturn replacementMethod as Target;\n}\n\n/**\n * Decorator for methods which should throw if the object is in a broken state.\n * @remarks\n * This should be used on methods which read data that could be invalid when the object is broken.\n * @privateRemarks\n * Explicitly capturing the full `Target` type is necessary to make this work with generic methods with unknown numbers of type parameters.\n */\nexport function throwIfBroken<\n\tTarget extends ((...args: any[]) => unknown) & ((this: This, ...args: Args) => Return),\n\tThis extends WithBreakable,\n\tArgs extends never[],\n\tReturn,\n>(target: Target, context: ClassMethodDecoratorContext<This, Target>): Target {\n\tfunction replacementMethod(this: This, ...args: Args): Return {\n\t\tthis.breaker.use();\n\t\treturn target.call(this, ...args);\n\t}\n\tmarkBreaker(replacementMethod);\n\tnameFunctionFrom(replacementMethod, target);\n\treturn replacementMethod as Target;\n}\n\n// eslint-disable-next-line @typescript-eslint/ban-types\ntype PossiblyNamedFunction = Function & { displayName?: undefined | string };\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction nameFunctionFrom(toName: Function, nameFrom: Function): void {\n\t(toName as PossiblyNamedFunction).displayName =\n\t\t(nameFrom as PossiblyNamedFunction).displayName ?? nameFrom.name;\n}\n\nconst isBreakerSymbol: unique symbol = Symbol(\"isBreaker\");\n\n// Accepting any function like value is desired and safe here as this does not call the provided function.\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction markBreaker(f: Function): void {\n\t(f as unknown as Record<typeof isBreakerSymbol, true>)[isBreakerSymbol] = true;\n}\n\n// Accepting any function like value is desired and safe here as this does not call the provided function.\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction isBreaker(f: Function): boolean {\n\treturn isBreakerSymbol in (f as unknown as Record<typeof isBreakerSymbol, true>);\n}\n\n/**\n * Decorator for classes which should break when their methods throw.\n * @remarks\n * Applies {@link breakingMethod} to all methods declared directly by class or its base classes.\n * Does not include those on derived classes.\n * Does not include getters or setters, or value properties.\n * Methods already marked as {@link breakingMethod} or {@link throwIfBroken} are unaffected.\n */\nexport function breakingClass<Target extends abstract new (...args: any[]) => WithBreakable>(\n\ttarget: Target,\n\tcontext: ClassDecoratorContext<Target>,\n): Target {\n\tabstract class DecoratedBreakable extends target {}\n\n\t// Keep track of what keys we have seen,\n\t// since we visit most derived properties first and need to avoid wrapping base properties overriding more derived ones.\n\tconst overriddenKeys: Set<string | symbol> = new Set();\n\n\tlet prototype: object | null = target.prototype;\n\twhile (prototype !== null) {\n\t\tfor (const key of Reflect.ownKeys(prototype)) {\n\t\t\tif (!overriddenKeys.has(key)) {\n\t\t\t\toverriddenKeys.add(key);\n\t\t\t\tconst descriptor = Reflect.getOwnPropertyDescriptor(prototype, key);\n\t\t\t\tif (descriptor !== undefined) {\n\t\t\t\t\t// Method\n\t\t\t\t\tif (typeof descriptor.value === \"function\") {\n\t\t\t\t\t\tif (!isBreaker(descriptor.value)) {\n\t\t\t\t\t\t\t// This does not affect the original class, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor\n\t\t\t\t\t\t\tdescriptor.value = breakingMethod(descriptor.value);\n\t\t\t\t\t\t\tObject.defineProperty(DecoratedBreakable.prototype, key, descriptor);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tprototype = Reflect.getPrototypeOf(prototype);\n\t}\n\n\treturn DecoratedBreakable;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"breakable.js","sourceRoot":"","sources":["../../src/util/breakable.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,uEAAsE;AAEtE;;GAEG;AACH,MAAa,SAAS;IAGrB,YAAoC,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;IAEpD;;;;OAIG;IACI,GAAG;QACT,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACjC,MAAM,IAAI,qBAAU,CACnB,kBAAkB,IAAI,CAAC,IAAI,+EAA+E,IAAI,CAAC,QAAQ,EAAE,CACzH,CAAC;QACH,CAAC;IACF,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,QAAe;QAC3B,2FAA2F;QAC3F,0KAA0K;QAC1K,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAChC,IAAI,CAAC,GAAG,EAAE,CAAC;YACX,IAAI,CAAC,QAAQ,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AAkB,MAAM,CAAC,SAAS,CAAC;IAChD,OAAO,SAAS,KAAK,IAAI,EAAE,CAAC;QAC3B,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzB,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBACnB,MAAM,UAAU,GAAG,OAAO,CAAC,wBAAwB,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;gBACpE,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;oBAC9B,SAAS;oBACT,IAAI,OAAO,UAAU,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;wBAC5C,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;4BAClC,gKAAgK;4BAChK,UAAU,CAAC,KAAK,GAAG,cAAc,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;4BACpD,MAAM,CAAC,cAAc,CAAC,kBAAkB,CAAC,SAAS,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;wBACtE,CAAC;oBACF,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QACD,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,kBAAkB,CAAC;AAC3B,CAAC;AAnCD,sCAmCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\n/**\n * An object which can enter a \"broken\" state where trying to use it is a UsageError.\n */\nexport class Breakable {\n\tprivate brokenBy?: Error;\n\n\tpublic constructor(private readonly name: string) {}\n\n\t/**\n\t * Throws if the object is in the broken state.\n\t * @remarks\n\t * Can use {@link throwIfBroken} to apply this to a method.\n\t */\n\tpublic use(): void {\n\t\tif (this.brokenBy !== undefined) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Invalid use of ${this.name} after it was put into an invalid state by another error.\\nOriginal Error:\\n${this.brokenBy}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Puts this object into the broken state, and throws an error.\n\t *\n\t * @throws If already broken by a different error, throws a UsageError, otherwise throws `brokenBy`.\n\t */\n\tpublic break(brokenBy: Error): never {\n\t\t// If already broken by this error, let it bubble up without rethrowing a modified version.\n\t\t// This prevents internal errors like asserts getting rethrown as different errors when wrapped with multiple call to `{@link Breakable.run}` or `{@link breakingMethod}`.\n\t\tif (this.brokenBy !== brokenBy) {\n\t\t\tthis.use();\n\t\t\tthis.brokenBy = brokenBy;\n\t\t}\n\t\tthrow brokenBy;\n\t}\n\n\t/**\n\t * {@link Breakable.break}, except tolerates `unknown` to be more easily used by catch blocks.\n\t * @privateRemarks\n\t * If there is a use-case, this should be made public.\n\t */\n\tpublic rethrowCaught(brokenBy: unknown): never {\n\t\tif (brokenBy instanceof Error) {\n\t\t\tthis.break(brokenBy);\n\t\t}\n\t\tthis.break(\n\t\t\tnew Error(`Non-error thrown breaking ${this.name}. Thrown value: \"${brokenBy}\"`),\n\t\t);\n\t}\n\n\t/**\n\t * Runs code which should break the object if it throws.\n\t * @remarks\n\t * This also throws if already broken like {@link Breakable.use}.\n\t * Any exceptions this catches are re-thrown.\n\t * Can use {@link breakingMethod} to apply this to a method.\n\t */\n\tpublic run<TResult>(breaker: () => TResult): TResult {\n\t\tthis.use();\n\t\ttry {\n\t\t\treturn breaker();\n\t\t} catch (error: unknown) {\n\t\t\tthis.rethrowCaught(error);\n\t\t}\n\t}\n\n\t/**\n\t * Clears the existing broken state.\n\t * @remarks\n\t * This is rarely safe to to: it is only ok when all objects using this breaker are known to not have been left in an invalid state.\n\t * This is pretty much only safe in tests which just were checking a specific error was thrown, and which know that error closepath is actually exception safe.\n\t */\n\tpublic clearError(): void {\n\t\tassert(this.brokenBy !== undefined, 0x9b6 /* No error to clear */);\n\t\tthis.brokenBy = undefined;\n\t}\n}\n\n/**\n * Marks an object as being able to be in a broken state (unknown/unspecified/broken state due to unhandled exception).\n * @remarks\n * See decorators {@link breakingMethod} and {@link throwIfBroken} for ease of use.\n */\nexport interface WithBreakable {\n\treadonly breaker: Breakable;\n}\n\n/**\n * Decorator for methods which should break the object when they throw.\n * @remarks\n * This also throws if already broken like {@link throwIfBroken}.\n * See {@link Breakable.run} for details.\n *\n * This should be used on methods which modify data that could result in an unsupported/broken state if an exception is thrown while modifying.\n * It is ok for breakingMethods to call each-other.\n * @privateRemarks\n * Explicitly capturing the full `Target` type is necessary to make this work with generic methods with unknown numbers of type parameters.\n */\nexport function breakingMethod<\n\tTarget extends ((...args: any[]) => unknown) & ((this: This, ...args: Args) => Return),\n\tThis extends WithBreakable,\n\tArgs extends never[],\n\tReturn,\n>(target: Target, context?: ClassMethodDecoratorContext<This, Target>): Target {\n\tfunction replacementMethod(this: This, ...args: Args): Return {\n\t\tif (this.breaker === undefined) {\n\t\t\t// This case is necessary for when wrapping methods which are invoked inside the constructor of the base class before `breaker` is set.\n\t\t\t// Since the constructor throwing does not return an object, failing to put it into a broken state is not too bad.\n\t\t\t// However when more than just the constructed object should be broken, this can result in missing a break.\n\t\t\treturn target.call(this, ...args);\n\t\t}\n\t\treturn this.breaker.run(() => {\n\t\t\treturn target.call(this, ...args);\n\t\t});\n\t}\n\tmarkBreaker(replacementMethod);\n\tnameFunctionFrom(replacementMethod, target);\n\treturn replacementMethod as Target;\n}\n\n/**\n * Decorator for methods which should throw if the object is in a broken state.\n * @remarks\n * This should be used on methods which read data that could be invalid when the object is broken.\n * @privateRemarks\n * Explicitly capturing the full `Target` type is necessary to make this work with generic methods with unknown numbers of type parameters.\n */\nexport function throwIfBroken<\n\tTarget extends ((...args: any[]) => unknown) & ((this: This, ...args: Args) => Return),\n\tThis extends WithBreakable,\n\tArgs extends never[],\n\tReturn,\n>(target: Target, context: ClassMethodDecoratorContext<This, Target>): Target {\n\tfunction replacementMethod(this: This, ...args: Args): Return {\n\t\tthis.breaker.use();\n\t\treturn target.call(this, ...args);\n\t}\n\tmarkBreaker(replacementMethod);\n\tnameFunctionFrom(replacementMethod, target);\n\treturn replacementMethod as Target;\n}\n\n// eslint-disable-next-line @typescript-eslint/ban-types\ntype PossiblyNamedFunction = Function & { displayName?: undefined | string };\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction nameFunctionFrom(toName: Function, nameFrom: Function): void {\n\t(toName as PossiblyNamedFunction).displayName =\n\t\t(nameFrom as PossiblyNamedFunction).displayName ?? nameFrom.name;\n}\n\nconst isBreakerSymbol: unique symbol = Symbol(\"isBreaker\");\n\n// Accepting any function like value is desired and safe here as this does not call the provided function.\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction markBreaker(f: Function): void {\n\t(f as unknown as Record<typeof isBreakerSymbol, true>)[isBreakerSymbol] = true;\n}\n\n// Accepting any function like value is desired and safe here as this does not call the provided function.\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction isBreaker(f: Function): boolean {\n\treturn isBreakerSymbol in (f as unknown as Record<typeof isBreakerSymbol, true>);\n}\n\n/**\n * Decorator for classes which should break when their methods throw.\n * @remarks\n * Applies {@link breakingMethod} to all methods declared directly by class or its base classes.\n * Does not include those on derived classes.\n * Does not include getters or setters, or value properties.\n * Methods already marked as {@link breakingMethod} or {@link throwIfBroken} are unaffected.\n */\nexport function breakingClass<Target extends abstract new (...args: any[]) => WithBreakable>(\n\ttarget: Target,\n\tcontext: ClassDecoratorContext<Target>,\n): Target {\n\t// This could extend target, but doing so adds an extra step in the prototype chain and makes the instances just show up as \"DecoratedBreakable\" in the debugger.\n\tconst DecoratedBreakable = target;\n\n\t// Keep track of what keys we have seen (and already wrapped if needed).\n\t// Used to avoid rewrapping already wrapped properties.\n\t// Preloaded with \"constructor\" to avoid wrapping the constructor as there is no need to set the broken flag when the constructor throws and does not return an object.\n\t// Avoiding wrapping the constructor also avoids messing up the displayed name in the debugger.\n\tconst doNotWrap: Set<string | symbol> = new Set([\"constructor\"]);\n\n\tlet prototype: object | null = target.prototype;\n\twhile (prototype !== null) {\n\t\tfor (const key of Reflect.ownKeys(prototype)) {\n\t\t\tif (!doNotWrap.has(key)) {\n\t\t\t\tdoNotWrap.add(key);\n\t\t\t\tconst descriptor = Reflect.getOwnPropertyDescriptor(prototype, key);\n\t\t\t\tif (descriptor !== undefined) {\n\t\t\t\t\t// Method\n\t\t\t\t\tif (typeof descriptor.value === \"function\") {\n\t\t\t\t\t\tif (!isBreaker(descriptor.value)) {\n\t\t\t\t\t\t\t// This does not affect the original class, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor\n\t\t\t\t\t\t\tdescriptor.value = breakingMethod(descriptor.value);\n\t\t\t\t\t\t\tObject.defineProperty(DecoratedBreakable.prototype, key, descriptor);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tprototype = Reflect.getPrototypeOf(prototype);\n\t}\n\n\treturn DecoratedBreakable;\n}\n"]}
|
package/lib/alpha.d.ts
CHANGED
|
@@ -107,7 +107,6 @@ export {
|
|
|
107
107
|
ArrayNodeSchema,
|
|
108
108
|
BranchableTree,
|
|
109
109
|
ConciseTree,
|
|
110
|
-
EncodeOptions,
|
|
111
110
|
FactoryContent,
|
|
112
111
|
FactoryContentObject,
|
|
113
112
|
FieldSchemaAlpha,
|
|
@@ -121,6 +120,7 @@ export {
|
|
|
121
120
|
ForestTypeReference,
|
|
122
121
|
HandleConverter,
|
|
123
122
|
ICodecOptions,
|
|
123
|
+
ITreeAlpha,
|
|
124
124
|
IdentifierIndex,
|
|
125
125
|
Insertable,
|
|
126
126
|
InsertableContent,
|
|
@@ -148,7 +148,6 @@ export {
|
|
|
148
148
|
MapNodePojoEmulationSchema,
|
|
149
149
|
MapNodeSchema,
|
|
150
150
|
ObjectNodeSchema,
|
|
151
|
-
ParseOptions,
|
|
152
151
|
PopUnion,
|
|
153
152
|
ReadSchema,
|
|
154
153
|
ReadableField,
|
|
@@ -180,10 +179,14 @@ export {
|
|
|
180
179
|
TreeBranchEvents,
|
|
181
180
|
TreeBranchFork,
|
|
182
181
|
TreeCompressionStrategy,
|
|
182
|
+
TreeEncodingOptions,
|
|
183
183
|
TreeIndex,
|
|
184
184
|
TreeIndexKey,
|
|
185
185
|
TreeIndexNodes,
|
|
186
|
+
TreeSchema,
|
|
187
|
+
TreeSchemaEncodingOptions,
|
|
186
188
|
TreeViewAlpha,
|
|
189
|
+
TreeViewConfigurationAlpha,
|
|
187
190
|
UnionToTuple,
|
|
188
191
|
UnsafeUnknownSchema,
|
|
189
192
|
ValueSchema,
|
|
@@ -203,6 +206,7 @@ export {
|
|
|
203
206
|
generateSchemaFromSimpleSchema,
|
|
204
207
|
getBranch,
|
|
205
208
|
getJsonSchema,
|
|
209
|
+
getSimpleSchema,
|
|
206
210
|
independentInitializedView,
|
|
207
211
|
independentView,
|
|
208
212
|
noopValidator,
|
|
@@ -7,7 +7,7 @@ import type { Listenable } from "@fluidframework/core-interfaces";
|
|
|
7
7
|
import { type IDisposable, disposeSymbol } from "../../util/index.js";
|
|
8
8
|
import type { NodeIdentifierManager } from "../node-identifier/index.js";
|
|
9
9
|
import type { FlexTreeField } from "./flexTreeTypes.js";
|
|
10
|
-
import {
|
|
10
|
+
import type { LazyEntity } from "./lazyEntity.js";
|
|
11
11
|
import type { ITreeCheckout } from "../../shared-tree/index.js";
|
|
12
12
|
/**
|
|
13
13
|
* Context for FlexTrees.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/flex-tree/context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EAGrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK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IAE/C;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;CACjC;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,mDAAwB,CAAC;AAEjD;;;;GAIG;AACH,qBAAa,OAAQ,YAAW,uBAAuB,EAAE,WAAW;aAalD,YAAY,EAAE,YAAY;aAC1B,QAAQ,EAAE,aAAa;aACvB,cAAc,EAAE,qBAAqB;IAdtD,SAAgB,WAAW,EAAE,GAAG,CAAC,UAAU,CAAC,CAAa;IACzD,SAAgB,WAAW,EAAE,GAAG,CAAC,UAAU,CAAC,CAAa;IAEzD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAiB;IACjD,OAAO,CAAC,QAAQ,CAAS;IAEzB;;;;OAIG;gBAEc,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,aAAa,EACvB,cAAc,EAAE,qBAAqB;IAe/C,UAAU,IAAI,IAAI,IAAI,uBAAuB;IAIpD,IAAW,MAAM,IAAI,gBAAgB,CAEpC;IAED;;;OAGG;IACH,OAAO,CAAC,cAAc;IAQf,CAAC,aAAa,CAAC,IAAI,IAAI;IAa9B;;;;;OAKG;IACI,KAAK,IAAI,IAAI;IAQpB,IAAW,IAAI,IAAI,aAAa,CAO/B;IAED,IAAW,MAAM,IAAI,UAAU,CAAC,YAAY,CAAC,CAE5C;CACD;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC7B,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,aAAa,EACvB,cAAc,EAAE,qBAAqB,GACnC,OAAO,CAET"}
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
import { assert } from "@fluidframework/core-utils/internal";
|
|
6
6
|
import { anchorSlot, moveToDetachedField, } from "../../core/index.js";
|
|
7
7
|
import { disposeSymbol } from "../../util/index.js";
|
|
8
|
-
import { prepareForEditSymbol } from "./lazyEntity.js";
|
|
9
8
|
import { makeField } from "./lazyField.js";
|
|
10
9
|
/**
|
|
11
10
|
* Creating multiple flex tree contexts for the same branch, and thus with the same underlying AnchorSet does not work due to how TreeNode caching works.
|
|
@@ -51,7 +50,7 @@ export class Context {
|
|
|
51
50
|
prepareForEdit() {
|
|
52
51
|
assert(this.disposed === false, 0x802 /* use after dispose */);
|
|
53
52
|
for (const target of this.withCursors) {
|
|
54
|
-
target
|
|
53
|
+
target.prepareForEdit();
|
|
55
54
|
}
|
|
56
55
|
assert(this.withCursors.size === 0, 0x773 /* prepareForEdit should remove all cursors */);
|
|
57
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/feature-libraries/flex-tree/context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EAIN,UAAU,EACV,mBAAmB,GACnB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAoB,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/feature-libraries/flex-tree/context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EAIN,UAAU,EACV,mBAAmB,GACnB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAoB,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKtE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA8C3C;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,EAAW,CAAC;AAEjD;;;;GAIG;AACH,MAAM,OAAO,OAAO;IAOnB;;;;OAIG;IACH,YACiB,YAA0B,EAC1B,QAAuB,EACvB,cAAqC;QAFrC,iBAAY,GAAZ,YAAY,CAAc;QAC1B,aAAQ,GAAR,QAAQ,CAAe;QACvB,mBAAc,GAAd,cAAc,CAAuB;QAdtC,gBAAW,GAAoB,IAAI,GAAG,EAAE,C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cAAc,CAC7B,MAAoB,EACpB,QAAuB,EACvB,cAAqC;IAErC,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;AACtD,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\ttype ForestEvents,\n\ttype SchemaPolicy,\n\ttype TreeStoredSchema,\n\tanchorSlot,\n\tmoveToDetachedField,\n} from \"../../core/index.js\";\nimport type { Listenable } from \"@fluidframework/core-interfaces\";\nimport { type IDisposable, disposeSymbol } from \"../../util/index.js\";\nimport type { NodeIdentifierManager } from \"../node-identifier/index.js\";\n\nimport type { FlexTreeField } from \"./flexTreeTypes.js\";\nimport type { LazyEntity } from \"./lazyEntity.js\";\nimport { makeField } from \"./lazyField.js\";\nimport type { ITreeCheckout } from \"../../shared-tree/index.js\";\n\n/**\n * Context for FlexTrees.\n */\nexport interface FlexTreeContext {\n\t/**\n\t * Schema used within this context.\n\t * All data must conform to these schema.\n\t */\n\treadonly schema: TreeStoredSchema;\n\n\t/**\n\t * SchemaPolicy used within this context.\n\t */\n\treadonly schemaPolicy: SchemaPolicy;\n\n\t/**\n\t * If true, this context is the canonical context instance for a given view,\n\t * and its schema include all schema from the document.\n\t *\n\t * If false, this context was created for use in a unhydrated tree, and the full document schema is unknown.\n\t */\n\tisHydrated(): this is FlexTreeHydratedContext;\n}\n\n/**\n * A common context of a \"forest\" of FlexTrees.\n * It handles group operations like transforming cursors into anchors for edits.\n */\nexport interface FlexTreeHydratedContext extends FlexTreeContext {\n\treadonly events: Listenable<ForestEvents>;\n\t/**\n\t * Gets the root field of the tree.\n\t */\n\tget root(): FlexTreeField;\n\n\treadonly nodeKeyManager: NodeIdentifierManager;\n\n\t/**\n\t * The checkout object associated with this context.\n\t */\n\treadonly checkout: ITreeCheckout;\n}\n\n/**\n * Creating multiple flex tree contexts for the same branch, and thus with the same underlying AnchorSet does not work due to how TreeNode caching works.\n * This slot is used to detect if one already exists and error if creating a second.\n */\nexport const ContextSlot = anchorSlot<Context>();\n\n/**\n * Implementation of `FlexTreeContext`.\n *\n * @remarks An editor is required to edit the FlexTree.\n */\nexport class Context implements FlexTreeHydratedContext, IDisposable {\n\tpublic readonly withCursors: Set<LazyEntity> = new Set();\n\tpublic readonly withAnchors: Set<LazyEntity> = new Set();\n\n\tprivate readonly eventUnregister: (() => void)[];\n\tprivate disposed = false;\n\n\t/**\n\t * @param flexSchema - Schema to use when working with the tree.\n\t * @param checkout - The checkout.\n\t * @param nodeKeyManager - An object which handles node key generation and conversion\n\t */\n\tpublic constructor(\n\t\tpublic readonly schemaPolicy: SchemaPolicy,\n\t\tpublic readonly checkout: ITreeCheckout,\n\t\tpublic readonly nodeKeyManager: NodeIdentifierManager,\n\t) {\n\t\tthis.eventUnregister = [\n\t\t\tthis.checkout.forest.events.on(\"beforeChange\", () => {\n\t\t\t\tthis.prepareForEdit();\n\t\t\t}),\n\t\t];\n\n\t\tassert(\n\t\t\t!this.checkout.forest.anchors.slots.has(ContextSlot),\n\t\t\t0x92b /* Cannot create second flex-tree from checkout */,\n\t\t);\n\t\tthis.checkout.forest.anchors.slots.set(ContextSlot, this);\n\t}\n\n\tpublic isHydrated(): this is FlexTreeHydratedContext {\n\t\treturn true;\n\t}\n\n\tpublic get schema(): TreeStoredSchema {\n\t\treturn this.checkout.storedSchema;\n\t}\n\n\t/**\n\t * Called before editing.\n\t * Clears all cursors so editing can proceed.\n\t */\n\tprivate prepareForEdit(): void {\n\t\tassert(this.disposed === false, 0x802 /* use after dispose */);\n\t\tfor (const target of this.withCursors) {\n\t\t\ttarget.prepareForEdit();\n\t\t}\n\t\tassert(this.withCursors.size === 0, 0x773 /* prepareForEdit should remove all cursors */);\n\t}\n\n\tpublic [disposeSymbol](): void {\n\t\tassert(this.disposed === false, 0x803 /* double dispose */);\n\t\tthis.disposed = true;\n\t\tthis.clear();\n\t\tfor (const unregister of this.eventUnregister) {\n\t\t\tunregister();\n\t\t}\n\t\tthis.eventUnregister.length = 0;\n\n\t\tconst deleted = this.checkout.forest.anchors.slots.delete(ContextSlot);\n\t\tassert(deleted, 0x8c4 /* unexpected dispose */);\n\t}\n\n\t/**\n\t * Release any cursors and anchors held by tree entities created in this context.\n\t * Ensures the cashed references to those entities on the Anchors are also cleared.\n\t * The tree entities are invalid to use after this, but the context may still be used\n\t * to create new trees starting from the root.\n\t */\n\tpublic clear(): void {\n\t\tfor (const target of this.withAnchors) {\n\t\t\ttarget[disposeSymbol]();\n\t\t}\n\t\tassert(this.withCursors.size === 0, 0x774 /* free should remove all cursors */);\n\t\tassert(this.withAnchors.size === 0, 0x775 /* free should remove all anchors */);\n\t}\n\n\tpublic get root(): FlexTreeField {\n\t\tassert(this.disposed === false, 0x804 /* use after dispose */);\n\t\tconst cursor = this.checkout.forest.allocateCursor(\"root\");\n\t\tmoveToDetachedField(this.checkout.forest, cursor);\n\t\tconst field = makeField(this, this.schema.rootFieldSchema.kind, cursor);\n\t\tcursor.free();\n\t\treturn field;\n\t}\n\n\tpublic get events(): Listenable<ForestEvents> {\n\t\treturn this.checkout.forest.events;\n\t}\n}\n\n/**\n * A simple API for a Forest to interact with the tree.\n *\n * @param forest - the Forest\n * @param editor - an editor that makes changes to the forest.\n * @param nodeKeyManager - an object which handles node key generation and conversion.\n * @returns {@link FlexTreeContext} which is used to manage the cursors and anchors within the FlexTrees:\n * This is necessary for supporting using this tree across edits to the forest, and not leaking memory.\n */\nexport function getTreeContext(\n\tschema: SchemaPolicy,\n\tcheckout: ITreeCheckout,\n\tnodeKeyManager: NodeIdentifierManager,\n): Context {\n\treturn new Context(schema, checkout, nodeKeyManager);\n}\n"]}
|
|
@@ -6,7 +6,7 @@ export { type FlexTreeField, type FlexTreeNode, type FlexTreeEntity, type FlexTr
|
|
|
6
6
|
export { visitBipartiteIterableTree, Skip, visitBipartiteIterableTreeWithState, visitIterableTree, visitIterableTreeWithState, } from "./navigation.js";
|
|
7
7
|
export { getTreeContext, type FlexTreeContext, type FlexTreeHydratedContext, Context, ContextSlot, } from "./context.js";
|
|
8
8
|
export { type FlexTreeNodeEvents } from "./treeEvents.js";
|
|
9
|
-
export { assertFlexTreeEntityNotFreed,
|
|
9
|
+
export { assertFlexTreeEntityNotFreed, LazyEntity, } from "./lazyEntity.js";
|
|
10
10
|
export { getSchemaAndPolicy, indexForAt } from "./utilities.js";
|
|
11
11
|
export { treeStatusFromAnchorCache } from "./utilities.js";
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/flex-tree/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,UAAU,EACV,KAAK,sBAAsB,EAC3B,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,YAAY,GACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACN,0BAA0B,EAC1B,IAAI,EACJ,mCAAmC,EACnC,iBAAiB,EACjB,0BAA0B,GAC1B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,OAAO,EACP,WAAW,GACX,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EACN,4BAA4B,EAC5B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/flex-tree/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,UAAU,EACV,KAAK,sBAAsB,EAC3B,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,YAAY,GACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACN,0BAA0B,EAC1B,IAAI,EACJ,mCAAmC,EACnC,iBAAiB,EACjB,0BAA0B,GAC1B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,OAAO,EACP,WAAW,GACX,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EACN,4BAA4B,EAC5B,UAAU,GACV,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
export { TreeStatus, flexTreeMarker, FlexTreeEntityKind, isFlexTreeNode, flexTreeSlot, } from "./flexTreeTypes.js";
|
|
6
6
|
export { visitBipartiteIterableTree, Skip, visitBipartiteIterableTreeWithState, visitIterableTree, visitIterableTreeWithState, } from "./navigation.js";
|
|
7
7
|
export { getTreeContext, Context, ContextSlot, } from "./context.js";
|
|
8
|
-
export { assertFlexTreeEntityNotFreed,
|
|
8
|
+
export { assertFlexTreeEntityNotFreed, LazyEntity, } from "./lazyEntity.js";
|
|
9
9
|
export { getSchemaAndPolicy, indexForAt } from "./utilities.js";
|
|
10
10
|
export { treeStatusFromAnchorCache } from "./utilities.js";
|
|
11
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/feature-libraries/flex-tree/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAQN,UAAU,EAEV,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,YAAY,GACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACN,0BAA0B,EAC1B,IAAI,EACJ,mCAAmC,EACnC,iBAAiB,EACjB,0BAA0B,GAC1B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,cAAc,EAGd,OAAO,EACP,WAAW,GACX,MAAM,cAAc,CAAC;AAItB,OAAO,EACN,4BAA4B,EAC5B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/feature-libraries/flex-tree/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAQN,UAAU,EAEV,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,YAAY,GACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACN,0BAA0B,EAC1B,IAAI,EACJ,mCAAmC,EACnC,iBAAiB,EACjB,0BAA0B,GAC1B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,cAAc,EAGd,OAAO,EACP,WAAW,GACX,MAAM,cAAc,CAAC;AAItB,OAAO,EACN,4BAA4B,EAC5B,UAAU,GACV,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\ttype FlexTreeField,\n\ttype FlexTreeNode,\n\ttype FlexTreeEntity,\n\ttype FlexTreeTypedField,\n\ttype FlexTreeOptionalField,\n\ttype FlexTreeRequiredField,\n\ttype FlexTreeSequenceField,\n\tTreeStatus,\n\ttype FlexTreeUnknownUnboxed,\n\tflexTreeMarker,\n\tFlexTreeEntityKind,\n\tisFlexTreeNode,\n\tflexTreeSlot,\n} from \"./flexTreeTypes.js\";\n\nexport {\n\tvisitBipartiteIterableTree,\n\tSkip,\n\tvisitBipartiteIterableTreeWithState,\n\tvisitIterableTree,\n\tvisitIterableTreeWithState,\n} from \"./navigation.js\";\n\nexport {\n\tgetTreeContext,\n\ttype FlexTreeContext,\n\ttype FlexTreeHydratedContext,\n\tContext,\n\tContextSlot,\n} from \"./context.js\";\n\nexport { type FlexTreeNodeEvents } from \"./treeEvents.js\";\n\nexport {\n\tassertFlexTreeEntityNotFreed,\n\tLazyEntity,\n} from \"./lazyEntity.js\";\n\nexport { getSchemaAndPolicy, indexForAt } from \"./utilities.js\";\n\nexport { treeStatusFromAnchorCache } from \"./utilities.js\";\n"]}
|
|
@@ -6,15 +6,6 @@ import { type ITreeSubscriptionCursor, TreeNavigationResult } from "../../core/i
|
|
|
6
6
|
import { type IDisposable, disposeSymbol } from "../../util/index.js";
|
|
7
7
|
import type { Context } from "./context.js";
|
|
8
8
|
import { type FlexTreeEntity, type FlexTreeEntityKind, flexTreeMarker } from "./flexTreeTypes.js";
|
|
9
|
-
export declare const prepareForEditSymbol: unique symbol;
|
|
10
|
-
export declare const isFreedSymbol: unique symbol;
|
|
11
|
-
export declare const tryMoveCursorToAnchorSymbol: unique symbol;
|
|
12
|
-
export declare const forgetAnchorSymbol: unique symbol;
|
|
13
|
-
export declare const cursorSymbol: unique symbol;
|
|
14
|
-
/**
|
|
15
|
-
* Symbol used to access the (generic) anchor of a {@link LazyEntity}.
|
|
16
|
-
*/
|
|
17
|
-
export declare const anchorSymbol: unique symbol;
|
|
18
9
|
/**
|
|
19
10
|
* Assert `entity` is not deleted.
|
|
20
11
|
* @privateRemarks
|
|
@@ -28,18 +19,18 @@ export declare function assertFlexTreeEntityNotFreed(entity: FlexTreeEntity): vo
|
|
|
28
19
|
export declare abstract class LazyEntity<TAnchor = unknown> implements FlexTreeEntity, IDisposable {
|
|
29
20
|
#private;
|
|
30
21
|
readonly context: Context;
|
|
31
|
-
readonly
|
|
22
|
+
readonly anchor: TAnchor;
|
|
32
23
|
protected constructor(context: Context, cursor: ITreeSubscriptionCursor, anchor: TAnchor);
|
|
33
24
|
abstract boxedIterator(): IterableIterator<FlexTreeEntity>;
|
|
34
25
|
abstract get [flexTreeMarker](): FlexTreeEntityKind;
|
|
35
26
|
[disposeSymbol](): void;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
get
|
|
39
|
-
protected abstract
|
|
27
|
+
prepareForEdit(): void;
|
|
28
|
+
isFreed(): boolean;
|
|
29
|
+
get cursor(): ITreeSubscriptionCursor;
|
|
30
|
+
protected abstract tryMoveCursorToAnchor(cursor: ITreeSubscriptionCursor): TreeNavigationResult;
|
|
40
31
|
/**
|
|
41
32
|
* Called when disposing of this target, iff it has an anchor.
|
|
42
33
|
*/
|
|
43
|
-
protected abstract
|
|
34
|
+
protected abstract forgetAnchor(): void;
|
|
44
35
|
}
|
|
45
36
|
//# sourceMappingURL=lazyEntity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazyEntity.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/flex-tree/lazyEntity.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,KAAK,uBAAuB,EAE5B,oBAAoB,EACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,KAAK,WAAW,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEtE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,cAAc,EACd,MAAM,oBAAoB,CAAC;AAE5B
|
|
1
|
+
{"version":3,"file":"lazyEntity.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/flex-tree/lazyEntity.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,KAAK,uBAAuB,EAE5B,oBAAoB,EACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,KAAK,WAAW,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEtE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,cAAc,EACd,MAAM,oBAAoB,CAAC;AAE5B;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAGzE;AAED;;GAEG;AACH,8BAAsB,UAAU,CAAC,OAAO,GAAG,OAAO,CAAE,YAAW,cAAc,EAAE,WAAW;;aAKxE,OAAO,EAAE,OAAO;IAHjC,SAAgB,MAAM,EAAE,OAAO,CAAC;IAEhC,SAAS,aACQ,OAAO,EAAE,OAAO,EAChC,MAAM,EAAE,uBAAuB,EAC/B,MAAM,EAAE,OAAO;aAQA,aAAa,IAAI,gBAAgB,CAAC,cAAc,CAAC;IACjE,aAAoB,CAAC,cAAc,CAAC,IAAI,kBAAkB,CAAC;IAEpD,CAAC,aAAa,CAAC,IAAI,IAAI;IAOvB,cAAc,IAAI,IAAI;IAKtB,OAAO,IAAI,OAAO;IAIzB,IAAW,MAAM,IAAI,uBAAuB,CAkB3C;IAED,SAAS,CAAC,QAAQ,CAAC,qBAAqB,CACvC,MAAM,EAAE,uBAAuB,GAC7B,oBAAoB;IAEvB;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,YAAY,IAAI,IAAI;CACvC"}
|
|
@@ -18,15 +18,6 @@ import { assert } from "@fluidframework/core-utils/internal";
|
|
|
18
18
|
import { ITreeSubscriptionCursorState, } from "../../core/index.js";
|
|
19
19
|
import { disposeSymbol } from "../../util/index.js";
|
|
20
20
|
import { flexTreeMarker, } from "./flexTreeTypes.js";
|
|
21
|
-
export const prepareForEditSymbol = Symbol("prepareForEdit");
|
|
22
|
-
export const isFreedSymbol = Symbol("isFreed");
|
|
23
|
-
export const tryMoveCursorToAnchorSymbol = Symbol("tryMoveCursorToAnchor");
|
|
24
|
-
export const forgetAnchorSymbol = Symbol("forgetAnchor");
|
|
25
|
-
export const cursorSymbol = Symbol("cursor");
|
|
26
|
-
/**
|
|
27
|
-
* Symbol used to access the (generic) anchor of a {@link LazyEntity}.
|
|
28
|
-
*/
|
|
29
|
-
export const anchorSymbol = Symbol("anchor");
|
|
30
21
|
/**
|
|
31
22
|
* Assert `entity` is not deleted.
|
|
32
23
|
* @privateRemarks
|
|
@@ -35,7 +26,7 @@ export const anchorSymbol = Symbol("anchor");
|
|
|
35
26
|
*/
|
|
36
27
|
export function assertFlexTreeEntityNotFreed(entity) {
|
|
37
28
|
assert(entity instanceof LazyEntity, 0x8c9 /* unexpected implementation */);
|
|
38
|
-
assert(!entity
|
|
29
|
+
assert(!entity.isFreed(), 0x8ca /* Use after free */);
|
|
39
30
|
}
|
|
40
31
|
/**
|
|
41
32
|
* This is a base class for lazy (cursor based) UntypedEntity implementations, which uniformly handles cursors and anchors.
|
|
@@ -44,7 +35,7 @@ export class LazyEntity {
|
|
|
44
35
|
constructor(context, cursor, anchor) {
|
|
45
36
|
this.context = context;
|
|
46
37
|
_LazyEntity_lazyCursor.set(this, void 0);
|
|
47
|
-
this
|
|
38
|
+
this.anchor = anchor;
|
|
48
39
|
__classPrivateFieldSet(this, _LazyEntity_lazyCursor, cursor.fork("LazyEntity Fork"), "f");
|
|
49
40
|
context.withCursors.add(this);
|
|
50
41
|
this.context.withAnchors.add(this);
|
|
@@ -52,21 +43,21 @@ export class LazyEntity {
|
|
|
52
43
|
[(_LazyEntity_lazyCursor = new WeakMap(), disposeSymbol)]() {
|
|
53
44
|
__classPrivateFieldGet(this, _LazyEntity_lazyCursor, "f").free();
|
|
54
45
|
this.context.withCursors.delete(this);
|
|
55
|
-
this
|
|
46
|
+
this.forgetAnchor();
|
|
56
47
|
this.context.withAnchors.delete(this);
|
|
57
48
|
}
|
|
58
|
-
|
|
49
|
+
prepareForEdit() {
|
|
59
50
|
__classPrivateFieldGet(this, _LazyEntity_lazyCursor, "f").clear();
|
|
60
51
|
this.context.withCursors.delete(this);
|
|
61
52
|
}
|
|
62
|
-
|
|
53
|
+
isFreed() {
|
|
63
54
|
return __classPrivateFieldGet(this, _LazyEntity_lazyCursor, "f").state === ITreeSubscriptionCursorState.Freed;
|
|
64
55
|
}
|
|
65
|
-
get
|
|
56
|
+
get cursor() {
|
|
66
57
|
if (__classPrivateFieldGet(this, _LazyEntity_lazyCursor, "f").state !== ITreeSubscriptionCursorState.Current) {
|
|
67
58
|
assert(__classPrivateFieldGet(this, _LazyEntity_lazyCursor, "f").state === ITreeSubscriptionCursorState.Cleared, 0x778 /* Unset cursor should be in cleared state */);
|
|
68
|
-
assert(this
|
|
69
|
-
const result = this
|
|
59
|
+
assert(this.anchor !== undefined, 0x779 /* FlexTree should have an anchor if it does not have a cursor */);
|
|
60
|
+
const result = this.tryMoveCursorToAnchor(__classPrivateFieldGet(this, _LazyEntity_lazyCursor, "f"));
|
|
70
61
|
assert(result === 1 /* TreeNavigationResult.Ok */, 0x77a /* It is invalid to access a FlexTree node which no longer exists */);
|
|
71
62
|
this.context.withCursors.add(this);
|
|
72
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazyEntity.js","sourceRoot":"","sources":["../../../src/feature-libraries/flex-tree/lazyEntity.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EAEN,4BAA4B,GAE5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAoB,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGtE,OAAO,EAGN,cAAc,GACd,MAAM,oBAAoB,CAAC;AAE5B
|
|
1
|
+
{"version":3,"file":"lazyEntity.js","sourceRoot":"","sources":["../../../src/feature-libraries/flex-tree/lazyEntity.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;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AAI,8BAAY,CAAC,KAAK,KAAK,4BAA4B,CAAC,KAAK,CAAC;IACtE,CAAC;IAED,IAAW,MAAM;QAChB,IAAI,uBAAA,IAAI,8BAAY,CAAC,KAAK,KAAK,4BAA4B,CAAC,OAAO,EAAE,CAAC;YACrE,MAAM,CACL,uBAAA,IAAI,8BAAY,CAAC,KAAK,KAAK,4BAA4B,CAAC,OAAO,EAC/D,KAAK,CAAC,6CAA6C,CACnD,CAAC;YACF,MAAM,CACL,IAAI,CAAC,MAAM,KAAK,SAAS,EACzB,KAAK,CAAC,iEAAiE,CACvE,CAAC;YACF,MAAM,MAAM,GAAG,IAAI,CAAC,qBAAqB,CAAC,uBAAA,IAAI,8BAAY,CAAC,CAAC;YAC5D,MAAM,CACL,MAAM,oCAA4B,EAClC,KAAK,CAAC,oEAAoE,CAC1E,CAAC;YACF,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,uBAAA,IAAI,8BAAY,CAAC;IACzB,CAAC;CAUD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\ttype ITreeSubscriptionCursor,\n\tITreeSubscriptionCursorState,\n\tTreeNavigationResult,\n} from \"../../core/index.js\";\nimport { type IDisposable, disposeSymbol } from \"../../util/index.js\";\n\nimport type { Context } from \"./context.js\";\nimport {\n\ttype FlexTreeEntity,\n\ttype FlexTreeEntityKind,\n\tflexTreeMarker,\n} from \"./flexTreeTypes.js\";\n\n/**\n * Assert `entity` is not deleted.\n * @privateRemarks\n * This can be faster than getting the tree status and checking that since that can require computing removed vs deleted.\n * TODO: provide a non implementation dependent way to leverage this optimization.\n */\nexport function assertFlexTreeEntityNotFreed(entity: FlexTreeEntity): void {\n\tassert(entity instanceof LazyEntity, 0x8c9 /* unexpected implementation */);\n\tassert(!entity.isFreed(), 0x8ca /* Use after free */);\n}\n\n/**\n * This is a base class for lazy (cursor based) UntypedEntity implementations, which uniformly handles cursors and anchors.\n */\nexport abstract class LazyEntity<TAnchor = unknown> implements FlexTreeEntity, IDisposable {\n\treadonly #lazyCursor: ITreeSubscriptionCursor;\n\tpublic readonly anchor: TAnchor;\n\n\tprotected constructor(\n\t\tpublic readonly context: Context,\n\t\tcursor: ITreeSubscriptionCursor,\n\t\tanchor: TAnchor,\n\t) {\n\t\tthis.anchor = anchor;\n\t\tthis.#lazyCursor = cursor.fork(\"LazyEntity Fork\");\n\t\tcontext.withCursors.add(this);\n\t\tthis.context.withAnchors.add(this);\n\t}\n\n\tpublic abstract boxedIterator(): IterableIterator<FlexTreeEntity>;\n\tpublic abstract get [flexTreeMarker](): FlexTreeEntityKind;\n\n\tpublic [disposeSymbol](): void {\n\t\tthis.#lazyCursor.free();\n\t\tthis.context.withCursors.delete(this);\n\t\tthis.forgetAnchor();\n\t\tthis.context.withAnchors.delete(this);\n\t}\n\n\tpublic prepareForEdit(): void {\n\t\tthis.#lazyCursor.clear();\n\t\tthis.context.withCursors.delete(this);\n\t}\n\n\tpublic isFreed(): boolean {\n\t\treturn this.#lazyCursor.state === ITreeSubscriptionCursorState.Freed;\n\t}\n\n\tpublic get cursor(): ITreeSubscriptionCursor {\n\t\tif (this.#lazyCursor.state !== ITreeSubscriptionCursorState.Current) {\n\t\t\tassert(\n\t\t\t\tthis.#lazyCursor.state === ITreeSubscriptionCursorState.Cleared,\n\t\t\t\t0x778 /* Unset cursor should be in cleared state */,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\tthis.anchor !== undefined,\n\t\t\t\t0x779 /* FlexTree should have an anchor if it does not have a cursor */,\n\t\t\t);\n\t\t\tconst result = this.tryMoveCursorToAnchor(this.#lazyCursor);\n\t\t\tassert(\n\t\t\t\tresult === TreeNavigationResult.Ok,\n\t\t\t\t0x77a /* It is invalid to access a FlexTree node which no longer exists */,\n\t\t\t);\n\t\t\tthis.context.withCursors.add(this);\n\t\t}\n\t\treturn this.#lazyCursor;\n\t}\n\n\tprotected abstract tryMoveCursorToAnchor(\n\t\tcursor: ITreeSubscriptionCursor,\n\t): TreeNavigationResult;\n\n\t/**\n\t * Called when disposing of this target, iff it has an anchor.\n\t */\n\tprotected abstract forgetAnchor(): void;\n}\n"]}
|
|
@@ -7,7 +7,7 @@ import { type IDefaultEditBuilder, type OptionalFieldEditBuilder, type SequenceF
|
|
|
7
7
|
import type { FlexFieldKind } from "../modular-schema/index.js";
|
|
8
8
|
import type { Context } from "./context.js";
|
|
9
9
|
import { FlexTreeEntityKind, type FlexTreeField, type FlexTreeNode, type FlexTreeOptionalField, type FlexTreeRequiredField, type FlexTreeSequenceField, type FlexTreeTypedField, type FlexTreeUnknownUnboxed, flexTreeMarker } from "./flexTreeTypes.js";
|
|
10
|
-
import { LazyEntity
|
|
10
|
+
import { LazyEntity } from "./lazyEntity.js";
|
|
11
11
|
export declare function makeField(context: Context, schema: FieldKindIdentifier, cursor: ITreeSubscriptionCursor): FlexTreeField;
|
|
12
12
|
/**
|
|
13
13
|
* Base type for fields implementing {@link FlexTreeField} using cursors.
|
|
@@ -24,8 +24,8 @@ export declare abstract class LazyField extends LazyEntity<FieldAnchor> implemen
|
|
|
24
24
|
constructor(context: Context, schema: FieldKindIdentifier, cursor: ITreeSubscriptionCursor, fieldAnchor: FieldAnchor);
|
|
25
25
|
is<TKind2 extends FlexFieldKind>(kind: TKind2): this is FlexTreeTypedField<TKind2>;
|
|
26
26
|
get parent(): FlexTreeNode | undefined;
|
|
27
|
-
protected
|
|
28
|
-
protected
|
|
27
|
+
protected tryMoveCursorToAnchor(cursor: ITreeSubscriptionCursor): TreeNavigationResult;
|
|
28
|
+
protected forgetAnchor(): void;
|
|
29
29
|
get length(): number;
|
|
30
30
|
atIndex(index: number): FlexTreeUnknownUnboxed;
|
|
31
31
|
boxedAt(index: number): FlexTreeNode | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazyField.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/flex-tree/lazyField.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAGN,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EAIzB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAGN,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACN,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAE3B,cAAc,EAEd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,
|
|
1
|
+
{"version":3,"file":"lazyField.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/flex-tree/lazyField.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAGN,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EAIzB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAGN,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4B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EAAE,uBAAuB,EAC/B,WAAW,EAAE,WAAW,GACtB,sBAAsB,CA8BxB"}
|
|
@@ -8,7 +8,7 @@ import { inCursorNode, iterateCursorField, rootFieldKey, } from "../../core/inde
|
|
|
8
8
|
import { disposeSymbol, getOrCreate } from "../../util/index.js";
|
|
9
9
|
import { FieldKinds, MappedEditBuilder, } from "../default-schema/index.js";
|
|
10
10
|
import { FlexTreeEntityKind, TreeStatus, flexTreeMarker, flexTreeSlot, } from "./flexTreeTypes.js";
|
|
11
|
-
import { LazyEntity
|
|
11
|
+
import { LazyEntity } from "./lazyEntity.js";
|
|
12
12
|
import { makeTree } from "./lazyNode.js";
|
|
13
13
|
import { indexForAt, treeStatusFromAnchorCache } from "./utilities.js";
|
|
14
14
|
import { cursorForMapTreeField } from "../mapTreeCursor.js";
|
|
@@ -83,45 +83,45 @@ export class LazyField extends LazyEntity {
|
|
|
83
83
|
return this.schema === kind.identifier;
|
|
84
84
|
}
|
|
85
85
|
get parent() {
|
|
86
|
-
if (this
|
|
86
|
+
if (this.anchor.parent === undefined) {
|
|
87
87
|
return undefined;
|
|
88
88
|
}
|
|
89
|
-
const cursor = this
|
|
89
|
+
const cursor = this.cursor;
|
|
90
90
|
cursor.exitField();
|
|
91
91
|
const output = makeTree(this.context, cursor);
|
|
92
92
|
cursor.enterField(this.key);
|
|
93
93
|
return output;
|
|
94
94
|
}
|
|
95
|
-
|
|
96
|
-
return this.context.checkout.forest.tryMoveCursorToField(this
|
|
95
|
+
tryMoveCursorToAnchor(cursor) {
|
|
96
|
+
return this.context.checkout.forest.tryMoveCursorToField(this.anchor, cursor);
|
|
97
97
|
}
|
|
98
|
-
|
|
98
|
+
forgetAnchor() {
|
|
99
99
|
this.offAfterDestroy?.();
|
|
100
|
-
if (this
|
|
100
|
+
if (this.anchor.parent === undefined)
|
|
101
101
|
return;
|
|
102
|
-
this.context.checkout.forest.anchors.forget(this
|
|
102
|
+
this.context.checkout.forest.anchors.forget(this.anchor.parent);
|
|
103
103
|
}
|
|
104
104
|
get length() {
|
|
105
|
-
return this
|
|
105
|
+
return this.cursor.getFieldLength();
|
|
106
106
|
}
|
|
107
107
|
atIndex(index) {
|
|
108
|
-
return inCursorNode(this
|
|
108
|
+
return inCursorNode(this.cursor, index, (cursor) => unboxedFlexNode(this.context, cursor, this.anchor));
|
|
109
109
|
}
|
|
110
110
|
boxedAt(index) {
|
|
111
111
|
const finalIndex = indexForAt(index, this.length);
|
|
112
112
|
if (finalIndex === undefined) {
|
|
113
113
|
return undefined;
|
|
114
114
|
}
|
|
115
|
-
return inCursorNode(this
|
|
115
|
+
return inCursorNode(this.cursor, finalIndex, (cursor) => makeTree(this.context, cursor));
|
|
116
116
|
}
|
|
117
117
|
map(callbackfn) {
|
|
118
118
|
return Array.from(this, callbackfn);
|
|
119
119
|
}
|
|
120
120
|
boxedIterator() {
|
|
121
|
-
return iterateCursorField(this
|
|
121
|
+
return iterateCursorField(this.cursor, (cursor) => makeTree(this.context, cursor));
|
|
122
122
|
}
|
|
123
123
|
[Symbol.iterator]() {
|
|
124
|
-
return iterateCursorField(this
|
|
124
|
+
return iterateCursorField(this.cursor, (cursor) => unboxedFlexNode(this.context, cursor, this.anchor));
|
|
125
125
|
}
|
|
126
126
|
getFieldPath() {
|
|
127
127
|
return { parent: this.parent?.anchorNode, field: this.key };
|
|
@@ -131,10 +131,10 @@ export class LazyField extends LazyEntity {
|
|
|
131
131
|
* This path is not valid to hold onto across edits: this must be recalled for each edit.
|
|
132
132
|
*/
|
|
133
133
|
getFieldPathForEditing() {
|
|
134
|
-
if (!this
|
|
134
|
+
if (!this.isFreed()) {
|
|
135
135
|
if (
|
|
136
136
|
// Only allow editing if we are the root document field...
|
|
137
|
-
(this.parent === undefined && this
|
|
137
|
+
(this.parent === undefined && this.anchor.fieldKey === rootFieldKey) ||
|
|
138
138
|
// ...or are under a node in the document
|
|
139
139
|
(this.parent !== undefined &&
|
|
140
140
|
treeStatusFromAnchorCache(this.parent.anchorNode) === TreeStatus.InDocument)) {
|