@fluidframework/local-driver 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.
Files changed (91) hide show
  1. package/.eslintrc.js +19 -22
  2. package/.mocharc.js +2 -2
  3. package/api-extractor.json +4 -0
  4. package/dist/auth.d.ts.map +1 -1
  5. package/dist/auth.js +2 -2
  6. package/dist/auth.js.map +1 -1
  7. package/dist/localCreateDocument.d.ts +8 -0
  8. package/dist/localCreateDocument.d.ts.map +1 -0
  9. package/dist/localCreateDocument.js +29 -0
  10. package/dist/localCreateDocument.js.map +1 -0
  11. package/dist/localDeltaStorageService.d.ts.map +1 -1
  12. package/dist/localDeltaStorageService.js.map +1 -1
  13. package/dist/localDocumentDeltaConnection.d.ts.map +1 -1
  14. package/dist/localDocumentDeltaConnection.js.map +1 -1
  15. package/dist/localDocumentService.d.ts.map +1 -1
  16. package/dist/localDocumentService.js +4 -1
  17. package/dist/localDocumentService.js.map +1 -1
  18. package/dist/localDocumentServiceFactory.d.ts +0 -1
  19. package/dist/localDocumentServiceFactory.d.ts.map +1 -1
  20. package/dist/localDocumentServiceFactory.js +4 -20
  21. package/dist/localDocumentServiceFactory.js.map +1 -1
  22. package/dist/localDocumentStorageService.d.ts +5 -2
  23. package/dist/localDocumentStorageService.d.ts.map +1 -1
  24. package/dist/localDocumentStorageService.js +18 -4
  25. package/dist/localDocumentStorageService.js.map +1 -1
  26. package/dist/localResolver.d.ts.map +1 -1
  27. package/dist/localResolver.js.map +1 -1
  28. package/dist/localSessionStorageDb.d.ts.map +1 -1
  29. package/dist/localSessionStorageDb.js +3 -2
  30. package/dist/localSessionStorageDb.js.map +1 -1
  31. package/dist/packageVersion.d.ts +1 -1
  32. package/dist/packageVersion.js +1 -1
  33. package/dist/packageVersion.js.map +1 -1
  34. package/lib/auth.d.ts +12 -0
  35. package/lib/auth.d.ts.map +1 -0
  36. package/lib/auth.js +38 -0
  37. package/lib/auth.js.map +1 -0
  38. package/lib/index.d.ts +12 -0
  39. package/lib/index.d.ts.map +1 -0
  40. package/lib/index.js +12 -0
  41. package/lib/index.js.map +1 -0
  42. package/lib/localCreateDocument.d.ts +8 -0
  43. package/lib/localCreateDocument.d.ts.map +1 -0
  44. package/lib/localCreateDocument.js +25 -0
  45. package/lib/localCreateDocument.js.map +1 -0
  46. package/lib/localDeltaStorageService.d.ts +19 -0
  47. package/lib/localDeltaStorageService.d.ts.map +1 -0
  48. package/lib/localDeltaStorageService.js +31 -0
  49. package/lib/localDeltaStorageService.js.map +1 -0
  50. package/lib/localDocumentDeltaConnection.d.ts +47 -0
  51. package/lib/localDocumentDeltaConnection.d.ts.map +1 -0
  52. package/lib/localDocumentDeltaConnection.js +88 -0
  53. package/lib/localDocumentDeltaConnection.js.map +1 -0
  54. package/lib/localDocumentService.d.ts +52 -0
  55. package/lib/localDocumentService.d.ts.map +1 -0
  56. package/lib/localDocumentService.js +80 -0
  57. package/lib/localDocumentService.js.map +1 -0
  58. package/lib/localDocumentServiceFactory.d.ts +43 -0
  59. package/lib/localDocumentServiceFactory.d.ts.map +1 -0
  60. package/lib/localDocumentServiceFactory.js +81 -0
  61. package/lib/localDocumentServiceFactory.js.map +1 -0
  62. package/lib/localDocumentStorageService.d.ts +27 -0
  63. package/lib/localDocumentStorageService.d.ts.map +1 -0
  64. package/lib/localDocumentStorageService.js +85 -0
  65. package/lib/localDocumentStorageService.js.map +1 -0
  66. package/lib/localResolver.d.ts +26 -0
  67. package/lib/localResolver.d.ts.map +1 -0
  68. package/lib/localResolver.js +70 -0
  69. package/lib/localResolver.js.map +1 -0
  70. package/lib/localSessionStorageDb.d.ts +10 -0
  71. package/lib/localSessionStorageDb.d.ts.map +1 -0
  72. package/lib/localSessionStorageDb.js +295 -0
  73. package/lib/localSessionStorageDb.js.map +1 -0
  74. package/lib/packageVersion.d.ts +9 -0
  75. package/lib/packageVersion.d.ts.map +1 -0
  76. package/lib/packageVersion.js +9 -0
  77. package/lib/packageVersion.js.map +1 -0
  78. package/package.json +59 -49
  79. package/prettier.config.cjs +1 -1
  80. package/src/auth.ts +35 -29
  81. package/src/localCreateDocument.ts +48 -0
  82. package/src/localDeltaStorageService.ts +26 -29
  83. package/src/localDocumentDeltaConnection.ts +89 -85
  84. package/src/localDocumentService.ts +108 -95
  85. package/src/localDocumentServiceFactory.ts +94 -122
  86. package/src/localDocumentStorageService.ts +35 -11
  87. package/src/localResolver.ts +55 -55
  88. package/src/localSessionStorageDb.ts +270 -263
  89. package/src/packageVersion.ts +1 -1
  90. package/tsconfig.esnext.json +7 -0
  91. package/tsconfig.json +9 -13
