@fluidframework/runtime-utils 0.54.2 → 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.
Files changed (74) hide show
  1. package/.eslintrc.js +1 -1
  2. package/dist/dataStoreHandleContextUtils.d.ts +4 -1
  3. package/dist/dataStoreHandleContextUtils.d.ts.map +1 -1
  4. package/dist/dataStoreHandleContextUtils.js +12 -6
  5. package/dist/dataStoreHandleContextUtils.js.map +1 -1
  6. package/dist/dataStoreHelpers.d.ts.map +1 -1
  7. package/dist/dataStoreHelpers.js +0 -1
  8. package/dist/dataStoreHelpers.js.map +1 -1
  9. package/dist/index.d.ts +0 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +0 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/packageVersion.d.ts +1 -1
  14. package/dist/packageVersion.d.ts.map +1 -1
  15. package/dist/packageVersion.js +1 -1
  16. package/dist/packageVersion.js.map +1 -1
  17. package/dist/summarizerNode/summarizerNodeWithGc.d.ts +12 -7
  18. package/dist/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  19. package/dist/summarizerNode/summarizerNodeWithGc.js +28 -19
  20. package/dist/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  21. package/dist/utils.d.ts +0 -2
  22. package/dist/utils.d.ts.map +1 -1
  23. package/dist/utils.js +1 -3
  24. package/dist/utils.js.map +1 -1
  25. package/lib/dataStoreHandleContextUtils.d.ts +4 -1
  26. package/lib/dataStoreHandleContextUtils.d.ts.map +1 -1
  27. package/lib/dataStoreHandleContextUtils.js +12 -6
  28. package/lib/dataStoreHandleContextUtils.js.map +1 -1
  29. package/lib/dataStoreHelpers.d.ts.map +1 -1
  30. package/lib/dataStoreHelpers.js +0 -1
  31. package/lib/dataStoreHelpers.js.map +1 -1
  32. package/lib/index.d.ts +0 -1
  33. package/lib/index.d.ts.map +1 -1
  34. package/lib/index.js +0 -1
  35. package/lib/index.js.map +1 -1
  36. package/lib/packageVersion.d.ts +1 -1
  37. package/lib/packageVersion.d.ts.map +1 -1
  38. package/lib/packageVersion.js +1 -1
  39. package/lib/packageVersion.js.map +1 -1
  40. package/lib/summarizerNode/summarizerNodeWithGc.d.ts +12 -7
  41. package/lib/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  42. package/lib/summarizerNode/summarizerNodeWithGc.js +28 -19
  43. package/lib/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  44. package/lib/utils.d.ts +0 -2
  45. package/lib/utils.d.ts.map +1 -1
  46. package/lib/utils.js +0 -1
  47. package/lib/utils.js.map +1 -1
  48. package/package.json +17 -19
  49. package/src/dataStoreHandleContextUtils.ts +13 -8
  50. package/src/dataStoreHelpers.ts +0 -1
  51. package/src/index.ts +0 -1
  52. package/src/packageVersion.ts +1 -1
  53. package/src/summarizerNode/summarizerNodeWithGc.ts +35 -24
  54. package/src/utils.ts +0 -4
  55. package/bench/src/index.ts +0 -68
  56. package/bench/src/util.ts +0 -56
  57. package/dist/remoteObjectHandle.d.ts +0 -32
  58. package/dist/remoteObjectHandle.d.ts.map +0 -1
  59. package/dist/remoteObjectHandle.js +0 -66
  60. package/dist/remoteObjectHandle.js.map +0 -1
  61. package/dist/serializer.d.ts +0 -45
  62. package/dist/serializer.d.ts.map +0 -1
  63. package/dist/serializer.js +0 -145
  64. package/dist/serializer.js.map +0 -1
  65. package/lib/remoteObjectHandle.d.ts +0 -32
  66. package/lib/remoteObjectHandle.d.ts.map +0 -1
  67. package/lib/remoteObjectHandle.js +0 -62
  68. package/lib/remoteObjectHandle.js.map +0 -1
  69. package/lib/serializer.d.ts +0 -45
  70. package/lib/serializer.d.ts.map +0 -1
  71. package/lib/serializer.js +0 -141
  72. package/lib/serializer.js.map +0 -1
  73. package/src/remoteObjectHandle.ts +0 -79
  74. package/src/serializer.ts +0 -174
package/src/index.ts CHANGED
@@ -9,7 +9,6 @@ export * from "./objectstoragepartition";
9
9
  export * from "./objectstorageutils";
10
10
  export * from "./requestParser";
11
11
  export * from "./runtimeFactoryHelper";
