@fluidframework/driver-utils 2.0.0-dev.7.2.0.204906 → 2.0.0-dev.7.3.0.206769

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.
@@ -1,588 +0,0 @@
1
- import { FetchSource } from '@fluidframework/driver-definitions';
2
- import { IAttachment } from '@fluidframework/protocol-definitions';
3
- import { IAuthorizationError } from '@fluidframework/driver-definitions';
4
- import { IBlob } from '@fluidframework/protocol-definitions';
5
- import { ICommittedProposal } from '@fluidframework/protocol-definitions';
6
- import { ICreateBlobResponse } from '@fluidframework/protocol-definitions';
7
- import { IDeltasFetchResult } from '@fluidframework/driver-definitions';
8
- import { IDocumentAttributes } from '@fluidframework/protocol-definitions';
9
- import { IDocumentMessage } from '@fluidframework/protocol-definitions';
10
- import { IDocumentServiceFactory } from '@fluidframework/driver-definitions';
11
- import { IDocumentStorageService } from '@fluidframework/driver-definitions';
12
- import { IDocumentStorageServicePolicies } from '@fluidframework/driver-definitions';
13
- import { IDriverErrorBase } from '@fluidframework/driver-definitions';
14
- import { IFluidErrorBase } from '@fluidframework/telemetry-utils';
15
- import { ILocationRedirectionError } from '@fluidframework/driver-definitions';
16
- import { IRequest } from '@fluidframework/core-interfaces';
17
- import { IResolvedUrl } from '@fluidframework/driver-definitions';
18
- import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
19
- import { ISnapshotTree } from '@fluidframework/protocol-definitions';
20
- import { IStream } from '@fluidframework/driver-definitions';
21
- import { IStreamResult } from '@fluidframework/driver-definitions';
22
- import { ISummaryContext } from '@fluidframework/driver-definitions';
23
- import { ISummaryHandle } from '@fluidframework/protocol-definitions';
24
- import { ISummaryTree } from '@fluidframework/protocol-definitions';
25
- import { ITelemetryErrorEvent } from '@fluidframework/core-interfaces';
26
- import { ITelemetryLoggerExt } from '@fluidframework/telemetry-utils';
27
- import { ITelemetryProperties } from '@fluidframework/core-interfaces';
28
- import { IThrottlingWarning } from '@fluidframework/driver-definitions';
29
- import { ITree } from '@fluidframework/protocol-definitions';
30
- import { ITreeEntry } from '@fluidframework/protocol-definitions';
31
- import { IUrlResolver } from '@fluidframework/driver-definitions';
32
- import { IVersion } from '@fluidframework/protocol-definitions';
33
- import { LoaderCachingPolicy } from '@fluidframework/driver-definitions';
34
- import { LoggingError } from '@fluidframework/telemetry-utils';
35
-
36
- /**
37
- * This method optionally applies compression to the given document service factory. The compression
38
- * must be enabled by setting the config to true or by passing a compression config object.
39
- * @param documentServiceFactory - The document service factory to apply compression to.
40
- * @param config - The compression configuration.
41
- * @returns The document service factory possibly with compression applied.
42
- * @public
43
- */
44
- export declare function applyStorageCompression(documentServiceFactory: IDocumentServiceFactory, config?: ICompressionStorageConfig | boolean): IDocumentServiceFactory;
45
-
46
- /**
47
- * Basic implementation of an attachment ITreeEntry
48
- * @public
49
- */
50
- export declare class AttachmentTreeEntry {
51
- readonly path: string;
52
- readonly id: string;
53
- readonly mode = FileMode.File;
54
- readonly type = TreeEntry.Attachment;
55
- readonly value: IAttachment;
56
- /**
57
- * Creates an attachment ITreeEntry
58
- * @param path - path of entry
59
- * @param id - id of external blob attachment
60
- */
61
- constructor(path: string, id: string);
62
- }
63
-
64
- /**
65
- * @public
66
- */
67
- export declare class AuthorizationError extends LoggingError implements IAuthorizationError, IFluidErrorBase {
68
- readonly claims: string | undefined;
69
- readonly tenantId: string | undefined;
70
- readonly errorType = DriverErrorType.authorizationError;
71
- readonly canRetry = false;
72
- constructor(message: string, claims: string | undefined, tenantId: string | undefined, props: DriverErrorTelemetryProps);
73
- }
74
-
75
- /**
76
- * @public
77
- */
78
- export declare const blobHeadersBlobName = ".metadata.blobHeaders";
79
-
80
- /**
81
- * Basic implementation of a blob ITreeEntry
82
- * @public
83
- */
84
- export declare class BlobTreeEntry {
85
- readonly path: string;
86
- readonly mode = FileMode.File;
87
- readonly type = TreeEntry.Blob;
88
- readonly value: IBlob;
89
- /**
90
- * Creates a blob ITreeEntry
91
- * @param path - path of entry
92
- * @param contents - blob contents
93
- * @param encoding - encoding of contents; defaults to utf-8
94
- */
95
- constructor(path: string, contents: string, encoding?: "utf-8" | "base64");
96
- }
97
-
98
- /**
99
- * Build a tree hierarchy base on an array of ITreeEntry
100
- *
101
- * @param entries - an array of ITreeEntry to flatten
102
- * @param blobMap - a map of blob's sha1 to content that gets filled with content from entries
103
- * NOTE: blobMap's validity is contingent on the returned promise's resolution
104
- * @returns the hierarchical tree
105
- * @public
106
- */
107
- export declare function buildSnapshotTree(entries: ITreeEntry[], blobMap: Map<string, ArrayBufferLike>): ISnapshotTree;
108
-
109
- /**
110
- * In case endpoint(service or socket) is not reachable, then we maybe offline or may have got some transient error
111
- * not related to endpoint, in that case we want to try at faster pace and hence the max wait is lesser 8s as compared
112
- * to when endpoint is reachable in which case it is 30s.
113
- * @param error - error based on which we decide max wait time.
114
- * @returns Max wait time.
115
- * @public
116
- */
117
- export declare function calculateMaxWaitTime(error: unknown): number;
118
-
119
- /**
120
- * @privateRemarks ADO #1385: To be moved to packages/protocol-base/src/protocol.ts
121
- * @public
122
- */
123
- export declare function canBeCoalescedByService(message: ISequencedDocumentMessage | IDocumentMessage): boolean;
124
-
125
- /**
126
- * Check if a connection error can be retried. Unless explicitly allowed, retry is disallowed.
127
- * I.e. asserts or unexpected exceptions in our code result in container failure.
128
- * @param error - The error to inspect for ability to retry
129
- * @public
130
- */
131
- export declare const canRetryOnError: (error: any) => boolean;
132
-
133
- /**
134
- * Defines the current layout of an .app + .protocol summary tree
135
- * this is used internally for create new, and single commit summary
136
- * @internal
137
- */
138
- export declare interface CombinedAppAndProtocolSummary extends ISummaryTree {
139
- tree: {
140
- [".app"]: ISummaryTree;
141
- [".protocol"]: ISummaryTree;
142
- };
143
- }
144
-
145
- /**
146
- * Converts ISummaryTree to ITree format.
147
- * @param summaryTree - summary tree in ISummaryTree format
148
- * @public
149
- */
150
- export declare function convertSummaryTreeToSnapshotITree(summaryTree: ISummaryTree): ITree;
151
-
152
- /**
153
- * @public
154
- */
155
- export declare function createGenericNetworkError(message: string, retryInfo: {
156
- canRetry: boolean;
157
- retryAfterMs?: number;
158
- }, props: DriverErrorTelemetryProps): ThrottlingError | GenericNetworkError;
159
-
160
- /**
161
- * @public
162
- */
163
- export declare const createWriteError: (message: string, props: DriverErrorTelemetryProps) => NonRetryableError<"writeError">;
164
-
165
- /**
166
- * @public
167
- */
168
- export declare class DeltaStreamConnectionForbiddenError extends LoggingError implements IDriverErrorBase, IFluidErrorBase {
169
- static readonly errorType = DriverErrorType.deltaStreamConnectionForbidden;
170
- readonly errorType = DriverErrorType.deltaStreamConnectionForbidden;
171
- readonly canRetry = false;
172
- readonly storageOnlyReason: string | undefined;
173
- constructor(message: string, props: DriverErrorTelemetryProps, storageOnlyReason?: string);
174
- }
175
-
176
- /**
177
- * @public
178
- */
179
- export declare class DocumentStorageServiceProxy implements IDocumentStorageService {
180
- protected readonly internalStorageService: IDocumentStorageService;
181
- private _policies;
182
- set policies(policies: IDocumentStorageServicePolicies | undefined);
183
- get policies(): IDocumentStorageServicePolicies | undefined;
184
- get repositoryUrl(): string;
185
- constructor(internalStorageService: IDocumentStorageService);
186
- getSnapshotTree(version?: IVersion, scenarioName?: string): Promise<ISnapshotTree | null>;
187
- getVersions(versionId: string | null, count: number, scenarioName?: string, fetchSource?: FetchSource): Promise<IVersion[]>;
188
- uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string>;
189
- downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree>;
190
- createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse>;
191
- readBlob(blobId: string): Promise<ArrayBufferLike>;
192
- }
193
-
194
- /**
195
- * Telemetry props with driver-specific required properties
196
- * @public
197
- */
198
- export declare type DriverErrorTelemetryProps = ITelemetryProperties & {
199
- driverVersion: string | undefined;
200
- };
201
-
202
- /**
203
- * @public
204
- */
205
- export declare const emptyMessageStream: IStream<ISequencedDocumentMessage[]>;
206
-
207
- /**
208
- * FluidInvalidSchema error class.
209
- * @public
210
- */
211
- export declare class FluidInvalidSchemaError extends LoggingError implements IDriverErrorBase, IFluidErrorBase {
212
- readonly errorType = DriverErrorType.fluidInvalidSchema;
213
- readonly canRetry = false;
214
- constructor(message: string, props: DriverErrorTelemetryProps);
215
- }
216
-
217
- /**
218
- * Generic network error class.
219
- * @public
220
- */
221
- export declare class GenericNetworkError extends LoggingError implements IDriverErrorBase, IFluidErrorBase {
222
- readonly canRetry: boolean;
223
- readonly errorType = DriverErrorType.genericNetworkError;
224
- constructor(message: string, canRetry: boolean, props: DriverErrorTelemetryProps);
225
- }
226
-
227
- /**
228
- * Extract the attributes from the protocol summary.
229
- * @param protocolSummary - protocol summary from which the values are to be extracted.
230
- * @public
231
- */
232
- export declare function getDocAttributesFromProtocolSummary(protocolSummary: ISummaryTree): IDocumentAttributes;
233
-
234
- /**
235
- * Extract quorum values from the protocol summary.
236
- * @param protocolSummary - protocol summary from which the values are to be extracted.
237
- * @public
238
- */
239
- export declare function getQuorumValuesFromProtocolSummary(protocolSummary: ISummaryTree): [string, ICommittedProposal][];
240
-
241
- /**
242
- * Check retryAfterSeconds property on error and convert to ms
243
- * @public
244
- * */
245
- export declare const getRetryDelayFromError: (error: any) => number | undefined;
246
-
247
- /**
248
- * Check retryAfterSeconds property on error
249
- * @public
250
- * */
251
- export declare const getRetryDelaySecondsFromError: (error: any) => number | undefined;
252
-
253
- /**
254
- * @public
255
- */
256
- export declare interface ICompressionStorageConfig {
257
- algorithm: SummaryCompressionAlgorithm;
258
- minSizeToCompress: number;
259
- }
260
-
261
- /**
262
- * As the name implies this is not secure and should not be used in production. It simply makes the example easier
263
- * to get up and running.
264
- *
265
- * In our example we run a simple web server via webpack-dev-server. This defines a URL format of the form
266
- * http://localhost:8080/<documentId>/<path>.
267
- *
268
- * We then need to map that to a Fluid based URL. These are of the form
269
- * fluid://orderingUrl/<tenantId>/<documentId>/<path>.
270
- *
271
- * The tenantId/documentId pair defines the 'full' document ID the service makes use of. The path is then an optional
272
- * part of the URL that the document interprets and maps to a data store. It's exactly similar to how a web service
273
- * works or a router inside of a single page app framework.
274
- * @public
275
- */
276
- export declare class InsecureUrlResolver implements IUrlResolver {
277
- private readonly hostUrl;
278
- private readonly ordererUrl;
279
- private readonly storageUrl;
280
- private readonly tenantId;
281
- private readonly bearer;
282
- private readonly isForNodeTest;
283
- private readonly cache;
284
- constructor(hostUrl: string, ordererUrl: string, storageUrl: string, tenantId: string, bearer: string, isForNodeTest?: boolean);
285
- resolve(request: IRequest): Promise<IResolvedUrl | undefined>;
286
- private resolveHelper;
287
- getAbsoluteUrl(resolvedUrl: IResolvedUrl, relativeUrl: string): Promise<string>;
288
- createCreateNewRequest(fileName?: string): IRequest;
289
- }
290
-
291
- /**
292
- * Interface describing an object passed to various network APIs.
293
- * It allows caller to control cancellation, as well as learn about any delays.
294
- * @public
295
- */
296
- export declare interface IProgress {
297
- /**
298
- * Abort signal used to cancel operation.
299
- *
300
- * @remarks Note that most of the layers do not use this signal yet. We need to change that over time.
301
- * Please consult with API documentation / implementation.
302
- * Note that number of layers may not check this signal while holding this request in a queue,
303
- * so it may take a while it takes effect. This can be improved in the future.
304
- *
305
- * The layers in question are:
306
- *
307
- * - driver (RateLimiter)
308
- *
309
- * - runWithRetry
310
- */
311
- cancel?: AbortSignal;
312
- /**
313
- * Called whenever api returns cancellable error and the call is going to be retried.
314
- * Any exception thrown from this call back result in cancellation of operation
315
- * and propagation of thrown exception.
316
- * @param delayInMs - delay before next retry. This value will depend on internal back-off logic,
317
- * as well as information provided by service (like 429 error asking to wait for some time before retry)
318
- * @param error - error object returned from the call.
319
- */
320
- onRetry?(delayInMs: number, error: any): void;
321
- }
322
-
323
- /**
324
- * Validates the current layout of an .app + .protocol summary tree
325
- * this is used internally for create new, and single commit summary
326
- * @internal
327
- */
328
- export declare function isCombinedAppAndProtocolSummary(summary: ISummaryTree | undefined, ...optionalRootTrees: string[]): summary is CombinedAppAndProtocolSummary;
329
-
330
- /**
331
- * It tells if we have local connection only - we might not have connection to web.
332
- * No solution for node.js (other than resolve dns names / ping specific sites)
333
- * Can also use window.addEventListener("online" / "offline")
334
- * @public
335
- */
336
- export declare function isOnline(): OnlineStatus;
337
-
338
- /**
339
- * Tells if message was sent by container runtime
340
- * @privateRemarks ADO #1385: To be moved to container-definitions
341
- * @returns whether the message is a runtime message
342
- * @public
343
- */
344
- export declare function isRuntimeMessage(message: {
345
- type: string;
346
- }): boolean;
347
-
348
- /**
349
- * @public
350
- */
351
- export declare class LocationRedirectionError extends LoggingError implements ILocationRedirectionError, IFluidErrorBase {
352
- readonly redirectUrl: IResolvedUrl;
353
- readonly errorType = DriverErrorType.locationRedirection;
354
- readonly canRetry = false;
355
- constructor(message: string, redirectUrl: IResolvedUrl, props: DriverErrorTelemetryProps);
356
- }
357
-
358
- /**
359
- * @public
360
- */
361
- export declare function logNetworkFailure(logger: ITelemetryLoggerExt, event: ITelemetryErrorEvent, error?: any): void;
362
-
363
- /**
364
- * @privateRemarks ADO #1385: staging code changes across layers.
365
- * Eventually to be replaced by MessageType.accept
366
- * @public
367
- */
368
- export declare enum MessageType2 {
369
- Accept = "accept"
370
- }
371
-
372
- /**
373
- * @public
374
- */
375
- export declare class NetworkErrorBasic<T extends string> extends LoggingError implements IFluidErrorBase {
376
- readonly errorType: T;
377
- readonly canRetry: boolean;
378
- constructor(message: string, errorType: T, canRetry: boolean, props: DriverErrorTelemetryProps);
379
- }
380
-
381
- /**
382
- * @public
383
- */
384
- export declare class NonRetryableError<T extends string> extends NetworkErrorBasic<T> {
385
- readonly errorType: T;
386
- constructor(message: string, errorType: T, props: DriverErrorTelemetryProps);
387
- }
388
-
389
- /**
390
- * @public
391
- */
392
- export declare enum OnlineStatus {
393
- Offline = 0,
394
- Online = 1,
395
- Unknown = 2
396
- }
397
-
398
- /**
399
- * Helper class to organize parallel fetching of data
400
- * It can be used to concurrently do many requests, while consuming
401
- * data in the right order. Take a look at UT for examples.
402
- * @param concurrency - level of concurrency
403
- * @param from - starting point of fetching data (inclusive)
404
- * @param to - ending point of fetching data. exclusive, or undefined if unknown
405
- * @param payloadSize - batch size
406
- * @param logger - logger to use
407
- * @param requestCallback - callback to request batches
408
- * @returns Queue that can be used to retrieve data
409
- * @public
410
- */
411
- export declare class ParallelRequests<T> {
412
- private to;
413
- private readonly payloadSize;
414
- private readonly logger;
415
- private readonly requestCallback;
416
- private readonly responseCallback;
417
- private latestRequested;
418
- private nextToDeliver;
419
- private readonly results;
420
- private workingState;
421
- private requestsInFlight;
422
- private readonly endEvent;
423
- private requests;
424
- private readonly knewTo;
425
- private get working();
426
- get canceled(): boolean;
427
- constructor(from: number, to: number | undefined, payloadSize: number, logger: ITelemetryLoggerExt, requestCallback: (request: number, from: number, to: number, strongTo: boolean, props: ITelemetryProperties) => Promise<{
428
- partial: boolean;
429
- cancel: boolean;
430
- payload: T[];
431
- }>, responseCallback: (payload: T[]) => void);
432
- cancel(): void;
433
- run(concurrency: number): Promise<void>;
434
- private done;
435
- private fail;
436
- private dispatch;
437
- private getNextChunk;
438
- private addRequest;
439
- private addRequestCore;
440
- }
441
-
442
- /**
443
- * @public
444
- */
445
- export declare class PrefetchDocumentStorageService extends DocumentStorageServiceProxy {
446
- private readonly prefetchCache;
447
- private prefetchEnabled;
448
- get policies(): {
449
- caching: LoaderCachingPolicy;
450
- maximumCacheDurationMs?: 432000000 | undefined;
451
- } | undefined;
452
- getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null>;
453
- readBlob(blobId: string): Promise<ArrayBufferLike>;
454
- stopPrefetch(): void;
455
- private cachedRead;
456
- private prefetchTree;
457
- private prefetchTreeCore;
458
- }
459
-
460
- /**
461
- * Helper queue class to allow async push / pull
462
- * It's essentially a pipe allowing multiple writers, and single reader
463
- * @public
464
- */
465
- export declare class Queue<T> implements IStream<T> {
466
- private readonly queue;
467
- private deferred;
468
- private done;
469
- pushValue(value: T): void;
470
- pushError(error: any): void;
471
- pushDone(): void;
472
- protected pushCore(value: Promise<IStreamResult<T>>): void;
473
- read(): Promise<IStreamResult<T>>;
474
- }
475
-
476
- /**
477
- * @public
478
- */
479
- export declare class RateLimiter {
480
- private maxRequests;
481
- private readonly tasks;
482
- constructor(maxRequests: number);
483
- get waitQueueLength(): number;
484
- protected readonly release: () => void;
485
- protected acquire(): Promise<void>;
486
- schedule<T>(work: () => Promise<T>): Promise<T>;
487
- }
488
-
489
- /**
490
- * Read a blob from {@link @fluidframework/driver-definitions#IDocumentStorageService} and
491
- * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse | JSON.parse}
492
- * it into object of type `T`.
493
- *
494
- * @param storage - The `DocumentStorageService` to read from.
495
- * @param id - The ID of the blob to read and parse.
496
- *
497
- * @typeParam T - Output type matching JSON format of inpyt blob data.
498
- *
499
- * @returns The object that we decoded and parsed via `JSON.parse`.
500
- * @public
501
- */
502
- export declare function readAndParse<T>(storage: Pick<IDocumentStorageService, "readBlob">, id: string): Promise<T>;
503
-
504
- /**
505
- * Request ops from storage
506
- * @param get - Getter callback to get individual batches
507
- * @param concurrency - Number of concurrent requests to make
508
- * @param fromTotal - starting sequence number to fetch (inclusive)
509
- * @param toTotal - max (exclusive) sequence number to fetch
510
- * @param payloadSize - Payload size
511
- * @param logger - Logger to log progress and errors
512
- * @param signal - Cancelation signal
513
- * @param scenarioName - Reason for fetching ops
514
- * @returns Messages fetched
515
- * @public
516
- */
517
- export declare function requestOps(get: (from: number, to: number, telemetryProps: ITelemetryProperties) => Promise<IDeltasFetchResult>, concurrency: number, fromTotal: number, toTotal: number | undefined, payloadSize: number, logger: ITelemetryLoggerExt, signal?: AbortSignal, scenarioName?: string): IStream<ISequencedDocumentMessage[]>;
518
-
519
- /**
520
- * @public
521
- */
522
- export declare class RetryableError<T extends string> extends NetworkErrorBasic<T> {
523
- readonly errorType: T;
524
- constructor(message: string, errorType: T, props: DriverErrorTelemetryProps);
525
- }
526
-
527
- /**
528
- * @public
529
- */
530
- export declare function runWithRetry<T>(api: (cancel?: AbortSignal) => Promise<T>, fetchCallName: string, logger: ITelemetryLoggerExt, progress: IProgress): Promise<T>;
531
-
532
- /**
533
- * @public
534
- */
535
- export declare function streamFromMessages(messagesArg: Promise<ISequencedDocumentMessage[]>): IStream<ISequencedDocumentMessage[]>;
536
-
537
- /**
538
- * @public
539
- */
540
- export declare function streamObserver<T>(stream: IStream<T>, handler: (value: IStreamResult<T>) => void): IStream<T>;
541
-
542
- /**
543
- * @public
544
- */
545
- export declare enum SummaryCompressionAlgorithm {
546
- None = 0,
547
- LZ4 = 1
548
- }
549
-
550
- /**
551
- * Throttling error class - used to communicate all throttling errors
552
- * @public
553
- */
554
- export declare class ThrottlingError extends LoggingError implements IThrottlingWarning, IFluidErrorBase {
555
- readonly retryAfterSeconds: number;
556
- readonly errorType = DriverErrorType.throttlingError;
557
- readonly canRetry = true;
558
- constructor(message: string, retryAfterSeconds: number, props: DriverErrorTelemetryProps);
559
- }
560
-
561
- /**
562
- * Basic implementation of a tree ITreeEntry
563
- * @public
564
- */
565
- export declare class TreeTreeEntry {
566
- readonly path: string;
567
- readonly value: ITree;
568
- readonly mode = FileMode.Directory;
569
- readonly type = TreeEntry.Tree;
570
- /**
571
- * Creates a tree ITreeEntry
572
- * @param path - path of entry
573
- * @param value - subtree
574
- */
575
- constructor(path: string, value: ITree);
576
- }
577
-
578
- /**
579
- * Error indicating an API is being used improperly resulting in an invalid operation.
580
- * @public
581
- */
582
- export declare class UsageError extends LoggingError implements IDriverErrorBase, IFluidErrorBase {
583
- readonly errorType = DriverErrorType.usageError;
584
- readonly canRetry = false;
585
- constructor(message: string);
586
- }
587
-
588
- export { }