@@ -5,146 +5,118 @@
5
5
 
6
6
  import { parse } from "url";
7
7
  import {
8
- IDocumentService,
9
- IDocumentServiceFactory,
10
- IDocumentServicePolicies,
11
- IResolvedUrl,
8
+ IDocumentService,
9
+ IDocumentServiceFactory,
10
+ IDocumentServicePolicies,
11
+ IResolvedUrl,
12
12
  } from "@fluidframework/driver-definitions";
13
13
  import { ITelemetryBaseLogger } from "@fluidframework/common-definitions";
14
14
  import { DefaultTokenProvider } from "@fluidframework/routerlicious-driver";
15
- import { ILocalDeltaConnectionServer, LocalDeltaConnectionServer } from "@fluidframework/server-local-server";
16
- import {
17
- ensureFluidResolvedUrl,
18
- getDocAttributesFromProtocolSummary,
19
- getQuorumValuesFromProtocolSummary,
20
- } from "@fluidframework/driver-utils";
15
+ import { ILocalDeltaConnectionServer } from "@fluidframework/server-local-server";
16
+ import { ensureFluidResolvedUrl } from "@fluidframework/driver-utils";
21
17
  import { ISummaryTree, NackErrorType } from "@fluidframework/protocol-definitions";
22
- import { defaultHash } from "@fluidframework/server-services-client";
23
18
  import { LocalDocumentDeltaConnection } from "./localDocumentDeltaConnection";
24
19
  import { createLocalDocumentService } from "./localDocumentService";
20
+ import { createDocument } from "./localCreateDocument";
25
21
 
26
22
  /**
27
23
  * Implementation of document service factory for local use.
28
24
  */
