@fluidframework/runtime-utils 2.0.0-dev.2.3.0.115467 → 2.0.0-dev.4.1.0.148229
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 +3 -1
- package/dist/dataStoreHelpers.d.ts.map +1 -1
- package/dist/dataStoreHelpers.js +27 -8
- package/dist/dataStoreHelpers.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- 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 +1 -1
- package/dist/runtimeFactoryHelper.d.ts.map +1 -1
- package/dist/runtimeFactoryHelper.js +7 -6
- package/dist/runtimeFactoryHelper.js.map +1 -1
- package/dist/summaryUtils.d.ts +33 -1
- package/dist/summaryUtils.d.ts.map +1 -1
- package/dist/summaryUtils.js +86 -3
- package/dist/summaryUtils.js.map +1 -1
- package/dist/unpackUsedRoutes.d.ts +11 -0
- package/dist/unpackUsedRoutes.d.ts.map +1 -0
- package/dist/unpackUsedRoutes.js +33 -0
- package/dist/unpackUsedRoutes.js.map +1 -0
- 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 +3 -1
- package/lib/dataStoreHelpers.d.ts.map +1 -1
- package/lib/dataStoreHelpers.js +27 -8
- package/lib/dataStoreHelpers.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -2
- 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 +1 -1
- package/lib/runtimeFactoryHelper.d.ts.map +1 -1
- package/lib/runtimeFactoryHelper.js +7 -6
- package/lib/runtimeFactoryHelper.js.map +1 -1
- package/lib/summaryUtils.d.ts +33 -1
- package/lib/summaryUtils.d.ts.map +1 -1
- package/lib/summaryUtils.js +84 -2
- package/lib/summaryUtils.js.map +1 -1
- package/lib/unpackUsedRoutes.d.ts +11 -0
- package/lib/unpackUsedRoutes.d.ts.map +1 -0
- package/lib/unpackUsedRoutes.js +29 -0
- package/lib/unpackUsedRoutes.js.map +1 -0
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js.map +1 -1
- package/package.json +54 -55
- package/prettier.config.cjs +1 -1
- package/src/dataStoreHandleContextUtils.ts +23 -16
- package/src/dataStoreHelpers.ts +104 -82
- package/src/index.ts +3 -9
- 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 -22
- package/src/summaryUtils.ts +393 -291
- package/src/unpackUsedRoutes.ts +30 -0
- package/src/utils.ts +6 -6
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +8 -12
- package/dist/summarizerNode/index.d.ts +0 -8
- package/dist/summarizerNode/index.d.ts.map +0 -1
- package/dist/summarizerNode/index.js +0 -12
- package/dist/summarizerNode/index.js.map +0 -1
- package/dist/summarizerNode/summarizerNode.d.ts +0 -140
- package/dist/summarizerNode/summarizerNode.d.ts.map +0 -1
- package/dist/summarizerNode/summarizerNode.js +0 -439
- package/dist/summarizerNode/summarizerNode.js.map +0 -1
- package/dist/summarizerNode/summarizerNodeUtils.d.ts +0 -128
- package/dist/summarizerNode/summarizerNodeUtils.d.ts.map +0 -1
- package/dist/summarizerNode/summarizerNodeUtils.js +0 -132
- package/dist/summarizerNode/summarizerNodeUtils.js.map +0 -1
- package/dist/summarizerNode/summarizerNodeWithGc.d.ts +0 -131
- package/dist/summarizerNode/summarizerNodeWithGc.d.ts.map +0 -1
- package/dist/summarizerNode/summarizerNodeWithGc.js +0 -275
- package/dist/summarizerNode/summarizerNodeWithGc.js.map +0 -1
- package/lib/summarizerNode/index.d.ts +0 -8
- package/lib/summarizerNode/index.d.ts.map +0 -1
- package/lib/summarizerNode/index.js +0 -7
- package/lib/summarizerNode/index.js.map +0 -1
- package/lib/summarizerNode/summarizerNode.d.ts +0 -140
- package/lib/summarizerNode/summarizerNode.d.ts.map +0 -1
- package/lib/summarizerNode/summarizerNode.js +0 -434
- package/lib/summarizerNode/summarizerNode.js.map +0 -1
- package/lib/summarizerNode/summarizerNodeUtils.d.ts +0 -128
- package/lib/summarizerNode/summarizerNodeUtils.d.ts.map +0 -1
- package/lib/summarizerNode/summarizerNodeUtils.js +0 -125
- package/lib/summarizerNode/summarizerNodeUtils.js.map +0 -1
- package/lib/summarizerNode/summarizerNodeWithGc.d.ts +0 -131
- package/lib/summarizerNode/summarizerNodeWithGc.d.ts.map +0 -1
- package/lib/summarizerNode/summarizerNodeWithGc.js +0 -270
- package/lib/summarizerNode/summarizerNodeWithGc.js.map +0 -1
- package/src/summarizerNode/index.ts +0 -8
- package/src/summarizerNode/summarizerNode.ts +0 -593
- package/src/summarizerNode/summarizerNodeUtils.ts +0 -216
- package/src/summarizerNode/summarizerNodeWithGc.ts +0 -432
|
@@ -11,21 +11,28 @@ import { IFluidHandleContext } from "@fluidframework/core-interfaces";
|
|
|
11
11
|
* @param routeContext - The route context that contains the Fluid object.
|
|
12
12
|
* @returns The absolute path to the Fluid object from the root of the Container.
|
|
13
13
|
*/
|
|
14
|
-
export function generateHandleContextPath(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
export function generateHandleContextPath(
|
|
15
|
+
path: string,
|
|
16
|
+
routeContext?: IFluidHandleContext,
|
|
17
|
+
): string {
|
|
18
|
+
if (path === "") {
|
|
19
|
+
// The `path` is empty.
|
|
20
|
+
// If the routeContext does not exist, this is the root.
|
|
21
|
+
// If the routeContext exists, the absolute path is the same as that of the routeContext.
|
|
22
|
+
return routeContext === undefined ? "" : routeContext.absolutePath;
|
|
23
|
+
} else {
|
|
24
|
+
// Remove beginning and trailing slashes, if any, from the path.
|
|
25
|
+
let normalizedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
26
|
+
normalizedPath = normalizedPath.endsWith("/")
|
|
27
|
+
? normalizedPath.slice(0, -1)
|
|
28
|
+
: normalizedPath;
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
// If the routeContext does not exist, path is the absolute path.
|
|
31
|
+
// If the routeContext exists, absolute path is routeContext's absolute path plus the path.
|
|
32
|
+
return routeContext === undefined
|
|
33
|
+
? `/${normalizedPath}`
|
|
34
|
+
: `${
|
|
35
|
+
routeContext.absolutePath === "/" ? "" : routeContext.absolutePath
|
|
36
|
+
}/${normalizedPath}`;
|
|
37
|
+
}
|
|
31
38
|
}
|
package/src/dataStoreHelpers.ts
CHANGED
|
@@ -5,114 +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
|
-
|
|
17
|
+
errorFromRequestFluidObject: true;
|
|
18
|
+
message: string;
|
|
19
|
+
code: number;
|
|
20
|
+
stack?: string;
|
|
21
|
+
underlyingResponseHeaders?: { [key: string]: any };
|
|
26
22
|
}
|
|
27
23
|
|
|
28
24
|
export function exceptionToResponse(err: any): IResponse {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
+
};
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
export function responseToException(response: IResponse, request: IRequest): Error {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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;
|
|
63
67
|
}
|
|
64
68
|
|
|
65
69
|
/**
|
|
66
70
|
* Takes a set of packages and joins them pkg1/pkg2... etc. Tags the field as a code artifact
|
|
67
71
|
*/
|
|
68
72
|
export function packagePathToTelemetryProperty(
|
|
69
|
-
|
|
73
|
+
packagePath: readonly string[] | undefined,
|
|
70
74
|
): ITaggedTelemetryPropertyType | undefined {
|
|
71
|
-
|
|
75
|
+
return packagePath
|
|
76
|
+
? { value: packagePath.join("/"), tag: TelemetryDataTag.CodeArtifact }
|
|
77
|
+
: undefined;
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
export async function requestFluidObject<T = FluidObject>(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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;
|
|
85
93
|
}
|
|
86
94
|
|
|
87
|
-
export const create404Response = (request: IRequest) =>
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
+
};
|
|
103
120
|
}
|
|
104
121
|
|
|
105
122
|
export type Factory = IFluidDataStoreFactory & Partial<IProvideFluidDataStoreRegistry>;
|
|
106
123
|
|
|
107
124
|
export function createDataStoreFactory(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
+
};
|
|
118
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";
|
|
@@ -18,14 +18,6 @@ export { ObjectStoragePartition } from "./objectstoragepartition";
|
|
|
18
18
|
export { getNormalizedObjectStoragePathParts, listBlobsAtTreePath } from "./objectstorageutils";
|
|
19
19
|
export { RequestParser } from "./requestParser";
|
|
20
20
|
export { RuntimeFactoryHelper } from "./runtimeFactoryHelper";
|
|
21
|
-
export {
|
|
22
|
-
createRootSummarizerNode,
|
|
23
|
-
createRootSummarizerNodeWithGC,
|
|
24
|
-
IRootSummarizerNode,
|
|
25
|
-
IRootSummarizerNodeWithGC,
|
|
26
|
-
ISummarizerNodeRootContract,
|
|
27
|
-
RefreshSummaryResult,
|
|
28
|
-
} from "./summarizerNode";
|
|
29
21
|
export {
|
|
30
22
|
addBlobToSummary,
|
|
31
23
|
addSummarizeResultToSummary,
|
|
@@ -35,10 +27,12 @@ export {
|
|
|
35
27
|
convertSummaryTreeToITree,
|
|
36
28
|
convertToSummaryTree,
|
|
37
29
|
convertToSummaryTreeWithStats,
|
|
30
|
+
GCDataBuilder,
|
|
38
31
|
getBlobSize,
|
|
39
32
|
mergeStats,
|
|
40
33
|
SummaryTreeBuilder,
|
|
41
34
|
TelemetryContext,
|
|
42
35
|
utf8ByteLength,
|
|
43
36
|
} from "./summaryUtils";
|
|
37
|
+
export { unpackChildNodesUsedRoutes } from "./unpackUsedRoutes";
|
|
44
38
|
export { ReadAndParseBlob, seqFromTree } from "./utils";
|
|
@@ -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,32 +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
|
-
|
|
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
|
+
}
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
public async instantiateFirstTime(_runtime: T): Promise<void> {}
|
|
33
|
-
public async instantiateFromExisting(_runtime: T): Promise<void> {}
|
|
34
|
-
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> {}
|
|
35
37
|
}
|