@fluidframework/runtime-definitions 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 (55) hide show
  1. package/.eslintrc.cjs +12 -0
  2. package/CHANGELOG.md +330 -0
  3. package/README.md +43 -7
  4. package/api-extractor-lint.json +4 -0
  5. package/api-extractor.json +2 -2
  6. package/api-report/runtime-definitions.api.md +474 -0
  7. package/dist/attribution.d.ts +71 -0
  8. package/dist/attribution.d.ts.map +1 -0
  9. package/dist/attribution.js +7 -0
  10. package/dist/attribution.js.map +1 -0
  11. package/dist/dataStoreContext.d.ts +114 -61
  12. package/dist/dataStoreContext.d.ts.map +1 -1
  13. package/dist/dataStoreContext.js +27 -5
  14. package/dist/dataStoreContext.js.map +1 -1
  15. package/dist/dataStoreFactory.d.ts +7 -0
  16. package/dist/dataStoreFactory.d.ts.map +1 -1
  17. package/dist/dataStoreFactory.js +3 -0
  18. package/dist/dataStoreFactory.js.map +1 -1
  19. package/dist/dataStoreRegistry.d.ts +14 -4
  20. package/dist/dataStoreRegistry.d.ts.map +1 -1
  21. package/dist/dataStoreRegistry.js +3 -0
  22. package/dist/dataStoreRegistry.js.map +1 -1
  23. package/dist/garbageCollection.d.ts +35 -10
  24. package/dist/garbageCollection.d.ts.map +1 -1
  25. package/dist/garbageCollection.js +25 -3
  26. package/dist/garbageCollection.js.map +1 -1
  27. package/dist/index.d.ts +52 -6
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +26 -16
  30. package/dist/index.js.map +1 -1
  31. package/dist/protocol.d.ts +10 -3
  32. package/dist/protocol.d.ts.map +1 -1
  33. package/dist/protocol.js.map +1 -1
  34. package/dist/runtime-definitions-alpha.d.ts +993 -0
  35. package/dist/runtime-definitions-beta.d.ts +264 -0
  36. package/dist/runtime-definitions-public.d.ts +264 -0
  37. package/dist/runtime-definitions-untrimmed.d.ts +1068 -0
  38. package/dist/summary.d.ts +138 -70
  39. package/dist/summary.d.ts.map +1 -1
  40. package/dist/summary.js +13 -1
  41. package/dist/summary.js.map +1 -1
  42. package/dist/tsdoc-metadata.json +11 -0
  43. package/package.json +100 -40
  44. package/prettier.config.cjs +8 -0
  45. package/src/aliasing.md +42 -0
  46. package/src/attribution.ts +78 -0
  47. package/src/dataStoreContext.ts +432 -388
  48. package/src/dataStoreFactory.ts +21 -11
  49. package/src/dataStoreRegistry.ts +18 -6
  50. package/src/garbageCollection.ts +38 -15
  51. package/src/index.ts +111 -6
  52. package/src/protocol.ts +46 -38
  53. package/src/summary.ts +298 -225
  54. package/tsconfig.json +10 -12
  55. package/.eslintrc.js +0 -13