29
25
  export class LocalDocumentServiceFactory implements IDocumentServiceFactory {
30
- public readonly protocolName = "fluid-test:";
31
-
32
- // A map of clientId to LocalDocumentService.
33
- private readonly documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection> = new Map();
34
-
35
- /**
36
- * @param localDeltaConnectionServer - delta connection server for ops
37
- */
38
- constructor(
39
- private readonly localDeltaConnectionServer: ILocalDeltaConnectionServer,
40
- private readonly policies?: IDocumentServicePolicies,
41
- private readonly innerDocumentService?: IDocumentService) { }
26
+ // A map of clientId to LocalDocumentService.
27
+ private readonly documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection> =
28
+ new Map();
42
29
 
43
- public async createContainer(
44
- createNewSummary: ISummaryTree | undefined,
45
- resolvedUrl: IResolvedUrl,
46
- logger?: ITelemetryBaseLogger,
47
- clientIsSummarizer?: boolean,
48
- ): Promise<IDocumentService> {
49
- ensureFluidResolvedUrl(resolvedUrl);
50
- if (createNewSummary === undefined) {
51
- throw new Error("Empty file summary creation isn't supported in this driver.");
52
- }
53
- const pathName = new URL(resolvedUrl.url).pathname;
54
- const pathArr = pathName.split("/");
55
- const tenantId = pathArr[pathArr.length - 2];
56
- const id = pathArr[pathArr.length - 1];
57
- if (!this.localDeltaConnectionServer) {
58
- throw new Error("Provide the localDeltaConnectionServer!!");
59
- }
60
- const documentStorage = (this.localDeltaConnectionServer as LocalDeltaConnectionServer).documentStorage;
30
+ /**
31
+ * @param localDeltaConnectionServer - delta connection server for ops
32
+ */
33
+ constructor(
34
+ private readonly localDeltaConnectionServer: ILocalDeltaConnectionServer,
35
+ private readonly policies?: IDocumentServicePolicies,
36
+ private readonly innerDocumentService?: IDocumentService,
37
+ ) {}
61
38
 
62
- const protocolSummary = createNewSummary.tree[".protocol"] as ISummaryTree;
63
- const appSummary = createNewSummary.tree[".app"] as ISummaryTree;
64
- if (!(protocolSummary && appSummary)) {
65
- throw new Error("Protocol and App Summary required in the full summary");
66
- }
67
- const documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary);
68
- const quorumValues = getQuorumValuesFromProtocolSummary(protocolSummary);
69
- const sequenceNumber = documentAttributes.sequenceNumber;
70
- await documentStorage.createDocument(
71
- tenantId,
72
- id,
73
- appSummary,
74
- sequenceNumber,
75
- documentAttributes.term ?? 1,
76
- defaultHash,
77
- resolvedUrl.endpoints.ordererUrl ?? "",
78
- resolvedUrl.endpoints.storageUrl ?? "",
79
- resolvedUrl.endpoints.deltaStorageUrl ?? "",
80
- quorumValues,
81
- false, /* enableDiscovery */
82
- );
83
- return this.createDocumentService(resolvedUrl, logger, clientIsSummarizer);
84
- }
39
+ public async createContainer(
40
+ createNewSummary: ISummaryTree | undefined,
41
+ resolvedUrl: IResolvedUrl,
42
+ logger?: ITelemetryBaseLogger,
43
+ clientIsSummarizer?: boolean,
44
+ ): Promise<IDocumentService> {
45
+ if (!this.localDeltaConnectionServer) {
46
+ throw new Error("Provide the localDeltaConnectionServer!!");
47
+ }
48
+ if (createNewSummary !== undefined) {
49
+ ensureFluidResolvedUrl(resolvedUrl);
50
+ await createDocument(this.localDeltaConnectionServer, resolvedUrl, createNewSummary);
51
+ }
52
+ return this.createDocumentService(resolvedUrl, logger, clientIsSummarizer);
53
+ }
85
54
 
