@fluid-experimental/oldest-client-observer 2.0.0-internal.7.3.0 → 2.0.0-internal.7.4.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @fluid-experimental/oldest-client-observer
2
2
 
3
+ ## 2.0.0-internal.7.4.0
4
+
5
+ Dependency updates only.
6
+
3
7
  ## 2.0.0-internal.7.3.0
4
8
 
5
9
  Dependency updates only.
@@ -0,0 +1,13 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "../../../common/build/build-common/api-extractor-lint.json",
4
+ "messages": {
5
+ "extractorMessageReporting": {
6
+ // TODO: remove once base config has this enabled as an error
7
+ "ae-incompatible-release-tags": {
8
+ "logLevel": "error",
9
+ "addToApiReportFile": false
10
+ }
11
+ }
12
+ }
13
+ }
@@ -1,4 +1,12 @@
1
1
  {
2
2
  "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
- "extends": "@fluidframework/build-common/api-extractor-base.json"
3
+ "extends": "../../../common/build/build-common/api-extractor-base.json",
4
+ "messages": {
5
+ "extractorMessageReporting": {
6
+ // TODO: Add missing documentation and remove this rule override
7
+ "ae-undocumented": {
8
+ "logLevel": "none"
9
+ }
10
+ }
11
+ }
4
12
  }
@@ -10,7 +10,7 @@ import { IEventProvider } from '@fluidframework/core-interfaces';
10
10
  import { IQuorumClients } from '@fluidframework/protocol-definitions';
11
11
  import { TypedEventEmitter } from '@fluid-internal/client-utils';
12
12
 
13
- // @public
13
+ // @internal
14
14
  export interface IOldestClientObservable extends IEventProvider<IOldestClientObservableEvents> {
15
15
  // (undocumented)
16
16
  attachState: AttachState;
@@ -22,7 +22,7 @@ export interface IOldestClientObservable extends IEventProvider<IOldestClientObs
22
22
  getQuorum(): IQuorumClients;
23
23
  }
24
24
 
25
- // @public
25
+ // @internal
26
26
  export interface IOldestClientObservableEvents extends IEvent {
27
27
  // (undocumented)
28
28
  (event: "connected", listener: () => void): any;
@@ -30,19 +30,19 @@ export interface IOldestClientObservableEvents extends IEvent {
30
30
  (event: "disconnected", listener: () => void): any;
31
31
  }
32
32
 
33
- // @public (undocumented)
33
+ // @internal (undocumented)
34
34
  export interface IOldestClientObserver extends IEventProvider<IOldestClientObserverEvents> {
35
35
  // (undocumented)
36
36
  isOldest(): boolean;
37
37
  }
38
38
 
39
- // @public
39
+ // @internal
40
40
  export interface IOldestClientObserverEvents extends IEvent {
41
41
  // (undocumented)
42
42
  (event: "becameOldest" | "lostOldest", listener: () => void): any;
43
43
  }
44
44
 
45
- // @public
45
+ // @internal
46
46
  export class OldestClientObserver extends TypedEventEmitter<IOldestClientObserverEvents> implements IOldestClientObserver {
47
47
  constructor(observable: IOldestClientObservable);
48
48
  // (undocumented)
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.cjs","sourceRoot":"","sources":["../src/interfaces.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 } from \"@fluidframework/core-interfaces\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IQuorumClients } from \"@fluidframework/protocol-definitions\";\n\n/**\n * Events emitted by {@link IOldestClientObservable}.\n *\n * @public\n */\nexport interface IOldestClientObservableEvents extends IEvent {\n\t(event: \"connected\", listener: () => void);\n\t(event: \"disconnected\", listener: () => void);\n}\n\n/**\n * This is to make OldestClientObserver work with either a ContainerRuntime or an IFluidDataStoreRuntime\n * (both expose the relevant API surface and eventing). However, really this info probably shouldn't live on either,\n * since neither is really the source of truth (they are just the only currently-available plumbing options).\n * It's information about the connection, so the real source of truth is lower (at the connection layer).\n *\n * @public\n */\nexport interface IOldestClientObservable extends IEventProvider<IOldestClientObservableEvents> {\n\tgetQuorum(): IQuorumClients;\n\t// Generic usage of attachState is a little unusual here. We will treat ourselves as \"the oldest client that\n\t// has information about this [container | data store]\", which in the case of detached data store may disagree\n\t// with whether we're the oldest client on the connected container. So in the data store case, it's only\n\t// safe use this as an indicator about rights to tasks performed against this specific data store, and not\n\t// more broadly.\n\tattachState: AttachState;\n\tconnected: boolean;\n\tclientId: string | undefined;\n}\n\n/**\n * Events emitted by {@link IOldestClientObservable}.\n *\n * @public\n */\nexport interface IOldestClientObserverEvents extends IEvent {\n\t(event: \"becameOldest\" | \"lostOldest\", listener: () => void);\n}\n\n/**\n * @public\n */\nexport interface IOldestClientObserver extends IEventProvider<IOldestClientObserverEvents> {\n\tisOldest(): boolean;\n}\n"]}
1
+ {"version":3,"file":"interfaces.cjs","sourceRoot":"","sources":["../src/interfaces.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 } from \"@fluidframework/core-interfaces\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IQuorumClients } from \"@fluidframework/protocol-definitions\";\n\n/**\n * Events emitted by {@link IOldestClientObservable}.\n * @internal\n */\nexport interface IOldestClientObservableEvents extends IEvent {\n\t(event: \"connected\", listener: () => void);\n\t(event: \"disconnected\", listener: () => void);\n}\n\n/**\n * This is to make OldestClientObserver work with either a ContainerRuntime or an IFluidDataStoreRuntime\n * (both expose the relevant API surface and eventing). However, really this info probably shouldn't live on either,\n * since neither is really the source of truth (they are just the only currently-available plumbing options).\n * It's information about the connection, so the real source of truth is lower (at the connection layer).\n * @internal\n */\nexport interface IOldestClientObservable extends IEventProvider<IOldestClientObservableEvents> {\n\tgetQuorum(): IQuorumClients;\n\t// Generic usage of attachState is a little unusual here. We will treat ourselves as \"the oldest client that\n\t// has information about this [container | data store]\", which in the case of detached data store may disagree\n\t// with whether we're the oldest client on the connected container. So in the data store case, it's only\n\t// safe use this as an indicator about rights to tasks performed against this specific data store, and not\n\t// more broadly.\n\tattachState: AttachState;\n\tconnected: boolean;\n\tclientId: string | undefined;\n}\n\n/**\n * Events emitted by {@link IOldestClientObservable}.\n * @internal\n */\nexport interface IOldestClientObserverEvents extends IEvent {\n\t(event: \"becameOldest\" | \"lostOldest\", listener: () => void);\n}\n\n/**\n * @internal\n */\nexport interface IOldestClientObserver extends IEventProvider<IOldestClientObserverEvents> {\n\tisOldest(): boolean;\n}\n"]}
@@ -7,8 +7,7 @@ import { AttachState } from "@fluidframework/container-definitions";
7
7
  import { IQuorumClients } from "@fluidframework/protocol-definitions";
8
8
  /**
9
9
  * Events emitted by {@link IOldestClientObservable}.
10
- *
11
- * @public
10
+ * @internal
12
11
  */
