@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.
- package/.eslintrc.js +5 -7
- package/.mocharc.js +2 -2
- package/api-extractor.json +2 -2
- package/dist/dataStoreHandleContextUtils.d.ts.map +1 -1
- package/dist/dataStoreHandleContextUtils.js +3 -1
- package/dist/dataStoreHandleContextUtils.js.map +1 -1
- package/dist/dataStoreHelpers.d.ts.map +1 -1
- package/dist/dataStoreHelpers.js +23 -7
- package/dist/dataStoreHelpers.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/objectstoragepartition.d.ts.map +1 -1
- package/dist/objectstoragepartition.js.map +1 -1
- package/dist/objectstorageutils.d.ts.map +1 -1
- package/dist/objectstorageutils.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/requestParser.d.ts.map +1 -1
- package/dist/requestParser.js.map +1 -1
- package/dist/runtimeFactoryHelper.d.ts.map +1 -1
- package/dist/runtimeFactoryHelper.js +6 -2
- package/dist/runtimeFactoryHelper.js.map +1 -1
- package/dist/summarizerNode/summarizerNode.d.ts +1 -1
- package/dist/summarizerNode/summarizerNode.d.ts.map +1 -1
- package/dist/summarizerNode/summarizerNode.js +12 -9
- package/dist/summarizerNode/summarizerNode.js.map +1 -1
- package/dist/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
- package/dist/summarizerNode/summarizerNodeUtils.js.map +1 -1
- package/dist/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
- package/dist/summarizerNode/summarizerNodeWithGc.js +24 -16
- package/dist/summarizerNode/summarizerNodeWithGc.js.map +1 -1
- package/dist/summaryUtils.d.ts +0 -4
- package/dist/summaryUtils.d.ts.map +1 -1
- package/dist/summaryUtils.js +3 -11
- package/dist/summaryUtils.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/lib/dataStoreHandleContextUtils.d.ts.map +1 -1
- package/lib/dataStoreHandleContextUtils.js +3 -1
- package/lib/dataStoreHandleContextUtils.js.map +1 -1
- package/lib/dataStoreHelpers.d.ts.map +1 -1
- package/lib/dataStoreHelpers.js +23 -7
- package/lib/dataStoreHelpers.js.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/objectstoragepartition.d.ts.map +1 -1
- package/lib/objectstoragepartition.js.map +1 -1
- package/lib/objectstorageutils.d.ts.map +1 -1
- package/lib/objectstorageutils.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/requestParser.d.ts.map +1 -1
- package/lib/requestParser.js.map +1 -1
- package/lib/runtimeFactoryHelper.d.ts.map +1 -1
- package/lib/runtimeFactoryHelper.js +6 -2
- package/lib/runtimeFactoryHelper.js.map +1 -1
- package/lib/summarizerNode/summarizerNode.d.ts +1 -1
- package/lib/summarizerNode/summarizerNode.d.ts.map +1 -1
- package/lib/summarizerNode/summarizerNode.js +12 -9
- package/lib/summarizerNode/summarizerNode.js.map +1 -1
- package/lib/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
- package/lib/summarizerNode/summarizerNodeUtils.js.map +1 -1
- package/lib/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
- package/lib/summarizerNode/summarizerNodeWithGc.js +25 -17
- package/lib/summarizerNode/summarizerNodeWithGc.js.map +1 -1
- package/lib/summaryUtils.d.ts +0 -4
- package/lib/summaryUtils.d.ts.map +1 -1
- package/lib/summaryUtils.js +3 -11
- package/lib/summaryUtils.js.map +1 -1
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js.map +1 -1
- package/package.json +110 -112
- package/prettier.config.cjs +1 -1
- package/src/dataStoreHandleContextUtils.ts +23 -16
- package/src/dataStoreHelpers.ts +104 -86
- package/src/index.ts +2 -2
- package/src/objectstoragepartition.ts +13 -13
- package/src/objectstorageutils.ts +31 -28
- package/src/packageVersion.ts +1 -1
- package/src/requestParser.ts +80 -82
- package/src/runtimeFactoryHelper.ts +24 -17
- package/src/summarizerNode/summarizerNode.ts +602 -574
- package/src/summarizerNode/summarizerNodeUtils.ts +154 -151
- package/src/summarizerNode/summarizerNodeWithGc.ts +508 -472
- package/src/summaryUtils.ts +299 -305
- package/src/utils.ts +6 -6
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +8 -12
package/src/dataStoreHelpers.ts
CHANGED
|
@@ -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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
73
|
+
packagePath: readonly string[] | undefined,
|
|
73
74
|
): ITaggedTelemetryPropertyType | undefined {
|
|
74
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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) =>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
public async readBlob(path: string): Promise<ArrayBufferLike> {
|
|
19
|
+
return this.storage.readBlob(`${this.path}/${path}`);
|
|
20
|
+
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
public async contains(path: string): Promise<boolean> {
|
|
23
|
+
return this.storage.contains(`${this.path}/${path}`);
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
}
|
package/src/packageVersion.ts
CHANGED
package/src/requestParser.ts
CHANGED
|
@@ -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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
31
|
-
|
|
28
|
+
private requestPathParts: readonly string[] | undefined;
|
|
29
|
+
public readonly query: string;
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
public get url(): string {
|
|
45
|
+
return this.request.url;
|
|
46
|
+
}
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
public get headers(): IRequestHeader | undefined {
|
|
49
|
+
return this.request.headers;
|
|
50
|
+
}
|
|
53
51
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
14
|
+
public get IRuntimeFactory() {
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
}
|