86
- /**
87
- * Creates and returns a document service for testing using the given resolved
88
- * URL for the tenant ID, document ID, and token.
89
- * @param resolvedUrl - resolved URL of document
90
- */
91
- public async createDocumentService(
92
- resolvedUrl: IResolvedUrl,
93
- logger?: ITelemetryBaseLogger,
94
- clientIsSummarizer?: boolean,
95
- ): Promise<IDocumentService> {
96
- ensureFluidResolvedUrl(resolvedUrl);
55
+ /**
56
+ * Creates and returns a document service for testing using the given resolved
57
+ * URL for the tenant ID, document ID, and token.
58
+ * @param resolvedUrl - resolved URL of document
59
+ */
60
+ public async createDocumentService(
61
+ resolvedUrl: IResolvedUrl,
62
+ logger?: ITelemetryBaseLogger,
63
+ clientIsSummarizer?: boolean,
64
+ ): Promise<IDocumentService> {
65
+ ensureFluidResolvedUrl(resolvedUrl);
97
66
 
98
- const parsedUrl = parse(resolvedUrl.url);
99
- const [, tenantId, documentId] = parsedUrl.path ? parsedUrl.path.split("/") : [];
100
- if (!documentId || !tenantId) {
101
- throw new Error(`Couldn't parse resolved url. [documentId:${documentId}][tenantId:${tenantId}]`);
102
- }
67
+ const parsedUrl = parse(resolvedUrl.url);
68
+ const [, tenantId, documentId] = parsedUrl.path ? parsedUrl.path.split("/") : [];
69
+ if (!documentId || !tenantId) {
70
+ throw new Error(
71
+ `Couldn't parse resolved url. [documentId:${documentId}][tenantId:${tenantId}]`,
72
+ );
73
+ }
103
74
 
104
- const fluidResolvedUrl = resolvedUrl;
105
- const jwtToken = fluidResolvedUrl.tokens.jwt;
106
- if (!jwtToken) {
107
- throw new Error(`Token was not provided.`);
108
- }
75
+ const fluidResolvedUrl = resolvedUrl;
76
+ const jwtToken = fluidResolvedUrl.tokens.jwt;
77
+ if (!jwtToken) {
78
+ throw new Error(`Token was not provided.`);
79
+ }
109
80
 
110
- const tokenProvider = new DefaultTokenProvider(jwtToken);
81
+ const tokenProvider = new DefaultTokenProvider(jwtToken);
111
82
 
112
- return createLocalDocumentService(
113
- resolvedUrl,
114
- this.localDeltaConnectionServer,
115
- tokenProvider,
116
- tenantId,
117
- documentId,
118
- this.documentDeltaConnectionsMap,
119
- this.policies,
120
- this.innerDocumentService);
121
- }
83
+ return createLocalDocumentService(
84
+ resolvedUrl,
85
+ this.localDeltaConnectionServer,
86
+ tokenProvider,
87
+ tenantId,
88
+ documentId,
89
+ this.documentDeltaConnectionsMap,
90
+ this.policies,
91
+ this.innerDocumentService,
92
+ );
93
+ }
122
94
 
123
- /**
124
- * Gets the document delta connection for the clientId and asks it to disconnect the client.
125
- * @param clientId - The ID of the client to be disconnected.
126
- * @param disconnectReason - The reason of the disconnection.
127
- */
128
- public disconnectClient(clientId: string, disconnectReason: string) {
129
- const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);
130
- if (documentDeltaConnection === undefined) {
131
- throw new Error(`No client with the id: ${clientId}`);
132
- }
133
- documentDeltaConnection.disconnectClient(disconnectReason);
134
- }
95
+ /**
96
+ * Gets the document delta connection for the clientId and asks it to disconnect the client.
97
+ * @param clientId - The ID of the client to be disconnected.
98
+ * @param disconnectReason - The reason of the disconnection.
99
+ */
100
+ public disconnectClient(clientId: string, disconnectReason: string) {
101
+ const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);
102
+ if (documentDeltaConnection === undefined) {
103
+ throw new Error(`No client with the id: ${clientId}`);
104
+ }
105
+ documentDeltaConnection.disconnectClient(disconnectReason);
106
+ }
135
107
 
