@fluidframework/runtime-utils 2.0.0-internal.3.0.5 → 2.0.0-internal.3.1.1

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 (90) hide show
  1. package/.eslintrc.js +5 -7
  2. package/.mocharc.js +2 -2
  3. package/api-extractor.json +2 -2
  4. package/dist/dataStoreHandleContextUtils.d.ts.map +1 -1
  5. package/dist/dataStoreHandleContextUtils.js +3 -1
  6. package/dist/dataStoreHandleContextUtils.js.map +1 -1
  7. package/dist/dataStoreHelpers.d.ts.map +1 -1
  8. package/dist/dataStoreHelpers.js +23 -7
  9. package/dist/dataStoreHelpers.js.map +1 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/objectstoragepartition.d.ts.map +1 -1
  13. package/dist/objectstoragepartition.js.map +1 -1
  14. package/dist/objectstorageutils.d.ts.map +1 -1
  15. package/dist/objectstorageutils.js.map +1 -1
  16. package/dist/packageVersion.d.ts +1 -1
  17. package/dist/packageVersion.js +1 -1
  18. package/dist/packageVersion.js.map +1 -1
  19. package/dist/requestParser.d.ts.map +1 -1
  20. package/dist/requestParser.js.map +1 -1
  21. package/dist/runtimeFactoryHelper.d.ts.map +1 -1
  22. package/dist/runtimeFactoryHelper.js +6 -2
  23. package/dist/runtimeFactoryHelper.js.map +1 -1
  24. package/dist/summarizerNode/summarizerNode.d.ts +1 -1
  25. package/dist/summarizerNode/summarizerNode.d.ts.map +1 -1
  26. package/dist/summarizerNode/summarizerNode.js +12 -9
  27. package/dist/summarizerNode/summarizerNode.js.map +1 -1
  28. package/dist/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
  29. package/dist/summarizerNode/summarizerNodeUtils.js.map +1 -1
  30. package/dist/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  31. package/dist/summarizerNode/summarizerNodeWithGc.js +24 -16
  32. package/dist/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  33. package/dist/summaryUtils.d.ts +0 -4
  34. package/dist/summaryUtils.d.ts.map +1 -1
  35. package/dist/summaryUtils.js +3 -11
  36. package/dist/summaryUtils.js.map +1 -1
  37. package/dist/utils.d.ts.map +1 -1
  38. package/dist/utils.js.map +1 -1
  39. package/lib/dataStoreHandleContextUtils.d.ts.map +1 -1
  40. package/lib/dataStoreHandleContextUtils.js +3 -1
  41. package/lib/dataStoreHandleContextUtils.js.map +1 -1
  42. package/lib/dataStoreHelpers.d.ts.map +1 -1
  43. package/lib/dataStoreHelpers.js +23 -7
  44. package/lib/dataStoreHelpers.js.map +1 -1
  45. package/lib/index.d.ts.map +1 -1
  46. package/lib/index.js.map +1 -1
  47. package/lib/objectstoragepartition.d.ts.map +1 -1
  48. package/lib/objectstoragepartition.js.map +1 -1
  49. package/lib/objectstorageutils.d.ts.map +1 -1
  50. package/lib/objectstorageutils.js.map +1 -1
  51. package/lib/packageVersion.d.ts +1 -1
  52. package/lib/packageVersion.js +1 -1
  53. package/lib/packageVersion.js.map +1 -1
  54. package/lib/requestParser.d.ts.map +1 -1
  55. package/lib/requestParser.js.map +1 -1
  56. package/lib/runtimeFactoryHelper.d.ts.map +1 -1
  57. package/lib/runtimeFactoryHelper.js +6 -2
  58. package/lib/runtimeFactoryHelper.js.map +1 -1
  59. package/lib/summarizerNode/summarizerNode.d.ts +1 -1
  60. package/lib/summarizerNode/summarizerNode.d.ts.map +1 -1
  61. package/lib/summarizerNode/summarizerNode.js +12 -9
  62. package/lib/summarizerNode/summarizerNode.js.map +1 -1
  63. package/lib/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
  64. package/lib/summarizerNode/summarizerNodeUtils.js.map +1 -1
  65. package/lib/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  66. package/lib/summarizerNode/summarizerNodeWithGc.js +25 -17
  67. package/lib/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  68. package/lib/summaryUtils.d.ts +0 -4
  69. package/lib/summaryUtils.d.ts.map +1 -1
  70. package/lib/summaryUtils.js +3 -11
  71. package/lib/summaryUtils.js.map +1 -1
  72. package/lib/utils.d.ts.map +1 -1
  73. package/lib/utils.js.map +1 -1
  74. package/package.json +110 -112
  75. package/prettier.config.cjs +1 -1
  76. package/src/dataStoreHandleContextUtils.ts +23 -16
  77. package/src/dataStoreHelpers.ts +104 -86
  78. package/src/index.ts +2 -2
  79. package/src/objectstoragepartition.ts +13 -13
  80. package/src/objectstorageutils.ts +31 -28
  81. package/src/packageVersion.ts +1 -1
  82. package/src/requestParser.ts +80 -82
  83. package/src/runtimeFactoryHelper.ts +24 -17
  84. package/src/summarizerNode/summarizerNode.ts +602 -574
  85. package/src/summarizerNode/summarizerNodeUtils.ts +154 -151
  86. package/src/summarizerNode/summarizerNodeWithGc.ts +508 -472
  87. package/src/summaryUtils.ts +299 -305
  88. package/src/utils.ts +6 -6
  89. package/tsconfig.esnext.json +6 -6
  90. package/tsconfig.json +8 -12
