@fluidframework/presence 2.10.0-307399

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 (255) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +216 -0
  3. package/dist/alpha.d.ts +58 -0
  4. package/dist/baseTypes.d.ts +24 -0
  5. package/dist/baseTypes.d.ts.map +1 -0
  6. package/dist/baseTypes.js +7 -0
  7. package/dist/baseTypes.js.map +1 -0
  8. package/dist/container-definitions/containerExtensions.d.ts +137 -0
  9. package/dist/container-definitions/containerExtensions.d.ts.map +1 -0
  10. package/dist/container-definitions/containerExtensions.js +7 -0
  11. package/dist/container-definitions/containerExtensions.js.map +1 -0
  12. package/dist/container-definitions/index.d.ts +7 -0
  13. package/dist/container-definitions/index.d.ts.map +1 -0
  14. package/dist/container-definitions/index.js +7 -0
  15. package/dist/container-definitions/index.js.map +1 -0
  16. package/dist/container-definitions/runtime.d.ts +12 -0
  17. package/dist/container-definitions/runtime.d.ts.map +1 -0
  18. package/dist/container-definitions/runtime.js +7 -0
  19. package/dist/container-definitions/runtime.js.map +1 -0
  20. package/dist/core-interfaces/exposedUtilityTypes.d.ts +446 -0
  21. package/dist/core-interfaces/exposedUtilityTypes.d.ts.map +1 -0
  22. package/dist/core-interfaces/exposedUtilityTypes.js +11 -0
  23. package/dist/core-interfaces/exposedUtilityTypes.js.map +1 -0
  24. package/dist/core-interfaces/index.d.ts +10 -0
  25. package/dist/core-interfaces/index.d.ts.map +1 -0
  26. package/dist/core-interfaces/index.js +7 -0
  27. package/dist/core-interfaces/index.js.map +1 -0
  28. package/dist/core-interfaces/jsonDeserialized.d.ts +109 -0
  29. package/dist/core-interfaces/jsonDeserialized.d.ts.map +1 -0
  30. package/dist/core-interfaces/jsonDeserialized.js +7 -0
  31. package/dist/core-interfaces/jsonDeserialized.js.map +1 -0
  32. package/dist/core-interfaces/jsonSerializable.d.ts +120 -0
  33. package/dist/core-interfaces/jsonSerializable.d.ts.map +1 -0
  34. package/dist/core-interfaces/jsonSerializable.js +7 -0
  35. package/dist/core-interfaces/jsonSerializable.js.map +1 -0
  36. package/dist/core-interfaces/jsonSerializationErrors.d.ts +31 -0
  37. package/dist/core-interfaces/jsonSerializationErrors.d.ts.map +1 -0
  38. package/dist/core-interfaces/jsonSerializationErrors.js +7 -0
  39. package/dist/core-interfaces/jsonSerializationErrors.js.map +1 -0
  40. package/dist/core-interfaces/jsonType.d.ts +29 -0
  41. package/dist/core-interfaces/jsonType.d.ts.map +1 -0
  42. package/dist/core-interfaces/jsonType.js +7 -0
  43. package/dist/core-interfaces/jsonType.js.map +1 -0
  44. package/dist/datastorePresenceManagerFactory.d.ts +48 -0
  45. package/dist/datastorePresenceManagerFactory.d.ts.map +1 -0
  46. package/dist/datastorePresenceManagerFactory.js +79 -0
  47. package/dist/datastorePresenceManagerFactory.js.map +1 -0
  48. package/dist/datastoreSupport.d.ts +31 -0
  49. package/dist/datastoreSupport.d.ts.map +1 -0
  50. package/dist/datastoreSupport.js +82 -0
  51. package/dist/datastoreSupport.js.map +1 -0
  52. package/dist/events/events.d.ts +198 -0
  53. package/dist/events/events.d.ts.map +1 -0
  54. package/dist/events/events.js +157 -0
  55. package/dist/events/events.js.map +1 -0
  56. package/dist/experimentalAccess.d.ts +15 -0
  57. package/dist/experimentalAccess.d.ts.map +1 -0
  58. package/dist/experimentalAccess.js +46 -0
  59. package/dist/experimentalAccess.js.map +1 -0
  60. package/dist/exposedInternalTypes.d.ts +100 -0
  61. package/dist/exposedInternalTypes.d.ts.map +1 -0
  62. package/dist/exposedInternalTypes.js +19 -0
  63. package/dist/exposedInternalTypes.js.map +1 -0
  64. package/dist/exposedUtilityTypes.d.ts +63 -0
  65. package/dist/exposedUtilityTypes.d.ts.map +1 -0
  66. package/dist/exposedUtilityTypes.js +7 -0
  67. package/dist/exposedUtilityTypes.js.map +1 -0
  68. package/dist/index.d.ts +22 -0
  69. package/dist/index.d.ts.map +1 -0
  70. package/dist/index.js +21 -0
  71. package/dist/index.js.map +1 -0
  72. package/dist/internalTypes.d.ts +39 -0
  73. package/dist/internalTypes.d.ts.map +1 -0
  74. package/dist/internalTypes.js +14 -0
  75. package/dist/internalTypes.js.map +1 -0
  76. package/dist/latestMapValueManager.d.ts +182 -0
  77. package/dist/latestMapValueManager.d.ts.map +1 -0
  78. package/dist/latestMapValueManager.js +206 -0
  79. package/dist/latestMapValueManager.js.map +1 -0
  80. package/dist/latestValueControls.d.ts +44 -0
  81. package/dist/latestValueControls.d.ts.map +1 -0
  82. package/dist/latestValueControls.js +28 -0
  83. package/dist/latestValueControls.js.map +1 -0
  84. package/dist/latestValueManager.d.ts +69 -0
  85. package/dist/latestValueManager.d.ts.map +1 -0
  86. package/dist/latestValueManager.js +100 -0
  87. package/dist/latestValueManager.js.map +1 -0
  88. package/dist/latestValueTypes.d.ts +44 -0
  89. package/dist/latestValueTypes.d.ts.map +1 -0
  90. package/dist/latestValueTypes.js +7 -0
  91. package/dist/latestValueTypes.js.map +1 -0
  92. package/dist/notificationsManager.d.ts +101 -0
  93. package/dist/notificationsManager.d.ts.map +1 -0
  94. package/dist/notificationsManager.js +82 -0
  95. package/dist/notificationsManager.js.map +1 -0
  96. package/dist/package.json +15 -0
  97. package/dist/presence.d.ts +180 -0
  98. package/dist/presence.d.ts.map +1 -0
  99. package/dist/presence.js +23 -0
  100. package/dist/presence.js.map +1 -0
  101. package/dist/presenceDatastoreManager.d.ts +91 -0
  102. package/dist/presenceDatastoreManager.d.ts.map +1 -0
  103. package/dist/presenceDatastoreManager.js +248 -0
  104. package/dist/presenceDatastoreManager.js.map +1 -0
  105. package/dist/presenceManager.d.ts +20 -0
  106. package/dist/presenceManager.d.ts.map +1 -0
  107. package/dist/presenceManager.js +104 -0
  108. package/dist/presenceManager.js.map +1 -0
  109. package/dist/presenceStates.d.ts +78 -0
  110. package/dist/presenceStates.d.ts.map +1 -0
  111. package/dist/presenceStates.js +182 -0
  112. package/dist/presenceStates.js.map +1 -0
  113. package/dist/stateDatastore.d.ts +35 -0
  114. package/dist/stateDatastore.d.ts.map +1 -0
  115. package/dist/stateDatastore.js +26 -0
  116. package/dist/stateDatastore.js.map +1 -0
  117. package/dist/systemWorkspace.d.ts +51 -0
  118. package/dist/systemWorkspace.d.ts.map +1 -0
  119. package/dist/systemWorkspace.js +180 -0
  120. package/dist/systemWorkspace.js.map +1 -0
  121. package/dist/types.d.ts +92 -0
  122. package/dist/types.d.ts.map +1 -0
  123. package/dist/types.js +8 -0
  124. package/dist/types.js.map +1 -0
  125. package/dist/valueManager.d.ts +19 -0
  126. package/dist/valueManager.d.ts.map +1 -0
  127. package/dist/valueManager.js +26 -0
  128. package/dist/valueManager.js.map +1 -0
  129. package/lib/alpha.d.ts +58 -0
  130. package/lib/baseTypes.d.ts +24 -0
  131. package/lib/baseTypes.d.ts.map +1 -0
  132. package/lib/baseTypes.js +6 -0
  133. package/lib/baseTypes.js.map +1 -0
  134. package/lib/container-definitions/containerExtensions.d.ts +137 -0
  135. package/lib/container-definitions/containerExtensions.d.ts.map +1 -0
  136. package/lib/container-definitions/containerExtensions.js +6 -0
  137. package/lib/container-definitions/containerExtensions.js.map +1 -0
  138. package/lib/container-definitions/index.d.ts +7 -0
  139. package/lib/container-definitions/index.d.ts.map +1 -0
  140. package/lib/container-definitions/index.js +6 -0
  141. package/lib/container-definitions/index.js.map +1 -0
  142. package/lib/container-definitions/runtime.d.ts +12 -0
  143. package/lib/container-definitions/runtime.d.ts.map +1 -0
  144. package/lib/container-definitions/runtime.js +6 -0
  145. package/lib/container-definitions/runtime.js.map +1 -0
  146. package/lib/core-interfaces/exposedUtilityTypes.d.ts +446 -0
  147. package/lib/core-interfaces/exposedUtilityTypes.d.ts.map +1 -0
  148. package/lib/core-interfaces/exposedUtilityTypes.js +10 -0
  149. package/lib/core-interfaces/exposedUtilityTypes.js.map +1 -0
  150. package/lib/core-interfaces/index.d.ts +10 -0
  151. package/lib/core-interfaces/index.d.ts.map +1 -0
  152. package/lib/core-interfaces/index.js +6 -0
  153. package/lib/core-interfaces/index.js.map +1 -0
  154. package/lib/core-interfaces/jsonDeserialized.d.ts +109 -0
  155. package/lib/core-interfaces/jsonDeserialized.d.ts.map +1 -0
  156. package/lib/core-interfaces/jsonDeserialized.js +6 -0
  157. package/lib/core-interfaces/jsonDeserialized.js.map +1 -0
  158. package/lib/core-interfaces/jsonSerializable.d.ts +120 -0
  159. package/lib/core-interfaces/jsonSerializable.d.ts.map +1 -0
  160. package/lib/core-interfaces/jsonSerializable.js +6 -0
  161. package/lib/core-interfaces/jsonSerializable.js.map +1 -0
  162. package/lib/core-interfaces/jsonSerializationErrors.d.ts +31 -0
  163. package/lib/core-interfaces/jsonSerializationErrors.d.ts.map +1 -0
  164. package/lib/core-interfaces/jsonSerializationErrors.js +6 -0
  165. package/lib/core-interfaces/jsonSerializationErrors.js.map +1 -0
  166. package/lib/core-interfaces/jsonType.d.ts +29 -0
  167. package/lib/core-interfaces/jsonType.d.ts.map +1 -0
  168. package/lib/core-interfaces/jsonType.js +6 -0
  169. package/lib/core-interfaces/jsonType.js.map +1 -0
  170. package/lib/datastorePresenceManagerFactory.d.ts +48 -0
  171. package/lib/datastorePresenceManagerFactory.d.ts.map +1 -0
  172. package/lib/datastorePresenceManagerFactory.js +75 -0
  173. package/lib/datastorePresenceManagerFactory.js.map +1 -0
  174. package/lib/datastoreSupport.d.ts +31 -0
  175. package/lib/datastoreSupport.d.ts.map +1 -0
  176. package/lib/datastoreSupport.js +77 -0
  177. package/lib/datastoreSupport.js.map +1 -0
  178. package/lib/events/events.d.ts +198 -0
  179. package/lib/events/events.d.ts.map +1 -0
  180. package/lib/events/events.js +152 -0
  181. package/lib/events/events.js.map +1 -0
  182. package/lib/experimentalAccess.d.ts +15 -0
  183. package/lib/experimentalAccess.d.ts.map +1 -0
  184. package/lib/experimentalAccess.js +42 -0
  185. package/lib/experimentalAccess.js.map +1 -0
  186. package/lib/exposedInternalTypes.d.ts +100 -0
  187. package/lib/exposedInternalTypes.d.ts.map +1 -0
  188. package/lib/exposedInternalTypes.js +16 -0
  189. package/lib/exposedInternalTypes.js.map +1 -0
  190. package/lib/exposedUtilityTypes.d.ts +63 -0
  191. package/lib/exposedUtilityTypes.d.ts.map +1 -0
  192. package/lib/exposedUtilityTypes.js +6 -0
  193. package/lib/exposedUtilityTypes.js.map +1 -0
  194. package/lib/index.d.ts +22 -0
  195. package/lib/index.d.ts.map +1 -0
  196. package/lib/index.js +11 -0
  197. package/lib/index.js.map +1 -0
  198. package/lib/internalTypes.d.ts +39 -0
  199. package/lib/internalTypes.d.ts.map +1 -0
  200. package/lib/internalTypes.js +11 -0
  201. package/lib/internalTypes.js.map +1 -0
  202. package/lib/latestMapValueManager.d.ts +182 -0
  203. package/lib/latestMapValueManager.d.ts.map +1 -0
  204. package/lib/latestMapValueManager.js +202 -0
  205. package/lib/latestMapValueManager.js.map +1 -0
  206. package/lib/latestValueControls.d.ts +44 -0
  207. package/lib/latestValueControls.d.ts.map +1 -0
  208. package/lib/latestValueControls.js +24 -0
  209. package/lib/latestValueControls.js.map +1 -0
  210. package/lib/latestValueManager.d.ts +69 -0
  211. package/lib/latestValueManager.d.ts.map +1 -0
  212. package/lib/latestValueManager.js +96 -0
  213. package/lib/latestValueManager.js.map +1 -0
  214. package/lib/latestValueTypes.d.ts +44 -0
  215. package/lib/latestValueTypes.d.ts.map +1 -0
  216. package/lib/latestValueTypes.js +6 -0
  217. package/lib/latestValueTypes.js.map +1 -0
  218. package/lib/notificationsManager.d.ts +101 -0
  219. package/lib/notificationsManager.d.ts.map +1 -0
  220. package/lib/notificationsManager.js +78 -0
  221. package/lib/notificationsManager.js.map +1 -0
  222. package/lib/presence.d.ts +180 -0
  223. package/lib/presence.d.ts.map +1 -0
  224. package/lib/presence.js +20 -0
  225. package/lib/presence.js.map +1 -0
  226. package/lib/presenceDatastoreManager.d.ts +91 -0
  227. package/lib/presenceDatastoreManager.d.ts.map +1 -0
  228. package/lib/presenceDatastoreManager.js +244 -0
  229. package/lib/presenceDatastoreManager.js.map +1 -0
  230. package/lib/presenceManager.d.ts +20 -0
  231. package/lib/presenceManager.d.ts.map +1 -0
  232. package/lib/presenceManager.js +100 -0
  233. package/lib/presenceManager.js.map +1 -0
  234. package/lib/presenceStates.d.ts +78 -0
  235. package/lib/presenceStates.d.ts.map +1 -0
  236. package/lib/presenceStates.js +177 -0
  237. package/lib/presenceStates.js.map +1 -0
  238. package/lib/stateDatastore.d.ts +35 -0
  239. package/lib/stateDatastore.d.ts.map +1 -0
  240. package/lib/stateDatastore.js +21 -0
  241. package/lib/stateDatastore.js.map +1 -0
  242. package/lib/systemWorkspace.d.ts +51 -0
  243. package/lib/systemWorkspace.d.ts.map +1 -0
  244. package/lib/systemWorkspace.js +176 -0
  245. package/lib/systemWorkspace.js.map +1 -0
  246. package/lib/tsdoc-metadata.json +11 -0
  247. package/lib/types.d.ts +92 -0
  248. package/lib/types.d.ts.map +1 -0
  249. package/lib/types.js +7 -0
  250. package/lib/types.js.map +1 -0
  251. package/lib/valueManager.d.ts +19 -0
  252. package/lib/valueManager.d.ts.map +1 -0
  253. package/lib/valueManager.js +21 -0
  254. package/lib/valueManager.js.map +1 -0
  255. package/package.json +175 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datastoreSupport.js","sourceRoot":"","sources":["../src/datastoreSupport.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AASH,kEAA6D;AAC7D,iEAA2E;AAK3E,qEAA2E;AAE3E;;;GAGG;AACH,MAAM,0BAA2B,SAAQ,gCAAqB;IAC7C,KAAK,CAAC,OAAO,CAAC,OAAiB;QAC9C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC9C,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC7B,OAAO,QAAQ,CAAC;QACjB,CAAC;QACD,4DAA4D;QAC5D,4CAA4C;QAC5C,gCAAgC;QAChC,gCAAgC;QAChC,IAAI,OAAO,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AAO,GAAP,OAAO,CAAuB;IAAG,CAAC;IAExE,IAAW,cAAc;QACxB,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;OAEG;IACH,IAAW,MAAM;QAChB,uEAAuE;QACvE,4EAA4E;QAC5E,uBAAuB;QACvB,IAAA,iBAAM,EAAC,IAAI,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS,EAAE,KAAK,CAAC,8BAA8B,CAAC,CAAC;QACpF,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;IAChC,CAAC;CACD;AAjBD,kDAiBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tFluidObject,\n\tIFluidLoadable,\n\tIRequest,\n\tIResponse,\n} from \"@fluidframework/core-interfaces\";\nimport type { IFluidHandleInternal } from \"@fluidframework/core-interfaces/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { FluidDataStoreRuntime } from \"@fluidframework/datastore/internal\";\nimport type {\n\tIFluidDataStoreContext,\n\tIFluidDataStoreFactory,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { create404Response } from \"@fluidframework/runtime-utils/internal\";\n\n/**\n * Extends the FluidDataStoreRuntime to provide a request method that routes requests to\n * the entrypoint Fluid object that is expected to be a {@link LoadableFluidObject}.\n */\nclass BasicFluidDataStoreRuntime extends FluidDataStoreRuntime {\n\tpublic override async request(request: IRequest): Promise<IResponse> {\n\t\tconst response = await super.request(request);\n\t\tif (response.status !== 404) {\n\t\t\treturn response;\n\t\t}\n\t\t// Return entrypoint object if someone requests it directly.\n\t\t// Direct requests exist from two scenarios:\n\t\t// 1. the request url is a \"/\"\n\t\t// 2. the request url is empty\n\t\tif (request.url === \"\" || request.url === \"/\" || request.url.startsWith(\"/?\")) {\n\t\t\t// The provideEntryPoint callback below always returns an instance of\n\t\t\t// LoadableFluidObject. Make sure that is the case.\n\t\t\tconst dataObject = await this.entryPoint.get();\n\t\t\tassert(\n\t\t\t\tdataObject instanceof LoadableFluidObject,\n\t\t\t\t0xa36 /* Data store runtime entryPoint is not expected type */,\n\t\t\t);\n\t\t\treturn { mimeType: \"fluid/object\", status: 200, value: dataObject };\n\t\t}\n\t\treturn create404Response(request);\n\t}\n}\n\n/**\n * @internal\n */\nexport class BasicDataStoreFactory<Type extends string> implements IFluidDataStoreFactory {\n\tpublic get IFluidDataStoreFactory(): IFluidDataStoreFactory {\n\t\treturn this;\n\t}\n\n\tpublic constructor(\n\t\tpublic readonly type: Type,\n\t\tprivate readonly instanceCtor: new (runtime: FluidDataStoreRuntime) => LoadableFluidObject,\n\t) {}\n\n\tpublic async instantiateDataStore(\n\t\tcontext: IFluidDataStoreContext,\n\t\texisting: boolean,\n\t): Promise<FluidDataStoreRuntime> {\n\t\t// Create a new runtime for our data store.\n\t\t// The runtime is what Fluid uses to route to our data store.\n\t\tconst runtime: FluidDataStoreRuntime = new BasicFluidDataStoreRuntime(\n\t\t\tcontext,\n\t\t\t/* ISharedObjectRegistry */ new Map(),\n\t\t\texisting,\n\t\t\t/* provideEntryPoint */ async () => {\n\t\t\t\tassert(instance !== undefined, 0xa37 /* Intended entryPoint is undefined */);\n\t\t\t\treturn instance;\n\t\t\t},\n\t\t);\n\n\t\tconst instance = new this.instanceCtor(runtime);\n\n\t\treturn runtime;\n\t}\n}\n\n/**\n * @internal\n */\nexport abstract class LoadableFluidObject implements FluidObject, IFluidLoadable {\n\tpublic constructor(protected readonly runtime: FluidDataStoreRuntime) {}\n\n\tpublic get IFluidLoadable(): this {\n\t\treturn this;\n\t}\n\n\t/**\n\t * Handle to the this Fluid object.\n\t */\n\tpublic get handle(): IFluidHandleInternal<FluidObject> {\n\t\t// BasicDataStoreFactory provides an entryPoint initialization function\n\t\t// to the data store runtime; so, this object should always have access to a\n\t\t// non-null entryPoint.\n\t\tassert(this.runtime.entryPoint !== undefined, 0xa38 /* EntryPoint was undefined */);\n\t\treturn this.runtime.entryPoint;\n\t}\n}\n"]}
