@fluidframework/driver-utils 1.2.7 → 2.0.0-dev.1.3.0.96595

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 (63) hide show
  1. package/.mocharc.js +12 -0
  2. package/dist/documentStorageServiceProxy.d.ts +2 -2
  3. package/dist/documentStorageServiceProxy.d.ts.map +1 -1
  4. package/dist/documentStorageServiceProxy.js +2 -2
  5. package/dist/documentStorageServiceProxy.js.map +1 -1
  6. package/dist/messageRecognition.d.ts +38 -22
  7. package/dist/messageRecognition.d.ts.map +1 -1
  8. package/dist/messageRecognition.js +48 -23
  9. package/dist/messageRecognition.js.map +1 -1
  10. package/dist/network.d.ts +15 -1
  11. package/dist/network.d.ts.map +1 -1
  12. package/dist/network.js +22 -1
  13. package/dist/network.js.map +1 -1
  14. package/dist/packageVersion.d.ts +1 -1
  15. package/dist/packageVersion.d.ts.map +1 -1
  16. package/dist/packageVersion.js +1 -1
  17. package/dist/packageVersion.js.map +1 -1
  18. package/dist/parallelRequests.d.ts +14 -2
  19. package/dist/parallelRequests.d.ts.map +1 -1
  20. package/dist/parallelRequests.js +21 -7
  21. package/dist/parallelRequests.js.map +1 -1
  22. package/dist/readAndParse.d.ts +9 -4
  23. package/dist/readAndParse.d.ts.map +1 -1
  24. package/dist/readAndParse.js +9 -4
  25. package/dist/readAndParse.js.map +1 -1
  26. package/dist/runWithRetry.d.ts +9 -5
  27. package/dist/runWithRetry.d.ts.map +1 -1
  28. package/dist/runWithRetry.js.map +1 -1
  29. package/lib/documentStorageServiceProxy.d.ts +2 -2
  30. package/lib/documentStorageServiceProxy.d.ts.map +1 -1
  31. package/lib/documentStorageServiceProxy.js +2 -2
  32. package/lib/documentStorageServiceProxy.js.map +1 -1
  33. package/lib/messageRecognition.d.ts +38 -22
  34. package/lib/messageRecognition.d.ts.map +1 -1
  35. package/lib/messageRecognition.js +46 -22
  36. package/lib/messageRecognition.js.map +1 -1
  37. package/lib/network.d.ts +15 -1
  38. package/lib/network.d.ts.map +1 -1
  39. package/lib/network.js +19 -0
  40. package/lib/network.js.map +1 -1
  41. package/lib/packageVersion.d.ts +1 -1
  42. package/lib/packageVersion.d.ts.map +1 -1
  43. package/lib/packageVersion.js +1 -1
  44. package/lib/packageVersion.js.map +1 -1
  45. package/lib/parallelRequests.d.ts +14 -2
  46. package/lib/parallelRequests.d.ts.map +1 -1
  47. package/lib/parallelRequests.js +21 -7
  48. package/lib/parallelRequests.js.map +1 -1
  49. package/lib/readAndParse.d.ts +9 -4
  50. package/lib/readAndParse.d.ts.map +1 -1
  51. package/lib/readAndParse.js +9 -4
  52. package/lib/readAndParse.js.map +1 -1
  53. package/lib/runWithRetry.d.ts +9 -5
  54. package/lib/runWithRetry.d.ts.map +1 -1
  55. package/lib/runWithRetry.js.map +1 -1
  56. package/package.json +40 -17
  57. package/src/documentStorageServiceProxy.ts +8 -2
  58. package/src/messageRecognition.ts +48 -23
  59. package/src/network.ts +31 -0
  60. package/src/packageVersion.ts +1 -1
  61. package/src/parallelRequests.ts +21 -6
  62. package/src/readAndParse.ts +9 -4
  63. package/src/runWithRetry.ts +9 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/driver-utils",
3
- "version": "1.2.7",
3
+ "version": "2.0.0-dev.1.3.0.96595",
4
4
  "description": "Collection of utility functions for Fluid drivers",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -61,29 +61,30 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "@fluidframework/common-definitions": "^0.20.1",