@@ -5,118 +5,136 @@
5
5
 
6
6
  import { ITaggedTelemetryPropertyType } from "@fluidframework/common-definitions";
7
7
  import { assert } from "@fluidframework/common-utils";
8
+ import { FluidObject, IFluidRouter, IRequest, IResponse } from "@fluidframework/core-interfaces";
8
9
  import {
9
- FluidObject,
10
- IFluidRouter,
11
- IRequest,
12
- IResponse,
13
- } from "@fluidframework/core-interfaces";
14
- import {
15
- IFluidDataStoreFactory,
16
- IFluidDataStoreRegistry,
17
- IProvideFluidDataStoreRegistry,
10
+ IFluidDataStoreFactory,
11
+ IFluidDataStoreRegistry,
12
+ IProvideFluidDataStoreRegistry,
18
13
  } from "@fluidframework/runtime-definitions";
19
14
  import { generateErrorWithStack, TelemetryDataTag } from "@fluidframework/telemetry-utils";
20
15
 
21
16
  interface IResponseException extends Error {
22
- errorFromRequestFluidObject: true;
23
- message: string;
24
- code: number;
25
- stack?: string;
26
- underlyingResponseHeaders?: { [key: string]: any; };
17
+ errorFromRequestFluidObject: true;
18
+ message: string;
19
+ code: number;
20
+ stack?: string;
21
+ underlyingResponseHeaders?: { [key: string]: any };
27
22
  }
28
23
 
29
24
  export function exceptionToResponse(err: any): IResponse {
30
- const status = 500;
31
- if (err !== null && typeof err === "object" && err.errorFromRequestFluidObject === true) {
32
- const responseErr: IResponseException = err;
33
- return {
34
- mimeType: "text/plain",
35
- status: responseErr.code,
36
- value: responseErr.message,
37
- get stack() { return responseErr.stack; },
38
- headers: responseErr.underlyingResponseHeaders,
39
- };
40
- }
41
-
42
- // Capture error objects, not stack itself, as stack retrieval is very expensive operation, so we delay it
43
- const errWithStack = generateErrorWithStack();
44
-
45
- return {
46
- mimeType: "text/plain",
47
- status,
48
- value: `${err}`,
49
- get stack() { return ((err?.stack) as (string | undefined)) ?? errWithStack.stack; },
50
- };
25
+ const status = 500;
26
+ if (err !== null && typeof err === "object" && err.errorFromRequestFluidObject === true) {
27
+ const responseErr: IResponseException = err;
28
+ return {
29
+ mimeType: "text/plain",
30
+ status: responseErr.code,
31
+ value: responseErr.message,
32
+ get stack() {
33
+ return responseErr.stack;
34
+ },
35
+ headers: responseErr.underlyingResponseHeaders,
36
+ };
37
+ }
38
+
39
+ // Capture error objects, not stack itself, as stack retrieval is very expensive operation, so we delay it
40
+ const errWithStack = generateErrorWithStack();
41
+
42
+ return {
43
+ mimeType: "text/plain",
44
+ status,
45
+ value: `${err}`,
46
+ get stack() {
47
+ return (err?.stack as string | undefined) ?? errWithStack.stack;
48
+ },
49
+ };
51
50
  }