@@ -0,0 +1,198 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * This file is a clone of the `events.ts` file from the `@fluidframework/tree` package.
7
+ * `@public` APIs have been changed to `@alpha` and some lint defects from more strict rules
8
+ * have been fixed or suppressed.
9
+ */
10
+ import type { IEvent } from "@fluidframework/core-interfaces";
11
+ /**
12
+ * Convert a union of types to an intersection of those types. Useful for `TransformEvents`.
13
+ */
14
+ export type UnionToIntersection<T> = (T extends any ? (k: T) => unknown : never) extends (k: infer U) => unknown ? U : never;
15
+ /**
16
+ * `true` iff the given type is an acceptable shape for an event
17
+ * @alpha
18
+ */
19
+ export type IsEvent<Event> = Event extends (...args: any[]) => any ? true : false;
20
+ /**
21
+ * Used to specify the kinds of events emitted by an {@link ISubscribable}.
22
+ *
23
+ * @remarks
24
+ *
25
+ * Any object type is a valid {@link Events}, but only the event-like properties of that
26
+ * type will be included.
27
+ *
28
+ * @example
29
+ *
30
+ * ```typescript
31
+ * interface MyEvents {
32
+ * load: (user: string, data: IUserData) => void;
33
+ * error: (errorCode: number) => void;
34
+ * }
35
+ * ```
36
+ *
37
+ * @alpha
38
+ */
39
+ export type Events<E> = {
40
+ [P in (string | symbol) & keyof E as IsEvent<E[P]> extends true ? P : never]: E[P];
41
+ };
42
+ /**
43
+ * Converts an `Events` type (i.e. the event registry for an {@link ISubscribable}) into a type consumable
44
+ * by an IEventProvider from `@fluidframework/core-interfaces`.
45
+ * @param E - the `Events` type to transform
46
+ * @param Target - an optional `IEvent` type that will be merged into the result along with the transformed `E`
47
+ *
48
+ * @example
49
+ *
50
+ * ```typescript
51
+ * interface MyEvents {
52
+ * load: (user: string, data: IUserData) => void;
53
+ * error: (errorCode: number) => void;
54
+ * }
55
+ *
56
+ * class MySharedObject extends SharedObject<TransformEvents<MyEvents, ISharedObjectEvents>> {
57
+ * // ...
58
+ * }
59
+ * ```
60
+ */
61
+ export type TransformEvents<E extends Events<E>, Target extends IEvent = IEvent> = {
62
+ [P in keyof Events<E>]: (event: P, listener: E[P]) => void;
63
+ } extends Record<any, infer Z> ? UnionToIntersection<Z> & Target : never;
64
+ /**
65
+ * An object which allows the registration of listeners so that subscribers can be notified when an event happens.
66
+ *
67
+ * `EventEmitter` can be used as a base class to implement this via extension.
68
+ * @param E - All the events that this emitter supports
69
+ * @example
70
+ * ```ts
71
+ * type MyEventEmitter = IEventEmitter<{
72
+ * load: (user: string, data: IUserData) => void;
73
+ * error: (errorCode: number) => void;
74
+ * }>
75
+ * ```
76
+ * @privateRemarks
77
+ * {@link createEmitter} can help implement this interface via delegation.
78
+ *
79
+ * @alpha
80
+ */
81
+ export interface ISubscribable<E extends Events<E>> {
82
+ /**
83
+ * Register an event listener.
84
+ * @param eventName - the name of the event
85
+ * @param listener - the handler to run when the event is fired by the emitter
86
+ * @returns a function which will deregister the listener when run. This function has undefined behavior
87
+ * if called more than once.
88
+ */
89
+ on<K extends keyof Events<E>>(eventName: K, listener: E[K]): () => void;
90
+ }
91
+ /**
92
+ * Interface for an event emitter that can emit typed events to subscribed listeners.
93
+ * @internal
94
+ */
95
+ export interface IEmitter<E extends Events<E>> {
96
+ /**
97
+ * Emits an event with the specified name and arguments, notifying all subscribers by calling their registered listener functions.
98
+ * @param eventName - the name of the event to fire
99
+ * @param args - the arguments passed to the event listener functions
100
+ */
101
+ emit<K extends keyof Events<E>>(eventName: K, ...args: Parameters<E[K]>): void;
102
+ /**
103
+ * Emits an event with the specified name and arguments, notifying all subscribers by calling their registered listener functions.
104
+ * It also collects the return values of all listeners into an array.
105
+ *
106
+ * Warning: This method should be used with caution. It deviates from the standard event-based integration pattern as creates substantial coupling between the emitter and its listeners.
107
+ * For the majority of use-cases it is recommended to use the standard {@link IEmitter.emit} functionality.
108
+ * @param eventName - the name of the event to fire
109
+ * @param args - the arguments passed to the event listener functions
110
+ * @returns An array of the return values of each listener, preserving the order listeners were called.
111
+ */
112
+ emitAndCollect<K extends keyof Events<E>>(eventName: K, ...args: Parameters<E[K]>): ReturnType<E[K]>[];
113
+ }
114
+ /**
115
+ * Create an {@link ISubscribable} that can be instructed to emit events via the {@link IEmitter} interface.
116
+ *
117
+ * A class can delegate handling {@link ISubscribable} to the returned value while using it to emit the events.
118
+ * See also `EventEmitter` which be used as a base class to implement {@link ISubscribable} via extension.
119
+ * @internal
120
+ */
121
+ export declare function createEmitter<E extends Events<E>>(noListeners?: NoListenersCallback<E>): ISubscribable<E> & IEmitter<E> & HasListeners<E>;
122
+ /**
123
+ * Called when the last listener for `eventName` is removed.
124
+ * Useful for determining when to clean up resources related to detecting when the event might occurs.
125
+ * @internal
126
+ */
127
+ export type NoListenersCallback<E extends Events<E>> = (eventName: keyof Events<E>) => void;
128
+ /**
129
+ * @internal
130
+ */
131
+ export interface HasListeners<E extends Events<E>> {
132
+ /**
133
+ * When no `eventName` is provided, returns true iff there are any listeners.
134
+ *
135
+ * When `eventName` is provided, returns true iff there are listeners for that event.
136
+ *
137
+ * @remarks
138
+ * This can be used to know when its safe to cleanup data-structures which only exist to fire events for their listeners.
139
+ */
140
+ hasListeners(eventName?: keyof Events<E>): boolean;
141
+ }
142
+ /**
143
+ * Provides an API for subscribing to and listening to events.
144
+ *
145
+ * @remarks Classes wishing to emit events may either extend this class or compose over it.
146
+ *
147
+ * @example Extending this class
148
+ *
149
+ * ```typescript
150
+ * interface MyEvents {
151
+ * "loaded": () => void;
152
+ * }
153
+ *
154
+ * class MyClass extends EventEmitter<MyEvents> {
155
+ * private load() {
156
+ * this.emit("loaded");
157
+ * }
158
+ * }
159
+ * ```
160
+ *
161
+ * @example Composing over this class
162
+ *
163
+ * ```typescript
164
+ * class MyClass implements ISubscribable<MyEvents> {
165
+ * private readonly events = EventEmitter.create<MyEvents>();
166
+ *
167
+ * private load() {
168
+ * this.events.emit("loaded");
169
+ * }
170
+ *
171
+ * public on<K extends keyof MyEvents>(eventName: K, listener: MyEvents[K]): () => void {
172
+ * return this.events.on(eventName, listener);
173
+ * }
174
+ * }
175
+ * ```
176
+ */
177
+ export declare class EventEmitter<E extends Events<E>> implements ISubscribable<E>, HasListeners<E> {
178
+ private readonly noListeners?;
179
+ private readonly listeners;
180
+ protected constructor(noListeners?: NoListenersCallback<E> | undefined);
181
+ protected emit<K extends keyof Events<E>>(eventName: K, ...args: Parameters<E[K]>): void;
182
+ protected emitAndCollect<K extends keyof Events<E>>(eventName: K, ...args: Parameters<E[K]>): ReturnType<E[K]>[];
183
+ /**
184
+ * Register an event listener.
185
+ * @param eventName - the name of the event
186
+ * @param listener - the handler to run when the event is fired by the emitter
187
+ * @returns a function which will deregister the listener when run.
188
+ * This function will error if called more than once.
189
+ * @privateRemarks
190
+ * TODO:
191
+ * invoking the returned callback can error even if its only called once if the same listener was provided to two calls to "on".
192
+ * This behavior is not documented and its unclear if its a bug or not: see note on listeners.
193
+ */
194
+ on<K extends keyof Events<E>>(eventName: K, listener: E[K]): () => void;
195
+ private off;
196
+ hasListeners(eventName?: keyof Events<E>): boolean;
197
+ }
198
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/events/events.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAuB9D;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,GAAG,KAAK,CAAC,SAAS,CACxF,CAAC,EAAE,MAAM,CAAC,KACN,OAAO,GACT,CAAC,GACD,KAAK,CAAC;AAET;;;GAGG;AACH,MAAM,MAAM,OAAO,CAAC,KAAK,IAAI,KAAK,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,IAAI,GAAG,KAAK,CAAC;AAElF;;;;;;;;;;;;;;;;;;GAkBG;AACH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,cAAc,CAAC,CAAC,SAAS,MAAM,MAAM,CAAC,CAAC,CAAC,EACjD,SAAS,EAAE,CAAC,EACZ,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACvB,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;IAgBrB;;;;;;;;;;OAUG;IACI,EAAE,CAAC,CAAC,SAAS,MAAM,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IAK9E,OAAO,CAAC,GAAG;IAeJ,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO;CAMzD"}
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.EventEmitter = exports.createEmitter = void 0;
8
+ const internal_1 = require("@fluidframework/core-utils/internal");
9
+ function fail(message) {
10
+ throw new Error(message);
11
+ }
12
+ /**
13
+ * Retrieve a value from a map with the given key, or create a new entry if the key is not in the map.
14
+ * @param map - The map to query/update
15
+ * @param key - The key to lookup in the map
16
+ * @param defaultValue - a function which returns a default value. This is called and used to set an initial value for the given key in the map if none exists
17
+ * @returns either the existing value for the given key, or the newly-created value (the result of `defaultValue`)
18
+ */
19
+ function getOrCreate(map, key, defaultValue) {
20
+ let value = map.get(key);
21
+ if (value === undefined) {
22
+ value = defaultValue(key);
23
+ map.set(key, value);
24
+ }
25
+ return value;
26
+ }
27
+ /**
28
+ * Create an {@link ISubscribable} that can be instructed to emit events via the {@link IEmitter} interface.
29
+ *
30
+ * A class can delegate handling {@link ISubscribable} to the returned value while using it to emit the events.
31
+ * See also `EventEmitter` which be used as a base class to implement {@link ISubscribable} via extension.
32
+ * @internal
33
+ */
34
+ function createEmitter(noListeners) {
35
+ return new ComposableEventEmitter(noListeners);
36
+ }
37
+ exports.createEmitter = createEmitter;
38
+ /**
39
+ * Provides an API for subscribing to and listening to events.
40
+ *
41
+ * @remarks Classes wishing to emit events may either extend this class or compose over it.
42
+ *
43
+ * @example Extending this class
44
+ *
45
+ * ```typescript
46
+ * interface MyEvents {
47
+ * "loaded": () => void;
48
+ * }
49
+ *
50
+ * class MyClass extends EventEmitter<MyEvents> {
51
+ * private load() {
52
+ * this.emit("loaded");
53
+ * }
54
+ * }
55
+ * ```
56
+ *
57
+ * @example Composing over this class
58
+ *
59
+ * ```typescript
60
+ * class MyClass implements ISubscribable<MyEvents> {
61
+ * private readonly events = EventEmitter.create<MyEvents>();
62
+ *
63
+ * private load() {
64
+ * this.events.emit("loaded");
65
+ * }
66
+ *
67
+ * public on<K extends keyof MyEvents>(eventName: K, listener: MyEvents[K]): () => void {
68
+ * return this.events.on(eventName, listener);
69
+ * }
70
+ * }
71
+ * ```
72
+ */
73
+ class EventEmitter {
74
+ // Because this is protected and not public, calling this externally (not from a subclass) makes sending events to the constructed instance impossible.
75
+ // Instead, use the static `create` function to get an instance which allows emitting events.
76
+ constructor(noListeners) {
77
+ this.noListeners = noListeners;
78
+ // TODO: because the inner data-structure here is a set, adding the same callback twice does not error,
79
+ // but only calls it once, and unsubscribing will stop calling it all together.
80
+ // This is surprising since it makes subscribing and unsubscribing not inverses (but instead both idempotent).
81
+ // This might be desired, but if so the documentation should indicate it.
82
+ this.listeners = new Map();
83
+ }
84
+ emit(eventName, ...args) {
85
+ const listeners = this.listeners.get(eventName);
86
+ if (listeners !== undefined) {
87
+ const argArray = args; // TODO: Current TS (4.5.5) cannot spread `args` into `listener()`, but future versions (e.g. 4.8.4) can.
88
+ // This explicitly copies listeners so that new listeners added during this call to emit will not receive this event.
89
+ for (const listener of listeners) {
90
+ // If listener has been unsubscribed while invoking other listeners, skip it.
91
+ if (listeners.has(listener)) {
92
+ listener(...argArray);
93
+ }
94
+ }
95
+ }
96
+ }
97
+ emitAndCollect(eventName, ...args) {
98
+ const listeners = this.listeners.get(eventName);
99
+ if (listeners !== undefined) {
100
+ const argArray = args;
101
+ const resultArray = [];
102
+ for (const listener of listeners.values()) {
103
+ // listner return type is any to enable this.listeners to be a Map
104
+ // of Sets rather than a Record with tracked (known) return types.
105
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
106
+ resultArray.push(listener(...argArray));
107
+ }
108
+ return resultArray;
109
+ }
110
+ return [];
111
+ }
112
+ /**
113
+ * Register an event listener.
114
+ * @param eventName - the name of the event
115
+ * @param listener - the handler to run when the event is fired by the emitter
116
+ * @returns a function which will deregister the listener when run.
117
+ * This function will error if called more than once.
118
+ * @privateRemarks
119
+ * TODO:
120
+ * invoking the returned callback can error even if its only called once if the same listener was provided to two calls to "on".
121
+ * This behavior is not documented and its unclear if its a bug or not: see note on listeners.
122
+ */
123
+ on(eventName, listener) {
124
+ getOrCreate(this.listeners, eventName, () => new Set()).add(listener);
125
+ return () => this.off(eventName, listener);
126
+ }
127
+ off(eventName, listener) {
128
+ const listeners = this.listeners.get(eventName) ??
129
+ // TODO: consider making this (and assert below) a usage error since it can be triggered by users of the public API: maybe separate those use cases somehow?
130
+ fail("Event has no listeners. Event deregistration functions may only be invoked once.");
131
+ (0, internal_1.assert)(listeners.delete(listener), 0xa30 /* Listener does not exist. Event deregistration functions may only be invoked once. */);
132
+ if (listeners.size === 0) {
133
+ this.listeners.delete(eventName);
134
+ this.noListeners?.(eventName);
135
+ }
136
+ }
137
+ hasListeners(eventName) {
138
+ if (eventName === undefined) {
139
+ return this.listeners.size > 0;
140
+ }
141
+ return this.listeners.has(eventName);
142
+ }
143
+ }
144
+ exports.EventEmitter = EventEmitter;
145
+ // This class exposes the constructor and the `emit` method of `EventEmitter`, elevating them from protected to public
146
+ class ComposableEventEmitter extends EventEmitter {
147
+ constructor(noListeners) {
148
+ super(noListeners);
149
+ }
150
+ emit(eventName, ...args) {
151
+ return super.emit(eventName, ...args);
152
+ }
153
+ emitAndCollect(eventName, ...args) {
154
+ return super.emitAndCollect(eventName, ...args);
155
+ }
156
+ }
157
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/events/events.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AASH,kEAA6D;AAE7D,SAAS,IAAI,CAAC,OAAe;IAC5B,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;;GAMG;AACH,SAAS,WAAW,CAAO,GAAc,EAAE,GAAM,EAAE,YAA2B;IAC7E,IAAI,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACzB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QAC1B,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAyHD;;;;;;GAMG;AACH,SAAgB,aAAa,CAC5B,WAAoC;IAEpC,OAAO,IAAI,sBAAsB,CAAI,WAAW,CAAC,CAAC;AACnD,CAAC;AAJD,sCAIC;AAwBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAa,YAAY;IAOxB,uJAAuJ;IACvJ,6FAA6F;IAC7F,YAAuC,WAAoC;QAApC,gBAAW,GAAX,WAAW,CAAyB;QAR3E,uGAAuG;QACvG,+EAA+E;QAC/E,8GAA8G;QAC9G,yEAAyE;QACxD,cAAS,GAAG,IAAI,GAAG,EAA6C,CAAC;IAIJ,CAAC;IAErE,IAAI,CAA4B,SAAY,EAAE,GAAG,IAAsB;QAChF,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAChD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC7B,M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kF,CAAC,CAAC;QAC1F,IAAA,iBAAM,EACL,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,EAC1B,KAAK,CAAC,uFAAuF,CAC7F,CAAC;QACF,IAAI,SAAS,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAC1B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACjC,IAAI,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC;QAC/B,CAAC;IACF,CAAC;IAEM,YAAY,CAAC,SAA2B;QAC9C,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,CAAC;QAChC,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;CACD;AAjFD,oCAiFC;AAED,sHAAsH;AACtH,MAAM,sBACL,SAAQ,YAAe;IAGvB,YAAmB,WAAoC;QACtD,KAAK,CAAC,WAAW,CAAC,CAAC;IACpB,CAAC;IAEe,IAAI,CACnB,SAAY,EACZ,GAAG,IAAsB;QAEzB,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;IACvC,CAAC;IAEe,cAAc,CAC7B,SAAY,EACZ,GAAG,IAAsB;QAEzB,OAAO,KAAK,CAAC,cAAc,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * This file is a clone of the `events.ts` file from the `@fluidframework/tree` package.\n * `@public` APIs have been changed to `@alpha` and some lint defects from more strict rules\n * have been fixed or suppressed.\n */\n\nimport type { IEvent } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nfunction fail(message: string): never {\n\tthrow new Error(message);\n}\n\n/**\n * Retrieve a value from a map with the given key, or create a new entry if the key is not in the map.\n * @param map - The map to query/update\n * @param key - The key to lookup in the map\n * @param defaultValue - a function which returns a default value. This is called and used to set an initial value for the given key in the map if none exists\n * @returns either the existing value for the given key, or the newly-created value (the result of `defaultValue`)\n */\nfunction getOrCreate<K, V>(map: Map<K, V>, key: K, defaultValue: (key: K) => V): V {\n\tlet value = map.get(key);\n\tif (value === undefined) {\n\t\tvalue = defaultValue(key);\n\t\tmap.set(key, value);\n\t}\n\treturn value;\n}\n\n/**\n * Convert a union of types to an intersection of those types. Useful for `TransformEvents`.\n */\nexport type UnionToIntersection<T> = (T extends any ? (k: T) => unknown : never) extends (\n\tk: infer U,\n) => unknown\n\t? U\n\t: never;\n\n/**\n * `true` iff the given type is an acceptable shape for an event\n * @alpha\n */\nexport type IsEvent<Event> = Event extends (...args: any[]) => any ? true : false;\n\n/**\n * Used to specify the kinds of events emitted by an {@link ISubscribable}.\n *\n * @remarks\n *\n * Any object type is a valid {@link Events}, but only the event-like properties of that\n * type will be included.\n *\n * @example\n *\n * ```typescript\n * interface MyEvents {\n * load: (user: string, data: IUserData) => void;\n * error: (errorCode: number) => void;\n * }\n * ```\n *\n * @alpha\n */\nexport type Events<E> = {\n\t[P in (string | symbol) & keyof E as IsEvent<E[P]> extends true ? P : never]: E[P];\n};\n\n/**\n * Converts an `Events` type (i.e. the event registry for an {@link ISubscribable}) into a type consumable\n * by an IEventProvider from `@fluidframework/core-interfaces`.\n * @param E - the `Events` type to transform\n * @param Target - an optional `IEvent` type that will be merged into the result along with the transformed `E`\n *\n * @example\n *\n * ```typescript\n * interface MyEvents {\n * load: (user: string, data: IUserData) => void;\n * error: (errorCode: number) => void;\n * }\n *\n * class MySharedObject extends SharedObject<TransformEvents<MyEvents, ISharedObjectEvents>> {\n * // ...\n * }\n * ```\n */\nexport type TransformEvents<E extends Events<E>, Target extends IEvent = IEvent> = {\n\t[P in keyof Events<E>]: (event: P, listener: E[P]) => void;\n} extends Record<any, infer Z>\n\t? UnionToIntersection<Z> & Target\n\t: never;\n\n/**\n * An object which allows the registration of listeners so that subscribers can be notified when an event happens.\n *\n * `EventEmitter` can be used as a base class to implement this via extension.\n * @param E - All the events that this emitter supports\n * @example\n * ```ts\n * type MyEventEmitter = IEventEmitter<{\n * load: (user: string, data: IUserData) => void;\n * error: (errorCode: number) => void;\n * }>\n * ```\n * @privateRemarks\n * {@link createEmitter} can help implement this interface via delegation.\n *\n * @alpha\n */\nexport interface ISubscribable<E extends Events<E>> {\n\t/**\n\t * Register an event listener.\n\t * @param eventName - the name of the event\n\t * @param listener - the handler to run when the event is fired by the emitter\n\t * @returns a function which will deregister the listener when run. This function has undefined behavior\n\t * if called more than once.\n\t */\n\ton<K extends keyof Events<E>>(eventName: K, listener: E[K]): () => void;\n}\n\n/**\n * Interface for an event emitter that can emit typed events to subscribed listeners.\n * @internal\n */\nexport interface IEmitter<E extends Events<E>> {\n\t/**\n\t * Emits an event with the specified name and arguments, notifying all subscribers by calling their registered listener functions.\n\t * @param eventName - the name of the event to fire\n\t * @param args - the arguments passed to the event listener functions\n\t */\n\temit<K extends keyof Events<E>>(eventName: K, ...args: Parameters<E[K]>): void;\n\n\t/**\n\t * Emits an event with the specified name and arguments, notifying all subscribers by calling their registered listener functions.\n\t * It also collects the return values of all listeners into an array.\n\t *\n\t * Warning: This method should be used with caution. It deviates from the standard event-based integration pattern as creates substantial coupling between the emitter and its listeners.\n\t * For the majority of use-cases it is recommended to use the standard {@link IEmitter.emit} functionality.\n\t * @param eventName - the name of the event to fire\n\t * @param args - the arguments passed to the event listener functions\n\t * @returns An array of the return values of each listener, preserving the order listeners were called.\n\t */\n\temitAndCollect<K extends keyof Events<E>>(\n\t\teventName: K,\n\t\t...args: Parameters<E[K]>\n\t): ReturnType<E[K]>[];\n}\n\n/**\n * Create an {@link ISubscribable} that can be instructed to emit events via the {@link IEmitter} interface.\n *\n * A class can delegate handling {@link ISubscribable} to the returned value while using it to emit the events.\n * See also `EventEmitter` which be used as a base class to implement {@link ISubscribable} via extension.\n * @internal\n */\nexport function createEmitter<E extends Events<E>>(\n\tnoListeners?: NoListenersCallback<E>,\n): ISubscribable<E> & IEmitter<E> & HasListeners<E> {\n\treturn new ComposableEventEmitter<E>(noListeners);\n}\n\n/**\n * Called when the last listener for `eventName` is removed.\n * Useful for determining when to clean up resources related to detecting when the event might occurs.\n * @internal\n */\nexport type NoListenersCallback<E extends Events<E>> = (eventName: keyof Events<E>) => void;\n\n/**\n * @internal\n */\nexport interface HasListeners<E extends Events<E>> {\n\t/**\n\t * When no `eventName` is provided, returns true iff there are any listeners.\n\t *\n\t * When `eventName` is provided, returns true iff there are listeners for that event.\n\t *\n\t * @remarks\n\t * This can be used to know when its safe to cleanup data-structures which only exist to fire events for their listeners.\n\t */\n\thasListeners(eventName?: keyof Events<E>): boolean;\n}\n\n/**\n * Provides an API for subscribing to and listening to events.\n *\n * @remarks Classes wishing to emit events may either extend this class or compose over it.\n *\n * @example Extending this class\n *\n * ```typescript\n * interface MyEvents {\n * \"loaded\": () => void;\n * }\n *\n * class MyClass extends EventEmitter<MyEvents> {\n * private load() {\n * this.emit(\"loaded\");\n * }\n * }\n * ```\n *\n * @example Composing over this class\n *\n * ```typescript\n * class MyClass implements ISubscribable<MyEvents> {\n * private readonly events = EventEmitter.create<MyEvents>();\n *\n * private load() {\n * this.events.emit(\"loaded\");\n * }\n *\n * public on<K extends keyof MyEvents>(eventName: K, listener: MyEvents[K]): () => void {\n * return this.events.on(eventName, listener);\n * }\n * }\n * ```\n */\nexport class EventEmitter<E extends Events<E>> implements ISubscribable<E>, HasListeners<E> {\n\t// TODO: because the inner data-structure here is a set, adding the same callback twice does not error,\n\t// but only calls it once, and unsubscribing will stop calling it all together.\n\t// This is surprising since it makes subscribing and unsubscribing not inverses (but instead both idempotent).\n\t// This might be desired, but if so the documentation should indicate it.\n\tprivate readonly listeners = new Map<keyof E, Set<(...args: unknown[]) => any>>();\n\n\t// Because this is protected and not public, calling this externally (not from a subclass) makes sending events to the constructed instance impossible.\n\t// Instead, use the static `create` function to get an instance which allows emitting events.\n\tprotected constructor(private readonly noListeners?: NoListenersCallback<E>) {}\n\n\tprotected emit<K extends keyof Events<E>>(eventName: K, ...args: Parameters<E[K]>): void {\n\t\tconst listeners = this.listeners.get(eventName);\n\t\tif (listeners !== undefined) {\n\t\t\tconst argArray: unknown[] = args; // TODO: Current TS (4.5.5) cannot spread `args` into `listener()`, but future versions (e.g. 4.8.4) can.\n\t\t\t// This explicitly copies listeners so that new listeners added during this call to emit will not receive this event.\n\t\t\tfor (const listener of listeners) {\n\t\t\t\t// If listener has been unsubscribed while invoking other listeners, skip it.\n\t\t\t\tif (listeners.has(listener)) {\n\t\t\t\t\tlistener(...argArray);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected emitAndCollect<K extends keyof Events<E>>(\n\t\teventName: K,\n\t\t...args: Parameters<E[K]>\n\t): ReturnType<E[K]>[] {\n\t\tconst listeners = this.listeners.get(eventName);\n\t\tif (listeners !== undefined) {\n\t\t\tconst argArray: unknown[] = args;\n\t\t\tconst resultArray: ReturnType<E[K]>[] = [];\n\t\t\tfor (const listener of listeners.values()) {\n\t\t\t\t// listner return type is any to enable this.listeners to be a Map\n\t\t\t\t// of Sets rather than a Record with tracked (known) return types.\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\t\tresultArray.push(listener(...argArray));\n\t\t\t}\n\t\t\treturn resultArray;\n\t\t}\n\t\treturn [];\n\t}\n\n\t/**\n\t * Register an event listener.\n\t * @param eventName - the name of the event\n\t * @param listener - the handler to run when the event is fired by the emitter\n\t * @returns a function which will deregister the listener when run.\n\t * This function will error if called more than once.\n\t * @privateRemarks\n\t * TODO:\n\t * invoking the returned callback can error even if its only called once if the same listener was provided to two calls to \"on\".\n\t * This behavior is not documented and its unclear if its a bug or not: see note on listeners.\n\t */\n\tpublic on<K extends keyof Events<E>>(eventName: K, listener: E[K]): () => void {\n\t\tgetOrCreate(this.listeners, eventName, () => new Set()).add(listener);\n\t\treturn () => this.off(eventName, listener);\n\t}\n\n\tprivate off<K extends keyof Events<E>>(eventName: K, listener: E[K]): void {\n\t\tconst listeners =\n\t\t\tthis.listeners.get(eventName) ??\n\t\t\t// TODO: consider making this (and assert below) a usage error since it can be triggered by users of the public API: maybe separate those use cases somehow?\n\t\t\tfail(\"Event has no listeners. Event deregistration functions may only be invoked once.\");\n\t\tassert(\n\t\t\tlisteners.delete(listener),\n\t\t\t0xa30 /* Listener does not exist. Event deregistration functions may only be invoked once. */,\n\t\t);\n\t\tif (listeners.size === 0) {\n\t\t\tthis.listeners.delete(eventName);\n\t\t\tthis.noListeners?.(eventName);\n\t\t}\n\t}\n\n\tpublic hasListeners(eventName?: keyof Events<E>): boolean {\n\t\tif (eventName === undefined) {\n\t\t\treturn this.listeners.size > 0;\n\t\t}\n\t\treturn this.listeners.has(eventName);\n\t}\n}\n\n// This class exposes the constructor and the `emit` method of `EventEmitter`, elevating them from protected to public\nclass ComposableEventEmitter<E extends Events<E>>\n\textends EventEmitter<E>\n\timplements IEmitter<E>\n{\n\tpublic constructor(noListeners?: NoListenersCallback<E>) {\n\t\tsuper(noListeners);\n\t}\n\n\tpublic override emit<K extends keyof Events<E>>(\n\t\teventName: K,\n\t\t...args: Parameters<E[K]>\n\t): void {\n\t\treturn super.emit(eventName, ...args);\n\t}\n\n\tpublic override emitAndCollect<K extends keyof Events<E>>(\n\t\teventName: K,\n\t\t...args: Parameters<E[K]>\n\t): ReturnType<E[K]>[] {\n\t\treturn super.emitAndCollect(eventName, ...args);\n\t}\n}\n"]}
@@ -0,0 +1,15 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import type { IFluidContainer } from "@fluidframework/fluid-static";
6
+ import type { IPresence } from "./presence.js";
7
+ /**
8
+ * Acquire an IPresence from a Fluid Container
9
+ * @param fluidContainer - Fluid Container to acquire the map from
10
+ * @returns the IPresence
11
+ *
12
+ * @alpha
13
+ */
14
+ export declare function acquirePresence(fluidContainer: IFluidContainer): IPresence;
15
+ //# sourceMappingURL=experimentalAccess.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"experimentalAccess.d.ts","sourceRoot":"","sources":["../src/experimentalAccess.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAKpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AA2C/C;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,cAAc,EAAE,eAAe,GAAG,SAAS,CAiB1E"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.acquirePresence = void 0;
8
+ const internal_1 = require("@fluidframework/core-utils/internal");
9
+ const internal_2 = require("@fluidframework/fluid-static/internal");
10
+ const presenceManager_js_1 = require("./presenceManager.js");
11
+ function isContainerExtensionStore(manager) {
12
+ return manager.acquireExtension !== undefined;
13
+ }
14
+ /**
15
+ * Common Presence manager for a container
16
+ */
17
+ class ContainerPresenceManager {
18
+ constructor(runtime) {
19
+ this.extension = this;
20
+ // TODO create the appropriate ephemeral runtime (map address must be in submitSignal, etc.)
21
+ this.interface = this.manager = (0, presenceManager_js_1.createPresenceManager)(runtime);
22
+ }
23
+ onNewContext() {
24
+ // No-op
25
+ }
26
+ processSignal(address, message, local) {
27
+ this.manager.processSignal(address, message, local);
28
+ }
29
+ }
30
+ ContainerPresenceManager.extensionId = "dis:bb89f4c0-80fd-4f0c-8469-4f2848ee7f4a";
31
+ /**
32
+ * Acquire an IPresence from a Fluid Container
33
+ * @param fluidContainer - Fluid Container to acquire the map from
34
+ * @returns the IPresence
35
+ *
36
+ * @alpha
37
+ */
38
+ function acquirePresence(fluidContainer) {
39
+ (0, internal_1.assert)((0, internal_2.isInternalFluidContainer)(fluidContainer), 0xa2f /* IFluidContainer was not recognized. Only Containers generated by the Fluid Framework are supported. */);
40
+ const innerContainer = fluidContainer.container;
41
+ (0, internal_1.assert)(isContainerExtensionStore(innerContainer), 0xa39 /* Container does not support extensions. Use acquirePresenceViaDataObject. */);
42
+ const presence = innerContainer.acquireExtension(ContainerPresenceManager.extensionId, ContainerPresenceManager);
43
+ return presence;
44
+ }
45
+ exports.acquirePresence = acquirePresence;
46
+ //# sourceMappingURL=experimentalAccess.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"experimentalAccess.js","sourceRoot":"","sources":["../src/experimentalAccess.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAA6D;AAE7D,oEAAiF;AAMjF,6DAA6D;AAS7D,SAAS,yBAAyB,CACjC,OAAiF;IAEjF,OAAQ,OAAmC,CAAC,gBAAgB,KAAK,SAAS,CAAC;AAC5E,CAAC;AAED;;GAEG;AACH,MAAM,wBAAwB;IAK7B,YAAmB,OAA0B;QAH7B,cAAS,GAAG,IAAI,CAAC;QAIhC,4FAA4F;QAC5F,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,GAAG,IAAA,0CAAqB,EACpD,OAAuC,CACvC,CAAC;IACH,CAAC;IAEM,YAAY;QAClB,QAAQ;IACT,CAAC;IAIM,aAAa,CAAC,OAAe,EAAE,OAA0B,EAAE,KAAc;QAC/E,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC;;AAJsB,oCAAW,GAAG,0CAA0C,AAA7C,CAA8C;AAOjF;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,cAA+B;IAC9D,IAAA,iBAAM,EACL,IAAA,mCAAwB,EAAC,cAAc,CAAC,EACxC,KAAK,CAAC,yGAAyG,CAC/G,CAAC;IACF,MAAM,cAAc,GAAG,cAAc,CAAC,SAAS,CAAC;IAEhD,IAAA,iBAAM,EACL,yBAAyB,CAAC,cAAc,CAAC,EACzC,KAAK,CAAC,8EAA8E,CACpF,CAAC;IAEF,MAAM,QAAQ,GAAG,cAAc,CAAC,gBAAgB,CAC/C,wBAAwB,CAAC,WAAW,EACpC,wBAAwB,CACxB,CAAC;IACF,OAAO,QAAQ,CAAC;AACjB,CAAC;AAjBD,0CAiBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IContainerExperimental } from \"@fluidframework/container-loader/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { IFluidContainer } from \"@fluidframework/fluid-static\";\nimport { isInternalFluidContainer } from \"@fluidframework/fluid-static/internal\";\nimport type { IContainerRuntimeBase } from \"@fluidframework/runtime-definitions/internal\";\n\nimport type { IEphemeralRuntime } from \"./internalTypes.js\";\nimport type { IPresence } from \"./presence.js\";\nimport type { PresenceExtensionInterface } from \"./presenceManager.js\";\nimport { createPresenceManager } from \"./presenceManager.js\";\n\nimport type {\n\tContainerExtensionStore,\n\tIContainerExtension,\n\tIExtensionMessage,\n\tIExtensionRuntime,\n} from \"@fluidframework/presence/internal/container-definitions/internal\";\n\nfunction isContainerExtensionStore(\n\tmanager: ContainerExtensionStore | IContainerRuntimeBase | IContainerExperimental,\n): manager is ContainerExtensionStore {\n\treturn (manager as ContainerExtensionStore).acquireExtension !== undefined;\n}\n\n/**\n * Common Presence manager for a container\n */\nclass ContainerPresenceManager implements IContainerExtension<never> {\n\tpublic readonly interface: IPresence;\n\tpublic readonly extension = this;\n\tprivate readonly manager: PresenceExtensionInterface;\n\n\tpublic constructor(runtime: IExtensionRuntime) {\n\t\t// TODO create the appropriate ephemeral runtime (map address must be in submitSignal, etc.)\n\t\tthis.interface = this.manager = createPresenceManager(\n\t\t\truntime as unknown as IEphemeralRuntime,\n\t\t);\n\t}\n\n\tpublic onNewContext(): void {\n\t\t// No-op\n\t}\n\n\tpublic static readonly extensionId = \"dis:bb89f4c0-80fd-4f0c-8469-4f2848ee7f4a\";\n\n\tpublic processSignal(address: string, message: IExtensionMessage, local: boolean): void {\n\t\tthis.manager.processSignal(address, message, local);\n\t}\n}\n\n/**\n * Acquire an IPresence from a Fluid Container\n * @param fluidContainer - Fluid Container to acquire the map from\n * @returns the IPresence\n *\n * @alpha\n */\nexport function acquirePresence(fluidContainer: IFluidContainer): IPresence {\n\tassert(\n\t\tisInternalFluidContainer(fluidContainer),\n\t\t0xa2f /* IFluidContainer was not recognized. Only Containers generated by the Fluid Framework are supported. */,\n\t);\n\tconst innerContainer = fluidContainer.container;\n\n\tassert(\n\t\tisContainerExtensionStore(innerContainer),\n\t\t0xa39 /* Container does not support extensions. Use acquirePresenceViaDataObject. */,\n\t);\n\n\tconst presence = innerContainer.acquireExtension(\n\t\tContainerPresenceManager.extensionId,\n\t\tContainerPresenceManager,\n\t);\n\treturn presence;\n}\n"]}
@@ -0,0 +1,100 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import type { JsonDeserialized, JsonSerializable } from "@fluidframework/presence/internal/core-interfaces";
6
+ /**
7
+ * Collection of value types that are not intended to be used/imported
8
+ * directly outside of this package.
9
+ *
10
+ * @alpha
11
+ * @system
12
+ */
13
+ export declare namespace InternalTypes {
14
+ /**
15
+ * @system
16
+ */
17
+ interface ValueStateMetadata {
18
+ rev: number;
19
+ timestamp: number;
20
+ }
21
+ /**
22
+ * @system
23
+ */
24
+ interface ValueOptionalState<TValue> extends ValueStateMetadata {
25
+ value?: JsonDeserialized<TValue>;
26
+ }
27
+ /**
28
+ * @system
29
+ */
30
+ interface ValueRequiredState<TValue> extends ValueStateMetadata {
31
+ value: JsonDeserialized<TValue>;
32
+ }
33
+ /**
34
+ * @system
35
+ */
36
+ interface ValueDirectory<T> {
37
+ rev: number;
38
+ items: {
39
+ [name: string | number]: ValueOptionalState<T> | ValueDirectory<T>;
40
+ };
41
+ }
42
+ /**
43
+ * @system
44
+ */
45
+ type ValueDirectoryOrState<T> = ValueRequiredState<T> | ValueDirectory<T>;
46
+ /**
47
+ * @system
48
+ */
49
+ interface MapValueState<T> {
50
+ rev: number;
51
+ items: {
52
+ [name: string | number]: ValueOptionalState<T>;
53
+ };
54
+ }
55
+ /**
56
+ * @system
57
+ */
58
+ class StateDatastoreHandle<TKey, TValue extends ValueDirectoryOrState<any>> {
59
+ private readonly StateDatastoreHandle;
60
+ }
61
+ /**
62
+ * Brand to ensure state values internal type safety without revealing
63
+ * internals that are subject to change.
64
+ *
65
+ * @system
66
+ */
67
+ class StateValueBrand<T> {
68
+ private readonly StateValue;
69
+ }
70
+ /**
71
+ * This type provides no additional functionality over the type it wraps.
72
+ * It is used to ensure type safety within package.
73
+ * Users may find it convenient to just use the type it wraps directly.
74
+ *
75
+ * @privateRemarks
76
+ * Checkout filtering omitting unknown from T (`Omit<T,unknown> &`).
77
+ *
78
+ * @system
79
+ */
80
+ type StateValue<T> = T & StateValueBrand<T>;
81
+ /**
82
+ * Package internal function declaration for value manager instantiation.
83
+ *
84
+ * @system
85
+ */
86
+ type ManagerFactory<TKey extends string, TValue extends ValueDirectoryOrState<any>, TManager> = {
87
+ instanceBase: new (...args: any[]) => any;
88
+ } & ((key: TKey, datastoreHandle: StateDatastoreHandle<TKey, TValue>) => {
89
+ value?: TValue;
90
+ manager: StateValue<TManager>;
91
+ });
92
+ /**
93
+ * @system
94
+ */
95
+ interface NotificationType {
96
+ name: string;
97
+ args: (JsonSerializable<unknown> & JsonDeserialized<unknown>)[];
98
+ }
99
+ }
100
+ //# sourceMappingURL=exposedInternalTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exposedInternalTypes.d.ts","sourceRoot":"","sources":["../src/exposedInternalTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,gBAAgB,EAChB,gBAAgB,EAChB,MAAM,mDAAmD,CAAC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e,CAAC,CAAC,CAAC,CAAC;IAEnD;;;;OAIG;IACH,KAAY,cAAc,CACzB,IAAI,SAAS,MAAM,EACnB,MAAM,SAAS,qBAAqB,CAAC,GAAG,CAAC,EACzC,QAAQ,IACL;QAAE,YAAY,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAA;KAAE,GAAG,CAAC,CACpD,GAAG,EAAE,IAAI,EACT,eAAe,EAAE,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,KAC/C;QACJ,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;KAC9B,CAAC,CAAC;IAEH;;OAEG;IACH,UAAiB,gBAAgB;QAChC,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;KAChE;CACD"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.InternalTypes = void 0;
8
+ /**
9
+ * Collection of value types that are not intended to be used/imported
10
+ * directly outside of this package.
11
+ *
12
+ * @alpha
13
+ * @system
14
+ */
15
+ // eslint-disable-next-line @typescript-eslint/no-namespace
16
+ var InternalTypes;
17
+ (function (InternalTypes) {
18
+ })(InternalTypes || (exports.InternalTypes = InternalTypes = {}));
19
+ //# sourceMappingURL=exposedInternalTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exposedInternalTypes.js","sourceRoot":"","sources":["../src/exposedInternalTypes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH;;;;;;GAMG;AACH,2DAA2D;AAC3D,IAAiB,aAAa,CA2G7B;AA3GD,WAAiB,aAAa;AA2G9B,CAAC,EA3GgB,aAAa,6BAAb,aAAa,QA2G7B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tJsonDeserialized,\n\tJsonSerializable,\n} from \"@fluidframework/presence/internal/core-interfaces\";\n\n/**\n * Collection of value types that are not intended to be used/imported\n * directly outside of this package.\n *\n * @alpha\n * @system\n */\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace InternalTypes {\n\t/**\n\t * @system\n\t */\n\texport interface ValueStateMetadata {\n\t\trev: number;\n\t\ttimestamp: number;\n\t}\n\n\t/**\n\t * @system\n\t */\n\texport interface ValueOptionalState<TValue> extends ValueStateMetadata {\n\t\tvalue?: JsonDeserialized<TValue>;\n\t}\n\n\t/**\n\t * @system\n\t */\n\texport interface ValueRequiredState<TValue> extends ValueStateMetadata {\n\t\tvalue: JsonDeserialized<TValue>;\n\t}\n\n\t/**\n\t * @system\n\t */\n\texport interface ValueDirectory<T> {\n\t\trev: number;\n\t\titems: {\n\t\t\t// Caution: any particular item may or may not exist\n\t\t\t// Typescript does not support absent keys without forcing type to also be undefined.\n\t\t\t// See https://github.com/microsoft/TypeScript/issues/42810.\n\t\t\t[name: string | number]: ValueOptionalState<T> | ValueDirectory<T>;\n\t\t};\n\t}\n\n\t/**\n\t * @system\n\t */\n\texport type ValueDirectoryOrState<T> = ValueRequiredState<T> | ValueDirectory<T>;\n\n\t/**\n\t * @system\n\t */\n\texport interface MapValueState<T> {\n\t\trev: number;\n\t\titems: {\n\t\t\t// Caution: any particular item may or may not exist\n\t\t\t// Typescript does not support absent keys without forcing type to also be undefined.\n\t\t\t// See https://github.com/microsoft/TypeScript/issues/42810.\n\t\t\t[name: string | number]: ValueOptionalState<T>;\n\t\t};\n\t}\n\n\t/**\n\t * @system\n\t */\n\texport declare class StateDatastoreHandle<TKey, TValue extends ValueDirectoryOrState<any>> {\n\t\tprivate readonly StateDatastoreHandle: StateDatastoreHandle<TKey, TValue>;\n\t}\n\n\t/**\n\t * Brand to ensure state values internal type safety without revealing\n\t * internals that are subject to change.\n\t *\n\t * @system\n\t */\n\texport declare class StateValueBrand<T> {\n\t\tprivate readonly StateValue: StateValue<T>;\n\t}\n\n\t/**\n\t * This type provides no additional functionality over the type it wraps.\n\t * It is used to ensure type safety within package.\n\t * Users may find it convenient to just use the type it wraps directly.\n\t *\n\t * @privateRemarks\n\t * Checkout filtering omitting unknown from T (`Omit<T,unknown> &`).\n\t *\n\t * @system\n\t */\n\texport type StateValue<T> = T & StateValueBrand<T>;\n\n\t/**\n\t * Package internal function declaration for value manager instantiation.\n\t *\n\t * @system\n\t */\n\texport type ManagerFactory<\n\t\tTKey extends string,\n\t\tTValue extends ValueDirectoryOrState<any>,\n\t\tTManager,\n\t> = { instanceBase: new (...args: any[]) => any } & ((\n\t\tkey: TKey,\n\t\tdatastoreHandle: StateDatastoreHandle<TKey, TValue>,\n\t) => {\n\t\tvalue?: TValue;\n\t\tmanager: StateValue<TManager>;\n\t});\n\n\t/**\n\t * @system\n\t */\n\texport interface NotificationType {\n\t\tname: string;\n\t\targs: (JsonSerializable<unknown> & JsonDeserialized<unknown>)[];\n\t}\n}\n"]}