@fluidframework/tree-agent 2.74.0 → 2.81.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 +99 -0
- package/api-report/tree-agent.alpha.api.md +195 -20
- package/dist/alpha.d.ts +31 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/methodBinding.d.ts +54 -10
- package/dist/methodBinding.d.ts.map +1 -1
- package/dist/methodBinding.js.map +1 -1
- package/dist/propertyBinding.d.ts +52 -2
- package/dist/propertyBinding.d.ts.map +1 -1
- package/dist/propertyBinding.js +28 -3
- package/dist/propertyBinding.js.map +1 -1
- package/dist/renderSchemaTypeScript.d.ts.map +1 -1
- package/dist/renderSchemaTypeScript.js +24 -9
- package/dist/renderSchemaTypeScript.js.map +1 -1
- package/dist/renderTypeFactoryTypeScript.d.ts +13 -0
- package/dist/renderTypeFactoryTypeScript.d.ts.map +1 -0
- package/dist/renderTypeFactoryTypeScript.js +290 -0
- package/dist/renderTypeFactoryTypeScript.js.map +1 -0
- package/dist/subtree.d.ts.map +1 -1
- package/dist/subtree.js +4 -4
- package/dist/subtree.js.map +1 -1
- package/dist/treeAgentTypes.d.ts +430 -0
- package/dist/treeAgentTypes.d.ts.map +1 -0
- package/dist/treeAgentTypes.js +227 -0
- package/dist/treeAgentTypes.js.map +1 -0
- package/dist/utils.d.ts +0 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -9
- package/dist/utils.js.map +1 -1
- package/eslint.config.mts +4 -4
- package/lib/alpha.d.ts +31 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/methodBinding.d.ts +54 -10
- package/lib/methodBinding.d.ts.map +1 -1
- package/lib/methodBinding.js.map +1 -1
- package/lib/propertyBinding.d.ts +52 -2
- package/lib/propertyBinding.d.ts.map +1 -1
- package/lib/propertyBinding.js +28 -3
- package/lib/propertyBinding.js.map +1 -1
- package/lib/renderSchemaTypeScript.d.ts.map +1 -1
- package/lib/renderSchemaTypeScript.js +24 -9
- package/lib/renderSchemaTypeScript.js.map +1 -1
- package/lib/renderTypeFactoryTypeScript.d.ts +13 -0
- package/lib/renderTypeFactoryTypeScript.d.ts.map +1 -0
- package/lib/renderTypeFactoryTypeScript.js +285 -0
- package/lib/renderTypeFactoryTypeScript.js.map +1 -0
- package/lib/subtree.d.ts.map +1 -1
- package/lib/subtree.js +4 -4
- package/lib/subtree.js.map +1 -1
- package/lib/treeAgentTypes.d.ts +430 -0
- package/lib/treeAgentTypes.d.ts.map +1 -0
- package/lib/treeAgentTypes.js +223 -0
- package/lib/treeAgentTypes.js.map +1 -0
- package/lib/utils.d.ts +0 -4
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +2 -8
- package/lib/utils.js.map +1 -1
- package/package.json +17 -17
- package/src/index.ts +36 -0
- package/src/methodBinding.ts +94 -15
- package/src/propertyBinding.ts +66 -9
- package/src/renderSchemaTypeScript.ts +32 -10
- package/src/renderTypeFactoryTypeScript.ts +339 -0
- package/src/subtree.ts +6 -5
- package/src/treeAgentTypes.ts +611 -0
- package/src/utils.ts +2 -9
- package/.eslintrc.cjs +0 -48
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.renderTypeFactoryTypeScript = exports.instanceOfsTypeFactory = void 0;
|
|
8
|
+
const internal_1 = require("@fluidframework/telemetry-utils/internal");
|
|
9
|
+
var treeAgentTypes_js_1 = require("./treeAgentTypes.js");
|
|
10
|
+
Object.defineProperty(exports, "instanceOfsTypeFactory", { enumerable: true, get: function () { return treeAgentTypes_js_1.instanceOfsTypeFactory; } });
|
|
11
|
+
/**
|
|
12
|
+
* Converts type factory type definitions into TypeScript declaration text.
|
|
13
|
+
* @alpha
|
|
14
|
+
*/
|
|
15
|
+
function renderTypeFactoryTypeScript(typeFactoryType, getFriendlyName, instanceOfLookup, initialIndent = 0) {
|
|
16
|
+
let result = "";
|
|
17
|
+
let startOfLine = false;
|
|
18
|
+
let indent = initialIndent;
|
|
19
|
+
appendType(typeFactoryType, 0 /* TypePrecedence.Union */);
|
|
20
|
+
return result;
|
|
21
|
+
function appendType(type, minPrecedence = 2 /* TypePrecedence.Object */) {
|
|
22
|
+
const shouldParenthesize = getTypePrecedence(type) < minPrecedence;
|
|
23
|
+
if (shouldParenthesize) {
|
|
24
|
+
append("(");
|
|
25
|
+
}
|
|
26
|
+
appendTypeDefinition(type);
|
|
27
|
+
if (shouldParenthesize) {
|
|
28
|
+
append(")");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function append(s) {
|
|
32
|
+
if (startOfLine) {
|
|
33
|
+
result += " ".repeat(indent);
|
|
34
|
+
startOfLine = false;
|
|
35
|
+
}
|
|
36
|
+
result += s;
|
|
37
|
+
}
|
|
38
|
+
function appendNewLine() {
|
|
39
|
+
append("\n");
|
|
40
|
+
startOfLine = true;
|
|
41
|
+
}
|
|
42
|
+
function appendTypeDefinition(type) {
|
|
43
|
+
switch (type._kind) {
|
|
44
|
+
case "string": {
|
|
45
|
+
append("string");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
case "number": {
|
|
49
|
+
append("number");
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
case "boolean": {
|
|
53
|
+
append("boolean");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
case "date": {
|
|
57
|
+
append("Date");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
case "void": {
|
|
61
|
+
append("void");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
case "undefined": {
|
|
65
|
+
append("undefined");
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
case "null": {
|
|
69
|
+
append("null");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
case "unknown": {
|
|
73
|
+
append("unknown");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
case "array": {
|
|
77
|
+
appendArrayType(type);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
case "promise": {
|
|
81
|
+
appendPromiseType(type);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
case "object": {
|
|
85
|
+
appendObjectType(type);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
case "union": {
|
|
89
|
+
appendUnionTypes(type.options, 0 /* TypePrecedence.Union */);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
case "intersection": {
|
|
93
|
+
appendIntersectionTypes(type.types, 1 /* TypePrecedence.Intersection */);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
case "tuple": {
|
|
97
|
+
appendTupleType(type);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
case "record": {
|
|
101
|
+
appendRecordType(type);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
case "map": {
|
|
105
|
+
appendMapType(type);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
case "literal": {
|
|
109
|
+
appendLiteral(type.value);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
case "optional": {
|
|
113
|
+
appendUnionTypes([type.innerType, { _kind: "undefined" }], 0 /* TypePrecedence.Union */);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
case "readonly": {
|
|
117
|
+
appendReadonlyType(type);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
case "function": {
|
|
121
|
+
appendFunctionType(type);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
case "instanceof": {
|
|
125
|
+
const schema = instanceOfLookup.get(type);
|
|
126
|
+
if (schema === undefined) {
|
|
127
|
+
throw new internal_1.UsageError("instanceof type not found in lookup - this typically indicates the type was not created via typeFactory.instanceOf");
|
|
128
|
+
}
|
|
129
|
+
append(getFriendlyName(schema));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
default: {
|
|
133
|
+
throw new internal_1.UsageError(`Unsupported type when formatting helper types: ${String(type._kind ?? "unknown")}. Expected one of: string, number, boolean, void, undefined, null, unknown, array, object, union, tuple, record, map, literal, optional, readonly, instanceof.`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function appendArrayType(arrayType) {
|
|
138
|
+
appendType(arrayType.element, 2 /* TypePrecedence.Object */);
|
|
139
|
+
append("[]");
|
|
140
|
+
}
|
|
141
|
+
function appendPromiseType(promiseType) {
|
|
142
|
+
append("Promise<");
|
|
143
|
+
appendType(promiseType.innerType, 0 /* TypePrecedence.Union */);
|
|
144
|
+
append(">");
|
|
145
|
+
}
|
|
146
|
+
function appendObjectType(objectType) {
|
|
147
|
+
append("{");
|
|
148
|
+
appendNewLine();
|
|
149
|
+
indent++;
|
|
150
|
+
for (const [name, propertyType] of Object.entries(objectType.shape)) {
|
|
151
|
+
append(name);
|
|
152
|
+
if (propertyType._kind === "optional") {
|
|
153
|
+
append("?");
|
|
154
|
+
append(": ");
|
|
155
|
+
appendType(propertyType.innerType);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
append(": ");
|
|
159
|
+
appendType(propertyType);
|
|
160
|
+
}
|
|
161
|
+
append(";");
|
|
162
|
+
appendNewLine();
|
|
163
|
+
}
|
|
164
|
+
indent--;
|
|
165
|
+
append("}");
|
|
166
|
+
}
|
|
167
|
+
function appendUnionTypes(types, minPrecedence) {
|
|
168
|
+
let first = true;
|
|
169
|
+
for (const innerType of types) {
|
|
170
|
+
if (!first) {
|
|
171
|
+
append(" | ");
|
|
172
|
+
}
|
|
173
|
+
appendType(innerType, minPrecedence);
|
|
174
|
+
first = false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function appendIntersectionTypes(types, minPrecedence) {
|
|
178
|
+
let first = true;
|
|
179
|
+
for (const innerType of types) {
|
|
180
|
+
if (!first) {
|
|
181
|
+
append(" & ");
|
|
182
|
+
}
|
|
183
|
+
appendType(innerType, minPrecedence);
|
|
184
|
+
first = false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function appendTupleType(tupleType) {
|
|
188
|
+
append("[");
|
|
189
|
+
let first = true;
|
|
190
|
+
for (const innerType of tupleType.items) {
|
|
191
|
+
if (!first) {
|
|
192
|
+
append(", ");
|
|
193
|
+
}
|
|
194
|
+
if (innerType._kind === "optional") {
|
|
195
|
+
appendType(innerType.innerType, 2 /* TypePrecedence.Object */);
|
|
196
|
+
append("?");
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
appendType(innerType);
|
|
200
|
+
}
|
|
201
|
+
first = false;
|
|
202
|
+
}
|
|
203
|
+
if (tupleType.rest !== undefined) {
|
|
204
|
+
if (!first) {
|
|
205
|
+
append(", ");
|
|
206
|
+
}
|
|
207
|
+
append("...");
|
|
208
|
+
appendType(tupleType.rest, 2 /* TypePrecedence.Object */);
|
|
209
|
+
append("[]");
|
|
210
|
+
}
|
|
211
|
+
append("]");
|
|
212
|
+
}
|
|
213
|
+
function appendRecordType(recordType) {
|
|
214
|
+
append("Record<");
|
|
215
|
+
appendType(recordType.keyType, 0 /* TypePrecedence.Union */);
|
|
216
|
+
append(", ");
|
|
217
|
+
appendType(recordType.valueType, 0 /* TypePrecedence.Union */);
|
|
218
|
+
append(">");
|
|
219
|
+
}
|
|
220
|
+
function appendMapType(mapType) {
|
|
221
|
+
append("Map<");
|
|
222
|
+
appendType(mapType.keyType, 0 /* TypePrecedence.Union */);
|
|
223
|
+
append(", ");
|
|
224
|
+
appendType(mapType.valueType, 0 /* TypePrecedence.Union */);
|
|
225
|
+
append(">");
|
|
226
|
+
}
|
|
227
|
+
function appendLiteral(value) {
|
|
228
|
+
append(JSON.stringify(value));
|
|
229
|
+
}
|
|
230
|
+
function appendReadonlyType(readonlyType) {
|
|
231
|
+
append("Readonly<");
|
|
232
|
+
appendType(readonlyType.innerType);
|
|
233
|
+
append(">");
|
|
234
|
+
}
|
|
235
|
+
function appendFunctionType(functionType) {
|
|
236
|
+
append("(");
|
|
237
|
+
let first = true;
|
|
238
|
+
for (const param of functionType.parameters) {
|
|
239
|
+
if (!first) {
|
|
240
|
+
append(", ");
|
|
241
|
+
}
|
|
242
|
+
const [name, type] = param;
|
|
243
|
+
append(name);
|
|
244
|
+
if (type._kind === "optional") {
|
|
245
|
+
append("?");
|
|
246
|
+
append(": ");
|
|
247
|
+
appendType(type.innerType, 0 /* TypePrecedence.Union */);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
append(": ");
|
|
251
|
+
appendType(type, 0 /* TypePrecedence.Union */);
|
|
252
|
+
}
|
|
253
|
+
first = false;
|
|
254
|
+
}
|
|
255
|
+
if (functionType.restParameter !== undefined) {
|
|
256
|
+
if (!first) {
|
|
257
|
+
append(", ");
|
|
258
|
+
}
|
|
259
|
+
const [name, type] = functionType.restParameter;
|
|
260
|
+
append("...");
|
|
261
|
+
append(name);
|
|
262
|
+
append(": ");
|
|
263
|
+
appendType(type, 2 /* TypePrecedence.Object */);
|
|
264
|
+
append("[]");
|
|
265
|
+
}
|
|
266
|
+
append(") => ");
|
|
267
|
+
appendType(functionType.returnType, 0 /* TypePrecedence.Union */);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
exports.renderTypeFactoryTypeScript = renderTypeFactoryTypeScript;
|
|
271
|
+
var TypePrecedence;
|
|
272
|
+
(function (TypePrecedence) {
|
|
273
|
+
TypePrecedence[TypePrecedence["Union"] = 0] = "Union";
|
|
274
|
+
TypePrecedence[TypePrecedence["Intersection"] = 1] = "Intersection";
|
|
275
|
+
TypePrecedence[TypePrecedence["Object"] = 2] = "Object";
|
|
276
|
+
})(TypePrecedence || (TypePrecedence = {}));
|
|
277
|
+
function getTypePrecedence(type) {
|
|
278
|
+
switch (type._kind) {
|
|
279
|
+
case "union": {
|
|
280
|
+
return 0 /* TypePrecedence.Union */;
|
|
281
|
+
}
|
|
282
|
+
case "intersection": {
|
|
283
|
+
return 1 /* TypePrecedence.Intersection */;
|
|
284
|
+
}
|
|
285
|
+
default: {
|
|
286
|
+
return 2 /* TypePrecedence.Object */;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=renderTypeFactoryTypeScript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderTypeFactoryTypeScript.js","sourceRoot":"","sources":["../src/renderTypeFactoryTypeScript.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uEAAsE;AAmBtE,yDAA6D;AAApD,2HAAA,sBAAsB,OAAA;AAE/B;;;GAGG;AACH,SAAgB,2BAA2B,CAC1C,eAAgC,EAChC,eAAmD,EACnD,gBAA4D,EAC5D,gBAAwB,CAAC;IAEzB,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,IAAI,MAAM,GAAG,aAAa,CAAC;IAE3B,UAAU,CAAC,eAAe,+BAAuB,CAAC;IAClD,OAAO,MAAM,CAAC;IAEd,SAAS,UAAU,CAAC,IAAqB,EAAE,aAAa,gCAAwB;QAC/E,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC;QACnE,IAAI,kBAAkB,EAAE,CAAC;YACxB,MAAM,CAAC,GAAG,CAAC,CAAC;QACb,CAAC;QACD,oBAAoB,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,kBAAkB,EAAE,CAAC;YACxB,MAAM,CAAC,GAAG,CAAC,CAAC;QACb,CAAC;IACF,CAAC;IAED,SAAS,MAAM,CAAC,CAAS;QACxB,IAAI,WAAW,EAA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AAED,SAAS,iBAAiB,CAAC,IAAqB;IAC/C,QAAQ,IAAI,CAAC,KAAK,EAAE,CAAC;QACpB,KAAK,OAAO,CAAC,CAAC,CAAC;YACd,oCAA4B;QAC7B,CAAC;QACD,KAAK,cAAc,CAAC,CAAC,CAAC;YACrB,2CAAmC;QACpC,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACT,qCAA6B;QAC9B,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { ObjectNodeSchema, TreeNodeSchema } from \"@fluidframework/tree/alpha\";\n\nimport type {\n\tTypeFactoryType,\n\tTypeFactoryArray,\n\tTypeFactoryPromise,\n\tTypeFactoryObject,\n\tTypeFactoryTuple,\n\tTypeFactoryRecord,\n\tTypeFactoryMap,\n\tTypeFactoryLiteral,\n\tTypeFactoryOptional,\n\tTypeFactoryReadonly,\n\tTypeFactoryUnion,\n\tTypeFactoryIntersection,\n\tTypeFactoryFunction,\n} from \"./treeAgentTypes.js\";\n\nexport { instanceOfsTypeFactory } from \"./treeAgentTypes.js\";\n\n/**\n * Converts type factory type definitions into TypeScript declaration text.\n * @alpha\n */\nexport function renderTypeFactoryTypeScript(\n\ttypeFactoryType: TypeFactoryType,\n\tgetFriendlyName: (schema: TreeNodeSchema) => string,\n\tinstanceOfLookup: WeakMap<TypeFactoryType, ObjectNodeSchema>,\n\tinitialIndent: number = 0,\n): string {\n\tlet result = \"\";\n\tlet startOfLine = false;\n\tlet indent = initialIndent;\n\n\tappendType(typeFactoryType, TypePrecedence.Union);\n\treturn result;\n\n\tfunction appendType(type: TypeFactoryType, minPrecedence = TypePrecedence.Object): void {\n\t\tconst shouldParenthesize = getTypePrecedence(type) < minPrecedence;\n\t\tif (shouldParenthesize) {\n\t\t\tappend(\"(\");\n\t\t}\n\t\tappendTypeDefinition(type);\n\t\tif (shouldParenthesize) {\n\t\t\tappend(\")\");\n\t\t}\n\t}\n\n\tfunction append(s: string): void {\n\t\tif (startOfLine) {\n\t\t\tresult += \" \".repeat(indent);\n\t\t\tstartOfLine = false;\n\t\t}\n\t\tresult += s;\n\t}\n\n\tfunction appendNewLine(): void {\n\t\tappend(\"\\n\");\n\t\tstartOfLine = true;\n\t}\n\n\tfunction appendTypeDefinition(type: TypeFactoryType): void {\n\t\tswitch (type._kind) {\n\t\t\tcase \"string\": {\n\t\t\t\tappend(\"string\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"number\": {\n\t\t\t\tappend(\"number\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"boolean\": {\n\t\t\t\tappend(\"boolean\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"date\": {\n\t\t\t\tappend(\"Date\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"void\": {\n\t\t\t\tappend(\"void\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"undefined\": {\n\t\t\t\tappend(\"undefined\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"null\": {\n\t\t\t\tappend(\"null\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"unknown\": {\n\t\t\t\tappend(\"unknown\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"array\": {\n\t\t\t\tappendArrayType(type as TypeFactoryArray);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"promise\": {\n\t\t\t\tappendPromiseType(type as TypeFactoryPromise);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"object\": {\n\t\t\t\tappendObjectType(type as TypeFactoryObject);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"union\": {\n\t\t\t\tappendUnionTypes((type as TypeFactoryUnion).options, TypePrecedence.Union);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"intersection\": {\n\t\t\t\tappendIntersectionTypes(\n\t\t\t\t\t(type as TypeFactoryIntersection).types,\n\t\t\t\t\tTypePrecedence.Intersection,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"tuple\": {\n\t\t\t\tappendTupleType(type as TypeFactoryTuple);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"record\": {\n\t\t\t\tappendRecordType(type as TypeFactoryRecord);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"map\": {\n\t\t\t\tappendMapType(type as TypeFactoryMap);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"literal\": {\n\t\t\t\tappendLiteral((type as TypeFactoryLiteral).value);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"optional\": {\n\t\t\t\tappendUnionTypes(\n\t\t\t\t\t[(type as TypeFactoryOptional).innerType, { _kind: \"undefined\" }],\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"readonly\": {\n\t\t\t\tappendReadonlyType(type as TypeFactoryReadonly);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"function\": {\n\t\t\t\tappendFunctionType(type as TypeFactoryFunction);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"instanceof\": {\n\t\t\t\tconst schema = instanceOfLookup.get(type);\n\t\t\t\tif (schema === undefined) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"instanceof type not found in lookup - this typically indicates the type was not created via typeFactory.instanceOf\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tappend(getFriendlyName(schema));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Unsupported type when formatting helper types: ${String(type._kind ?? \"unknown\")}. Expected one of: string, number, boolean, void, undefined, null, unknown, array, object, union, tuple, record, map, literal, optional, readonly, instanceof.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction appendArrayType(arrayType: TypeFactoryArray): void {\n\t\tappendType(arrayType.element, TypePrecedence.Object);\n\t\tappend(\"[]\");\n\t}\n\n\tfunction appendPromiseType(promiseType: TypeFactoryPromise): void {\n\t\tappend(\"Promise<\");\n\t\tappendType(promiseType.innerType, TypePrecedence.Union);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendObjectType(objectType: TypeFactoryObject): void {\n\t\tappend(\"{\");\n\t\tappendNewLine();\n\t\tindent++;\n\t\tfor (const [name, propertyType] of Object.entries(objectType.shape)) {\n\t\t\tappend(name);\n\t\t\tif (propertyType._kind === \"optional\") {\n\t\t\t\tappend(\"?\");\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType((propertyType as TypeFactoryOptional).innerType);\n\t\t\t} else {\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType(propertyType);\n\t\t\t}\n\t\t\tappend(\";\");\n\t\t\tappendNewLine();\n\t\t}\n\t\tindent--;\n\t\tappend(\"}\");\n\t}\n\n\tfunction appendUnionTypes(\n\t\ttypes: readonly TypeFactoryType[],\n\t\tminPrecedence: TypePrecedence,\n\t): void {\n\t\tlet first = true;\n\t\tfor (const innerType of types) {\n\t\t\tif (!first) {\n\t\t\t\tappend(\" | \");\n\t\t\t}\n\t\t\tappendType(innerType, minPrecedence);\n\t\t\tfirst = false;\n\t\t}\n\t}\n\n\tfunction appendIntersectionTypes(\n\t\ttypes: readonly TypeFactoryType[],\n\t\tminPrecedence: TypePrecedence,\n\t): void {\n\t\tlet first = true;\n\t\tfor (const innerType of types) {\n\t\t\tif (!first) {\n\t\t\t\tappend(\" & \");\n\t\t\t}\n\t\t\tappendType(innerType, minPrecedence);\n\t\t\tfirst = false;\n\t\t}\n\t}\n\n\tfunction appendTupleType(tupleType: TypeFactoryTuple): void {\n\t\tappend(\"[\");\n\t\tlet first = true;\n\t\tfor (const innerType of tupleType.items) {\n\t\t\tif (!first) {\n\t\t\t\tappend(\", \");\n\t\t\t}\n\t\t\tif (innerType._kind === \"optional\") {\n\t\t\t\tappendType((innerType as TypeFactoryOptional).innerType, TypePrecedence.Object);\n\t\t\t\tappend(\"?\");\n\t\t\t} else {\n\t\t\t\tappendType(innerType);\n\t\t\t}\n\t\t\tfirst = false;\n\t\t}\n\t\tif (tupleType.rest !== undefined) {\n\t\t\tif (!first) {\n\t\t\t\tappend(\", \");\n\t\t\t}\n\t\t\tappend(\"...\");\n\t\t\tappendType(tupleType.rest, TypePrecedence.Object);\n\t\t\tappend(\"[]\");\n\t\t}\n\t\tappend(\"]\");\n\t}\n\n\tfunction appendRecordType(recordType: TypeFactoryRecord): void {\n\t\tappend(\"Record<\");\n\t\tappendType(recordType.keyType, TypePrecedence.Union);\n\t\tappend(\", \");\n\t\tappendType(recordType.valueType, TypePrecedence.Union);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendMapType(mapType: TypeFactoryMap): void {\n\t\tappend(\"Map<\");\n\t\tappendType(mapType.keyType, TypePrecedence.Union);\n\t\tappend(\", \");\n\t\tappendType(mapType.valueType, TypePrecedence.Union);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendLiteral(value: string | number | boolean): void {\n\t\tappend(JSON.stringify(value));\n\t}\n\n\tfunction appendReadonlyType(readonlyType: TypeFactoryReadonly): void {\n\t\tappend(\"Readonly<\");\n\t\tappendType(readonlyType.innerType);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendFunctionType(functionType: TypeFactoryFunction): void {\n\t\tappend(\"(\");\n\t\tlet first = true;\n\t\tfor (const param of functionType.parameters) {\n\t\t\tif (!first) {\n\t\t\t\tappend(\", \");\n\t\t\t}\n\t\t\tconst [name, type] = param;\n\t\t\tappend(name);\n\t\t\tif (type._kind === \"optional\") {\n\t\t\t\tappend(\"?\");\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType((type as TypeFactoryOptional).innerType, TypePrecedence.Union);\n\t\t\t} else {\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType(type, TypePrecedence.Union);\n\t\t\t}\n\t\t\tfirst = false;\n\t\t}\n\t\tif (functionType.restParameter !== undefined) {\n\t\t\tif (!first) {\n\t\t\t\tappend(\", \");\n\t\t\t}\n\t\t\tconst [name, type] = functionType.restParameter;\n\t\t\tappend(\"...\");\n\t\t\tappend(name);\n\t\t\tappend(\": \");\n\t\t\tappendType(type, TypePrecedence.Object);\n\t\t\tappend(\"[]\");\n\t\t}\n\t\tappend(\") => \");\n\t\tappendType(functionType.returnType, TypePrecedence.Union);\n\t}\n}\n\nconst enum TypePrecedence {\n\tUnion = 0,\n\tIntersection = 1,\n\tObject = 2,\n}\n\nfunction getTypePrecedence(type: TypeFactoryType): TypePrecedence {\n\tswitch (type._kind) {\n\t\tcase \"union\": {\n\t\t\treturn TypePrecedence.Union;\n\t\t}\n\t\tcase \"intersection\": {\n\t\t\treturn TypePrecedence.Intersection;\n\t\t}\n\t\tdefault: {\n\t\t\treturn TypePrecedence.Object;\n\t\t}\n\t}\n}\n"]}
|
package/dist/subtree.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subtree.d.ts","sourceRoot":"","sources":["../src/subtree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EACX,mBAAmB,EACnB,0BAA0B,EAG1B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EACX,aAAa,EAEb,eAAe,EACf,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"subtree.d.ts","sourceRoot":"","sources":["../src/subtree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EACX,mBAAmB,EACnB,0BAA0B,EAG1B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EACX,aAAa,EAEb,eAAe,EACf,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAY,UAAU,EAAE,MAAM,UAAU,CAAC;AAGrD;;GAEG;AACH,qBAAa,OAAO,CAAC,KAAK,SAAS,mBAAmB;aAClB,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC;gBAA7B,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC;IAMhE,IAAW,MAAM,IAAI,eAAe,CAInC;IAED,IAAW,KAAK,IAAI,aAAa,CAAC,KAAK,CAAC,CAEvC;IAED,IAAW,KAAK,CAAC,KAAK,EAAE,0BAA0B,CAAC,KAAK,CAAC,EAsDxD;IAED,IAAW,MAAM,IAAI,KAAK,CAMzB;IAEM,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC;CAa7B"}
|
package/dist/subtree.js
CHANGED
|
@@ -22,7 +22,7 @@ class Subtree {
|
|
|
22
22
|
}
|
|
23
23
|
get branch() {
|
|
24
24
|
return this.viewOrTree instanceof tree_1.TreeNode
|
|
25
|
-
? (alpha_1.TreeAlpha.branch(this.viewOrTree) ?? (0, internal_1.fail)(
|
|
25
|
+
? (alpha_1.TreeAlpha.branch(this.viewOrTree) ?? (0, internal_1.fail)(0xcb3 /* Node cannot be raw. */))
|
|
26
26
|
: this.viewOrTree;
|
|
27
27
|
}
|
|
28
28
|
get field() {
|
|
@@ -79,7 +79,7 @@ class Subtree {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
default: {
|
|
82
|
-
(0, internal_1.fail)(
|
|
82
|
+
(0, internal_1.fail)(0xcb4 /* Unexpected node kind */);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -95,9 +95,9 @@ class Subtree {
|
|
|
95
95
|
}
|
|
96
96
|
fork() {
|
|
97
97
|
if (this.viewOrTree instanceof tree_1.TreeNode) {
|
|
98
|
-
const branch = alpha_1.TreeAlpha.branch(this.viewOrTree) ?? (0, internal_1.fail)(
|
|
98
|
+
const branch = alpha_1.TreeAlpha.branch(this.viewOrTree) ?? (0, internal_1.fail)(0xcb5 /* Node cannot be raw. */);
|
|
99
99
|
const node = (0, getNodeOnBranch_js_1.getNodeOnBranch)(this.viewOrTree, branch.fork()) ??
|
|
100
|
-
(0, internal_1.fail)(
|
|
100
|
+
(0, internal_1.fail)(0xcb6 /* Expected node to be on new fork. */);
|
|
101
101
|
return new Subtree(node);
|
|
102
102
|
}
|
|
103
103
|
else {
|
package/dist/subtree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subtree.js","sourceRoot":"","sources":["../src/subtree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA2D;AAC3D,uEAAsE;AACtE,+CAAgE;AAOhE,sDAAuD;
|
|
1
|
+
{"version":3,"file":"subtree.js","sourceRoot":"","sources":["../src/subtree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA2D;AAC3D,uEAAsE;AACtE,+CAAgE;AAOhE,sDAAuD;AAQvD,6DAAuD;AAEvD;;GAEG;AACH,MAAa,OAAO;IACnB,YAAmC,UAA6B;QAA7B,eAAU,GAAV,UAAU,CAAmB;QAC/D,IAAI,UAAU,YAAY,eAAQ,IAAI,iBAAS,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,SAAS,EAAE,CAAC;YAClF,MAAM,IAAI,qBAAU,CAAC,4CAA4C,CAAC,CAAC;QACpE,CAAC;IACF,CAAC;IAED,IAAW,MAAM;QAChB,OAAO,IAAI,CAAC,UAAU,YAAY,eAAQ;YACzC,CAAC,CAAC,CAAC,iBAAS,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAA,eAAI,EAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;YAC9E,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;IACpB,CAAC;IAED,IAAW,KAAK;QACf,OAAO,IAAI,CAAC,UAAU,YAAY,eAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;IACrF,CAAC;IAED,IAAW,KAAK,CAAC,KAAwC;QACxD,IAAI,IAAI,CAAC,UAAU,YAAY,eAAQ,EAAE,CAAC;YACzC,MAAM,MAAM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AC,IAAI,EAAE,CAAC;gBAC/C,IAAA,eAAI,EAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;YAEpD,OAAO,IAAI,OAAO,CAAQ,IAAI,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACP,OAAO,IAAI,OAAO,CAAQ,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;QACnD,CAAC;IACF,CAAC;CACD;AA9FD,0BA8FC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { fail } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { TreeNode, Tree, NodeKind } from \"@fluidframework/tree\";\nimport type {\n\tImplicitFieldSchema,\n\tTreeFieldFromImplicitField,\n\tTreeMapNode,\n\tTreeArrayNode,\n} from \"@fluidframework/tree\";\nimport { TreeAlpha } from \"@fluidframework/tree/alpha\";\nimport type {\n\tReadableField,\n\tTreeRecordNode,\n\tTreeBranchAlpha,\n} from \"@fluidframework/tree/alpha\";\n\nimport type { TreeView, ViewOrTree } from \"./api.js\";\nimport { getNodeOnBranch } from \"./getNodeOnBranch.js\";\n\n/**\n * Wraps either a {@link TreeView} or a {@link TreeNode} and provides a common interface over them.\n */\nexport class Subtree<TRoot extends ImplicitFieldSchema> {\n\tpublic constructor(public readonly viewOrTree: ViewOrTree<TRoot>) {\n\t\tif (viewOrTree instanceof TreeNode && TreeAlpha.branch(viewOrTree) === undefined) {\n\t\t\tthrow new UsageError(\"The provided node must belong to a branch.\");\n\t\t}\n\t}\n\n\tpublic get branch(): TreeBranchAlpha {\n\t\treturn this.viewOrTree instanceof TreeNode\n\t\t\t? (TreeAlpha.branch(this.viewOrTree) ?? fail(0xcb3 /* Node cannot be raw. */))\n\t\t\t: this.viewOrTree;\n\t}\n\n\tpublic get field(): ReadableField<TRoot> {\n\t\treturn this.viewOrTree instanceof TreeNode ? this.viewOrTree : this.viewOrTree.root;\n\t}\n\n\tpublic set field(value: TreeFieldFromImplicitField<TRoot>) {\n\t\tif (this.viewOrTree instanceof TreeNode) {\n\t\t\tconst parent = Tree.parent(this.viewOrTree);\n\t\t\tif (parent === undefined) {\n\t\t\t\t// In general, this is not a correct cast, but we know that the root of the branch at least allows the type of `value`\n\t\t\t\tconst view = this.branch as TreeView<TRoot>;\n\t\t\t\tview.root = value;\n\t\t\t} else {\n\t\t\t\tconst schema = Tree.schema(parent);\n\t\t\t\tswitch (schema.kind) {\n\t\t\t\t\tcase NodeKind.Object: {\n\t\t\t\t\t\tconst key = Tree.key(this.viewOrTree) as string;\n\t\t\t\t\t\t(parent as unknown as Record<string, unknown>)[key] = value;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase NodeKind.Record: {\n\t\t\t\t\t\tconst key = Tree.key(this.viewOrTree) as string;\n\t\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\t\t\t\t\tdelete (parent as TreeRecordNode)[key];\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t(parent as TreeRecordNode)[key] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase NodeKind.Map: {\n\t\t\t\t\t\tconst key = Tree.key(this.viewOrTree) as string;\n\t\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\t\t(parent as TreeMapNode).delete(key);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t(parent as TreeMapNode).set(key, value as never);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase NodeKind.Array: {\n\t\t\t\t\t\tconst index = Tree.key(this.viewOrTree) as number;\n\t\t\t\t\t\tconst arrayNode = parent as TreeArrayNode;\n\t\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\t\tarrayNode.removeAt(index);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.branch.runTransaction(() => {\n\t\t\t\t\t\t\t\tarrayNode.removeAt(index);\n\t\t\t\t\t\t\t\tarrayNode.insertAt(index, value as never);\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tfail(0xcb4 /* Unexpected node kind */);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthis.viewOrTree.root = value;\n\t\t}\n\t}\n\n\tpublic get schema(): TRoot {\n\t\treturn (\n\t\t\tthis.viewOrTree instanceof TreeNode\n\t\t\t\t? Tree.schema(this.viewOrTree)\n\t\t\t\t: this.viewOrTree.schema\n\t\t) as TRoot;\n\t}\n\n\tpublic fork(): Subtree<TRoot> {\n\t\tif (this.viewOrTree instanceof TreeNode) {\n\t\t\tconst branch =\n\t\t\t\tTreeAlpha.branch(this.viewOrTree) ?? fail(0xcb5 /* Node cannot be raw. */);\n\t\t\tconst node =\n\t\t\t\tgetNodeOnBranch(this.viewOrTree, branch.fork()) ??\n\t\t\t\tfail(0xcb6 /* Expected node to be on new fork. */);\n\n\t\t\treturn new Subtree<TRoot>(node);\n\t\t} else {\n\t\t\treturn new Subtree<TRoot>(this.viewOrTree.fork());\n\t\t}\n\t}\n}\n"]}
|