52
51
 
53
52
  export function responseToException(response: IResponse, request: IRequest): Error {
54
- const message = response.value;
55
- const errWithStack = generateErrorWithStack();
56
- const responseErr: Error & IResponseException = {
57
- errorFromRequestFluidObject: true,
58
- message,
59
- name: "Error",
60
- code: response.status,
61
- get stack() { return response.stack ?? errWithStack.stack; },
62
- underlyingResponseHeaders: response.headers,
63
- };
64
-
65
- return responseErr;
53
+ const message = response.value;
54
+ const errWithStack = generateErrorWithStack();
55
+ const responseErr: Error & IResponseException = {
56
+ errorFromRequestFluidObject: true,
57
+ message,
58
+ name: "Error",
59
+ code: response.status,
60
+ get stack() {
61
+ return response.stack ?? errWithStack.stack;
62
+ },
63
+ underlyingResponseHeaders: response.headers,
64
+ };
65
+
66
+ return responseErr;
66
67
  }
67
68
 
68
69
  /**
69
70
  * Takes a set of packages and joins them pkg1/pkg2... etc. Tags the field as a code artifact
70
71
  */
71
72
  export function packagePathToTelemetryProperty(
72
- packagePath: readonly string[] | undefined,
73
+ packagePath: readonly string[] | undefined,
73
74
  ): ITaggedTelemetryPropertyType | undefined {
74
- return packagePath ? { value: packagePath.join("/"), tag: TelemetryDataTag.CodeArtifact } : undefined;
75
+ return packagePath
76
+ ? { value: packagePath.join("/"), tag: TelemetryDataTag.CodeArtifact }
77
+ : undefined;
75
78
  }
76
79
 
77
80
  export async function requestFluidObject<T = FluidObject>(
78
- router: IFluidRouter, url: string | IRequest): Promise<T> {
79
- const request = typeof url === "string" ? { url } : url;
80
- const response = await router.request(request);
81
-
82
- if (response.status !== 200 || response.mimeType !== "fluid/object") {
83
- throw responseToException(response, request);
84
- }
85
-
86
- assert(response.value, 0x19a /* "Invalid response value for Fluid object request" */);
87
- return response.value as T;
81
+ router: IFluidRouter,
82
+ url: string | IRequest,
83
+ ): Promise<T> {
84
+ const request = typeof url === "string" ? { url } : url;
85
+ const response = await router.request(request);
86
+
87
+ if (response.status !== 200 || response.mimeType !== "fluid/object") {
88
+ throw responseToException(response, request);
89
+ }
90
+
91
+ assert(response.value, 0x19a /* "Invalid response value for Fluid object request" */);
92
+ return response.value as T;
88
93
  }
89
94
 