12
- export * from "./serializer";
13
12
  export * from "./summarizerNode";
14
13
  export * from "./summaryUtils";
15
14
  export * from "./utils";
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/runtime-utils";
9
- export const pkgVersion = "0.54.2";
9
+ export const pkgVersion = "0.55.0-48551";
@@ -11,6 +11,7 @@ import {
11
11
  CreateChildSummarizerNodeParam,
12
12
  gcBlobKey,
13
13
  IGarbageCollectionData,
14
+ IGarbageCollectionDetailsBase,
14
15
  IGarbageCollectionSummaryDetails,
15
16
  ISummarizeInternalResult,
16
17
  ISummarizeResult,
@@ -60,8 +61,11 @@ export class SummarizerNodeWithGC extends SummarizerNode implements IRootSummari
60
61
  // This is the last known used routes of this node as seen by the server as part of a summary.
61
62
  private referenceUsedRoutes: string[] | undefined;
62
63
 
63
- // The GC details of this node in the initial summary.
64
- private gcDetailsInInitialSummaryP: LazyPromise<IGarbageCollectionSummaryDetails> | undefined;
64
+ // The base GC details of this node used to initialize the GC state.
65
+ private readonly baseGCDetailsP: LazyPromise<IGarbageCollectionDetailsBase>;
66
+
67
+ // Keeps track of whether we have loaded the base details to ensure that we on;y do it once.
68
+ private baseGCDetailsLoaded: boolean = false;
65
69
 
66
70
  private gcData: IGarbageCollectionData | undefined;
67
71
 
@@ -90,7 +94,7 @@ export class SummarizerNodeWithGC extends SummarizerNode implements IRootSummari
90
94
  initialSummary?: IInitialSummary,
91
95
  wipSummaryLogger?: ITelemetryLogger,
92
96
  private readonly getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>,
93
- getInitialGCSummaryDetailsFn?: () => Promise<IGarbageCollectionSummaryDetails>,
97
+ getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>,
94
98
  ) {
95
99
  super(
96
100
  logger,
@@ -104,14 +108,20 @@ export class SummarizerNodeWithGC extends SummarizerNode implements IRootSummari
104
108
 
105
109
  this.gcDisabled = config.gcDisabled === true;
106
110
 
107
- this.gcDetailsInInitialSummaryP = new LazyPromise(async () => {
108
- const gcSummaryDetails = await getInitialGCSummaryDetailsFn?.();
109
- return gcSummaryDetails ?? { usedRoutes: [] };
111
+ this.baseGCDetailsP = new LazyPromise(async () => {
112
+ return (await getBaseGCDetailsFn?.()) ?? { usedRoutes: [] };
110
113
  });
111
114
  }
112
115
 
113
- // Returns the GC details that may be added to this node's summary.
116
+ /**
117
+ * @deprecated - Renamed to getBaseGCDetails.
118
+ */
114
119
  public getGCSummaryDetails(): IGarbageCollectionSummaryDetails {
120
+ return this.getBaseGCDetails();
121
+ }
122
+
123
+ // Returns the GC details to be added to this node's summary and is used to initialize new nodes' GC state.
124
+ public getBaseGCDetails(): IGarbageCollectionDetailsBase {
115
125
  return {
116
126
  gcData: this.gcData,
117
127
  usedRoutes: this.usedRoutes,
@@ -125,21 +135,22 @@ export class SummarizerNodeWithGC extends SummarizerNode implements IRootSummari
125
135
  * - usedRoutes: This is used to figure out if the used state of this node changed since last summary.
126
136
  * - gcData: The garbage collection data of this node that is required for running GC.
127
137
  */
128
- private async loadInitialGCSummaryDetails() {
129
- if (this.gcDetailsInInitialSummaryP === undefined) {
138
+ private async loadBaseGCDetails() {
139
+ const baseGCDetails = await this.baseGCDetailsP;
140
+
141
+ // Possible race - If there were parallel calls to loadBaseGCDetails, we want to make sure that we only update
142
+ // the state from the base details only once.
143
+ if (this.baseGCDetailsLoaded) {
130
144
  return;
131
145
  }
146
+ this.baseGCDetailsLoaded = true;
132
147
 
133
- const gcDetailsInInitialSummaryP = this.gcDetailsInInitialSummaryP;
134
- this.gcDetailsInInitialSummaryP = undefined;
135
-
136
- const gcDetailsInInitialSummary = await gcDetailsInInitialSummaryP;
137
148
  // If the GC details has GC data, initialize our GC data from it.
138
- if (gcDetailsInInitialSummary.gcData !== undefined) {
139
- this.gcData = cloneGCData(gcDetailsInInitialSummary.gcData);
149
+ if (baseGCDetails.gcData !== undefined) {
150
+ this.gcData = cloneGCData(baseGCDetails.gcData);
140
151
  }
141
- this.referenceUsedRoutes = gcDetailsInInitialSummary.usedRoutes;
142
- this.unreferencedTimestampMs = gcDetailsInInitialSummary.unrefTimestamp;
152
+ this.referenceUsedRoutes = baseGCDetails.usedRoutes;
153
+ this.unreferencedTimestampMs = baseGCDetails.unrefTimestamp;
143
154
  }
144
155
 
145
156
  public async summarize(fullTree: boolean, trackState: boolean = true): Promise<ISummarizeResult> {
@@ -166,7 +177,7 @@ export class SummarizerNodeWithGC extends SummarizerNode implements IRootSummari
166
177
 
167
178
  // Load GC details from the initial summary, if not already loaded. If this is the first time this function is
168
179
  // called and the node's data has not changed since last summary, the GC data in initial details is returned.
169
- await this.loadInitialGCSummaryDetails();
180
+ await this.loadBaseGCDetails();
170
181
 
171
182
  // If there is no new data since last summary and we have GC data from the previous run, return it. We may not
172
183
  // have data from previous GC run for clients with older summary format before GC was added. They won't have
@@ -265,7 +276,7 @@ export class SummarizerNodeWithGC extends SummarizerNode implements IRootSummari
265
276
  if (!this.gcDisabled) {
266
277
  const gcDetailsBlob = snapshotTree.blobs[gcBlobKey];
267
278
  if (gcDetailsBlob !== undefined) {
268
- const gcDetails = await readAndParseBlob<IGarbageCollectionSummaryDetails>(gcDetailsBlob);
279
+ const gcDetails = await readAndParseBlob<IGarbageCollectionDetailsBase>(gcDetailsBlob);
269
280
 
270
281
  // Possible re-entrancy. If we have already seen a summary later than this one, ignore it.
271
282
  if (this.referenceSequenceNumber >= referenceSequenceNumber) {
@@ -302,7 +313,7 @@ export class SummarizerNodeWithGC extends SummarizerNode implements IRootSummari
302
313
  createParam: CreateChildSummarizerNodeParam,
303
314
  config: ISummarizerNodeConfigWithGC = {},
304
315
  getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>,
305
- getInitialGCSummaryDetailsFn?: () => Promise<IGarbageCollectionSummaryDetails>,
316
+ getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>,
306
317
  ): ISummarizerNodeWithGC {
307
318
  assert(!this.children.has(id), 0x1b6 /* "Create SummarizerNode child already exists" */);
308
319
 
@@ -320,7 +331,7 @@ export class SummarizerNodeWithGC extends SummarizerNode implements IRootSummari
320
331
  createDetails.initialSummary,
321
332
  this.wipSummaryLogger,
322
333
  getGCDataFn,
323
- getInitialGCSummaryDetailsFn,
334
+ getBaseGCDetailsFn,
324
335
  );
325
336
 
326
337
  // There may be additional state that has to be updated in this child. For example, if a summary is being
@@ -410,7 +421,7 @@ export class SummarizerNodeWithGC extends SummarizerNode implements IRootSummari
410
421
  * or undefined if not loaded from summary
411
422
  * @param config - Configure behavior of summarizer node
412
423
  * @param getGCDataFn - Function to get the GC data of this node
413
- * @param gcDetailsInInitialSummaryP - Function to get the initial GC details of this node
424
+ * @param baseGCDetailsP - Function to get the initial GC details of this node
414
425
  */
415
426
  export const createRootSummarizerNodeWithGC = (
416
427
  logger: ITelemetryLogger,
@@ -419,7 +430,7 @@ export const createRootSummarizerNodeWithGC = (
419
430
  referenceSequenceNumber: number | undefined,
420
431
  config: ISummarizerNodeConfigWithGC = {},
421
432
  getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>,
422
- getInitialGCSummaryDetailsFn?: () => Promise<IGarbageCollectionSummaryDetails>,
433
+ getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>,
423
434
  ): IRootSummarizerNodeWithGC => new SummarizerNodeWithGC(
424
435
  logger,
425
436
  summarizeInternalFn,
@@ -429,5 +440,5 @@ export const createRootSummarizerNodeWithGC = (
429
440
  undefined /* initialSummary */,
430
441
  undefined /* wipSummaryLogger */,
431
442
  getGCDataFn,
432
- getInitialGCSummaryDetailsFn,
443
+ getBaseGCDetailsFn,
433
444
  );
package/src/utils.ts CHANGED
@@ -3,12 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { ISerializedHandle } from "@fluidframework/core-interfaces";
7
6
  import { IDocumentAttributes, ISnapshotTree } from "@fluidframework/protocol-definitions";
8
7
 
9
- export const isSerializedHandle = (value: any): value is ISerializedHandle =>
10
- value?.type === "__fluid_handle__";
11
-
12
8
  /** Reads a blob from storage and parses it from JSON. */
13
9
  export type ReadAndParseBlob = <T>(id: string) => Promise<T>;
14
10
 
@@ -1,68 +0,0 @@
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(`replaceHandles Handles: ${name}`)
32
- .add("replaceHandles(...)", () => {
33
- consume(serializer.replaceHandles(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(replaceHandles(...))", () => {
41
- consume(JSON.stringify(serializer.replaceHandles(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
- ]);
package/bench/src/util.ts DELETED
@@ -1,56 +0,0 @@
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
- }
@@ -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,66 +0,0 @@
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 dataStoreHelpers_1 = require("./dataStoreHelpers");
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 dataStoreHelpers_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
- : dataStoreHelpers_1.create404Response(request);
59
- }
60
- catch (error) {
61
- return dataStoreHelpers_1.exceptionToResponse(error);
62
- }
63
- }
64
- }
65
- exports.RemoteFluidObjectHandle = RemoteFluidObjectHandle;
66
- //# sourceMappingURL=remoteObjectHandle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"remoteObjectHandle.js","sourceRoot":"","sources":["../src/remoteObjectHandle.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AAStD,yDAAiG;AAEjG;;;;;;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,IAAI,CAAC,CAAC,CAAC;IAC1C,IAAW,mBAAmB,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;IACjD,IAAW,YAAY,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;IAiBnC,KAAK,CAAC,GAAG;QACZ,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE;YAC5B,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,YAAY,EAAE,CAAC;YAC3C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,OAAO,CAAC;iBAClD,IAAI,CAAc,CAAC,QAAQ,EAAE,EAAE;gBAC5B,IAAI,QAAQ,CAAC,QAAQ,KAAK,cAAc,EAAE;oBACtC,MAAM,WAAW,GAAgB,QAAQ,CAAC,KAAK,CAAC;oBAChD,OAAO,WAAW,CAAC;iBACtB;gBACD,MAAM,sCAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YACjD,CAAC,CAAC,CAAC;SACV;QACD,OAAO,IAAI,CAAC,OAAO,CAAC;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,oCAAiB,CAAC,OAAO,CAAC,CAAC;SACpC;QAAC,OAAO,KAAK,EAAE;YACZ,OAAO,sCAAmB,CAAC,KAAK,CAAC,CAAC;SACrC;IACL,CAAC;CACJ;AAvDD,0DAuDC","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"]}
@@ -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
@@ -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"}
@@ -1,145 +0,0 @@
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 = void 0;
8
- const remoteObjectHandle_1 = require("./remoteObjectHandle");
9
- const dataStoreHandleContextUtils_1 = require("./dataStoreHandleContextUtils");
10
- const utils_1 = require("./utils");
11
- /**
12
- * Data Store serializer implementation
13
- */
14
- class FluidSerializer {
15
- constructor(context,
16
- // To be called whenever a handle is parsed by this serializer.
17
- handleParsedCb) {
18
- this.context = context;
19
- this.handleParsedCb = handleParsedCb;
20
- // If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.
21
- // Otherwise returns the original 'value'. Used by 'replaceHandles()' and 'stringify()'.
22
- this.encodeValue = (value, bind) => {
23
- // Detect if 'value' is an IFluidHandle.
24
- const handle = value === null || value === void 0 ? void 0 : value.IFluidHandle;
25
- // If 'value' is an IFluidHandle return its encoded form.
26
- return handle !== undefined
27
- ? this.serializeHandle(handle, bind)
28
- : value;
29
- };
30
- // If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle.
31
- // Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'.
32
- this.decodeValue = (value) => {
33
- // If 'value' is a serialized IFluidHandle return the deserialized result.
34
- if (utils_1.isSerializedHandle(value)) {
35
- // Old documents may have handles with relative path in their summaries. Convert these to absolute
36
- // paths. This will ensure that future summaries will have absolute paths for these handles.
37
- const absolutePath = value.url.startsWith("/")
38
- ? value.url
39
- : dataStoreHandleContextUtils_1.generateHandleContextPath(value.url, this.context);
40
- const parsedHandle = new remoteObjectHandle_1.RemoteFluidObjectHandle(absolutePath, this.root);
41
- this.handleParsedCb(parsedHandle);
42
- return parsedHandle;
43
- }
44
- else {
45
- return value;
46
- }
47
- };
48
- this.root = this.context;
49
- while (this.root.routeContext !== undefined) {
50
- this.root = this.root.routeContext;
51
- }
52
- }
53
- get IFluidSerializer() { return this; }
54
- /**
55
- * Given a mostly-jsonable object tree that may have handle objects embedded within, will return a
56
- * fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.
57
- *
58
- * The original `input` object is not mutated. This method will shallowly clones all objects in the path from
59
- * the root to any replaced handles. (If no handles are found, returns the original object.)
60
- *
61
- * Any unbound handles encountered are bound to the provided IFluidHandle.
62
- */
63
- replaceHandles(input, bind) {
64
- // If the given 'input' cannot contain handles, return it immediately. Otherwise,
65
- // return the result of 'recursivelyReplace()'.
66
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
67
- return !!input && typeof input === "object"
68
- ? this.recursivelyReplace(input, this.encodeValue, bind)
69
- : input;
70
- }
71
- /**
72
- * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an
73
- * equivalent object tree where any encoded IFluidHandles have been replaced with thier decoded form.
74
- *
75
- * The original `input` object is not mutated. This method will shallowly clones all objects in the path from
76
- * the root to any replaced handles. (If no handles are found, returns the original object.)
77
- *
78
- * The decoded handles are implicitly bound to the handle context of this serializer.
79
- */
80
- decode(input) {
81
- // If the given 'input' cannot contain handles, return it immediately. Otherwise,
82
- // return the result of 'recursivelyReplace()'.
83
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
84
- return !!input && typeof input === "object"
85
- ? this.recursivelyReplace(input, this.decodeValue)
86
- : input;
87
- }
88
- stringify(input, bind) {
89
- return JSON.stringify(input, (key, value) => this.encodeValue(value, bind));
90
- }
91
- // Parses the serialized data - context must match the context with which the JSON was stringified
92
- parse(input) {
93
- return JSON.parse(input, (key, value) => this.decodeValue(value));
94
- }
95
- // Invoked for non-null objects to recursively replace references to IFluidHandles.
96
- // Clones as-needed to avoid mutating the `input` object. If no IFluidHandes are present,
97
- // returns the original `input`.
98
- recursivelyReplace(input, replacer, context) {
99
- // Note: Caller is responsible for ensuring that `input` is defined / non-null.
100
- // (Required for Object.keys() below.)
101
- // Execute the `replace` on the current input. Note that Caller is responsible for ensuring that `input`
102
- // is a non-null object.
103
- const maybeReplaced = replacer(input, context);
104
- // If the replacer made a substitution there is no need to decscend further. IFluidHandles are always
105
- // leaves in the object graph.
106
- if (maybeReplaced !== input) {
107
- return maybeReplaced;
108
- }
109
- // Otherwise descend into the object graph looking for IFluidHandle instances.
110
- // eslint-disable-next-line @typescript-eslint/ban-types
111
- let clone;
112
- for (const key of Object.keys(input)) {
113
- const value = input[key];
114
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
115
- if (!!value && typeof value === "object") {
116
- // Note: Except for IFluidHandle, `input` must not contain circular references (as object must
117
- // be JSON serializable.) Therefore, guarding against infinite recursion here would only
118
- // lead to a later error when attempting to stringify().
119
- const replaced = this.recursivelyReplace(value, replacer, context);
120
- // If the `replaced` object is different than the original `value` then the subgraph contained one
121
- // or more handles. If this happens, we need to return a clone of the `input` object where the
122
- // current property is replaced by the `replaced` value.
123
- if (replaced !== value) {
124
- // Lazily create a shallow clone of the `input` object if we haven't done so already.
125
- clone = clone !== null && clone !== void 0 ? clone : (Array.isArray(input)
126
- ? [...input]
127
- : Object.assign({}, input));
128
- // Overwrite the current property `key` in the clone with the `replaced` value.
129
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
130
- clone[key] = replaced;
131
- }
132
- }
133
- }
134
- return clone !== null && clone !== void 0 ? clone : input;
135
- }
136
- serializeHandle(handle, bind) {
137
- bind.bind(handle);
138
- return {
139
- type: "__fluid_handle__",
140
- url: handle.absolutePath,
141
- };
142
- }
143
- }
144
- exports.FluidSerializer = FluidSerializer;
145
- //# sourceMappingURL=serializer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serializer.js","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"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","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"]}