@fluidframework/routerlicious-driver 2.0.0-dev.2.3.0.115467 → 2.0.0-dev.3.1.0.125672
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 +10 -12
- package/.mocharc.js +2 -2
- package/README.md +1 -1
- package/api-extractor.json +2 -2
- package/dist/cache.d.ts +3 -0
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +6 -4
- package/dist/cache.js.map +1 -1
- package/dist/createNewUtils.d.ts.map +1 -1
- package/dist/createNewUtils.js +4 -2
- package/dist/createNewUtils.js.map +1 -1
- package/dist/defaultTokenProvider.d.ts.map +1 -1
- package/dist/defaultTokenProvider.js.map +1 -1
- package/dist/definitions.d.ts.map +1 -1
- package/dist/definitions.js.map +1 -1
- package/dist/deltaStorageService.d.ts.map +1 -1
- package/dist/deltaStorageService.js +4 -1
- package/dist/deltaStorageService.js.map +1 -1
- package/dist/documentDeltaConnection.d.ts.map +1 -1
- package/dist/documentDeltaConnection.js.map +1 -1
- package/dist/documentService.d.ts +4 -2
- package/dist/documentService.d.ts.map +1 -1
- package/dist/documentService.js +22 -41
- package/dist/documentService.js.map +1 -1
- package/dist/documentServiceFactory.d.ts.map +1 -1
- package/dist/documentServiceFactory.js +23 -9
- package/dist/documentServiceFactory.js.map +1 -1
- package/dist/documentStorageService.d.ts +1 -1
- package/dist/documentStorageService.d.ts.map +1 -1
- package/dist/documentStorageService.js +8 -6
- package/dist/documentStorageService.js.map +1 -1
- package/dist/errorUtils.d.ts +2 -1
- package/dist/errorUtils.d.ts.map +1 -1
- package/dist/errorUtils.js +6 -0
- package/dist/errorUtils.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/nullBlobStorageService.d.ts.map +1 -1
- package/dist/nullBlobStorageService.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/policies.d.ts.map +1 -1
- package/dist/policies.js.map +1 -1
- package/dist/restWrapper.d.ts +8 -5
- package/dist/restWrapper.d.ts.map +1 -1
- package/dist/restWrapper.js +38 -44
- package/dist/restWrapper.js.map +1 -1
- package/dist/retriableGitManager.d.ts.map +1 -1
- package/dist/retriableGitManager.js.map +1 -1
- package/dist/shreddedSummaryDocumentStorageService.d.ts +1 -1
- package/dist/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
- package/dist/shreddedSummaryDocumentStorageService.js +9 -5
- package/dist/shreddedSummaryDocumentStorageService.js.map +1 -1
- package/dist/tokens.d.ts.map +1 -1
- package/dist/tokens.js.map +1 -1
- package/dist/urlUtils.d.ts.map +1 -1
- package/dist/urlUtils.js.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.d.ts +1 -1
- package/dist/wholeSummaryDocumentStorageService.d.ts.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.js +25 -11
- package/dist/wholeSummaryDocumentStorageService.js.map +1 -1
- package/lib/cache.d.ts +3 -0
- package/lib/cache.d.ts.map +1 -1
- package/lib/cache.js +6 -4
- package/lib/cache.js.map +1 -1
- package/lib/createNewUtils.d.ts.map +1 -1
- package/lib/createNewUtils.js +4 -2
- package/lib/createNewUtils.js.map +1 -1
- package/lib/defaultTokenProvider.d.ts.map +1 -1
- package/lib/defaultTokenProvider.js.map +1 -1
- package/lib/definitions.d.ts.map +1 -1
- package/lib/definitions.js.map +1 -1
- package/lib/deltaStorageService.d.ts.map +1 -1
- package/lib/deltaStorageService.js +4 -1
- package/lib/deltaStorageService.js.map +1 -1
- package/lib/documentDeltaConnection.d.ts.map +1 -1
- package/lib/documentDeltaConnection.js.map +1 -1
- package/lib/documentService.d.ts +4 -2
- package/lib/documentService.d.ts.map +1 -1
- package/lib/documentService.js +22 -22
- package/lib/documentService.js.map +1 -1
- package/lib/documentServiceFactory.d.ts.map +1 -1
- package/lib/documentServiceFactory.js +23 -9
- package/lib/documentServiceFactory.js.map +1 -1
- package/lib/documentStorageService.d.ts +1 -1
- package/lib/documentStorageService.d.ts.map +1 -1
- package/lib/documentStorageService.js +9 -7
- package/lib/documentStorageService.js.map +1 -1
- package/lib/errorUtils.d.ts +2 -1
- package/lib/errorUtils.d.ts.map +1 -1
- package/lib/errorUtils.js +6 -0
- package/lib/errorUtils.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/nullBlobStorageService.d.ts.map +1 -1
- package/lib/nullBlobStorageService.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/policies.d.ts.map +1 -1
- package/lib/policies.js.map +1 -1
- package/lib/restWrapper.d.ts +8 -5
- package/lib/restWrapper.d.ts.map +1 -1
- package/lib/restWrapper.js +38 -44
- package/lib/restWrapper.js.map +1 -1
- package/lib/retriableGitManager.d.ts.map +1 -1
- package/lib/retriableGitManager.js.map +1 -1
- package/lib/shreddedSummaryDocumentStorageService.d.ts +1 -1
- package/lib/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
- package/lib/shreddedSummaryDocumentStorageService.js +10 -6
- package/lib/shreddedSummaryDocumentStorageService.js.map +1 -1
- package/lib/tokens.d.ts.map +1 -1
- package/lib/tokens.js.map +1 -1
- package/lib/urlUtils.d.ts.map +1 -1
- package/lib/urlUtils.js.map +1 -1
- package/lib/wholeSummaryDocumentStorageService.d.ts +1 -1
- package/lib/wholeSummaryDocumentStorageService.d.ts.map +1 -1
- package/lib/wholeSummaryDocumentStorageService.js +27 -13
- package/lib/wholeSummaryDocumentStorageService.js.map +1 -1
- package/package.json +19 -15
- package/prettier.config.cjs +1 -1
- package/src/cache.ts +21 -14
- package/src/createNewUtils.ts +24 -22
- package/src/defaultTokenProvider.ts +13 -15
- package/src/definitions.ts +2 -2
- package/src/deltaStorageService.ts +99 -95
- package/src/documentDeltaConnection.ts +53 -47
- package/src/documentService.ts +243 -239
- package/src/documentServiceFactory.ts +267 -237
- package/src/documentStorageService.ts +87 -83
- package/src/errorUtils.ts +78 -75
- package/src/index.ts +4 -1
- package/src/nullBlobStorageService.ts +24 -21
- package/src/packageVersion.ts +1 -1
- package/src/policies.ts +44 -44
- package/src/restWrapper.ts +270 -208
- package/src/retriableGitManager.ts +152 -151
- package/src/shreddedSummaryDocumentStorageService.ts +202 -194
- package/src/tokens.ts +51 -43
- package/src/urlUtils.ts +26 -23
- package/src/wholeSummaryDocumentStorageService.ts +246 -228
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +9 -13
|
@@ -5,18 +5,21 @@
|
|
|
5
5
|
|
|
6
6
|
import { assert } from "@fluidframework/common-utils";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
FiveDaysMs,
|
|
9
|
+
IDocumentService,
|
|
10
|
+
IDocumentServiceFactory,
|
|
11
|
+
IDocumentStorageServicePolicies,
|
|
12
|
+
IFluidResolvedUrl,
|
|
13
|
+
IResolvedUrl,
|
|
14
|
+
LoaderCachingPolicy,
|
|
12
15
|
} from "@fluidframework/driver-definitions";
|
|
13
16
|
import { ITelemetryBaseLogger } from "@fluidframework/common-definitions";
|
|
14
17
|
import { ISummaryTree } from "@fluidframework/protocol-definitions";
|
|
15
18
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
ensureFluidResolvedUrl,
|
|
20
|
+
getDocAttributesFromProtocolSummary,
|
|
21
|
+
getQuorumValuesFromProtocolSummary,
|
|
22
|
+
RateLimiter,
|
|
20
23
|
} from "@fluidframework/driver-utils";
|
|
21
24
|
import { ChildLogger, PerformanceEvent } from "@fluidframework/telemetry-utils";
|
|
22
25
|
import { ISession } from "@fluidframework/server-services-client";
|
|
@@ -30,15 +33,17 @@ import { ICache, InMemoryCache, NullCache } from "./cache";
|
|
|
30
33
|
import { pkgVersion as driverVersion } from "./packageVersion";
|
|
31
34
|
import { ISnapshotTreeVersion } from "./definitions";
|
|
32
35
|
|
|
36
|
+
const maximumSnapshotCacheDurationMs: FiveDaysMs = 432_000_000; // 5 days in ms
|
|
37
|
+
|
|
33
38
|
const defaultRouterliciousDriverPolicies: IRouterliciousDriverPolicies = {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
enablePrefetch: true,
|
|
40
|
+
maxConcurrentStorageRequests: 100,
|
|
41
|
+
maxConcurrentOrdererRequests: 100,
|
|
42
|
+
aggregateBlobsSmallerThanBytes: undefined,
|
|
43
|
+
enableDiscovery: false,
|
|
44
|
+
enableWholeSummaryUpload: false,
|
|
45
|
+
enableRestLess: true,
|
|
46
|
+
enableInternalSummaryCaching: true,
|
|
42
47
|
};
|
|
43
48
|
|
|
44
49
|
/**
|
|
@@ -46,234 +51,257 @@ const defaultRouterliciousDriverPolicies: IRouterliciousDriverPolicies = {
|
|
|
46
51
|
* use the routerlicious implementation.
|
|
47
52
|
*/
|
|
48
53
|
export class RouterliciousDocumentServiceFactory implements IDocumentServiceFactory {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
public readonly protocolName = "fluid:";
|
|
55
|
+
private readonly driverPolicies: IRouterliciousDriverPolicies;
|
|
56
|
+
private readonly blobCache: ICache<ArrayBufferLike>;
|
|
57
|
+
private readonly snapshotTreeCache: ICache<ISnapshotTreeVersion>;
|
|
58
|
+
|
|
59
|
+
constructor(
|
|
60
|
+
private readonly tokenProvider: ITokenProvider,
|
|
61
|
+
driverPolicies: Partial<IRouterliciousDriverPolicies> = {},
|
|
62
|
+
) {
|
|
63
|
+
// Use the maximum allowed by the policy (IDocumentStorageServicePolicies.maximumCacheDurationMs set below)
|
|
64
|
+
const snapshotCacheExpiryMs: FiveDaysMs = maximumSnapshotCacheDurationMs;
|
|
65
|
+
|
|
66
|
+
this.driverPolicies = {
|
|
67
|
+
...defaultRouterliciousDriverPolicies,
|
|
68
|
+
...driverPolicies,
|
|
69
|
+
};
|
|
70
|
+
this.blobCache = new InMemoryCache<ArrayBufferLike>();
|
|
71
|
+
this.snapshotTreeCache = this.driverPolicies.enableInternalSummaryCaching
|
|
72
|
+
? new InMemoryCache<ISnapshotTreeVersion>(snapshotCacheExpiryMs)
|
|
73
|
+
: new NullCache<ISnapshotTreeVersion>();
|
|
74
|
+
}
|
|
53
75
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
76
|
+
/**
|
|
77
|
+
* {@inheritDoc @fluidframework/driver-definitions#IDocumentServiceFactory.createContainer}
|
|
78
|
+
*
|
|
79
|
+
* @throws {@link DocumentPostCreateError}
|
|
80
|
+
* If an exception is thrown while invoking the provided {@link ITokenProvider.documentPostCreateCallback}.
|
|
81
|
+
*/
|
|
82
|
+
public async createContainer(
|
|
83
|
+
createNewSummary: ISummaryTree | undefined,
|
|
84
|
+
resolvedUrl: IResolvedUrl,
|
|
85
|
+
logger?: ITelemetryBaseLogger,
|
|
86
|
+
clientIsSummarizer?: boolean,
|
|
87
|
+
): Promise<IDocumentService> {
|
|
88
|
+
ensureFluidResolvedUrl(resolvedUrl);
|
|
89
|
+
if (createNewSummary === undefined) {
|
|
90
|
+
throw new Error("Empty file summary creation isn't supported in this driver.");
|
|
91
|
+
}
|
|
92
|
+
assert(!!resolvedUrl.endpoints.ordererUrl, 0x0b2 /* "Missing orderer URL!" */);
|
|
93
|
+
let parsedUrl = parseFluidUrl(resolvedUrl.url);
|
|
94
|
+
if (!parsedUrl.pathname) {
|
|
95
|
+
throw new Error("Parsed url should contain tenant and doc Id!!");
|
|
96
|
+
}
|
|
97
|
+
const [, tenantId] = parsedUrl.pathname.split("/");
|
|
67
98
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
createNewSummary: ISummaryTree | undefined,
|
|
76
|
-
resolvedUrl: IResolvedUrl,
|
|
77
|
-
logger?: ITelemetryBaseLogger,
|
|
78
|
-
clientIsSummarizer?: boolean,
|
|
79
|
-
): Promise<IDocumentService> {
|
|
80
|
-
ensureFluidResolvedUrl(resolvedUrl);
|
|
81
|
-
if (createNewSummary === undefined) {
|
|
82
|
-
throw new Error("Empty file summary creation isn't supported in this driver.");
|
|
83
|
-
}
|
|
84
|
-
assert(!!resolvedUrl.endpoints.ordererUrl, 0x0b2 /* "Missing orderer URL!" */);
|
|
85
|
-
let parsedUrl = parseFluidUrl(resolvedUrl.url);
|
|
86
|
-
if (!parsedUrl.pathname) {
|
|
87
|
-
throw new Error("Parsed url should contain tenant and doc Id!!");
|
|
88
|
-
}
|
|
89
|
-
const [, tenantId] = parsedUrl.pathname.split("/");
|
|
99
|
+
const protocolSummary = createNewSummary.tree[".protocol"] as ISummaryTree;
|
|
100
|
+
const appSummary = createNewSummary.tree[".app"] as ISummaryTree;
|
|
101
|
+
if (!(protocolSummary && appSummary)) {
|
|
102
|
+
throw new Error("Protocol and App Summary required in the full summary");
|
|
103
|
+
}
|
|
104
|
+
const documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary);
|
|
105
|
+
const quorumValues = getQuorumValuesFromProtocolSummary(protocolSummary);
|
|
90
106
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
107
|
+
const logger2 = ChildLogger.create(logger, "RouterliciousDriver");
|
|
108
|
+
const rateLimiter = new RateLimiter(this.driverPolicies.maxConcurrentOrdererRequests);
|
|
109
|
+
const ordererRestWrapper = await RouterliciousOrdererRestWrapper.load(
|
|
110
|
+
tenantId,
|
|
111
|
+
undefined,
|
|
112
|
+
this.tokenProvider,
|
|
113
|
+
logger2,
|
|
114
|
+
rateLimiter,
|
|
115
|
+
this.driverPolicies.enableRestLess,
|
|
116
|
+
resolvedUrl.endpoints.ordererUrl,
|
|
117
|
+
);
|
|
98
118
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
119
|
+
const res = await PerformanceEvent.timedExecAsync(
|
|
120
|
+
logger2,
|
|
121
|
+
{
|
|
122
|
+
eventName: "CreateNew",
|
|
123
|
+
details: JSON.stringify({
|
|
124
|
+
enableDiscovery: this.driverPolicies.enableDiscovery,
|
|
125
|
+
sequenceNumber: documentAttributes.sequenceNumber,
|
|
126
|
+
}),
|
|
127
|
+
},
|
|
128
|
+
async (event) => {
|
|
129
|
+
// @TODO: Remove returned "string" type when removing back-compat code
|
|
130
|
+
const postRes = await ordererRestWrapper.post<
|
|
131
|
+
{ id: string; token?: string; session?: ISession } | string
|
|
132
|
+
>(`/documents/${tenantId}`, {
|
|
133
|
+
summary: convertSummaryToCreateNewSummary(appSummary),
|
|
134
|
+
sequenceNumber: documentAttributes.sequenceNumber,
|
|
135
|
+
values: quorumValues,
|
|
136
|
+
enableDiscovery: this.driverPolicies.enableDiscovery,
|
|
137
|
+
generateToken: this.tokenProvider.documentPostCreateCallback !== undefined,
|
|
138
|
+
});
|
|
110
139
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
sequenceNumber: documentAttributes.sequenceNumber,
|
|
118
|
-
}),
|
|
119
|
-
},
|
|
120
|
-
async (event) => {
|
|
121
|
-
// @TODO: Remove returned "string" type when removing back-compat code
|
|
122
|
-
const postRes = await ordererRestWrapper.post<
|
|
123
|
-
{ id: string; token?: string; session?: ISession; } | string
|
|
124
|
-
>(`/documents/${tenantId}`, {
|
|
125
|
-
summary: convertSummaryToCreateNewSummary(appSummary),
|
|
126
|
-
sequenceNumber: documentAttributes.sequenceNumber,
|
|
127
|
-
values: quorumValues,
|
|
128
|
-
enableDiscovery: this.driverPolicies.enableDiscovery,
|
|
129
|
-
generateToken:
|
|
130
|
-
this.tokenProvider.documentPostCreateCallback !==
|
|
131
|
-
undefined,
|
|
132
|
-
});
|
|
140
|
+
event.end({
|
|
141
|
+
docId: typeof postRes === "string" ? postRes : postRes.id,
|
|
142
|
+
});
|
|
143
|
+
return postRes;
|
|
144
|
+
},
|
|
145
|
+
);
|
|
133
146
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return postRes;
|
|
138
|
-
}
|
|
139
|
-
);
|
|
147
|
+
// For supporting backward compatibility, when the request has generateToken === true, it will return
|
|
148
|
+
// an object instead of string
|
|
149
|
+
// @TODO: Remove the logic when no need to support back-compat
|
|
140
150
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
151
|
+
let documentId: string;
|
|
152
|
+
let token: string | undefined;
|
|
153
|
+
let session: ISession | undefined;
|
|
154
|
+
if (typeof res === "string") {
|
|
155
|
+
documentId = res;
|
|
156
|
+
} else {
|
|
157
|
+
documentId = res.id;
|
|
158
|
+
token = res.token;
|
|
159
|
+
session = this.driverPolicies.enableDiscovery ? res.session : undefined;
|
|
160
|
+
}
|
|
161
|
+
parsedUrl = parseFluidUrl(resolvedUrl.url);
|
|
144
162
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
163
|
+
// @TODO: Remove token from the condition, checking the documentPostCreateCallback !== undefined
|
|
164
|
+
// is sufficient to determine if the token will be undefined or not.
|
|
165
|
+
try {
|
|
166
|
+
await PerformanceEvent.timedExecAsync(
|
|
167
|
+
logger2,
|
|
168
|
+
{
|
|
169
|
+
eventName: "DocPostCreateCallback",
|
|
170
|
+
docId: documentId,
|
|
171
|
+
},
|
|
172
|
+
async () => {
|
|
173
|
+
if (token && this.tokenProvider.documentPostCreateCallback !== undefined) {
|
|
174
|
+
return this.tokenProvider.documentPostCreateCallback(documentId, token);
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
} catch (error: any) {
|
|
179
|
+
throw new DocumentPostCreateError(error);
|
|
180
|
+
}
|
|
156
181
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
} catch (error: any) {
|
|
172
|
-
throw new DocumentPostCreateError(error);
|
|
173
|
-
}
|
|
182
|
+
parsedUrl.set("pathname", replaceDocumentIdInPath(parsedUrl.pathname, documentId));
|
|
183
|
+
const deltaStorageUrl = resolvedUrl.endpoints.deltaStorageUrl;
|
|
184
|
+
if (!deltaStorageUrl) {
|
|
185
|
+
throw new Error(
|
|
186
|
+
`All endpoints urls must be provided. [deltaStorageUrl:${deltaStorageUrl}]`,
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
const parsedDeltaStorageUrl = new URL(deltaStorageUrl);
|
|
190
|
+
parsedDeltaStorageUrl.pathname = replaceDocumentIdInPath(
|
|
191
|
+
parsedDeltaStorageUrl.pathname,
|
|
192
|
+
documentId,
|
|
193
|
+
);
|
|
174
194
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
195
|
+
return this.createDocumentService(
|
|
196
|
+
{
|
|
197
|
+
...resolvedUrl,
|
|
198
|
+
url: parsedUrl.toString(),
|
|
199
|
+
id: documentId,
|
|
200
|
+
endpoints: {
|
|
201
|
+
...resolvedUrl.endpoints,
|
|
202
|
+
deltaStorageUrl: parsedDeltaStorageUrl.toString(),
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
logger,
|
|
206
|
+
clientIsSummarizer,
|
|
207
|
+
session,
|
|
208
|
+
);
|
|
209
|
+
}
|
|
183
210
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
211
|
+
/**
|
|
212
|
+
* {@inheritDoc @fluidframework/driver-definitions#IDocumentServiceFactory.createDocumentService}
|
|
213
|
+
*
|
|
214
|
+
* @returns Routerlicious document service.
|
|
215
|
+
*/
|
|
216
|
+
public async createDocumentService(
|
|
217
|
+
resolvedUrl: IResolvedUrl,
|
|
218
|
+
logger?: ITelemetryBaseLogger,
|
|
219
|
+
clientIsSummarizer?: boolean,
|
|
220
|
+
session?: ISession,
|
|
221
|
+
): Promise<IDocumentService> {
|
|
222
|
+
ensureFluidResolvedUrl(resolvedUrl);
|
|
223
|
+
const parsedUrl = parseFluidUrl(resolvedUrl.url);
|
|
224
|
+
const [, tenantId, documentId] = parsedUrl.pathname.split("/");
|
|
225
|
+
if (!documentId || !tenantId) {
|
|
226
|
+
throw new Error(
|
|
227
|
+
`Couldn't parse documentId and/or tenantId. [documentId:${documentId}][tenantId:${tenantId}]`,
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
const logger2 = ChildLogger.create(logger, "RouterliciousDriver", {
|
|
231
|
+
all: { driverVersion },
|
|
232
|
+
});
|
|
199
233
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
session?: ISession,
|
|
210
|
-
): Promise<IDocumentService> {
|
|
211
|
-
ensureFluidResolvedUrl(resolvedUrl);
|
|
234
|
+
const rateLimiter = new RateLimiter(this.driverPolicies.maxConcurrentOrdererRequests);
|
|
235
|
+
const ordererRestWrapper = await RouterliciousOrdererRestWrapper.load(
|
|
236
|
+
tenantId,
|
|
237
|
+
documentId,
|
|
238
|
+
this.tokenProvider,
|
|
239
|
+
logger2,
|
|
240
|
+
rateLimiter,
|
|
241
|
+
this.driverPolicies.enableRestLess,
|
|
242
|
+
);
|
|
212
243
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
`Couldn't parse documentId and/or tenantId. [documentId:${documentId}][tenantId:${tenantId}]`);
|
|
218
|
-
}
|
|
219
|
-
const logger2 = ChildLogger.create(logger, "RouterliciousDriver", { all: { driverVersion } });
|
|
244
|
+
const discoverFluidResolvedUrl = async (): Promise<IFluidResolvedUrl> => {
|
|
245
|
+
if (!this.driverPolicies.enableDiscovery) {
|
|
246
|
+
return resolvedUrl;
|
|
247
|
+
}
|
|
220
248
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
249
|
+
const discoveredSession = await PerformanceEvent.timedExecAsync(
|
|
250
|
+
logger2,
|
|
251
|
+
{
|
|
252
|
+
eventName: "DiscoverSession",
|
|
253
|
+
docId: documentId,
|
|
254
|
+
},
|
|
255
|
+
async () => {
|
|
256
|
+
// The service responds with the current document session associated with the container.
|
|
257
|
+
return ordererRestWrapper.get<ISession>(
|
|
258
|
+
`${resolvedUrl.endpoints.ordererUrl}/documents/${tenantId}/session/${documentId}`,
|
|
259
|
+
);
|
|
260
|
+
},
|
|
261
|
+
);
|
|
262
|
+
return getDiscoveredFluidResolvedUrl(resolvedUrl, discoveredSession);
|
|
263
|
+
};
|
|
264
|
+
const fluidResolvedUrl: IFluidResolvedUrl =
|
|
265
|
+
session !== undefined
|
|
266
|
+
? getDiscoveredFluidResolvedUrl(resolvedUrl, session)
|
|
267
|
+
: await discoverFluidResolvedUrl();
|
|
235
268
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
`/documents/${tenantId}/session/${documentId}`);
|
|
246
|
-
});
|
|
247
|
-
return getDiscoveredFluidResolvedUrl(resolvedUrl, discoveredSession);
|
|
248
|
-
};
|
|
249
|
-
const fluidResolvedUrl: IFluidResolvedUrl = session !== undefined
|
|
250
|
-
? getDiscoveredFluidResolvedUrl(resolvedUrl, session)
|
|
251
|
-
: await discoverFluidResolvedUrl();
|
|
269
|
+
const storageUrl = fluidResolvedUrl.endpoints.storageUrl;
|
|
270
|
+
const ordererUrl = fluidResolvedUrl.endpoints.ordererUrl;
|
|
271
|
+
const deltaStorageUrl = fluidResolvedUrl.endpoints.deltaStorageUrl;
|
|
272
|
+
const deltaStreamUrl = fluidResolvedUrl.endpoints.deltaStreamUrl || ordererUrl; // backward compatibility
|
|
273
|
+
if (!ordererUrl || !deltaStorageUrl) {
|
|
274
|
+
throw new Error(
|
|
275
|
+
`All endpoints urls must be provided. [ordererUrl:${ordererUrl}][deltaStorageUrl:${deltaStorageUrl}]`,
|
|
276
|
+
);
|
|
277
|
+
}
|
|
252
278
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
279
|
+
const documentStorageServicePolicies: IDocumentStorageServicePolicies = {
|
|
280
|
+
caching: this.driverPolicies.enablePrefetch
|
|
281
|
+
? LoaderCachingPolicy.Prefetch
|
|
282
|
+
: LoaderCachingPolicy.NoCaching,
|
|
283
|
+
minBlobSize: this.driverPolicies.aggregateBlobsSmallerThanBytes,
|
|
284
|
+
maximumCacheDurationMs: maximumSnapshotCacheDurationMs,
|
|
285
|
+
};
|
|
261
286
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
287
|
+
return new DocumentService(
|
|
288
|
+
fluidResolvedUrl,
|
|
289
|
+
ordererUrl,
|
|
290
|
+
deltaStorageUrl,
|
|
291
|
+
deltaStreamUrl,
|
|
292
|
+
storageUrl,
|
|
293
|
+
logger2,
|
|
294
|
+
this.tokenProvider,
|
|
295
|
+
tenantId,
|
|
296
|
+
documentId,
|
|
297
|
+
ordererRestWrapper,
|
|
298
|
+
documentStorageServicePolicies,
|
|
299
|
+
this.driverPolicies,
|
|
300
|
+
this.blobCache,
|
|
301
|
+
this.snapshotTreeCache,
|
|
302
|
+
discoverFluidResolvedUrl,
|
|
303
|
+
);
|
|
304
|
+
}
|
|
277
305
|
}
|
|
278
306
|
|
|
279
307
|
/**
|
|
@@ -288,16 +316,18 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
|
|
|
288
316
|
* - What would a retry pattern look like here?
|
|
289
317
|
*/
|
|
290
318
|
export class DocumentPostCreateError extends Error {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
319
|
+
public constructor(
|
|
320
|
+
/**
|
|
321
|
+
* Inner error being wrapped.
|
|
322
|
+
*/
|
|
323
|
+
private readonly innerError: Error,
|
|
324
|
+
) {
|
|
325
|
+
super(innerError.message);
|
|
326
|
+
}
|
|
299
327
|
|
|
300
|
-
|
|
328
|
+
public readonly name = "DocumentPostCreateError";
|
|
301
329
|
|
|
302
|
-
|
|
330
|
+
public get stack() {
|
|
331
|
+
return this.innerError.stack;
|
|
332
|
+
}
|
|
303
333
|
}
|