@fluidframework/fluid-static 1.4.0-115997 → 2.0.0-dev-rc.1.0.0.224419

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 (100) hide show
  1. package/.eslintrc.js +8 -10
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +225 -53
  4. package/README.md +38 -0
  5. package/api-extractor-lint.json +4 -0
  6. package/api-extractor.json +2 -2
  7. package/api-report/fluid-static.api.md +141 -0
  8. package/dist/fluid-static-alpha.d.ts +408 -0
  9. package/dist/fluid-static-beta.d.ts +412 -0
  10. package/dist/fluid-static-public.d.ts +412 -0
  11. package/dist/fluid-static-untrimmed.d.ts +452 -0
  12. package/dist/{fluidContainer.js → fluidContainer.cjs} +39 -12
  13. package/dist/fluidContainer.cjs.map +1 -0
  14. package/dist/fluidContainer.d.ts +95 -142
  15. package/dist/fluidContainer.d.ts.map +1 -1
  16. package/dist/index.cjs +19 -0
  17. package/dist/index.cjs.map +1 -0
  18. package/dist/index.d.ts +4 -4
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/{rootDataObject.js → rootDataObject.cjs} +59 -23
  21. package/dist/rootDataObject.cjs.map +1 -0
  22. package/dist/rootDataObject.d.ts +9 -59
  23. package/dist/rootDataObject.d.ts.map +1 -1
  24. package/dist/{serviceAudience.js → serviceAudience.cjs} +44 -20
  25. package/dist/serviceAudience.cjs.map +1 -0
  26. package/dist/serviceAudience.d.ts +7 -54
  27. package/dist/serviceAudience.d.ts.map +1 -1
  28. package/dist/tsdoc-metadata.json +11 -0
  29. package/dist/{types.js → types.cjs} +1 -1
  30. package/dist/types.cjs.map +1 -0
  31. package/dist/types.d.ts +130 -80
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/{utils.js → utils.cjs} +7 -9
  34. package/dist/utils.cjs.map +1 -0
  35. package/dist/utils.d.ts +10 -2
  36. package/dist/utils.d.ts.map +1 -1
  37. package/lib/fluid-static-alpha.d.mts +408 -0
  38. package/lib/fluid-static-beta.d.mts +412 -0
  39. package/lib/fluid-static-public.d.mts +412 -0
  40. package/lib/fluid-static-untrimmed.d.mts +452 -0
  41. package/lib/fluidContainer.d.mts +188 -0
  42. package/lib/fluidContainer.d.mts.map +1 -0
  43. package/lib/{fluidContainer.js → fluidContainer.mjs} +36 -13
  44. package/lib/fluidContainer.mjs.map +1 -0
  45. package/lib/index.d.mts +9 -0
  46. package/lib/index.d.mts.map +1 -0
  47. package/lib/index.mjs +8 -0
  48. package/lib/index.mjs.map +1 -0
  49. package/lib/rootDataObject.d.mts +20 -0
  50. package/lib/rootDataObject.d.mts.map +1 -0
  51. package/lib/{rootDataObject.js → rootDataObject.mjs} +61 -28
  52. package/lib/rootDataObject.mjs.map +1 -0
  53. package/lib/serviceAudience.d.mts +15 -0
  54. package/lib/serviceAudience.d.mts.map +1 -0
  55. package/lib/{serviceAudience.js → serviceAudience.mjs} +42 -18
  56. package/lib/serviceAudience.mjs.map +1 -0
  57. package/lib/types.d.mts +223 -0
  58. package/lib/types.d.mts.map +1 -0
  59. package/lib/{types.js → types.mjs} +1 -1
  60. package/lib/types.mjs.map +1 -0
  61. package/lib/{utils.d.ts → utils.d.mts} +11 -3
  62. package/lib/utils.d.mts.map +1 -0
  63. package/lib/{utils.js → utils.mjs} +7 -9
  64. package/lib/utils.mjs.map +1 -0
  65. package/package.json +130 -61
  66. package/prettier.config.cjs +8 -0
  67. package/src/fluidContainer.ts +316 -250
  68. package/src/index.ts +25 -4
  69. package/src/rootDataObject.ts +203 -157
  70. package/src/serviceAudience.ts +152 -124
  71. package/src/types.ts +190 -132
  72. package/src/utils.ts +44 -39
  73. package/tsc-multi.test.json +4 -0
  74. package/tsconfig.json +12 -16
  75. package/dist/fluidContainer.js.map +0 -1
  76. package/dist/index.js +0 -26
  77. package/dist/index.js.map +0 -1
  78. package/dist/rootDataObject.js.map +0 -1
  79. package/dist/serviceAudience.js.map +0 -1
  80. package/dist/types.js.map +0 -1
  81. package/dist/utils.js.map +0 -1
  82. package/lib/fluidContainer.d.ts +0 -235
  83. package/lib/fluidContainer.d.ts.map +0 -1
  84. package/lib/fluidContainer.js.map +0 -1
  85. package/lib/index.d.ts +0 -14
  86. package/lib/index.d.ts.map +0 -1
  87. package/lib/index.js +0 -14
  88. package/lib/index.js.map +0 -1
  89. package/lib/rootDataObject.d.ts +0 -70
  90. package/lib/rootDataObject.d.ts.map +0 -1
  91. package/lib/rootDataObject.js.map +0 -1
  92. package/lib/serviceAudience.d.ts +0 -62
  93. package/lib/serviceAudience.d.ts.map +0 -1
  94. package/lib/serviceAudience.js.map +0 -1
  95. package/lib/types.d.ts +0 -173
  96. package/lib/types.d.ts.map +0 -1
  97. package/lib/types.js.map +0 -1
  98. package/lib/utils.d.ts.map +0 -1
  99. package/lib/utils.js.map +0 -1
  100. package/tsconfig.esnext.json +0 -7
@@ -4,32 +4,51 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ServiceAudience = void 0;
8
- const common_utils_1 = require("@fluidframework/common-utils");
7
+ exports.createServiceAudience = void 0;
8
+ const client_utils_1 = require("@fluid-internal/client-utils");
9
9
  /**
10
- * Base class for providing audience information for sessions interacting with FluidContainer
10
+ * @internal
11
+ */
12
+ function createServiceAudience(props) {
13
+ return new ServiceAudience(props.container, props.createServiceMember);
14
+ }
15
+ exports.createServiceAudience = createServiceAudience;
16
+ /**
17
+ * Base class for providing audience information for sessions interacting with {@link IFluidContainer}
18
+ *
19
+ * @remarks
20
+ *
11
21
  * This can be extended by different service-specific client packages to additional parameters to
12
- * the user and client details returned in IMember
13
- * @typeParam M - A service-specific member type.
22
+ * the user and client details returned in {@link IMember}.
23
+ *
24
+ * @typeParam M - A service-specific {@link IMember} implementation.
25
+ * @internal
14
26
  */
