@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/.eslintrc.js
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { IFluidHandle } from "@fluidframework/core-interfaces";
|
|
7
|
+
import { Suite } from "benchmark";
|
|
8
|
+
import { FluidSerializer } from "../..";
|
|
9
|
+
import { makeJson, MockHandleContext } from "../../src/test/utils";
|
|
10
|
+
import { consume, runSuites } from "./util";
|
|
11
|
+
|
|
12
|
+
const serializer = new FluidSerializer(new MockHandleContext(), (handle: IFluidHandle) => {});
|
|
13
|
+
|
|
14
|
+
// Mock Fluid handle
|
|
15
|
+
const handle: IFluidHandle = {
|
|
16
|
+
get IFluidHandle() { return handle; },
|
|
17
|
+
absolutePath: "/",
|
|
18
|
+
isAttached: false,
|
|
19
|
+
|
|
20
|
+
attachGraph(): void { },
|
|
21
|
+
get: async () => Promise.resolve(undefined as any),
|
|
22
|
+
bind() {},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const shallowNoHandles = makeJson(/* breadth: */ 2, /* depth: */ 2, () => ({}));
|
|
26
|
+
const deepWithHandles = makeJson(/* breadth: */ 8, /* depth: */ 8, () => handle);
|
|
27
|
+
|
|
28
|
+
const shallowNoHandlesString = serializer.stringify(shallowNoHandles, handle);
|
|
29
|
+
const deepWithHandlesString = serializer.stringify(deepWithHandles, handle);
|
|
30
|
+
|
|
31
|
+
const measureReplaceHandles = (name: string, value: any) => new Suite(`encode Handles: ${name}`)
|
|
32
|
+
.add("encode(...)", () => {
|
|
33
|
+
consume(serializer.encode(value, handle));
|
|
34
|
+
})
|
|
35
|
+
.add("parse(stringify(...))", () => {
|
|
36
|
+
consume(serializer.parse(serializer.stringify(value, handle)));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const measureStringify = (name: string, value: any) => new Suite(`Stringify: ${name}`)
|
|
40
|
+
.add("JSON.stringify(encode(...))", () => {
|
|
41
|
+
consume(JSON.stringify(serializer.encode(value, handle)));
|
|
42
|
+
})
|
|
43
|
+
.add("stringify(...)", () => {
|
|
44
|
+
consume(serializer.stringify(value, handle));
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const measureParse = (name: string, value: any) => new Suite(`Parse: ${name}`)
|
|
48
|
+
.add("parse(...)", () => {
|
|
49
|
+
consume(serializer.parse(value));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
runSuites([
|
|
53
|
+
measureReplaceHandles("primitive", 0),
|
|
54
|
+
measureReplaceHandles("shallow (no handles)", shallowNoHandles),
|
|
55
|
+
measureReplaceHandles("deep (with handles)", deepWithHandles),
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
runSuites([
|
|
59
|
+
measureStringify("primitive", 0),
|
|
60
|
+
measureStringify("shallow (no handles)", shallowNoHandles),
|
|
61
|
+
measureStringify("deep (with handles)", deepWithHandles),
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
runSuites([
|
|
65
|
+
measureParse("primitive", "0"),
|
|
66
|
+
measureParse("shallow (no handles)", shallowNoHandlesString),
|
|
67
|
+
measureParse("deep (with handles)", deepWithHandlesString),
|
|
68
|
+
]);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/* eslint-disable no-bitwise */
|
|
7
|
+
|
|
8
|
+
// This file contains some helpers creating/executing benchmark suites using 'Benchmark.js'.
|
|
9
|
+
|
|
10
|
+
import process = require("process");
|
|
11
|
+
import { Suite } from "benchmark";
|
|
12
|
+
|
|
13
|
+
let count = 0;
|
|
14
|
+
let cached: any;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Paranoid defense against dead code elimination.
|
|
18
|
+
*/
|
|
19
|
+
export function consume(value: any) {
|
|
20
|
+
count++;
|
|
21
|
+
if ((count >>> 0) === 0) {
|
|
22
|
+
cached = value;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Prevent v8's optimizer from identifying 'cached' as an unused value.
|
|
27
|
+
process.on("exit", () => {
|
|
28
|
+
if ((count >>> 0) === 0) {
|
|
29
|
+
console.log(`Ignore this: ${cached}`);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export function runSuite(suite: Suite) {
|
|
34
|
+
count = 0;
|
|
35
|
+
|
|
36
|
+
console.log();
|
|
37
|
+
console.group((suite as any).name);
|
|
38
|
+
return suite
|
|
39
|
+
.on("cycle", (event: any) => {
|
|
40
|
+
console.log(String(event.target));
|
|
41
|
+
})
|
|
42
|
+
.on("error", (event: any) => {
|
|
43
|
+
console.error(String(event.target.error));
|
|
44
|
+
})
|
|
45
|
+
.on("complete", (event: any) => {
|
|
46
|
+
console.groupEnd();
|
|
47
|
+
console.log(`Fastest is ${event.currentTarget.filter("fastest").map("name")}`);
|
|
48
|
+
})
|
|
49
|
+
.run();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function runSuites(suites: Iterable<Suite>) {
|
|
53
|
+
for (const suite of suites) {
|
|
54
|
+
runSuite(suite);
|
|
55
|
+
}
|
|
56
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/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/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./serializer"), exports);
|
|
17
18
|
__exportStar(require("./sharedObject"), exports);
|
|
18
19
|
__exportStar(require("./summarySerializer"), exports);
|
|
19
20
|
__exportStar(require("./types"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH,iDAA+B;AAC/B,sDAAoC;AACpC,0CAAwB;AACxB,0CAAwB;AACxB,8CAA4B","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,+CAA6B;AAC7B,iDAA+B;AAC/B,sDAAoC;AACpC,0CAAwB;AACxB,0CAAwB;AACxB,8CAA4B","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/dist/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/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/shared-object-base";
|
|
11
|
-
exports.pkgVersion = "0.
|
|
11
|
+
exports.pkgVersion = "0.55.0-48551";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,oCAAoC,CAAC;AAC/C,QAAA,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;;;AAEU,QAAA,OAAO,GAAG,oCAAoC,CAAC;AAC/C,QAAA,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,66 @@
|
|
|
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.RemoteFluidObjectHandle = void 0;
|
|
8
|
+
const common_utils_1 = require("@fluidframework/common-utils");
|
|
9
|
+
const runtime_utils_1 = require("@fluidframework/runtime-utils");
|
|
10
|
+
/**
|
|
11
|
+
* This handle is used to dynamically load a Fluid object on a remote client and is created on parsing a serialized
|
|
12
|
+
* FluidObjectHandle.
|
|
13
|
+
* This class is used to generate an IFluidHandle when de-serializing any all handles (including handles to DDSs, custom
|
|
14
|
+
* objects) that are stored in SharedObjects. The Data Store or SharedObject corresponding to the IFluidHandle can be
|
|
15
|
+
* retrieved by calling `get` on it.
|
|
16
|
+
*/
|
|
17
|
+
class RemoteFluidObjectHandle {
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new RemoteFluidObjectHandle when parsing an IFluidHandle.
|
|
20
|
+
* @param absolutePath - The absolute path to the handle from the container runtime.
|
|
21
|
+
* @param routeContext - The root IFluidHandleContext that has a route to this handle.
|
|
22
|
+
*/
|
|
23
|
+
constructor(absolutePath, routeContext) {
|
|
24
|
+
this.absolutePath = absolutePath;
|
|
25
|
+
this.routeContext = routeContext;
|
|
26
|
+
this.isAttached = true;
|
|
27
|
+
common_utils_1.assert(absolutePath.startsWith("/"), 0x19d /* "Handles should always have absolute paths" */);
|
|
28
|
+
}
|
|
29
|
+
get IFluidRouter() { return this; }
|
|
30
|
+
get IFluidHandleContext() { return this; }
|
|
31
|
+
get IFluidHandle() { return this; }
|
|
32
|
+
async get() {
|
|
33
|
+
if (this.objectP === undefined) {
|
|
34
|
+
const request = { url: this.absolutePath };
|
|
35
|
+
this.objectP = this.routeContext.resolveHandle(request)
|
|
36
|
+
.then((response) => {
|
|
37
|
+
if (response.mimeType === "fluid/object") {
|
|
38
|
+
const fluidObject = response.value;
|
|
39
|
+
return fluidObject;
|
|
40
|
+
}
|
|
41
|
+
throw runtime_utils_1.responseToException(response, request);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return this.objectP;
|
|
45
|
+
}
|
|
46
|
+
attachGraph() {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
bind(handle) {
|
|
50
|
+
handle.attachGraph();
|
|
51
|
+
}
|
|
52
|
+
async request(request) {
|
|
53
|
+
try {
|
|
54
|
+
const object = await this.get();
|
|
55
|
+
const router = object.IFluidRouter;
|
|
56
|
+
return router !== undefined
|
|
57
|
+
? router.request(request)
|
|
58
|
+
: runtime_utils_1.create404Response(request);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return runtime_utils_1.exceptionToResponse(error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.RemoteFluidObjectHandle = RemoteFluidObjectHandle;
|
|
66
|
+
//# sourceMappingURL=remoteObjectHandle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remoteObjectHandle.js","sourceRoot":"","sources":["../src/remoteObjectHandle.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AAStD,iEAA4G;AAE5G;;;;;;GAMG;AACH,MAAa,uBAAuB;IAQhC;;;;OAIG;IACH,YACoB,YAAoB,EACpB,YAAiC;QADjC,iBAAY,GAAZ,YAAY,CAAQ;QACpB,iBAAY,GAAZ,YAAY,CAAqB;QAVrC,eAAU,GAAG,IAAI,CAAC;QAY9B,qBAAM,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,iDAAiD,CAAC,CAAC;IAClG,CAAC;IAjBD,IAAW,YAAY,KAAK,OAAO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poration 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
|
+
//# sour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AM;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,148 @@
|
|
|
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.FluidSerializer = exports.isSerializedHandle = void 0;
|
|
8
|
+
// RATIONALE: Many methods consume and return 'any' by necessity.
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
10
|
+
const runtime_utils_1 = require("@fluidframework/runtime-utils");
|
|
11
|
+
const remoteObjectHandle_1 = require("./remoteObjectHandle");
|
|
12
|
+
const isSerializedHandle = (value) => (value === null || value === void 0 ? void 0 : value.type) === "__fluid_handle__";
|
|
13
|
+
exports.isSerializedHandle = isSerializedHandle;
|
|
14
|
+
/**
|
|
15
|
+
* Data Store serializer implementation
|
|
16
|
+
*/
|
|
17
|
+
class FluidSerializer {
|
|
18
|
+
constructor(context,
|
|
19
|
+
// To be called whenever a handle is parsed by this serializer.
|
|
20
|
+
handleParsedCb) {
|
|
21
|
+
this.context = context;
|
|
22
|
+
this.handleParsedCb = handleParsedCb;
|
|
23
|
+
// If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.
|
|
24
|
+
// Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'.
|
|
25
|
+
this.encodeValue = (value, bind) => {
|
|
26
|
+
// Detect if 'value' is an IFluidHandle.
|
|
27
|
+
const handle = value === null || value === void 0 ? void 0 : value.IFluidHandle;
|
|
28
|
+
// If 'value' is an IFluidHandle return its encoded form.
|
|
29
|
+
return handle !== undefined
|
|
30
|
+
? this.serializeHandle(handle, bind)
|
|
31
|
+
: value;
|
|
32
|
+
};
|
|
33
|
+
// If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle.
|
|
34
|
+
// Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'.
|
|
35
|
+
this.decodeValue = (value) => {
|
|
36
|
+
// If 'value' is a serialized IFluidHandle return the deserialized result.
|
|
37
|
+
if (exports.isSerializedHandle(value)) {
|
|
38
|
+
// Old documents may have handles with relative path in their summaries. Convert these to absolute
|
|
39
|
+
// paths. This will ensure that future summaries will have absolute paths for these handles.
|
|
40
|
+
const absolutePath = value.url.startsWith("/")
|
|
41
|
+
? value.url
|
|
42
|
+
: runtime_utils_1.generateHandleContextPath(value.url, this.context);
|
|
43
|
+
const parsedHandle = new remoteObjectHandle_1.RemoteFluidObjectHandle(absolutePath, this.root);
|
|
44
|
+
this.handleParsedCb(parsedHandle);
|
|
45
|
+
return parsedHandle;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
this.root = this.context;
|
|
52
|
+
while (this.root.routeContext !== undefined) {
|
|
53
|
+
this.root = this.root.routeContext;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
get IFluidSerializer() { return this; }
|
|
57
|
+
/**
|
|
58
|
+
* Given a mostly-jsonable object tree that may have handle objects embedded within, will return a
|
|
59
|
+
* fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.
|
|
60
|
+
*
|
|
61
|
+
* The original `input` object is not mutated. This method will shallowly clone all objects in the path from
|
|
62
|
+
* the root to any replaced handles. (If no handles are found, returns the original object.)
|
|
63
|
+
*
|
|
64
|
+
* Any unbound handles encountered are bound to the provided IFluidHandle.
|
|
65
|
+
*/
|
|
66
|
+
encode(input, bind) {
|
|
67
|
+
// If the given 'input' cannot contain handles, return it immediately. Otherwise,
|
|
68
|
+
// return the result of 'recursivelyReplace()'.
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
70
|
+
return !!input && typeof input === "object"
|
|
71
|
+
? this.recursivelyReplace(input, this.encodeValue, bind)
|
|
72
|
+
: input;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an
|
|
76
|
+
* equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.
|
|
77
|
+
*
|
|
78
|
+
* The original `input` object is not mutated. This method will shallowly clone all objects in the path from
|
|
79
|
+
* the root to any replaced handles. (If no handles are found, returns the original object.)
|
|
80
|
+
*
|
|
81
|
+
* The decoded handles are implicitly bound to the handle context of this serializer.
|
|
82
|
+
*/
|
|
83
|
+
decode(input) {
|
|
84
|
+
// If the given 'input' cannot contain handles, return it immediately. Otherwise,
|
|
85
|
+
// return the result of 'recursivelyReplace()'.
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
87
|
+
return !!input && typeof input === "object"
|
|
88
|
+
? this.recursivelyReplace(input, this.decodeValue)
|
|
89
|
+
: input;
|
|
90
|
+
}
|
|
91
|
+
stringify(input, bind) {
|
|
92
|
+
return JSON.stringify(input, (key, value) => this.encodeValue(value, bind));
|
|
93
|
+
}
|
|
94
|
+
// Parses the serialized data - context must match the context with which the JSON was stringified
|
|
95
|
+
parse(input) {
|
|
96
|
+
return JSON.parse(input, (key, value) => this.decodeValue(value));
|
|
97
|
+
}
|
|
98
|
+
// Invoked for non-null objects to recursively replace references to IFluidHandles.
|
|
99
|
+
// Clones as-needed to avoid mutating the `input` object. If no IFluidHandes are present,
|
|
100
|
+
// returns the original `input`.
|
|
101
|
+
recursivelyReplace(input, replacer, context) {
|
|
102
|
+
// Note: Caller is responsible for ensuring that `input` is defined / non-null.
|
|
103
|
+
// (Required for Object.keys() below.)
|
|
104
|
+
// Execute the `replace` on the current input. Note that Caller is responsible for ensuring that `input`
|
|
105
|
+
// is a non-null object.
|
|
106
|
+
const maybeReplaced = replacer(input, context);
|
|
107
|
+
// If the replacer made a substitution there is no need to decscend further. IFluidHandles are always
|
|
108
|
+
// leaves in the object graph.
|
|
109
|
+
if (maybeReplaced !== input) {
|
|
110
|
+
return maybeReplaced;
|
|
111
|
+
}
|
|
112
|
+
// Otherwise descend into the object graph looking for IFluidHandle instances.
|
|
113
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
114
|
+
let clone;
|
|
115
|
+
for (const key of Object.keys(input)) {
|
|
116
|
+
const value = input[key];
|
|
117
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
118
|
+
if (!!value && typeof value === "object") {
|
|
119
|
+
// Note: Except for IFluidHandle, `input` must not contain circular references (as object must
|
|
120
|
+
// be JSON serializable.) Therefore, guarding against infinite recursion here would only
|
|
121
|
+
// lead to a later error when attempting to stringify().
|
|
122
|
+
const replaced = this.recursivelyReplace(value, replacer, context);
|
|
123
|
+
// If the `replaced` object is different than the original `value` then the subgraph contained one
|
|
124
|
+
// or more handles. If this happens, we need to return a clone of the `input` object where the
|
|
125
|
+
// current property is replaced by the `replaced` value.
|
|
126
|
+
if (replaced !== value) {
|
|
127
|
+
// Lazily create a shallow clone of the `input` object if we haven't done so already.
|
|
128
|
+
clone = clone !== null && clone !== void 0 ? clone : (Array.isArray(input)
|
|
129
|
+
? [...input]
|
|
130
|
+
: Object.assign({}, input));
|
|
131
|
+
// Overwrite the current property `key` in the clone with the `replaced` value.
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
133
|
+
clone[key] = replaced;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return clone !== null && clone !== void 0 ? clone : input;
|
|
138
|
+
}
|
|
139
|
+
serializeHandle(handle, bind) {
|
|
140
|
+
bind.bind(handle);
|
|
141
|
+
return {
|
|
142
|
+
type: "__fluid_handle__",
|
|
143
|
+
url: handle.absolutePath,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.FluidSerializer = FluidSerializer;
|
|
148
|
+
//# 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,iEAA0E;AAE1E,6DAA+D;AAaxD,MAAM,kBAAkB,GAAG,CAAC,KAAU,EAA8B,EAAE,CACzE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,MAAK,kBAAkB,CAAC;AAD1B,QAAA,kBAAkB,sBACQ;AAmCvC;;GAEG;AACH,MAAa,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,CAAC,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC;gBACpC,CAAC,CAAC,KAAK,CAAC;QAChB,CAAC,CAAC;QAEF,qFAAqF;QACrF,6EAA6E;QAC5D,gBAAW,GAAG,CAAC,KAAU,EAAE,EAAE;YAC1C,0EAA0E;YAC1E,IAAI,0BAAkB,CAAC,KAAK,CAAC,EAAE;gBAC3B,kGAAkG;gBAClG,4FAA4F;gBAC5F,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC;oBAC1C,CAAC,CAAC,KAAK,CAAC,GAAG;oBACX,CAAC,CAAC,yCAAyB,CAAC,KAAK,CA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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;AAzJD,0CAyJC","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"]}
|