@fluidframework/map 1.4.0-121020 → 2.0.0-dev-rc.1.0.0.225277

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 (119) hide show
  1. package/.eslintrc.js +12 -11
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +162 -0
  4. package/README.md +24 -8
  5. package/api-extractor-esm.json +4 -0
  6. package/api-extractor-lint.json +4 -0
  7. package/api-extractor.json +2 -2
  8. package/api-report/map.api.md +297 -0
  9. package/dist/{directory.js → directory.cjs} +749 -228
  10. package/dist/directory.cjs.map +1 -0
  11. package/dist/directory.d.ts +567 -34
  12. package/dist/directory.d.ts.map +1 -1
  13. package/dist/index.cjs +27 -0
  14. package/dist/index.cjs.map +1 -0
  15. package/dist/index.d.ts +5 -5
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/{interfaces.js → interfaces.cjs} +1 -1
  18. package/dist/interfaces.cjs.map +1 -0
  19. package/dist/interfaces.d.ts +167 -184
  20. package/dist/interfaces.d.ts.map +1 -1
  21. package/dist/internalInterfaces.cjs +7 -0
  22. package/dist/internalInterfaces.cjs.map +1 -0
  23. package/dist/internalInterfaces.d.ts +101 -0
  24. package/dist/internalInterfaces.d.ts.map +1 -0
  25. package/dist/{localValues.js → localValues.cjs} +15 -3
  26. package/dist/localValues.cjs.map +1 -0
  27. package/dist/localValues.d.ts +17 -6
  28. package/dist/localValues.d.ts.map +1 -1
  29. package/dist/map-alpha.d.ts +982 -0
  30. package/dist/map-beta.d.ts +275 -0
  31. package/dist/map-public.d.ts +275 -0
  32. package/dist/map-untrimmed.d.ts +996 -0
  33. package/dist/{map.js → map.cjs} +39 -34
  34. package/dist/map.cjs.map +1 -0
  35. package/dist/map.d.ts +10 -17
  36. package/dist/map.d.ts.map +1 -1
  37. package/dist/{mapKernel.js → mapKernel.cjs} +122 -79
  38. package/dist/mapKernel.cjs.map +1 -0
  39. package/dist/mapKernel.d.ts +17 -48
  40. package/dist/mapKernel.d.ts.map +1 -1
  41. package/dist/{packageVersion.js → packageVersion.cjs} +2 -2
  42. package/dist/packageVersion.cjs.map +1 -0
  43. package/dist/packageVersion.d.ts +1 -1
  44. package/dist/packageVersion.d.ts.map +1 -1
  45. package/dist/tsdoc-metadata.json +11 -0
  46. package/lib/directory.d.mts +902 -0
  47. package/lib/directory.d.mts.map +1 -0
  48. package/lib/{directory.js → directory.mjs} +736 -199
  49. package/lib/directory.mjs.map +1 -0
  50. package/lib/index.d.mts +9 -0
  51. package/lib/index.d.mts.map +1 -0
  52. package/lib/index.mjs +8 -0
  53. package/lib/index.mjs.map +1 -0
  54. package/lib/{interfaces.d.ts → interfaces.d.mts} +168 -185
  55. package/lib/interfaces.d.mts.map +1 -0
  56. package/lib/{interfaces.js → interfaces.mjs} +1 -1
  57. package/lib/interfaces.mjs.map +1 -0
  58. package/lib/internalInterfaces.d.mts +101 -0
  59. package/lib/internalInterfaces.d.mts.map +1 -0
  60. package/lib/internalInterfaces.mjs +6 -0
  61. package/lib/internalInterfaces.mjs.map +1 -0
  62. package/lib/{localValues.d.ts → localValues.d.mts} +19 -8
  63. package/lib/localValues.d.mts.map +1 -0
  64. package/lib/{localValues.js → localValues.mjs} +15 -3
  65. package/lib/localValues.mjs.map +1 -0
  66. package/lib/map-alpha.d.mts +970 -0
  67. package/lib/map-beta.d.mts +263 -0
  68. package/lib/map-public.d.mts +263 -0
  69. package/lib/map-untrimmed.d.mts +984 -0
  70. package/lib/{map.d.ts → map.d.mts} +12 -19
  71. package/lib/map.d.mts.map +1 -0
  72. package/lib/{map.js → map.mjs} +40 -35
  73. package/lib/map.mjs.map +1 -0
  74. package/lib/{mapKernel.d.ts → mapKernel.d.mts} +19 -50
  75. package/lib/mapKernel.d.mts.map +1 -0
  76. package/lib/{mapKernel.js → mapKernel.mjs} +116 -73
  77. package/lib/mapKernel.mjs.map +1 -0
  78. package/lib/{packageVersion.d.ts → packageVersion.d.mts} +2 -2
  79. package/lib/packageVersion.d.mts.map +1 -0
  80. package/lib/{packageVersion.js → packageVersion.mjs} +2 -2
  81. package/lib/packageVersion.mjs.map +1 -0
  82. package/package.json +143 -65
  83. package/prettier.config.cjs +8 -0
  84. package/src/directory.ts +2544 -1727
  85. package/src/index.ts +31 -5
  86. package/src/interfaces.ts +346 -345
  87. package/src/internalInterfaces.ts +119 -0
  88. package/src/localValues.ts +103 -96
  89. package/src/map.ts +362 -351
  90. package/src/mapKernel.ts +755 -722
  91. package/src/packageVersion.ts +1 -1
  92. package/tsc-multi.test.json +4 -0
  93. package/tsconfig.json +10 -15
  94. package/dist/directory.js.map +0 -1
  95. package/dist/index.js +0 -34
  96. package/dist/index.js.map +0 -1
  97. package/dist/interfaces.js.map +0 -1
  98. package/dist/localValues.js.map +0 -1
  99. package/dist/map.js.map +0 -1
  100. package/dist/mapKernel.js.map +0 -1
  101. package/dist/packageVersion.js.map +0 -1
  102. package/lib/directory.d.ts +0 -369
  103. package/lib/directory.d.ts.map +0 -1
  104. package/lib/directory.js.map +0 -1
  105. package/lib/index.d.ts +0 -20
  106. package/lib/index.d.ts.map +0 -1
  107. package/lib/index.js +0 -20
  108. package/lib/index.js.map +0 -1
  109. package/lib/interfaces.d.ts.map +0 -1
  110. package/lib/interfaces.js.map +0 -1
  111. package/lib/localValues.d.ts.map +0 -1
  112. package/lib/localValues.js.map +0 -1
  113. package/lib/map.d.ts.map +0 -1
  114. package/lib/map.js.map +0 -1
  115. package/lib/mapKernel.d.ts.map +0 -1
  116. package/lib/mapKernel.js.map +0 -1
  117. package/lib/packageVersion.d.ts.map +0 -1
  118. package/lib/packageVersion.js.map +0 -1
  119. package/tsconfig.esnext.json +0 -7