@@ -0,0 +1,42 @@
1
+ # Aliasing and root datastores
2
+
3
+ ## What is a root datastore? What is an aliased datastore?
4
+
5
+ A root datastore is a datastore which is addressable by a custom identifier (client supplied) and is a direct child of the container runtime. A root datastore will never be garbage collected and it is a singleton with regards to the runtime it belongs to. The concept of a root datastore is considered legacy, mainly due to the previous (deprecated and removed) APIs which referred to such datastores as root. 'Aliased datastore' is the preferred current term to refer to such datastores.
6
+
7
+ ## When to alias datastores?
8
+
9
+ Alias needs to happen for datastores which:
10
+
11
+ - must be referenced by a custom id
12
+ - must never be garbage collected (as they are bound to a custom id which may be stored by the client, they must always be available to be referenced)
13
+ - must be singletons in the container
14
+
15
+ Creating root datastores was vulnerable to name conflicts, as two clients attempting to create the same root datastore with the same id risks corrupting the document. Aliasing changed the way to achieve the same goal, by enabling an asynchronous 'aliasing' operation on any newly created datastore. So in order to create such a datastore, the client needs to create an anonymous datastore (which will receive a newly generated UUID) and then explicitly attempt to bind it to a custom id (the alias) within a different operation which is decoupled from its creation.
16
+
17
+ ## Aliasing API
18
+
19
+ The process of aliasing a datastore is split in two parts:
20
+
21
+ - Creating a regular datastore using the `IContainerRuntimeBase.createDataStore(pkg: string | string[]): Promise<IDataStore>` function
22
+ - Aliasing the resulting datastore by using the `IDataStore.trySetAlias(alias: string): Promise<AliasResult>` function and specifying a string value to serve as the alias to which the datastore needs to be bound. If successful, `"Success"` will be returned, and a call to `getAliasedDataStoreEntryPoint` with the alias as parameter will return the same datastore's entry point.
23
+
24
+ The alias API can fail in the following situations, per the `AliasResult` type (see `@fluidframework/runtime-definitions`) type:
25
+
26
+ - `"Conflict"` - the alias has already been taken. In this case, the client can call `getAliasedDataStoreEntryPoint` to get the entry point of the datastore already aliased for that value. The current datastore can be left alone unreferenced so it can eventually be garbage collected.
27
+ - `"AlreadyAliased"` - the datastore has already been aliased to a different id.
28
+
29
+ The alias API is idempotent. Repeatedly calling the trySetAlias function on the same datastore will return Success when the datastore has already been aliased to the same value.
30
+
31
+ Example:
32
+
33
+ ```typescript
34
+ const dataStore = await dataObject.context.containerRuntime.createDataStore("packageName");
35
+ // One client will receive "Success", the other client will receive "Conflict".
36
+ const aliasResult = await dataStore.trySetAlias("alias");
37
+ // Both clients will get the actual aliased datastore. However, the client with the "Conflict" result must fetch the datastore by name
38
+ const finalDataStore =
39
+ aliasResult === "Success"
40
+ ? dataStore
41
+ : await dataObject.context.containerRuntime.getAliasedDataStoreEntryPoint("alias");
42
+ ```
@@ -0,0 +1,78 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import type { IUser } from "@fluidframework/protocol-definitions";
7
+
8
+ /**
9
+ * AttributionKey representing a reference to some op in the op stream.
10
+ * Content associated with this key aligns with content modified by that op.
11
+ * @alpha
12
+ */
13
+ export interface OpAttributionKey {
14
+ /**
15
+ * The type of attribution this key corresponds to.
16
+ *
17
+ * Keys currently all represent op-based attribution, so have the form `{ type: "op", key: sequenceNumber }`.
18
+ * Thus, they can be used with an `OpStreamAttributor` to recover timestamp/user information.
19
+ */
20
+ type: "op";
21
+
22
+ /**
23
+ * The sequenceNumber of the op this attribution key is for.
24
+ */
25
+ seq: number;
26
+ }
27
+
28
+ /**
29
+ * AttributionKey associated with content that was inserted while the container was in a detached state.
30
+ *
31
+ * @remarks Retrieving an {@link AttributionInfo} from content associated with detached attribution keys
32
+ * is currently unsupported, as applications can effectively modify content anonymously while detached.
33
+ * The runtime has no mechanism for reliably obtaining the user. It would be reasonable to start supporting
34
+ * this functionality if the host provided additional context to their attributor or attach calls.
35
+ * @alpha
36
+ */
37
+ export interface DetachedAttributionKey {
38
+ type: "detached";
39
+
40
+ /**
41
+ * Arbitrary discriminator associated with content inserted while detached.
42
+ *
43
+ * @remarks For now, the runtime assumes all content created while detached is associated
44
+ * with the same user/timestamp.
45
+ * We could weaken this assumption in the future with further API support and
46
+ * allow arbitrary strings or numbers as part of this key.
47
+ */
48
+ id: 0;
49
+ }
50
+
51
+ /**
52
+ * AttributionKey associated with content that has been made locally but not yet acked by the server.
53
+ * @alpha
54
+ */
55
+ export interface LocalAttributionKey {
56
+ type: "local";
57
+ }
58
+
59
+ /**
60
+ * Can be indexed into the ContainerRuntime in order to retrieve {@link AttributionInfo}.
61
+ * @alpha
62
+ */
63
+ export type AttributionKey = OpAttributionKey | DetachedAttributionKey | LocalAttributionKey;
64
+
65
+ /**
66
+ * Attribution information associated with a change.
67
+ * @internal
68
+ */
69
+ export interface AttributionInfo {
70
+ /**
71
+ * The user that performed the change.
72
+ */
73
+ user: IUser;
74
+ /**
75
+ * When the change happened.
76
+ */
77
+ timestamp: number;
78
+ }