64
- "@fluidframework/common-utils": "^0.32.1",
65
- "@fluidframework/core-interfaces": "^1.2.7",
66
- "@fluidframework/driver-definitions": "^1.2.7",
67
- "@fluidframework/gitresources": "^0.1036.5000",
68
- "@fluidframework/protocol-base": "^0.1036.5000",
69
- "@fluidframework/protocol-definitions": "^0.1028.2000",
70
- "@fluidframework/telemetry-utils": "^1.2.7",
64
+ "@fluidframework/common-utils": "^1.0.0",
65
+ "@fluidframework/core-interfaces": "2.0.0-dev.1.3.0.96595",
66
+ "@fluidframework/driver-definitions": "2.0.0-dev.1.3.0.96595",
67
+ "@fluidframework/gitresources": "^0.1037.2001",
68
+ "@fluidframework/protocol-base": "^0.1037.2001",
69
+ "@fluidframework/protocol-definitions": "^1.0.0",
70
+ "@fluidframework/telemetry-utils": "2.0.0-dev.1.3.0.96595",
71
71
  "axios": "^0.26.0",
72
+ "url": "^0.11.0",
72
73
  "uuid": "^8.3.1"
73
74
  },
74
75
  "devDependencies": {
75
- "@fluidframework/build-common": "^0.24.0",
76
- "@fluidframework/build-tools": "^0.2.74327",
77
- "@fluidframework/driver-utils-previous": "npm:@fluidframework/driver-utils@1.2.1",
78
- "@fluidframework/eslint-config-fluid": "^0.28.2000",
79
- "@fluidframework/mocha-test-setup": "^1.2.7",
80
- "@fluidframework/runtime-utils": "^1.2.7",
76
+ "@fluidframework/build-common": "^1.0.0",
77
+ "@fluidframework/build-tools": "^0.4.6000",
78
+ "@fluidframework/driver-utils-previous": "npm:@fluidframework/driver-utils@^1.0.0",
79
+ "@fluidframework/eslint-config-fluid": "^1.0.0",
80
+ "@fluidframework/mocha-test-setup": "2.0.0-dev.1.3.0.96595",
81
+ "@fluidframework/runtime-utils": "2.0.0-dev.1.3.0.96595",
81
82
  "@microsoft/api-extractor": "^7.22.2",
82
83
  "@rushstack/eslint-config": "^2.5.1",
83
84
  "@types/mocha": "^9.1.1",
84
85
  "@types/node": "^14.18.0",
85
86
  "concurrently": "^6.2.0",
86
- "copyfiles": "^2.1.0",
87
+ "copyfiles": "^2.4.1",
87
88
  "cross-env": "^7.0.2",
88
89
  "eslint": "~8.6.0",
89
90
  "mocha": "^10.0.0",
@@ -93,7 +94,29 @@
93
94
  "typescript-formatter": "7.1.0"
94
95
  },
95
96
  "typeValidation": {
96
- "version": "1.2.2",
97
- "broken": {}
97
+ "version": "2.0.0",
98
+ "broken": {
99
+ "RemovedFunctionDeclaration_convertSnapshotAndBlobsToSummaryTree": {
100
+ "forwardCompat": false,
101
+ "backCompat": false
102
+ },
103
+ "RemovedInterfaceDeclaration_ISummaryTreeAssemblerProps": {
104
+ "forwardCompat": false,
105
+ "backCompat": false
106
+ },
107
+ "RemovedClassDeclaration_SummaryTreeAssembler": {
108
+ "forwardCompat": false,
109
+ "backCompat": false
110
+ },
111
+ "ClassDeclaration_AuthorizationError": {
112
+ "backCompat": false
113
+ },
114
+ "ClassDeclaration_GenericNetworkError": {
115
+ "backCompat": false
116
+ },
117
+ "ClassDeclaration_ThrottlingError": {
118
+ "backCompat": false
119
+ }
120
+ }
98
121
  }
