@fluid-experimental/pact-map 2.117.0 → 3.0.0
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 +24 -2
- package/README.md +52 -48
- package/{api-extractor.json → api-extractor/api-extractor-model.json} +1 -1
- package/api-extractor/api-extractor-report.json +5 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/pactMap.js +82 -82
- package/dist/pactMap.js.map +1 -1
- package/dist/pactMapFactory.d.ts +1 -1
- package/dist/pactMapFactory.d.ts.map +1 -1
- package/dist/pactMapFactory.js +9 -9
- package/dist/pactMapFactory.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/pactMap.js +82 -82
- package/lib/pactMap.js.map +1 -1
- package/lib/pactMapFactory.js +9 -9
- package/lib/pactMapFactory.js.map +1 -1
- package/package.json +23 -29
- package/src/packageVersion.ts +1 -1
- package/tsconfig.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
# @fluid-experimental/pact-map
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 3.0.0
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Removal of direct CommonJS support ([#28124](https://github.com/microsoft/FluidFramework/pull/28124)) [0f84e3b8878](https://github.com/microsoft/FluidFramework/commit/0f84e3b8878a5e75b2253976d98fd963bbd9db88)
|
|
8
|
+
|
|
9
|
+
Direct `require()` import is no longer directly supported.
|
|
10
|
+
Package is transpiled as ECMAScript Module.
|
|
11
|
+
|
|
12
|
+
See [Removal of direct CommonJS support in v3.0](https://github.com/microsoft/FluidFramework/issues/27444) for more information.
|
|
13
|
+
|
|
14
|
+
- Client packages now target ES2022 ([#27846](https://github.com/microsoft/FluidFramework/pull/27846)) [91c78541bdd](https://github.com/microsoft/FluidFramework/commit/91c78541bddcbca5d6c5f357b023eeaee617d885)
|
|
15
|
+
|
|
16
|
+
The TypeScript compilation `target` and `lib` for the Fluid Framework client packages have been raised from ES2021/ES2020 to **ES2022**.
|
|
17
|
+
The published JavaScript now uses ES2022 language features (with correspondingly less down-leveling), so consuming these packages requires a runtime that supports ES2022.
|
|
18
|
+
All actively supported Node.js versions and evergreen browsers already meet this requirement.
|
|
19
|
+
|
|
20
|
+
Note that Fluid Framework has not officially supported targets older than ES2022 since before 2.0: this is documented in [ClientRequirements.md](https://github.com/microsoft/FluidFramework/blob/main/ClientRequirements.md) as well as the README for every client package.
|
|
21
|
+
|
|
22
|
+
It is possible this change could impact users of less up to date JavaScript runtimes.
|
|
23
|
+
Impacted users can use a tool like [babel](https://babeljs.io/) to transpile out unsupported language features.
|
|
24
|
+
|
|
25
|
+
- Build with TypeScript 6 ([#28052](https://github.com/microsoft/FluidFramework/pull/28052)) [7ab015c49de](https://github.com/microsoft/FluidFramework/commit/7ab015c49deec84833cdfe1fb5e1606b901f6e81)
|
|
26
|
+
|
|
27
|
+
FluidFramework Client SDK is now built using TypeScript 6. Consumers should build with TypeScript v6 or v7 or compatible tooling.
|
|
6
28
|
|
|
7
29
|
## 2.116.0
|
|
8
30
|
|
package/README.md
CHANGED
|
@@ -8,21 +8,22 @@ A distributed data structure for key-value pairs using pact consensus.
|
|
|
8
8
|
<!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
|
|
9
9
|
|
|
10
10
|
**IMPORTANT: This package is experimental.**
|
|
11
|
-
**
|
|
11
|
+
**The APIs can change without notice.**
|
|
12
12
|
|
|
13
|
-
**Do not use in production scenarios.**
|
|
13
|
+
**Do not use it as a dependency in production scenarios.**
|
|
14
|
+
**We do not guarantee the stability of this package or its APIs.**
|
|
14
15
|
|
|
15
16
|
## Using Fluid Framework libraries
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
library consumers should always prefer `^`.
|
|
18
|
+
For a dependency on a Fluid Framework library's public APIs, we recommend a `^` (caret) version range.
|
|
19
|
+
For example, use `^1.3.4`.
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
For a dependency on an unstable API, such as a `beta` API, we recommend a more restrictive version range.
|
|
22
|
+
For example, use a `~` version range.
|
|
22
23
|
|
|
23
24
|
## Installation
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
Run this command to install the package:
|
|
26
27
|
|
|
27
28
|
```bash
|
|
28
29
|
npm i @fluid-experimental/pact-map
|
|
@@ -30,7 +31,7 @@ npm i @fluid-experimental/pact-map
|
|
|
30
31
|
|
|
31
32
|
## API Documentation
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
Read the **@fluid-experimental/pact-map** API documentation at <https://fluidframework.com/docs/apis/pact-map>.
|
|
34
35
|
|
|
35
36
|
<!-- prettier-ignore-end -->
|
|
36
37
|
|
|
@@ -43,62 +44,69 @@ API documentation for **@fluid-experimental/pact-map** is available at <https://
|
|
|
43
44
|
|
|
44
45
|
## Minimum Client Requirements
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
These requirements
|
|
48
|
-
|
|
47
|
+
Fluid Framework client libraries support the platforms in this document.
|
|
48
|
+
These requirements are intentionally restrictive.
|
|
49
|
+
Within a major version series, we can relax these requirements, but we cannot make them stricter.
|
|
50
|
+
For a Long Term Support (LTS) version, we might need to support these platforms for several years.
|
|
49
51
|
|
|
50
|
-
|
|
51
|
-
If
|
|
52
|
-
|
|
52
|
+
Other configurations can work, but Fluid Framework does not support them.
|
|
53
|
+
If an unsupported configuration stops working, we do not classify this as a bug.
|
|
54
|
+
To request support for a configuration that is not listed, file an issue.
|
|
55
|
+
The product team will evaluate your request.
|
|
56
|
+
In the issue, specify the current status of the configuration:
|
|
57
|
+
|
|
58
|
+
- The configuration works but needs official support.
|
|
59
|
+
- The configuration does not work and requires changes.
|
|
53
60
|
|
|
54
61
|
### Supported Runtimes
|
|
55
62
|
|
|
56
|
-
-
|
|
57
|
-
-
|
|
58
|
-
-
|
|
63
|
+
- Fluid Framework supports Node.js versions 22 and 24 while they receive [upstream support](https://nodejs.org/en/about/previous-releases).
|
|
64
|
+
- Fluid Framework will stop support for version 22 [when upstream support ends on 2027-04-30](https://github.com/nodejs/release#release-schedule).
|
|
65
|
+
- Fluid Framework does not support Node.js with the `--no-experimental-fetch` flag.
|
|
66
|
+
- Fluid Framework supports modern browsers that support the ES2022 standard library.
|
|
59
67
|
|
|
60
68
|
### Supported Tools
|
|
61
69
|
|
|
62
|
-
- TypeScript
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
- [
|
|
66
|
-
-
|
|
67
|
-
|
|
70
|
+
- [TypeScript 6.0](https://typescriptdocs.com/release-notes/TypeScript%206.0):
|
|
71
|
+
- Fluid Framework supports all [`strict`](https://www.typescriptlang.org/tsconfig) options.
|
|
72
|
+
- Set the build targets (`lib`, `target`) to `ES2022` or later.
|
|
73
|
+
- Enable [`strictNullChecks`](https://www.typescriptlang.org/tsconfig).
|
|
74
|
+
- Fluid Framework does not support [configuration options deprecated in TypeScript 6.0](https://typescriptdocs.com/release-notes/TypeScript%206.0#breaking-changes-and-deprecations-in-typescript-6-0).
|
|
75
|
+
- Fluid Framework does not fully support `exactOptionalPropertyTypes`.
|
|
76
|
+
If you enable this option, do not use `in`, `Reflect.has`, `Object.hasOwn`, or `Object.prototype.hasOwnProperty` to narrow members of Fluid Framework types.
|
|
77
|
+
These methods can incorrectly exclude `undefined` from the possible values.
|
|
68
78
|
- [webpack](https://webpack.js.org/) 5
|
|
69
|
-
- We
|
|
70
|
-
Other bundlers
|
|
79
|
+
- We do not require a specific bundler.
|
|
80
|
+
Other bundlers that handle ES Modules can work, but we actively test only webpack.
|
|
71
81
|
|
|
72
82
|
### Module Resolution
|
|
73
83
|
|
|
74
|
-
[`Node16`, `NodeNext`, or `Bundler`](https://www.typescriptlang.org/tsconfig#moduleResolution)
|
|
75
|
-
|
|
84
|
+
In TypeScript `compilerOptions`, use [`Node16`, `Node20`, `NodeNext`, or `Bundler`](https://www.typescriptlang.org/tsconfig#moduleResolution) module resolution.
|
|
85
|
+
These settings follow the [Node.js v12+ ESM Resolution and Loading algorithm](https://nodejs.github.io/nodejs.dev/en/api/v20/esm/#resolution-and-loading-algorithm).
|
|
86
|
+
|
|
87
|
+
Do not use `Node10` module resolution.
|
|
76
88
|
|
|
77
89
|
### Module Formats
|
|
78
90
|
|
|
79
91
|
- ES Modules:
|
|
80
|
-
ES Modules
|
|
81
|
-
-
|
|
82
|
-
|
|
83
|
-
This is done to accommodate some workflows without good ES Module support.
|
|
84
|
-
If you have a workflow you would like included in this list, file an issue.
|
|
85
|
-
Once this list of workflows motivating CommonJS support is empty, we may drop support for CommonJS one year after notice of the change is posted here.
|
|
86
|
-
|
|
87
|
-
- Testing with Jest (which lacks [stable ESM support](https://jestjs.io/docs/ecmascript-modules) due to [unstable APIs in NodeJs](https://github.com/nodejs/node/issues/37648))
|
|
92
|
+
Use ES Modules to consume Fluid Framework client packages, including in Node.js.
|
|
93
|
+
- CommonJS:
|
|
94
|
+
Fluid Framework does not officially support CommonJS in version 3.0 or later.
|
|
88
95
|
|
|
89
96
|
## Contribution Guidelines
|
|
90
97
|
|
|
91
|
-
|
|
98
|
+
You can [contribute](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md) to Fluid Framework in these ways:
|
|
92
99
|
|
|
93
|
-
-
|
|
94
|
-
- [Submit
|
|
95
|
-
- Review
|
|
100
|
+
- Answer questions in [GitHub Discussions](https://github.com/microsoft/FluidFramework/discussions).
|
|
101
|
+
- [Submit bug reports](https://github.com/microsoft/FluidFramework/issues) and help verify fixes.
|
|
102
|
+
- Review [source code changes](https://github.com/microsoft/FluidFramework/pulls).
|
|
96
103
|
- [Contribute bug fixes](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md).
|
|
97
104
|
|
|
98
|
-
|
|
105
|
+
For detailed instructions, read the [repo documentation](https://github.com/microsoft/FluidFramework/blob/main/docs/content/Home.md).
|
|
99
106
|
|
|
100
|
-
This project
|
|
101
|
-
For more information
|
|
107
|
+
This project follows the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
|
108
|
+
For more information, read the [Code of Conduct frequently asked questions](https://opensource.microsoft.com/codeofconduct/faq/).
|
|
109
|
+
For questions or comments, contact [opencode@microsoft.com](mailto:opencode@microsoft.com).
|
|
102
110
|
|
|
103
111
|
This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
|
|
104
112
|
Use of these trademarks or logos must follow Microsoft’s [Trademark & Brand Guidelines](https://www.microsoft.com/trademarks).
|
|
@@ -106,13 +114,9 @@ Use of Microsoft trademarks or logos in modified versions of this project must n
|
|
|
106
114
|
|
|
107
115
|
## Help
|
|
108
116
|
|
|
109
|
-
|
|
110
|
-
Check out [fluidframework.com](https://fluidframework.com/docs/).
|
|
111
|
-
|
|
112
|
-
Still not finding what you're looking for?
|
|
113
|
-
Please [file an issue](https://github.com/microsoft/FluidFramework/blob/main/docs/content/Contributing/Submitting-Bugs-and-Feature-Requests.md).
|
|
117
|
+
Read the [Fluid Framework documentation](https://fluidframework.com/docs/) for information about Fluid Framework concepts and APIs.
|
|
114
118
|
|
|
115
|
-
|
|
119
|
+
To request information that the documentation does not contain, [create an issue](https://github.com/microsoft/FluidFramework/blob/main/docs/content/Contributing/Submitting-Bugs-and-Feature-Requests.md).
|
|
116
120
|
|
|
117
121
|
## Trademark
|
|
118
122
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
-
"extends": "
|
|
3
|
+
"extends": "<projectFolder>/../../../common/build/build-common/api-extractor-model.esm.json"
|
|
4
4
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
+
"extends": "<projectFolder>/../../../common/build/build-common/api-extractor-report-base.esm.json",
|
|
4
|
+
"mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts"
|
|
5
|
+
}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluid-experimental/pact-map";
|
|
8
|
-
export declare const pkgVersion = "
|
|
8
|
+
export declare const pkgVersion = "3.0.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,iCAAiC,CAAC;AACtD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,iCAAiC,CAAC;AACtD,eAAO,MAAM,UAAU,UAAU,CAAC"}
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluid-experimental/pact-map";
|
|
11
|
-
exports.pkgVersion = "
|
|
11
|
+
exports.pkgVersion = "3.0.0";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,8BAA8B,CAAC;AACzC,QAAA,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,8BAA8B,CAAC;AACzC,QAAA,UAAU,GAAG,OAAO,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluid-experimental/pact-map\";\nexport const pkgVersion = \"3.0.0\";\n"]}
|
package/dist/pactMap.js
CHANGED
|
@@ -15,6 +15,8 @@ const snapshotFileName = "header";
|
|
|
15
15
|
* {@inheritDoc PactMap}
|
|
16
16
|
*/
|
|
17
17
|
class PactMapClass extends internal_4.SharedObject {
|
|
18
|
+
values = new Map();
|
|
19
|
+
incomingOp = new client_utils_1.EventEmitter();
|
|
18
20
|
/**
|
|
19
21
|
* Constructs a new PactMap. If the object is non-local an id and service interfaces will
|
|
20
22
|
* be provided
|
|
@@ -24,88 +26,6 @@ class PactMapClass extends internal_4.SharedObject {
|
|
|
24
26
|
*/
|
|
25
27
|
constructor(id, runtime, attributes) {
|
|
26
28
|
super(id, runtime, attributes, "fluid_pactMap_");
|
|
27
|
-
this.values = new Map();
|
|
28
|
-
this.incomingOp = new client_utils_1.EventEmitter();
|
|
29
|
-
this.handleIncomingSet = (key, value, refSeq, setSequenceNumber) => {
|
|
30
|
-
const currentValue = this.values.get(key);
|
|
31
|
-
// We use a consensus-like approach here, so a proposal is valid if the value is unset or if there is no
|
|
32
|
-
// pending change and it was made with knowledge of the most recently accepted value. We'll drop invalid
|
|
33
|
-
// proposals on the ground.
|
|
34
|
-
const proposalValid = currentValue === undefined ||
|
|
35
|
-
(currentValue.pending === undefined && currentValue.accepted.sequenceNumber <= refSeq);
|
|
36
|
-
if (!proposalValid) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const accepted = currentValue?.accepted;
|
|
40
|
-
// We expect signoffs from all connected clients at the time the set was sequenced (including the client who
|
|
41
|
-
// sent the set).
|
|
42
|
-
const expectedSignoffs = this.getSignoffClients();
|
|
43
|
-
const newPact = {
|
|
44
|
-
accepted,
|
|
45
|
-
pending: {
|
|
46
|
-
value,
|
|
47
|
-
expectedSignoffs,
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
this.values.set(key, newPact);
|
|
51
|
-
this.emit("pending", key);
|
|
52
|
-
if (expectedSignoffs.length === 0) {
|
|
53
|
-
// At least the submitting client should be amongst the expectedSignoffs, but keeping this check around
|
|
54
|
-
// as extra protection and in case we bring back the "submitting client implicitly accepts" optimization.
|
|
55
|
-
this.values.set(key, {
|
|
56
|
-
accepted: { value, sequenceNumber: setSequenceNumber },
|
|
57
|
-
pending: undefined,
|
|
58
|
-
});
|
|
59
|
-
this.emit("accepted", key);
|
|
60
|
-
}
|
|
61
|
-
else if (this.runtime.clientId !== undefined &&
|
|
62
|
-
expectedSignoffs.includes(this.runtime.clientId)) {
|
|
63
|
-
// Emit an accept upon a new key entering pending state if our accept is expected.
|
|
64
|
-
const acceptOp = {
|
|
65
|
-
type: "accept",
|
|
66
|
-
key,
|
|
67
|
-
};
|
|
68
|
-
this.submitLocalMessage(acceptOp);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
this.handleIncomingAccept = (key, clientId, sequenceNumber) => {
|
|
72
|
-
const pending = this.values.get(key)?.pending;
|
|
73
|
-
if (pending === undefined) {
|
|
74
|
-
// If there is no pending value, we already accepted it, so we can ignore the accept op.
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
(0, internal_1.assert)(pending.expectedSignoffs.includes(clientId), 0x2f9 /* Unexpected accept op, client not in expectedSignoffs */);
|
|
78
|
-
// Remove the client from the expected signoffs
|
|
79
|
-
pending.expectedSignoffs = pending.expectedSignoffs.filter((expectedClientId) => expectedClientId !== clientId);
|
|
80
|
-
if (pending.expectedSignoffs.length === 0) {
|
|
81
|
-
// The pending value has settled
|
|
82
|
-
this.values.set(key, {
|
|
83
|
-
accepted: { value: pending.value, sequenceNumber },
|
|
84
|
-
pending: undefined,
|
|
85
|
-
});
|
|
86
|
-
this.emit("accepted", key);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
this.handleQuorumRemoveMember = (clientId) => {
|
|
90
|
-
for (const [key, { pending }] of this.values) {
|
|
91
|
-
if (pending !== undefined) {
|
|
92
|
-
pending.expectedSignoffs = pending.expectedSignoffs.filter((expectedClientId) => expectedClientId !== clientId);
|
|
93
|
-
if (pending.expectedSignoffs.length === 0) {
|
|
94
|
-
// The pending value has settled
|
|
95
|
-
const clientLeaveSequenceNumber = this.deltaManager.lastSequenceNumber;
|
|
96
|
-
this.values.set(key, {
|
|
97
|
-
accepted: {
|
|
98
|
-
value: pending.value,
|
|
99
|
-
// The sequence number of the ClientLeave message.
|
|
100
|
-
sequenceNumber: clientLeaveSequenceNumber,
|
|
101
|
-
},
|
|
102
|
-
pending: undefined,
|
|
103
|
-
});
|
|
104
|
-
this.emit("accepted", key);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
29
|
this.incomingOp.on("set", this.handleIncomingSet);
|
|
110
30
|
this.incomingOp.on("accept", this.handleIncomingAccept);
|
|
111
31
|
this.runtime.getQuorum().on("removeMember", this.handleQuorumRemoveMember);
|
|
@@ -197,6 +117,86 @@ class PactMapClass extends internal_4.SharedObject {
|
|
|
197
117
|
// If detached, we don't need anyone to sign off. Otherwise, we need all currently connected clients.
|
|
198
118
|
return this.isAttached() ? [...this.runtime.getQuorum().getMembers().keys()] : [];
|
|
199
119
|
}
|
|
120
|
+
handleIncomingSet = (key, value, refSeq, setSequenceNumber) => {
|
|
121
|
+
const currentValue = this.values.get(key);
|
|
122
|
+
// We use a consensus-like approach here, so a proposal is valid if the value is unset or if there is no
|
|
123
|
+
// pending change and it was made with knowledge of the most recently accepted value. We'll drop invalid
|
|
124
|
+
// proposals on the ground.
|
|
125
|
+
const proposalValid = currentValue === undefined ||
|
|
126
|
+
(currentValue.pending === undefined && currentValue.accepted.sequenceNumber <= refSeq);
|
|
127
|
+
if (!proposalValid) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const accepted = currentValue?.accepted;
|
|
131
|
+
// We expect signoffs from all connected clients at the time the set was sequenced (including the client who
|
|
132
|
+
// sent the set).
|
|
133
|
+
const expectedSignoffs = this.getSignoffClients();
|
|
134
|
+
const newPact = {
|
|
135
|
+
accepted,
|
|
136
|
+
pending: {
|
|
137
|
+
value,
|
|
138
|
+
expectedSignoffs,
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
this.values.set(key, newPact);
|
|
142
|
+
this.emit("pending", key);
|
|
143
|
+
if (expectedSignoffs.length === 0) {
|
|
144
|
+
// At least the submitting client should be amongst the expectedSignoffs, but keeping this check around
|
|
145
|
+
// as extra protection and in case we bring back the "submitting client implicitly accepts" optimization.
|
|
146
|
+
this.values.set(key, {
|
|
147
|
+
accepted: { value, sequenceNumber: setSequenceNumber },
|
|
148
|
+
pending: undefined,
|
|
149
|
+
});
|
|
150
|
+
this.emit("accepted", key);
|
|
151
|
+
}
|
|
152
|
+
else if (this.runtime.clientId !== undefined &&
|
|
153
|
+
expectedSignoffs.includes(this.runtime.clientId)) {
|
|
154
|
+
// Emit an accept upon a new key entering pending state if our accept is expected.
|
|
155
|
+
const acceptOp = {
|
|
156
|
+
type: "accept",
|
|
157
|
+
key,
|
|
158
|
+
};
|
|
159
|
+
this.submitLocalMessage(acceptOp);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
handleIncomingAccept = (key, clientId, sequenceNumber) => {
|
|
163
|
+
const pending = this.values.get(key)?.pending;
|
|
164
|
+
if (pending === undefined) {
|
|
165
|
+
// If there is no pending value, we already accepted it, so we can ignore the accept op.
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
(0, internal_1.assert)(pending.expectedSignoffs.includes(clientId), 0x2f9 /* Unexpected accept op, client not in expectedSignoffs */);
|
|
169
|
+
// Remove the client from the expected signoffs
|
|
170
|
+
pending.expectedSignoffs = pending.expectedSignoffs.filter((expectedClientId) => expectedClientId !== clientId);
|
|
171
|
+
if (pending.expectedSignoffs.length === 0) {
|
|
172
|
+
// The pending value has settled
|
|
173
|
+
this.values.set(key, {
|
|
174
|
+
accepted: { value: pending.value, sequenceNumber },
|
|
175
|
+
pending: undefined,
|
|
176
|
+
});
|
|
177
|
+
this.emit("accepted", key);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
handleQuorumRemoveMember = (clientId) => {
|
|
181
|
+
for (const [key, { pending }] of this.values) {
|
|
182
|
+
if (pending !== undefined) {
|
|
183
|
+
pending.expectedSignoffs = pending.expectedSignoffs.filter((expectedClientId) => expectedClientId !== clientId);
|
|
184
|
+
if (pending.expectedSignoffs.length === 0) {
|
|
185
|
+
// The pending value has settled
|
|
186
|
+
const clientLeaveSequenceNumber = this.deltaManager.lastSequenceNumber;
|
|
187
|
+
this.values.set(key, {
|
|
188
|
+
accepted: {
|
|
189
|
+
value: pending.value,
|
|
190
|
+
// The sequence number of the ClientLeave message.
|
|
191
|
+
sequenceNumber: clientLeaveSequenceNumber,
|
|
192
|
+
},
|
|
193
|
+
pending: undefined,
|
|
194
|
+
});
|
|
195
|
+
this.emit("accepted", key);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
200
|
/**
|
|
201
201
|
* Create a summary for the PactMap
|
|
202
202
|
*
|
package/dist/pactMap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pactMap.js","sourceRoot":"","sources":["../src/pactMap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA4D;AAC5D,kEAA6D;AAM7D,0EAA0E;AAC1E,oEAAqE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,IAAI,EAAE,CAAC;gBACjB,KAAK,KAAK,CAAC,CAAC,CAAC;oBACZ,IAAI,CAAC,UAAU,CAAC,IAAI,CACnB,KAAK,EACL,EAAE,CAAC,GAAG,EACN,EAAE,CAAC,KAAK,EACR,EAAE,CAAC,MAAM,EACT,eAAe,CAAC,cAAc,CAC9B,CAAC;oBACF,MAAM;gBACP,CAAC;gBAED,KAAK,QAAQ,CAAC,CAAC,CAAC;oBACf,IAAI,CAAC,UAAU,CAAC,IAAI,CACnB,QAAQ,EACR,EAAE,CAAC,GAAG,EACN,eAAe,CAAC,QAAQ,EACxB,eAAe,CAAC,cAAc,CAC9B,CAAC;oBACF,MAAM;gBACP,CAAC;gBAED,OAAO,CAAC,CAAC,CAAC;oBACT,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;gBACtC,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;IAES,cAAc;QACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD;AAjVD,oCAiVC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { MessageType } from \"@fluidframework/driver-definitions/internal\";\nimport { readAndParse } from \"@fluidframework/driver-utils/internal\";\nimport type {\n\tISummaryTreeWithStats,\n\tIRuntimeMessageCollection,\n\tIRuntimeMessagesContent,\n\tISequencedMessageEnvelope,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport type { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tSharedObject,\n\tcreateSingleBlobSummary,\n} from \"@fluidframework/shared-object-base/internal\";\n\nimport type { IAcceptedPact, IPactMap, IPactMapEvents } from \"./interfaces.js\";\n\n/**\n * The accepted pact information, if any.\n */\ninterface IAcceptedPactInternal<T> {\n\t/**\n\t * The accepted value of the given type or undefined (typically in case of delete).\n\t */\n\tvalue: T | undefined;\n\n\t/**\n\t * The sequence number when the value was accepted, which will normally coincide with one of two possibilities:\n\t * - The sequence number of the \"accept\" op from the final client we expected signoff from\n\t * - The sequence number of the ClientLeave of the final client we expected signoff from\n\t *\n\t * For values set in detached state, it will be 0.\n\t */\n\tsequenceNumber: number;\n}\n\n/**\n * The pending pact information, if any.\n */\ninterface IPendingPact<T> {\n\t/**\n\t * The pending value of the given type or undefined (typically in case of delete).\n\t */\n\tvalue: T | undefined;\n\t/**\n\t * The list of clientIds that we expect \"accept\" ops from. Clients are also removed from this list if they\n\t * disconnect without accepting. When this list empties, the pending value transitions to accepted.\n\t */\n\texpectedSignoffs: string[];\n}\n\n/**\n * Internal format of the values stored in the PactMap.\n */\ntype Pact<T> =\n\t| { accepted: IAcceptedPactInternal<T>; pending: undefined }\n\t| { accepted: undefined; pending: IPendingPact<T> }\n\t| { accepted: IAcceptedPactInternal<T>; pending: IPendingPact<T> };\n\n/**\n * PactMap operation formats\n */\ninterface IPactMapSetOperation<T> {\n\ttype: \"set\";\n\tkey: string;\n\tvalue: T | undefined;\n\n\t/**\n\t * A \"set\" is only valid if it is made with knowledge of the most-recent accepted proposal - its reference\n\t * sequence number is greater than or equal to the sequence number when that prior value was accepted.\n\t *\n\t * However, we can't trust the built-in referenceSequenceNumber of the op because of resubmit on reconnect,\n\t * which will update the referenceSequenceNumber on our behalf.\n\t *\n\t * Instead we need to separately stamp the real reference sequence number on the op itself.\n\t */\n\trefSeq: number;\n}\n\ninterface IPactMapAcceptOperation {\n\ttype: \"accept\";\n\tkey: string;\n}\n\ntype IPactMapOperation<T> = IPactMapSetOperation<T> | IPactMapAcceptOperation;\n\nconst snapshotFileName = \"header\";\n\n/**\n * {@inheritDoc PactMap}\n */\nexport class PactMapClass<T = unknown>\n\textends SharedObject<IPactMapEvents>\n\timplements IPactMap<T>\n{\n\tprivate readonly values = new Map<string, Pact<T>>();\n\n\tprivate readonly incomingOp: EventEmitter = new EventEmitter();\n\n\t/**\n\t * Constructs a new PactMap. If the object is non-local an id and service interfaces will\n\t * be provided\n\t *\n\t * @param runtime - data store runtime the PactMap belongs to\n\t * @param id - optional name of the PactMap\n\t */\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_pactMap_\");\n\n\t\tthis.incomingOp.on(\"set\", this.handleIncomingSet);\n\t\tthis.incomingOp.on(\"accept\", this.handleIncomingAccept);\n\n\t\tthis.runtime.getQuorum().on(\"removeMember\", this.handleQuorumRemoveMember);\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.get}\n\t */\n\tpublic get(key: string): T | undefined {\n\t\treturn this.values.get(key)?.accepted?.value;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.getWithDetails}\n\t */\n\tpublic getWithDetails(key: string): IAcceptedPact<T> | undefined {\n\t\t// Note: We return type `IAcceptedPact` instead of `IAcceptedPactInternal` since we may want to diverge\n\t\t// the interfaces in the future.\n\t\tconst acceptedPact = this.values.get(key)?.accepted;\n\t\tif (acceptedPact === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tvalue: acceptedPact.value,\n\t\t\tacceptedSequenceNumber: acceptedPact.sequenceNumber,\n\t\t};\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.isPending}\n\t */\n\tpublic isPending(key: string): boolean {\n\t\treturn this.values.get(key)?.pending !== undefined;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.getPending}\n\t */\n\tpublic getPending(key: string): T | undefined {\n\t\treturn this.values.get(key)?.pending?.value;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.set}\n\t */\n\tpublic set(key: string, value: T | undefined): void {\n\t\tconst currentValue = this.values.get(key);\n\t\t// Early-exit if we can't submit a valid proposal (there's already a pending proposal)\n\t\tif (currentValue?.pending !== undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If not attached, we basically pretend we got an ack immediately.\n\t\tif (!this.isAttached()) {\n\t\t\t// Queueing as a microtask to permit callers to complete their callstacks before the result of the set\n\t\t\t// takes effect. This more closely resembles the pattern in the attached state, where the ack will not\n\t\t\t// be received synchronously.\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthis.handleIncomingSet(key, value, 0 /* refSeq */, 0 /* setSequenceNumber */);\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst setOp: IPactMapSetOperation<T> = {\n\t\t\ttype: \"set\",\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\trefSeq: this.deltaManager.lastSequenceNumber,\n\t\t};\n\n\t\tthis.submitLocalMessage(setOp);\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.delete}\n\t */\n\tpublic delete(key: string): void {\n\t\tconst currentValue = this.values.get(key);\n\t\t// Early-exit if:\n\t\tif (\n\t\t\t// there's nothing to delete\n\t\t\tcurrentValue === undefined ||\n\t\t\t// if something is pending (and so our proposal won't be valid)\n\t\t\tcurrentValue.pending !== undefined ||\n\t\t\t// or if the accepted value is undefined which is equivalent to already being deleted\n\t\t\tcurrentValue.accepted.value === undefined\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.set(key, undefined);\n\t}\n\n\t/**\n\t * Get a point-in-time list of clients who must sign off on values coming in for them to move from \"pending\" to\n\t * \"accepted\" state. This list is finalized for a value at the moment it goes pending (i.e. if more clients\n\t * join later, they are not added to the list of signoffs).\n\t * @returns The list of clientIds for clients who must sign off to accept the incoming pending value\n\t */\n\tprivate getSignoffClients(): string[] {\n\t\t// If detached, we don't need anyone to sign off. Otherwise, we need all currently connected clients.\n\t\treturn this.isAttached() ? [...this.runtime.getQuorum().getMembers().keys()] : [];\n\t}\n\n\tprivate readonly handleIncomingSet = (\n\t\tkey: string,\n\t\tvalue: T | undefined,\n\t\trefSeq: number,\n\t\tsetSequenceNumber: number,\n\t): void => {\n\t\tconst currentValue = this.values.get(key);\n\t\t// We use a consensus-like approach here, so a proposal is valid if the value is unset or if there is no\n\t\t// pending change and it was made with knowledge of the most recently accepted value. We'll drop invalid\n\t\t// proposals on the ground.\n\t\tconst proposalValid =\n\t\t\tcurrentValue === undefined ||\n\t\t\t(currentValue.pending === undefined && currentValue.accepted.sequenceNumber <= refSeq);\n\t\tif (!proposalValid) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst accepted = currentValue?.accepted;\n\n\t\t// We expect signoffs from all connected clients at the time the set was sequenced (including the client who\n\t\t// sent the set).\n\t\tconst expectedSignoffs = this.getSignoffClients();\n\n\t\tconst newPact: Pact<T> = {\n\t\t\taccepted,\n\t\t\tpending: {\n\t\t\t\tvalue,\n\t\t\t\texpectedSignoffs,\n\t\t\t},\n\t\t};\n\n\t\tthis.values.set(key, newPact);\n\n\t\tthis.emit(\"pending\", key);\n\n\t\tif (expectedSignoffs.length === 0) {\n\t\t\t// At least the submitting client should be amongst the expectedSignoffs, but keeping this check around\n\t\t\t// as extra protection and in case we bring back the \"submitting client implicitly accepts\" optimization.\n\t\t\tthis.values.set(key, {\n\t\t\t\taccepted: { value, sequenceNumber: setSequenceNumber },\n\t\t\t\tpending: undefined,\n\t\t\t});\n\t\t\tthis.emit(\"accepted\", key);\n\t\t} else if (\n\t\t\tthis.runtime.clientId !== undefined &&\n\t\t\texpectedSignoffs.includes(this.runtime.clientId)\n\t\t) {\n\t\t\t// Emit an accept upon a new key entering pending state if our accept is expected.\n\t\t\tconst acceptOp: IPactMapAcceptOperation = {\n\t\t\t\ttype: \"accept\",\n\t\t\t\tkey,\n\t\t\t};\n\t\t\tthis.submitLocalMessage(acceptOp);\n\t\t}\n\t};\n\n\tprivate readonly handleIncomingAccept = (\n\t\tkey: string,\n\t\tclientId: string,\n\t\tsequenceNumber: number,\n\t): void => {\n\t\tconst pending = this.values.get(key)?.pending;\n\t\tif (pending === undefined) {\n\t\t\t// If there is no pending value, we already accepted it, so we can ignore the accept op.\n\t\t\treturn;\n\t\t}\n\t\tassert(\n\t\t\tpending.expectedSignoffs.includes(clientId),\n\t\t\t0x2f9 /* Unexpected accept op, client not in expectedSignoffs */,\n\t\t);\n\n\t\t// Remove the client from the expected signoffs\n\t\tpending.expectedSignoffs = pending.expectedSignoffs.filter(\n\t\t\t(expectedClientId) => expectedClientId !== clientId,\n\t\t);\n\n\t\tif (pending.expectedSignoffs.length === 0) {\n\t\t\t// The pending value has settled\n\t\t\tthis.values.set(key, {\n\t\t\t\taccepted: { value: pending.value, sequenceNumber },\n\t\t\t\tpending: undefined,\n\t\t\t});\n\t\t\tthis.emit(\"accepted\", key);\n\t\t}\n\t};\n\n\tprivate readonly handleQuorumRemoveMember = (clientId: string): void => {\n\t\tfor (const [key, { pending }] of this.values) {\n\t\t\tif (pending !== undefined) {\n\t\t\t\tpending.expectedSignoffs = pending.expectedSignoffs.filter(\n\t\t\t\t\t(expectedClientId) => expectedClientId !== clientId,\n\t\t\t\t);\n\n\t\t\t\tif (pending.expectedSignoffs.length === 0) {\n\t\t\t\t\t// The pending value has settled\n\t\t\t\t\tconst clientLeaveSequenceNumber = this.deltaManager.lastSequenceNumber;\n\t\t\t\t\tthis.values.set(key, {\n\t\t\t\t\t\taccepted: {\n\t\t\t\t\t\t\tvalue: pending.value,\n\t\t\t\t\t\t\t// The sequence number of the ClientLeave message.\n\t\t\t\t\t\t\tsequenceNumber: clientLeaveSequenceNumber,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tpending: undefined,\n\t\t\t\t\t});\n\t\t\t\t\tthis.emit(\"accepted\", key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\t/**\n\t * Create a summary for the PactMap\n\t *\n\t * @returns the summary of the current state of the PactMap\n\t */\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tconst allEntries = [...this.values.entries()];\n\t\treturn createSingleBlobSummary(snapshotFileName, JSON.stringify(allEntries));\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst content = await readAndParse<[string, Pact<T>][]>(storage, snapshotFileName);\n\t\tfor (const [key, value] of content) {\n\t\t\tthis.values.set(key, value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.initializeLocalCore}\n\t */\n\tprotected initializeLocalCore(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.onDisconnect}\n\t */\n\tprotected onDisconnect(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.reSubmitCore}\n\t */\n\tprotected reSubmitCore(content: unknown, localOpMetadata: unknown): void {\n\t\tconst pactMapOp = content as IPactMapOperation<T>;\n\n\t\t// Filter out set messages that have no chance of being accepted because there's another value pending\n\t\t// or another value was accepted while we were disconnected.\n\t\tconst currentValue = this.values.get(pactMapOp.key);\n\t\tif (\n\t\t\tpactMapOp.type === \"set\" &&\n\t\t\tcurrentValue !== undefined &&\n\t\t\t(currentValue.pending !== undefined ||\n\t\t\t\tpactMapOp.refSeq < currentValue.accepted?.sequenceNumber)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Otherwise we can resubmit\n\t\tthis.submitLocalMessage(pactMapOp, localOpMetadata);\n\t}\n\n\tprotected override processMessagesCore(messagesCollection: IRuntimeMessageCollection): void {\n\t\tconst { envelope, local, messagesContent } = messagesCollection;\n\t\tfor (const messageContent of messagesContent) {\n\t\t\tthis.processMessage(envelope, messageContent, local);\n\t\t}\n\t}\n\n\tprivate processMessage(\n\t\tmessageEnvelope: ISequencedMessageEnvelope,\n\t\tmessageContent: IRuntimeMessagesContent,\n\t\tlocal: boolean,\n\t): void {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n\t\tif (messageEnvelope.type === MessageType.Operation) {\n\t\t\tconst op = messageContent.contents as IPactMapOperation<T>;\n\n\t\t\tswitch (op.type) {\n\t\t\t\tcase \"set\": {\n\t\t\t\t\tthis.incomingOp.emit(\n\t\t\t\t\t\t\"set\",\n\t\t\t\t\t\top.key,\n\t\t\t\t\t\top.value,\n\t\t\t\t\t\top.refSeq,\n\t\t\t\t\t\tmessageEnvelope.sequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase \"accept\": {\n\t\t\t\t\tthis.incomingOp.emit(\n\t\t\t\t\t\t\"accept\",\n\t\t\t\t\t\top.key,\n\t\t\t\t\t\tmessageEnvelope.clientId,\n\t\t\t\t\t\tmessageEnvelope.sequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new Error(\"Unknown operation\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected applyStashedOp(): void {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pactMap.js","sourceRoot":"","sources":["../src/pactMap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA4D;AAC5D,kEAA6D;AAM7D,0EAA0E;AAC1E,oEAAqE;AAQrE,0EAGqD;AAyErD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;GAEG;AACH,MAAa,YACZ,SAAQ,uBAA4B;IAGnB,MAAM,GAAG,IAAI,GAAG,EAAmB,CAAC;IAEpC,UAAU,GAAiB,IAAI,2BAAY,EAAE,CAAC;IAE/D;;;;;;OAMG;IACH,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B;QAE9B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;QAEjD,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,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,CAAC;gBAED,OAAO,CAAC,CAAC,CAAC;oBACT,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;gBACtC,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;IAES,cAAc;QACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD;AAjVD,oCAiVC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { MessageType } from \"@fluidframework/driver-definitions/internal\";\nimport { readAndParse } from \"@fluidframework/driver-utils/internal\";\nimport type {\n\tISummaryTreeWithStats,\n\tIRuntimeMessageCollection,\n\tIRuntimeMessagesContent,\n\tISequencedMessageEnvelope,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport type { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tSharedObject,\n\tcreateSingleBlobSummary,\n} from \"@fluidframework/shared-object-base/internal\";\n\nimport type { IAcceptedPact, IPactMap, IPactMapEvents } from \"./interfaces.js\";\n\n/**\n * The accepted pact information, if any.\n */\ninterface IAcceptedPactInternal<T> {\n\t/**\n\t * The accepted value of the given type or undefined (typically in case of delete).\n\t */\n\tvalue: T | undefined;\n\n\t/**\n\t * The sequence number when the value was accepted, which will normally coincide with one of two possibilities:\n\t * - The sequence number of the \"accept\" op from the final client we expected signoff from\n\t * - The sequence number of the ClientLeave of the final client we expected signoff from\n\t *\n\t * For values set in detached state, it will be 0.\n\t */\n\tsequenceNumber: number;\n}\n\n/**\n * The pending pact information, if any.\n */\ninterface IPendingPact<T> {\n\t/**\n\t * The pending value of the given type or undefined (typically in case of delete).\n\t */\n\tvalue: T | undefined;\n\t/**\n\t * The list of clientIds that we expect \"accept\" ops from. Clients are also removed from this list if they\n\t * disconnect without accepting. When this list empties, the pending value transitions to accepted.\n\t */\n\texpectedSignoffs: string[];\n}\n\n/**\n * Internal format of the values stored in the PactMap.\n */\ntype Pact<T> =\n\t| { accepted: IAcceptedPactInternal<T>; pending: undefined }\n\t| { accepted: undefined; pending: IPendingPact<T> }\n\t| { accepted: IAcceptedPactInternal<T>; pending: IPendingPact<T> };\n\n/**\n * PactMap operation formats\n */\ninterface IPactMapSetOperation<T> {\n\ttype: \"set\";\n\tkey: string;\n\tvalue: T | undefined;\n\n\t/**\n\t * A \"set\" is only valid if it is made with knowledge of the most-recent accepted proposal - its reference\n\t * sequence number is greater than or equal to the sequence number when that prior value was accepted.\n\t *\n\t * However, we can't trust the built-in referenceSequenceNumber of the op because of resubmit on reconnect,\n\t * which will update the referenceSequenceNumber on our behalf.\n\t *\n\t * Instead we need to separately stamp the real reference sequence number on the op itself.\n\t */\n\trefSeq: number;\n}\n\ninterface IPactMapAcceptOperation {\n\ttype: \"accept\";\n\tkey: string;\n}\n\ntype IPactMapOperation<T> = IPactMapSetOperation<T> | IPactMapAcceptOperation;\n\nconst snapshotFileName = \"header\";\n\n/**\n * {@inheritDoc PactMap}\n */\nexport class PactMapClass<T = unknown>\n\textends SharedObject<IPactMapEvents>\n\timplements IPactMap<T>\n{\n\tprivate readonly values = new Map<string, Pact<T>>();\n\n\tprivate readonly incomingOp: EventEmitter = new EventEmitter();\n\n\t/**\n\t * Constructs a new PactMap. If the object is non-local an id and service interfaces will\n\t * be provided\n\t *\n\t * @param runtime - data store runtime the PactMap belongs to\n\t * @param id - optional name of the PactMap\n\t */\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_pactMap_\");\n\n\t\tthis.incomingOp.on(\"set\", this.handleIncomingSet);\n\t\tthis.incomingOp.on(\"accept\", this.handleIncomingAccept);\n\n\t\tthis.runtime.getQuorum().on(\"removeMember\", this.handleQuorumRemoveMember);\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.get}\n\t */\n\tpublic get(key: string): T | undefined {\n\t\treturn this.values.get(key)?.accepted?.value;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.getWithDetails}\n\t */\n\tpublic getWithDetails(key: string): IAcceptedPact<T> | undefined {\n\t\t// Note: We return type `IAcceptedPact` instead of `IAcceptedPactInternal` since we may want to diverge\n\t\t// the interfaces in the future.\n\t\tconst acceptedPact = this.values.get(key)?.accepted;\n\t\tif (acceptedPact === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tvalue: acceptedPact.value,\n\t\t\tacceptedSequenceNumber: acceptedPact.sequenceNumber,\n\t\t};\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.isPending}\n\t */\n\tpublic isPending(key: string): boolean {\n\t\treturn this.values.get(key)?.pending !== undefined;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.getPending}\n\t */\n\tpublic getPending(key: string): T | undefined {\n\t\treturn this.values.get(key)?.pending?.value;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.set}\n\t */\n\tpublic set(key: string, value: T | undefined): void {\n\t\tconst currentValue = this.values.get(key);\n\t\t// Early-exit if we can't submit a valid proposal (there's already a pending proposal)\n\t\tif (currentValue?.pending !== undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If not attached, we basically pretend we got an ack immediately.\n\t\tif (!this.isAttached()) {\n\t\t\t// Queueing as a microtask to permit callers to complete their callstacks before the result of the set\n\t\t\t// takes effect. This more closely resembles the pattern in the attached state, where the ack will not\n\t\t\t// be received synchronously.\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthis.handleIncomingSet(key, value, 0 /* refSeq */, 0 /* setSequenceNumber */);\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst setOp: IPactMapSetOperation<T> = {\n\t\t\ttype: \"set\",\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\trefSeq: this.deltaManager.lastSequenceNumber,\n\t\t};\n\n\t\tthis.submitLocalMessage(setOp);\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.delete}\n\t */\n\tpublic delete(key: string): void {\n\t\tconst currentValue = this.values.get(key);\n\t\t// Early-exit if:\n\t\tif (\n\t\t\t// there's nothing to delete\n\t\t\tcurrentValue === undefined ||\n\t\t\t// if something is pending (and so our proposal won't be valid)\n\t\t\tcurrentValue.pending !== undefined ||\n\t\t\t// or if the accepted value is undefined which is equivalent to already being deleted\n\t\t\tcurrentValue.accepted.value === undefined\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.set(key, undefined);\n\t}\n\n\t/**\n\t * Get a point-in-time list of clients who must sign off on values coming in for them to move from \"pending\" to\n\t * \"accepted\" state. This list is finalized for a value at the moment it goes pending (i.e. if more clients\n\t * join later, they are not added to the list of signoffs).\n\t * @returns The list of clientIds for clients who must sign off to accept the incoming pending value\n\t */\n\tprivate getSignoffClients(): string[] {\n\t\t// If detached, we don't need anyone to sign off. Otherwise, we need all currently connected clients.\n\t\treturn this.isAttached() ? [...this.runtime.getQuorum().getMembers().keys()] : [];\n\t}\n\n\tprivate readonly handleIncomingSet = (\n\t\tkey: string,\n\t\tvalue: T | undefined,\n\t\trefSeq: number,\n\t\tsetSequenceNumber: number,\n\t): void => {\n\t\tconst currentValue = this.values.get(key);\n\t\t// We use a consensus-like approach here, so a proposal is valid if the value is unset or if there is no\n\t\t// pending change and it was made with knowledge of the most recently accepted value. We'll drop invalid\n\t\t// proposals on the ground.\n\t\tconst proposalValid =\n\t\t\tcurrentValue === undefined ||\n\t\t\t(currentValue.pending === undefined && currentValue.accepted.sequenceNumber <= refSeq);\n\t\tif (!proposalValid) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst accepted = currentValue?.accepted;\n\n\t\t// We expect signoffs from all connected clients at the time the set was sequenced (including the client who\n\t\t// sent the set).\n\t\tconst expectedSignoffs = this.getSignoffClients();\n\n\t\tconst newPact: Pact<T> = {\n\t\t\taccepted,\n\t\t\tpending: {\n\t\t\t\tvalue,\n\t\t\t\texpectedSignoffs,\n\t\t\t},\n\t\t};\n\n\t\tthis.values.set(key, newPact);\n\n\t\tthis.emit(\"pending\", key);\n\n\t\tif (expectedSignoffs.length === 0) {\n\t\t\t// At least the submitting client should be amongst the expectedSignoffs, but keeping this check around\n\t\t\t// as extra protection and in case we bring back the \"submitting client implicitly accepts\" optimization.\n\t\t\tthis.values.set(key, {\n\t\t\t\taccepted: { value, sequenceNumber: setSequenceNumber },\n\t\t\t\tpending: undefined,\n\t\t\t});\n\t\t\tthis.emit(\"accepted\", key);\n\t\t} else if (\n\t\t\tthis.runtime.clientId !== undefined &&\n\t\t\texpectedSignoffs.includes(this.runtime.clientId)\n\t\t) {\n\t\t\t// Emit an accept upon a new key entering pending state if our accept is expected.\n\t\t\tconst acceptOp: IPactMapAcceptOperation = {\n\t\t\t\ttype: \"accept\",\n\t\t\t\tkey,\n\t\t\t};\n\t\t\tthis.submitLocalMessage(acceptOp);\n\t\t}\n\t};\n\n\tprivate readonly handleIncomingAccept = (\n\t\tkey: string,\n\t\tclientId: string,\n\t\tsequenceNumber: number,\n\t): void => {\n\t\tconst pending = this.values.get(key)?.pending;\n\t\tif (pending === undefined) {\n\t\t\t// If there is no pending value, we already accepted it, so we can ignore the accept op.\n\t\t\treturn;\n\t\t}\n\t\tassert(\n\t\t\tpending.expectedSignoffs.includes(clientId),\n\t\t\t0x2f9 /* Unexpected accept op, client not in expectedSignoffs */,\n\t\t);\n\n\t\t// Remove the client from the expected signoffs\n\t\tpending.expectedSignoffs = pending.expectedSignoffs.filter(\n\t\t\t(expectedClientId) => expectedClientId !== clientId,\n\t\t);\n\n\t\tif (pending.expectedSignoffs.length === 0) {\n\t\t\t// The pending value has settled\n\t\t\tthis.values.set(key, {\n\t\t\t\taccepted: { value: pending.value, sequenceNumber },\n\t\t\t\tpending: undefined,\n\t\t\t});\n\t\t\tthis.emit(\"accepted\", key);\n\t\t}\n\t};\n\n\tprivate readonly handleQuorumRemoveMember = (clientId: string): void => {\n\t\tfor (const [key, { pending }] of this.values) {\n\t\t\tif (pending !== undefined) {\n\t\t\t\tpending.expectedSignoffs = pending.expectedSignoffs.filter(\n\t\t\t\t\t(expectedClientId) => expectedClientId !== clientId,\n\t\t\t\t);\n\n\t\t\t\tif (pending.expectedSignoffs.length === 0) {\n\t\t\t\t\t// The pending value has settled\n\t\t\t\t\tconst clientLeaveSequenceNumber = this.deltaManager.lastSequenceNumber;\n\t\t\t\t\tthis.values.set(key, {\n\t\t\t\t\t\taccepted: {\n\t\t\t\t\t\t\tvalue: pending.value,\n\t\t\t\t\t\t\t// The sequence number of the ClientLeave message.\n\t\t\t\t\t\t\tsequenceNumber: clientLeaveSequenceNumber,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tpending: undefined,\n\t\t\t\t\t});\n\t\t\t\t\tthis.emit(\"accepted\", key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\t/**\n\t * Create a summary for the PactMap\n\t *\n\t * @returns the summary of the current state of the PactMap\n\t */\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tconst allEntries = [...this.values.entries()];\n\t\treturn createSingleBlobSummary(snapshotFileName, JSON.stringify(allEntries));\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst content = await readAndParse<[string, Pact<T>][]>(storage, snapshotFileName);\n\t\tfor (const [key, value] of content) {\n\t\t\tthis.values.set(key, value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.initializeLocalCore}\n\t */\n\tprotected initializeLocalCore(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.onDisconnect}\n\t */\n\tprotected onDisconnect(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.reSubmitCore}\n\t */\n\tprotected reSubmitCore(content: unknown, localOpMetadata: unknown): void {\n\t\tconst pactMapOp = content as IPactMapOperation<T>;\n\n\t\t// Filter out set messages that have no chance of being accepted because there's another value pending\n\t\t// or another value was accepted while we were disconnected.\n\t\tconst currentValue = this.values.get(pactMapOp.key);\n\t\tif (\n\t\t\tpactMapOp.type === \"set\" &&\n\t\t\tcurrentValue !== undefined &&\n\t\t\t(currentValue.pending !== undefined ||\n\t\t\t\tpactMapOp.refSeq < currentValue.accepted?.sequenceNumber)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Otherwise we can resubmit\n\t\tthis.submitLocalMessage(pactMapOp, localOpMetadata);\n\t}\n\n\tprotected override processMessagesCore(messagesCollection: IRuntimeMessageCollection): void {\n\t\tconst { envelope, local, messagesContent } = messagesCollection;\n\t\tfor (const messageContent of messagesContent) {\n\t\t\tthis.processMessage(envelope, messageContent, local);\n\t\t}\n\t}\n\n\tprivate processMessage(\n\t\tmessageEnvelope: ISequencedMessageEnvelope,\n\t\tmessageContent: IRuntimeMessagesContent,\n\t\tlocal: boolean,\n\t): void {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n\t\tif (messageEnvelope.type === MessageType.Operation) {\n\t\t\tconst op = messageContent.contents as IPactMapOperation<T>;\n\n\t\t\tswitch (op.type) {\n\t\t\t\tcase \"set\": {\n\t\t\t\t\tthis.incomingOp.emit(\n\t\t\t\t\t\t\"set\",\n\t\t\t\t\t\top.key,\n\t\t\t\t\t\top.value,\n\t\t\t\t\t\top.refSeq,\n\t\t\t\t\t\tmessageEnvelope.sequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase \"accept\": {\n\t\t\t\t\tthis.incomingOp.emit(\n\t\t\t\t\t\t\"accept\",\n\t\t\t\t\t\top.key,\n\t\t\t\t\t\tmessageEnvelope.clientId,\n\t\t\t\t\t\tmessageEnvelope.sequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new Error(\"Unknown operation\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected applyStashedOp(): void {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
|
package/dist/pactMapFactory.d.ts
CHANGED
|
@@ -77,5 +77,5 @@ export declare class PactMapFactory implements IChannelFactory<IPactMap> {
|
|
|
77
77
|
* ```
|
|
78
78
|
* @internal
|
|
79
79
|
*/
|
|
80
|
-
export declare const PactMap: import("@fluidframework/shared-object-base
|
|
80
|
+
export declare const PactMap: import("@fluidframework/shared-object-base", { with: { "resolution-mode": "import" } }).ISharedObjectKind<IPactMap<unknown>> & import("@fluidframework/shared-object-base", { with: { "resolution-mode": "import" } }).SharedObjectKind<IPactMap<unknown>>;
|
|
81
81
|
//# sourceMappingURL=pactMapFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pactMapFactory.d.ts","sourceRoot":"","sources":["../src/pactMapFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,kBAAkB,EAClB,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,MAAM,gDAAgD,CAAC;AAGxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAIhD;;GAEG;AACH,qBAAa,cAAe,YAAW,eAAe,CAAC,QAAQ,CAAC;IAI/D,gBAAuB,IAAI,gDAAgD;IAE3E,gBAAuB,UAAU,EAAE,kBAAkB,CAInD;IAEF,IAAW,IAAI,IAAI,MAAM,CAExB;IAED,IAAW,UAAU,IAAI,kBAAkB,CAE1C;IAED;;OAEG;IACU,IAAI,CAChB,OAAO,EAAE,sBAAsB,EAC/B,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,gBAAgB,EAC1B,UAAU,EAAE,kBAAkB,GAC5B,OAAO,CAAC,QAAQ,CAAC;IAMb,MAAM,CAAC,QAAQ,EAAE,sBAAsB,EAAE,EAAE,EAAE,MAAM,GAAG,QAAQ;CAKrE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"pactMapFactory.d.ts","sourceRoot":"","sources":["../src/pactMapFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,kBAAkB,EAClB,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,MAAM,gDAAgD,CAAC;AAGxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAIhD;;GAEG;AACH,qBAAa,cAAe,YAAW,eAAe,CAAC,QAAQ,CAAC;IAI/D,gBAAuB,IAAI,gDAAgD;IAE3E,gBAAuB,UAAU,EAAE,kBAAkB,CAInD;IAEF,IAAW,IAAI,IAAI,MAAM,CAExB;IAED,IAAW,UAAU,IAAI,kBAAkB,CAE1C;IAED;;OAEG;IACU,IAAI,CAChB,OAAO,EAAE,sBAAsB,EAC/B,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,gBAAgB,EAC1B,UAAU,EAAE,kBAAkB,GAC5B,OAAO,CAAC,QAAQ,CAAC;IAMb,MAAM,CAAC,QAAQ,EAAE,sBAAsB,EAAE,EAAE,EAAE,MAAM,GAAG,QAAQ;CAKrE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,eAAO,MAAM,OAAO,4PAAyC,CAAC"}
|
package/dist/pactMapFactory.js
CHANGED
|
@@ -12,6 +12,15 @@ const pactMap_js_1 = require("./pactMap.js");
|
|
|
12
12
|
* The factory that produces the PactMap
|
|
13
13
|
*/
|
|
14
14
|
class PactMapFactory {
|
|
15
|
+
// New type string, to be activated once the migration has been fully shipped dark and is safe to flip.
|
|
16
|
+
// See LegacyTypeAwareRegistry in packages/runtime/datastore/src/dataStoreRuntime.ts.
|
|
17
|
+
// public static readonly Type = "pact-map";
|
|
18
|
+
static Type = "https://graph.microsoft.com/types/pact-map";
|
|
19
|
+
static Attributes = {
|
|
20
|
+
type: PactMapFactory.Type,
|
|
21
|
+
snapshotFormatVersion: "0.1",
|
|
22
|
+
packageVersion: packageVersion_js_1.pkgVersion,
|
|
23
|
+
};
|
|
15
24
|
get type() {
|
|
16
25
|
return PactMapFactory.Type;
|
|
17
26
|
}
|
|
@@ -33,15 +42,6 @@ class PactMapFactory {
|
|
|
33
42
|
}
|
|
34
43
|
}
|
|
35
44
|
exports.PactMapFactory = PactMapFactory;
|
|
36
|
-
// New type string, to be activated once the migration has been fully shipped dark and is safe to flip.
|
|
37
|
-
// See LegacyTypeAwareRegistry in packages/runtime/datastore/src/dataStoreRuntime.ts.
|
|
38
|
-
// public static readonly Type = "pact-map";
|
|
39
|
-
PactMapFactory.Type = "https://graph.microsoft.com/types/pact-map";
|
|
40
|
-
PactMapFactory.Attributes = {
|
|
41
|
-
type: PactMapFactory.Type,
|
|
42
|
-
snapshotFormatVersion: "0.1",
|
|
43
|
-
packageVersion: packageVersion_js_1.pkgVersion,
|
|
44
|
-
};
|
|
45
45
|
/**
|
|
46
46
|
* The PactMap distributed data structure provides key/value storage with a cautious conflict resolution strategy.
|
|
47
47
|
* This strategy optimizes for all clients being aware of the change prior to considering the value as accepted.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pactMapFactory.js","sourceRoot":"","sources":["../src/pactMapFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,0EAAqF;AAGrF,2DAAiD;AACjD,6CAA4C;AAE5C;;GAEG;AACH,MAAa,cAAc;
|
|
1
|
+
{"version":3,"file":"pactMapFactory.js","sourceRoot":"","sources":["../src/pactMapFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,0EAAqF;AAGrF,2DAAiD;AACjD,6CAA4C;AAE5C;;GAEG;AACH,MAAa,cAAc;IAC1B,uGAAuG;IACvG,qFAAqF;IACrF,4CAA4C;IACrC,MAAM,CAAU,IAAI,GAAG,4CAA4C,CAAC;IAEpE,MAAM,CAAU,UAAU,GAAuB;QACvD,IAAI,EAAE,cAAc,CAAC,IAAI;QACzB,qBAAqB,EAAE,KAAK;QAC5B,cAAc,EAAE,8BAAU;KAC1B,CAAC;IAEF,IAAW,IAAI;QACd,OAAO,cAAc,CAAC,IAAI,CAAC;IAC5B,CAAC;IAED,IAAW,UAAU;QACpB,OAAO,cAAc,CAAC,UAAU,CAAC;IAClC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAI,CAChB,OAA+B,EAC/B,EAAU,EACV,QAA0B,EAC1B,UAA8B;QAE9B,MAAM,OAAO,GAAG,IAAI,yBAAY,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QAC1D,MAAM,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7B,OAAO,OAAO,CAAC;IAChB,CAAC;IAEM,MAAM,CAAC,QAAgC,EAAE,EAAU;QACzD,MAAM,OAAO,GAAG,IAAI,yBAAY,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAChE,OAAO,CAAC,eAAe,EAAE,CAAC;QAC1B,OAAO,OAAO,CAAC;IAChB,CAAC;;AAtCF,wCAuCC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACU,QAAA,OAAO,GAAG,IAAA,iCAAsB,EAAC,cAAc,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tIChannelAttributes,\n\tIChannelFactory,\n\tIFluidDataStoreRuntime,\n\tIChannelServices,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { createSharedObjectKind } from \"@fluidframework/shared-object-base/internal\";\n\nimport type { IPactMap } from \"./interfaces.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\nimport { PactMapClass } from \"./pactMap.js\";\n\n/**\n * The factory that produces the PactMap\n */\nexport class PactMapFactory implements IChannelFactory<IPactMap> {\n\t// New type string, to be activated once the migration has been fully shipped dark and is safe to flip.\n\t// See LegacyTypeAwareRegistry in packages/runtime/datastore/src/dataStoreRuntime.ts.\n\t// public static readonly Type = \"pact-map\";\n\tpublic static readonly Type = \"https://graph.microsoft.com/types/pact-map\";\n\n\tpublic static readonly Attributes: IChannelAttributes = {\n\t\ttype: PactMapFactory.Type,\n\t\tsnapshotFormatVersion: \"0.1\",\n\t\tpackageVersion: pkgVersion,\n\t};\n\n\tpublic get type(): string {\n\t\treturn PactMapFactory.Type;\n\t}\n\n\tpublic get attributes(): IChannelAttributes {\n\t\treturn PactMapFactory.Attributes;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}\n\t */\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tid: string,\n\t\tservices: IChannelServices,\n\t\tattributes: IChannelAttributes,\n\t): Promise<IPactMap> {\n\t\tconst pactMap = new PactMapClass(id, runtime, attributes);\n\t\tawait pactMap.load(services);\n\t\treturn pactMap;\n\t}\n\n\tpublic create(document: IFluidDataStoreRuntime, id: string): IPactMap {\n\t\tconst pactMap = new PactMapClass(id, document, this.attributes);\n\t\tpactMap.initializeLocal();\n\t\treturn pactMap;\n\t}\n}\n\n/**\n * The PactMap distributed data structure provides key/value storage with a cautious conflict resolution strategy.\n * This strategy optimizes for all clients being aware of the change prior to considering the value as accepted.\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 * To create a `PactMap`, call the static create method:\n *\n * ```typescript\n * const pactMap = PactMap.create(this.runtime, id);\n * ```\n *\n * ### Usage\n *\n * Setting and reading values is somewhat similar to a `SharedMap`. However, because the acceptance strategy\n * cannot be resolved until other clients have witnessed the set, the new value will only be reflected in the data\n * after the consensus is reached.\n *\n * ```typescript\n * pactMap.on(\"pending\", (key: string) => {\n * console.log(pactMap.getPending(key));\n * });\n * pactMap.on(\"accepted\", (key: string) => {\n * console.log(pactMap.get(key));\n * });\n * pactMap.set(\"myKey\", \"myValue\");\n *\n * // Reading from the pact map prior to the async operation's completion will still return the old value.\n * console.log(pactMap.get(\"myKey\"));\n * ```\n *\n * The acceptance process has two stages. When an op indicating a client's attempt to set a value is sequenced,\n * we first verify that it was set with knowledge of the most recently accepted value (consensus-like FWW). If it\n * meets this bar, then the value is \"pending\". During this time, clients may observe the pending value and act\n * upon it, but should be aware that not all other clients may have witnessed the value yet. Once all clients\n * that were connected at the time of the value being set have explicitly acknowledged the new value, the value\n * becomes \"accepted\". Once the value is accepted, it once again becomes possible to set the value, again with\n * consensus-like FWW resolution.\n *\n * Since all connected clients must explicitly accept the new value, it is important that all connected clients\n * have the PactMap loaded, including e.g. the summarizing client. Otherwise, those clients who have not loaded\n * the PactMap will not be responding to proposals and delay their acceptance (until they disconnect, which implicitly\n * removes them from consideration). The easiest way to ensure all clients load the PactMap is to instantiate it\n * as part of instantiating the IRuntime for the container (containerHasInitialized if using Aqueduct).\n *\n * ### Eventing\n *\n * `PactMap` is an `EventEmitter`, and will emit events when a new value is accepted for a key.\n *\n * ```typescript\n * pactMap.on(\"accept\", (key: string) => {\n * console.log(`New value was accepted for key: ${ key }, value: ${ pactMap.get(key) }`);\n * });\n * ```\n * @internal\n */\nexport const PactMap = createSharedObjectKind(PactMapFactory);\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluid-experimental/pact-map";
|
|
8
|
-
export declare const pkgVersion = "
|
|
8
|
+
export declare const pkgVersion = "3.0.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,iCAAiC,CAAC;AACtD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,iCAAiC,CAAC;AACtD,eAAO,MAAM,UAAU,UAAU,CAAC"}
|
package/lib/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,8BAA8B,CAAC;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,8BAA8B,CAAC;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluid-experimental/pact-map\";\nexport const pkgVersion = \"3.0.0\";\n"]}
|
package/lib/pactMap.js
CHANGED
|
@@ -12,6 +12,8 @@ const snapshotFileName = "header";
|
|
|
12
12
|
* {@inheritDoc PactMap}
|
|
13
13
|
*/
|
|
14
14
|
export class PactMapClass extends SharedObject {
|
|
15
|
+
values = new Map();
|
|
16
|
+
incomingOp = new EventEmitter();
|
|
15
17
|
/**
|
|
16
18
|
* Constructs a new PactMap. If the object is non-local an id and service interfaces will
|
|
17
19
|
* be provided
|
|
@@ -21,88 +23,6 @@ export class PactMapClass extends SharedObject {
|
|
|
21
23
|
*/
|
|
22
24
|
constructor(id, runtime, attributes) {
|
|
23
25
|
super(id, runtime, attributes, "fluid_pactMap_");
|
|
24
|
-
this.values = new Map();
|
|
25
|
-
this.incomingOp = new EventEmitter();
|
|
26
|
-
this.handleIncomingSet = (key, value, refSeq, setSequenceNumber) => {
|
|
27
|
-
const currentValue = this.values.get(key);
|
|
28
|
-
// We use a consensus-like approach here, so a proposal is valid if the value is unset or if there is no
|
|
29
|
-
// pending change and it was made with knowledge of the most recently accepted value. We'll drop invalid
|
|
30
|
-
// proposals on the ground.
|
|
31
|
-
const proposalValid = currentValue === undefined ||
|
|
32
|
-
(currentValue.pending === undefined && currentValue.accepted.sequenceNumber <= refSeq);
|
|
33
|
-
if (!proposalValid) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const accepted = currentValue?.accepted;
|
|
37
|
-
// We expect signoffs from all connected clients at the time the set was sequenced (including the client who
|
|
38
|
-
// sent the set).
|
|
39
|
-
const expectedSignoffs = this.getSignoffClients();
|
|
40
|
-
const newPact = {
|
|
41
|
-
accepted,
|
|
42
|
-
pending: {
|
|
43
|
-
value,
|
|
44
|
-
expectedSignoffs,
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
this.values.set(key, newPact);
|
|
48
|
-
this.emit("pending", key);
|
|
49
|
-
if (expectedSignoffs.length === 0) {
|
|
50
|
-
// At least the submitting client should be amongst the expectedSignoffs, but keeping this check around
|
|
51
|
-
// as extra protection and in case we bring back the "submitting client implicitly accepts" optimization.
|
|
52
|
-
this.values.set(key, {
|
|
53
|
-
accepted: { value, sequenceNumber: setSequenceNumber },
|
|
54
|
-
pending: undefined,
|
|
55
|
-
});
|
|
56
|
-
this.emit("accepted", key);
|
|
57
|
-
}
|
|
58
|
-
else if (this.runtime.clientId !== undefined &&
|
|
59
|
-
expectedSignoffs.includes(this.runtime.clientId)) {
|
|
60
|
-
// Emit an accept upon a new key entering pending state if our accept is expected.
|
|
61
|
-
const acceptOp = {
|
|
62
|
-
type: "accept",
|
|
63
|
-
key,
|
|
64
|
-
};
|
|
65
|
-
this.submitLocalMessage(acceptOp);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
this.handleIncomingAccept = (key, clientId, sequenceNumber) => {
|
|
69
|
-
const pending = this.values.get(key)?.pending;
|
|
70
|
-
if (pending === undefined) {
|
|
71
|
-
// If there is no pending value, we already accepted it, so we can ignore the accept op.
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
assert(pending.expectedSignoffs.includes(clientId), 0x2f9 /* Unexpected accept op, client not in expectedSignoffs */);
|
|
75
|
-
// Remove the client from the expected signoffs
|
|
76
|
-
pending.expectedSignoffs = pending.expectedSignoffs.filter((expectedClientId) => expectedClientId !== clientId);
|
|
77
|
-
if (pending.expectedSignoffs.length === 0) {
|
|
78
|
-
// The pending value has settled
|
|
79
|
-
this.values.set(key, {
|
|
80
|
-
accepted: { value: pending.value, sequenceNumber },
|
|
81
|
-
pending: undefined,
|
|
82
|
-
});
|
|
83
|
-
this.emit("accepted", key);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
this.handleQuorumRemoveMember = (clientId) => {
|
|
87
|
-
for (const [key, { pending }] of this.values) {
|
|
88
|
-
if (pending !== undefined) {
|
|
89
|
-
pending.expectedSignoffs = pending.expectedSignoffs.filter((expectedClientId) => expectedClientId !== clientId);
|
|
90
|
-
if (pending.expectedSignoffs.length === 0) {
|
|
91
|
-
// The pending value has settled
|
|
92
|
-
const clientLeaveSequenceNumber = this.deltaManager.lastSequenceNumber;
|
|
93
|
-
this.values.set(key, {
|
|
94
|
-
accepted: {
|
|
95
|
-
value: pending.value,
|
|
96
|
-
// The sequence number of the ClientLeave message.
|
|
97
|
-
sequenceNumber: clientLeaveSequenceNumber,
|
|
98
|
-
},
|
|
99
|
-
pending: undefined,
|
|
100
|
-
});
|
|
101
|
-
this.emit("accepted", key);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
26
|
this.incomingOp.on("set", this.handleIncomingSet);
|
|
107
27
|
this.incomingOp.on("accept", this.handleIncomingAccept);
|
|
108
28
|
this.runtime.getQuorum().on("removeMember", this.handleQuorumRemoveMember);
|
|
@@ -194,6 +114,86 @@ export class PactMapClass extends SharedObject {
|
|
|
194
114
|
// If detached, we don't need anyone to sign off. Otherwise, we need all currently connected clients.
|
|
195
115
|
return this.isAttached() ? [...this.runtime.getQuorum().getMembers().keys()] : [];
|
|
196
116
|
}
|
|
117
|
+
handleIncomingSet = (key, value, refSeq, setSequenceNumber) => {
|
|
118
|
+
const currentValue = this.values.get(key);
|
|
119
|
+
// We use a consensus-like approach here, so a proposal is valid if the value is unset or if there is no
|
|
120
|
+
// pending change and it was made with knowledge of the most recently accepted value. We'll drop invalid
|
|
121
|
+
// proposals on the ground.
|
|
122
|
+
const proposalValid = currentValue === undefined ||
|
|
123
|
+
(currentValue.pending === undefined && currentValue.accepted.sequenceNumber <= refSeq);
|
|
124
|
+
if (!proposalValid) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const accepted = currentValue?.accepted;
|
|
128
|
+
// We expect signoffs from all connected clients at the time the set was sequenced (including the client who
|
|
129
|
+
// sent the set).
|
|
130
|
+
const expectedSignoffs = this.getSignoffClients();
|
|
131
|
+
const newPact = {
|
|
132
|
+
accepted,
|
|
133
|
+
pending: {
|
|
134
|
+
value,
|
|
135
|
+
expectedSignoffs,
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
this.values.set(key, newPact);
|
|
139
|
+
this.emit("pending", key);
|
|
140
|
+
if (expectedSignoffs.length === 0) {
|
|
141
|
+
// At least the submitting client should be amongst the expectedSignoffs, but keeping this check around
|
|
142
|
+
// as extra protection and in case we bring back the "submitting client implicitly accepts" optimization.
|
|
143
|
+
this.values.set(key, {
|
|
144
|
+
accepted: { value, sequenceNumber: setSequenceNumber },
|
|
145
|
+
pending: undefined,
|
|
146
|
+
});
|
|
147
|
+
this.emit("accepted", key);
|
|
148
|
+
}
|
|
149
|
+
else if (this.runtime.clientId !== undefined &&
|
|
150
|
+
expectedSignoffs.includes(this.runtime.clientId)) {
|
|
151
|
+
// Emit an accept upon a new key entering pending state if our accept is expected.
|
|
152
|
+
const acceptOp = {
|
|
153
|
+
type: "accept",
|
|
154
|
+
key,
|
|
155
|
+
};
|
|
156
|
+
this.submitLocalMessage(acceptOp);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
handleIncomingAccept = (key, clientId, sequenceNumber) => {
|
|
160
|
+
const pending = this.values.get(key)?.pending;
|
|
161
|
+
if (pending === undefined) {
|
|
162
|
+
// If there is no pending value, we already accepted it, so we can ignore the accept op.
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
assert(pending.expectedSignoffs.includes(clientId), 0x2f9 /* Unexpected accept op, client not in expectedSignoffs */);
|
|
166
|
+
// Remove the client from the expected signoffs
|
|
167
|
+
pending.expectedSignoffs = pending.expectedSignoffs.filter((expectedClientId) => expectedClientId !== clientId);
|
|
168
|
+
if (pending.expectedSignoffs.length === 0) {
|
|
169
|
+
// The pending value has settled
|
|
170
|
+
this.values.set(key, {
|
|
171
|
+
accepted: { value: pending.value, sequenceNumber },
|
|
172
|
+
pending: undefined,
|
|
173
|
+
});
|
|
174
|
+
this.emit("accepted", key);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
handleQuorumRemoveMember = (clientId) => {
|
|
178
|
+
for (const [key, { pending }] of this.values) {
|
|
179
|
+
if (pending !== undefined) {
|
|
180
|
+
pending.expectedSignoffs = pending.expectedSignoffs.filter((expectedClientId) => expectedClientId !== clientId);
|
|
181
|
+
if (pending.expectedSignoffs.length === 0) {
|
|
182
|
+
// The pending value has settled
|
|
183
|
+
const clientLeaveSequenceNumber = this.deltaManager.lastSequenceNumber;
|
|
184
|
+
this.values.set(key, {
|
|
185
|
+
accepted: {
|
|
186
|
+
value: pending.value,
|
|
187
|
+
// The sequence number of the ClientLeave message.
|
|
188
|
+
sequenceNumber: clientLeaveSequenceNumber,
|
|
189
|
+
},
|
|
190
|
+
pending: undefined,
|
|
191
|
+
});
|
|
192
|
+
this.emit("accepted", key);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
197
|
/**
|
|
198
198
|
* Create a summary for the PactMap
|
|
199
199
|
*
|
package/lib/pactMap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pactMap.js","sourceRoot":"","sources":["../src/pactMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAM7D,OAAO,EAAE,WAAW,EAAE,MAAM,6CAA6C,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAQrE,OAAO,EACN,YAAY,EACZ,uBAAuB,GACvB,MAAM,6CAA6C,CAAC;AAyErD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;GAEG;AACH,MAAM,OAAO,YACZ,SAAQ,YAA4B;IAOpC;;;;;;OAMG;IACH,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B;QAE9B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;QAhBjC,WAAM,GAAG,IAAI,GAAG,EAAmB,CAAC;QAEpC,eAAU,GAAiB,IAAI,YAAY,EAAE,CAAC;QAyH9C,sBAAiB,GAAG,CACpC,GAAW,EACX,KAAoB,EACpB,MAAc,EACd,iBAAyB,EAClB,EAAE;YACT,MAAM,YAAY,GAAG,IAAI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MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;gBACtC,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;IAES,cAAc;QACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { MessageType } from \"@fluidframework/driver-definitions/internal\";\nimport { readAndParse } from \"@fluidframework/driver-utils/internal\";\nimport type {\n\tISummaryTreeWithStats,\n\tIRuntimeMessageCollection,\n\tIRuntimeMessagesContent,\n\tISequencedMessageEnvelope,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport type { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tSharedObject,\n\tcreateSingleBlobSummary,\n} from \"@fluidframework/shared-object-base/internal\";\n\nimport type { IAcceptedPact, IPactMap, IPactMapEvents } from \"./interfaces.js\";\n\n/**\n * The accepted pact information, if any.\n */\ninterface IAcceptedPactInternal<T> {\n\t/**\n\t * The accepted value of the given type or undefined (typically in case of delete).\n\t */\n\tvalue: T | undefined;\n\n\t/**\n\t * The sequence number when the value was accepted, which will normally coincide with one of two possibilities:\n\t * - The sequence number of the \"accept\" op from the final client we expected signoff from\n\t * - The sequence number of the ClientLeave of the final client we expected signoff from\n\t *\n\t * For values set in detached state, it will be 0.\n\t */\n\tsequenceNumber: number;\n}\n\n/**\n * The pending pact information, if any.\n */\ninterface IPendingPact<T> {\n\t/**\n\t * The pending value of the given type or undefined (typically in case of delete).\n\t */\n\tvalue: T | undefined;\n\t/**\n\t * The list of clientIds that we expect \"accept\" ops from. Clients are also removed from this list if they\n\t * disconnect without accepting. When this list empties, the pending value transitions to accepted.\n\t */\n\texpectedSignoffs: string[];\n}\n\n/**\n * Internal format of the values stored in the PactMap.\n */\ntype Pact<T> =\n\t| { accepted: IAcceptedPactInternal<T>; pending: undefined }\n\t| { accepted: undefined; pending: IPendingPact<T> }\n\t| { accepted: IAcceptedPactInternal<T>; pending: IPendingPact<T> };\n\n/**\n * PactMap operation formats\n */\ninterface IPactMapSetOperation<T> {\n\ttype: \"set\";\n\tkey: string;\n\tvalue: T | undefined;\n\n\t/**\n\t * A \"set\" is only valid if it is made with knowledge of the most-recent accepted proposal - its reference\n\t * sequence number is greater than or equal to the sequence number when that prior value was accepted.\n\t *\n\t * However, we can't trust the built-in referenceSequenceNumber of the op because of resubmit on reconnect,\n\t * which will update the referenceSequenceNumber on our behalf.\n\t *\n\t * Instead we need to separately stamp the real reference sequence number on the op itself.\n\t */\n\trefSeq: number;\n}\n\ninterface IPactMapAcceptOperation {\n\ttype: \"accept\";\n\tkey: string;\n}\n\ntype IPactMapOperation<T> = IPactMapSetOperation<T> | IPactMapAcceptOperation;\n\nconst snapshotFileName = \"header\";\n\n/**\n * {@inheritDoc PactMap}\n */\nexport class PactMapClass<T = unknown>\n\textends SharedObject<IPactMapEvents>\n\timplements IPactMap<T>\n{\n\tprivate readonly values = new Map<string, Pact<T>>();\n\n\tprivate readonly incomingOp: EventEmitter = new EventEmitter();\n\n\t/**\n\t * Constructs a new PactMap. If the object is non-local an id and service interfaces will\n\t * be provided\n\t *\n\t * @param runtime - data store runtime the PactMap belongs to\n\t * @param id - optional name of the PactMap\n\t */\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_pactMap_\");\n\n\t\tthis.incomingOp.on(\"set\", this.handleIncomingSet);\n\t\tthis.incomingOp.on(\"accept\", this.handleIncomingAccept);\n\n\t\tthis.runtime.getQuorum().on(\"removeMember\", this.handleQuorumRemoveMember);\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.get}\n\t */\n\tpublic get(key: string): T | undefined {\n\t\treturn this.values.get(key)?.accepted?.value;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.getWithDetails}\n\t */\n\tpublic getWithDetails(key: string): IAcceptedPact<T> | undefined {\n\t\t// Note: We return type `IAcceptedPact` instead of `IAcceptedPactInternal` since we may want to diverge\n\t\t// the interfaces in the future.\n\t\tconst acceptedPact = this.values.get(key)?.accepted;\n\t\tif (acceptedPact === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tvalue: acceptedPact.value,\n\t\t\tacceptedSequenceNumber: acceptedPact.sequenceNumber,\n\t\t};\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.isPending}\n\t */\n\tpublic isPending(key: string): boolean {\n\t\treturn this.values.get(key)?.pending !== undefined;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.getPending}\n\t */\n\tpublic getPending(key: string): T | undefined {\n\t\treturn this.values.get(key)?.pending?.value;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.set}\n\t */\n\tpublic set(key: string, value: T | undefined): void {\n\t\tconst currentValue = this.values.get(key);\n\t\t// Early-exit if we can't submit a valid proposal (there's already a pending proposal)\n\t\tif (currentValue?.pending !== undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If not attached, we basically pretend we got an ack immediately.\n\t\tif (!this.isAttached()) {\n\t\t\t// Queueing as a microtask to permit callers to complete their callstacks before the result of the set\n\t\t\t// takes effect. This more closely resembles the pattern in the attached state, where the ack will not\n\t\t\t// be received synchronously.\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthis.handleIncomingSet(key, value, 0 /* refSeq */, 0 /* setSequenceNumber */);\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst setOp: IPactMapSetOperation<T> = {\n\t\t\ttype: \"set\",\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\trefSeq: this.deltaManager.lastSequenceNumber,\n\t\t};\n\n\t\tthis.submitLocalMessage(setOp);\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.delete}\n\t */\n\tpublic delete(key: string): void {\n\t\tconst currentValue = this.values.get(key);\n\t\t// Early-exit if:\n\t\tif (\n\t\t\t// there's nothing to delete\n\t\t\tcurrentValue === undefined ||\n\t\t\t// if something is pending (and so our proposal won't be valid)\n\t\t\tcurrentValue.pending !== undefined ||\n\t\t\t// or if the accepted value is undefined which is equivalent to already being deleted\n\t\t\tcurrentValue.accepted.value === undefined\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.set(key, undefined);\n\t}\n\n\t/**\n\t * Get a point-in-time list of clients who must sign off on values coming in for them to move from \"pending\" to\n\t * \"accepted\" state. This list is finalized for a value at the moment it goes pending (i.e. if more clients\n\t * join later, they are not added to the list of signoffs).\n\t * @returns The list of clientIds for clients who must sign off to accept the incoming pending value\n\t */\n\tprivate getSignoffClients(): string[] {\n\t\t// If detached, we don't need anyone to sign off. Otherwise, we need all currently connected clients.\n\t\treturn this.isAttached() ? [...this.runtime.getQuorum().getMembers().keys()] : [];\n\t}\n\n\tprivate readonly handleIncomingSet = (\n\t\tkey: string,\n\t\tvalue: T | undefined,\n\t\trefSeq: number,\n\t\tsetSequenceNumber: number,\n\t): void => {\n\t\tconst currentValue = this.values.get(key);\n\t\t// We use a consensus-like approach here, so a proposal is valid if the value is unset or if there is no\n\t\t// pending change and it was made with knowledge of the most recently accepted value. We'll drop invalid\n\t\t// proposals on the ground.\n\t\tconst proposalValid =\n\t\t\tcurrentValue === undefined ||\n\t\t\t(currentValue.pending === undefined && currentValue.accepted.sequenceNumber <= refSeq);\n\t\tif (!proposalValid) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst accepted = currentValue?.accepted;\n\n\t\t// We expect signoffs from all connected clients at the time the set was sequenced (including the client who\n\t\t// sent the set).\n\t\tconst expectedSignoffs = this.getSignoffClients();\n\n\t\tconst newPact: Pact<T> = {\n\t\t\taccepted,\n\t\t\tpending: {\n\t\t\t\tvalue,\n\t\t\t\texpectedSignoffs,\n\t\t\t},\n\t\t};\n\n\t\tthis.values.set(key, newPact);\n\n\t\tthis.emit(\"pending\", key);\n\n\t\tif (expectedSignoffs.length === 0) {\n\t\t\t// At least the submitting client should be amongst the expectedSignoffs, but keeping this check around\n\t\t\t// as extra protection and in case we bring back the \"submitting client implicitly accepts\" optimization.\n\t\t\tthis.values.set(key, {\n\t\t\t\taccepted: { value, sequenceNumber: setSequenceNumber },\n\t\t\t\tpending: undefined,\n\t\t\t});\n\t\t\tthis.emit(\"accepted\", key);\n\t\t} else if (\n\t\t\tthis.runtime.clientId !== undefined &&\n\t\t\texpectedSignoffs.includes(this.runtime.clientId)\n\t\t) {\n\t\t\t// Emit an accept upon a new key entering pending state if our accept is expected.\n\t\t\tconst acceptOp: IPactMapAcceptOperation = {\n\t\t\t\ttype: \"accept\",\n\t\t\t\tkey,\n\t\t\t};\n\t\t\tthis.submitLocalMessage(acceptOp);\n\t\t}\n\t};\n\n\tprivate readonly handleIncomingAccept = (\n\t\tkey: string,\n\t\tclientId: string,\n\t\tsequenceNumber: number,\n\t): void => {\n\t\tconst pending = this.values.get(key)?.pending;\n\t\tif (pending === undefined) {\n\t\t\t// If there is no pending value, we already accepted it, so we can ignore the accept op.\n\t\t\treturn;\n\t\t}\n\t\tassert(\n\t\t\tpending.expectedSignoffs.includes(clientId),\n\t\t\t0x2f9 /* Unexpected accept op, client not in expectedSignoffs */,\n\t\t);\n\n\t\t// Remove the client from the expected signoffs\n\t\tpending.expectedSignoffs = pending.expectedSignoffs.filter(\n\t\t\t(expectedClientId) => expectedClientId !== clientId,\n\t\t);\n\n\t\tif (pending.expectedSignoffs.length === 0) {\n\t\t\t// The pending value has settled\n\t\t\tthis.values.set(key, {\n\t\t\t\taccepted: { value: pending.value, sequenceNumber },\n\t\t\t\tpending: undefined,\n\t\t\t});\n\t\t\tthis.emit(\"accepted\", key);\n\t\t}\n\t};\n\n\tprivate readonly handleQuorumRemoveMember = (clientId: string): void => {\n\t\tfor (const [key, { pending }] of this.values) {\n\t\t\tif (pending !== undefined) {\n\t\t\t\tpending.expectedSignoffs = pending.expectedSignoffs.filter(\n\t\t\t\t\t(expectedClientId) => expectedClientId !== clientId,\n\t\t\t\t);\n\n\t\t\t\tif (pending.expectedSignoffs.length === 0) {\n\t\t\t\t\t// The pending value has settled\n\t\t\t\t\tconst clientLeaveSequenceNumber = this.deltaManager.lastSequenceNumber;\n\t\t\t\t\tthis.values.set(key, {\n\t\t\t\t\t\taccepted: {\n\t\t\t\t\t\t\tvalue: pending.value,\n\t\t\t\t\t\t\t// The sequence number of the ClientLeave message.\n\t\t\t\t\t\t\tsequenceNumber: clientLeaveSequenceNumber,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tpending: undefined,\n\t\t\t\t\t});\n\t\t\t\t\tthis.emit(\"accepted\", key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\t/**\n\t * Create a summary for the PactMap\n\t *\n\t * @returns the summary of the current state of the PactMap\n\t */\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tconst allEntries = [...this.values.entries()];\n\t\treturn createSingleBlobSummary(snapshotFileName, JSON.stringify(allEntries));\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst content = await readAndParse<[string, Pact<T>][]>(storage, snapshotFileName);\n\t\tfor (const [key, value] of content) {\n\t\t\tthis.values.set(key, value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.initializeLocalCore}\n\t */\n\tprotected initializeLocalCore(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.onDisconnect}\n\t */\n\tprotected onDisconnect(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.reSubmitCore}\n\t */\n\tprotected reSubmitCore(content: unknown, localOpMetadata: unknown): void {\n\t\tconst pactMapOp = content as IPactMapOperation<T>;\n\n\t\t// Filter out set messages that have no chance of being accepted because there's another value pending\n\t\t// or another value was accepted while we were disconnected.\n\t\tconst currentValue = this.values.get(pactMapOp.key);\n\t\tif (\n\t\t\tpactMapOp.type === \"set\" &&\n\t\t\tcurrentValue !== undefined &&\n\t\t\t(currentValue.pending !== undefined ||\n\t\t\t\tpactMapOp.refSeq < currentValue.accepted?.sequenceNumber)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Otherwise we can resubmit\n\t\tthis.submitLocalMessage(pactMapOp, localOpMetadata);\n\t}\n\n\tprotected override processMessagesCore(messagesCollection: IRuntimeMessageCollection): void {\n\t\tconst { envelope, local, messagesContent } = messagesCollection;\n\t\tfor (const messageContent of messagesContent) {\n\t\t\tthis.processMessage(envelope, messageContent, local);\n\t\t}\n\t}\n\n\tprivate processMessage(\n\t\tmessageEnvelope: ISequencedMessageEnvelope,\n\t\tmessageContent: IRuntimeMessagesContent,\n\t\tlocal: boolean,\n\t): void {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n\t\tif (messageEnvelope.type === MessageType.Operation) {\n\t\t\tconst op = messageContent.contents as IPactMapOperation<T>;\n\n\t\t\tswitch (op.type) {\n\t\t\t\tcase \"set\": {\n\t\t\t\t\tthis.incomingOp.emit(\n\t\t\t\t\t\t\"set\",\n\t\t\t\t\t\top.key,\n\t\t\t\t\t\top.value,\n\t\t\t\t\t\top.refSeq,\n\t\t\t\t\t\tmessageEnvelope.sequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase \"accept\": {\n\t\t\t\t\tthis.incomingOp.emit(\n\t\t\t\t\t\t\"accept\",\n\t\t\t\t\t\top.key,\n\t\t\t\t\t\tmessageEnvelope.clientId,\n\t\t\t\t\t\tmessageEnvelope.sequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new Error(\"Unknown operation\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected applyStashedOp(): void {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pactMap.js","sourceRoot":"","sources":["../src/pactMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAM7D,OAAO,EAAE,WAAW,EAAE,MAAM,6CAA6C,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAQrE,OAAO,EACN,YAAY,EACZ,uBAAuB,GACvB,MAAM,6CAA6C,CAAC;AAyErD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;GAEG;AACH,MAAM,OAAO,YACZ,SAAQ,YAA4B;IAGnB,MAAM,GAAG,IAAI,GAAG,EAAmB,CAAC;IAEpC,UAAU,GAAiB,IAAI,YAAY,EAAE,CAAC;IAE/D;;;;;;OAMG;IACH,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B;QAE9B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;QAEjD,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAClD,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAExD,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAC5E,CAAC;IAED;;OAEG;IACI,GAAG,CAAC,GAAW;QACrB,OAAO,IAAI,C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,SAAS,EAAE,eAAe,CAAC,CAAC;IACrD,CAAC;IAEkB,mBAAmB,CAAC,kBAA6C;QACnF,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,kBAAkB,CAAC;QAChE,KAAK,MAAM,cAAc,IAAI,eAAe,EAAE,CAAC;YAC9C,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,cAAc,EAAE,KAAK,CAAC,CAAC;QACtD,CAAC;IACF,CAAC;IAEO,cAAc,CACrB,eAA0C,EAC1C,cAAuC,EACvC,KAAc;QAEd,wEAAwE;QACxE,IAAI,eAAe,CAAC,IAAI,KAAK,WAAW,CAAC,SAAS,EAAE,CAAC;YACpD,MAAM,EAAE,GAAG,cAAc,CAAC,QAAgC,CAAC;YAE3D,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;gBACjB,KAAK,KAAK,CAAC,CAAC,CAAC;oBACZ,IAAI,CAAC,UAAU,CAAC,IAAI,CACnB,KAAK,EACL,EAAE,CAAC,GAAG,EACN,EAAE,CAAC,KAAK,EACR,EAAE,CAAC,MAAM,EACT,eAAe,CAAC,cAAc,CAC9B,CAAC;oBACF,MAAM;gBACP,CAAC;gBAED,KAAK,QAAQ,CAAC,CAAC,CAAC;oBACf,IAAI,CAAC,UAAU,CAAC,IAAI,CACnB,QAAQ,EACR,EAAE,CAAC,GAAG,EACN,eAAe,CAAC,QAAQ,EACxB,eAAe,CAAC,cAAc,CAC9B,CAAC;oBACF,MAAM;gBACP,CAAC;gBAED,OAAO,CAAC,CAAC,CAAC;oBACT,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;gBACtC,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;IAES,cAAc;QACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { MessageType } from \"@fluidframework/driver-definitions/internal\";\nimport { readAndParse } from \"@fluidframework/driver-utils/internal\";\nimport type {\n\tISummaryTreeWithStats,\n\tIRuntimeMessageCollection,\n\tIRuntimeMessagesContent,\n\tISequencedMessageEnvelope,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport type { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tSharedObject,\n\tcreateSingleBlobSummary,\n} from \"@fluidframework/shared-object-base/internal\";\n\nimport type { IAcceptedPact, IPactMap, IPactMapEvents } from \"./interfaces.js\";\n\n/**\n * The accepted pact information, if any.\n */\ninterface IAcceptedPactInternal<T> {\n\t/**\n\t * The accepted value of the given type or undefined (typically in case of delete).\n\t */\n\tvalue: T | undefined;\n\n\t/**\n\t * The sequence number when the value was accepted, which will normally coincide with one of two possibilities:\n\t * - The sequence number of the \"accept\" op from the final client we expected signoff from\n\t * - The sequence number of the ClientLeave of the final client we expected signoff from\n\t *\n\t * For values set in detached state, it will be 0.\n\t */\n\tsequenceNumber: number;\n}\n\n/**\n * The pending pact information, if any.\n */\ninterface IPendingPact<T> {\n\t/**\n\t * The pending value of the given type or undefined (typically in case of delete).\n\t */\n\tvalue: T | undefined;\n\t/**\n\t * The list of clientIds that we expect \"accept\" ops from. Clients are also removed from this list if they\n\t * disconnect without accepting. When this list empties, the pending value transitions to accepted.\n\t */\n\texpectedSignoffs: string[];\n}\n\n/**\n * Internal format of the values stored in the PactMap.\n */\ntype Pact<T> =\n\t| { accepted: IAcceptedPactInternal<T>; pending: undefined }\n\t| { accepted: undefined; pending: IPendingPact<T> }\n\t| { accepted: IAcceptedPactInternal<T>; pending: IPendingPact<T> };\n\n/**\n * PactMap operation formats\n */\ninterface IPactMapSetOperation<T> {\n\ttype: \"set\";\n\tkey: string;\n\tvalue: T | undefined;\n\n\t/**\n\t * A \"set\" is only valid if it is made with knowledge of the most-recent accepted proposal - its reference\n\t * sequence number is greater than or equal to the sequence number when that prior value was accepted.\n\t *\n\t * However, we can't trust the built-in referenceSequenceNumber of the op because of resubmit on reconnect,\n\t * which will update the referenceSequenceNumber on our behalf.\n\t *\n\t * Instead we need to separately stamp the real reference sequence number on the op itself.\n\t */\n\trefSeq: number;\n}\n\ninterface IPactMapAcceptOperation {\n\ttype: \"accept\";\n\tkey: string;\n}\n\ntype IPactMapOperation<T> = IPactMapSetOperation<T> | IPactMapAcceptOperation;\n\nconst snapshotFileName = \"header\";\n\n/**\n * {@inheritDoc PactMap}\n */\nexport class PactMapClass<T = unknown>\n\textends SharedObject<IPactMapEvents>\n\timplements IPactMap<T>\n{\n\tprivate readonly values = new Map<string, Pact<T>>();\n\n\tprivate readonly incomingOp: EventEmitter = new EventEmitter();\n\n\t/**\n\t * Constructs a new PactMap. If the object is non-local an id and service interfaces will\n\t * be provided\n\t *\n\t * @param runtime - data store runtime the PactMap belongs to\n\t * @param id - optional name of the PactMap\n\t */\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_pactMap_\");\n\n\t\tthis.incomingOp.on(\"set\", this.handleIncomingSet);\n\t\tthis.incomingOp.on(\"accept\", this.handleIncomingAccept);\n\n\t\tthis.runtime.getQuorum().on(\"removeMember\", this.handleQuorumRemoveMember);\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.get}\n\t */\n\tpublic get(key: string): T | undefined {\n\t\treturn this.values.get(key)?.accepted?.value;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.getWithDetails}\n\t */\n\tpublic getWithDetails(key: string): IAcceptedPact<T> | undefined {\n\t\t// Note: We return type `IAcceptedPact` instead of `IAcceptedPactInternal` since we may want to diverge\n\t\t// the interfaces in the future.\n\t\tconst acceptedPact = this.values.get(key)?.accepted;\n\t\tif (acceptedPact === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tvalue: acceptedPact.value,\n\t\t\tacceptedSequenceNumber: acceptedPact.sequenceNumber,\n\t\t};\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.isPending}\n\t */\n\tpublic isPending(key: string): boolean {\n\t\treturn this.values.get(key)?.pending !== undefined;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.getPending}\n\t */\n\tpublic getPending(key: string): T | undefined {\n\t\treturn this.values.get(key)?.pending?.value;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.set}\n\t */\n\tpublic set(key: string, value: T | undefined): void {\n\t\tconst currentValue = this.values.get(key);\n\t\t// Early-exit if we can't submit a valid proposal (there's already a pending proposal)\n\t\tif (currentValue?.pending !== undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If not attached, we basically pretend we got an ack immediately.\n\t\tif (!this.isAttached()) {\n\t\t\t// Queueing as a microtask to permit callers to complete their callstacks before the result of the set\n\t\t\t// takes effect. This more closely resembles the pattern in the attached state, where the ack will not\n\t\t\t// be received synchronously.\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthis.handleIncomingSet(key, value, 0 /* refSeq */, 0 /* setSequenceNumber */);\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst setOp: IPactMapSetOperation<T> = {\n\t\t\ttype: \"set\",\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\trefSeq: this.deltaManager.lastSequenceNumber,\n\t\t};\n\n\t\tthis.submitLocalMessage(setOp);\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.delete}\n\t */\n\tpublic delete(key: string): void {\n\t\tconst currentValue = this.values.get(key);\n\t\t// Early-exit if:\n\t\tif (\n\t\t\t// there's nothing to delete\n\t\t\tcurrentValue === undefined ||\n\t\t\t// if something is pending (and so our proposal won't be valid)\n\t\t\tcurrentValue.pending !== undefined ||\n\t\t\t// or if the accepted value is undefined which is equivalent to already being deleted\n\t\t\tcurrentValue.accepted.value === undefined\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.set(key, undefined);\n\t}\n\n\t/**\n\t * Get a point-in-time list of clients who must sign off on values coming in for them to move from \"pending\" to\n\t * \"accepted\" state. This list is finalized for a value at the moment it goes pending (i.e. if more clients\n\t * join later, they are not added to the list of signoffs).\n\t * @returns The list of clientIds for clients who must sign off to accept the incoming pending value\n\t */\n\tprivate getSignoffClients(): string[] {\n\t\t// If detached, we don't need anyone to sign off. Otherwise, we need all currently connected clients.\n\t\treturn this.isAttached() ? [...this.runtime.getQuorum().getMembers().keys()] : [];\n\t}\n\n\tprivate readonly handleIncomingSet = (\n\t\tkey: string,\n\t\tvalue: T | undefined,\n\t\trefSeq: number,\n\t\tsetSequenceNumber: number,\n\t): void => {\n\t\tconst currentValue = this.values.get(key);\n\t\t// We use a consensus-like approach here, so a proposal is valid if the value is unset or if there is no\n\t\t// pending change and it was made with knowledge of the most recently accepted value. We'll drop invalid\n\t\t// proposals on the ground.\n\t\tconst proposalValid =\n\t\t\tcurrentValue === undefined ||\n\t\t\t(currentValue.pending === undefined && currentValue.accepted.sequenceNumber <= refSeq);\n\t\tif (!proposalValid) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst accepted = currentValue?.accepted;\n\n\t\t// We expect signoffs from all connected clients at the time the set was sequenced (including the client who\n\t\t// sent the set).\n\t\tconst expectedSignoffs = this.getSignoffClients();\n\n\t\tconst newPact: Pact<T> = {\n\t\t\taccepted,\n\t\t\tpending: {\n\t\t\t\tvalue,\n\t\t\t\texpectedSignoffs,\n\t\t\t},\n\t\t};\n\n\t\tthis.values.set(key, newPact);\n\n\t\tthis.emit(\"pending\", key);\n\n\t\tif (expectedSignoffs.length === 0) {\n\t\t\t// At least the submitting client should be amongst the expectedSignoffs, but keeping this check around\n\t\t\t// as extra protection and in case we bring back the \"submitting client implicitly accepts\" optimization.\n\t\t\tthis.values.set(key, {\n\t\t\t\taccepted: { value, sequenceNumber: setSequenceNumber },\n\t\t\t\tpending: undefined,\n\t\t\t});\n\t\t\tthis.emit(\"accepted\", key);\n\t\t} else if (\n\t\t\tthis.runtime.clientId !== undefined &&\n\t\t\texpectedSignoffs.includes(this.runtime.clientId)\n\t\t) {\n\t\t\t// Emit an accept upon a new key entering pending state if our accept is expected.\n\t\t\tconst acceptOp: IPactMapAcceptOperation = {\n\t\t\t\ttype: \"accept\",\n\t\t\t\tkey,\n\t\t\t};\n\t\t\tthis.submitLocalMessage(acceptOp);\n\t\t}\n\t};\n\n\tprivate readonly handleIncomingAccept = (\n\t\tkey: string,\n\t\tclientId: string,\n\t\tsequenceNumber: number,\n\t): void => {\n\t\tconst pending = this.values.get(key)?.pending;\n\t\tif (pending === undefined) {\n\t\t\t// If there is no pending value, we already accepted it, so we can ignore the accept op.\n\t\t\treturn;\n\t\t}\n\t\tassert(\n\t\t\tpending.expectedSignoffs.includes(clientId),\n\t\t\t0x2f9 /* Unexpected accept op, client not in expectedSignoffs */,\n\t\t);\n\n\t\t// Remove the client from the expected signoffs\n\t\tpending.expectedSignoffs = pending.expectedSignoffs.filter(\n\t\t\t(expectedClientId) => expectedClientId !== clientId,\n\t\t);\n\n\t\tif (pending.expectedSignoffs.length === 0) {\n\t\t\t// The pending value has settled\n\t\t\tthis.values.set(key, {\n\t\t\t\taccepted: { value: pending.value, sequenceNumber },\n\t\t\t\tpending: undefined,\n\t\t\t});\n\t\t\tthis.emit(\"accepted\", key);\n\t\t}\n\t};\n\n\tprivate readonly handleQuorumRemoveMember = (clientId: string): void => {\n\t\tfor (const [key, { pending }] of this.values) {\n\t\t\tif (pending !== undefined) {\n\t\t\t\tpending.expectedSignoffs = pending.expectedSignoffs.filter(\n\t\t\t\t\t(expectedClientId) => expectedClientId !== clientId,\n\t\t\t\t);\n\n\t\t\t\tif (pending.expectedSignoffs.length === 0) {\n\t\t\t\t\t// The pending value has settled\n\t\t\t\t\tconst clientLeaveSequenceNumber = this.deltaManager.lastSequenceNumber;\n\t\t\t\t\tthis.values.set(key, {\n\t\t\t\t\t\taccepted: {\n\t\t\t\t\t\t\tvalue: pending.value,\n\t\t\t\t\t\t\t// The sequence number of the ClientLeave message.\n\t\t\t\t\t\t\tsequenceNumber: clientLeaveSequenceNumber,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tpending: undefined,\n\t\t\t\t\t});\n\t\t\t\t\tthis.emit(\"accepted\", key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\t/**\n\t * Create a summary for the PactMap\n\t *\n\t * @returns the summary of the current state of the PactMap\n\t */\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tconst allEntries = [...this.values.entries()];\n\t\treturn createSingleBlobSummary(snapshotFileName, JSON.stringify(allEntries));\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst content = await readAndParse<[string, Pact<T>][]>(storage, snapshotFileName);\n\t\tfor (const [key, value] of content) {\n\t\t\tthis.values.set(key, value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.initializeLocalCore}\n\t */\n\tprotected initializeLocalCore(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.onDisconnect}\n\t */\n\tprotected onDisconnect(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.reSubmitCore}\n\t */\n\tprotected reSubmitCore(content: unknown, localOpMetadata: unknown): void {\n\t\tconst pactMapOp = content as IPactMapOperation<T>;\n\n\t\t// Filter out set messages that have no chance of being accepted because there's another value pending\n\t\t// or another value was accepted while we were disconnected.\n\t\tconst currentValue = this.values.get(pactMapOp.key);\n\t\tif (\n\t\t\tpactMapOp.type === \"set\" &&\n\t\t\tcurrentValue !== undefined &&\n\t\t\t(currentValue.pending !== undefined ||\n\t\t\t\tpactMapOp.refSeq < currentValue.accepted?.sequenceNumber)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Otherwise we can resubmit\n\t\tthis.submitLocalMessage(pactMapOp, localOpMetadata);\n\t}\n\n\tprotected override processMessagesCore(messagesCollection: IRuntimeMessageCollection): void {\n\t\tconst { envelope, local, messagesContent } = messagesCollection;\n\t\tfor (const messageContent of messagesContent) {\n\t\t\tthis.processMessage(envelope, messageContent, local);\n\t\t}\n\t}\n\n\tprivate processMessage(\n\t\tmessageEnvelope: ISequencedMessageEnvelope,\n\t\tmessageContent: IRuntimeMessagesContent,\n\t\tlocal: boolean,\n\t): void {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n\t\tif (messageEnvelope.type === MessageType.Operation) {\n\t\t\tconst op = messageContent.contents as IPactMapOperation<T>;\n\n\t\t\tswitch (op.type) {\n\t\t\t\tcase \"set\": {\n\t\t\t\t\tthis.incomingOp.emit(\n\t\t\t\t\t\t\"set\",\n\t\t\t\t\t\top.key,\n\t\t\t\t\t\top.value,\n\t\t\t\t\t\top.refSeq,\n\t\t\t\t\t\tmessageEnvelope.sequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase \"accept\": {\n\t\t\t\t\tthis.incomingOp.emit(\n\t\t\t\t\t\t\"accept\",\n\t\t\t\t\t\top.key,\n\t\t\t\t\t\tmessageEnvelope.clientId,\n\t\t\t\t\t\tmessageEnvelope.sequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new Error(\"Unknown operation\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected applyStashedOp(): void {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
|
package/lib/pactMapFactory.js
CHANGED
|
@@ -9,6 +9,15 @@ import { PactMapClass } from "./pactMap.js";
|
|
|
9
9
|
* The factory that produces the PactMap
|
|
10
10
|
*/
|
|
11
11
|
export class PactMapFactory {
|
|
12
|
+
// New type string, to be activated once the migration has been fully shipped dark and is safe to flip.
|
|
13
|
+
// See LegacyTypeAwareRegistry in packages/runtime/datastore/src/dataStoreRuntime.ts.
|
|
14
|
+
// public static readonly Type = "pact-map";
|
|
15
|
+
static Type = "https://graph.microsoft.com/types/pact-map";
|
|
16
|
+
static Attributes = {
|
|
17
|
+
type: PactMapFactory.Type,
|
|
18
|
+
snapshotFormatVersion: "0.1",
|
|
19
|
+
packageVersion: pkgVersion,
|
|
20
|
+
};
|
|
12
21
|
get type() {
|
|
13
22
|
return PactMapFactory.Type;
|
|
14
23
|
}
|
|
@@ -29,15 +38,6 @@ export class PactMapFactory {
|
|
|
29
38
|
return pactMap;
|
|
30
39
|
}
|
|
31
40
|
}
|
|
32
|
-
// New type string, to be activated once the migration has been fully shipped dark and is safe to flip.
|
|
33
|
-
// See LegacyTypeAwareRegistry in packages/runtime/datastore/src/dataStoreRuntime.ts.
|
|
34
|
-
// public static readonly Type = "pact-map";
|
|
35
|
-
PactMapFactory.Type = "https://graph.microsoft.com/types/pact-map";
|
|
36
|
-
PactMapFactory.Attributes = {
|
|
37
|
-
type: PactMapFactory.Type,
|
|
38
|
-
snapshotFormatVersion: "0.1",
|
|
39
|
-
packageVersion: pkgVersion,
|
|
40
|
-
};
|
|
41
41
|
/**
|
|
42
42
|
* The PactMap distributed data structure provides key/value storage with a cautious conflict resolution strategy.
|
|
43
43
|
* This strategy optimizes for all clients being aware of the change prior to considering the value as accepted.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pactMapFactory.js","sourceRoot":"","sources":["../src/pactMapFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,EAAE,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AAGrF,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,sBAAsB,CAAC,cAAc,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tIChannelAttributes,\n\tIChannelFactory,\n\tIFluidDataStoreRuntime,\n\tIChannelServices,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { createSharedObjectKind } from \"@fluidframework/shared-object-base/internal\";\n\nimport type { IPactMap } from \"./interfaces.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\nimport { PactMapClass } from \"./pactMap.js\";\n\n/**\n * The factory that produces the PactMap\n */\nexport class PactMapFactory implements IChannelFactory<IPactMap> {\n\t// New type string, to be activated once the migration has been fully shipped dark and is safe to flip.\n\t// See LegacyTypeAwareRegistry in packages/runtime/datastore/src/dataStoreRuntime.ts.\n\t// public static readonly Type = \"pact-map\";\n\tpublic static readonly Type = \"https://graph.microsoft.com/types/pact-map\";\n\n\tpublic static readonly Attributes: IChannelAttributes = {\n\t\ttype: PactMapFactory.Type,\n\t\tsnapshotFormatVersion: \"0.1\",\n\t\tpackageVersion: pkgVersion,\n\t};\n\n\tpublic get type(): string {\n\t\treturn PactMapFactory.Type;\n\t}\n\n\tpublic get attributes(): IChannelAttributes {\n\t\treturn PactMapFactory.Attributes;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}\n\t */\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tid: string,\n\t\tservices: IChannelServices,\n\t\tattributes: IChannelAttributes,\n\t): Promise<IPactMap> {\n\t\tconst pactMap = new PactMapClass(id, runtime, attributes);\n\t\tawait pactMap.load(services);\n\t\treturn pactMap;\n\t}\n\n\tpublic create(document: IFluidDataStoreRuntime, id: string): IPactMap {\n\t\tconst pactMap = new PactMapClass(id, document, this.attributes);\n\t\tpactMap.initializeLocal();\n\t\treturn pactMap;\n\t}\n}\n\n/**\n * The PactMap distributed data structure provides key/value storage with a cautious conflict resolution strategy.\n * This strategy optimizes for all clients being aware of the change prior to considering the value as accepted.\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 * To create a `PactMap`, call the static create method:\n *\n * ```typescript\n * const pactMap = PactMap.create(this.runtime, id);\n * ```\n *\n * ### Usage\n *\n * Setting and reading values is somewhat similar to a `SharedMap`. However, because the acceptance strategy\n * cannot be resolved until other clients have witnessed the set, the new value will only be reflected in the data\n * after the consensus is reached.\n *\n * ```typescript\n * pactMap.on(\"pending\", (key: string) => {\n * console.log(pactMap.getPending(key));\n * });\n * pactMap.on(\"accepted\", (key: string) => {\n * console.log(pactMap.get(key));\n * });\n * pactMap.set(\"myKey\", \"myValue\");\n *\n * // Reading from the pact map prior to the async operation's completion will still return the old value.\n * console.log(pactMap.get(\"myKey\"));\n * ```\n *\n * The acceptance process has two stages. When an op indicating a client's attempt to set a value is sequenced,\n * we first verify that it was set with knowledge of the most recently accepted value (consensus-like FWW). If it\n * meets this bar, then the value is \"pending\". During this time, clients may observe the pending value and act\n * upon it, but should be aware that not all other clients may have witnessed the value yet. Once all clients\n * that were connected at the time of the value being set have explicitly acknowledged the new value, the value\n * becomes \"accepted\". Once the value is accepted, it once again becomes possible to set the value, again with\n * consensus-like FWW resolution.\n *\n * Since all connected clients must explicitly accept the new value, it is important that all connected clients\n * have the PactMap loaded, including e.g. the summarizing client. Otherwise, those clients who have not loaded\n * the PactMap will not be responding to proposals and delay their acceptance (until they disconnect, which implicitly\n * removes them from consideration). The easiest way to ensure all clients load the PactMap is to instantiate it\n * as part of instantiating the IRuntime for the container (containerHasInitialized if using Aqueduct).\n *\n * ### Eventing\n *\n * `PactMap` is an `EventEmitter`, and will emit events when a new value is accepted for a key.\n *\n * ```typescript\n * pactMap.on(\"accept\", (key: string) => {\n * console.log(`New value was accepted for key: ${ key }, value: ${ pactMap.get(key) }`);\n * });\n * ```\n * @internal\n */\nexport const PactMap = createSharedObjectKind(PactMapFactory);\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-experimental/pact-map",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Distributed data structure for key-value pairs using pact consensus",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -14,18 +14,10 @@
|
|
|
14
14
|
"type": "module",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
"default": "./lib/index.js"
|
|
20
|
-
},
|
|
21
|
-
"require": {
|
|
22
|
-
"types": "./dist/index.d.ts",
|
|
23
|
-
"default": "./dist/index.js"
|
|
24
|
-
}
|
|
17
|
+
"types": "./lib/index.d.ts",
|
|
18
|
+
"default": "./lib/index.js"
|
|
25
19
|
}
|
|
26
20
|
},
|
|
27
|
-
"main": "lib/index.js",
|
|
28
|
-
"types": "lib/index.d.ts",
|
|
29
21
|
"c8": {
|
|
30
22
|
"all": true,
|
|
31
23
|
"cache-dir": "nyc/.cache",
|
|
@@ -49,25 +41,25 @@
|
|
|
49
41
|
"temp-directory": "nyc/.nyc_output"
|
|
50
42
|
},
|
|
51
43
|
"dependencies": {
|
|
52
|
-
"@fluid-internal/client-utils": "~
|
|
53
|
-
"@fluidframework/core-interfaces": "~
|
|
54
|
-
"@fluidframework/core-utils": "~
|
|
55
|
-
"@fluidframework/datastore-definitions": "~
|
|
56
|
-
"@fluidframework/driver-definitions": "~
|
|
57
|
-
"@fluidframework/driver-utils": "~
|
|
58
|
-
"@fluidframework/runtime-definitions": "~
|
|
59
|
-
"@fluidframework/shared-object-base": "~
|
|
44
|
+
"@fluid-internal/client-utils": "~3.0.0",
|
|
45
|
+
"@fluidframework/core-interfaces": "~3.0.0",
|
|
46
|
+
"@fluidframework/core-utils": "~3.0.0",
|
|
47
|
+
"@fluidframework/datastore-definitions": "~3.0.0",
|
|
48
|
+
"@fluidframework/driver-definitions": "~3.0.0",
|
|
49
|
+
"@fluidframework/driver-utils": "~3.0.0",
|
|
50
|
+
"@fluidframework/runtime-definitions": "~3.0.0",
|
|
51
|
+
"@fluidframework/shared-object-base": "~3.0.0"
|
|
60
52
|
},
|
|
61
53
|
"devDependencies": {
|
|
62
54
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
63
55
|
"@biomejs/biome": "~2.4.5",
|
|
64
|
-
"@fluid-internal/mocha-test-setup": "~
|
|
65
|
-
"@fluid-private/test-dds-utils": "~
|
|
56
|
+
"@fluid-internal/mocha-test-setup": "~3.0.0",
|
|
57
|
+
"@fluid-private/test-dds-utils": "~3.0.0",
|
|
66
58
|
"@fluid-tools/build-cli": "^0.67.0",
|
|
67
59
|
"@fluidframework/build-common": "^2.0.3",
|
|
68
60
|
"@fluidframework/build-tools": "^0.67.0",
|
|
69
61
|
"@fluidframework/eslint-config-fluid": "^14.0.0",
|
|
70
|
-
"@fluidframework/test-runtime-utils": "~
|
|
62
|
+
"@fluidframework/test-runtime-utils": "~3.0.0",
|
|
71
63
|
"@microsoft/api-extractor": "7.58.1",
|
|
72
64
|
"@types/mocha": "^10.0.10",
|
|
73
65
|
"@types/node": "~22.19.17",
|
|
@@ -80,29 +72,32 @@
|
|
|
80
72
|
"mocha": "^11.7.5",
|
|
81
73
|
"mocha-multi-reporters": "^1.5.1",
|
|
82
74
|
"rimraf": "^6.1.3",
|
|
83
|
-
"typescript": "~
|
|
75
|
+
"typescript": "~6.0.3"
|
|
84
76
|
},
|
|
85
77
|
"typeValidation": {
|
|
86
78
|
"disabled": true
|
|
87
79
|
},
|
|
88
80
|
"scripts": {
|
|
89
81
|
"build": "fluid-build . --task build",
|
|
82
|
+
"build:api-reports": "api-extractor run --local --config api-extractor/api-extractor-report.json",
|
|
83
|
+
"build:cjs": "fluid-tsc commonjs --project ./tsconfig.cjs.json && copyfiles -f ../../../common/build/build-common/src/cjs/package.json ./dist",
|
|
90
84
|
"build:commonjs": "fluid-build . --task commonjs",
|
|
91
85
|
"build:compile": "fluid-build . --task compile",
|
|
92
|
-
"build:docs": "api-extractor run --local",
|
|
93
|
-
"build:
|
|
86
|
+
"build:docs": "api-extractor run --local --config api-extractor/api-extractor-model.json",
|
|
87
|
+
"build:esm": "tsc --project ./tsconfig.json",
|
|
94
88
|
"build:genver": "gen-version",
|
|
95
89
|
"build:test": "concurrently npm:build:test:esm npm:build:test:cjs",
|
|
96
90
|
"build:test:cjs": "fluid-tsc commonjs --project ./src/test/tsconfig.cjs.json",
|
|
97
91
|
"build:test:esm": "tsc --project ./src/test/tsconfig.json",
|
|
98
|
-
"check:are-the-types-wrong": "attw --pack .",
|
|
92
|
+
"check:are-the-types-wrong": "attw --pack . --profile esm-only",
|
|
99
93
|
"check:biome": "biome check .",
|
|
100
94
|
"check:exports": "concurrently \"npm:check:exports:*\"",
|
|
101
95
|
"check:exports:bundle-release-tags": "api-extractor run --config api-extractor/api-extractor-lint-bundle.json",
|
|
102
96
|
"check:exports:cjs:index": "api-extractor run --config api-extractor/api-extractor-lint-index.cjs.json",
|
|
103
97
|
"check:exports:esm:index": "api-extractor run --config api-extractor/api-extractor-lint-index.esm.json",
|
|
104
98
|
"check:format": "npm run check:biome",
|
|
105
|
-
"ci:build:
|
|
99
|
+
"ci:build:api-reports": "api-extractor run --config api-extractor/api-extractor-report.json",
|
|
100
|
+
"ci:build:docs": "api-extractor run --config api-extractor/api-extractor-model.json",
|
|
106
101
|
"clean": "rimraf --glob dist lib \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc",
|
|
107
102
|
"eslint": "eslint --quiet --format stylish src",
|
|
108
103
|
"eslint:fix": "eslint --quiet --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
@@ -115,7 +110,6 @@
|
|
|
115
110
|
"test:mocha": "npm run test:mocha:esm && echo skipping cjs to avoid overhead - npm run test:mocha:cjs",
|
|
116
111
|
"test:mocha:cjs": "cross-env FLUID_TEST_MODULE_SYSTEM=CJS mocha",
|
|
117
112
|
"test:mocha:esm": "mocha",
|
|
118
|
-
"test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha"
|
|
119
|
-
"tsc": "fluid-tsc commonjs --project ./tsconfig.cjs.json && copyfiles -f ../../../common/build/build-common/src/cjs/package.json ./dist"
|
|
113
|
+
"test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha"
|
|
120
114
|
}
|
|
121
115
|
}
|
package/src/packageVersion.ts
CHANGED
package/tsconfig.json
CHANGED