15
- class ServiceAudience extends common_utils_1.TypedEventEmitter {
27
+ class ServiceAudience extends client_utils_1.TypedEventEmitter {
16
28
  constructor(
17
29
  /**
18
30
  * Fluid Container to read the audience from.
19
31
  */
20
- container) {
32
+ container, createServiceMember) {
21
33
  super();
22
34
  this.container = container;
35
+ this.createServiceMember = createServiceMember;
23
36
  /**
24
- * Retain the most recent member list. This is so we have more information about a member
25
- * leaving the audience in the removeMember event. It allows us to match the behavior of the
26
- * addMember event where it only fires on a change to the members this class exposes (and would
27
- * actually produce a change in what getMembers returns). It also allows us to provide the
28
- * client details in the event which makes it easier to find that client connection in a map
29
- * keyed on the userId and not clientId.
30
- * This map will always be up-to-date in a removeMember event because it is set once at
31
- * construction and in every addMember event.
32
- * It is mapped clientId to M to be better work with what the IAudience event provides
37
+ * Retain the most recent member list.
38
+ *
39
+ * @remarks
40
+ *
41
+ * This is so we have more information about a member leaving the audience in the `removeMember` event.
42
+ *
43
+ * It allows us to match the behavior of the `addMember` event where it only fires on a change to the members this
44
+ * class exposes (and would actually produce a change in what `getMembers` returns).
45
+ *
46
+ * It also allows us to provide the client details in the event which makes it easier to find that client connection
47
+ * in a map keyed on the `userId` and not `clientId`.
48
+ *
49
+ * This map will always be up-to-date in a `removeMember` event because it is set once at construction and in
50
+ * every `addMember` event. It is mapped `clientId` to `M` to be better work with what the {@link IServiceAudience}
51
+ * events provide.
33
52
  */
34
53
  this.lastMembers = new Map();
35
54
  this.audience = container.audience;
@@ -83,7 +102,12 @@ class ServiceAudience extends common_utils_1.TypedEventEmitter {
83
102
  if (clientId === undefined) {
84
103
  return undefined;
85
104
  }
86
- return this.getMember(clientId);
105
+ const member = this.getMember(clientId);
106
+ if (member === undefined) {
107
+ return undefined;
108
+ }
109
+ const myself = { ...member, currentConnection: clientId };
110
+ return myself;
87
111
  }
88
112
  getMember(clientId) {
89
113
  // Fetch the user ID assoicated with this client ID from the runtime
@@ -93,7 +117,7 @@ class ServiceAudience extends common_utils_1.TypedEventEmitter {
93
117
  }
94
118
  // Return the member object with any other clients associated for this user
95
119
  const allMembers = this.getMembers();
96
- const member = allMembers.get(internalAudienceMember === null || internalAudienceMember === void 0 ? void 0 : internalAudienceMember.user.id);
120
+ const member = allMembers.get(internalAudienceMember?.user.id);
97
121
  if (member === undefined) {
98
122
  throw Error(`Attempted to fetch client ${clientId} that is not part of the current member list`);
99
123
  }
@@ -102,6 +126,7 @@ class ServiceAudience extends common_utils_1.TypedEventEmitter {
102
126
  /**
103
127
  * Provides ability for the inheriting class to include/omit specific members.
104
128
  * An example use case is omitting the summarizer client.
129
+ *
105
130
  * @param member - Member to be included/omitted.
106
131
  */
107
132
  shouldIncludeAsMember(member) {
@@ -109,5 +134,4 @@ class ServiceAudience extends common_utils_1.TypedEventEmitter {
109
134
  return member.details.capabilities.interactive;
110
135
  }
111
136
  }
112
- exports.ServiceAudience = ServiceAudience;
113
- //# sourceMappingURL=serviceAudience.js.map
137
+ //# sourceMappingURL=serviceAudience.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serviceAudience.cjs","sourceRoot":"","sources":["../src/serviceAudience.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAiE;AAKjE;;GAEG;AACH,SAAgB,qBAAqB,CAA8B,KAGlE;IACA,OAAO,IAAI,eAAe,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAC;AACxE,CAAC;AALD,sDAKC;AAED;;;;;;;;;;GAUG;AACH,MAAM,eACL,SAAQ,gCAA4C;IA2BpD;IACC;;OAEG;IACc,SAAqB,EACrB,mBAAmD;QAEpE,KAAK,EAAE,CAAC;QAHS,cAAS,GAAT,SAAS,CAAY;QACrB,wBAAmB,GAAnB,mBAAmB,CAAgC;QAxBrE;;;;;;;;;;;;;;;;WAgBG;QACK,gBAAW,GAAG,IAAI,GAAG,EAAa,CAAC;QAU1C,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;QAEnC,iFAAiF;QACjF,+EAA+E;QAC/E,IAAI,CAAC,UAAU,EAAE,CAAC;QAElB,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC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C;QAC/D,IAAI,MAAM,KAAK,SAAS,EAAE;YACzB,MAAM,KAAK,CACV,6BAA6B,QAAQ,8CAA8C,CACnF,CAAC;SACF;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACK,qBAAqB,CAAC,MAAe;QAC5C,6BAA6B;QAC7B,OAAO,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC;IAChD,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { IAudience, IContainer } from \"@fluidframework/container-definitions\";\nimport { IClient } from \"@fluidframework/protocol-definitions\";\nimport { IServiceAudience, IServiceAudienceEvents, IMember, Myself } from \"./types\";\n\n/**\n * @internal\n */\nexport function createServiceAudience<M extends IMember = IMember>(props: {\n\tcontainer: IContainer;\n\tcreateServiceMember: (audienceMember: IClient) => M;\n}): IServiceAudience<M> {\n\treturn new ServiceAudience(props.container, props.createServiceMember);\n}\n\n/**\n * Base class for providing audience information for sessions interacting with {@link IFluidContainer}\n *\n * @remarks\n *\n * This can be extended by different service-specific client packages to additional parameters to\n * the user and client details returned in {@link IMember}.\n *\n * @typeParam M - A service-specific {@link IMember} implementation.\n * @internal\n */\nclass ServiceAudience<M extends IMember = IMember>\n\textends TypedEventEmitter<IServiceAudienceEvents<M>>\n\timplements IServiceAudience<M>\n{\n\t/**\n\t * Audience object which includes all the existing members of the {@link IFluidContainer | container}.\n\t */\n\tprivate readonly audience: IAudience;\n\n\t/**\n\t * Retain the most recent member list.\n\t *\n\t * @remarks\n\t *\n\t * This is so we have more information about a member leaving the audience in the `removeMember` event.\n\t *\n\t * It allows us to match the behavior of the `addMember` event where it only fires on a change to the members this\n\t * class exposes (and would actually produce a change in what `getMembers` returns).\n\t *\n\t * It also allows us to provide the client details in the event which makes it easier to find that client connection\n\t * in a map keyed on the `userId` and not `clientId`.\n\t *\n\t * This map will always be up-to-date in a `removeMember` event because it is set once at construction and in\n\t * every `addMember` event. It is mapped `clientId` to `M` to be better work with what the {@link IServiceAudience}\n\t * events provide.\n\t */\n\tprivate lastMembers = new Map<string, M>();\n\n\tconstructor(\n\t\t/**\n\t\t * Fluid Container to read the audience from.\n\t\t */\n\t\tprivate readonly container: IContainer,\n\t\tprivate readonly createServiceMember: (audienceMember: IClient) => M,\n\t) {\n\t\tsuper();\n\t\tthis.audience = container.audience;\n\n\t\t// getMembers will assign lastMembers so the removeMember event has what it needs\n\t\t// in case it would fire before getMembers otherwise gets called the first time\n\t\tthis.getMembers();\n\n\t\tthis.audience.on(\"addMember\", (clientId: string, details: IClient) => {\n\t\t\tif (this.shouldIncludeAsMember(details)) {\n\t\t\t\tconst member = this.getMember(clientId);\n\t\t\t\tthis.emit(\"memberAdded\", clientId, member);\n\t\t\t\tthis.emit(\"membersChanged\");\n\t\t\t}\n\t\t});\n\n\t\tthis.audience.on(\"removeMember\", (clientId: string) => {\n\t\t\tif (this.lastMembers.has(clientId)) {\n\t\t\t\tthis.emit(\"memberRemoved\", clientId, this.lastMembers.get(clientId));\n\t\t\t\tthis.emit(\"membersChanged\");\n\t\t\t}\n\t\t});\n\n\t\tthis.container.on(\"connected\", () => this.emit(\"membersChanged\"));\n\t}\n\n\t/**\n\t * {@inheritDoc IServiceAudience.getMembers}\n\t */\n\tpublic getMembers(): Map<string, M> {\n\t\tconst users = new Map<string, M>();\n\t\tconst clientMemberMap = new Map<string, M>();\n\t\t// Iterate through the members and get the user specifics.\n\t\tthis.audience.getMembers().forEach((member: IClient, clientId: string) => {\n\t\t\tif (this.shouldIncludeAsMember(member)) {\n\t\t\t\tconst userId = member.user.id;\n\t\t\t\t// Ensure we're tracking the user\n\t\t\t\tlet user = users.get(userId);\n\t\t\t\tif (user === undefined) {\n\t\t\t\t\tuser = this.createServiceMember(member);\n\t\t\t\t\tusers.set(userId, user);\n\t\t\t\t}\n\n\t\t\t\t// Add this connection to their collection\n\t\t\t\tuser.connections.push({ id: clientId, mode: member.mode });\n\t\t\t\tclientMemberMap.set(clientId, user);\n\t\t\t}\n\t\t});\n\t\tthis.lastMembers = clientMemberMap;\n\t\treturn users;\n\t}\n\n\t/**\n\t * {@inheritDoc IServiceAudience.getMyself}\n\t */\n\tpublic getMyself(): Myself<M> | undefined {\n\t\tconst clientId = this.container.clientId;\n\t\tif (clientId === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst member = this.getMember(clientId);\n\t\tif (member === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst myself: Myself<M> = { ...member, currentConnection: clientId };\n\n\t\treturn myself;\n\t}\n\n\tprivate getMember(clientId: string): M | undefined {\n\t\t// Fetch the user ID assoicated with this client ID from the runtime\n\t\tconst internalAudienceMember = this.audience.getMember(clientId);\n\t\tif (internalAudienceMember === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\t// Return the member object with any other clients associated for this user\n\t\tconst allMembers = this.getMembers();\n\t\tconst member = allMembers.get(internalAudienceMember?.user.id);\n\t\tif (member === undefined) {\n\t\t\tthrow Error(\n\t\t\t\t`Attempted to fetch client ${clientId} that is not part of the current member list`,\n\t\t\t);\n\t\t}\n\t\treturn member;\n\t}\n\n\t/**\n\t * Provides ability for the inheriting class to include/omit specific members.\n\t * An example use case is omitting the summarizer client.\n\t *\n\t * @param member - Member to be included/omitted.\n\t */\n\tprivate shouldIncludeAsMember(member: IClient): boolean {\n\t\t// Include only human members\n\t\treturn member.details.capabilities.interactive;\n\t}\n}\n"]}
@@ -2,61 +2,14 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { TypedEventEmitter } from "@fluidframework/common-utils";
6
- import { IAudience, IContainer } from "@fluidframework/container-definitions";
5
+ import { IContainer } from "@fluidframework/container-definitions";
7
6
  import { IClient } from "@fluidframework/protocol-definitions";
8
- import { IServiceAudience, IServiceAudienceEvents, IMember } from "./types";
7
+ import { IServiceAudience, IMember } from "./types";
9
8
  /**
10
- * Base class for providing audience information for sessions interacting with FluidContainer
11
- * This can be extended by different service-specific client packages to additional parameters to
12
- * the user and client details returned in IMember
13
- * @typeParam M - A service-specific member type.
9
+ * @internal
14
10
  */
15
- export declare abstract class ServiceAudience<M extends IMember = IMember> extends TypedEventEmitter<IServiceAudienceEvents<M>> implements IServiceAudience<M> {
16
- /**
17
- * Fluid Container to read the audience from.
18
- */
19
- protected readonly container: IContainer;
20
- /**
21
- * Audience object which includes all the existing members of the container.
22
- */
23
- protected readonly audience: IAudience;
24
- /**
25
- * Retain the most recent member list. This is so we have more information about a member
26
- * leaving the audience in the removeMember event. It allows us to match the behavior of the
27
- * addMember event where it only fires on a change to the members this class exposes (and would
28
- * actually produce a change in what getMembers returns). It also allows us to provide the
29
- * client details in the event which makes it easier to find that client connection in a map
30
- * keyed on the userId and not clientId.
31
- * This map will always be up-to-date in a removeMember event because it is set once at
32
- * construction and in every addMember event.
33
- * It is mapped clientId to M to be better work with what the IAudience event provides
34
- */
35
- protected lastMembers: Map<string, M>;
36
- constructor(
37
- /**
38
- * Fluid Container to read the audience from.
39
- */
40
- container: IContainer);
41
- /**
42
- * Provides ability for inheriting class to modify/extend the audience object.
43
- * @param audienceMember - Record of a specific audience member.
44
- */
45
- protected abstract createServiceMember(audienceMember: IClient): M;
46
- /**
47
- * {@inheritDoc IServiceAudience.getMembers}
48
- */
49
- getMembers(): Map<string, M>;
50
- /**
51
- * {@inheritDoc IServiceAudience.getMyself}
52
- */
53
- getMyself(): M | undefined;
54
- private getMember;
55
- /**
56
- * Provides ability for the inheriting class to include/omit specific members.
57
- * An example use case is omitting the summarizer client.
58
- * @param member - Member to be included/omitted.
59
- */
60
- protected shouldIncludeAsMember(member: IClient): boolean;
61
- }
11
+ export declare function createServiceAudience<M extends IMember = IMember>(props: {
12
+ container: IContainer;
13
+ createServiceMember: (audienceMember: IClient) => M;
14
+ }): IServiceAudience<M>;
62
15
  //# sourceMappingURL=serviceAudience.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serviceAudience.d.ts","sourceRoot":"","sources":["../src/serviceAudience.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAE5E;;;;;GAKG;AACH,8BAAsB,eAAe,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,CAC/D,SAAQ,iBAAiB,CAAC,sBAAsB,CAAC,CAAC,CAAC,CACnD,YAAW,gBAAgB,CAAC,CAAC,CAAC;IAoB5B;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,UAAU;IAtB1C;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAEvC;;;;;;;;;;OAUG;IACH,SAAS,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAa;;IAGhD;;OAEG;IACgB,SAAS,EAAE,UAAU;IA2B1C;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,mBAAmB,CAAC,cAAc,EAAE,OAAO,GAAG,CAAC;IAElE;;OAEG;IACI,UAAU,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;IAuBnC;;OAEG;IACI,SAAS,IAAI,CAAC,GAAG,SAAS;IAQjC,OAAO,CAAC,SAAS;IAejB;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO;CAI1D"}
1
+ {"version":3,"file":"serviceAudience.d.ts","sourceRoot":"","sources":["../src/serviceAudience.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAa,UAAU,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAA0B,OAAO,EAAU,MAAM,SAAS,CAAC;AAEpF;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,KAAK,EAAE;IACzE,SAAS,EAAE,UAAU,CAAC;IACtB,mBAAmB,EAAE,CAAC,cAAc,EAAE,OAAO,KAAK,CAAC,CAAC;CACpD,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAEtB"}
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.38.3"
9
+ }
10
+ ]
11
+ }
@@ -4,4 +4,4 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- //# sourceMappingURL=types.js.map
7
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IEvent, IEventProvider, IFluidLoadable } from \"@fluidframework/core-interfaces\";\nimport { IChannelFactory } from \"@fluidframework/datastore-definitions\";\n\n/**\n * A mapping of string identifiers to instantiated `DataObject`s or `SharedObject`s.\n * @internal\n */\nexport type LoadableObjectRecord = Record<string, IFluidLoadable>;\n\n/**\n * A mapping of string identifiers to classes that will later be used to instantiate a corresponding `DataObject`\n * or `SharedObject` in a {@link LoadableObjectRecord}.\n * @public\n */\nexport type LoadableObjectClassRecord = Record<string, LoadableObjectClass<any>>;\n\n/**\n * A class object of `DataObject` or `SharedObject`.\n *\n * @typeParam T - The class of the `DataObject` or `SharedObject`.\n * @public\n */\nexport type LoadableObjectClass<T extends IFluidLoadable> =\n\t| DataObjectClass<T>\n\t| SharedObjectClass<T>;\n\n/**\n * A class that has a factory that can create a `DataObject` and a\n * constructor that will return the type of the `DataObject`.\n *\n * @typeParam T - The class of the `DataObject`.\n * @public\n */\nexport type DataObjectClass<T extends IFluidLoadable> = {\n\treadonly factory: { IFluidDataStoreFactory: DataObjectClass<T>[\"factory\"] };\n} & LoadableObjectCtor<T>;\n\n/**\n * A class that has a factory that can create a DDSes (`SharedObject`s) and a\n * constructor that will return the type of the `DataObject`.\n *\n * @typeParam T - The class of the `SharedObject`.\n * @public\n */\nexport type SharedObjectClass<T extends IFluidLoadable> = {\n\treadonly getFactory: () => IChannelFactory;\n} & LoadableObjectCtor<T>;\n\n/**\n * An object with a constructor that will return an {@link @fluidframework/core-interfaces#IFluidLoadable}.\n *\n * @typeParam T - The class of the loadable object.\n * @public\n */\nexport type LoadableObjectCtor<T extends IFluidLoadable> = new (...args: any[]) => T;\n\n/**\n * Declares the Fluid objects that will be available in the {@link IFluidContainer | Container}.\n *\n * @remarks\n *\n * It includes both the instances of objects that are initially available upon `Container` creation, as well\n * as the types of objects that may be dynamically created throughout the lifetime of the `Container`.\n * @public\n */\nexport interface ContainerSchema {\n\t/**\n\t * Defines loadable objects that will be created when the {@link IFluidContainer | Container} is first created.\n\t *\n\t * @remarks It uses the key as the id and the value as the loadable object to create.\n\t *\n\t * @example\n\t *\n\t * In the example below two objects will be created when the `Container` is first\n\t * created. One with id \"map1\" that will return a `SharedMap` and the other with\n\t * id \"pair1\" that will return a `KeyValueDataObject`.\n\t *\n\t * ```typescript\n\t * {\n\t * map1: SharedMap,\n\t * pair1: KeyValueDataObject,\n\t * }\n\t * ```\n\t */\n\tinitialObjects: LoadableObjectClassRecord;\n\n\t/**\n\t * Loadable objects that can be created after the initial {@link IFluidContainer | Container} creation.\n\t *\n\t * @remarks\n\t *\n\t * Types defined in `initialObjects` will always be available and are not required to be provided here.\n\t *\n\t * For best practice it's recommended to define all the dynamic types you create even if they are\n\t * included via initialObjects.\n\t */\n\tdynamicObjectTypes?: LoadableObjectClass<any>[];\n}\n\n/**\n * @internal\n */\nexport interface IProvideRootDataObject {\n\treadonly IRootDataObject: IRootDataObject;\n}\n\n/**\n * Holds the collection of objects that the container was initially created with, as well as provides the ability\n * to dynamically create further objects during usage.\n * @internal\n */\nexport interface IRootDataObject extends IProvideRootDataObject {\n\t/**\n\t * Provides a record of the initial objects defined on creation.\n\t */\n\treadonly initialObjects: LoadableObjectRecord;\n\n\t/**\n\t * Dynamically creates a new detached collaborative object (DDS/DataObject).\n\t *\n\t * @param objectClass - Type of the collaborative object to be created.\n\t *\n\t * @typeParam T - The class of the `DataObject` or `SharedObject`.\n\t */\n\tcreate<T extends IFluidLoadable>(objectClass: LoadableObjectClass<T>): Promise<T>;\n}\n\n/**\n * Signature for {@link IMember} change events.\n *\n * @param clientId - A unique identifier for the client.\n * @param member - The service-specific member object for the client.\n *\n * @see See {@link IServiceAudienceEvents} for usage details.\n * @public\n */\nexport type MemberChangedListener<M extends IMember> = (clientId: string, member: M) => void;\n\n/**\n * Events that trigger when the roster of members in the Fluid session change.\n *\n * @remarks\n *\n * Only changes that would be reflected in the returned map of {@link IServiceAudience}'s\n * {@link IServiceAudience.getMembers} method will emit events.\n *\n * @typeParam M - A service-specific {@link IMember} implementation.\n * @public\n */\nexport interface IServiceAudienceEvents<M extends IMember> extends IEvent {\n\t/**\n\t * Emitted when a {@link IMember | member}(s) are either added or removed.\n\t *\n\t * @eventProperty\n\t */\n\t(event: \"membersChanged\", listener: () => void): void;\n\n\t/**\n\t * Emitted when a {@link IMember | member} joins the audience.\n\t *\n\t * @eventProperty\n\t */\n\t(event: \"memberAdded\", listener: MemberChangedListener<M>): void;\n\n\t/**\n\t * Emitted when a {@link IMember | member} leaves the audience.\n\t *\n\t * @eventProperty\n\t */\n\t(event: \"memberRemoved\", listener: MemberChangedListener<M>): void;\n}\n\n/**\n * Base interface to be implemented to fetch each service's audience.\n *\n * @remarks\n *\n * The type parameter `M` allows consumers to further extend the client object with service-specific\n * details about the connecting client, such as device information, environment, or a username.\n *\n * @typeParam M - A service-specific {@link IMember} type.\n * @public\n */\nexport interface IServiceAudience<M extends IMember>\n\textends IEventProvider<IServiceAudienceEvents<M>> {\n\t/**\n\t * Returns an map of all users currently in the Fluid session where key is the userId and the value is the\n\t * member object. The implementation may choose to exclude certain connections from the returned map.\n\t * E.g. ServiceAudience excludes non-interactive connections to represent only the roster of live users.\n\t */\n\tgetMembers(): Map<string, M>;\n\n\t/**\n\t * Returns the current active user on this client once they are connected. Otherwise, returns undefined.\n\t */\n\tgetMyself(): Myself<M> | undefined;\n}\n\n/**\n * Base interface for information for each connection made to the Fluid session.\n *\n * @remarks This interface can be extended to provide additional information specific to each service.\n * @public\n */\nexport interface IConnection {\n\t/**\n\t * A unique ID for the connection. A single user may have multiple connections, each with a different ID.\n\t */\n\tid: string;\n\n\t/**\n\t * Whether the connection is in read or read/write mode.\n\t */\n\tmode: \"write\" | \"read\";\n}\n\n/**\n * Base interface to be implemented to fetch each service's member.\n *\n * @remarks This interface can be extended by each service to provide additional service-specific user metadata.\n * @public\n */\nexport interface IMember {\n\t/**\n\t * An ID for the user, unique among each individual user connecting to the session.\n\t */\n\tuserId: string;\n\n\t/**\n\t * The set of connections the user has made, e.g. from multiple tabs or devices.\n\t */\n\tconnections: IConnection[];\n}\n\n/**\n * An extended member object that includes currentConnection\n * @public\n */\nexport type Myself<M extends IMember = IMember> = M & { currentConnection: string };\n"]}
package/dist/types.d.ts CHANGED
@@ -2,61 +2,77 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { IEvent, IEventProvider } from "@fluidframework/common-definitions";
6
- import { IFluidLoadable } from "@fluidframework/core-interfaces";
5
+ import { IEvent, IEventProvider, IFluidLoadable } from "@fluidframework/core-interfaces";
7
6
  import { IChannelFactory } from "@fluidframework/datastore-definitions";