@@ -0,0 +1,902 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { TypedEventEmitter } from "@fluid-internal/client-utils";
6
+ import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
7
+ import { IChannelAttributes, IFluidDataStoreRuntime, IChannelStorageService, IChannelServices, IChannelFactory } from "@fluidframework/datastore-definitions";
8
+ import { ISummaryTreeWithStats, ITelemetryContext } from "@fluidframework/runtime-definitions";
9
+ import { IFluidSerializer, SharedObject } from "@fluidframework/shared-object-base";
10
+ import { RedBlackTree } from "@fluidframework/merge-tree";
11
+ import { IDirectory, IDirectoryEvents, ISerializableValue, ISerializedValue, ISharedDirectory, ISharedDirectoryEvents } from "./interfaces.mjs";
12
+ import { ILocalValue, LocalValueMaker } from "./localValues.mjs";
13
+ /**
14
+ * Operation indicating a value should be set for a key.
15
+ * @alpha
16
+ */
17
+ export interface IDirectorySetOperation {
18
+ /**
19
+ * String identifier of the operation type.
20
+ */
21
+ type: "set";
22
+ /**
23
+ * Directory key being modified.
24
+ */
25
+ key: string;
26
+ /**
27
+ * Absolute path of the directory where the modified key is located.
28
+ */
29
+ path: string;
30
+ /**
31
+ * Value to be set on the key.
32
+ */
33
+ value: ISerializableValue;
34
+ }
35
+ /**
36
+ * Operation indicating a key should be deleted from the directory.
37
+ * @alpha
38
+ */
39
+ export interface IDirectoryDeleteOperation {
40
+ /**
41
+ * String identifier of the operation type.
42
+ */
43
+ type: "delete";
44
+ /**
45
+ * Directory key being modified.
46
+ */
47
+ key: string;
48
+ /**
49
+ * Absolute path of the directory where the modified key is located.
50
+ */
51
+ path: string;
52
+ }
53
+ /**
54
+ * An operation on a specific key within a directory.
55
+ * @alpha
56
+ */
57
+ export type IDirectoryKeyOperation = IDirectorySetOperation | IDirectoryDeleteOperation;
58
+ /**
59
+ * Operation indicating the directory should be cleared.
60
+ * @alpha
61
+ */
62
+ export interface IDirectoryClearOperation {
63
+ /**
64
+ * String identifier of the operation type.
65
+ */
66
+ type: "clear";
67
+ /**
68
+ * Absolute path of the directory being cleared.
69
+ */
70
+ path: string;
71
+ }
72
+ /**
73
+ * An operation on one or more of the keys within a directory.
74
+ * @alpha
75
+ */
76
+ export type IDirectoryStorageOperation = IDirectoryKeyOperation | IDirectoryClearOperation;
77
+ /**
78
+ * Operation indicating a subdirectory should be created.
79
+ * @alpha
80
+ */
81
+ export interface IDirectoryCreateSubDirectoryOperation {
82
+ /**
83
+ * String identifier of the operation type.
84
+ */
85
+ type: "createSubDirectory";
86
+ /**
87
+ * Absolute path of the directory that will contain the new subdirectory.
88
+ */
89
+ path: string;
90
+ /**
91
+ * Name of the new subdirectory.
92
+ */
93
+ subdirName: string;
94
+ }
95
+ /**
96
+ * Operation indicating a subdirectory should be deleted.
97
+ * @alpha
98
+ */
99
+ export interface IDirectoryDeleteSubDirectoryOperation {
100
+ /**
101
+ * String identifier of the operation type.
102
+ */
103
+ type: "deleteSubDirectory";
104
+ /**
105
+ * Absolute path of the directory that contains the directory to be deleted.
106
+ */
107
+ path: string;
108
+ /**
109
+ * Name of the subdirectory to be deleted.
110
+ */
111
+ subdirName: string;
112
+ }
113
+ /**
114
+ * An operation on the subdirectories within a directory.
115
+ * @alpha
116
+ */
117
+ export type IDirectorySubDirectoryOperation = IDirectoryCreateSubDirectoryOperation | IDirectoryDeleteSubDirectoryOperation;
118
+ /**
119
+ * Any operation on a directory.
120
+ * @alpha
121
+ */
122
+ export type IDirectoryOperation = IDirectoryStorageOperation | IDirectorySubDirectoryOperation;
123
+ /**
124
+ * Create info for the subdirectory.
125
+ * @alpha
126
+ */
127
+ export interface ICreateInfo {
128
+ /**
129
+ * Sequence number at which this subdirectory was created.
130
+ */
131
+ csn: number;
132
+ /**
133
+ * clientids of the clients which created this sub directory.
134
+ */
135
+ ccIds: string[];
136
+ }
137
+ /**
138
+ * Defines the in-memory object structure to be used for the conversion to/from serialized.
139
+ *
140
+ * @remarks Directly used in
141
+ * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
142
+ * | JSON.stringify}, direct result from
143
+ * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse | JSON.parse}.
144
+ * @alpha
145
+ */
146
+ export interface IDirectoryDataObject {
147
+ /**
148
+ * Key/value date set by the user.
149
+ */
150
+ storage?: {
151
+ [key: string]: ISerializableValue;
152
+ };
153
+ /**
154
+ * Recursive sub-directories {@link IDirectoryDataObject | objects}.
155
+ */
156
+ subdirectories?: {
157
+ [subdirName: string]: IDirectoryDataObject;
158
+ };
159
+ /**
160
+ * Create info for the sub directory. Since directories with same name can get deleted/created by multiple clients
161
+ * asynchronously, this info helps us to determine whether the ops where for the current instance of sub directory
162
+ * or not and whether to process them or not based on that. Summaries which were not produced which this change
163
+ * will not have this info and in that case we can still run in eventual consistency issues but that is no worse
164
+ * than the state before this change.
165
+ */
166
+ ci?: ICreateInfo;
167
+ }
168
+ /**
169
+ * {@link IDirectory} storage format.
170
+ *
171
+ * @internal
172
+ */
173
+ export interface IDirectoryNewStorageFormat {
174
+ /**
175
+ * Blob IDs representing larger directory data that was serialized.
176
+ */
177
+ blobs: string[];
178
+ /**
179
+ * Storage content representing directory data that was not serialized.
180
+ */
181
+ content: IDirectoryDataObject;
182
+ }
183
+ /**
184
+ * {@link @fluidframework/datastore-definitions#IChannelFactory} for {@link SharedDirectory}.
185
+ *
186
+ * @sealed
187
+ * @alpha
188
+ */
189
+ export declare class DirectoryFactory implements IChannelFactory {
190
+ /**
191
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory."type"}
192
+ */
193
+ static readonly Type = "https://graph.microsoft.com/types/directory";
194
+ /**
195
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}
196
+ */
197
+ static readonly Attributes: IChannelAttributes;
198
+ /**
199
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory."type"}
200
+ */
201
+ get type(): string;
202
+ /**
203
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}
204
+ */
205
+ get attributes(): IChannelAttributes;
206
+ /**
207
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}
208
+ */
209
+ load(runtime: IFluidDataStoreRuntime, id: string, services: IChannelServices, attributes: IChannelAttributes): Promise<ISharedDirectory>;
210
+ /**
211
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}
212
+ */
213
+ create(runtime: IFluidDataStoreRuntime, id: string): ISharedDirectory;
214
+ }
215
+ /**
216
+ * The combination of sequence numebr and client sequence number of a subdirectory
217
+ */
218
+ interface SequenceData {
219
+ seq: number;
220
+ clientSeq?: number;
221
+ }
222
+ /**
223
+ * A utility class for tracking associations between keys and their creation indices.
224
+ * This is relevant to support map iteration in insertion order, see
225
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/%40%40iterator
226
+ *
227
+ * TODO: It can be combined with the creation tracker utilized in SharedMap
228
+ */
229
+ declare class DirectoryCreationTracker {
230
+ readonly indexToKey: RedBlackTree<SequenceData, string>;
231
+ readonly keyToIndex: Map<string, SequenceData>;
232
+ constructor();
233
+ set(key: string, seqData: SequenceData): void;
234
+ has(keyOrSeqData: string | SequenceData): boolean;
235
+ delete(keyOrSeqData: string | SequenceData): void;
236
+ /**
237
+ * Retrieves all subdirectories with creation order that satisfy an optional constraint function.
238
+ * @param constraint - An optional constraint function that filters keys.
239
+ * @returns An array of keys that satisfy the constraint (or all keys if no constraint is provided).
240
+ */
241
+ keys(constraint?: (key: string) => boolean): string[];
242
+ }
243
+ /**
244
+ * {@inheritDoc ISharedDirectory}
245
+ *
246
+ * @example
247
+ *
248
+ * ```typescript
249
+ * mySharedDirectory.createSubDirectory("a").createSubDirectory("b").createSubDirectory("c").set("foo", val1);
250
+ * const mySubDir = mySharedDirectory.getWorkingDirectory("/a/b/c");
251
+ * mySubDir.get("foo"); // returns val1
252
+ * ```
253
+ *
254
+ * @sealed
255
+ * @alpha
256
+ */
257
+ export declare class SharedDirectory extends SharedObject<ISharedDirectoryEvents> implements ISharedDirectory {
258
+ /**
259
+ * Create a new shared directory
260
+ *
261
+ * @param runtime - Data store runtime the new shared directory belongs to
262
+ * @param id - Optional name of the shared directory
263
+ * @returns Newly create shared directory (but not attached yet)
264
+ */
265
+ static create(runtime: IFluidDataStoreRuntime, id?: string): SharedDirectory;
266
+ /**
267
+ * Get a factory for SharedDirectory to register with the data store.
268
+ *
269
+ * @returns A factory that creates and load SharedDirectory
270
+ */
271
+ static getFactory(): IChannelFactory;
272
+ /**
273
+ * String representation for the class.
274
+ */
275
+ [Symbol.toStringTag]: string;
276
+ /**
277
+ * {@inheritDoc IDirectory.absolutePath}
278
+ */
279
+ get absolutePath(): string;
280
+ /***/
281
+ readonly localValueMaker: LocalValueMaker;
282
+ /**
283
+ * Root of the SharedDirectory, most operations on the SharedDirectory itself act on the root.
284
+ */
285
+ private readonly root;
286
+ /**
287
+ * Mapping of op types to message handlers.
288
+ */
289
+ private readonly messageHandlers;
290
+ /**
291
+ * Constructs a new shared directory. If the object is non-local an id and service interfaces will
292
+ * be provided.
293
+ * @param id - String identifier for the SharedDirectory
294
+ * @param runtime - Data store runtime
295
+ * @param type - Type identifier
296
+ */
297
+ constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
298
+ /**
299
+ * {@inheritDoc IDirectory.get}
300
+ */
301
+ get<T = any>(key: string): T | undefined;
302
+ /**
303
+ * {@inheritDoc IDirectory.set}
304
+ */
305
+ set<T = unknown>(key: string, value: T): this;
306
+ dispose(error?: Error): void;
307
+ get disposed(): boolean;
308
+ /**
309
+ * Deletes the given key from within this IDirectory.
310
+ * @param key - The key to delete
311
+ * @returns True if the key existed and was deleted, false if it did not exist
312
+ */
313
+ delete(key: string): boolean;
314
+ /**
315
+ * Deletes all keys from within this IDirectory.
316
+ */
317
+ clear(): void;
318
+ /**
319
+ * Checks whether the given key exists in this IDirectory.
320
+ * @param key - The key to check
321
+ * @returns True if the key exists, false otherwise
322
+ */
323
+ has(key: string): boolean;
324
+ /**
325
+ * The number of entries under this IDirectory.
326
+ */
327
+ get size(): number;
328
+ /**
329
+ * Issue a callback on each entry under this IDirectory.
330
+ * @param callback - Callback to issue
331
+ */
332
+ forEach(callback: (value: any, key: string, map: Map<string, any>) => void): void;
333
+ /**
334
+ * Get an iterator over the entries under this IDirectory.
335
+ * @returns The iterator
336
+ */
337
+ [Symbol.iterator](): IterableIterator<[string, any]>;
338
+ /**
339
+ * Get an iterator over the entries under this IDirectory.
340
+ * @returns The iterator
341
+ */
342
+ entries(): IterableIterator<[string, any]>;
343
+ /**
344
+ * {@inheritDoc IDirectory.countSubDirectory}
345
+ */
346
+ countSubDirectory(): number;
347
+ /**
348
+ * Get an iterator over the keys under this IDirectory.
349
+ * @returns The iterator
350
+ */
351
+ keys(): IterableIterator<string>;
352
+ /**
353
+ * Get an iterator over the values under this IDirectory.
354
+ * @returns The iterator
355
+ */
356
+ values(): IterableIterator<any>;
357
+ /**
358
+ * {@inheritDoc IDirectory.createSubDirectory}
359
+ */
360
+ createSubDirectory(subdirName: string): IDirectory;
361
+ /**
362
+ * {@inheritDoc IDirectory.getSubDirectory}
363
+ */
364
+ getSubDirectory(subdirName: string): IDirectory | undefined;
365
+ /**
366
+ * {@inheritDoc IDirectory.hasSubDirectory}
367
+ */
368
+ hasSubDirectory(subdirName: string): boolean;
369
+ /**
370
+ * {@inheritDoc IDirectory.deleteSubDirectory}
371
+ */
372
+ deleteSubDirectory(subdirName: string): boolean;
373
+ /**
374
+ * {@inheritDoc IDirectory.subdirectories}
375
+ */
376
+ subdirectories(): IterableIterator<[string, IDirectory]>;
377
+ /**
378
+ * {@inheritDoc IDirectory.getWorkingDirectory}
379
+ */
380
+ getWorkingDirectory(relativePath: string): IDirectory | undefined;
381
+ /**
382
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.summarizeCore}
383
+ */
384
+ protected summarizeCore(serializer: IFluidSerializer, telemetryContext?: ITelemetryContext): ISummaryTreeWithStats;
385
+ /**
386
+ * Submits an operation
387
+ * @param op - Op to submit
388
+ * @param localOpMetadata - The local metadata associated with the op. We send a unique id that is used to track
389
+ * this op while it has not been ack'd. This will be sent when we receive this op back from the server.
390
+ */
391
+ submitDirectoryMessage(op: IDirectoryOperation, localOpMetadata: unknown): void;
392
+ /**
393
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}
394
+ */
395
+ protected onDisconnect(): void;
396
+ /**
397
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.reSubmitCore}
398
+ */
399
+ protected reSubmitCore(content: unknown, localOpMetadata: unknown): void;
400
+ /**
401
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
402
+ */
403
+ protected loadCore(storage: IChannelStorageService): Promise<void>;
404
+ /**
405
+ * Populate the directory with the given directory data.
406
+ * @param data - A JSON string containing serialized directory data
407
+ */
408
+ protected populate(data: IDirectoryDataObject): void;
409
+ /**
410
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.processCore}
411
+ */
412
+ protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
413
+ /**
414
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.rollback}
415
+ */
416
+ protected rollback(content: unknown, localOpMetadata: unknown): void;
417
+ /**
418
+ * Converts the given relative path to absolute against the root.
419
+ * @param relativePath - The path to convert
420
+ */
421
+ private makeAbsolute;
422
+ /**
423
+ * The remote ISerializableValue we're receiving (either as a result of a snapshot load or an incoming set op)
424
+ * will have the information we need to create a real object, but will not be the real object yet. For example,
425
+ * we might know it's a map and the ID but not have the actual map or its data yet. makeLocal's job
426
+ * is to convert that information into a real object for local usage.
427
+ * @param key - Key of element being converted
428
+ * @param absolutePath - Path of element being converted
429
+ * @param serializable - The remote information that we can convert into a real object
430
+ * @returns The local value that was produced
431
+ */
432
+ private makeLocal;
433
+ /**
434
+ * This checks if there is pending delete op for local delete for a any subdir in the relative path.
435
+ * @param relativePath - path of sub directory.
436
+ * @returns `true` if there is pending delete, `false` otherwise.
437
+ */
438
+ private isSubDirectoryDeletePending;
439
+ /**
440
+ * Set the message handlers for the directory.
441
+ */
442
+ private setMessageHandlers;
443
+ /**
444
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
445
+ */
446
+ protected applyStashedOp(op: unknown): unknown;
447
+ private serializeDirectory;
448
+ }
449
+ interface IKeyEditLocalOpMetadata {
450
+ type: "edit";
451
+ pendingMessageId: number;
452
+ previousValue: ILocalValue | undefined;
453
+ }
454
+ interface IClearLocalOpMetadata {
455
+ type: "clear";
456
+ pendingMessageId: number;
457
+ previousStorage: Map<string, ILocalValue>;
458
+ }
459
+ interface ICreateSubDirLocalOpMetadata {
460
+ type: "createSubDir";
461
+ }
462
+ interface IDeleteSubDirLocalOpMetadata {
463
+ type: "deleteSubDir";
464
+ subDirectory: SubDirectory | undefined;
465
+ }
466
+ type SubDirLocalOpMetadata = ICreateSubDirLocalOpMetadata | IDeleteSubDirLocalOpMetadata;
467
+ export type DirectoryLocalOpMetadata = IClearLocalOpMetadata | IKeyEditLocalOpMetadata | SubDirLocalOpMetadata;
468
+ /**
469
+ * Node of the directory tree.
470
+ * @sealed
471
+ */
472
+ declare class SubDirectory extends TypedEventEmitter<IDirectoryEvents> implements IDirectory {
473
+ private readonly seqData;
474
+ private readonly clientIds;
475
+ private readonly directory;
476
+ private readonly runtime;
477
+ private readonly serializer;
478
+ readonly absolutePath: string;
479
+ /**
480
+ * Tells if the sub directory is deleted or not.
481
+ */
482
+ private _deleted;
483
+ /**
484
+ * String representation for the class.
485
+ */
486
+ [Symbol.toStringTag]: string;
487
+ /**
488
+ * The in-memory data the directory is storing.
489
+ */
490
+ private readonly _storage;
491
+ /**
492
+ * The subdirectories the directory is holding.
493
+ */
494
+ private readonly _subdirectories;
495
+ /**
496
+ * Keys that have been modified locally but not yet ack'd from the server. This is for operations on keys like
497
+ * set/delete operations on keys. The value of this map is list of pendingMessageIds at which that key
498
+ * was modified. We don't store the type of ops, and behaviour of key ops are different from behaviour of sub
499
+ * directory ops, so we have separate map from subDirectories tracker.
500
+ */
501
+ private readonly pendingKeys;
502
+ /**
503
+ * Subdirectories that have been deleted locally but not yet ack'd from the server. This maintains the record
504
+ * of delete op that are pending or yet to be acked from server. This is maintained just to track the locally
505
+ * deleted sub directory.
506
+ */
507
+ private readonly pendingDeleteSubDirectoriesTracker;
508
+ /**
509
+ * Subdirectories that have been created locally but not yet ack'd from the server. This maintains the record
510
+ * of create op that are pending or yet to be acked from server. This is maintained just to track the locally
511
+ * created sub directory.
512
+ */
513
+ private readonly pendingCreateSubDirectoriesTracker;
514
+ /**
515
+ * This is used to assign a unique id to every outgoing operation and helps in tracking unack'd ops.
516
+ */
517
+ private pendingMessageId;
518
+ /**
519
+ * The pending ids of any clears that have been performed locally but not yet ack'd from the server
520
+ */
521
+ private readonly pendingClearMessageIds;
522
+ /**
523
+ * Assigns a unique ID to each subdirectory created locally but pending for acknowledgement, facilitating the tracking
524
+ * of the creation order.
525
+ */
526
+ localCreationSeq: number;
527
+ /**
528
+ * Maintains a bidirectional association between ack'd subdirectories and their seqData.
529
+ * This helps to ensure iteration order which is consistent with the JS map spec.
530
+ */
531
+ readonly ackedCreationSeqTracker: DirectoryCreationTracker;
532
+ /**
533
+ * Similar to {@link ackedCreationSeqTracker}, but for local (unacked) entries.
534
+ */
535
+ readonly localCreationSeqTracker: DirectoryCreationTracker;
536
+ /**
537
+ * Constructor.
538
+ * @param sequenceNumber - Message seq number at which this was created.
539
+ * @param clientIds - Ids of client which created this directory.
540
+ * @param directory - Reference back to the SharedDirectory to perform operations
541
+ * @param runtime - The data store runtime this directory is associated with
542
+ * @param serializer - The serializer to serialize / parse handles
543
+ * @param absolutePath - The absolute path of this IDirectory
544
+ */
545
+ constructor(seqData: SequenceData, clientIds: Set<string>, directory: SharedDirectory, runtime: IFluidDataStoreRuntime, serializer: IFluidSerializer, absolutePath: string);
546
+ dispose(error?: Error): void;
547
+ /**
548
+ * Unmark the deleted property only when rolling back delete.
549
+ */
550
+ private undispose;
551
+ get disposed(): boolean;
552
+ private throwIfDisposed;
553
+ /**
554
+ * Checks whether the given key exists in this IDirectory.
555
+ * @param key - The key to check
556
+ * @returns True if the key exists, false otherwise
557
+ */
558
+ has(key: string): boolean;
559
+ /**
560
+ * {@inheritDoc IDirectory.get}
561
+ */
562
+ get<T = unknown>(key: string): T | undefined;
563
+ /**
564
+ * {@inheritDoc IDirectory.set}
565
+ */
566
+ set<T = unknown>(key: string, value: T): this;
567
+ /**
568
+ * {@inheritDoc IDirectory.countSubDirectory}
569
+ */
570
+ countSubDirectory(): number;
571
+ /**
572
+ * {@inheritDoc IDirectory.createSubDirectory}
573
+ */
574
+ createSubDirectory(subdirName: string): IDirectory;
575
+ /**
576
+ * @returns The Sequence Data which should be used for local changes.
577
+ * @remarks While detached, 0 is used rather than -1 to represent a change which should be universally known (as opposed to known
578
+ * only by the local client). This ensures that if the directory is later attached, none of its data needs to be updated (the values
579
+ * last set while detached will now be known to any new client, until they are changed).
580
+ *
581
+ * The client sequence number is incremented by 1 for maintaining the internal order of locally created subdirectories
582
+ * TODO: Convert these conventions to named constants. The semantics used here match those for merge-tree.
583
+ */
584
+ private getLocalSeq;
585
+ /**
586
+ * {@inheritDoc IDirectory.getSubDirectory}
587
+ */
588
+ getSubDirectory(subdirName: string): IDirectory | undefined;
589
+ /**
590
+ * {@inheritDoc IDirectory.hasSubDirectory}
591
+ */
592
+ hasSubDirectory(subdirName: string): boolean;
593
+ /**
594
+ * {@inheritDoc IDirectory.deleteSubDirectory}
595
+ */
596
+ deleteSubDirectory(subdirName: string): boolean;
597
+ /**
598
+ * {@inheritDoc IDirectory.subdirectories}
599
+ */
600
+ subdirectories(): IterableIterator<[string, IDirectory]>;
601
+ /**
602
+ * {@inheritDoc IDirectory.getWorkingDirectory}
603
+ */
604
+ getWorkingDirectory(relativePath: string): IDirectory | undefined;
605
+ /**
606
+ * This checks if there is pending delete op for local delete for a given child subdirectory.
607
+ * @param subDirName - directory name.
608
+ * @returns true if there is pending delete.
609
+ */
610
+ isSubDirectoryDeletePending(subDirName: string): boolean;
611
+ /**
612
+ * Deletes the given key from within this IDirectory.
613
+ * @param key - The key to delete
614
+ * @returns True if the key existed and was deleted, false if it did not exist
615
+ */
616
+ delete(key: string): boolean;
617
+ /**
618
+ * Deletes all keys from within this IDirectory.
619
+ */
620
+ clear(): void;
621
+ /**
622
+ * Issue a callback on each entry under this IDirectory.
623
+ * @param callback - Callback to issue
624
+ */
625
+ forEach(callback: (value: unknown, key: string, map: Map<string, unknown>) => void): void;
626
+ /**
627
+ * The number of entries under this IDirectory.
628
+ */
629
+ get size(): number;
630
+ /**
631
+ * Get an iterator over the entries under this IDirectory.
632
+ * @returns The iterator
633
+ */
634
+ entries(): IterableIterator<[string, unknown]>;
635
+ /**
636
+ * Get an iterator over the keys under this IDirectory.
637
+ * @returns The iterator
638
+ */
639
+ keys(): IterableIterator<string>;
640
+ /**
641
+ * Get an iterator over the values under this IDirectory.
642
+ * @returns The iterator
643
+ */
644
+ values(): IterableIterator<unknown>;
645
+ /**
646
+ * Get an iterator over the entries under this IDirectory.
647
+ * @returns The iterator
648
+ */
649
+ [Symbol.iterator](): IterableIterator<[string, unknown]>;
650
+ /**
651
+ * Process a clear operation.
652
+ * @param msg - The message from the server to apply.
653
+ * @param op - The op to process
654
+ * @param local - Whether the message originated from the local client
655
+ * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
656
+ * For messages from a remote client, this will be undefined.
657
+ * @internal
658
+ */
659
+ processClearMessage(msg: ISequencedDocumentMessage, op: IDirectoryClearOperation, local: boolean, localOpMetadata: unknown): void;
660
+ /**
661
+ * Apply clear operation locally and generate metadata
662
+ * @param op - Op to apply
663
+ * @returns metadata generated for stahed op
664
+ */
665
+ applyStashedClearMessage(op: IDirectoryClearOperation): IClearLocalOpMetadata;
666
+ /**
667
+ * Process a delete operation.
668
+ * @param msg - The message from the server to apply.
669
+ * @param op - The op to process
670
+ * @param local - Whether the message originated from the local client
671
+ * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
672
+ * For messages from a remote client, this will be undefined.
673
+ * @internal
674
+ */
675
+ processDeleteMessage(msg: ISequencedDocumentMessage, op: IDirectoryDeleteOperation, local: boolean, localOpMetadata: unknown): void;
676
+ /**
677
+ * Apply delete operation locally and generate metadata
678
+ * @param op - Op to apply
679
+ * @returns metadata generated for stahed op
680
+ */
681
+ applyStashedDeleteMessage(op: IDirectoryDeleteOperation): IKeyEditLocalOpMetadata;
682
+ /**
683
+ * Process a set operation.
684
+ * @param msg - The message from the server to apply.
685
+ * @param op - The op to process
686
+ * @param local - Whether the message originated from the local client
687
+ * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
688
+ * For messages from a remote client, this will be undefined.
689
+ * @internal
690
+ */
691
+ processSetMessage(msg: ISequencedDocumentMessage, op: IDirectorySetOperation, context: ILocalValue | undefined, local: boolean, localOpMetadata: unknown): void;
692
+ /**
693
+ * Apply set operation locally and generate metadata
694
+ * @param op - Op to apply
695
+ * @returns metadata generated for stahed op
696
+ */
697
+ applyStashedSetMessage(op: IDirectorySetOperation, context: ILocalValue): IKeyEditLocalOpMetadata;
698
+ /**
699
+ * Process a create subdirectory operation.
700
+ * @param msg - The message from the server to apply.
701
+ * @param op - The op to process
702
+ * @param local - Whether the message originated from the local client
703
+ * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
704
+ * For messages from a remote client, this will be undefined.
705
+ * @internal
706
+ */
707
+ processCreateSubDirectoryMessage(msg: ISequencedDocumentMessage, op: IDirectoryCreateSubDirectoryOperation, local: boolean, localOpMetadata: unknown): void;
708
+ /**
709
+ * Apply createSubDirectory operation locally and generate metadata
710
+ * @param op - Op to apply
711
+ * @returns metadata generated for stahed op
712
+ */
713
+ applyStashedCreateSubDirMessage(op: IDirectoryCreateSubDirectoryOperation): ICreateSubDirLocalOpMetadata;
714
+ /**
715
+ * Process a delete subdirectory operation.
716
+ * @param msg - The message from the server to apply.
717
+ * @param op - The op to process
718
+ * @param local - Whether the message originated from the local client
719
+ * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
720
+ * For messages from a remote client, this will be undefined.
721
+ * @internal
722
+ */
723
+ processDeleteSubDirectoryMessage(msg: ISequencedDocumentMessage, op: IDirectoryDeleteSubDirectoryOperation, local: boolean, localOpMetadata: unknown): void;
724
+ /**
725
+ * Apply deleteSubDirectory operation locally and generate metadata
726
+ * @param op - Op to apply
727
+ * @returns metadata generated for stahed op
728
+ */
729
+ applyStashedDeleteSubDirMessage(op: IDirectoryDeleteSubDirectoryOperation): IDeleteSubDirLocalOpMetadata;
730
+ /**
731
+ * Submit a clear operation.
732
+ * @param op - The operation
733
+ */
734
+ private submitClearMessage;
735
+ /**
736
+ * Resubmit a clear operation.
737
+ * @param op - The operation
738
+ * @internal
739
+ */
740
+ resubmitClearMessage(op: IDirectoryClearOperation, localOpMetadata: unknown): void;
741
+ /**
742
+ * Get a new pending message id for the op and cache it to track the pending op
743
+ */
744
+ private getKeyMessageId;
745
+ /**
746
+ * Submit a key operation.
747
+ * @param op - The operation
748
+ * @param previousValue - The value of the key before this op
749
+ */
750
+ private submitKeyMessage;
751
+ /**
752
+ * Submit a key message to remote clients based on a previous submit.
753
+ * @param op - The map key message
754
+ * @param localOpMetadata - Metadata from the previous submit
755
+ * @internal
756
+ */
757
+ resubmitKeyMessage(op: IDirectoryKeyOperation, localOpMetadata: unknown): void;
758
+ private incrementPendingSubDirCount;
759
+ private decrementPendingSubDirCount;
760
+ /**
761
+ * Update the count for pending create/delete of the sub directory so that it can be validated on receiving op
762
+ * or while resubmitting the op.
763
+ */
764
+ private updatePendingSubDirMessageCount;
765
+ /**
766
+ * Submit a create subdirectory operation.
767
+ * @param op - The operation
768
+ */
769
+ private submitCreateSubDirectoryMessage;
770
+ /**
771
+ * Submit a delete subdirectory operation.
772
+ * @param op - The operation
773
+ * @param subDir - Any subdirectory deleted by the op
774
+ */
775
+ private submitDeleteSubDirectoryMessage;
776
+ /**
777
+ * Submit a subdirectory operation again
778
+ * @param op - The operation
779
+ * @param localOpMetadata - metadata submitted with the op originally
780
+ * @internal
781
+ */
782
+ resubmitSubDirectoryMessage(op: IDirectorySubDirectoryOperation, localOpMetadata: unknown): void;
783
+ /**
784
+ * Get the storage of this subdirectory in a serializable format, to be used in snapshotting.
785
+ * @param serializer - The serializer to use to serialize handles in its values.
786
+ * @returns The JSONable string representing the storage of this subdirectory
787
+ * @internal
788
+ */
789
+ getSerializedStorage(serializer: IFluidSerializer): Generator<[string, ISerializedValue], void>;
790
+ getSerializableCreateInfo(): ICreateInfo;
791
+ /**
792
+ * Populate a key value in this subdirectory's storage, to be used when loading from snapshot.
793
+ * @param key - The key to populate
794
+ * @param localValue - The local value to populate into it
795
+ * @internal
796
+ */
797
+ populateStorage(key: string, localValue: ILocalValue): void;
798
+ /**
799
+ * Populate a subdirectory into this subdirectory, to be used when loading from snapshot.
800
+ * @param subdirName - The name of the subdirectory to add
801
+ * @param newSubDir - The new subdirectory to add
802
+ * @internal
803
+ */
804
+ populateSubDirectory(subdirName: string, newSubDir: SubDirectory): void;
805
+ /**
806
+ * Retrieve the local value at the given key. This is used to get value type information stashed on the local
807
+ * value so op handlers can be retrieved
808
+ * @param key - The key to retrieve from
809
+ * @returns The local value
810
+ * @internal
811
+ */
812
+ getLocalValue<T extends ILocalValue = ILocalValue>(key: string): T;
813
+ /**
814
+ * Remove the pendingMessageId from the map tracking it on rollback
815
+ * @param map - map tracking the pending messages
816
+ * @param key - key of the edit in the op
817
+ */
818
+ private rollbackPendingMessageId;
819
+ /**
820
+ * Rollback a local op
821
+ * @param op - The operation to rollback
822
+ * @param localOpMetadata - The local metadata associated with the op.
823
+ */
824
+ rollback(op: any, localOpMetadata: unknown): void;
825
+ /**
826
+ * Converts the given relative path into an absolute path.
827
+ * @param path - Relative path to convert
828
+ * @returns The equivalent absolute path
829
+ */
830
+ private makeAbsolute;
831
+ /**
832
+ * If our local operations that have not yet been ack'd will eventually overwrite an incoming operation, we should
833
+ * not process the incoming operation.
834
+ * @param op - Operation to check
835
+ * @param local - Whether the operation originated from the local client
836
+ * @param localOpMetadata - For local client ops, this is the metadata that was submitted with the op.
837
+ * For ops from a remote client, this will be undefined.
838
+ * @returns True if the operation should be processed, false otherwise
839
+ */
840
+ private needProcessStorageOperation;
841
+ /**
842
+ * This return true if the message is for the current instance of this sub directory. As the sub directory
843
+ * can be deleted and created again, then this finds if the message is for current instance of directory or not.
844
+ * @param msg - message for the directory
845
+ */
846
+ private isMessageForCurrentInstanceOfSubDirectory;
847
+ /**
848
+ * If our local operations that have not yet been ack'd will eventually overwrite an incoming operation, we should
849
+ * not process the incoming operation.
850
+ * @param op - Operation to check
851
+ * @param local - Whether the message originated from the local client
852
+ * @param message - The message
853
+ * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
854
+ * For messages from a remote client, this will be undefined.
855
+ * @returns True if the operation should be processed, false otherwise
856
+ */
857
+ private needProcessSubDirectoryOperation;
858
+ /**
859
+ * Clear all keys in memory in response to a remote clear, but retain keys we have modified but not yet been ack'd.
860
+ */
861
+ private clearExceptPendingKeys;
862
+ /**
863
+ * Clear implementation used for both locally sourced clears as well as incoming remote clears.
864
+ * @param local - Whether the message originated from the local client
865
+ */
866
+ private clearCore;
867
+ /**
868
+ * Delete implementation used for both locally sourced deletes as well as incoming remote deletes.
869
+ * @param key - The key being deleted
870
+ * @param local - Whether the message originated from the local client
871
+ * @returns Previous local value of the key if it existed, undefined if it did not exist
872
+ */
873
+ private deleteCore;
874
+ /**
875
+ * Set implementation used for both locally sourced sets as well as incoming remote sets.
876
+ * @param key - The key being set
877
+ * @param value - The value being set
878
+ * @param local - Whether the message originated from the local client
879
+ * @returns Previous local value of the key, if any
880
+ */
881
+ private setCore;
882
+ /**
883
+ * Create subdirectory implementation used for both locally sourced creation as well as incoming remote creation.
884
+ * @param subdirName - The name of the subdirectory being created
885
+ * @param local - Whether the message originated from the local client
886
+ * @param seqData - Sequence number and client sequence number at which this directory is created
887
+ * @param clientId - Id of client which created this directory.
888
+ * @returns True if is newly created, false if it already existed.
889
+ */
890
+ private createSubDirectoryCore;
891
+ private registerEventsOnSubDirectory;
892
+ /**
893
+ * Delete subdirectory implementation used for both locally sourced creation as well as incoming remote creation.
894
+ * @param subdirName - The name of the subdirectory being deleted
895
+ * @param local - Whether the message originated from the local client
896
+ */
897
+ private deleteSubDirectoryCore;
898
+ private disposeSubDirectoryTree;
899
+ private undeleteSubDirectoryTree;
900
+ }
901
+ export {};
902
+ //# sourceMappingURL=directory.d.mts.map