@fluidframework/shared-object-base 0.54.0-47413 → 0.55.0-48551
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +5 -2
- package/bench/src/index.ts +68 -0
- package/bench/src/util.ts +56 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- 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/remoteObjectHandle.d.ts +32 -0
- package/dist/remoteObjectHandle.d.ts.map +1 -0
- package/dist/remoteObjectHandle.js +66 -0
- package/dist/remoteObjectHandle.js.map +1 -0
- package/dist/serializer.d.ts +82 -0
- package/dist/serializer.d.ts.map +1 -0
- package/dist/serializer.js +148 -0
- package/dist/serializer.js.map +1 -0
- package/dist/sharedObject.d.ts +54 -26
- package/dist/sharedObject.d.ts.map +1 -1
- package/dist/sharedObject.js +77 -75
- package/dist/sharedObject.js.map +1 -1
- package/dist/summarySerializer.d.ts +1 -1
- package/dist/summarySerializer.d.ts.map +1 -1
- package/dist/summarySerializer.js +2 -2
- package/dist/summarySerializer.js.map +1 -1
- package/dist/types.d.ts +8 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +10 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +15 -5
- package/dist/utils.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- 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/remoteObjectHandle.d.ts +32 -0
- package/lib/remoteObjectHandle.d.ts.map +1 -0
- package/lib/remoteObjectHandle.js +62 -0
- package/lib/remoteObjectHandle.js.map +1 -0
- package/lib/serializer.d.ts +82 -0
- package/lib/serializer.d.ts.map +1 -0
- package/lib/serializer.js +143 -0
- package/lib/serializer.js.map +1 -0
- package/lib/sharedObject.d.ts +54 -26
- package/lib/sharedObject.d.ts.map +1 -1
- package/lib/sharedObject.js +75 -74
- package/lib/sharedObject.js.map +1 -1
- package/lib/summarySerializer.d.ts +1 -1
- package/lib/summarySerializer.d.ts.map +1 -1
- package/lib/summarySerializer.js +1 -1
- package/lib/summarySerializer.js.map +1 -1
- package/lib/types.d.ts +8 -2
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/utils.d.ts +10 -1
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +13 -4
- package/lib/utils.js.map +1 -1
- package/package.json +54 -18
- package/src/index.ts +1 -0
- package/src/packageVersion.ts +1 -1
- package/src/remoteObjectHandle.ts +79 -0
- package/src/serializer.ts +216 -0
- package/src/sharedObject.ts +116 -97
- package/src/summarySerializer.ts +1 -1
- package/src/types.ts +9 -2
- package/src/utils.ts +17 -8
- package/tsconfig.json +5 -3
package/dist/utils.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.parseHandles = exports.makeHandlesSerializable = exports.serializeHandles = void 0;
|
|
7
|
+
exports.createSingleBlobSummary = exports.parseHandles = exports.makeHandlesSerializable = exports.serializeHandles = void 0;
|
|
8
|
+
const runtime_utils_1 = require("@fluidframework/runtime-utils");
|
|
8
9
|
/**
|
|
9
10
|
* Given a mostly-plain object that may have handle objects embedded within, return a string representation of an object
|
|
10
11
|
* where the handle objects have been replaced with a serializable form.
|
|
@@ -14,7 +15,6 @@ exports.parseHandles = exports.makeHandlesSerializable = exports.serializeHandle
|
|
|
14
15
|
* @param bind - Bind any other handles we find in the object against this given handle.
|
|
15
16
|
* @returns Result of strigifying an object
|
|
16
17
|
*/
|
|
17
|
-
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
|
18
18
|
function serializeHandles(value, serializer, bind) {
|
|
19
19
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
20
20
|
return value !== undefined
|
|
@@ -34,10 +34,9 @@ exports.serializeHandles = serializeHandles;
|
|
|
34
34
|
* @param bind - Bind any other handles we find in the object against this given handle.
|
|
35
35
|
* @returns The fully-plain object
|
|
36
36
|
*/
|
|
37
|
-
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
|
38
37
|
function makeHandlesSerializable(value, serializer, bind) {
|
|
39
38
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
40
|
-
return serializer.
|
|
39
|
+
return serializer.encode(value, bind);
|
|
41
40
|
}
|
|
42
41
|
exports.makeHandlesSerializable = makeHandlesSerializable;
|
|
43
42
|
/**
|
|
@@ -48,10 +47,21 @@ exports.makeHandlesSerializable = makeHandlesSerializable;
|
|
|
48
47
|
* @param context - The handle context for the container
|
|
49
48
|
* @returns The mostly-plain object with handle objects within
|
|
50
49
|
*/
|
|
51
|
-
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
|
52
50
|
function parseHandles(value, serializer) {
|
|
53
51
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
54
52
|
return value !== undefined ? serializer.parse(JSON.stringify(value)) : value;
|
|
55
53
|
}
|
|
56
54
|
exports.parseHandles = parseHandles;
|
|
55
|
+
/**
|
|
56
|
+
* Create a new summary containing one blob
|
|
57
|
+
* @param key - the key for the blob in the summary
|
|
58
|
+
* @param content - blob content
|
|
59
|
+
* @returns The summary containing the blob
|
|
60
|
+
*/
|
|
61
|
+
function createSingleBlobSummary(key, content) {
|
|
62
|
+
const builder = new runtime_utils_1.SummaryTreeBuilder();
|
|
63
|
+
builder.addBlob(key, content);
|
|
64
|
+
return builder.getSummaryTree();
|
|
65
|
+
}
|
|
66
|
+
exports.createSingleBlobSummary = createSingleBlobSummary;
|
|
57
67
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,iEAAmE;AAGnE;;;;;;;;GAQG;AACH,SAAgB,gBAAgB,CAC5B,KAAU,EACV,UAA4B,EAC5B,IAAkB;IAElB,+DAA+D;IAC/D,OAAO,KAAK,KAAK,SAAS;QACtB,CAAC,CAAC,UAAU,CAAC,SAAS,CAClB,KAAK,EACL,IAAI,CAAC;QACT,CAAC,CAAC,KAAK,CAAC;AAChB,CAAC;AAXD,4CAWC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,uBAAuB,CACnC,KAAU,EACV,UAA4B,EAC5B,IAAkB;IAElB,+DAA+D;IAC/D,OAAO,UAAU,CAAC,MAAM,CACpB,KAAK,EACL,IAAI,CAAC,CAAC;AACd,CAAC;AATD,0DASC;AAED;;;;;;;GAOG;AACH,SAAgB,YAAY,CACxB,KAAU,EACV,UAA4B;IAE5B,+DAA+D;IAC/D,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACjF,CAAC;AAND,oCAMC;AAED;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAC,GAAW,EAAE,OAA4B;IAC7E,MAAM,OAAO,GAAG,IAAI,kCAAkB,EAAE,CAAC;IACzC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC9B,OAAO,OAAO,CAAC,cAAc,EAAE,CAAC;AACpC,CAAC;AAJD,0DAIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { IFluidSerializer } from \"./serializer\";\n\n/**\n * Given a mostly-plain object that may have handle objects embedded within, return a string representation of an object\n * where the handle objects have been replaced with a serializable form.\n * @param value - The mostly-plain object\n * @param serializer - The serializer that knows how to convert handles into serializable format\n * @param context - The handle context for the container\n * @param bind - Bind any other handles we find in the object against this given handle.\n * @returns Result of strigifying an object\n */\nexport function serializeHandles(\n value: any,\n serializer: IFluidSerializer,\n bind: IFluidHandle,\n): string | undefined {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value !== undefined\n ? serializer.stringify(\n value,\n bind)\n : value;\n}\n\n/**\n * Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object\n * where any embedded IFluidHandles have been replaced with a serializable form.\n *\n * The original `input` object is not mutated. This method will shallowly clones all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * @param input - The mostly-plain object\n * @param context - The handle context for the container\n * @param bind - Bind any other handles we find in the object against this given handle.\n * @returns The fully-plain object\n */\nexport function makeHandlesSerializable(\n value: any,\n serializer: IFluidSerializer,\n bind: IFluidHandle,\n) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return serializer.encode(\n value,\n bind);\n}\n\n/**\n * Given a fully-plain object that may have serializable-form handles within, will return the mostly-plain object\n * with handle objects created instead.\n * @param value - The fully-plain object\n * @param serializer - The serializer that knows how to convert serializable-form handles into handle objects\n * @param context - The handle context for the container\n * @returns The mostly-plain object with handle objects within\n */\nexport function parseHandles(\n value: any,\n serializer: IFluidSerializer,\n) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value !== undefined ? serializer.parse(JSON.stringify(value)) : value;\n}\n\n/**\n * Create a new summary containing one blob\n * @param key - the key for the blob in the summary\n * @param content - blob content\n * @returns The summary containing the blob\n */\nexport function createSingleBlobSummary(key: string, content: string | Uint8Array): ISummaryTreeWithStats {\n const builder = new SummaryTreeBuilder();\n builder.addBlob(key, content);\n return builder.getSummaryTree();\n}\n"]}
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
|
package/lib/index.js
CHANGED
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport * from \"./sharedObject\";\nexport * from \"./summarySerializer\";\nexport * from \"./types\";\nexport * from \"./utils\";\nexport * from \"./valueType\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport * from \"./serializer\";\nexport * from \"./sharedObject\";\nexport * from \"./summarySerializer\";\nexport * from \"./types\";\nexport * from \"./utils\";\nexport * from \"./valueType\";\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/shared-object-base";
|
|
8
|
-
export declare const pkgVersion = "0.
|
|
8
|
+
export declare const pkgVersion = "0.55.0-48551";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/lib/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,oCAAoC,CAAC;AAC5D,MAAM,CAAC,MAAM,UAAU,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/shared-object-base\";\nexport const pkgVersion = \"0.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,oCAAoC,CAAC;AAC5D,MAAM,CAAC,MAAM,UAAU,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/shared-object-base\";\nexport const pkgVersion = \"0.55.0-48551\";\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { IFluidHandle, IFluidHandleContext, IRequest, IResponse } from "@fluidframework/core-interfaces";
|
|
6
|
+
/**
|
|
7
|
+
* This handle is used to dynamically load a Fluid object on a remote client and is created on parsing a serialized
|
|
8
|
+
* FluidObjectHandle.
|
|
9
|
+
* This class is used to generate an IFluidHandle when de-serializing any all handles (including handles to DDSs, custom
|
|
10
|
+
* objects) that are stored in SharedObjects. The Data Store or SharedObject corresponding to the IFluidHandle can be
|
|
11
|
+
* retrieved by calling `get` on it.
|
|
12
|
+
*/
|
|
13
|
+
export declare class RemoteFluidObjectHandle implements IFluidHandle {
|
|
14
|
+
readonly absolutePath: string;
|
|
15
|
+
readonly routeContext: IFluidHandleContext;
|
|
16
|
+
get IFluidRouter(): this;
|
|
17
|
+
get IFluidHandleContext(): this;
|
|
18
|
+
get IFluidHandle(): this;
|
|
19
|
+
readonly isAttached = true;
|
|
20
|
+
private objectP;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new RemoteFluidObjectHandle when parsing an IFluidHandle.
|
|
23
|
+
* @param absolutePath - The absolute path to the handle from the container runtime.
|
|
24
|
+
* @param routeContext - The root IFluidHandleContext that has a route to this handle.
|
|
25
|
+
*/
|
|
26
|
+
constructor(absolutePath: string, routeContext: IFluidHandleContext);
|
|
27
|
+
get(): Promise<any>;
|
|
28
|
+
attachGraph(): void;
|
|
29
|
+
bind(handle: IFluidHandle): void;
|
|
30
|
+
request(request: IRequest): Promise<IResponse>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=remoteObjectHandle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remoteObjectHandle.d.ts","sourceRoot":"","sources":["../src/remoteObjectHandle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACH,YAAY,EACZ,mBAAmB,EACnB,QAAQ,EACR,SAAS,EAGZ,MAAM,iCAAiC,CAAC;AAGzC;;;;;;GAMG;AACH,qBAAa,uBAAwB,YAAW,YAAY;aAcpC,YAAY,EAAE,MAAM;aACpB,YAAY,EAAE,mBAAmB;IAdrD,IAAW,YAAY,SAAmB;IAC1C,IAAW,mBAAmB,SAAmB;IACjD,IAAW,YAAY,SAAmB;IAE1C,SAAgB,UAAU,QAAQ;IAClC,OAAO,CAAC,OAAO,CAAmC;IAElD;;;;OAIG;gBAEiB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,mBAAmB;IAKxC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IAezB,WAAW,IAAI,IAAI;IAInB,IAAI,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAI1B,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;CAY9D"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { assert } from "@fluidframework/common-utils";
|
|
6
|
+
import { create404Response, exceptionToResponse, responseToException } from "@fluidframework/runtime-utils";
|
|
7
|
+
/**
|
|
8
|
+
* This handle is used to dynamically load a Fluid object on a remote client and is created on parsing a serialized
|
|
9
|
+
* FluidObjectHandle.
|
|
10
|
+
* This class is used to generate an IFluidHandle when de-serializing any all handles (including handles to DDSs, custom
|
|
11
|
+
* objects) that are stored in SharedObjects. The Data Store or SharedObject corresponding to the IFluidHandle can be
|
|
12
|
+
* retrieved by calling `get` on it.
|
|
13
|
+
*/
|
|
14
|
+
export class RemoteFluidObjectHandle {
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new RemoteFluidObjectHandle when parsing an IFluidHandle.
|
|
17
|
+
* @param absolutePath - The absolute path to the handle from the container runtime.
|
|
18
|
+
* @param routeContext - The root IFluidHandleContext that has a route to this handle.
|
|
19
|
+
*/
|
|
20
|
+
constructor(absolutePath, routeContext) {
|
|
21
|
+
this.absolutePath = absolutePath;
|
|
22
|
+
this.routeContext = routeContext;
|
|
23
|
+
this.isAttached = true;
|
|
24
|
+
assert(absolutePath.startsWith("/"), 0x19d /* "Handles should always have absolute paths" */);
|
|
25
|
+
}
|
|
26
|
+
get IFluidRouter() { return this; }
|
|
27
|
+
get IFluidHandleContext() { return this; }
|
|
28
|
+
get IFluidHandle() { return this; }
|
|
29
|
+
async get() {
|
|
30
|
+
if (this.objectP === undefined) {
|
|
31
|
+
const request = { url: this.absolutePath };
|
|
32
|
+
this.objectP = this.routeContext.resolveHandle(request)
|
|
33
|
+
.then((response) => {
|
|
34
|
+
if (response.mimeType === "fluid/object") {
|
|
35
|
+
const fluidObject = response.value;
|
|
36
|
+
return fluidObject;
|
|
37
|
+
}
|
|
38
|
+
throw responseToException(response, request);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return this.objectP;
|
|
42
|
+
}
|
|
43
|
+
attachGraph() {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
bind(handle) {
|
|
47
|
+
handle.attachGraph();
|
|
48
|
+
}
|
|
49
|
+
async request(request) {
|
|
50
|
+
try {
|
|
51
|
+
const object = await this.get();
|
|
52
|
+
const router = object.IFluidRouter;
|
|
53
|
+
return router !== undefined
|
|
54
|
+
? router.request(request)
|
|
55
|
+
: create404Response(request);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
return exceptionToResponse(error);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=remoteObjectHandle.js.map
|
|
@@ -0,0 +1 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AC;IACxB,CAAC;IAEM,WAAW;QACd,OAAO;IACX,CAAC;IAEM,IAAI,CAAC,MAAoB;QAC5B,MAAM,CAAC,WAAW,EAAE,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,OAAiB;QAClC,IAAI;YACA,MAAM,MAAM,GAA8B,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;YAC3D,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC;YAEnC,OAAO,MAAM,KAAK,SAAS;gBACvB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;gBACzB,CAAC,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;SACpC;QAAC,OAAO,KAAK,EAAE;YACZ,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAC;SACrC;IACL,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport {\n IFluidHandle,\n IFluidHandleContext,\n IRequest,\n IResponse,\n FluidObject,\n IFluidRouter,\n} from \"@fluidframework/core-interfaces\";\nimport { create404Response, exceptionToResponse, responseToException } from \"@fluidframework/runtime-utils\";\n\n/**\n * This handle is used to dynamically load a Fluid object on a remote client and is created on parsing a serialized\n * FluidObjectHandle.\n * This class is used to generate an IFluidHandle when de-serializing any all handles (including handles to DDSs, custom\n * objects) that are stored in SharedObjects. The Data Store or SharedObject corresponding to the IFluidHandle can be\n * retrieved by calling `get` on it.\n */\nexport class RemoteFluidObjectHandle implements IFluidHandle {\n public get IFluidRouter() { return this; }\n public get IFluidHandleContext() { return this; }\n public get IFluidHandle() { return this; }\n\n public readonly isAttached = true;\n private objectP: Promise<FluidObject> | undefined;\n\n /**\n * Creates a new RemoteFluidObjectHandle when parsing an IFluidHandle.\n * @param absolutePath - The absolute path to the handle from the container runtime.\n * @param routeContext - The root IFluidHandleContext that has a route to this handle.\n */\n constructor(\n public readonly absolutePath: string,\n public readonly routeContext: IFluidHandleContext,\n ) {\n assert(absolutePath.startsWith(\"/\"), 0x19d /* \"Handles should always have absolute paths\" */);\n }\n\n public async get(): Promise<any> {\n if (this.objectP === undefined) {\n const request = { url: this.absolutePath };\n this.objectP = this.routeContext.resolveHandle(request)\n .then<FluidObject>((response) => {\n if (response.mimeType === \"fluid/object\") {\n const fluidObject: FluidObject = response.value;\n return fluidObject;\n }\n throw responseToException(response, request);\n });\n }\n return this.objectP;\n }\n\n public attachGraph(): void {\n return;\n }\n\n public bind(handle: IFluidHandle): void {\n handle.attachGraph();\n }\n\n public async request(request: IRequest): Promise<IResponse> {\n try {\n const object: FluidObject<IFluidRouter> = await this.get();\n const router = object.IFluidRouter;\n\n return router !== undefined\n ? router.request(request)\n : create404Response(request);\n } catch (error) {\n return exceptionToResponse(error);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { IFluidHandle, IFluidHandleContext } from "@fluidframework/core-interfaces";
|
|
6
|
+
/**
|
|
7
|
+
* JSON serialized form of an IFluidHandle
|
|
8
|
+
*/
|
|
9
|
+
export interface ISerializedHandle {
|
|
10
|
+
type: "__fluid_handle__";
|
|
11
|
+
url: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const isSerializedHandle: (value: any) => value is ISerializedHandle;
|
|
14
|
+
export interface IFluidSerializer {
|
|
15
|
+
/**
|
|
16
|
+
* Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object
|
|
17
|
+
* where any embedded IFluidHandles have been replaced with a serializable form.
|
|
18
|
+
*
|
|
19
|
+
* The original `input` object is not mutated. This method will shallowly clones all objects in the path from
|
|
20
|
+
* the root to any replaced handles. (If no handles are found, returns the original object.)
|
|
21
|
+
*/
|
|
22
|
+
encode(value: any, bind: IFluidHandle): any;
|
|
23
|
+
/**
|
|
24
|
+
* Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an
|
|
25
|
+
* equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.
|
|
26
|
+
*
|
|
27
|
+
* The original `input` object is not mutated. This method will shallowly clone all objects in the path from
|
|
28
|
+
* the root to any replaced handles. (If no handles are found, returns the original object.)
|
|
29
|
+
*
|
|
30
|
+
* The decoded handles are implicitly bound to the handle context of this serializer.
|
|
31
|
+
*/
|
|
32
|
+
decode(input: any): any;
|
|
33
|
+
/**
|
|
34
|
+
* Stringifies a given value. Converts any IFluidHandle to its stringified equivalent.
|
|
35
|
+
*/
|
|
36
|
+
stringify(value: any, bind: IFluidHandle): string;
|
|
37
|
+
/**
|
|
38
|
+
* Parses the given JSON input string and returns the JavaScript object defined by it. Any Fluid
|
|
39
|
+
* handles will be realized as part of the parse
|
|
40
|
+
*/
|
|
41
|
+
parse(value: string): any;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Data Store serializer implementation
|
|
45
|
+
*/
|
|
46
|
+
export declare class FluidSerializer implements IFluidSerializer {
|
|
47
|
+
private readonly context;
|
|
48
|
+
private readonly handleParsedCb;
|
|
49
|
+
private readonly root;
|
|
50
|
+
constructor(context: IFluidHandleContext, handleParsedCb: (handle: IFluidHandle) => void);
|
|
51
|
+
get IFluidSerializer(): this;
|
|
52
|
+
/**
|
|
53
|
+
* Given a mostly-jsonable object tree that may have handle objects embedded within, will return a
|
|
54
|
+
* fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.
|
|
55
|
+
*
|
|
56
|
+
* The original `input` object is not mutated. This method will shallowly clone all objects in the path from
|
|
57
|
+
* the root to any replaced handles. (If no handles are found, returns the original object.)
|
|
58
|
+
*
|
|
59
|
+
* Any unbound handles encountered are bound to the provided IFluidHandle.
|
|
60
|
+
*/
|
|
61
|
+
encode(input: any, bind: IFluidHandle): any;
|
|
62
|
+
/**
|
|
63
|
+
* Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an
|
|
64
|
+
* equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.
|
|
65
|
+
*
|
|
66
|
+
* The original `input` object is not mutated. This method will shallowly clone all objects in the path from
|
|
67
|
+
* the root to any replaced handles. (If no handles are found, returns the original object.)
|
|
68
|
+
*
|
|
69
|
+
* The decoded handles are implicitly bound to the handle context of this serializer.
|
|
70
|
+
*/
|
|
71
|
+
decode(input: any): any;
|
|
72
|
+
stringify(input: any, bind: IFluidHandle): string;
|
|
73
|
+
parse(input: string): any;
|
|
74
|
+
private readonly encodeValue;
|
|
75
|
+
private readonly decodeValue;
|
|
76
|
+
private recursivelyReplace;
|
|
77
|
+
protected serializeHandle(handle: IFluidHandle, bind: IFluidHandle): {
|
|
78
|
+
type: string;
|
|
79
|
+
url: string;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=serializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAGpF;;GAEG;AACF,MAAM,WAAW,iBAAiB;IAE/B,IAAI,EAAE,kBAAkB,CAAC;IAGzB,GAAG,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,kBAAkB,UAAW,GAAG,+BACP,CAAC;AAEvC,MAAM,WAAW,gBAAgB;IAC7B;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,GAAG,GAAG,CAAC;IAE5C;;;;;;;;OAQG;IACH,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,GAAG,CAAC;IAExB;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,GAAG,MAAM,CAAC;IAElD;;;OAGG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC;CAC7B;AAED;;GAEG;AACH,qBAAa,eAAgB,YAAW,gBAAgB;IAIhD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAExB,OAAO,CAAC,QAAQ,CAAC,cAAc;IALnC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAsB;gBAGtB,OAAO,EAAE,mBAAmB,EAE5B,cAAc,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI;IAQnE,IAAW,gBAAgB,SAAmB;IAE9C;;;;;;;;OAQG;IACK,MAAM,CACV,KAAK,EAAE,GAAG,EACV,IAAI,EAAE,YAAY;IAUtB;;;;;;;;OAQG;IACK,MAAM,CAAC,KAAK,EAAE,GAAG;IASlB,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY;IAKxC,KAAK,CAAC,KAAK,EAAE,MAAM;IAM1B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAQ1B;IAIF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAe1B;IAKF,OAAO,CAAC,kBAAkB;IAgD1B,SAAS,CAAC,eAAe,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY;;;;CAOrE"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
// RATIONALE: Many methods consume and return 'any' by necessity.
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
7
|
+
import { generateHandleContextPath } from "@fluidframework/runtime-utils";
|
|
8
|
+
import { RemoteFluidObjectHandle } from "./remoteObjectHandle";
|
|
9
|
+
export const isSerializedHandle = (value) => (value === null || value === void 0 ? void 0 : value.type) === "__fluid_handle__";
|
|
10
|
+
/**
|
|
11
|
+
* Data Store serializer implementation
|
|
12
|
+
*/
|
|
13
|
+
export class FluidSerializer {
|
|
14
|
+
constructor(context,
|
|
15
|
+
// To be called whenever a handle is parsed by this serializer.
|
|
16
|
+
handleParsedCb) {
|
|
17
|
+
this.context = context;
|
|
18
|
+
this.handleParsedCb = handleParsedCb;
|
|
19
|
+
// If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.
|
|
20
|
+
// Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'.
|
|
21
|
+
this.encodeValue = (value, bind) => {
|
|
22
|
+
// Detect if 'value' is an IFluidHandle.
|
|
23
|
+
const handle = value === null || value === void 0 ? void 0 : value.IFluidHandle;
|
|
24
|
+
// If 'value' is an IFluidHandle return its encoded form.
|
|
25
|
+
return handle !== undefined
|
|
26
|
+
? this.serializeHandle(handle, bind)
|
|
27
|
+
: value;
|
|
28
|
+
};
|
|
29
|
+
// If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle.
|
|
30
|
+
// Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'.
|
|
31
|
+
this.decodeValue = (value) => {
|
|
32
|
+
// If 'value' is a serialized IFluidHandle return the deserialized result.
|
|
33
|
+
if (isSerializedHandle(value)) {
|
|
34
|
+
// Old documents may have handles with relative path in their summaries. Convert these to absolute
|
|
35
|
+
// paths. This will ensure that future summaries will have absolute paths for these handles.
|
|
36
|
+
const absolutePath = value.url.startsWith("/")
|
|
37
|
+
? value.url
|
|
38
|
+
: generateHandleContextPath(value.url, this.context);
|
|
39
|
+
const parsedHandle = new RemoteFluidObjectHandle(absolutePath, this.root);
|
|
40
|
+
this.handleParsedCb(parsedHandle);
|
|
41
|
+
return parsedHandle;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
this.root = this.context;
|
|
48
|
+
while (this.root.routeContext !== undefined) {
|
|
49
|
+
this.root = this.root.routeContext;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
get IFluidSerializer() { return this; }
|
|
53
|
+
/**
|
|
54
|
+
* Given a mostly-jsonable object tree that may have handle objects embedded within, will return a
|
|
55
|
+
* fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.
|
|
56
|
+
*
|
|
57
|
+
* The original `input` object is not mutated. This method will shallowly clone all objects in the path from
|
|
58
|
+
* the root to any replaced handles. (If no handles are found, returns the original object.)
|
|
59
|
+
*
|
|
60
|
+
* Any unbound handles encountered are bound to the provided IFluidHandle.
|
|
61
|
+
*/
|
|
62
|
+
encode(input, bind) {
|
|
63
|
+
// If the given 'input' cannot contain handles, return it immediately. Otherwise,
|
|
64
|
+
// return the result of 'recursivelyReplace()'.
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
66
|
+
return !!input && typeof input === "object"
|
|
67
|
+
? this.recursivelyReplace(input, this.encodeValue, bind)
|
|
68
|
+
: input;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an
|
|
72
|
+
* equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.
|
|
73
|
+
*
|
|
74
|
+
* The original `input` object is not mutated. This method will shallowly clone all objects in the path from
|
|
75
|
+
* the root to any replaced handles. (If no handles are found, returns the original object.)
|
|
76
|
+
*
|
|
77
|
+
* The decoded handles are implicitly bound to the handle context of this serializer.
|
|
78
|
+
*/
|
|
79
|
+
decode(input) {
|
|
80
|
+
// If the given 'input' cannot contain handles, return it immediately. Otherwise,
|
|
81
|
+
// return the result of 'recursivelyReplace()'.
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
83
|
+
return !!input && typeof input === "object"
|
|
84
|
+
? this.recursivelyReplace(input, this.decodeValue)
|
|
85
|
+
: input;
|
|
86
|
+
}
|
|
87
|
+
stringify(input, bind) {
|
|
88
|
+
return JSON.stringify(input, (key, value) => this.encodeValue(value, bind));
|
|
89
|
+
}
|
|
90
|
+
// Parses the serialized data - context must match the context with which the JSON was stringified
|
|
91
|
+
parse(input) {
|
|
92
|
+
return JSON.parse(input, (key, value) => this.decodeValue(value));
|
|
93
|
+
}
|
|
94
|
+
// Invoked for non-null objects to recursively replace references to IFluidHandles.
|
|
95
|
+
// Clones as-needed to avoid mutating the `input` object. If no IFluidHandes are present,
|
|
96
|
+
// returns the original `input`.
|
|
97
|
+
recursivelyReplace(input, replacer, context) {
|
|
98
|
+
// Note: Caller is responsible for ensuring that `input` is defined / non-null.
|
|
99
|
+
// (Required for Object.keys() below.)
|
|
100
|
+
// Execute the `replace` on the current input. Note that Caller is responsible for ensuring that `input`
|
|
101
|
+
// is a non-null object.
|
|
102
|
+
const maybeReplaced = replacer(input, context);
|
|
103
|
+
// If the replacer made a substitution there is no need to decscend further. IFluidHandles are always
|
|
104
|
+
// leaves in the object graph.
|
|
105
|
+
if (maybeReplaced !== input) {
|
|
106
|
+
return maybeReplaced;
|
|
107
|
+
}
|
|
108
|
+
// Otherwise descend into the object graph looking for IFluidHandle instances.
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
110
|
+
let clone;
|
|
111
|
+
for (const key of Object.keys(input)) {
|
|
112
|
+
const value = input[key];
|
|
113
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
114
|
+
if (!!value && typeof value === "object") {
|
|
115
|
+
// Note: Except for IFluidHandle, `input` must not contain circular references (as object must
|
|
116
|
+
// be JSON serializable.) Therefore, guarding against infinite recursion here would only
|
|
117
|
+
// lead to a later error when attempting to stringify().
|
|
118
|
+
const replaced = this.recursivelyReplace(value, replacer, context);
|
|
119
|
+
// If the `replaced` object is different than the original `value` then the subgraph contained one
|
|
120
|
+
// or more handles. If this happens, we need to return a clone of the `input` object where the
|
|
121
|
+
// current property is replaced by the `replaced` value.
|
|
122
|
+
if (replaced !== value) {
|
|
123
|
+
// Lazily create a shallow clone of the `input` object if we haven't done so already.
|
|
124
|
+
clone = clone !== null && clone !== void 0 ? clone : (Array.isArray(input)
|
|
125
|
+
? [...input]
|
|
126
|
+
: Object.assign({}, input));
|
|
127
|
+
// Overwrite the current property `key` in the clone with the `replaced` value.
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
129
|
+
clone[key] = replaced;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return clone !== null && clone !== void 0 ? clone : input;
|
|
134
|
+
}
|
|
135
|
+
serializeHandle(handle, bind) {
|
|
136
|
+
bind.bind(handle);
|
|
137
|
+
return {
|
|
138
|
+
type: "__fluid_handle__",
|
|
139
|
+
url: handle.absolutePath,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=serializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,iEAAiE;AACjE,wDAAwD;AAExD,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAE1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAa/D,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAU,EAA8B,EAAE,CACzE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,MAAK,kBAAkB,CAAC;AAmCvC;;GAEG;AACH,MAAM,OAAO,eAAe;IAGxB,YACqB,OAA4B;IAC7C,+DAA+D;IAC9C,cAA8C;QAF9C,YAAO,GAAP,OAAO,CAAqB;QAE5B,mBAAc,GAAd,cAAc,CAAgC;QA0DnE,6EAA6E;QAC7E,iFAAiF;QAChE,gBAAW,GAAG,CAAC,KAAU,EAAE,IAAkB,EAAE,EAAE;YAC9D,wCAAwC;YACxC,MAAM,MAAM,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,YAAY,CAAC;YAEnC,yDAAyD;YACzD,OAAO,MAAM,KAAK,SAAS;gBACvB,CAAC,CAAC,IAAI,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,QAAQ,EAAE;gBACtC,8FAA8F;gBAC9F,+FAA+F;gBAC/F,8DAA8D;gBAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;gBAEnE,kGAAkG;gBAClG,+FAA+F;gBAC/F,wDAAwD;gBACxD,IAAI,QAAQ,KAAK,KAAK,EAAE;oBACpB,qFAAqF;oBACrF,KAAK,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;wBAClC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;wBACZ,CAAC,mBAAM,KAAK,CAAE,CAAC,CAAC;oBAEpB,+EAA+E;oBAC/E,oEAAoE;oBACpE,KAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;iBAC1B;aACJ;SACJ;QACD,OAAO,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,KAAK,CAAC;IAC1B,CAAC;IAES,eAAe,CAAC,MAAoB,EAAE,IAAkB;QAC9D,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClB,OAAO;YACH,IAAI,EAAE,kBAAkB;YACxB,GAAG,EAAE,MAAM,CAAC,YAAY;SAC3B,CAAC;IACN,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// RATIONALE: Many methods consume and return 'any' by necessity.\n/* eslint-disable @typescript-eslint/no-unsafe-return */\n\nimport { generateHandleContextPath } from \"@fluidframework/runtime-utils\";\nimport { IFluidHandle, IFluidHandleContext } from \"@fluidframework/core-interfaces\";\nimport { RemoteFluidObjectHandle } from \"./remoteObjectHandle\";\n\n/**\n * JSON serialized form of an IFluidHandle\n */\n export interface ISerializedHandle {\n // Marker to indicate to JSON.parse that the object is a Fluid handle\n type: \"__fluid_handle__\";\n\n // URL to the object. Relative URLs are relative to the handle context passed to the stringify.\n url: string;\n}\n\nexport const isSerializedHandle = (value: any): value is ISerializedHandle =>\n value?.type === \"__fluid_handle__\";\n\nexport interface IFluidSerializer {\n /**\n * Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object\n * where any embedded IFluidHandles have been replaced with a serializable form.\n *\n * The original `input` object is not mutated. This method will shallowly clones all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n */\n encode(value: any, bind: IFluidHandle): any;\n\n /**\n * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n *\n * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * The decoded handles are implicitly bound to the handle context of this serializer.\n */\n decode(input: any): any;\n\n /**\n * Stringifies a given value. Converts any IFluidHandle to its stringified equivalent.\n */\n stringify(value: any, bind: IFluidHandle): string;\n\n /**\n * Parses the given JSON input string and returns the JavaScript object defined by it. Any Fluid\n * handles will be realized as part of the parse\n */\n parse(value: string): any;\n}\n\n/**\n * Data Store serializer implementation\n */\nexport class FluidSerializer implements IFluidSerializer {\n private readonly root: IFluidHandleContext;\n\n public constructor(\n private readonly context: IFluidHandleContext,\n // To be called whenever a handle is parsed by this serializer.\n private readonly handleParsedCb: (handle: IFluidHandle) => void,\n ) {\n this.root = this.context;\n while (this.root.routeContext !== undefined) {\n this.root = this.root.routeContext;\n }\n }\n\n public get IFluidSerializer() { return this; }\n\n /**\n * Given a mostly-jsonable object tree that may have handle objects embedded within, will return a\n * fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.\n *\n * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * Any unbound handles encountered are bound to the provided IFluidHandle.\n */\n public encode(\n input: any,\n bind: IFluidHandle,\n ) {\n // If the given 'input' cannot contain handles, return it immediately. Otherwise,\n // return the result of 'recursivelyReplace()'.\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n return !!input && typeof input === \"object\"\n ? this.recursivelyReplace(input, this.encodeValue, bind)\n : input;\n }\n\n /**\n * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n *\n * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * The decoded handles are implicitly bound to the handle context of this serializer.\n */\n public decode(input: any) {\n // If the given 'input' cannot contain handles, return it immediately. Otherwise,\n // return the result of 'recursivelyReplace()'.\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n return !!input && typeof input === \"object\"\n ? this.recursivelyReplace(input, this.decodeValue)\n : input;\n }\n\n public stringify(input: any, bind: IFluidHandle) {\n return JSON.stringify(input, (key, value) => this.encodeValue(value, bind));\n }\n\n // Parses the serialized data - context must match the context with which the JSON was stringified\n public parse(input: string) {\n return JSON.parse(input, (key, value) => this.decodeValue(value));\n }\n\n // If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.\n // Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'.\n private readonly encodeValue = (value: any, bind: IFluidHandle) => {\n // Detect if 'value' is an IFluidHandle.\n const handle = value?.IFluidHandle;\n\n // If 'value' is an IFluidHandle return its encoded form.\n return handle !== undefined\n ? this.serializeHandle(handle, bind)\n : value;\n };\n\n // If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle.\n // Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'.\n private readonly decodeValue = (value: any) => {\n // If 'value' is a serialized IFluidHandle return the deserialized result.\n if (isSerializedHandle(value)) {\n // Old documents may have handles with relative path in their summaries. Convert these to absolute\n // paths. This will ensure that future summaries will have absolute paths for these handles.\n const absolutePath = value.url.startsWith(\"/\")\n ? value.url\n : generateHandleContextPath(value.url, this.context);\n\n const parsedHandle = new RemoteFluidObjectHandle(absolutePath, this.root);\n this.handleParsedCb(parsedHandle);\n return parsedHandle;\n } else {\n return value;\n }\n };\n\n // Invoked for non-null objects to recursively replace references to IFluidHandles.\n // Clones as-needed to avoid mutating the `input` object. If no IFluidHandes are present,\n // returns the original `input`.\n private recursivelyReplace(\n input: any,\n replacer: (input: any, context: any) => any,\n context?: any,\n ) {\n // Note: Caller is responsible for ensuring that `input` is defined / non-null.\n // (Required for Object.keys() below.)\n\n // Execute the `replace` on the current input. Note that Caller is responsible for ensuring that `input`\n // is a non-null object.\n const maybeReplaced = replacer(input, context);\n\n // If the replacer made a substitution there is no need to decscend further. IFluidHandles are always\n // leaves in the object graph.\n if (maybeReplaced !== input) {\n return maybeReplaced;\n }\n\n // Otherwise descend into the object graph looking for IFluidHandle instances.\n // eslint-disable-next-line @typescript-eslint/ban-types\n let clone: object | undefined;\n for (const key of Object.keys(input)) {\n const value = input[key];\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n if (!!value && typeof value === \"object\") {\n // Note: Except for IFluidHandle, `input` must not contain circular references (as object must\n // be JSON serializable.) Therefore, guarding against infinite recursion here would only\n // lead to a later error when attempting to stringify().\n const replaced = this.recursivelyReplace(value, replacer, context);\n\n // If the `replaced` object is different than the original `value` then the subgraph contained one\n // or more handles. If this happens, we need to return a clone of the `input` object where the\n // current property is replaced by the `replaced` value.\n if (replaced !== value) {\n // Lazily create a shallow clone of the `input` object if we haven't done so already.\n clone = clone ?? (Array.isArray(input)\n ? [...input]\n : { ...input });\n\n // Overwrite the current property `key` in the clone with the `replaced` value.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n clone![key] = replaced;\n }\n }\n }\n return clone ?? input;\n }\n\n protected serializeHandle(handle: IFluidHandle, bind: IFluidHandle) {\n bind.bind(handle);\n return {\n type: \"__fluid_handle__\",\n url: handle.absolutePath,\n };\n }\n}\n"]}
|
package/lib/sharedObject.d.ts
CHANGED
|
@@ -3,16 +3,18 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
6
|
-
import { IFluidHandle
|
|
6
|
+
import { IFluidHandle } from "@fluidframework/core-interfaces";
|
|
7
7
|
import { IChannelAttributes, IFluidDataStoreRuntime, IChannelStorageService, IChannelServices } from "@fluidframework/datastore-definitions";
|
|
8
|
-
import { ISequencedDocumentMessage
|
|
8
|
+
import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
9
9
|
import { IGarbageCollectionData, ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
|
|
10
10
|
import { EventEmitterWithErrorHandling } from "@fluidframework/telemetry-utils";
|
|
11
|
+
import { IFluidSerializer } from "./serializer";
|
|
12
|
+
import { SummarySerializer } from "./summarySerializer";
|
|
11
13
|
import { ISharedObject, ISharedObjectEvents } from "./types";
|
|
12
14
|
/**
|
|
13
15
|
* Base class from which all shared objects derive
|
|
14
16
|
*/
|
|
15
|
-
export declare abstract class
|
|
17
|
+
export declare abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISharedObjectEvents> extends EventEmitterWithErrorHandling<TEvent> implements ISharedObject<TEvent> {
|
|
16
18
|
id: string;
|
|
17
19
|
protected runtime: IFluidDataStoreRuntime;
|
|
18
20
|
readonly attributes: IChannelAttributes;
|
|
@@ -20,7 +22,7 @@ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents =
|
|
|
20
22
|
* @param obj - The thing to check if it is a SharedObject
|
|
21
23
|
* @returns Returns true if the thing is a SharedObject
|
|
22
24
|
*/
|
|
23
|
-
static is(obj: any): obj is
|
|
25
|
+
static is(obj: any): obj is SharedObjectCore;
|
|
24
26
|
get ISharedObject(): this;
|
|
25
27
|
get IChannel(): this;
|
|
26
28
|
get IFluidLoadable(): this;
|
|
@@ -44,10 +46,6 @@ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents =
|
|
|
44
46
|
* True if the dds is bound to its parent.
|
|
45
47
|
*/
|
|
46
48
|
private _isBoundToContext;
|
|
47
|
-
/**
|
|
48
|
-
* True while we are summarizing this object's data.
|
|
49
|
-
*/
|
|
50
|
-
private _isSummarizing;
|
|
51
49
|
/**
|
|
52
50
|
* Tracks error that closed this object.
|
|
53
51
|
*/
|
|
@@ -57,11 +55,6 @@ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents =
|
|
|
57
55
|
* @returns The state of the connection
|
|
58
56
|
*/
|
|
59
57
|
get connected(): boolean;
|
|
60
|
-
protected get serializer(): IFluidSerializer;
|
|
61
|
-
/**
|
|
62
|
-
* The serializer to use to serialize / parse handles, if any.
|
|
63
|
-
*/
|
|
64
|
-
private readonly _serializer;
|
|
65
58
|
/**
|
|
66
59
|
* @param id - The id of the shared object
|
|
67
60
|
* @param runtime - The IFluidDataStoreRuntime which contains the shared object
|
|
@@ -114,30 +107,23 @@ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents =
|
|
|
114
107
|
*/
|
|
115
108
|
isAttached(): boolean;
|
|
116
109
|
/**
|
|
117
|
-
* {@inheritDoc (ISharedObject:interface).
|
|
110
|
+
* {@inheritDoc (ISharedObject:interface).getAttachSummary}
|
|
118
111
|
*/
|
|
119
|
-
|
|
112
|
+
abstract getAttachSummary(fullTree?: boolean, trackState?: boolean): ISummaryTreeWithStats;
|
|
120
113
|
/**
|
|
121
|
-
* {@inheritDoc (ISharedObject:interface).
|
|
114
|
+
* {@inheritDoc (ISharedObject:interface).summarize}
|
|
122
115
|
*/
|
|
123
|
-
|
|
116
|
+
abstract summarize(fullTree?: boolean, trackState?: boolean): Promise<ISummaryTreeWithStats>;
|
|
124
117
|
/**
|
|
125
|
-
*
|
|
126
|
-
* other GC nodes.
|
|
127
|
-
* Derived classes must override this to provide custom list of references to other GC nodes.
|
|
118
|
+
* {@inheritDoc (ISharedObject:interface).getGCData}
|
|
128
119
|
*/
|
|
129
|
-
|
|
120
|
+
abstract getGCData(fullGC?: boolean): IGarbageCollectionData;
|
|
130
121
|
/**
|
|
131
122
|
* Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference
|
|
132
123
|
* to another object in the container.
|
|
133
124
|
* @param decodedHandle - The handle of the Fluid object that is decoded.
|
|
134
125
|
*/
|
|
135
126
|
protected handleDecoded(decodedHandle: IFluidHandle): void;
|
|
136
|
-
/**
|
|
137
|
-
* Gets a form of the object that can be serialized.
|
|
138
|
-
* @returns A tree representing the snapshot of the shared object.
|
|
139
|
-
*/
|
|
140
|
-
protected abstract snapshotCore(serializer: IFluidSerializer): ITree;
|
|
141
127
|
/**
|
|
142
128
|
* Allows the distributed data type to perform custom loading
|
|
143
129
|
* @param services - Storage used by the shared object
|
|
@@ -225,4 +211,46 @@ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents =
|
|
|
225
211
|
private reSubmit;
|
|
226
212
|
protected abstract applyStashedOp(content: any): unknown;
|
|
227
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* SharedObject with simplified, synchronous summarization and GC
|
|
216
|
+
*/
|
|
217
|
+
export declare abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents> extends SharedObjectCore<TEvent> {
|
|
218
|
+
/**
|
|
219
|
+
* True while we are garbage collecting this object's data.
|
|
220
|
+
*/
|
|
221
|
+
private _isGCing;
|
|
222
|
+
/**
|
|
223
|
+
* The serializer to use to serialize / parse handles, if any.
|
|
224
|
+
*/
|
|
225
|
+
private readonly _serializer;
|
|
226
|
+
protected get serializer(): IFluidSerializer;
|
|
227
|
+
/**
|
|
228
|
+
* @param id - The id of the shared object
|
|
229
|
+
* @param runtime - The IFluidDataStoreRuntime which contains the shared object
|
|
230
|
+
* @param attributes - Attributes of the shared object
|
|
231
|
+
*/
|
|
232
|
+
constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
|
|
233
|
+
/**
|
|
234
|
+
* {@inheritDoc (ISharedObject:interface).getAttachSummary}
|
|
235
|
+
*/
|
|
236
|
+
getAttachSummary(fullTree?: boolean, trackState?: boolean): ISummaryTreeWithStats;
|
|
237
|
+
/**
|
|
238
|
+
* {@inheritDoc (ISharedObject:interface).summarize}
|
|
239
|
+
*/
|
|
240
|
+
summarize(fullTree?: boolean, trackState?: boolean): Promise<ISummaryTreeWithStats>;
|
|
241
|
+
/**
|
|
242
|
+
* {@inheritDoc (ISharedObject:interface).getGCData}
|
|
243
|
+
*/
|
|
244
|
+
getGCData(fullGC?: boolean): IGarbageCollectionData;
|
|
245
|
+
/**
|
|
246
|
+
* Calls the serializer over all data in this object that reference other GC nodes.
|
|
247
|
+
* Derived classes must override this to provide custom list of references to other GC nodes.
|
|
248
|
+
*/
|
|
249
|
+
protected processGCDataCore(serializer: SummarySerializer): void;
|
|
250
|
+
/**
|
|
251
|
+
* Gets a form of the object that can be serialized.
|
|
252
|
+
* @returns A tree representing the snapshot of the shared object.
|
|
253
|
+
*/
|
|
254
|
+
protected abstract summarizeCore(serializer: IFluidSerializer, fullTree: boolean): ISummaryTreeWithStats;
|
|
255
|
+
}
|
|
228
256
|
//# sourceMappingURL=sharedObject.d.ts.map
|