8
- import { IFluidDataStoreFactory } from "@fluidframework/runtime-definitions";
9
7
  /**
10
- * A mapping of string identifiers to instantiated DataObjects or SharedObjects.
8
+ * A mapping of string identifiers to instantiated `DataObject`s or `SharedObject`s.
9
+ * @internal
11
10
  */
12
- export declare type LoadableObjectRecord = Record<string, IFluidLoadable>;
11
+ export type LoadableObjectRecord = Record<string, IFluidLoadable>;
13
12
  /**
14
- * A mapping of string identifiers to classes that will later be used to instantiate a corresponding DataObject
15
- * or SharedObject in a LoadableObjectRecord.
13
+ * A mapping of string identifiers to classes that will later be used to instantiate a corresponding `DataObject`
14
+ * or `SharedObject` in a {@link LoadableObjectRecord}.
15
+ * @public
16
16
  */
17
- export declare type LoadableObjectClassRecord = Record<string, LoadableObjectClass<any>>;
17
+ export type LoadableObjectClassRecord = Record<string, LoadableObjectClass<any>>;
18
18
  /**
19
- * A LoadableObjectClass is an class object of DataObject or SharedObject
20
- * @typeParam T - The class of the DataObject or SharedObject
19
+ * A class object of `DataObject` or `SharedObject`.
20
+ *
21
+ * @typeParam T - The class of the `DataObject` or `SharedObject`.
22
+ * @public
21
23
  */