99
122
  }
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  import {
7
+ FetchSource,
7
8
  IDocumentStorageService,
8
9
  IDocumentStorageServicePolicies,
9
10
  ISummaryContext,
@@ -37,8 +38,13 @@ export class DocumentStorageServiceProxy implements IDocumentStorageService {
37
38
  return this.internalStorageService.getSnapshotTree(version, scenarioName);
38
39
  }
39
40
 
40
- public async getVersions(versionId: string | null, count: number, scenarioName?: string): Promise<IVersion[]> {
41
- return this.internalStorageService.getVersions(versionId, count, scenarioName);
41
+ public async getVersions(
42
+ versionId: string | null,
43
+ count: number,
44
+ scenarioName?: string,
45
+ fetchSource?: FetchSource,
46
+ ): Promise<IVersion[]> {
47
+ return this.internalStorageService.getVersions(versionId, count, scenarioName, fetchSource);
42
48
  }
43
49
 
44
50
  public async uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string> {
@@ -5,14 +5,19 @@
5
5
  import { IDocumentMessage, ISequencedDocumentMessage, MessageType } from "@fluidframework/protocol-definitions";
6
6
 
7
7
  /**
8
+ * Determines whether or not the message type is one of the following:
8
9
  *
9
- * @param message-message
10
- * @returns whether or not the message type is one listed below
11
- * "op"
12
- * "summarize"
13
- * "propose"
14
- * "reject"
15
- * "noop"
10
+ * - {@link @fluidframework/protocol-definitions#MessageType.Operation}
11
+ *
12
+ * - {@link @fluidframework/protocol-definitions#MessageType.Summarize}
13
+ *
14
+ * - {@link @fluidframework/protocol-definitions#MessageType.Propose}
15
+ *
16
+ * - {@link @fluidframework/protocol-definitions#MessageType.Reject}
17
+ *
18
+ * - {@link @fluidframework/protocol-definitions#MessageType2.Accept}
19
+ *
20
+ * - {@link @fluidframework/protocol-definitions#MessageType.NoOp}
16
21
  */
17
22
  export function isClientMessage(message: ISequencedDocumentMessage | IDocumentMessage): boolean {
18
23
  if (isRuntimeMessage(message)) {
@@ -22,6 +27,8 @@ export function isClientMessage(message: ISequencedDocumentMessage | IDocumentMe
22
27
  case MessageType.Propose:
23
28
  case MessageType.Reject:
24
29
  case MessageType.NoOp:
30
+ case MessageType2.Accept:
31
+ case MessageType.Summarize:
25
32
  return true;
26
33
  default:
27
34
  return false;
@@ -29,14 +36,12 @@ export function isClientMessage(message: ISequencedDocumentMessage | IDocumentMe
29
36
  }
30
37
 
31
38
  /**
32
- *
33
- * @param message-message
34
- * @returns whether or not the message type is one listed below
35
- * "op"
36
- * "summarize"
39
+ * Tells if message was sent by container runtime
40
+ * @privateRemarks ADO #1385: To be moved to container-definitions
41
+ * @returns whether the message is a runtime message
37
42
  */
38
- export function isRuntimeMessage(message: ISequencedDocumentMessage | IDocumentMessage): boolean {
39
- return message.type === MessageType.Operation || message.type === MessageType.Summarize;
43
+ export function isRuntimeMessage(message: { type: string; }): boolean {
44
+ return message.type === MessageType.Operation;
40
45
  }
41
46
 
42
47
  enum RuntimeMessage {
@@ -50,16 +55,23 @@ enum RuntimeMessage {
50
55
  }
51
56
 
52
57
  /**
58
+ * Determines whether or not the message type is one of the following: (legacy)
59
+ *
60
+ * - "component"
61
+ *
62
+ * - "attach"
63
+ *
64
+ * - "chunkedOp"
53
65
  *
54
- * @param message-message
55
- * @returns whether or not the message type is one listed below (legacy)
56
- * "component"
57
- * "attach"
58
- * "chunkedOp"
59
- * "blobAttach"
60
- * "rejoin"
61
- * "alias"
62
- * "op"
66
+ * - "blobAttach"
67
+ *
68
+ * - "rejoin"
69
+ *
70
+ * - "alias"
71
+ *
72
+ * - "op"
73
+ *
74
+ * @deprecated This API should not be used.
63
75
  */
64
76
  export function isUnpackedRuntimeMessage(message: ISequencedDocumentMessage): boolean {
65
77
  if ((Object.values(RuntimeMessage) as string[]).includes(message.type)) {
@@ -67,3 +79,16 @@ export function isUnpackedRuntimeMessage(message: ISequencedDocumentMessage): bo
67
79
  }
68
80
  return false;
69
81
  }
82
+
83
+ // ADO #1385: staging code changes across layers.
84
+ // Eventually to be replaced by MessageType.accept
85
+ export enum MessageType2 {
86
+ Accept = "accept",
87
+ }
88
+
89
+ // ADO #1385: To be moved to packages/protocol-base/src/protocol.ts
90
+ export function canBeCoalescedByService(message: ISequencedDocumentMessage | IDocumentMessage): boolean {
91
+ // This assumes that in the future relay service may implement coalescing of accept messages,
92
+ // same way it was doing coalescing of immediate noops in the past.
93
+ return message.type === MessageType.NoOp || message.type === MessageType2.Accept;
94
+ }
package/src/network.ts CHANGED
@@ -8,6 +8,8 @@ import {
8
8
  IDriverErrorBase,
9
9
  IAuthorizationError,
10
10
  DriverErrorType,
11
+ ILocationRedirectionError,
12
+ IResolvedUrl,
11
13
  } from "@fluidframework/driver-definitions";
12
14
  import { ITelemetryProperties } from "@fluidframework/common-definitions";
13
15
  import { IFluidErrorBase, LoggingError } from "@fluidframework/telemetry-utils";
@@ -59,6 +61,21 @@ export class GenericNetworkError extends LoggingError implements IDriverErrorBas
59
61
  }
60
62
  }
61
63
 
64
+ /**
65
+ * FluidInvalidSchema error class.
66
+ */
67
+ export class FluidInvalidSchemaError extends LoggingError implements IDriverErrorBase, IFluidErrorBase {
68
+ readonly errorType = DriverErrorType.fluidInvalidSchema;
69
+ readonly canRetry = false;
70
+
71
+ constructor(
72
+ message: string,
73
+ props: DriverErrorTelemetryProps,
74
+ ) {
75
+ super(message, props);
76
+ }
77
+ }
78
+
62
79
  // Todo GH #6214: Remove after next drive def bump. This is necessary as there is no
63
80
  // compatible way to augment an enum, as it can't be optional. So for now
64
81
  // we need to duplicate the value here. We likely need to rethink our
@@ -91,6 +108,20 @@ export class AuthorizationError extends LoggingError implements IAuthorizationEr
91
108
  }
92
109
  }
93
110
 
111
+ export class LocationRedirectionError extends LoggingError implements ILocationRedirectionError, IFluidErrorBase {
112
+ readonly errorType = DriverErrorType.locationRedirection;
113
+ readonly canRetry = false;
114
+
115
+ constructor(
116
+ message: string,
117
+ readonly redirectUrl: IResolvedUrl,
118
+ props: DriverErrorTelemetryProps,
119
+ ) {
120
+ // do not log redirectURL
121
+ super(message, props, new Set(["redirectUrl"]));
122
+ }
123
+ }
124
+
94
125
  export class NetworkErrorBasic<T extends string> extends LoggingError implements IFluidErrorBase {
95
126
  constructor(
96
127
  message: string,
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/driver-utils";
9
- export const pkgVersion = "1.2.7";
9
+ export const pkgVersion = "2.0.0-dev.1.3.0.96595";
@@ -23,7 +23,7 @@ type WorkingState = "working" | "done" | "canceled";
23
23
  * data in the right order. Take a look at UT for examples.
24
24
  * @param concurrency - level of concurrency
25
25
  * @param from - starting point of fetching data (inclusive)
26
- * @param to - ending point of fetching data. exclusive, or undefined if unknown
26
+ * @param to - ending point of fetching data. exclusive, or undefined if unknown
27
27
  * @param payloadSize - batch size
28
28
  * @param logger - logger to use
29
29
  * @param requestCallback - callback to request batches
@@ -354,6 +354,9 @@ export class Queue<T> implements IStream<T> {
354
354
  * @param telemetryEvent - telemetry event used to track consecutive batch of requests
355
355
  * @param strongTo - tells if ops in range from...to have to be there and have to be retrieved.
356
356
  * If false, returning less ops would mean we reached end of file.
357
+ * @param logger - logger object to use to log progress & errors
358
+ * @param signal - cancelation signal
359
+ * @param scenarioName - reason for fetching ops
357
360
  * @returns - an object with resulting ops and cancellation / partial result flags
358
361
  */
359
362
  async function getSingleOpBatch(
@@ -362,7 +365,7 @@ async function getSingleOpBatch(
362
365
  strongTo: boolean,
363
366
  logger: ITelemetryLogger,
364
367
  signal?: AbortSignal,
365
- fetchReason?: string):
368
+ scenarioName?: string):
366
369
  Promise<{ partial: boolean; cancel: boolean; payload: ISequencedDocumentMessage[]; }> {
367
370
  let lastSuccessTime: number | undefined;
368
371
 
@@ -426,7 +429,7 @@ async function getSingleOpBatch(
426
429
  retry,
427
430
  duration: performance.now() - startTime,
428
431
  retryAfter,
429
- fetchReason,
432
+ reason: scenarioName,
430
433
  },
431
434
  error);
432
435
 
@@ -446,6 +449,18 @@ async function getSingleOpBatch(
446
449
  return nothing;
447
450
  }
448
451
 
452
+ /**
453
+ * Request ops from storage
454
+ * @param get - Getter callback to get individual batches
455
+ * @param concurrency - Number of concurrent requests to make
456
+ * @param fromTotal - starting sequence number to fetch (inclusive)
457
+ * @param toTotal - max (exclusive) sequence number to fetch
458
+ * @param payloadSize - Payload size
459
+ * @param logger - Logger to log progress and errors
460
+ * @param signal - Cancelation signal
461
+ * @param scenarioName - Reason for fetching ops
462
+ * @returns - Messages fetched
463
+ */
449
464
  export function requestOps(
450
465
  get: (from: number, to: number, telemetryProps: ITelemetryProperties) => Promise<IDeltasFetchResult>,
451
466
  concurrency: number,
@@ -454,7 +469,7 @@ export function requestOps(
454
469
  payloadSize: number,
455
470
  logger: ITelemetryLogger,
456
471
  signal?: AbortSignal,
457
- fetchReason?: string,
472
+ scenarioName?: string,
458
473
  ): IStream<ISequencedDocumentMessage[]> {
459
474
  let requests = 0;
460
475
  let lastFetch: number | undefined;
@@ -469,7 +484,7 @@ export function requestOps(
469
484
  const telemetryEvent = PerformanceEvent.start(logger, {
470
485
  eventName: "GetDeltas",
471
486
  ...propsTotal,
472
- fetchReason,
487
+ reason: scenarioName,
473
488
  });
474
489
 
475
490
  const manager = new ParallelRequests<ISequencedDocumentMessage>(
@@ -485,7 +500,7 @@ export function requestOps(
485
500
  strongTo,
486
501
  logger,
487
502
  signal,
488
- fetchReason,
503
+ scenarioName,
489
504
  );
490
505
  },
491
506
  (deltas: ISequencedDocumentMessage[]) => {
@@ -7,11 +7,16 @@ import { bufferToString } from "@fluidframework/common-utils";
7
7
  import { IDocumentStorageService } from "@fluidframework/driver-definitions";
8
8
 
9
9
  /**
10
- * Read a blob from IDocumentStorageService and JSON.parse it into object of type T
10
+ * Read a blob from {@link @fluidframework/driver-definitions#IDocumentStorageService} and
11
+ * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse | JSON.parse}
12
+ * it into object of type `T`.
11
13
  *
12
- * @param storage - the IDocumentStorageService to read from
13
- * @param id - the id of the blob to read and parse
14
- * @returns the object that we decoded and JSON.parse
14
+ * @param storage - The `DocumentStorageService` to read from.
15
+ * @param id - The ID of the blob to read and parse.
16
+ *
17
+ * @typeParam T - Output type matching JSON format of inpyt blob data.
18
+ *
19
+ * @returns The object that we decoded and parsed via `JSON.parse`.
15
20
  */
16
21
  export async function readAndParse<T>(storage: Pick<IDocumentStorageService, "readBlob">, id: string): Promise<T> {
17
22
  const blob = await storage.readBlob(id);
@@ -16,14 +16,18 @@ import { NonRetryableError } from ".";
16
16
  */
17
17
  export interface IProgress {
18
18
  /**
19
- * Abort signal used to cancel operation
20
- * Note that most of the layers do not use this signal yet. We need to change that over time.
19
+ * Abort signal used to cancel operation.
20
+ *
21
+ * @remarks Note that most of the layers do not use this signal yet. We need to change that over time.
21
22
  * Please consult with API documentation / implementation.
22
23
  * Note that number of layers may not check this signal while holding this request in a queue,
23
24
  * so it may take a while it takes effect. This can be improved in the future.
24
- * Layers in question are:
25
- * - driver (RateLimiter)
26
- * - runWithRetry
25
+ *
26
+ * The layers in question are:
27
+ *
28
+ * - driver (RateLimiter)
29
+ *
30
+ * - runWithRetry
27
31
  */
28
32
  cancel?: AbortSignal;
29
33