@fluidframework/runtime-utils 0.54.0 → 0.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +1 -1
- package/dist/dataStoreHandleContextUtils.d.ts +4 -1
- package/dist/dataStoreHandleContextUtils.d.ts.map +1 -1
- package/dist/dataStoreHandleContextUtils.js +12 -6
- package/dist/dataStoreHandleContextUtils.js.map +1 -1
- package/dist/dataStoreHelpers.d.ts.map +1 -1
- package/dist/dataStoreHelpers.js +0 -1
- package/dist/dataStoreHelpers.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- 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/summarizerNode/summarizerNodeWithGc.d.ts +12 -7
- package/dist/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
- package/dist/summarizerNode/summarizerNodeWithGc.js +28 -19
- package/dist/summarizerNode/summarizerNodeWithGc.js.map +1 -1
- package/dist/utils.d.ts +0 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -3
- package/dist/utils.js.map +1 -1
- package/lib/dataStoreHandleContextUtils.d.ts +4 -1
- package/lib/dataStoreHandleContextUtils.d.ts.map +1 -1
- package/lib/dataStoreHandleContextUtils.js +12 -6
- package/lib/dataStoreHandleContextUtils.js.map +1 -1
- package/lib/dataStoreHelpers.d.ts.map +1 -1
- package/lib/dataStoreHelpers.js +0 -1
- package/lib/dataStoreHelpers.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/summarizerNode/summarizerNodeWithGc.d.ts +12 -7
- package/lib/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
- package/lib/summarizerNode/summarizerNodeWithGc.js +28 -19
- package/lib/summarizerNode/summarizerNodeWithGc.js.map +1 -1
- package/lib/utils.d.ts +0 -2
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +0 -1
- package/lib/utils.js.map +1 -1
- package/package.json +17 -19
- package/src/dataStoreHandleContextUtils.ts +13 -8
- package/src/dataStoreHelpers.ts +0 -1
- package/src/index.ts +0 -1
- package/src/packageVersion.ts +1 -1
- package/src/summarizerNode/summarizerNodeWithGc.ts +35 -24
- package/src/utils.ts +0 -4
- package/bench/src/index.ts +0 -68
- package/bench/src/util.ts +0 -56
- package/dist/remoteObjectHandle.d.ts +0 -32
- package/dist/remoteObjectHandle.d.ts.map +0 -1
- package/dist/remoteObjectHandle.js +0 -66
- package/dist/remoteObjectHandle.js.map +0 -1
- package/dist/serializer.d.ts +0 -45
- package/dist/serializer.d.ts.map +0 -1
- package/dist/serializer.js +0 -145
- package/dist/serializer.js.map +0 -1
- package/lib/remoteObjectHandle.d.ts +0 -32
- package/lib/remoteObjectHandle.d.ts.map +0 -1
- package/lib/remoteObjectHandle.js +0 -62
- package/lib/remoteObjectHandle.js.map +0 -1
- package/lib/serializer.d.ts +0 -45
- package/lib/serializer.d.ts.map +0 -1
- package/lib/serializer.js +0 -141
- package/lib/serializer.js.map +0 -1
- package/src/remoteObjectHandle.ts +0 -79
- package/src/serializer.ts +0 -174
|
@@ -1,32 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,62 +0,0 @@
|
|
|
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 "./dataStoreHelpers";
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remoteObjectHandle.js","sourceRoot":"","sources":["../src/remoteObjectHandle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAStD,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEjG;;;;;;GAMG;AACH,MAAM,OAAO,uBAAuB;IAQhC;;;;OAIG;IACH,YACoB,YAAoB,EACpB,YAAiC;QADjC,iBAAY,GAAZ,YAAY,CAAQ;QACpB,iBAAY,GAAZ,YAAY,CAAqB;QAVrC,eAAU,GAAG,IAAI,CAAC;QAY9B,MAAM,CAAC,YAAY,CAAC,UAAU,CA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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 \"./dataStoreHelpers\";\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"]}
|
package/lib/serializer.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { IFluidHandle, IFluidHandleContext, IFluidSerializer } from "@fluidframework/core-interfaces";
|
|
6
|
-
/**
|
|
7
|
-
* Data Store serializer implementation
|
|
8
|
-
*/
|
|
9
|
-
export declare class FluidSerializer implements IFluidSerializer {
|
|
10
|
-
private readonly context;
|
|
11
|
-
private readonly handleParsedCb;
|
|
12
|
-
private readonly root;
|
|
13
|
-
constructor(context: IFluidHandleContext, handleParsedCb: (handle: IFluidHandle) => void);
|
|
14
|
-
get IFluidSerializer(): this;
|
|
15
|
-
/**
|
|
16
|
-
* Given a mostly-jsonable object tree that may have handle objects embedded within, will return a
|
|
17
|
-
* fully-jsonable object tree 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
|
-
* Any unbound handles encountered are bound to the provided IFluidHandle.
|
|
23
|
-
*/
|
|
24
|
-
replaceHandles(input: any, bind: IFluidHandle): any;
|
|
25
|
-
/**
|
|
26
|
-
* Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an
|
|
27
|
-
* equivalent object tree where any encoded IFluidHandles have been replaced with thier decoded form.
|
|
28
|
-
*
|
|
29
|
-
* The original `input` object is not mutated. This method will shallowly clones all objects in the path from
|
|
30
|
-
* the root to any replaced handles. (If no handles are found, returns the original object.)
|
|
31
|
-
*
|
|
32
|
-
* The decoded handles are implicitly bound to the handle context of this serializer.
|
|
33
|
-
*/
|
|
34
|
-
decode(input: any): any;
|
|
35
|
-
stringify(input: any, bind: IFluidHandle): string;
|
|
36
|
-
parse(input: string): any;
|
|
37
|
-
private readonly encodeValue;
|
|
38
|
-
private readonly decodeValue;
|
|
39
|
-
private recursivelyReplace;
|
|
40
|
-
protected serializeHandle(handle: IFluidHandle, bind: IFluidHandle): {
|
|
41
|
-
type: string;
|
|
42
|
-
url: string;
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=serializer.d.ts.map
|
package/lib/serializer.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EACH,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EACnB,MAAM,iCAAiC,CAAC;AAKzC;;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,cAAc,CAClB,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"}
|
package/lib/serializer.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { RemoteFluidObjectHandle } from "./remoteObjectHandle";
|
|
6
|
-
import { generateHandleContextPath } from "./dataStoreHandleContextUtils";
|
|
7
|
-
import { isSerializedHandle } from "./utils";
|
|
8
|
-
/**
|
|
9
|
-
* Data Store serializer implementation
|
|
10
|
-
*/
|
|
11
|
-
export class FluidSerializer {
|
|
12
|
-
constructor(context,
|
|
13
|
-
// To be called whenever a handle is parsed by this serializer.
|
|
14
|
-
handleParsedCb) {
|
|
15
|
-
this.context = context;
|
|
16
|
-
this.handleParsedCb = handleParsedCb;
|
|
17
|
-
// If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.
|
|
18
|
-
// Otherwise returns the original 'value'. Used by 'replaceHandles()' and 'stringify()'.
|
|
19
|
-
this.encodeValue = (value, bind) => {
|
|
20
|
-
// Detect if 'value' is an IFluidHandle.
|
|
21
|
-
const handle = value === null || value === void 0 ? void 0 : value.IFluidHandle;
|
|
22
|
-
// If 'value' is an IFluidHandle return its encoded form.
|
|
23
|
-
return handle !== undefined
|
|
24
|
-
? this.serializeHandle(handle, bind)
|
|
25
|
-
: value;
|
|
26
|
-
};
|
|
27
|
-
// If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle.
|
|
28
|
-
// Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'.
|
|
29
|
-
this.decodeValue = (value) => {
|
|
30
|
-
// If 'value' is a serialized IFluidHandle return the deserialized result.
|
|
31
|
-
if (isSerializedHandle(value)) {
|
|
32
|
-
// Old documents may have handles with relative path in their summaries. Convert these to absolute
|
|
33
|
-
// paths. This will ensure that future summaries will have absolute paths for these handles.
|
|
34
|
-
const absolutePath = value.url.startsWith("/")
|
|
35
|
-
? value.url
|
|
36
|
-
: generateHandleContextPath(value.url, this.context);
|
|
37
|
-
const parsedHandle = new RemoteFluidObjectHandle(absolutePath, this.root);
|
|
38
|
-
this.handleParsedCb(parsedHandle);
|
|
39
|
-
return parsedHandle;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
return value;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
this.root = this.context;
|
|
46
|
-
while (this.root.routeContext !== undefined) {
|
|
47
|
-
this.root = this.root.routeContext;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
get IFluidSerializer() { return this; }
|
|
51
|
-
/**
|
|
52
|
-
* Given a mostly-jsonable object tree that may have handle objects embedded within, will return a
|
|
53
|
-
* fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.
|
|
54
|
-
*
|
|
55
|
-
* The original `input` object is not mutated. This method will shallowly clones all objects in the path from
|
|
56
|
-
* the root to any replaced handles. (If no handles are found, returns the original object.)
|
|
57
|
-
*
|
|
58
|
-
* Any unbound handles encountered are bound to the provided IFluidHandle.
|
|
59
|
-
*/
|
|
60
|
-
replaceHandles(input, bind) {
|
|
61
|
-
// If the given 'input' cannot contain handles, return it immediately. Otherwise,
|
|
62
|
-
// return the result of 'recursivelyReplace()'.
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
64
|
-
return !!input && typeof input === "object"
|
|
65
|
-
? this.recursivelyReplace(input, this.encodeValue, bind)
|
|
66
|
-
: input;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an
|
|
70
|
-
* equivalent object tree where any encoded IFluidHandles have been replaced with thier decoded form.
|
|
71
|
-
*
|
|
72
|
-
* The original `input` object is not mutated. This method will shallowly clones all objects in the path from
|
|
73
|
-
* the root to any replaced handles. (If no handles are found, returns the original object.)
|
|
74
|
-
*
|
|
75
|
-
* The decoded handles are implicitly bound to the handle context of this serializer.
|
|
76
|
-
*/
|
|
77
|
-
decode(input) {
|
|
78
|
-
// If the given 'input' cannot contain handles, return it immediately. Otherwise,
|
|
79
|
-
// return the result of 'recursivelyReplace()'.
|
|
80
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
81
|
-
return !!input && typeof input === "object"
|
|
82
|
-
? this.recursivelyReplace(input, this.decodeValue)
|
|
83
|
-
: input;
|
|
84
|
-
}
|
|
85
|
-
stringify(input, bind) {
|
|
86
|
-
return JSON.stringify(input, (key, value) => this.encodeValue(value, bind));
|
|
87
|
-
}
|
|
88
|
-
// Parses the serialized data - context must match the context with which the JSON was stringified
|
|
89
|
-
parse(input) {
|
|
90
|
-
return JSON.parse(input, (key, value) => this.decodeValue(value));
|
|
91
|
-
}
|
|
92
|
-
// Invoked for non-null objects to recursively replace references to IFluidHandles.
|
|
93
|
-
// Clones as-needed to avoid mutating the `input` object. If no IFluidHandes are present,
|
|
94
|
-
// returns the original `input`.
|
|
95
|
-
recursivelyReplace(input, replacer, context) {
|
|
96
|
-
// Note: Caller is responsible for ensuring that `input` is defined / non-null.
|
|
97
|
-
// (Required for Object.keys() below.)
|
|
98
|
-
// Execute the `replace` on the current input. Note that Caller is responsible for ensuring that `input`
|
|
99
|
-
// is a non-null object.
|
|
100
|
-
const maybeReplaced = replacer(input, context);
|
|
101
|
-
// If the replacer made a substitution there is no need to decscend further. IFluidHandles are always
|
|
102
|
-
// leaves in the object graph.
|
|
103
|
-
if (maybeReplaced !== input) {
|
|
104
|
-
return maybeReplaced;
|
|
105
|
-
}
|
|
106
|
-
// Otherwise descend into the object graph looking for IFluidHandle instances.
|
|
107
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
108
|
-
let clone;
|
|
109
|
-
for (const key of Object.keys(input)) {
|
|
110
|
-
const value = input[key];
|
|
111
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
112
|
-
if (!!value && typeof value === "object") {
|
|
113
|
-
// Note: Except for IFluidHandle, `input` must not contain circular references (as object must
|
|
114
|
-
// be JSON serializable.) Therefore, guarding against infinite recursion here would only
|
|
115
|
-
// lead to a later error when attempting to stringify().
|
|
116
|
-
const replaced = this.recursivelyReplace(value, replacer, context);
|
|
117
|
-
// If the `replaced` object is different than the original `value` then the subgraph contained one
|
|
118
|
-
// or more handles. If this happens, we need to return a clone of the `input` object where the
|
|
119
|
-
// current property is replaced by the `replaced` value.
|
|
120
|
-
if (replaced !== value) {
|
|
121
|
-
// Lazily create a shallow clone of the `input` object if we haven't done so already.
|
|
122
|
-
clone = clone !== null && clone !== void 0 ? clone : (Array.isArray(input)
|
|
123
|
-
? [...input]
|
|
124
|
-
: Object.assign({}, input));
|
|
125
|
-
// Overwrite the current property `key` in the clone with the `replaced` value.
|
|
126
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
127
|
-
clone[key] = replaced;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return clone !== null && clone !== void 0 ? clone : input;
|
|
132
|
-
}
|
|
133
|
-
serializeHandle(handle, bind) {
|
|
134
|
-
bind.bind(handle);
|
|
135
|
-
return {
|
|
136
|
-
type: "__fluid_handle__",
|
|
137
|
-
url: handle.absolutePath,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
//# sourceMappingURL=serializer.js.map
|
package/lib/serializer.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C;;GAEG;AACH,MAAM,OAAO,eAAe;IAGxB,YACqB,OAA4B;IAC7C,+DAA+D;IAC9C,cAA8C;QAF9C,YAAO,GAAP,OAAO,CAAqB;QAE5B,mBAAc,GAAd,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a,CAAC;SACxB;QAED,8EAA8E;QAC9E,wDAAwD;QACxD,IAAI,KAAyB,CAAC;QAC9B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YAClC,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YACzB,yEAAyE;YACzE,IAAI,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,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 {\n IFluidHandle,\n IFluidHandleContext,\n IFluidSerializer,\n} from \"@fluidframework/core-interfaces\";\nimport { RemoteFluidObjectHandle } from \"./remoteObjectHandle\";\nimport { generateHandleContextPath } from \"./dataStoreHandleContextUtils\";\nimport { isSerializedHandle } from \"./utils\";\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 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 * Any unbound handles encountered are bound to the provided IFluidHandle.\n */\n public replaceHandles(\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 thier decoded 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 * 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 'replaceHandles()' 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"]}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { assert } from "@fluidframework/common-utils";
|
|
7
|
-
import {
|
|
8
|
-
IFluidHandle,
|
|
9
|
-
IFluidHandleContext,
|
|
10
|
-
IRequest,
|
|
11
|
-
IResponse,
|
|
12
|
-
FluidObject,
|
|
13
|
-
IFluidRouter,
|
|
14
|
-
} from "@fluidframework/core-interfaces";
|
|
15
|
-
import { create404Response, exceptionToResponse, responseToException } from "./dataStoreHelpers";
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* This handle is used to dynamically load a Fluid object on a remote client and is created on parsing a serialized
|
|
19
|
-
* FluidObjectHandle.
|
|
20
|
-
* This class is used to generate an IFluidHandle when de-serializing any all handles (including handles to DDSs, custom
|
|
21
|
-
* objects) that are stored in SharedObjects. The Data Store or SharedObject corresponding to the IFluidHandle can be
|
|
22
|
-
* retrieved by calling `get` on it.
|
|
23
|
-
*/
|
|
24
|
-
export class RemoteFluidObjectHandle implements IFluidHandle {
|
|
25
|
-
public get IFluidRouter() { return this; }
|
|
26
|
-
public get IFluidHandleContext() { return this; }
|
|
27
|
-
public get IFluidHandle() { return this; }
|
|
28
|
-
|
|
29
|
-
public readonly isAttached = true;
|
|
30
|
-
private objectP: Promise<FluidObject> | undefined;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Creates a new RemoteFluidObjectHandle when parsing an IFluidHandle.
|
|
34
|
-
* @param absolutePath - The absolute path to the handle from the container runtime.
|
|
35
|
-
* @param routeContext - The root IFluidHandleContext that has a route to this handle.
|
|
36
|
-
*/
|
|
37
|
-
constructor(
|
|
38
|
-
public readonly absolutePath: string,
|
|
39
|
-
public readonly routeContext: IFluidHandleContext,
|
|
40
|
-
) {
|
|
41
|
-
assert(absolutePath.startsWith("/"), 0x19d /* "Handles should always have absolute paths" */);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public async get(): Promise<any> {
|
|
45
|
-
if (this.objectP === undefined) {
|
|
46
|
-
const request = { url: this.absolutePath };
|
|
47
|
-
this.objectP = this.routeContext.resolveHandle(request)
|
|
48
|
-
.then<FluidObject>((response) => {
|
|
49
|
-
if (response.mimeType === "fluid/object") {
|
|
50
|
-
const fluidObject: FluidObject = response.value;
|
|
51
|
-
return fluidObject;
|
|
52
|
-
}
|
|
53
|
-
throw responseToException(response, request);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return this.objectP;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public attachGraph(): void {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public bind(handle: IFluidHandle): void {
|
|
64
|
-
handle.attachGraph();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
public async request(request: IRequest): Promise<IResponse> {
|
|
68
|
-
try {
|
|
69
|
-
const object: FluidObject<IFluidRouter> = await this.get();
|
|
70
|
-
const router = object.IFluidRouter;
|
|
71
|
-
|
|
72
|
-
return router !== undefined
|
|
73
|
-
? router.request(request)
|
|
74
|
-
: create404Response(request);
|
|
75
|
-
} catch (error) {
|
|
76
|
-
return exceptionToResponse(error);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
package/src/serializer.ts
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// RATIONALE: Many methods consume and return 'any' by necessity.
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
IFluidHandle,
|
|
11
|
-
IFluidHandleContext,
|
|
12
|
-
IFluidSerializer,
|
|
13
|
-
} from "@fluidframework/core-interfaces";
|
|
14
|
-
import { RemoteFluidObjectHandle } from "./remoteObjectHandle";
|
|
15
|
-
import { generateHandleContextPath } from "./dataStoreHandleContextUtils";
|
|
16
|
-
import { isSerializedHandle } from "./utils";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Data Store serializer implementation
|
|
20
|
-
*/
|
|
21
|
-
export class FluidSerializer implements IFluidSerializer {
|
|
22
|
-
private readonly root: IFluidHandleContext;
|
|
23
|
-
|
|
24
|
-
public constructor(
|
|
25
|
-
private readonly context: IFluidHandleContext,
|
|
26
|
-
// To be called whenever a handle is parsed by this serializer.
|
|
27
|
-
private readonly handleParsedCb: (handle: IFluidHandle) => void,
|
|
28
|
-
) {
|
|
29
|
-
this.root = this.context;
|
|
30
|
-
while (this.root.routeContext !== undefined) {
|
|
31
|
-
this.root = this.root.routeContext;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public get IFluidSerializer() { return this; }
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Given a mostly-jsonable object tree that may have handle objects embedded within, will return a
|
|
39
|
-
* fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.
|
|
40
|
-
*
|
|
41
|
-
* The original `input` object is not mutated. This method will shallowly clones all objects in the path from
|
|
42
|
-
* the root to any replaced handles. (If no handles are found, returns the original object.)
|
|
43
|
-
*
|
|
44
|
-
* Any unbound handles encountered are bound to the provided IFluidHandle.
|
|
45
|
-
*/
|
|
46
|
-
public replaceHandles(
|
|
47
|
-
input: any,
|
|
48
|
-
bind: IFluidHandle,
|
|
49
|
-
) {
|
|
50
|
-
// If the given 'input' cannot contain handles, return it immediately. Otherwise,
|
|
51
|
-
// return the result of 'recursivelyReplace()'.
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
53
|
-
return !!input && typeof input === "object"
|
|
54
|
-
? this.recursivelyReplace(input, this.encodeValue, bind)
|
|
55
|
-
: input;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an
|
|
60
|
-
* equivalent object tree where any encoded IFluidHandles have been replaced with thier decoded form.
|
|
61
|
-
*
|
|
62
|
-
* The original `input` object is not mutated. This method will shallowly clones all objects in the path from
|
|
63
|
-
* the root to any replaced handles. (If no handles are found, returns the original object.)
|
|
64
|
-
*
|
|
65
|
-
* The decoded handles are implicitly bound to the handle context of this serializer.
|
|
66
|
-
*/
|
|
67
|
-
public decode(input: any) {
|
|
68
|
-
// If the given 'input' cannot contain handles, return it immediately. Otherwise,
|
|
69
|
-
// return the result of 'recursivelyReplace()'.
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
71
|
-
return !!input && typeof input === "object"
|
|
72
|
-
? this.recursivelyReplace(input, this.decodeValue)
|
|
73
|
-
: input;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
public stringify(input: any, bind: IFluidHandle) {
|
|
77
|
-
return JSON.stringify(input, (key, value) => this.encodeValue(value, bind));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Parses the serialized data - context must match the context with which the JSON was stringified
|
|
81
|
-
public parse(input: string) {
|
|
82
|
-
return JSON.parse(input, (key, value) => this.decodeValue(value));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.
|
|
86
|
-
// Otherwise returns the original 'value'. Used by 'replaceHandles()' and 'stringify()'.
|
|
87
|
-
private readonly encodeValue = (value: any, bind: IFluidHandle) => {
|
|
88
|
-
// Detect if 'value' is an IFluidHandle.
|
|
89
|
-
const handle = value?.IFluidHandle;
|
|
90
|
-
|
|
91
|
-
// If 'value' is an IFluidHandle return its encoded form.
|
|
92
|
-
return handle !== undefined
|
|
93
|
-
? this.serializeHandle(handle, bind)
|
|
94
|
-
: value;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle.
|
|
98
|
-
// Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'.
|
|
99
|
-
private readonly decodeValue = (value: any) => {
|
|
100
|
-
// If 'value' is a serialized IFluidHandle return the deserialized result.
|
|
101
|
-
if (isSerializedHandle(value)) {
|
|
102
|
-
// Old documents may have handles with relative path in their summaries. Convert these to absolute
|
|
103
|
-
// paths. This will ensure that future summaries will have absolute paths for these handles.
|
|
104
|
-
const absolutePath = value.url.startsWith("/")
|
|
105
|
-
? value.url
|
|
106
|
-
: generateHandleContextPath(value.url, this.context);
|
|
107
|
-
|
|
108
|
-
const parsedHandle = new RemoteFluidObjectHandle(absolutePath, this.root);
|
|
109
|
-
this.handleParsedCb(parsedHandle);
|
|
110
|
-
return parsedHandle;
|
|
111
|
-
} else {
|
|
112
|
-
return value;
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// Invoked for non-null objects to recursively replace references to IFluidHandles.
|
|
117
|
-
// Clones as-needed to avoid mutating the `input` object. If no IFluidHandes are present,
|
|
118
|
-
// returns the original `input`.
|
|
119
|
-
private recursivelyReplace(
|
|
120
|
-
input: any,
|
|
121
|
-
replacer: (input: any, context: any) => any,
|
|
122
|
-
context?: any,
|
|
123
|
-
) {
|
|
124
|
-
// Note: Caller is responsible for ensuring that `input` is defined / non-null.
|
|
125
|
-
// (Required for Object.keys() below.)
|
|
126
|
-
|
|
127
|
-
// Execute the `replace` on the current input. Note that Caller is responsible for ensuring that `input`
|
|
128
|
-
// is a non-null object.
|
|
129
|
-
const maybeReplaced = replacer(input, context);
|
|
130
|
-
|
|
131
|
-
// If the replacer made a substitution there is no need to decscend further. IFluidHandles are always
|
|
132
|
-
// leaves in the object graph.
|
|
133
|
-
if (maybeReplaced !== input) {
|
|
134
|
-
return maybeReplaced;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Otherwise descend into the object graph looking for IFluidHandle instances.
|
|
138
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
139
|
-
let clone: object | undefined;
|
|
140
|
-
for (const key of Object.keys(input)) {
|
|
141
|
-
const value = input[key];
|
|
142
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
143
|
-
if (!!value && typeof value === "object") {
|
|
144
|
-
// Note: Except for IFluidHandle, `input` must not contain circular references (as object must
|
|
145
|
-
// be JSON serializable.) Therefore, guarding against infinite recursion here would only
|
|
146
|
-
// lead to a later error when attempting to stringify().
|
|
147
|
-
const replaced = this.recursivelyReplace(value, replacer, context);
|
|
148
|
-
|
|
149
|
-
// If the `replaced` object is different than the original `value` then the subgraph contained one
|
|
150
|
-
// or more handles. If this happens, we need to return a clone of the `input` object where the
|
|
151
|
-
// current property is replaced by the `replaced` value.
|
|
152
|
-
if (replaced !== value) {
|
|
153
|
-
// Lazily create a shallow clone of the `input` object if we haven't done so already.
|
|
154
|
-
clone = clone ?? (Array.isArray(input)
|
|
155
|
-
? [...input]
|
|
156
|
-
: { ...input });
|
|
157
|
-
|
|
158
|
-
// Overwrite the current property `key` in the clone with the `replaced` value.
|
|
159
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
160
|
-
clone![key] = replaced;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return clone ?? input;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
protected serializeHandle(handle: IFluidHandle, bind: IFluidHandle) {
|
|
168
|
-
bind.bind(handle);
|
|
169
|
-
return {
|
|
170
|
-
type: "__fluid_handle__",
|
|
171
|
-
url: handle.absolutePath,
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
}
|