90
- export const create404Response = (request: IRequest) => createResponseError(404, "not found", request);
91
-
92
- export function createResponseError(status: number, value: string, request: IRequest, headers?: { [key: string]: any }): IResponse {
93
- assert(status !== 200, 0x19b /* "Cannot not create response error on 200 status" */);
94
- // Omit query string which could contain personal data (aka "PII")
95
- const urlNoQuery = request.url?.split("?")[0];
96
-
97
- // Capture error objects, not stack itself, as stack retrieval is very expensive operation, so we delay it
98
- const errWithStack = generateErrorWithStack();
99
-
100
- return {
101
- mimeType: "text/plain",
102
- status,
103
- value: urlNoQuery === undefined ? value : `${value}: ${urlNoQuery}`,
104
- get stack() { return errWithStack.stack; },
105
- headers,
106
- };
95
+ export const create404Response = (request: IRequest) =>
96
+ createResponseError(404, "not found", request);
97
+
98
+ export function createResponseError(
99
+ status: number,
100
+ value: string,
101
+ request: IRequest,
102
+ headers?: { [key: string]: any },
103
+ ): IResponse {
104
+ assert(status !== 200, 0x19b /* "Cannot not create response error on 200 status" */);
105
+ // Omit query string which could contain personal data (aka "PII")
106
+ const urlNoQuery = request.url?.split("?")[0];
107
+
108
+ // Capture error objects, not stack itself, as stack retrieval is very expensive operation, so we delay it
109
+ const errWithStack = generateErrorWithStack();
110
+
111
+ return {
112
+ mimeType: "text/plain",
113
+ status,
114
+ value: urlNoQuery === undefined ? value : `${value}: ${urlNoQuery}`,
115
+ get stack() {
116
+ return errWithStack.stack;
117
+ },
118
+ headers,
119
+ };
107
120
  }
108
121
 
109
122
  export type Factory = IFluidDataStoreFactory & Partial<IProvideFluidDataStoreRegistry>;
110
123
 
111
124
  export function createDataStoreFactory(
112
- type: string,
113
- factory: Factory | Promise<Factory>,
114
- ): IFluidDataStoreFactory & IFluidDataStoreRegistry {
115
- return {
116
- type,
117
- get IFluidDataStoreFactory() { return this; },
118
- get IFluidDataStoreRegistry() { return this; },
119
- instantiateDataStore: async (context, existing) => (await factory).instantiateDataStore(context, existing),
120
- get: async (name: string) => (await factory).IFluidDataStoreRegistry?.get(name),
121
- };
125
+ type: string,
126
+ factory: Factory | Promise<Factory>,
127
+ ): IFluidDataStoreFactory & IFluidDataStoreRegistry {
128
+ return {
129
+ type,
130
+ get IFluidDataStoreFactory() {
131
+ return this;
132
+ },
133
+ get IFluidDataStoreRegistry() {
134
+ return this;
135
+ },
136
+ instantiateDataStore: async (context, existing) =>
137
+ (await factory).instantiateDataStore(context, existing),
138
+ get: async (name: string) => (await factory).IFluidDataStoreRegistry?.get(name),
139
+ };
122
140
  }
package/src/index.ts CHANGED
@@ -10,7 +10,7 @@ export {
10
10
  createResponseError,
11
11
  exceptionToResponse,
12
12
  Factory,
13
- packagePathToTelemetryProperty,
13
+ packagePathToTelemetryProperty,
14
14
  requestFluidObject,
15
15
  responseToException,
16
16
  } from "./dataStoreHelpers";
@@ -21,7 +21,7 @@ export { RuntimeFactoryHelper } from "./runtimeFactoryHelper";
21
21
  export {
22
22
  createRootSummarizerNode,
23
23
  createRootSummarizerNodeWithGC,
24
- IFetchSnapshotResult,
24
+ IFetchSnapshotResult,
25
25
  IRootSummarizerNode,
26
26
  IRootSummarizerNodeWithGC,
27
27
  ISummarizerNodeRootContract,
@@ -10,20 +10,20 @@ import { IChannelStorageService } from "@fluidframework/datastore-definitions";
10
10
  * Returns a new IChannelStorageService that resolves the given `path` as root.
11
11
  */
12
12
  export class ObjectStoragePartition implements IChannelStorageService {
13
- constructor(private readonly storage: IChannelStorageService, private readonly path: string) {
14
- // `path` must not include the trailing separator.
15
- assert(!path.endsWith("/"), 0x19c /* "storage service path has trailing separator" */);
16
- }
13
+ constructor(private readonly storage: IChannelStorageService, private readonly path: string) {
14
+ // `path` must not include the trailing separator.
15
+ assert(!path.endsWith("/"), 0x19c /* "storage service path has trailing separator" */);
16
+ }
17
17
 
18
- public async readBlob(path: string): Promise<ArrayBufferLike> {
19
- return this.storage.readBlob(`${this.path}/${path}`);
20
- }
18
+ public async readBlob(path: string): Promise<ArrayBufferLike> {
19
+ return this.storage.readBlob(`${this.path}/${path}`);
20
+ }
21
21
 
22
- public async contains(path: string): Promise<boolean> {
23
- return this.storage.contains(`${this.path}/${path}`);
24
- }
22
+ public async contains(path: string): Promise<boolean> {
23
+ return this.storage.contains(`${this.path}/${path}`);
24
+ }
25
25
 
26
- public async list(path: string): Promise<string[]> {
27
- return this.storage.list(`${this.path}/${path}`);
28
- }
26
+ public async list(path: string): Promise<string[]> {
27
+ return this.storage.list(`${this.path}/${path}`);
28
+ }
29
29
  }
@@ -6,35 +6,38 @@
6
6
  import { ITree } from "@fluidframework/protocol-definitions";
7
7
 
8
8
  export function getNormalizedObjectStoragePathParts(path: string) {
9
- let normalizePath = path;
10
- if (normalizePath.startsWith("/")) {
11
- normalizePath = normalizePath.substr(1);
12
- }
13
- if (normalizePath.endsWith("/")) {
14
- normalizePath = normalizePath.substr(0, normalizePath.length - 1);
15
- }
16
- if (normalizePath.length > 0) {
17
- return normalizePath.split("/");
18
- }
19
- return [];
9
+ let normalizePath = path;
10
+ if (normalizePath.startsWith("/")) {
11
+ normalizePath = normalizePath.substr(1);
12
+ }
13
+ if (normalizePath.endsWith("/")) {
14
+ normalizePath = normalizePath.substr(0, normalizePath.length - 1);
15
+ }
16
+ if (normalizePath.length > 0) {
17
+ return normalizePath.split("/");
18
+ }
19
+ return [];
20
20
  }
21
21
 
22
- export async function listBlobsAtTreePath(inputTree: ITree | undefined, path: string): Promise<string[]> {
23
- const pathParts = getNormalizedObjectStoragePathParts(path);
24
- let tree: ITree | undefined = inputTree;
25
- while (tree?.entries !== undefined && pathParts.length > 0) {
26
- const part = pathParts.shift();
27
- const treeEntry = tree.entries.find((value) => {
28
- return value.type === "Tree" && value.path === part ? true : false;
29
- });
22
+ export async function listBlobsAtTreePath(
23
+ inputTree: ITree | undefined,
24
+ path: string,
25
+ ): Promise<string[]> {
26
+ const pathParts = getNormalizedObjectStoragePathParts(path);
27
+ let tree: ITree | undefined = inputTree;
28
+ while (tree?.entries !== undefined && pathParts.length > 0) {
29
+ const part = pathParts.shift();
30
+ const treeEntry = tree.entries.find((value) => {
31
+ return value.type === "Tree" && value.path === part ? true : false;
32
+ });
30
33
 
31
- // this check is largely superfluous due to the same check being done
32
- // immediately above. the type system, however, is not aware of this.
33
- // so we must redundantly determine that the entry's type is "Tree"
34
- tree = treeEntry?.type === "Tree" ? treeEntry.value : undefined;
35
- }
36
- if (tree?.entries === undefined || pathParts.length !== 0) {
37
- throw new Error("path does not exist");
38
- }
39
- return tree.entries.filter((e) => e.type === "Blob").map((e) => e.path);
34
+ // this check is largely superfluous due to the same check being done
35
+ // immediately above. the type system, however, is not aware of this.
36
+ // so we must redundantly determine that the entry's type is "Tree"
37
+ tree = treeEntry?.type === "Tree" ? treeEntry.value : undefined;
38
+ }
39
+ if (tree?.entries === undefined || pathParts.length !== 0) {
40
+ throw new Error("path does not exist");
41
+ }
42
+ return tree.entries.filter((e) => e.type === "Blob").map((e) => e.path);
40
43
  }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/runtime-utils";
9
- export const pkgVersion = "2.0.0-internal.3.0.5";
9
+ export const pkgVersion = "2.0.0-internal.3.1.1";
@@ -8,94 +8,92 @@ import { IRequest, IRequestHeader } from "@fluidframework/core-interfaces";
8
8
  * The Request Parser takes an IRequest provides parsing and sub request creation
9
9
  */
10
10
  export class RequestParser implements IRequest {
11
- /**
12
- * Splits the path of the url and decodes each path part
13
- * @param url - the url to get path parts of
14
- */
15
- public static getPathParts(url: string): readonly string[] {
16
- const queryStartIndex = url.indexOf("?");
17
- return url
18
- .substring(0, queryStartIndex < 0 ? url.length : queryStartIndex)
19
- .split("/")
20
- .reduce<string[]>(
21
- (pv, cv) => {
22
- if (cv !== undefined && cv.length > 0) {
23
- pv.push(decodeURIComponent(cv));
24
- }
25
- return pv;
26
- },
27
- []);
28
- }
11
+ /**
12
+ * Splits the path of the url and decodes each path part
13
+ * @param url - the url to get path parts of
14
+ */
15
+ public static getPathParts(url: string): readonly string[] {
16
+ const queryStartIndex = url.indexOf("?");
17
+ return url
18
+ .substring(0, queryStartIndex < 0 ? url.length : queryStartIndex)
19
+ .split("/")
20
+ .reduce<string[]>((pv, cv) => {
21
+ if (cv !== undefined && cv.length > 0) {
22
+ pv.push(decodeURIComponent(cv));
23
+ }
24
+ return pv;
25
+ }, []);
26
+ }
29
27
 
30
- private requestPathParts: readonly string[] | undefined;
31
- public readonly query: string;
28
+ private requestPathParts: readonly string[] | undefined;
29
+ public readonly query: string;
32
30
 
33
- public static create(request: Readonly<IRequest>) {
34
- // Perf optimizations.
35
- if (request instanceof RequestParser) {
36
- return request;
37
- }
38
- return new RequestParser(request);
39
- }
31
+ public static create(request: Readonly<IRequest>) {
32
+ // Perf optimizations.
33
+ if (request instanceof RequestParser) {
34
+ return request;
35
+ }
36
+ return new RequestParser(request);
37
+ }
40
38
 
41
- protected constructor(private readonly request: Readonly<IRequest>) {
42
- const queryStartIndex = this.request.url.indexOf("?");
43
- this.query = queryStartIndex >= 0 ? this.request.url.substring(queryStartIndex) : "";
44
- }
39
+ protected constructor(private readonly request: Readonly<IRequest>) {
40
+ const queryStartIndex = this.request.url.indexOf("?");
41
+ this.query = queryStartIndex >= 0 ? this.request.url.substring(queryStartIndex) : "";
42
+ }
45
43
 
46
- public get url(): string {
47
- return this.request.url;
48
- }
44
+ public get url(): string {
45
+ return this.request.url;
46
+ }
49
47
 
50
- public get headers(): IRequestHeader | undefined {
51
- return this.request.headers;
52
- }
48
+ public get headers(): IRequestHeader | undefined {
49
+ return this.request.headers;
50
+ }
53
51
 
54
- /**
55
- * Returns the decoded path parts of the request's url
56
- */
57
- public get pathParts(): readonly string[] {
58
- if (this.requestPathParts === undefined) {
59
- this.requestPathParts = RequestParser.getPathParts(this.url);
60
- }
61
- return this.requestPathParts;
62
- }
52
+ /**
53
+ * Returns the decoded path parts of the request's url
54
+ */
55
+ public get pathParts(): readonly string[] {
56
+ if (this.requestPathParts === undefined) {
57
+ this.requestPathParts = RequestParser.getPathParts(this.url);
58
+ }
59
+ return this.requestPathParts;
60
+ }
63
61
 
64
- /**
65
- * Returns true if it's a terminating path, i.e. no more elements after `elements` entries and empty query.
66
- * @param elements - number of elements in path
67
- */
68
- public isLeaf(elements: number) {
69
- return this.query === "" && this.pathParts.length === elements;
70
- }
62
+ /**
63
+ * Returns true if it's a terminating path, i.e. no more elements after `elements` entries and empty query.
64
+ * @param elements - number of elements in path
65
+ */
66
+ public isLeaf(elements: number) {
67
+ return this.query === "" && this.pathParts.length === elements;
68
+ }
71
69
 
72
- /**
73
- * Creates a sub request starting at a specific path part of this request's url
74
- * The sub request url always has a leading slash, and always include query params if original url has any
75
- * e.g. original url is /a/b/?queryParams, createSubRequest(0) is /a/b/?queryParams
76
- * createSubRequest(1) is /b/?queryParams
77
- * createSubRequest(2) is /?queryParams
78
- * createSubRequest(n) where n is bigger than parts length, e.g. 2, or n is less than 0 will throw an exception
79
- *
80
- * note: query params are not counted towards path parts.
81
- *
82
- * @param startingPathIndex - The index of the first path part of the sub request
83
- */
84
- public createSubRequest(startingPathIndex: number): IRequest {
85
- const pathLen = this.pathParts.length;
86
- if (startingPathIndex < 0 || startingPathIndex > pathLen) {
87
- throw new Error("incorrect sub-request");
88
- }
89
- if (startingPathIndex === pathLen && this.url.includes("?")) {
90
- return {
91
- url: `/${this.query}`,
92
- headers: this.headers,
93
- };
94
- }
95
- const path = `/${this.pathParts.slice(startingPathIndex).join("/")}`;
96
- return {
97
- url: this.query === "" ? path : `${path}/${this.query}`,
98
- headers: this.headers,
99
- };
100
- }
70
+ /**
71
+ * Creates a sub request starting at a specific path part of this request's url
72
+ * The sub request url always has a leading slash, and always include query params if original url has any
73
+ * e.g. original url is /a/b/?queryParams, createSubRequest(0) is /a/b/?queryParams
74
+ * createSubRequest(1) is /b/?queryParams
75
+ * createSubRequest(2) is /?queryParams
76
+ * createSubRequest(n) where n is bigger than parts length, e.g. 2, or n is less than 0 will throw an exception
77
+ *
78
+ * note: query params are not counted towards path parts.
79
+ *
80
+ * @param startingPathIndex - The index of the first path part of the sub request
81
+ */
82
+ public createSubRequest(startingPathIndex: number): IRequest {
83
+ const pathLen = this.pathParts.length;
84
+ if (startingPathIndex < 0 || startingPathIndex > pathLen) {
85
+ throw new Error("incorrect sub-request");
86
+ }
87
+ if (startingPathIndex === pathLen && this.url.includes("?")) {
88
+ return {
89
+ url: `/${this.query}`,
90
+ headers: this.headers,
91
+ };
92
+ }
93
+ const path = `/${this.pathParts.slice(startingPathIndex).join("/")}`;
94
+ return {
95
+ url: this.query === "" ? path : `${path}/${this.query}`,
96
+ headers: this.headers,
97
+ };
98
+ }
101
99
  }
@@ -4,27 +4,34 @@
4
4
  */
5
5
 
6
6
  import {
7
- IContainerContext,
8
- IRuntime,
9
- IRuntimeFactory,
7
+ IContainerContext,
8
+ IRuntime,
9
+ IRuntimeFactory,
10
10
  } from "@fluidframework/container-definitions";
11
11
  import { IContainerRuntime } from "@fluidframework/container-runtime-definitions";
12
12
 
13
13
  export abstract class RuntimeFactoryHelper<T = IContainerRuntime> implements IRuntimeFactory {
14
- public get IRuntimeFactory() { return this; }
14
+ public get IRuntimeFactory() {
15
+ return this;
16
+ }
15
17
 
16
- public async instantiateRuntime(
17
- context: IContainerContext,
18
- existing: boolean,
19
- ): Promise<IRuntime> {
20
- const runtime = await this.preInitialize(context, existing);
21
- await (existing ? this.instantiateFromExisting(runtime) : this.instantiateFirstTime(runtime));
22
- await this.hasInitialized(runtime);
23
- return runtime;
24
- }
18
+ public async instantiateRuntime(
19
+ context: IContainerContext,
20
+ existing: boolean,
21
+ ): Promise<IRuntime> {
22
+ const runtime = await this.preInitialize(context, existing);
23
+ await (existing
24
+ ? this.instantiateFromExisting(runtime)
25
+ : this.instantiateFirstTime(runtime));
26
+ await this.hasInitialized(runtime);
27
+ return runtime;
28
+ }
25
29
 
26
- public abstract preInitialize(context: IContainerContext, existing: boolean): Promise<IRuntime & T>;
27
- public async instantiateFirstTime(_runtime: T): Promise<void> {}
28
- public async instantiateFromExisting(_runtime: T): Promise<void> {}
29
- public async hasInitialized(_runtime: T): Promise<void> {}
30
+ public abstract preInitialize(
31
+ context: IContainerContext,
32
+ existing: boolean,
33
+ ): Promise<IRuntime & T>;
34
+ public async instantiateFirstTime(_runtime: T): Promise<void> {}
35
+ public async instantiateFromExisting(_runtime: T): Promise<void> {}
36
+ public async hasInitialized(_runtime: T): Promise<void> {}
30
37
  }