136
- /**
137
- * Gets the document delta connection for the clientId and asks it to nack the client.
138
- * @param clientId - The ID of the client to be Nack'd.
139
- * @param code - An error code number that represents the error. It will be a valid HTTP error code.
140
- * @param type - Type of the Nack.
141
- * @param message - A message about the nack for debugging/logging/telemetry purposes.
142
- */
143
- public nackClient(clientId: string, code?: number, type?: NackErrorType, message?: any) {
144
- const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);
145
- if (documentDeltaConnection === undefined) {
146
- throw new Error(`No client with the id: ${clientId}`);
147
- }
148
- documentDeltaConnection.nackClient(code, type, message);
149
- }
108
+ /**
109
+ * Gets the document delta connection for the clientId and asks it to nack the client.
110
+ * @param clientId - The ID of the client to be Nack'd.
111
+ * @param code - An error code number that represents the error. It will be a valid HTTP error code.
112
+ * @param type - Type of the Nack.
113
+ * @param message - A message about the nack for debugging/logging/telemetry purposes.
114
+ */
115
+ public nackClient(clientId: string, code?: number, type?: NackErrorType, message?: any) {
116
+ const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);
117
+ if (documentDeltaConnection === undefined) {
118
+ throw new Error(`No client with the id: ${clientId}`);
119
+ }
120
+ documentDeltaConnection.nackClient(code, type, message);
121
+ }
150
122
  }
@@ -7,6 +7,7 @@ import { stringToBuffer, Uint8ArrayToString } from "@fluidframework/common-utils
7
7
  import {
8
8
  IDocumentStorageService,
9
9
  IDocumentStorageServicePolicies,
10
+ IResolvedUrl,
10
11
  ISummaryContext,
11
12
  } from "@fluidframework/driver-definitions";