13
12
  export interface IOldestClientObservableEvents extends IEvent {
14
13
  (event: "connected", listener: () => void): any;
@@ -19,8 +18,7 @@ export interface IOldestClientObservableEvents extends IEvent {
19
18
  * (both expose the relevant API surface and eventing). However, really this info probably shouldn't live on either,
20
19
  * since neither is really the source of truth (they are just the only currently-available plumbing options).
21
20
  * It's information about the connection, so the real source of truth is lower (at the connection layer).
22
- *
23
- * @public
21
+ * @internal
24
22
  */
25
23
  export interface IOldestClientObservable extends IEventProvider<IOldestClientObservableEvents> {
26
24
  getQuorum(): IQuorumClients;
@@ -30,14 +28,13 @@ export interface IOldestClientObservable extends IEventProvider<IOldestClientObs
30
28
  }
31
29
  /**
32
30
  * Events emitted by {@link IOldestClientObservable}.
33
- *
34
- * @public
31
+ * @internal
35
32
  */
36
33
  export interface IOldestClientObserverEvents extends IEvent {
37
34
  (event: "becameOldest" | "lostOldest", listener: () => void): any;
38
35
  }
39
36
  /**
40
- * @public
37
+ * @internal
41
38
  */
42
39
  export interface IOldestClientObserver extends IEventProvider<IOldestClientObserverEvents> {
43
40
  isOldest(): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAEtE;;;;GAIG;AACH,MAAM,WAAW,6BAA8B,SAAQ,MAAM;IAC5D,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;IAC3C,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;CAC9C;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,uBAAwB,SAAQ,cAAc,CAAC,6BAA6B,CAAC;IAC7F,SAAS,IAAI,cAAc,CAAC;IAM5B,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,WAAW,2BAA4B,SAAQ,MAAM;IAC1D,CAAC,KAAK,EAAE,cAAc,GAAG,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;CAC7D;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,cAAc,CAAC,2BAA2B,CAAC;IACzF,QAAQ,IAAI,OAAO,CAAC;CACpB"}
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAEtE;;;GAGG;AACH,MAAM,WAAW,6BAA8B,SAAQ,MAAM;IAC5D,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;IAC3C,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;CAC9C;AAED;;;;;;GAMG;AACH,MAAM,WAAW,uBAAwB,SAAQ,cAAc,CAAC,6BAA6B,CAAC;IAC7F,SAAS,IAAI,cAAc,CAAC;IAM5B,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,2BAA4B,SAAQ,MAAM;IAC1D,CAAC,KAAK,EAAE,cAAc,GAAG,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;CAC7D;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,cAAc,CAAC,2BAA2B,CAAC;IACzF,QAAQ,IAAI,OAAO,CAAC;CACpB"}
@@ -0,0 +1,17 @@
1
+ import { AttachState } from '@fluidframework/container-definitions';
2
+ import { IEvent } from '@fluidframework/core-interfaces';
3
+ import { IEventProvider } from '@fluidframework/core-interfaces';
4
+ import { IQuorumClients } from '@fluidframework/protocol-definitions';
5
+ import { TypedEventEmitter } from '@fluid-internal/client-utils';
6
+
7
+ /* Excluded from this release type: IOldestClientObservable */
8
+
9
+ /* Excluded from this release type: IOldestClientObservableEvents */
10
+
11
+ /* Excluded from this release type: IOldestClientObserver */
12
+
13
+ /* Excluded from this release type: IOldestClientObserverEvents */
14
+
15
+ /* Excluded from this release type: OldestClientObserver */
16
+
17
+ export { }
@@ -0,0 +1,25 @@
1
+ import { AttachState } from '@fluidframework/container-definitions';
2
+ import { IEvent } from '@fluidframework/core-interfaces';
3
+ import { IEventProvider } from '@fluidframework/core-interfaces';
4
+ import { IQuorumClients } from '@fluidframework/protocol-definitions';
5
+ import { TypedEventEmitter } from '@fluid-internal/client-utils';
6
+
7
+ /* Excluded from this release type: AttachState */
8
+
9
+ /* Excluded from this release type: IEvent */
10
+
11
+ /* Excluded from this release type: IEventProvider */
12
+
13
+ /* Excluded from this release type: IOldestClientObservable */
14
+
15
+ /* Excluded from this release type: IOldestClientObservableEvents */
16
+
17
+ /* Excluded from this release type: IOldestClientObserver */
18
+
19
+ /* Excluded from this release type: IOldestClientObserverEvents */
20
+
21
+ /* Excluded from this release type: OldestClientObserver */
22
+
23
+ /* Excluded from this release type: TypedEventEmitter */
24
+
25
+ export { }
@@ -0,0 +1,25 @@
1
+ import { AttachState } from '@fluidframework/container-definitions';
2
+ import { IEvent } from '@fluidframework/core-interfaces';
3
+ import { IEventProvider } from '@fluidframework/core-interfaces';
4
+ import { IQuorumClients } from '@fluidframework/protocol-definitions';
5
+ import { TypedEventEmitter } from '@fluid-internal/client-utils';
6
+
7
+ /* Excluded from this release type: AttachState */
8
+
9
+ /* Excluded from this release type: IEvent */
10
+
11
+ /* Excluded from this release type: IEventProvider */
12
+
13
+ /* Excluded from this release type: IOldestClientObservable */
14
+
15
+ /* Excluded from this release type: IOldestClientObservableEvents */
16
+
17
+ /* Excluded from this release type: IOldestClientObserver */
18
+
19
+ /* Excluded from this release type: IOldestClientObserverEvents */
20
+
21
+ /* Excluded from this release type: OldestClientObserver */
22
+
23
+ /* Excluded from this release type: TypedEventEmitter */
24
+
25
+ export { }
@@ -0,0 +1,111 @@
1
+ import { AttachState } from '@fluidframework/container-definitions';
2
+ import { IEvent } from '@fluidframework/core-interfaces';
3
+ import { IEventProvider } from '@fluidframework/core-interfaces';
4
+ import { IQuorumClients } from '@fluidframework/protocol-definitions';
5
+ import { TypedEventEmitter } from '@fluid-internal/client-utils';
6
+
7
+ /**
8
+ * This is to make OldestClientObserver work with either a ContainerRuntime or an IFluidDataStoreRuntime
9
+ * (both expose the relevant API surface and eventing). However, really this info probably shouldn't live on either,
10
+ * since neither is really the source of truth (they are just the only currently-available plumbing options).
11
+ * It's information about the connection, so the real source of truth is lower (at the connection layer).
12
+ * @internal
13
+ */
14
+ export declare interface IOldestClientObservable extends IEventProvider<IOldestClientObservableEvents> {
15
+ getQuorum(): IQuorumClients;
16
+ attachState: AttachState;
17
+ connected: boolean;
18
+ clientId: string | undefined;
19
+ }
20
+
21
+ /**
22
+ * Events emitted by {@link IOldestClientObservable}.
23
+ * @internal
24
+ */
25
+ export declare interface IOldestClientObservableEvents extends IEvent {
26
+ (event: "connected", listener: () => void): any;
27
+ (event: "disconnected", listener: () => void): any;
28
+ }
29
+
30
+ /**
31
+ * @internal
32
+ */
33
+ export declare interface IOldestClientObserver extends IEventProvider<IOldestClientObserverEvents> {
34
+ isOldest(): boolean;
35
+ }
36
+
37
+ /**
38
+ * Events emitted by {@link IOldestClientObservable}.
39
+ * @internal
40
+ */
41
+ export declare interface IOldestClientObserverEvents extends IEvent {
42
+ (event: "becameOldest" | "lostOldest", listener: () => void): any;
43
+ }
44
+
45
+ /**
46
+ * The `OldestClientObserver` is a utility inspect if the local client is the oldest amongst connected clients (in
47
+ * terms of when they connected) and watch for changes.
48
+ *
49
+ * It is still experimental and under development. Please do try it out, but expect breaking changes in the future.
50
+ *
51
+ * @remarks
52
+ * ### Creation
53
+ *
54
+ * The `OldestClientObserver` constructor takes an `IOldestClientObservable`. This is most easily satisfied with
55
+ * either an `IContainerRuntime` or an `IFluidDataStoreRuntime`:
56
+ *
57
+ * ```typescript
58
+ * // E.g. from within a BaseContainerRuntimeFactory:
59
+ * protected async containerHasInitialized(runtime: IContainerRuntime) {
60
+ * const oldestClientObserver = new OldestClientObserver(runtime);
61
+ * // ...
62
+ * }
63
+ * ```
64
+ *
65
+ * ```typescript
66
+ * // From within a DataObject
67
+ * protected async hasInitialized() {
68
+ * const oldestClientObserver = new OldestClientObserver(this.runtime);
69
+ * // ...
70
+ * }
71
+ * ```
72
+ *
73
+ * ### Usage
74
+ *
75
+ * To check if the local client is the oldest, use the `isOldest()` method.
76
+ *
77
+ * ```typescript
78
+ * if (oldestClientObserver.isOldest()) {
79
+ * console.log("I'm the oldest");
80
+ * } else {
81
+ * console.log("Someone else is older");
82
+ * }
83
+ * ```
84
+ *
85
+ * ### Eventing
86
+ *
87
+ * `OldestClientObserver` is an `EventEmitter`, and will emit events when the local client becomes the oldest and when
88
+ * it is no longer the oldest.
89
+ *
90
+ * ```typescript
91
+ * oldestClientObserver.on("becameOldest", () => {
92
+ * console.log("I'm the oldest now");
93
+ * });
94
+ *
95
+ * oldestClientObserver.on("lostOldest", () => {
96
+ * console.log("I'm not the oldest anymore");
97
+ * });
98
+ * ```
99
+ * @internal
100
+ */
101
+ export declare class OldestClientObserver extends TypedEventEmitter<IOldestClientObserverEvents> implements IOldestClientObserver {
102
+ private readonly observable;
103
+ private readonly quorum;
104
+ private currentIsOldest;
105
+ constructor(observable: IOldestClientObservable);
106
+ isOldest(): boolean;
107
+ private readonly updateOldest;
108
+ private computeIsOldest;
109
+ }
110
+
111
+ export { }
@@ -62,8 +62,7 @@ const container_definitions_1 = require("@fluidframework/container-definitions")
62
62
  * console.log("I'm not the oldest anymore");
63
63
  * });
64
64
  * ```
65
- *
66
- * @public
65
+ * @internal
67
66
  */
68
67
  class OldestClientObserver extends client_utils_1.TypedEventEmitter {
69
68
  constructor(observable) {
@@ -1 +1 @@
1
- {"version":3,"file":"oldestClientObserver.cjs","sourceRoot":"","sources":["../src/oldestClientObserver.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAiE;AACjE,2DAAoD;AACpD,iFAAoE;AAQpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,MAAa,oBACZ,SAAQ,gCAA8C;IAKtD,YAA6B,UAAmC;QAC/D,KAAK,EAAE,CAAC;QADoB,eAAU,GAAV,UAAU,CAAyB;QADxD,oBAAe,GAAY,KAAK,CAAC;QAexB,iBAAY,GAAG,GAAS,EAAE;YAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;YACtC,IAAI,IAAI,CAAC,eAAe,KAAK,MAAM,EAAE;gBACpC,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC;gBAC9B,IAAI,MAAM,EAAE;oBACX,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;iBAC1B;qBAAM;oBACN,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;iBACxB;aACD;QACF,CAAC,CAAC;QAtBD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;QAC1C,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAClD,UAAU,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC9C,UAAU,CAAC,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAClD,CAAC;IAEM,QAAQ;QACd,OAAO,IAAI,CAAC,eAAe,CAAC;IAC7B,CAAC;IAcO,eAAe;QACtB,uGAAuG;QACvG,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,KAAK,mCAAW,CAAC,QAAQ,EAAE;YACzD,OAAO,IAAI,CAAC;SACZ;QAED,kEAAkE;QAClE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE;YAC/B,OAAO,KAAK,CAAC;SACb;QAED,yDAAyD;QACzD,IAAA,mBAAM,EACL,IAAI,CAAC,UAAU,CAAC,QAAQ,KAAK,SAAS;QACtC,4DAA4D;QAC5D,KAAK,CAAC,4CAA4C,CAClD,CAAC;QAEF,MAAM,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC5E,wEAAwE;QACxE,IAAI,mBAAmB,KAAK,SAAS,EAAE;YACtC,OAAO,KAAK,CAAC;SACb;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACzC,KAAK,MAAM,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE;YAC/C,IAAI,eAAe,CAAC,cAAc,GAAG,mBAAmB,CAAC,cAAc,EAAE;gBACxE,OAAO,KAAK,CAAC;aACb;SACD;QAED,oCAAoC;QACpC,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAlED,oDAkEC","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 { assert } from \"@fluidframework/core-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IQuorumClients } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIOldestClientObservable,\n\tIOldestClientObserverEvents,\n\tIOldestClientObserver,\n} from \"./interfaces\";\n\n/**\n * The `OldestClientObserver` is a utility inspect if the local client is the oldest amongst connected clients (in\n * terms of when they connected) and watch for changes.\n *\n * It is still experimental and under development. Please do try it out, but expect breaking changes in the future.\n *\n * @remarks\n * ### Creation\n *\n * The `OldestClientObserver` constructor takes an `IOldestClientObservable`. This is most easily satisfied with\n * either an `IContainerRuntime` or an `IFluidDataStoreRuntime`:\n *\n * ```typescript\n * // E.g. from within a BaseContainerRuntimeFactory:\n * protected async containerHasInitialized(runtime: IContainerRuntime) {\n * const oldestClientObserver = new OldestClientObserver(runtime);\n * // ...\n * }\n * ```\n *\n * ```typescript\n * // From within a DataObject\n * protected async hasInitialized() {\n * const oldestClientObserver = new OldestClientObserver(this.runtime);\n * // ...\n * }\n * ```\n *\n * ### Usage\n *\n * To check if the local client is the oldest, use the `isOldest()` method.\n *\n * ```typescript\n * if (oldestClientObserver.isOldest()) {\n * console.log(\"I'm the oldest\");\n * } else {\n * console.log(\"Someone else is older\");\n * }\n * ```\n *\n * ### Eventing\n *\n * `OldestClientObserver` is an `EventEmitter`, and will emit events when the local client becomes the oldest and when\n * it is no longer the oldest.\n *\n * ```typescript\n * oldestClientObserver.on(\"becameOldest\", () => {\n * console.log(\"I'm the oldest now\");\n * });\n *\n * oldestClientObserver.on(\"lostOldest\", () => {\n * console.log(\"I'm not the oldest anymore\");\n * });\n * ```\n *\n * @public\n */\nexport class OldestClientObserver\n\textends TypedEventEmitter<IOldestClientObserverEvents>\n\timplements IOldestClientObserver\n{\n\tprivate readonly quorum: IQuorumClients;\n\tprivate currentIsOldest: boolean = false;\n\tconstructor(private readonly observable: IOldestClientObservable) {\n\t\tsuper();\n\t\tthis.quorum = this.observable.getQuorum();\n\t\tthis.currentIsOldest = this.computeIsOldest();\n\t\tthis.quorum.on(\"addMember\", this.updateOldest);\n\t\tthis.quorum.on(\"removeMember\", this.updateOldest);\n\t\tobservable.on(\"connected\", this.updateOldest);\n\t\tobservable.on(\"disconnected\", this.updateOldest);\n\t}\n\n\tpublic isOldest(): boolean {\n\t\treturn this.currentIsOldest;\n\t}\n\n\tprivate readonly updateOldest = (): void => {\n\t\tconst oldest = this.computeIsOldest();\n\t\tif (this.currentIsOldest !== oldest) {\n\t\t\tthis.currentIsOldest = oldest;\n\t\t\tif (oldest) {\n\t\t\t\tthis.emit(\"becameOldest\");\n\t\t\t} else {\n\t\t\t\tthis.emit(\"lostOldest\");\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate computeIsOldest(): boolean {\n\t\t// If the container is detached, we are the only ones that know about it and are the oldest by default.\n\t\tif (this.observable.attachState === AttachState.Detached) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// If we're not connected we can't be the oldest connected client.\n\t\tif (!this.observable.connected) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// TODO: Clean up error code linter violations repo-wide.\n\t\tassert(\n\t\t\tthis.observable.clientId !== undefined,\n\t\t\t// eslint-disable-next-line unicorn/numeric-separators-style\n\t\t\t0x1da /* \"Client id should be set if connected\" */,\n\t\t);\n\n\t\tconst selfSequencedClient = this.quorum.getMember(this.observable.clientId);\n\t\t// When in readonly mode our clientId will not be present in the quorum.\n\t\tif (selfSequencedClient === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst members = this.quorum.getMembers();\n\t\tfor (const sequencedClient of members.values()) {\n\t\t\tif (sequencedClient.sequenceNumber < selfSequencedClient.sequenceNumber) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\t// No member of the quorum was older\n\t\treturn true;\n\t}\n}\n"]}
1
+ {"version":3,"file":"oldestClientObserver.cjs","sourceRoot":"","sources":["../src/oldestClientObserver.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAiE;AACjE,2DAAoD;AACpD,iFAAoE;AAQpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,MAAa,oBACZ,SAAQ,gCAA8C;IAKtD,YAA6B,UAAmC;QAC/D,KAAK,EAAE,CAAC;QADoB,eAAU,GAAV,UAAU,CAAyB;QADxD,oBAAe,GAAY,KAAK,CAAC;QAexB,iBAAY,GAAG,GAAS,EAAE;YAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;YACtC,IAAI,IAAI,CAAC,eAAe,KAAK,MAAM,EAAE;gBACpC,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC;gBAC9B,IAAI,MAAM,EAAE;oBACX,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;iBAC1B;qBAAM;oBACN,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;iBACxB;aACD;QACF,CAAC,CAAC;QAtBD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;QAC1C,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAClD,UAAU,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC9C,UAAU,CAAC,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAClD,CAAC;IAEM,QAAQ;QACd,OAAO,IAAI,CAAC,eAAe,CAAC;IAC7B,CAAC;IAcO,eAAe;QACtB,uGAAuG;QACvG,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,KAAK,mCAAW,CAAC,QAAQ,EAAE;YACzD,OAAO,IAAI,CAAC;SACZ;QAED,kEAAkE;QAClE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE;YAC/B,OAAO,KAAK,CAAC;SACb;QAED,yDAAyD;QACzD,IAAA,mBAAM,EACL,IAAI,CAAC,UAAU,CAAC,QAAQ,KAAK,SAAS;QACtC,4DAA4D;QAC5D,KAAK,CAAC,4CAA4C,CAClD,CAAC;QAEF,MAAM,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC5E,wEAAwE;QACxE,IAAI,mBAAmB,KAAK,SAAS,EAAE;YACtC,OAAO,KAAK,CAAC;SACb;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACzC,KAAK,MAAM,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE;YAC/C,IAAI,eAAe,CAAC,cAAc,GAAG,mBAAmB,CAAC,cAAc,EAAE;gBACxE,OAAO,KAAK,CAAC;aACb;SACD;QAED,oCAAoC;QACpC,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAlED,oDAkEC","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 { assert } from \"@fluidframework/core-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IQuorumClients } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIOldestClientObservable,\n\tIOldestClientObserverEvents,\n\tIOldestClientObserver,\n} from \"./interfaces\";\n\n/**\n * The `OldestClientObserver` is a utility inspect if the local client is the oldest amongst connected clients (in\n * terms of when they connected) and watch for changes.\n *\n * It is still experimental and under development. Please do try it out, but expect breaking changes in the future.\n *\n * @remarks\n * ### Creation\n *\n * The `OldestClientObserver` constructor takes an `IOldestClientObservable`. This is most easily satisfied with\n * either an `IContainerRuntime` or an `IFluidDataStoreRuntime`:\n *\n * ```typescript\n * // E.g. from within a BaseContainerRuntimeFactory:\n * protected async containerHasInitialized(runtime: IContainerRuntime) {\n * const oldestClientObserver = new OldestClientObserver(runtime);\n * // ...\n * }\n * ```\n *\n * ```typescript\n * // From within a DataObject\n * protected async hasInitialized() {\n * const oldestClientObserver = new OldestClientObserver(this.runtime);\n * // ...\n * }\n * ```\n *\n * ### Usage\n *\n * To check if the local client is the oldest, use the `isOldest()` method.\n *\n * ```typescript\n * if (oldestClientObserver.isOldest()) {\n * console.log(\"I'm the oldest\");\n * } else {\n * console.log(\"Someone else is older\");\n * }\n * ```\n *\n * ### Eventing\n *\n * `OldestClientObserver` is an `EventEmitter`, and will emit events when the local client becomes the oldest and when\n * it is no longer the oldest.\n *\n * ```typescript\n * oldestClientObserver.on(\"becameOldest\", () => {\n * console.log(\"I'm the oldest now\");\n * });\n *\n * oldestClientObserver.on(\"lostOldest\", () => {\n * console.log(\"I'm not the oldest anymore\");\n * });\n * ```\n * @internal\n */\nexport class OldestClientObserver\n\textends TypedEventEmitter<IOldestClientObserverEvents>\n\timplements IOldestClientObserver\n{\n\tprivate readonly quorum: IQuorumClients;\n\tprivate currentIsOldest: boolean = false;\n\tconstructor(private readonly observable: IOldestClientObservable) {\n\t\tsuper();\n\t\tthis.quorum = this.observable.getQuorum();\n\t\tthis.currentIsOldest = this.computeIsOldest();\n\t\tthis.quorum.on(\"addMember\", this.updateOldest);\n\t\tthis.quorum.on(\"removeMember\", this.updateOldest);\n\t\tobservable.on(\"connected\", this.updateOldest);\n\t\tobservable.on(\"disconnected\", this.updateOldest);\n\t}\n\n\tpublic isOldest(): boolean {\n\t\treturn this.currentIsOldest;\n\t}\n\n\tprivate readonly updateOldest = (): void => {\n\t\tconst oldest = this.computeIsOldest();\n\t\tif (this.currentIsOldest !== oldest) {\n\t\t\tthis.currentIsOldest = oldest;\n\t\t\tif (oldest) {\n\t\t\t\tthis.emit(\"becameOldest\");\n\t\t\t} else {\n\t\t\t\tthis.emit(\"lostOldest\");\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate computeIsOldest(): boolean {\n\t\t// If the container is detached, we are the only ones that know about it and are the oldest by default.\n\t\tif (this.observable.attachState === AttachState.Detached) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// If we're not connected we can't be the oldest connected client.\n\t\tif (!this.observable.connected) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// TODO: Clean up error code linter violations repo-wide.\n\t\tassert(\n\t\t\tthis.observable.clientId !== undefined,\n\t\t\t// eslint-disable-next-line unicorn/numeric-separators-style\n\t\t\t0x1da /* \"Client id should be set if connected\" */,\n\t\t);\n\n\t\tconst selfSequencedClient = this.quorum.getMember(this.observable.clientId);\n\t\t// When in readonly mode our clientId will not be present in the quorum.\n\t\tif (selfSequencedClient === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst members = this.quorum.getMembers();\n\t\tfor (const sequencedClient of members.values()) {\n\t\t\tif (sequencedClient.sequenceNumber < selfSequencedClient.sequenceNumber) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\t// No member of the quorum was older\n\t\treturn true;\n\t}\n}\n"]}
@@ -58,8 +58,7 @@ import { IOldestClientObservable, IOldestClientObserverEvents, IOldestClientObse
58
58
  * console.log("I'm not the oldest anymore");
59
59
  * });