22
- export declare type LoadableObjectClass<T extends IFluidLoadable> = DataObjectClass<T> | SharedObjectClass<T>;
24
+ export type LoadableObjectClass<T extends IFluidLoadable> = DataObjectClass<T> | SharedObjectClass<T>;
23
25
  /**
24
- * A DataObjectClass is a class that has a factory that can create a DataObject and a
25
- * constructor that will return the type of the DataObject.
26
- * @typeParam T - The class of the DataObject
26
+ * A class that has a factory that can create a `DataObject` and a
27
+ * constructor that will return the type of the `DataObject`.
28
+ *
29
+ * @typeParam T - The class of the `DataObject`.
30
+ * @public
27
31
  */
28
- export declare type DataObjectClass<T extends IFluidLoadable> = {
29
- readonly factory: IFluidDataStoreFactory;
32
+ export type DataObjectClass<T extends IFluidLoadable> = {
33
+ readonly factory: {
34
+ IFluidDataStoreFactory: DataObjectClass<T>["factory"];
35
+ };
30
36
  } & LoadableObjectCtor<T>;
31
37
  /**
32
- * A SharedObjectClass is a class that has a factory that can create a DDS (SharedObject) and a
33
- * constructor that will return the type of the DataObject.
34
- * @typeParam T - The class of the SharedObject
38
+ * A class that has a factory that can create a DDSes (`SharedObject`s) and a
39
+ * constructor that will return the type of the `DataObject`.
40
+ *
41
+ * @typeParam T - The class of the `SharedObject`.
42
+ * @public
35
43
  */
36
- export declare type SharedObjectClass<T extends IFluidLoadable> = {
44
+ export type SharedObjectClass<T extends IFluidLoadable> = {
37
45
  readonly getFactory: () => IChannelFactory;
38
46
  } & LoadableObjectCtor<T>;
39
47
  /**
40
- * An object with a constructor that will return an `IFluidLoadable`.
41
- * @typeParam T - The class of the loadable object
48
+ * An object with a constructor that will return an {@link @fluidframework/core-interfaces#IFluidLoadable}.
49
+ *
50
+ * @typeParam T - The class of the loadable object.
51
+ * @public
42
52
  */
43
- export declare type LoadableObjectCtor<T extends IFluidLoadable> = new (...args: any[]) => T;
53
+ export type LoadableObjectCtor<T extends IFluidLoadable> = new (...args: any[]) => T;
44
54
  /**
45
- * The ContainerSchema declares the Fluid objects that will be available in the container. It includes both the
46
- * instances of objects that are initially available upon container creation, as well as the types of objects that may
47
- * be dynamically created throughout the lifetime of the container.
55
+ * Declares the Fluid objects that will be available in the {@link IFluidContainer | Container}.
56
+ *
57
+ * @remarks
58
+ *
59
+ * It includes both the instances of objects that are initially available upon `Container` creation, as well
60
+ * as the types of objects that may be dynamically created throughout the lifetime of the `Container`.
61
+ * @public
48
62
  */
49
63
  export interface ContainerSchema {
50
64
  /**
51
- * Defines loadable objects that will be created when the `Container` is first created.
52
- * It uses the key as the id and the value as the loadable object to create.
65
+ * Defines loadable objects that will be created when the {@link IFluidContainer | Container} is first created.
66
+ *
67
+ * @remarks It uses the key as the id and the value as the loadable object to create.
53
68
  *
54
69
  * @example
55
- * In the example below two objects will be created when the Container is first
70
+ *
71
+ * In the example below two objects will be created when the `Container` is first
56
72
  * created. One with id "map1" that will return a `SharedMap` and the other with
57
73
  * id "pair1" that will return a `KeyValueDataObject`.
58
74
  *
59
- * ```
75
+ * ```typescript
60
76
  * {
61
77
  * map1: SharedMap,
62
78
  * pair1: KeyValueDataObject,
@@ -65,7 +81,9 @@ export interface ContainerSchema {
65
81
  */
66
82
  initialObjects: LoadableObjectClassRecord;
67
83
  /**
68
- * Dynamic objects are Loadable objects that can be created after the initial Container creation.
84
+ * Loadable objects that can be created after the initial {@link IFluidContainer | Container} creation.
85
+ *
86
+ * @remarks
69
87
  *
70
88
  * Types defined in `initialObjects` will always be available and are not required to be provided here.
71
89
  *
@@ -75,60 +93,81 @@ export interface ContainerSchema {
75
93
  dynamicObjectTypes?: LoadableObjectClass<any>[];
76
94
  }
77
95
  /**
78
- * Events that trigger when the roster of members in the Fluid session change.
79
- * Only changes that would be reflected in the returned map of {@link IServiceAudience}'s
80
- * {@link IServiceAudience.getMembers} method will emit events.
81
- *
82
- * @remarks
83
- *
84
- * The following is the list of events emitted.
85
- *
86
- * ### "membersChanged"
87
- *
88
- * The "membersChanged" event is emitted when a member is either added or removed.
89
- *
90
- * #### Listener signature
91
- *
92
- * ```typescript
93
- * () => void;
94
- * ```
95
- *
96
- * ### "memberAdded"
97
- *
98
- * The "memberAdded" event is emitted when a member joins the audience.
99
- *
100
- * #### Listener signature
101
- *
102
- * ```typescript
103
- * (clientId: string, member: M) => void;
104
- * ```
105
- * - `clientId` - A unique identifier for the client
106
- *
107
- * - `member` - The service-specific member object for the client
96
+ * @internal
97
+ */
98
+ export interface IProvideRootDataObject {
99
+ readonly IRootDataObject: IRootDataObject;
100
+ }
101
+ /**
102
+ * Holds the collection of objects that the container was initially created with, as well as provides the ability
103
+ * to dynamically create further objects during usage.
104
+ * @internal
105
+ */
106
+ export interface IRootDataObject extends IProvideRootDataObject {
107
+ /**
108
+ * Provides a record of the initial objects defined on creation.
109
+ */
110
+ readonly initialObjects: LoadableObjectRecord;
111
+ /**
112
+ * Dynamically creates a new detached collaborative object (DDS/DataObject).
113
+ *
114
+ * @param objectClass - Type of the collaborative object to be created.
115
+ *
116
+ * @typeParam T - The class of the `DataObject` or `SharedObject`.
117
+ */
118
+ create<T extends IFluidLoadable>(objectClass: LoadableObjectClass<T>): Promise<T>;
119
+ }
120
+ /**
121
+ * Signature for {@link IMember} change events.
108
122
  *
109
- * ### "memberRemoved"
123
+ * @param clientId - A unique identifier for the client.
124
+ * @param member - The service-specific member object for the client.
110
125
  *
111
- * The "memberRemoved" event is emitted when a member leaves the audience.
126
+ * @see See {@link IServiceAudienceEvents} for usage details.
127
+ * @public
128
+ */
129
+ export type MemberChangedListener<M extends IMember> = (clientId: string, member: M) => void;
130
+ /**
131
+ * Events that trigger when the roster of members in the Fluid session change.
112
132
  *
113
- * #### Listener signature
133
+ * @remarks
114
134
  *
115
- * ```typescript
116
- * (clientId: string, member: M) => void;
117
- * ```
118
- * - `clientId` - A unique identifier for the client
135
+ * Only changes that would be reflected in the returned map of {@link IServiceAudience}'s
136
+ * {@link IServiceAudience.getMembers} method will emit events.
119
137
  *
120
- * - `member` - The service-specific member object for the client
121
- * @typeParam M - A service-specific member type.
138
+ * @typeParam M - A service-specific {@link IMember} implementation.
139
+ * @public
122
140
  */
123
141
  export interface IServiceAudienceEvents<M extends IMember> extends IEvent {
142
+ /**
143
+ * Emitted when a {@link IMember | member}(s) are either added or removed.
144
+ *
145
+ * @eventProperty
146
+ */
124
147
  (event: "membersChanged", listener: () => void): void;
125
- (event: "memberAdded" | "memberRemoved", listener: (clientId: string, member: M) => void): void;
148
+ /**
149
+ * Emitted when a {@link IMember | member} joins the audience.
150
+ *
151
+ * @eventProperty
152
+ */
153
+ (event: "memberAdded", listener: MemberChangedListener<M>): void;
154
+ /**
155
+ * Emitted when a {@link IMember | member} leaves the audience.
156
+ *
157
+ * @eventProperty
158
+ */
159
+ (event: "memberRemoved", listener: MemberChangedListener<M>): void;
126
160
  }
127
161
  /**
128
- * Base interface to be implemented to fetch each service's audience. The generic M allows consumers to further
129
- * extend the client object with service-specific details about the connecting client, such as device information,
130
- * environment, or a username.
131
- * @typeParam M - A service-specific member type.
162
+ * Base interface to be implemented to fetch each service's audience.
163
+ *
164
+ * @remarks
165
+ *
166
+ * The type parameter `M` allows consumers to further extend the client object with service-specific
167
+ * details about the connecting client, such as device information, environment, or a username.
168
+ *
169
+ * @typeParam M - A service-specific {@link IMember} type.
170
+ * @public
132
171
  */
133
172
  export interface IServiceAudience<M extends IMember> extends IEventProvider<IServiceAudienceEvents<M>> {
134
173
  /**
@@ -140,11 +179,13 @@ export interface IServiceAudience<M extends IMember> extends IEventProvider<ISer
140
179
  /**
141
180
  * Returns the current active user on this client once they are connected. Otherwise, returns undefined.
142
181
  */
143
- getMyself(): M | undefined;
182
+ getMyself(): Myself<M> | undefined;
144
183
  }
145
184
  /**
146
- * Base interface for information for each connection made to the Fluid session. This interface can be extended
147
- * to provide additional information specific to each service.
185
+ * Base interface for information for each connection made to the Fluid session.
186
+ *
187
+ * @remarks This interface can be extended to provide additional information specific to each service.
188
+ * @public
148
189
  */
149
190
  export interface IConnection {
150
191
  /**
@@ -157,8 +198,10 @@ export interface IConnection {
157
198
  mode: "write" | "read";
158
199
  }
159
200
  /**
160
- * Base interface to be implemented to fetch each service's member. This interface can be extended by each service
161
- * to provide additional service-specific user metadata.
201
+ * Base interface to be implemented to fetch each service's member.
202
+ *
203
+ * @remarks This interface can be extended by each service to provide additional service-specific user metadata.
204
+ * @public
162
205
  */
163
206
  export interface IMember {
164
207
  /**
@@ -170,4 +213,11 @@ export interface IMember {
170
213
  */
171
214
  connections: IConnection[];
172
215
  }
216
+ /**
217
+ * An extended member object that includes currentConnection
218
+ * @public
219
+ */
220
+ export type Myself<M extends IMember = IMember> = M & {
221
+ currentConnection: string;
222
+ };
173
223
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"A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"}
@@ -9,14 +9,16 @@ exports.parseDataObjectsFromSharedObjects = exports.isSharedObjectClass = export
9
9
  * Runtime check to determine if a class is a DataObject type
10
10
  */
11
11
  const isDataObjectClass = (obj) => {
12
- return (obj === null || obj === void 0 ? void 0 : obj.factory) !== undefined;
12
+ const maybe = obj;
13
+ return (maybe?.factory?.IFluidDataStoreFactory !== undefined &&
14
+ maybe?.factory?.IFluidDataStoreFactory === maybe?.factory);
13
15
  };
14
16
  exports.isDataObjectClass = isDataObjectClass;
15
17
  /**
16
18
  * Runtime check to determine if a class is a SharedObject type
17
19
  */
18
20
  const isSharedObjectClass = (obj) => {
19
- return (obj === null || obj === void 0 ? void 0 : obj.getFactory) !== undefined;
21
+ return obj?.getFactory !== undefined;
20
22
  };
21
23
  exports.isSharedObjectClass = isSharedObjectClass;
22
24
  /**
@@ -25,7 +27,6 @@ exports.isSharedObjectClass = isSharedObjectClass;
25
27
  * of DataObject types and an array of SharedObjects.
26
28
  */
27
29
  const parseDataObjectsFromSharedObjects = (schema) => {
28
- var _a;
29
30
  const registryEntries = new Set();
30
31
  const sharedObjects = new Set();
31
32
  const tryAddObject = (obj) => {
@@ -33,10 +34,7 @@ const parseDataObjectsFromSharedObjects = (schema) => {
33
34
  sharedObjects.add(obj.getFactory());
34
35
  }
35
36
  else if ((0, exports.isDataObjectClass)(obj)) {
36
- registryEntries.add([
37
- obj.factory.type,
38
- Promise.resolve(obj.factory),
39
- ]);
37
+ registryEntries.add([obj.factory.type, Promise.resolve(obj.factory)]);
40
38
  }
41
39
  else {
42
40
  throw new Error(`Entry is neither a DataObject or a SharedObject`);
@@ -45,7 +43,7 @@ const parseDataObjectsFromSharedObjects = (schema) => {
45
43
  // Add the object types that will be initialized
46
44
  const dedupedObjects = new Set([
47
45
  ...Object.values(schema.initialObjects),
48
- ...((_a = schema.dynamicObjectTypes) !== null && _a !== void 0 ? _a : []),
46
+ ...(schema.dynamicObjectTypes ?? []),
49
47
  ]);
50
48
  dedupedObjects.forEach(tryAddObject);
51
49
  if (registryEntries.size === 0 && sharedObjects.size === 0) {
@@ -54,4 +52,4 @@ const parseDataObjectsFromSharedObjects = (schema) => {
54
52
  return [Array.from(registryEntries), Array.from(sharedObjects)];
55
53
  };
56
54
  exports.parseDataObjectsFromSharedObjects = parseDataObjectsFromSharedObjects;
57
- //# sourceMappingURL=utils.js.map
55
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAmBH;;GAEG;AACI,MAAM,iBAAiB,GAAG,CAAC,GAAQ,EAAkD,EAAE;IAC7F,MAAM,KAAK,GAAiE,GAAG,CAAC;IAChF,OAAO,CACN,KAAK,EAAE,OAAO,EAAE,sBAAsB,KAAK,SAAS;QACpD,KAAK,EAAE,OAAO,EAAE,sBAAsB,KAAK,KAAK,EAAE,OAAO,CACzD,CAAC;AACH,CAAC,CAAC;AANW,QAAA,iBAAiB,qBAM5B;AAEF;;GAEG;AACI,MAAM,mBAAmB,GAAG,CAAC,GAAQ,EAAiC,EAAE;IAC9E,OAAO,GAAG,EAAE,UAAU,KAAK,SAAS,CAAC;AACtC,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B;AAEF;;;;GAIG;AACI,MAAM,iCAAiC,GAAG,CAChD,MAAuB,EACmC,EAAE;IAC5D,MAAM,eAAe,GAAG,IAAI,GAAG,EAAoC,CAAC;IACpE,MAAM,aAAa,GAAG,IAAI,GAAG,EAAmB,CAAC;IAEjD,MAAM,YAAY,GAAG,CAAC,GAA6B,EAAE,EAAE;QACtD,IAAI,IAAA,2BAAmB,EAAC,GAAG,CAAC,EAAE;YAC7B,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC;SACpC;aAAM,IAAI,IAAA,yBAAiB,EAAC,GAAG,CAAC,EAAE;YAClC,eAAe,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;SACtE;aAAM;YACN,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;SACnE;IACF,CAAC,CAAC;IAEF,gDAAgD;IAChD,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;QAC9B,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC;QACvC,GAAG,CAAC,MAAM,CAAC,kBAAkB,IAAI,EAAE,CAAC;KACpC,CAAC,CAAC;IACH,cAAc,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAErC,IAAI,eAAe,CAAC,IAAI,KAAK,CAAC,IAAI,aAAa,CAAC,IAAI,KAAK,CAAC,EAAE;QAC3D,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;KACzE;IAED,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;AACjE,CAAC,CAAC;AA5BW,QAAA,iCAAiC,qCA4B5C","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IChannelFactory } from \"@fluidframework/datastore-definitions\";\nimport {\n\tIFluidDataStoreFactory,\n\tNamedFluidDataStoreRegistryEntry,\n} from \"@fluidframework/runtime-definitions\";\nimport { IFluidLoadable } from \"@fluidframework/core-interfaces\";\nimport { ContainerSchema, DataObjectClass, LoadableObjectClass, SharedObjectClass } from \"./types\";\n\n/**\n * An internal type used by the internal type guard isDataObjectClass to cast a\n * DataObjectClass to a type that is strongly coupled to IFluidDataStoreFactory.\n * Unlike the external and exported type DataObjectClass which is\n * weakly coupled to the IFluidDataStoreFactory to prevent leaking internals.\n */\nexport type InternalDataObjectClass<T extends IFluidLoadable> = DataObjectClass<T> &\n\tRecord<\"factory\", IFluidDataStoreFactory>;\n\n/**\n * Runtime check to determine if a class is a DataObject type\n */\nexport const isDataObjectClass = (obj: any): obj is InternalDataObjectClass<IFluidLoadable> => {\n\tconst maybe: Partial<InternalDataObjectClass<IFluidLoadable>> | undefined = obj;\n\treturn (\n\t\tmaybe?.factory?.IFluidDataStoreFactory !== undefined &&\n\t\tmaybe?.factory?.IFluidDataStoreFactory === maybe?.factory\n\t);\n};\n\n/**\n * Runtime check to determine if a class is a SharedObject type\n */\nexport const isSharedObjectClass = (obj: any): obj is SharedObjectClass<any> => {\n\treturn obj?.getFactory !== undefined;\n};\n\n/**\n * The ContainerSchema consists of initialObjects and dynamicObjectTypes. These types can be\n * of both SharedObject or DataObject. This function seperates the two and returns a registery\n * of DataObject types and an array of SharedObjects.\n */\nexport const parseDataObjectsFromSharedObjects = (\n\tschema: ContainerSchema,\n): [NamedFluidDataStoreRegistryEntry[], IChannelFactory[]] => {\n\tconst registryEntries = new Set<NamedFluidDataStoreRegistryEntry>();\n\tconst sharedObjects = new Set<IChannelFactory>();\n\n\tconst tryAddObject = (obj: LoadableObjectClass<any>) => {\n\t\tif (isSharedObjectClass(obj)) {\n\t\t\tsharedObjects.add(obj.getFactory());\n\t\t} else if (isDataObjectClass(obj)) {\n\t\t\tregistryEntries.add([obj.factory.type, Promise.resolve(obj.factory)]);\n\t\t} else {\n\t\t\tthrow new Error(`Entry is neither a DataObject or a SharedObject`);\n\t\t}\n\t};\n\n\t// Add the object types that will be initialized\n\tconst dedupedObjects = new Set([\n\t\t...Object.values(schema.initialObjects),\n\t\t...(schema.dynamicObjectTypes ?? []),\n\t]);\n\tdedupedObjects.forEach(tryAddObject);\n\n\tif (registryEntries.size === 0 && sharedObjects.size === 0) {\n\t\tthrow new Error(\"Container cannot be initialized without any DataTypes\");\n\t}\n\n\treturn [Array.from(registryEntries), Array.from(sharedObjects)];\n};\n"]}
package/dist/utils.d.ts CHANGED
@@ -3,12 +3,20 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { IChannelFactory } from "@fluidframework/datastore-definitions";
6
- import { NamedFluidDataStoreRegistryEntry } from "@fluidframework/runtime-definitions";
6
+ import { IFluidDataStoreFactory, NamedFluidDataStoreRegistryEntry } from "@fluidframework/runtime-definitions";
7
+ import { IFluidLoadable } from "@fluidframework/core-interfaces";
7
8
  import { ContainerSchema, DataObjectClass, SharedObjectClass } from "./types";
9
+ /**
10
+ * An internal type used by the internal type guard isDataObjectClass to cast a
11
+ * DataObjectClass to a type that is strongly coupled to IFluidDataStoreFactory.
12
+ * Unlike the external and exported type DataObjectClass which is
13
+ * weakly coupled to the IFluidDataStoreFactory to prevent leaking internals.
14
+ */
15
+ export type InternalDataObjectClass<T extends IFluidLoadable> = DataObjectClass<T> & Record<"factory", IFluidDataStoreFactory>;
8
16
  /**
9
17
  * Runtime check to determine if a class is a DataObject type
10
18
  */
11
- export declare const isDataObjectClass: (obj: any) => obj is DataObjectClass<any>;
19
+ export declare const isDataObjectClass: (obj: any) => obj is InternalDataObjectClass<IFluidLoadable>;
12
20
  /**
13
21
  * Runtime check to determine if a class is a SharedObject type
14
22
  */