12
13
  import {
@@ -17,7 +18,14 @@ import {
17
18
  IVersion,
18
19
  } from "@fluidframework/protocol-definitions";
19
20
  import { buildHierarchy } from "@fluidframework/protocol-base";
20
- import { GitManager, ISummaryUploadManager, SummaryTreeUploadManager } from "@fluidframework/server-services-client";
21
+ import {
22
+ GitManager,
23
+ ISummaryUploadManager,
24
+ SummaryTreeUploadManager,
25
+ } from "@fluidframework/server-services-client";
26
+ import { ILocalDeltaConnectionServer } from "@fluidframework/server-local-server";
27
+ import { ensureFluidResolvedUrl } from "@fluidframework/driver-utils";
28
+ import { createDocument } from "./localCreateDocument";
21
29
 
22
30
  export class LocalDocumentStorageService implements IDocumentStorageService {
23
31
  // The values of this cache is useless. We only need the keys. So we are always putting
@@ -32,7 +40,9 @@ export class LocalDocumentStorageService implements IDocumentStorageService {
32
40
  constructor(
33
41
  private readonly id: string,
34
42
  private readonly manager: GitManager,
35
- public readonly policies: IDocumentStorageServicePolicies = {},
43
+ public readonly policies: IDocumentStorageServicePolicies,
44
+ private readonly localDeltaConnectionServer?: ILocalDeltaConnectionServer,
45
+ private readonly resolvedUrl?: IResolvedUrl,
36
46
  ) {
37
47
  this.summaryTreeUploadManager = new SummaryTreeUploadManager(
38
48
  manager,
@@ -74,7 +84,21 @@ export class LocalDocumentStorageService implements IDocumentStorageService {
74
84
  return bufferContent;
75
85
  }
76
86
 
77
- public async uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string> {
87
+ public async uploadSummaryWithContext(
88
+ summary: ISummaryTree,
89
+ context: ISummaryContext,
90
+ ): Promise<string> {
91
+ if (context.referenceSequenceNumber === 0) {
92
+ if (this.localDeltaConnectionServer === undefined || this.resolvedUrl === undefined) {
93
+ throw new Error(
94
+ "Insufficient constructor parameters. An ILocalDeltaConnectionServer and IResolvedUrl required",
95
+ );
96
+ }
97
+ ensureFluidResolvedUrl(this.resolvedUrl);
98
+ await createDocument(this.localDeltaConnectionServer, this.resolvedUrl, summary);
99
+ const version = await this.getVersions(this.id, 1);
100
+ return version[0].id;
101
+ }
78
102
  return this.summaryTreeUploadManager.writeSummaryTree(
79
103
  summary,
80
104
  context.ackHandle ?? "",
@@ -84,24 +108,24 @@ export class LocalDocumentStorageService implements IDocumentStorageService {
84
108
 
85
109
  public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {
86
110
  const uint8ArrayFile = new Uint8Array(file);
87
- return this.manager.createBlob(
88
- Uint8ArrayToString(
89
- uint8ArrayFile, "base64"),
90
- "base64").then((r) => ({ id: r.sha, url: r.url }));
111
+ return this.manager
112
+ .createBlob(Uint8ArrayToString(uint8ArrayFile, "base64"), "base64")
113
+ .then((r) => ({ id: r.sha, url: r.url }));
91
114
  }
92
115
 
93
116
  public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {
94
117
  throw new Error("NOT IMPLEMENTED!");
95
118
  }
96
119
 
97
- private async getPreviousFullSnapshot(parentHandle: string): Promise<ISnapshotTreeEx | null | undefined> {
120
+ private async getPreviousFullSnapshot(
121
+ parentHandle: string,
122
+ ): Promise<ISnapshotTreeEx | null | undefined> {
98
123
  return parentHandle
99
- ? this.getVersions(parentHandle, 1)
100
- .then(async (versions) => {
124
+ ? this.getVersions(parentHandle, 1).then(async (versions) => {
101
125
  // Clear the cache as the getSnapshotTree call will fill the cache.
102
126
  this.blobsShaCache.clear();
103
127
  return this.getSnapshotTree(versions[0]);
104
- })
128
+ })
105
129
  : undefined;
106
130
  }
107
131
  }
@@ -7,22 +7,22 @@ import { parse } from "url";
7
7
  import { assert } from "@fluidframework/common-utils";
8
8
  import { IRequest } from "@fluidframework/core-interfaces";
9
9
  import {
10
- IFluidResolvedUrl,
11
- IResolvedUrl,
12
- IUrlResolver,
13
- DriverHeader,
10
+ IFluidResolvedUrl,
11
+ IResolvedUrl,
12
+ IUrlResolver,
13
+ DriverHeader,
14
14
  } from "@fluidframework/driver-definitions";
15
15
  import { ScopeType } from "@fluidframework/protocol-definitions";
16
16
  import { generateToken } from "./auth";
17
17
 
18
18
  export function createLocalResolverCreateNewRequest(documentId: string): IRequest {
19
- const createNewRequest: IRequest = {
20
- url: `http://localhost:3000/${documentId}`,
21
- headers: {
22
- [DriverHeader.createNew]: true,
23
- },
24
- };
25
- return createNewRequest;
19
+ const createNewRequest: IRequest = {
20
+ url: `http://localhost:3000/${documentId}`,
21
+ headers: {
22
+ [DriverHeader.createNew]: true,
23
+ },
24
+ };
25
+ return createNewRequest;
26
26
  }
27
27
 
28
28
  /**
@@ -30,55 +30,55 @@ export function createLocalResolverCreateNewRequest(documentId: string): IReques
30
30
  * related local classes.
31
31
  */
32
32
  export class LocalResolver implements IUrlResolver {
33
- private readonly tenantId = "tenantId";
34
- private readonly tokenKey = "tokenKey";
33
+ private readonly tenantId = "tenantId";
34
+ private readonly tokenKey = "tokenKey";
35
35
 
36
- constructor() { }
36
+ constructor() {}
37
37
 
38
- /**
39
- * Resolves URL requests by providing fake URLs with an actually generated
40
- * token from constant test strings. The root of the URL is fake, but the
41
- * remaining relative URL can still be parsed.
42
- * @param request - request to handle
43
- */
44
- public async resolve(request: IRequest): Promise<IResolvedUrl> {
45
- const parsedUrl = new URL(request.url);
46
- const fullPath = `${parsedUrl.pathname.substr(1)}${parsedUrl.search}`;
47
- const documentId = fullPath.split("/")[0];
48
- const scopes = [ScopeType.DocRead, ScopeType.DocWrite, ScopeType.SummaryWrite];
49
- const resolved: IFluidResolvedUrl = {
50
- endpoints: {
51
- deltaStorageUrl: `http://localhost:3000/deltas/${this.tenantId}/${documentId}`,
52
- ordererUrl: "http://localhost:3000",
53
- storageUrl: `http://localhost:3000/repos/${this.tenantId}`,
54
- },
55
- id: documentId,
56
- tokens: { jwt: generateToken(this.tenantId, documentId, this.tokenKey, scopes) },
57
- type: "fluid",
58
- url: `fluid-test://localhost:3000/${this.tenantId}/${fullPath}`,
59
- };
38
+ /**
39
+ * Resolves URL requests by providing fake URLs with an actually generated
40
+ * token from constant test strings. The root of the URL is fake, but the
41
+ * remaining relative URL can still be parsed.
42
+ * @param request - request to handle
43
+ */
44
+ public async resolve(request: IRequest): Promise<IResolvedUrl> {
45
+ const parsedUrl = new URL(request.url);
46
+ const fullPath = `${parsedUrl.pathname.substr(1)}${parsedUrl.search}`;
47
+ const documentId = fullPath.split("/")[0];
48
+ const scopes = [ScopeType.DocRead, ScopeType.DocWrite, ScopeType.SummaryWrite];
49
+ const resolved: IFluidResolvedUrl = {
50
+ endpoints: {
51
+ deltaStorageUrl: `http://localhost:3000/deltas/${this.tenantId}/${documentId}`,
52
+ ordererUrl: "http://localhost:3000",
53
+ storageUrl: `http://localhost:3000/repos/${this.tenantId}`,
54
+ },
55
+ id: documentId,
56
+ tokens: { jwt: generateToken(this.tenantId, documentId, this.tokenKey, scopes) },
57
+ type: "fluid",
58
+ url: `fluid-test://localhost:3000/${this.tenantId}/${fullPath}`,
59
+ };
60
60
 
61
- return resolved;
62
- }
61
+ return resolved;
62
+ }
63
63
 
64
- public async getAbsoluteUrl(resolvedUrl: IResolvedUrl, relativeUrl: string): Promise<string> {
65
- let url = relativeUrl;
66
- if (url.startsWith("/")) {
67
- url = url.substr(1);
68
- }
69
- const fluidResolvedUrl = resolvedUrl as IFluidResolvedUrl;
64
+ public async getAbsoluteUrl(resolvedUrl: IResolvedUrl, relativeUrl: string): Promise<string> {
65
+ let url = relativeUrl;
66
+ if (url.startsWith("/")) {
67
+ url = url.substr(1);
68
+ }
69
+ const fluidResolvedUrl = resolvedUrl as IFluidResolvedUrl;
70
70
 
71
- const parsedUrl = parse(fluidResolvedUrl.url);
72
- if (parsedUrl.pathname === null) {
73
- throw new Error("Url should contain tenant and docId!!");
74
- }
75
- const [, , documentId] = parsedUrl.pathname.split("/");
76
- assert(!!documentId, 0x09a /* "'documentId' must be a defined, non-zero length string." */);
71
+ const parsedUrl = parse(fluidResolvedUrl.url);
72
+ if (parsedUrl.pathname === null) {
73
+ throw new Error("Url should contain tenant and docId!!");
74
+ }
75
+ const [, , documentId] = parsedUrl.pathname.split("/");
76
+ assert(!!documentId, 0x09a /* "'documentId' must be a defined, non-zero length string." */);
77
77
 
78
- return `http://localhost:3000/${documentId}/${url}`;
79
- }
78
+ return `http://localhost:3000/${documentId}/${url}`;
79
+ }
80
80
 
81
- public createCreateNewRequest(documentId: string): IRequest {
82
- return createLocalResolverCreateNewRequest(documentId);
83
- }
81
+ public createCreateNewRequest(documentId: string): IRequest {
82
+ return createLocalResolverCreateNewRequest(documentId);
83
+ }
84
84
  }