60
60
  * ```
61
- *
62
- * @public
61
+ * @internal
63
62
  */
64
63
  export declare class OldestClientObserver extends TypedEventEmitter<IOldestClientObserverEvents> implements IOldestClientObserver {
65
64
  private readonly observable;
@@ -1 +1 @@
1
- {"version":3,"file":"oldestClientObserver.d.ts","sourceRoot":"","sources":["../src/oldestClientObserver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAIjE,OAAO,EACN,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,EACrB,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,qBAAa,oBACZ,SAAQ,iBAAiB,CAAC,2BAA2B,CACrD,YAAW,qBAAqB;IAIpB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAFvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,eAAe,CAAkB;gBACZ,UAAU,EAAE,uBAAuB;IAUzD,QAAQ,IAAI,OAAO;IAI1B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAU3B;IAEF,OAAO,CAAC,eAAe;CAkCvB"}
1
+ {"version":3,"file":"oldestClientObserver.d.ts","sourceRoot":"","sources":["../src/oldestClientObserver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAIjE,OAAO,EACN,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,EACrB,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,qBAAa,oBACZ,SAAQ,iBAAiB,CAAC,2BAA2B,CACrD,YAAW,qBAAqB;IAIpB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAFvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,eAAe,CAAkB;gBACZ,UAAU,EAAE,uBAAuB;IAUzD,QAAQ,IAAI,OAAO;IAI1B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAU3B;IAEF,OAAO,CAAC,eAAe;CAkCvB"}
package/lib/index.d.ts CHANGED
@@ -2,6 +2,6 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- export { IOldestClientObservable, IOldestClientObservableEvents, IOldestClientObserver, IOldestClientObserverEvents, } from "./interfaces";
6
- export { OldestClientObserver } from "./oldestClientObserver";
5
+ export { IOldestClientObservable, IOldestClientObservableEvents, IOldestClientObserver, IOldestClientObserverEvents, } from "./interfaces.mjs";
6
+ export { OldestClientObserver } from "./oldestClientObserver.mjs";
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,uBAAuB,EACvB,6BAA6B,EAC7B,qBAAqB,EACrB,2BAA2B,GAC3B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EACN,uBAAuB,EACvB,6BAA6B,EAC7B,qBAAqB,EACrB,2BAA2B,GAC3B;OACM,EAAE,oBAAoB,EAAE"}
@@ -7,8 +7,7 @@ import { AttachState } from "@fluidframework/container-definitions";
7
7
  import { IQuorumClients } from "@fluidframework/protocol-definitions";
8
8
  /**
9
9
  * Events emitted by {@link IOldestClientObservable}.
10
- *
11
- * @public
10
+ * @internal
12
11
  */
13
12
  export interface IOldestClientObservableEvents extends IEvent {
14
13
  (event: "connected", listener: () => void): any;
@@ -19,8 +18,7 @@ export interface IOldestClientObservableEvents extends IEvent {
19
18
  * (both expose the relevant API surface and eventing). However, really this info probably shouldn't live on either,
20
19
  * since neither is really the source of truth (they are just the only currently-available plumbing options).
21
20
  * It's information about the connection, so the real source of truth is lower (at the connection layer).
22
- *
23
- * @public
21
+ * @internal
24
22
  */
25
23
  export interface IOldestClientObservable extends IEventProvider<IOldestClientObservableEvents> {
26
24
  getQuorum(): IQuorumClients;
@@ -30,14 +28,13 @@ export interface IOldestClientObservable extends IEventProvider<IOldestClientObs
30
28
  }
31
29
  /**
32
30
  * Events emitted by {@link IOldestClientObservable}.
33
- *
34
- * @public
31
+ * @internal
35
32
  */
36
33
  export interface IOldestClientObserverEvents extends IEvent {
37
34
  (event: "becameOldest" | "lostOldest", listener: () => void): any;
38
35
  }
39
36
  /**
40
- * @public
37
+ * @internal
41
38
  */
42
39
  export interface IOldestClientObserver extends IEventProvider<IOldestClientObserverEvents> {
43
40
  isOldest(): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAEtE;;;;GAIG;AACH,MAAM,WAAW,6BAA8B,SAAQ,MAAM;IAC5D,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;IAC3C,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;CAC9C;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,uBAAwB,SAAQ,cAAc,CAAC,6BAA6B,CAAC;IAC7F,SAAS,IAAI,cAAc,CAAC;IAM5B,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,WAAW,2BAA4B,SAAQ,MAAM;IAC1D,CAAC,KAAK,EAAE,cAAc,GAAG,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;CAC7D;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,cAAc,CAAC,2BAA2B,CAAC;IACzF,QAAQ,IAAI,OAAO,CAAC;CACpB"}
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,iCAAiC;OACjE,EAAE,WAAW,EAAE,MAAM,uCAAuC;OAC5D,EAAE,cAAc,EAAE,MAAM,sCAAsC;AAErE;;;GAGG;AACH,MAAM,WAAW,6BAA8B,SAAQ,MAAM;IAC5D,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;IAC3C,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;CAC9C;AAED;;;;;;GAMG;AACH,MAAM,WAAW,uBAAwB,SAAQ,cAAc,CAAC,6BAA6B,CAAC;IAC7F,SAAS,IAAI,cAAc,CAAC;IAM5B,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,2BAA4B,SAAQ,MAAM;IAC1D,CAAC,KAAK,EAAE,cAAc,GAAG,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;CAC7D;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,cAAc,CAAC,2BAA2B,CAAC;IACzF,QAAQ,IAAI,OAAO,CAAC;CACpB"}
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.mjs","sourceRoot":"","sources":["../src/interfaces.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 } from \"@fluidframework/core-interfaces\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IQuorumClients } from \"@fluidframework/protocol-definitions\";\n\n/**\n * Events emitted by {@link IOldestClientObservable}.\n *\n * @public\n */\nexport interface IOldestClientObservableEvents extends IEvent {\n\t(event: \"connected\", listener: () => void);\n\t(event: \"disconnected\", listener: () => void);\n}\n\n/**\n * This is to make OldestClientObserver work with either a ContainerRuntime or an IFluidDataStoreRuntime\n * (both expose the relevant API surface and eventing). However, really this info probably shouldn't live on either,\n * since neither is really the source of truth (they are just the only currently-available plumbing options).\n * It's information about the connection, so the real source of truth is lower (at the connection layer).\n *\n * @public\n */\nexport interface IOldestClientObservable extends IEventProvider<IOldestClientObservableEvents> {\n\tgetQuorum(): IQuorumClients;\n\t// Generic usage of attachState is a little unusual here. We will treat ourselves as \"the oldest client that\n\t// has information about this [container | data store]\", which in the case of detached data store may disagree\n\t// with whether we're the oldest client on the connected container. So in the data store case, it's only\n\t// safe use this as an indicator about rights to tasks performed against this specific data store, and not\n\t// more broadly.\n\tattachState: AttachState;\n\tconnected: boolean;\n\tclientId: string | undefined;\n}\n\n/**\n * Events emitted by {@link IOldestClientObservable}.\n *\n * @public\n */\nexport interface IOldestClientObserverEvents extends IEvent {\n\t(event: \"becameOldest\" | \"lostOldest\", listener: () => void);\n}\n\n/**\n * @public\n */\nexport interface IOldestClientObserver extends IEventProvider<IOldestClientObserverEvents> {\n\tisOldest(): boolean;\n}\n"]}
1
+ {"version":3,"file":"interfaces.mjs","sourceRoot":"","sources":["../src/interfaces.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 } from \"@fluidframework/core-interfaces\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IQuorumClients } from \"@fluidframework/protocol-definitions\";\n\n/**\n * Events emitted by {@link IOldestClientObservable}.\n * @internal\n */\nexport interface IOldestClientObservableEvents extends IEvent {\n\t(event: \"connected\", listener: () => void);\n\t(event: \"disconnected\", listener: () => void);\n}\n\n/**\n * This is to make OldestClientObserver work with either a ContainerRuntime or an IFluidDataStoreRuntime\n * (both expose the relevant API surface and eventing). However, really this info probably shouldn't live on either,\n * since neither is really the source of truth (they are just the only currently-available plumbing options).\n * It's information about the connection, so the real source of truth is lower (at the connection layer).\n * @internal\n */\nexport interface IOldestClientObservable extends IEventProvider<IOldestClientObservableEvents> {\n\tgetQuorum(): IQuorumClients;\n\t// Generic usage of attachState is a little unusual here. We will treat ourselves as \"the oldest client that\n\t// has information about this [container | data store]\", which in the case of detached data store may disagree\n\t// with whether we're the oldest client on the connected container. So in the data store case, it's only\n\t// safe use this as an indicator about rights to tasks performed against this specific data store, and not\n\t// more broadly.\n\tattachState: AttachState;\n\tconnected: boolean;\n\tclientId: string | undefined;\n}\n\n/**\n * Events emitted by {@link IOldestClientObservable}.\n * @internal\n */\nexport interface IOldestClientObserverEvents extends IEvent {\n\t(event: \"becameOldest\" | \"lostOldest\", listener: () => void);\n}\n\n/**\n * @internal\n */\nexport interface IOldestClientObserver extends IEventProvider<IOldestClientObserverEvents> {\n\tisOldest(): boolean;\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import { AttachState } from '@fluidframework/container-definitions';
2
+ import { IEvent } from '@fluidframework/core-interfaces';
3
+ import { IEventProvider } from '@fluidframework/core-interfaces';
4
+ import { IQuorumClients } from '@fluidframework/protocol-definitions';
5
+ import { TypedEventEmitter } from '@fluid-internal/client-utils';
6
+
7
+ /* Excluded from this release type: IOldestClientObservable */
8
+
9
+ /* Excluded from this release type: IOldestClientObservableEvents */
10
+
11
+ /* Excluded from this release type: IOldestClientObserver */
12
+
13
+ /* Excluded from this release type: IOldestClientObserverEvents */
14
+
15
+ /* Excluded from this release type: OldestClientObserver */
16
+
17
+ export { }
@@ -0,0 +1,25 @@
1
+ import { AttachState } from '@fluidframework/container-definitions';
2
+ import { IEvent } from '@fluidframework/core-interfaces';
3
+ import { IEventProvider } from '@fluidframework/core-interfaces';
4
+ import { IQuorumClients } from '@fluidframework/protocol-definitions';
5
+ import { TypedEventEmitter } from '@fluid-internal/client-utils';
6
+
7
+ /* Excluded from this release type: AttachState */
8
+
9
+ /* Excluded from this release type: IEvent */
10
+
11
+ /* Excluded from this release type: IEventProvider */
12
+
13
+ /* Excluded from this release type: IOldestClientObservable */
14
+
15
+ /* Excluded from this release type: IOldestClientObservableEvents */
16
+
17
+ /* Excluded from this release type: IOldestClientObserver */
18
+
19
+ /* Excluded from this release type: IOldestClientObserverEvents */
20
+
21
+ /* Excluded from this release type: OldestClientObserver */
22
+
23
+ /* Excluded from this release type: TypedEventEmitter */
24
+
25
+ export { }
@@ -0,0 +1,25 @@
1
+ import { AttachState } from '@fluidframework/container-definitions';
2
+ import { IEvent } from '@fluidframework/core-interfaces';
3
+ import { IEventProvider } from '@fluidframework/core-interfaces';
4
+ import { IQuorumClients } from '@fluidframework/protocol-definitions';
5
+ import { TypedEventEmitter } from '@fluid-internal/client-utils';
6
+
7
+ /* Excluded from this release type: AttachState */
8
+
9
+ /* Excluded from this release type: IEvent */
10
+
11
+ /* Excluded from this release type: IEventProvider */
12
+
13
+ /* Excluded from this release type: IOldestClientObservable */
14
+
15
+ /* Excluded from this release type: IOldestClientObservableEvents */
16
+
17
+ /* Excluded from this release type: IOldestClientObserver */
18
+
19
+ /* Excluded from this release type: IOldestClientObserverEvents */
20
+
21
+ /* Excluded from this release type: OldestClientObserver */
22
+
23
+ /* Excluded from this release type: TypedEventEmitter */
24
+
25
+ export { }
@@ -0,0 +1,111 @@
1
+ import { AttachState } from '@fluidframework/container-definitions';
2
+ import { IEvent } from '@fluidframework/core-interfaces';
3
+ import { IEventProvider } from '@fluidframework/core-interfaces';
4
+ import { IQuorumClients } from '@fluidframework/protocol-definitions';
5
+ import { TypedEventEmitter } from '@fluid-internal/client-utils';
6
+
7
+ /**
8
+ * This is to make OldestClientObserver work with either a ContainerRuntime or an IFluidDataStoreRuntime
9
+ * (both expose the relevant API surface and eventing). However, really this info probably shouldn't live on either,
10
+ * since neither is really the source of truth (they are just the only currently-available plumbing options).
11
+ * It's information about the connection, so the real source of truth is lower (at the connection layer).
12
+ * @internal
13
+ */
14
+ export declare interface IOldestClientObservable extends IEventProvider<IOldestClientObservableEvents> {
15
+ getQuorum(): IQuorumClients;
16
+ attachState: AttachState;
17
+ connected: boolean;
18
+ clientId: string | undefined;
19
+ }
20
+
21
+ /**
22
+ * Events emitted by {@link IOldestClientObservable}.
23
+ * @internal
24
+ */
25
+ export declare interface IOldestClientObservableEvents extends IEvent {
26
+ (event: "connected", listener: () => void): any;
27
+ (event: "disconnected", listener: () => void): any;
28
+ }
29
+
30
+ /**
31
+ * @internal
32
+ */
33
+ export declare interface IOldestClientObserver extends IEventProvider<IOldestClientObserverEvents> {
34
+ isOldest(): boolean;
35
+ }
36
+
37
+ /**
38
+ * Events emitted by {@link IOldestClientObservable}.
39
+ * @internal
40
+ */
41
+ export declare interface IOldestClientObserverEvents extends IEvent {
42
+ (event: "becameOldest" | "lostOldest", listener: () => void): any;
43
+ }
44
+
45
+ /**
46
+ * The `OldestClientObserver` is a utility inspect if the local client is the oldest amongst connected clients (in
47
+ * terms of when they connected) and watch for changes.
48
+ *
49
+ * It is still experimental and under development. Please do try it out, but expect breaking changes in the future.
50
+ *
51
+ * @remarks
52
+ * ### Creation
53
+ *
54
+ * The `OldestClientObserver` constructor takes an `IOldestClientObservable`. This is most easily satisfied with
55
+ * either an `IContainerRuntime` or an `IFluidDataStoreRuntime`:
56
+ *
57
+ * ```typescript
58
+ * // E.g. from within a BaseContainerRuntimeFactory:
59
+ * protected async containerHasInitialized(runtime: IContainerRuntime) {
60
+ * const oldestClientObserver = new OldestClientObserver(runtime);
61
+ * // ...
62
+ * }
63
+ * ```
64
+ *
65
+ * ```typescript
66
+ * // From within a DataObject
67
+ * protected async hasInitialized() {
68
+ * const oldestClientObserver = new OldestClientObserver(this.runtime);
69
+ * // ...
70
+ * }
71
+ * ```
72
+ *
73
+ * ### Usage
74
+ *
75
+ * To check if the local client is the oldest, use the `isOldest()` method.
76
+ *
77
+ * ```typescript
78
+ * if (oldestClientObserver.isOldest()) {
79
+ * console.log("I'm the oldest");
80
+ * } else {
81
+ * console.log("Someone else is older");
82
+ * }
83
+ * ```
84
+ *
85
+ * ### Eventing
86
+ *
87
+ * `OldestClientObserver` is an `EventEmitter`, and will emit events when the local client becomes the oldest and when
88
+ * it is no longer the oldest.
89
+ *
90
+ * ```typescript
91
+ * oldestClientObserver.on("becameOldest", () => {
92
+ * console.log("I'm the oldest now");
93
+ * });
94
+ *
95
+ * oldestClientObserver.on("lostOldest", () => {
96
+ * console.log("I'm not the oldest anymore");
97
+ * });
98
+ * ```
99
+ * @internal
100
+ */
101
+ export declare class OldestClientObserver extends TypedEventEmitter<IOldestClientObserverEvents> implements IOldestClientObserver {
102
+ private readonly observable;
103
+ private readonly quorum;
104
+ private currentIsOldest;
105
+ constructor(observable: IOldestClientObservable);
106
+ isOldest(): boolean;
107
+ private readonly updateOldest;
108
+ private computeIsOldest;
109
+ }
110
+
111
+ export { }
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { TypedEventEmitter } from "@fluid-internal/client-utils";
6
- import { IOldestClientObservable, IOldestClientObserverEvents, IOldestClientObserver } from "./interfaces";
6
+ import { IOldestClientObservable, IOldestClientObserverEvents, IOldestClientObserver } from "./interfaces.mjs";
7
7
  /**
8
8
  * The `OldestClientObserver` is a utility inspect if the local client is the oldest amongst connected clients (in
9
9
  * terms of when they connected) and watch for changes.
@@ -58,8 +58,7 @@ import { IOldestClientObservable, IOldestClientObserverEvents, IOldestClientObse
58
58
  * console.log("I'm not the oldest anymore");
59
59
  * });
60
60
  * ```
61
- *
62
- * @public
61
+ * @internal
63
62
  */
64
63
  export declare class OldestClientObserver extends TypedEventEmitter<IOldestClientObserverEvents> implements IOldestClientObserver {
65
64
  private readonly observable;
@@ -1 +1 @@
1
- {"version":3,"file":"oldestClientObserver.d.ts","sourceRoot":"","sources":["../src/oldestClientObserver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAIjE,OAAO,EACN,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,EACrB,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,qBAAa,oBACZ,SAAQ,iBAAiB,CAAC,2BAA2B,CACrD,YAAW,qBAAqB;IAIpB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAFvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,eAAe,CAAkB;gBACZ,UAAU,EAAE,uBAAuB;IAUzD,QAAQ,IAAI,OAAO;IAI1B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAU3B;IAEF,OAAO,CAAC,eAAe;CAkCvB"}
1
+ {"version":3,"file":"oldestClientObserver.d.ts","sourceRoot":"","sources":["../src/oldestClientObserver.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,iBAAiB,EAAE,MAAM,8BAA8B;OAIzD,EACN,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,EACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,qBAAa,oBACZ,SAAQ,iBAAiB,CAAC,2BAA2B,CACrD,YAAW,qBAAqB;IAIpB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAFvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,eAAe,CAAkB;gBACZ,UAAU,EAAE,uBAAuB;IAUzD,QAAQ,IAAI,OAAO;IAI1B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAU3B;IAEF,OAAO,CAAC,eAAe;CAkCvB"}
@@ -59,8 +59,7 @@ import { AttachState } from "@fluidframework/container-definitions";
59
59
  * console.log("I'm not the oldest anymore");
60
60
  * });
61
61
  * ```
62
- *
63
- * @public
62
+ * @internal
64
63
  */
65
64
  export class OldestClientObserver extends TypedEventEmitter {
66
65
  constructor(observable) {
@@ -1 +1 @@
1
- {"version":3,"file":"oldestClientObserver.mjs","sourceRoot":"","sources":["../src/oldestClientObserver.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,iBAAiB,EAAE,MAAM,8BAA8B;OACzD,EAAE,MAAM,EAAE,MAAM,4BAA4B;OAC5C,EAAE,WAAW,EAAE,MAAM,uCAAuC;AAQnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,MAAM,OAAO,oBACZ,SAAQ,iBAA8C;IAKtD,YAA6B,UAAmC;QAC/D,KAAK,EAAE,CAAC;QADoB,eAAU,GAAV,UAAU,CAAyB;QADxD,oBAAe,GAAY,KAAK,CAAC;QAexB,iBAAY,GAAG,GAAS,EAAE;YAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;YACtC,IAAI,IAAI,CAAC,eAAe,KAAK,MAAM,EAAE;gBACpC,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC;gBAC9B,IAAI,MAAM,EAAE;oBACX,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;iBAC1B;qBAAM;oBACN,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;iBACxB;aACD;QACF,CAAC,CAAC;QAtBD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;QAC1C,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAClD,UAAU,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC9C,UAAU,CAAC,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAClD,CAAC;IAEM,QAAQ;QACd,OAAO,IAAI,CAAC,eAAe,CAAC;IAC7B,CAAC;IAcO,eAAe;QACtB,uGAAuG;QACvG,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,KAAK,WAAW,CAAC,QAAQ,EAAE;YACzD,OAAO,IAAI,CAAC;SACZ;QAED,kEAAkE;QAClE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE;YAC/B,OAAO,KAAK,CAAC;SACb;QAED,yDAAyD;QACzD,MAAM,CACL,IAAI,CAAC,UAAU,CAAC,QAAQ,KAAK,SAAS;QACtC,4DAA4D;QAC5D,KAAK,CAAC,4CAA4C,CAClD,CAAC;QAEF,MAAM,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC5E,wEAAwE;QACxE,IAAI,mBAAmB,KAAK,SAAS,EAAE;YACtC,OAAO,KAAK,CAAC;SACb;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACzC,KAAK,MAAM,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE;YAC/C,IAAI,eAAe,CAAC,cAAc,GAAG,mBAAmB,CAAC,cAAc,EAAE;gBACxE,OAAO,KAAK,CAAC;aACb;SACD;QAED,oCAAoC;QACpC,OAAO,IAAI,CAAC;IACb,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 { assert } from \"@fluidframework/core-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IQuorumClients } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIOldestClientObservable,\n\tIOldestClientObserverEvents,\n\tIOldestClientObserver,\n} from \"./interfaces\";\n\n/**\n * The `OldestClientObserver` is a utility inspect if the local client is the oldest amongst connected clients (in\n * terms of when they connected) and watch for changes.\n *\n * It is still experimental and under development. Please do try it out, but expect breaking changes in the future.\n *\n * @remarks\n * ### Creation\n *\n * The `OldestClientObserver` constructor takes an `IOldestClientObservable`. This is most easily satisfied with\n * either an `IContainerRuntime` or an `IFluidDataStoreRuntime`:\n *\n * ```typescript\n * // E.g. from within a BaseContainerRuntimeFactory:\n * protected async containerHasInitialized(runtime: IContainerRuntime) {\n * const oldestClientObserver = new OldestClientObserver(runtime);\n * // ...\n * }\n * ```\n *\n * ```typescript\n * // From within a DataObject\n * protected async hasInitialized() {\n * const oldestClientObserver = new OldestClientObserver(this.runtime);\n * // ...\n * }\n * ```\n *\n * ### Usage\n *\n * To check if the local client is the oldest, use the `isOldest()` method.\n *\n * ```typescript\n * if (oldestClientObserver.isOldest()) {\n * console.log(\"I'm the oldest\");\n * } else {\n * console.log(\"Someone else is older\");\n * }\n * ```\n *\n * ### Eventing\n *\n * `OldestClientObserver` is an `EventEmitter`, and will emit events when the local client becomes the oldest and when\n * it is no longer the oldest.\n *\n * ```typescript\n * oldestClientObserver.on(\"becameOldest\", () => {\n * console.log(\"I'm the oldest now\");\n * });\n *\n * oldestClientObserver.on(\"lostOldest\", () => {\n * console.log(\"I'm not the oldest anymore\");\n * });\n * ```\n *\n * @public\n */\nexport class OldestClientObserver\n\textends TypedEventEmitter<IOldestClientObserverEvents>\n\timplements IOldestClientObserver\n{\n\tprivate readonly quorum: IQuorumClients;\n\tprivate currentIsOldest: boolean = false;\n\tconstructor(private readonly observable: IOldestClientObservable) {\n\t\tsuper();\n\t\tthis.quorum = this.observable.getQuorum();\n\t\tthis.currentIsOldest = this.computeIsOldest();\n\t\tthis.quorum.on(\"addMember\", this.updateOldest);\n\t\tthis.quorum.on(\"removeMember\", this.updateOldest);\n\t\tobservable.on(\"connected\", this.updateOldest);\n\t\tobservable.on(\"disconnected\", this.updateOldest);\n\t}\n\n\tpublic isOldest(): boolean {\n\t\treturn this.currentIsOldest;\n\t}\n\n\tprivate readonly updateOldest = (): void => {\n\t\tconst oldest = this.computeIsOldest();\n\t\tif (this.currentIsOldest !== oldest) {\n\t\t\tthis.currentIsOldest = oldest;\n\t\t\tif (oldest) {\n\t\t\t\tthis.emit(\"becameOldest\");\n\t\t\t} else {\n\t\t\t\tthis.emit(\"lostOldest\");\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate computeIsOldest(): boolean {\n\t\t// If the container is detached, we are the only ones that know about it and are the oldest by default.\n\t\tif (this.observable.attachState === AttachState.Detached) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// If we're not connected we can't be the oldest connected client.\n\t\tif (!this.observable.connected) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// TODO: Clean up error code linter violations repo-wide.\n\t\tassert(\n\t\t\tthis.observable.clientId !== undefined,\n\t\t\t// eslint-disable-next-line unicorn/numeric-separators-style\n\t\t\t0x1da /* \"Client id should be set if connected\" */,\n\t\t);\n\n\t\tconst selfSequencedClient = this.quorum.getMember(this.observable.clientId);\n\t\t// When in readonly mode our clientId will not be present in the quorum.\n\t\tif (selfSequencedClient === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst members = this.quorum.getMembers();\n\t\tfor (const sequencedClient of members.values()) {\n\t\t\tif (sequencedClient.sequenceNumber < selfSequencedClient.sequenceNumber) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\t// No member of the quorum was older\n\t\treturn true;\n\t}\n}\n"]}
1
+ {"version":3,"file":"oldestClientObserver.mjs","sourceRoot":"","sources":["../src/oldestClientObserver.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,iBAAiB,EAAE,MAAM,8BAA8B;OACzD,EAAE,MAAM,EAAE,MAAM,4BAA4B;OAC5C,EAAE,WAAW,EAAE,MAAM,uCAAuC;AAQnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,MAAM,OAAO,oBACZ,SAAQ,iBAA8C;IAKtD,YAA6B,UAAmC;QAC/D,KAAK,EAAE,CAAC;QADoB,eAAU,GAAV,UAAU,CAAyB;QADxD,oBAAe,GAAY,KAAK,CAAC;QAexB,iBAAY,GAAG,GAAS,EAAE;YAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;YACtC,IAAI,IAAI,CAAC,eAAe,KAAK,MAAM,EAAE;gBACpC,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC;gBAC9B,IAAI,MAAM,EAAE;oBACX,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;iBAC1B;qBAAM;oBACN,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;iBACxB;aACD;QACF,CAAC,CAAC;QAtBD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;QAC1C,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAClD,UAAU,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC9C,UAAU,CAAC,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAClD,CAAC;IAEM,QAAQ;QACd,OAAO,IAAI,CAAC,eAAe,CAAC;IAC7B,CAAC;IAcO,eAAe;QACtB,uGAAuG;QACvG,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,KAAK,WAAW,CAAC,QAAQ,EAAE;YACzD,OAAO,IAAI,CAAC;SACZ;QAED,kEAAkE;QAClE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE;YAC/B,OAAO,KAAK,CAAC;SACb;QAED,yDAAyD;QACzD,MAAM,CACL,IAAI,CAAC,UAAU,CAAC,QAAQ,KAAK,SAAS;QACtC,4DAA4D;QAC5D,KAAK,CAAC,4CAA4C,CAClD,CAAC;QAEF,MAAM,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC5E,wEAAwE;QACxE,IAAI,mBAAmB,KAAK,SAAS,EAAE;YACtC,OAAO,KAAK,CAAC;SACb;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACzC,KAAK,MAAM,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE;YAC/C,IAAI,eAAe,CAAC,cAAc,GAAG,mBAAmB,CAAC,cAAc,EAAE;gBACxE,OAAO,KAAK,CAAC;aACb;SACD;QAED,oCAAoC;QACpC,OAAO,IAAI,CAAC;IACb,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 { assert } from \"@fluidframework/core-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IQuorumClients } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIOldestClientObservable,\n\tIOldestClientObserverEvents,\n\tIOldestClientObserver,\n} from \"./interfaces\";\n\n/**\n * The `OldestClientObserver` is a utility inspect if the local client is the oldest amongst connected clients (in\n * terms of when they connected) and watch for changes.\n *\n * It is still experimental and under development. Please do try it out, but expect breaking changes in the future.\n *\n * @remarks\n * ### Creation\n *\n * The `OldestClientObserver` constructor takes an `IOldestClientObservable`. This is most easily satisfied with\n * either an `IContainerRuntime` or an `IFluidDataStoreRuntime`:\n *\n * ```typescript\n * // E.g. from within a BaseContainerRuntimeFactory:\n * protected async containerHasInitialized(runtime: IContainerRuntime) {\n * const oldestClientObserver = new OldestClientObserver(runtime);\n * // ...\n * }\n * ```\n *\n * ```typescript\n * // From within a DataObject\n * protected async hasInitialized() {\n * const oldestClientObserver = new OldestClientObserver(this.runtime);\n * // ...\n * }\n * ```\n *\n * ### Usage\n *\n * To check if the local client is the oldest, use the `isOldest()` method.\n *\n * ```typescript\n * if (oldestClientObserver.isOldest()) {\n * console.log(\"I'm the oldest\");\n * } else {\n * console.log(\"Someone else is older\");\n * }\n * ```\n *\n * ### Eventing\n *\n * `OldestClientObserver` is an `EventEmitter`, and will emit events when the local client becomes the oldest and when\n * it is no longer the oldest.\n *\n * ```typescript\n * oldestClientObserver.on(\"becameOldest\", () => {\n * console.log(\"I'm the oldest now\");\n * });\n *\n * oldestClientObserver.on(\"lostOldest\", () => {\n * console.log(\"I'm not the oldest anymore\");\n * });\n * ```\n * @internal\n */\nexport class OldestClientObserver\n\textends TypedEventEmitter<IOldestClientObserverEvents>\n\timplements IOldestClientObserver\n{\n\tprivate readonly quorum: IQuorumClients;\n\tprivate currentIsOldest: boolean = false;\n\tconstructor(private readonly observable: IOldestClientObservable) {\n\t\tsuper();\n\t\tthis.quorum = this.observable.getQuorum();\n\t\tthis.currentIsOldest = this.computeIsOldest();\n\t\tthis.quorum.on(\"addMember\", this.updateOldest);\n\t\tthis.quorum.on(\"removeMember\", this.updateOldest);\n\t\tobservable.on(\"connected\", this.updateOldest);\n\t\tobservable.on(\"disconnected\", this.updateOldest);\n\t}\n\n\tpublic isOldest(): boolean {\n\t\treturn this.currentIsOldest;\n\t}\n\n\tprivate readonly updateOldest = (): void => {\n\t\tconst oldest = this.computeIsOldest();\n\t\tif (this.currentIsOldest !== oldest) {\n\t\t\tthis.currentIsOldest = oldest;\n\t\t\tif (oldest) {\n\t\t\t\tthis.emit(\"becameOldest\");\n\t\t\t} else {\n\t\t\t\tthis.emit(\"lostOldest\");\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate computeIsOldest(): boolean {\n\t\t// If the container is detached, we are the only ones that know about it and are the oldest by default.\n\t\tif (this.observable.attachState === AttachState.Detached) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// If we're not connected we can't be the oldest connected client.\n\t\tif (!this.observable.connected) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// TODO: Clean up error code linter violations repo-wide.\n\t\tassert(\n\t\t\tthis.observable.clientId !== undefined,\n\t\t\t// eslint-disable-next-line unicorn/numeric-separators-style\n\t\t\t0x1da /* \"Client id should be set if connected\" */,\n\t\t);\n\n\t\tconst selfSequencedClient = this.quorum.getMember(this.observable.clientId);\n\t\t// When in readonly mode our clientId will not be present in the quorum.\n\t\tif (selfSequencedClient === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst members = this.quorum.getMembers();\n\t\tfor (const sequencedClient of members.values()) {\n\t\t\tif (sequencedClient.sequenceNumber < selfSequencedClient.sequenceNumber) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\t// No member of the quorum was older\n\t\treturn true;\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-experimental/oldest-client-observer",
3
- "version": "2.0.0-internal.7.3.0",
3
+ "version": "2.0.0-internal.7.4.1",
4
4
  "description": "Data object to determine if the local client is the oldest amongst connected clients",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -11,18 +11,6 @@
11
11
  "license": "MIT",
12
12
  "author": "Microsoft and contributors",
13
13
  "sideEffects": false,
14
- "exports": {
15
- ".": {
16
- "import": {
17
- "types": "./lib/index.d.ts",
18
- "default": "./lib/index.mjs"
19
- },
20
- "require": {
21
- "types": "./dist/index.d.ts",
22
- "default": "./dist/index.cjs"
23
- }
24
- }
25
- },
26
14
  "main": "dist/index.cjs",
27
15
  "module": "lib/index.mjs",
28
16
  "types": "dist/index.d.ts",
@@ -47,21 +35,22 @@
47
35
  "temp-directory": "nyc/.nyc_output"
48
36
  },
49
37
  "dependencies": {
50
- "@fluid-internal/client-utils": ">=2.0.0-internal.7.3.0 <2.0.0-internal.7.4.0",
51
- "@fluidframework/container-definitions": ">=2.0.0-internal.7.3.0 <2.0.0-internal.7.4.0",
52
- "@fluidframework/core-interfaces": ">=2.0.0-internal.7.3.0 <2.0.0-internal.7.4.0",
53
- "@fluidframework/core-utils": ">=2.0.0-internal.7.3.0 <2.0.0-internal.7.4.0",
38
+ "@fluid-internal/client-utils": ">=2.0.0-internal.7.4.1 <2.0.0-internal.7.5.0",
39
+ "@fluidframework/container-definitions": ">=2.0.0-internal.7.4.1 <2.0.0-internal.7.5.0",
40
+ "@fluidframework/core-interfaces": ">=2.0.0-internal.7.4.1 <2.0.0-internal.7.5.0",
41
+ "@fluidframework/core-utils": ">=2.0.0-internal.7.4.1 <2.0.0-internal.7.5.0",
54
42
  "@fluidframework/protocol-definitions": "^3.0.0"
55
43
  },
56
44
  "devDependencies": {
57
- "@fluid-private/test-dds-utils": ">=2.0.0-internal.7.3.0 <2.0.0-internal.7.4.0",
45
+ "@fluid-private/test-dds-utils": ">=2.0.0-internal.7.4.1 <2.0.0-internal.7.5.0",
58
46
  "@fluid-tools/build-cli": "^0.28.0",
59
47
  "@fluidframework/build-common": "^2.0.3",
60
48
  "@fluidframework/build-tools": "^0.28.0",
61
49
  "@fluidframework/eslint-config-fluid": "^3.1.0",
62
- "@fluidframework/test-runtime-utils": ">=2.0.0-internal.7.3.0 <2.0.0-internal.7.4.0",
50
+ "@fluidframework/test-runtime-utils": ">=2.0.0-internal.7.4.1 <2.0.0-internal.7.5.0",
63
51
  "@microsoft/api-extractor": "^7.38.3",
64
- "@types/node": "^16.18.38",
52
+ "@types/node": "^18.19.0",
53
+ "copyfiles": "^2.4.1",
65
54
  "cross-env": "^7.0.3",
66
55
  "eslint": "~8.50.0",
67
56
  "prettier": "~3.0.3",
@@ -71,6 +60,14 @@
71
60
  },
72
61
  "fluidBuild": {
73
62
  "tasks": {
63
+ "build:docs": {
64
+ "dependsOn": [
65
+ "...",
66
+ "api-extractor:commonjs",
67
+ "api-extractor:esnext"
68
+ ],
69
+ "script": false
70
+ },
74
71
  "tsc": [
75
72
  "...",
76
73
  "typetests:gen"
@@ -82,20 +79,24 @@
82
79
  "broken": {}
83
80
  },
84
81
  "scripts": {
82
+ "api": "fluid-build . --task api",
83
+ "api-extractor:commonjs": "api-extractor run --local",
84
+ "api-extractor:esnext": "copyfiles -u 1 \"dist/**/*-@(alpha|beta|public|untrimmed).d.ts\" lib",
85
85
  "build": "fluid-build . --task build",
86
86
  "build:commonjs": "fluid-build . --task commonjs",
87
87
  "build:compile": "fluid-build . --task compile",
88
- "build:docs": "api-extractor run --local",
88
+ "build:docs": "fluid-build . --task api",
89
89
  "build:esnext": "tsc-multi --config ../../../common/build/build-common/tsc-multi.esm.json",
90
+ "check:release-tags": "api-extractor run --local --config ./api-extractor-lint.json",
90
91
  "ci:build:docs": "api-extractor run",
91
92
  "clean": "rimraf --glob dist lib \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp",
92
93
  "eslint": "eslint --format stylish src",
93
94
  "eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
94
95
  "format": "npm run prettier:fix",
95
- "lint": "npm run prettier && npm run eslint",
96
+ "lint": "npm run prettier && npm run check:release-tags && npm run eslint",
96
97
  "lint:fix": "npm run prettier:fix && npm run eslint:fix",
97
- "prettier": "prettier --check . --ignore-path ../../../.prettierignore",
98
- "prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
98
+ "prettier": "prettier --check . --cache --ignore-path ../../../.prettierignore",
99
+ "prettier:fix": "prettier --write . --cache --ignore-path ../../../.prettierignore",
99
100
  "tsc": "tsc-multi --config ../../../common/build/build-common/tsc-multi.cjs.json",
100
101
  "typetests:gen": "fluid-type-test-generator",
101
102
  "typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
package/src/interfaces.ts CHANGED
@@ -9,8 +9,7 @@ import { IQuorumClients } from "@fluidframework/protocol-definitions";
9
9
 
10
10
  /**
11
11
  * Events emitted by {@link IOldestClientObservable}.
12
- *
13
- * @public
12
+ * @internal
14
13
  */
15
14
  export interface IOldestClientObservableEvents extends IEvent {
16
15
  (event: "connected", listener: () => void);
@@ -22,8 +21,7 @@ export interface IOldestClientObservableEvents extends IEvent {
22
21
  * (both expose the relevant API surface and eventing). However, really this info probably shouldn't live on either,
23
22
  * since neither is really the source of truth (they are just the only currently-available plumbing options).
24
23
  * It's information about the connection, so the real source of truth is lower (at the connection layer).
25
- *
26
- * @public
24
+ * @internal
27
25
  */
28
26
  export interface IOldestClientObservable extends IEventProvider<IOldestClientObservableEvents> {
29
27
  getQuorum(): IQuorumClients;
@@ -39,15 +37,14 @@ export interface IOldestClientObservable extends IEventProvider<IOldestClientObs
39
37
 
40
38
  /**
41
39
  * Events emitted by {@link IOldestClientObservable}.
42
- *
43
- * @public
40
+ * @internal
44
41
  */
45
42
  export interface IOldestClientObserverEvents extends IEvent {
46
43
  (event: "becameOldest" | "lostOldest", listener: () => void);
47
44
  }
48
45
 
49
46
  /**
50
- * @public
47
+ * @internal
51
48
  */
52
49
  export interface IOldestClientObserver extends IEventProvider<IOldestClientObserverEvents> {
53
50
  isOldest(): boolean;
@@ -67,8 +67,7 @@ import {
67
67
  * console.log("I'm not the oldest anymore");
68
68
  * });
69
69
  * ```
70
- *
71
- * @public
70
+ * @internal
72
71
  */
73
72
  export class OldestClientObserver
74
73
  extends TypedEventEmitter<IOldestClientObserverEvents>