@spine-event-engine/storage-mysql 2.0.0-snapshot.24 → 2.0.0-snapshot.26
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/README.md +34 -26
- package/REFERENCE.md +47 -47
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mysql/agent-history.d.ts +47 -8
- package/dist/mysql/agent-history.d.ts.map +1 -1
- package/dist/mysql/agent-history.js +85 -19
- package/dist/mysql/agent-history.js.map +1 -1
- package/dist/mysql/agent-transaction.d.ts +6 -0
- package/dist/mysql/agent-transaction.d.ts.map +1 -1
- package/dist/mysql/agent-transaction.js +15 -0
- package/dist/mysql/agent-transaction.js.map +1 -1
- package/dist/mysql/column-mapping.d.ts +1 -0
- package/dist/mysql/column-mapping.d.ts.map +1 -1
- package/dist/mysql/column-mapping.js +26 -3
- package/dist/mysql/column-mapping.js.map +1 -1
- package/dist/mysql/entity-history.d.ts +23 -6
- package/dist/mysql/entity-history.d.ts.map +1 -1
- package/dist/mysql/entity-history.js +210 -48
- package/dist/mysql/entity-history.js.map +1 -1
- package/dist/mysql/id-column.d.ts +7 -0
- package/dist/mysql/id-column.d.ts.map +1 -1
- package/dist/mysql/id-column.js +27 -3
- package/dist/mysql/id-column.js.map +1 -1
- package/dist/mysql/record-storage.d.ts +175 -34
- package/dist/mysql/record-storage.d.ts.map +1 -1
- package/dist/mysql/record-storage.js +317 -140
- package/dist/mysql/record-storage.js.map +1 -1
- package/dist/mysql/storage-factory.d.ts +284 -29
- package/dist/mysql/storage-factory.d.ts.map +1 -1
- package/dist/mysql/storage-factory.js +1226 -170
- package/dist/mysql/storage-factory.js.map +1 -1
- package/dist/mysql/table-resolver.d.ts +26 -1
- package/dist/mysql/table-resolver.d.ts.map +1 -1
- package/dist/mysql/table-resolver.js +69 -18
- package/dist/mysql/table-resolver.js.map +1 -1
- package/dist/mysql/table-spec.d.ts +0 -4
- package/dist/mysql/table-spec.d.ts.map +1 -1
- package/dist/mysql/table-spec.js +2 -34
- package/dist/mysql/table-spec.js.map +1 -1
- package/dist/mysql/testing.d.ts +8 -0
- package/dist/mysql/testing.d.ts.map +1 -1
- package/dist/mysql/testing.js +23 -2
- package/dist/mysql/testing.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -6
- package/dist/mysql/agent-execution.d.ts +0 -276
- package/dist/mysql/agent-execution.d.ts.map +0 -1
- package/dist/mysql/agent-execution.js +0 -630
- package/dist/mysql/agent-execution.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-transaction.js","sourceRoot":"","sources":["../../src/mysql/agent-transaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH;;GAEG;AACH,MAAM,OAAO,qBAAqB;IASb;IARnB,kBAAkB;IAElB;;;;OAIG;IACH,YACmB,WAGhB;QAHgB,gBAAW,GAAX,WAAW,CAG3B;IACA,CAAC;IAEJ;;;;;;;OAOG;IACH,KAAK,CAAC,MAAM,CACV,MAAyB,EACzB,IAAgD;QAEhD,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QACpD,IAAI,CAAC;YACH,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YACtE,IAAI,CAAC,aAAa;gBAChB,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;YACjF,OAAO,MAAM,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACxD,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACK,KAAK,CAAC,gBAAgB,CAC5B,UAA0B,EAC1B,MAAyB;QAEzB,MAAM,CAAC,IAAI,CA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CAAC;QACF,OAAO,CACL,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,QAAQ,CAAC,CAC7F,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACK,KAAK,CAAC,iBAAiB,CAC7B,UAA0B,EAC1B,IAAgD;QAEhD,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC;YAChD,IAAI,CAAC;gBACH,MAAM,UAAU,CAAC,gBAAgB,EAAE,CAAC;gBACpC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC;gBACtC,MAAM,UAAU,CAAC,MAAM,EAAE,CAAC;gBAC1B,OAAO,MAAM,CAAC;YAChB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,UAAU,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;gBACnD,IAAI,OAAO,KAAK,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;oBAAE,SAAS;gBACtD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IAED;;;;;OAKG;IACK,UAAU,CAAC,KAAc;QAC/B,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;YACzB,KAAK,KAAK,IAAI;YACb,KAA4B,CAAC,IAAI,KAAK,kBAAkB,CAC1D,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -14,6 +14,7 @@ export declare class MysqlColumnMapping implements ColumnMapping<unknown> {
|
|
|
14
14
|
/**
|
|
15
15
|
* Returns the conversion for one generated column type.
|
|
16
16
|
*
|
|
17
|
+
* @typeParam V Protobuf column value type.
|
|
17
18
|
* @param type The generated Protobuf column type.
|
|
18
19
|
* @returns The JVM-compatible MySQL parameter conversion.
|
|
19
20
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-mapping.d.ts","sourceRoot":"","sources":["../../src/mysql/column-mapping.ts"],"names":[],"mappings":"AAgBA,OAAO,
|
|
1
|
+
{"version":3,"file":"column-mapping.d.ts","sourceRoot":"","sources":["../../src/mysql/column-mapping.ts"],"names":[],"mappings":"AAgBA,OAAO,EAA8B,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC3F,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,6BAA6B,CAAC;AAKrC;;GAEG;AACH,qBAAa,kBAAmB,YAAW,aAAa,CAAC,OAAO,CAAC;;IAG/D;;;;OAIG;gBACS,YAAY,GAAE,mBAAgD;IAS1E;;;;;;OAMG;IACH,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC;IAoB/D;;;OAGG;IACH,MAAM,IAAI,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC;CAG3C"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* the License.
|
|
13
13
|
*/
|
|
14
14
|
import { ScalarType } from "@bufbuild/protobuf";
|
|
15
|
-
import { StringifierRegistry } from "@spine-event-engine/core";
|
|
15
|
+
import { defaultStringifierRegistry, StringifierRegistry } from "@spine-event-engine/core";
|
|
16
16
|
const timestampType = "google.protobuf.Timestamp";
|
|
17
17
|
const versionType = "spine.core.Version";
|
|
18
18
|
/**
|
|
@@ -25,13 +25,17 @@ export class MysqlColumnMapping {
|
|
|
25
25
|
*
|
|
26
26
|
* @param stringifiers The schema-bound message stringifiers.
|
|
27
27
|
*/
|
|
28
|
-
constructor(stringifiers =
|
|
29
|
-
this.#stringifiers =
|
|
28
|
+
constructor(stringifiers = defaultStringifierRegistry) {
|
|
29
|
+
this.#stringifiers =
|
|
30
|
+
stringifiers === defaultStringifierRegistry
|
|
31
|
+
? stringifiers
|
|
32
|
+
: new StringifierRegistry(stringifiers);
|
|
30
33
|
}
|
|
31
34
|
// prettier-ignore
|
|
32
35
|
/**
|
|
33
36
|
* Returns the conversion for one generated column type.
|
|
34
37
|
*
|
|
38
|
+
* @typeParam V Protobuf column value type.
|
|
35
39
|
* @param type The generated Protobuf column type.
|
|
36
40
|
* @returns The JVM-compatible MySQL parameter conversion.
|
|
37
41
|
*/
|
|
@@ -62,6 +66,13 @@ export class MysqlColumnMapping {
|
|
|
62
66
|
}
|
|
63
67
|
}
|
|
64
68
|
const MysqlMappings = Object.freeze({
|
|
69
|
+
/**
|
|
70
|
+
* Maps a scalar column to a MySQL parameter.
|
|
71
|
+
*
|
|
72
|
+
* @typeParam V Scalar value type.
|
|
73
|
+
* @param type Protobuf scalar kind.
|
|
74
|
+
* @returns The scalar conversion.
|
|
75
|
+
*/
|
|
65
76
|
scalar(type) {
|
|
66
77
|
switch (type) {
|
|
67
78
|
case ScalarType.STRING:
|
|
@@ -83,10 +94,22 @@ const MysqlMappings = Object.freeze({
|
|
|
83
94
|
throw new Error("Spine JVM JDBC does not support floating-point record columns.");
|
|
84
95
|
}
|
|
85
96
|
},
|
|
97
|
+
/**
|
|
98
|
+
* Converts a timestamp to epoch nanoseconds.
|
|
99
|
+
*
|
|
100
|
+
* @param value Protobuf timestamp value.
|
|
101
|
+
* @returns Epoch nanoseconds.
|
|
102
|
+
*/
|
|
86
103
|
timestamp(value) {
|
|
87
104
|
const timestamp = value;
|
|
88
105
|
return timestamp.seconds * 1000000000n + BigInt(timestamp.nanos);
|
|
89
106
|
},
|
|
107
|
+
/**
|
|
108
|
+
* Converts a version to its integer number.
|
|
109
|
+
*
|
|
110
|
+
* @param value Protobuf version value.
|
|
111
|
+
* @returns Version number.
|
|
112
|
+
*/
|
|
90
113
|
version(value) {
|
|
91
114
|
return value.number;
|
|
92
115
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-mapping.js","sourceRoot":"","sources":["../../src/mysql/column-mapping.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAgB,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"column-mapping.js","sourceRoot":"","sources":["../../src/mysql/column-mapping.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAgB,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAO3F,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAClD,MAAM,WAAW,GAAG,oBAAoB,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,kBAAkB;IACpB,aAAa,CAAsB;IAE5C;;;;OAIG;IACH,YAAY,eAAoC,0BAA0B;QACxE,IAAI,CAAC,aAAa;YAChB,YAAY,KAAK,0BAA0B;gBACzC,CAAC,CAAC,YAAY;gBACd,CAAC,CAAC,IAAI,mBAAmB,CAAC,YAAY,CAAC,CAAC;IAC9C,CAAC;IAED,kBAAkB;IAElB;;;;;;OAMG;IACH,EAAE,CAAI,IAAyB;QAC7B,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,QAAQ;gBACX,OAAO,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC3C,KAAK,MAAM;gBACT,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC;YAC1B,KAAK,SAAS;gBACZ,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,KAAK,aAAa,EAAE,CAAC;oBAC5C,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,SAAS,CAAC,KAAK,CAAC,C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ED;;;;;OAKG;IACH,SAAS,CAAC,KAAc;QACtB,MAAM,SAAS,GAAG,KAA6D,CAAC;QAChF,OAAO,SAAS,CAAC,OAAO,GAAG,WAAc,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACtE,CAAC;IAED;;;;;OAKG;IACH,OAAO,CAAC,KAAc;QACpB,OAAQ,KAAqC,CAAC,MAAM,CAAC;IACvD,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -3,11 +3,9 @@ import type { Event } from "@spine-event-engine/proto";
|
|
|
3
3
|
import type { EntityRecord } from "@spine-event-engine/proto/generated/spine/server/entity/entity_pb.js";
|
|
4
4
|
import { RecordSpec } from "@spine-event-engine/storage";
|
|
5
5
|
import { type EntityEventHistoryPort, type EntityRecordStorage, type EntityStateHistoryPort, type EntityStorageInput } from "@spine-event-engine/storage/provider";
|
|
6
|
-
import { MysqlRecordStorage } from "./record-storage.js";
|
|
6
|
+
import { MysqlRecordStorage, type OnPublicOperation } from "./record-storage.js";
|
|
7
7
|
/**
|
|
8
|
-
|
|
9
8
|
* Opens one MySQL record family for Entity storage.
|
|
10
|
-
|
|
11
9
|
*/
|
|
12
10
|
interface OpenRecords {
|
|
13
11
|
/**
|
|
@@ -59,7 +57,10 @@ export interface MysqlEntityStorageHandle<I, S extends Message> {
|
|
|
59
57
|
*/
|
|
60
58
|
export declare class MysqlEntityStorage<I, S extends Message> implements MysqlEntityStorageHandle<I, S> {
|
|
61
59
|
#private;
|
|
60
|
+
private readonly input;
|
|
61
|
+
private readonly open;
|
|
62
62
|
private readonly onClose;
|
|
63
|
+
private readonly onAdmit;
|
|
63
64
|
/**
|
|
64
65
|
* Exposes current Entity records.
|
|
65
66
|
*/
|
|
@@ -67,19 +68,28 @@ export declare class MysqlEntityStorage<I, S extends Message> implements MysqlEn
|
|
|
67
68
|
/**
|
|
68
69
|
* Exposes Entity state history records.
|
|
69
70
|
*/
|
|
70
|
-
|
|
71
|
+
states: EntityStateHistoryPort<I, S>;
|
|
71
72
|
/**
|
|
72
73
|
* Exposes Entity event history records.
|
|
73
74
|
*/
|
|
74
|
-
|
|
75
|
+
events: EntityEventHistoryPort<I>;
|
|
75
76
|
/**
|
|
76
77
|
* Creates MySQL-backed Entity storage handles.
|
|
77
78
|
*
|
|
78
79
|
* @param input Configures the Entity storage families.
|
|
79
80
|
* @param open Opens one record-family storage handle.
|
|
80
81
|
* @param onClose Removes this Entity handle from its factory.
|
|
82
|
+
* @param lazy Whether optional families are acquired on first use.
|
|
83
|
+
* @param onAdmit Admits complete public Entity operations.
|
|
84
|
+
*/
|
|
85
|
+
constructor(input: EntityStorageInput<I, S>, open: OpenRecords, onClose?: () => void, lazy?: boolean, onAdmit?: OnPublicOperation);
|
|
86
|
+
/**
|
|
87
|
+
* Acquires only missing requested history families, rolling back a failed upgrade.
|
|
88
|
+
*
|
|
89
|
+
* @param wantEvents Whether diagnostic Event history is required.
|
|
90
|
+
* @param wantStates Whether state history is required.
|
|
81
91
|
*/
|
|
82
|
-
|
|
92
|
+
ensure(wantStates: boolean, wantEvents: boolean): void;
|
|
83
93
|
/**
|
|
84
94
|
* Returns whether this Entity storage handle accepts operations.
|
|
85
95
|
*
|
|
@@ -118,6 +128,13 @@ export declare class MysqlEntityStorage<I, S extends Message> implements MysqlEn
|
|
|
118
128
|
* @returns Current record when present.
|
|
119
129
|
*/
|
|
120
130
|
readCurrentLocked(id: I): Promise<EntityRecord | undefined>;
|
|
131
|
+
/**
|
|
132
|
+
* Writes current state inside an already admitted Agent transaction.
|
|
133
|
+
*
|
|
134
|
+
* @param record Committed current Entity state.
|
|
135
|
+
* @returns Completion after the record write.
|
|
136
|
+
*/
|
|
137
|
+
writeCurrentAdmitted(record: EntityRecord): Promise<void>;
|
|
121
138
|
/**
|
|
122
139
|
* Returns configured Entity history writers for the Agent transaction.
|
|
123
140
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-history.d.ts","sourceRoot":"","sources":["../../src/mysql/entity-history.ts"],"names":[],"mappings":"AAcA,OAAO,
|
|
1
|
+
{"version":3,"file":"entity-history.d.ts","sourceRoot":"","sources":["../../src/mysql/entity-history.ts"],"names":[],"mappings":"AAcA,OAAO,EAAU,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,KAAK,EAAE,KAAK,EAAW,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sEAAsE,CAAC;AAKzG,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACxB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,kBAAkB,EAAE,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEjF;;GAEG;AACH,UAAU,WAAW;IACnB;;;;;;;;OAQG;IAEH,CAAC,EAAE,EAAE,CAAC,SAAS,OAAO,EACpB,IAAI,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,EACvB,KAAK,CAAC,EAAE,OAAO,6BAA6B,EAAE,YAAY,GACzD,kBAAkB,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;CAC9B;AAED;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO;IAG5D;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAEzC;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAE9C;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;IAE3C;;;;OAIG;IACH,MAAM,IAAI,OAAO,CAAC;IAElB;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;;;;GAKG;AACH,qBA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EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzD;;;;OAIG;IACH,gBAAgB,IAAI;QAClB,oBAAoB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC1D,yBAAyB,CAAC,MAAM,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KACzD;CAQF"}
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* or implied. See the License for the specific language governing permissions and limitations under
|
|
12
12
|
* the License.
|
|
13
13
|
*/
|
|
14
|
-
import { create
|
|
14
|
+
import { create } from "@bufbuild/protobuf";
|
|
15
|
+
import { AnyPacker } from "@spine-event-engine/core";
|
|
15
16
|
import { EntityStateKeySchema, } from "@spine-event-engine/proto/generated/spine/server/entity/state_key_pb.js";
|
|
16
17
|
import { RecordSpec } from "@spine-event-engine/storage";
|
|
17
18
|
import { eventHistorySpec, stateHistorySpec, } from "@spine-event-engine/storage/provider";
|
|
@@ -23,28 +24,25 @@ import { MysqlRecordStorage } from "./record-storage.js";
|
|
|
23
24
|
* @typeParam S Entity state message type.
|
|
24
25
|
*/
|
|
25
26
|
export class MysqlEntityStorage {
|
|
27
|
+
input;
|
|
28
|
+
open;
|
|
26
29
|
onClose;
|
|
30
|
+
onAdmit;
|
|
27
31
|
// prettier-ignore
|
|
28
32
|
/**
|
|
29
33
|
* Exposes current Entity records.
|
|
30
34
|
*/
|
|
31
35
|
current;
|
|
32
36
|
/**
|
|
33
|
-
|
|
34
37
|
* Current record-family handle.
|
|
35
|
-
|
|
36
38
|
*/
|
|
37
39
|
#current;
|
|
38
40
|
/**
|
|
39
|
-
|
|
40
41
|
* Optional state-history handle.
|
|
41
|
-
|
|
42
42
|
*/
|
|
43
43
|
#states;
|
|
44
44
|
/**
|
|
45
|
-
|
|
46
45
|
* Optional diagnostic-history handle.
|
|
47
|
-
|
|
48
46
|
*/
|
|
49
47
|
#events;
|
|
50
48
|
/**
|
|
@@ -56,9 +54,7 @@ export class MysqlEntityStorage {
|
|
|
56
54
|
*/
|
|
57
55
|
events;
|
|
58
56
|
/**
|
|
59
|
-
|
|
60
57
|
* Whether this Entity storage accepts operations.
|
|
61
|
-
|
|
62
58
|
*/
|
|
63
59
|
#open = true;
|
|
64
60
|
/**
|
|
@@ -67,19 +63,60 @@ export class MysqlEntityStorage {
|
|
|
67
63
|
* @param input Configures the Entity storage families.
|
|
68
64
|
* @param open Opens one record-family storage handle.
|
|
69
65
|
* @param onClose Removes this Entity handle from its factory.
|
|
66
|
+
* @param lazy Whether optional families are acquired on first use.
|
|
67
|
+
* @param onAdmit Admits complete public Entity operations.
|
|
70
68
|
*/
|
|
71
|
-
constructor(input, open, onClose = () => undefined) {
|
|
69
|
+
constructor(input, open, onClose = () => undefined, lazy = false, onAdmit = (work) => work()) {
|
|
70
|
+
this.input = input;
|
|
71
|
+
this.open = open;
|
|
72
72
|
this.onClose = onClose;
|
|
73
|
-
this
|
|
73
|
+
this.onAdmit = onAdmit;
|
|
74
|
+
this.#current = new CurrentStorage(input, open(input.recordSpec), onAdmit);
|
|
74
75
|
this.current = this.#current;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
this.states = disabledStates(onAdmit);
|
|
77
|
+
this.events = disabledEvents(onAdmit);
|
|
78
|
+
if (!lazy)
|
|
79
|
+
this.ensure(Boolean(input.stateHistory), Boolean(input.eventHistory));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Acquires only missing requested history families, rolling back a failed upgrade.
|
|
83
|
+
*
|
|
84
|
+
* @param wantEvents Whether diagnostic Event history is required.
|
|
85
|
+
* @param wantStates Whether state history is required.
|
|
86
|
+
*/
|
|
87
|
+
ensure(wantStates, wantEvents) {
|
|
88
|
+
if (!this.#open)
|
|
89
|
+
throw new Error("MySQL Entity storage is closed.");
|
|
90
|
+
let states;
|
|
91
|
+
let events;
|
|
92
|
+
try {
|
|
93
|
+
if (wantStates && this.#states === undefined) {
|
|
94
|
+
const layout = stateHistorySpec(this.input.stateSchema);
|
|
95
|
+
states = new States(this.input, this.open(layout.spec, layout.group), this.onAdmit);
|
|
96
|
+
}
|
|
97
|
+
if (wantEvents && this.#events === undefined) {
|
|
98
|
+
const layout = eventHistorySpec(this.input.stateSchema);
|
|
99
|
+
events = new Events(this.input, this.open(layout.spec, layout.group), this.onAdmit);
|
|
100
|
+
}
|
|
101
|
+
this.#states ??= states;
|
|
102
|
+
this.#events ??= events;
|
|
103
|
+
this.states = this.#states ?? disabledStates(this.onAdmit);
|
|
104
|
+
this.events = this.#events ?? disabledEvents(this.onAdmit);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
const failures = [];
|
|
108
|
+
for (const port of [states, events]) {
|
|
109
|
+
try {
|
|
110
|
+
port?.close();
|
|
111
|
+
}
|
|
112
|
+
catch (cleanup) {
|
|
113
|
+
failures.push(cleanup);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (failures.length)
|
|
117
|
+
throw new AggregateError([error, ...failures], "MySQL family acquisition failed.");
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
83
120
|
}
|
|
84
121
|
/**
|
|
85
122
|
* Returns whether this Entity storage handle accepts operations.
|
|
@@ -96,10 +133,25 @@ export class MysqlEntityStorage {
|
|
|
96
133
|
if (!this.#open)
|
|
97
134
|
return;
|
|
98
135
|
this.#open = false;
|
|
99
|
-
|
|
100
|
-
this
|
|
101
|
-
|
|
102
|
-
|
|
136
|
+
const failures = [];
|
|
137
|
+
for (const port of [this.#current, this.#states, this.#events]) {
|
|
138
|
+
try {
|
|
139
|
+
port?.close();
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
failures.push(error);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
this.onClose();
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
failures.push(error);
|
|
150
|
+
}
|
|
151
|
+
if (failures.length === 1)
|
|
152
|
+
throw failures[0];
|
|
153
|
+
if (failures.length)
|
|
154
|
+
throw new AggregateError(failures, "MySQL Entity storage close failed.");
|
|
103
155
|
}
|
|
104
156
|
/**
|
|
105
157
|
* Prepares every Entity record-family table.
|
|
@@ -147,6 +199,15 @@ export class MysqlEntityStorage {
|
|
|
147
199
|
readCurrentLocked(id) {
|
|
148
200
|
return this.#current.readLocked(id);
|
|
149
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Writes current state inside an already admitted Agent transaction.
|
|
204
|
+
*
|
|
205
|
+
* @param record Committed current Entity state.
|
|
206
|
+
* @returns Completion after the record write.
|
|
207
|
+
*/
|
|
208
|
+
writeCurrentAdmitted(record) {
|
|
209
|
+
return this.#current.writeAdmitted(record);
|
|
210
|
+
}
|
|
150
211
|
/**
|
|
151
212
|
* Returns configured Entity history writers for the Agent transaction.
|
|
152
213
|
*
|
|
@@ -154,8 +215,8 @@ export class MysqlEntityStorage {
|
|
|
154
215
|
*/
|
|
155
216
|
commitCapability() {
|
|
156
217
|
return {
|
|
157
|
-
appendStateImmutable: (record) => this.#states?.
|
|
158
|
-
appendDiagnosticImmutable: (record) => this.#events?.
|
|
218
|
+
appendStateImmutable: (record) => this.#states?.appendAdmitted(record) ?? Promise.resolve(),
|
|
219
|
+
appendDiagnosticImmutable: (record) => this.#events?.appendAdmitted(record) ?? Promise.resolve(),
|
|
159
220
|
};
|
|
160
221
|
}
|
|
161
222
|
}
|
|
@@ -168,15 +229,18 @@ export class MysqlEntityStorage {
|
|
|
168
229
|
class CurrentStorage {
|
|
169
230
|
input;
|
|
170
231
|
records;
|
|
232
|
+
onAdmit;
|
|
171
233
|
/**
|
|
172
234
|
* Connects the Entity layout to its current-record handle.
|
|
173
235
|
*
|
|
174
236
|
* @param input Defines the Entity layout.
|
|
175
237
|
* @param records Stores current Entity records.
|
|
238
|
+
* @param onAdmit Admits complete public current operations.
|
|
176
239
|
*/
|
|
177
|
-
constructor(input, records) {
|
|
240
|
+
constructor(input, records, onAdmit) {
|
|
178
241
|
this.input = input;
|
|
179
242
|
this.records = records;
|
|
243
|
+
this.onAdmit = onAdmit;
|
|
180
244
|
}
|
|
181
245
|
/**
|
|
182
246
|
* Returns the current-record table name.
|
|
@@ -213,7 +277,7 @@ class CurrentStorage {
|
|
|
213
277
|
* @returns The current record when present.
|
|
214
278
|
*/
|
|
215
279
|
read(id) {
|
|
216
|
-
return this.records.read(id);
|
|
280
|
+
return this.onAdmit(() => this.records.read(id));
|
|
217
281
|
}
|
|
218
282
|
/**
|
|
219
283
|
* Writes the current Entity record.
|
|
@@ -222,6 +286,15 @@ class CurrentStorage {
|
|
|
222
286
|
* @returns Completion after the write.
|
|
223
287
|
*/
|
|
224
288
|
write(record) {
|
|
289
|
+
return this.onAdmit(() => this.writeAdmitted(record));
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Executes an admitted provider operation.
|
|
293
|
+
*
|
|
294
|
+
* @param record Current Entity record.
|
|
295
|
+
* @returns Stored result.
|
|
296
|
+
*/
|
|
297
|
+
writeAdmitted(record) {
|
|
225
298
|
return this.records.write(record);
|
|
226
299
|
}
|
|
227
300
|
/**
|
|
@@ -231,6 +304,15 @@ class CurrentStorage {
|
|
|
231
304
|
* @returns Matching records and mapped column values.
|
|
232
305
|
*/
|
|
233
306
|
async query(plan) {
|
|
307
|
+
return this.onAdmit(() => this.queryAdmitted(plan));
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Executes an admitted provider operation.
|
|
311
|
+
*
|
|
312
|
+
* @param plan Normalized query.
|
|
313
|
+
* @returns Current records and columns.
|
|
314
|
+
*/
|
|
315
|
+
async queryAdmitted(plan) {
|
|
234
316
|
const entries = await this.records.queryPlanEntries(plan);
|
|
235
317
|
return entries.map((entry) => {
|
|
236
318
|
if (entry.record.entityId === undefined)
|
|
@@ -254,9 +336,7 @@ class CurrentStorage {
|
|
|
254
336
|
return this.records.prepare();
|
|
255
337
|
}
|
|
256
338
|
/**
|
|
257
|
-
|
|
258
339
|
* Closes the current record handle.
|
|
259
|
-
|
|
260
340
|
*/
|
|
261
341
|
close() {
|
|
262
342
|
this.records.close();
|
|
@@ -271,15 +351,18 @@ class CurrentStorage {
|
|
|
271
351
|
class States {
|
|
272
352
|
input;
|
|
273
353
|
records;
|
|
354
|
+
onAdmit;
|
|
274
355
|
/**
|
|
275
356
|
* Connects the Entity layout to its state-history handle.
|
|
276
357
|
*
|
|
277
358
|
* @param input Defines the Entity ID and state schemas.
|
|
278
359
|
* @param records Stores immutable state-history records.
|
|
360
|
+
* @param onAdmit Admits complete public state-history operations.
|
|
279
361
|
*/
|
|
280
|
-
constructor(input, records) {
|
|
362
|
+
constructor(input, records, onAdmit) {
|
|
281
363
|
this.input = input;
|
|
282
364
|
this.records = records;
|
|
365
|
+
this.onAdmit = onAdmit;
|
|
283
366
|
}
|
|
284
367
|
/**
|
|
285
368
|
* Returns the state-history table name.
|
|
@@ -307,6 +390,15 @@ class States {
|
|
|
307
390
|
* @returns Completion after insertion or identical retry.
|
|
308
391
|
*/
|
|
309
392
|
append(record) {
|
|
393
|
+
return this.onAdmit(() => this.appendAdmitted(record));
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Executes an admitted provider operation.
|
|
397
|
+
*
|
|
398
|
+
* @param record Immutable state record.
|
|
399
|
+
* @returns Stored result.
|
|
400
|
+
*/
|
|
401
|
+
appendAdmitted(record) {
|
|
310
402
|
return this.records.writeImmutable(record);
|
|
311
403
|
}
|
|
312
404
|
/**
|
|
@@ -318,6 +410,17 @@ class States {
|
|
|
318
410
|
* @returns Matching states in descending version order.
|
|
319
411
|
*/
|
|
320
412
|
async backward(id, depth, startingFromVersion) {
|
|
413
|
+
return this.onAdmit(() => this.backwardAdmitted(id, depth, startingFromVersion));
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Executes an admitted provider operation.
|
|
417
|
+
*
|
|
418
|
+
* @param id Entity ID.
|
|
419
|
+
* @param depth Read limit.
|
|
420
|
+
* @param startingFromVersion Maximum version.
|
|
421
|
+
* @returns Retained states in reverse order.
|
|
422
|
+
*/
|
|
423
|
+
async backwardAdmitted(id, depth, startingFromVersion) {
|
|
321
424
|
const all = await this.records.query({ sort: [{ field: "version", direction: "desc" }] });
|
|
322
425
|
return all
|
|
323
426
|
.filter((record) => record.entityId !== undefined &&
|
|
@@ -334,7 +437,17 @@ class States {
|
|
|
334
437
|
* @returns Decoded state when present.
|
|
335
438
|
*/
|
|
336
439
|
async stateAt(id, time) {
|
|
337
|
-
|
|
440
|
+
return this.onAdmit(() => this.stateAtAdmitted(id, time));
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Executes an admitted provider operation.
|
|
444
|
+
*
|
|
445
|
+
* @param id Entity ID.
|
|
446
|
+
* @param time Inclusive timestamp.
|
|
447
|
+
* @returns State at the requested time.
|
|
448
|
+
*/
|
|
449
|
+
async stateAtAdmitted(id, time) {
|
|
450
|
+
const records = await this.backwardAdmitted(id, Number.MAX_SAFE_INTEGER);
|
|
338
451
|
const found = records.find((record) => {
|
|
339
452
|
const timestamp = record.version?.timestamp;
|
|
340
453
|
return (timestamp !== undefined &&
|
|
@@ -343,7 +456,7 @@ class States {
|
|
|
343
456
|
});
|
|
344
457
|
return found?.state === undefined
|
|
345
458
|
? undefined
|
|
346
|
-
:
|
|
459
|
+
: AnyPacker.unpack(found.state, this.input.stateSchema);
|
|
347
460
|
}
|
|
348
461
|
/**
|
|
349
462
|
* Removes older states beyond the requested retained count.
|
|
@@ -353,7 +466,17 @@ class States {
|
|
|
353
466
|
* @returns Completion after independent deletions.
|
|
354
467
|
*/
|
|
355
468
|
async trim(id, keep) {
|
|
356
|
-
|
|
469
|
+
return this.onAdmit(() => this.trimAdmitted(id, keep));
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Executes an admitted provider operation.
|
|
473
|
+
*
|
|
474
|
+
* @param id Entity ID.
|
|
475
|
+
* @param keep Retained count.
|
|
476
|
+
* @returns Completion after older states are removed.
|
|
477
|
+
*/
|
|
478
|
+
async trimAdmitted(id, keep) {
|
|
479
|
+
const records = await this.backwardAdmitted(id, Number.MAX_SAFE_INTEGER);
|
|
357
480
|
for (const record of records.slice(keep)) {
|
|
358
481
|
if (record.entityId !== undefined)
|
|
359
482
|
await this.records.delete(create(EntityStateKeySchema, {
|
|
@@ -369,6 +492,15 @@ class States {
|
|
|
369
492
|
* @returns Completion after independent deletions.
|
|
370
493
|
*/
|
|
371
494
|
async truncate(olderThan) {
|
|
495
|
+
return this.onAdmit(() => this.truncateAdmitted(olderThan));
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Executes an admitted provider operation.
|
|
499
|
+
*
|
|
500
|
+
* @param olderThan Exclusive cutoff.
|
|
501
|
+
* @returns Completion after truncation.
|
|
502
|
+
*/
|
|
503
|
+
async truncateAdmitted(olderThan) {
|
|
372
504
|
const all = await this.records.query();
|
|
373
505
|
for (const record of all) {
|
|
374
506
|
const timestamp = record.version?.timestamp;
|
|
@@ -383,9 +515,7 @@ class States {
|
|
|
383
515
|
}
|
|
384
516
|
}
|
|
385
517
|
/**
|
|
386
|
-
|
|
387
518
|
* Closes the state-history handle.
|
|
388
|
-
|
|
389
519
|
*/
|
|
390
520
|
close() {
|
|
391
521
|
this.records.close();
|
|
@@ -408,15 +538,18 @@ class States {
|
|
|
408
538
|
class Events {
|
|
409
539
|
input;
|
|
410
540
|
records;
|
|
541
|
+
onAdmit;
|
|
411
542
|
/**
|
|
412
543
|
* Connects the Entity layout to its diagnostic-history handle.
|
|
413
544
|
*
|
|
414
545
|
* @param input Defines the Entity ID and state schemas.
|
|
415
546
|
* @param records Stores immutable diagnostic Events.
|
|
547
|
+
* @param onAdmit Admits complete public Event-history operations.
|
|
416
548
|
*/
|
|
417
|
-
constructor(input, records) {
|
|
549
|
+
constructor(input, records, onAdmit) {
|
|
418
550
|
this.input = input;
|
|
419
551
|
this.records = records;
|
|
552
|
+
this.onAdmit = onAdmit;
|
|
420
553
|
}
|
|
421
554
|
/**
|
|
422
555
|
* Returns the diagnostic Event-history table name.
|
|
@@ -444,6 +577,15 @@ class Events {
|
|
|
444
577
|
* @returns Completion after insertion or identical retry.
|
|
445
578
|
*/
|
|
446
579
|
append(record) {
|
|
580
|
+
return this.onAdmit(() => this.appendAdmitted(record));
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Executes an admitted provider operation.
|
|
584
|
+
*
|
|
585
|
+
* @param record Immutable diagnostic Event.
|
|
586
|
+
* @returns Stored result.
|
|
587
|
+
*/
|
|
588
|
+
appendAdmitted(record) {
|
|
447
589
|
return this.records.writeImmutable(record);
|
|
448
590
|
}
|
|
449
591
|
/**
|
|
@@ -455,6 +597,17 @@ class Events {
|
|
|
455
597
|
* @returns Matching Events in descending version order.
|
|
456
598
|
*/
|
|
457
599
|
async backward(id, depth, startingFromVersion) {
|
|
600
|
+
return this.onAdmit(() => this.backwardAdmitted(id, depth, startingFromVersion));
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Executes an admitted provider operation.
|
|
604
|
+
*
|
|
605
|
+
* @param id Producer ID.
|
|
606
|
+
* @param depth Read limit.
|
|
607
|
+
* @param startingFromVersion Maximum version.
|
|
608
|
+
* @returns Diagnostic Events in reverse order.
|
|
609
|
+
*/
|
|
610
|
+
async backwardAdmitted(id, depth, startingFromVersion) {
|
|
458
611
|
const all = await this.records.query({ sort: [{ field: "version", direction: "desc" }] });
|
|
459
612
|
return all
|
|
460
613
|
.filter((event) => event.context?.producerId !== undefined &&
|
|
@@ -470,6 +623,15 @@ class Events {
|
|
|
470
623
|
* @returns Completion after independent deletions.
|
|
471
624
|
*/
|
|
472
625
|
async truncate(olderThan) {
|
|
626
|
+
return this.onAdmit(() => this.truncateAdmitted(olderThan));
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Executes an admitted provider operation.
|
|
630
|
+
*
|
|
631
|
+
* @param olderThan Exclusive cutoff.
|
|
632
|
+
* @returns Completion after truncation.
|
|
633
|
+
*/
|
|
634
|
+
async truncateAdmitted(olderThan) {
|
|
473
635
|
const all = await this.records.query();
|
|
474
636
|
for (const event of all) {
|
|
475
637
|
const timestamp = event.context?.timestamp;
|
|
@@ -481,9 +643,7 @@ class Events {
|
|
|
481
643
|
}
|
|
482
644
|
}
|
|
483
645
|
/**
|
|
484
|
-
|
|
485
646
|
* Closes the diagnostic-history handle.
|
|
486
|
-
|
|
487
647
|
*/
|
|
488
648
|
close() {
|
|
489
649
|
this.records.close();
|
|
@@ -502,15 +662,16 @@ class Events {
|
|
|
502
662
|
*
|
|
503
663
|
* @typeParam I Entity identifier type.
|
|
504
664
|
* @typeParam S Entity state message type.
|
|
665
|
+
* @param onAdmit Admits public calls even when history is disabled.
|
|
505
666
|
* @returns A disabled state-history port.
|
|
506
667
|
*/
|
|
507
|
-
function disabledStates() {
|
|
668
|
+
function disabledStates(onAdmit) {
|
|
508
669
|
return {
|
|
509
|
-
append: () => Promise.reject(new Error("Entity state history is disabled.")),
|
|
510
|
-
backward: () => Promise.resolve([]),
|
|
511
|
-
stateAt: () => Promise.resolve(undefined),
|
|
512
|
-
trim: () => Promise.resolve(),
|
|
513
|
-
truncate: () => Promise.resolve(),
|
|
670
|
+
append: () => onAdmit(() => Promise.reject(new Error("Entity state history is disabled."))),
|
|
671
|
+
backward: () => onAdmit(() => Promise.resolve([])),
|
|
672
|
+
stateAt: () => onAdmit(() => Promise.resolve(undefined)),
|
|
673
|
+
trim: () => onAdmit(() => Promise.resolve()),
|
|
674
|
+
truncate: () => onAdmit(() => Promise.resolve()),
|
|
514
675
|
close: () => undefined,
|
|
515
676
|
};
|
|
516
677
|
}
|
|
@@ -518,13 +679,14 @@ function disabledStates() {
|
|
|
518
679
|
* Creates a rejecting diagnostic-history port when retention is disabled.
|
|
519
680
|
*
|
|
520
681
|
* @typeParam I Entity identifier type.
|
|
682
|
+
* @param onAdmit Admits public calls even when history is disabled.
|
|
521
683
|
* @returns A disabled diagnostic-history port.
|
|
522
684
|
*/
|
|
523
|
-
function disabledEvents() {
|
|
685
|
+
function disabledEvents(onAdmit) {
|
|
524
686
|
return {
|
|
525
|
-
append: () => Promise.reject(new Error("Entity event history is disabled.")),
|
|
526
|
-
backward: () => Promise.resolve([]),
|
|
527
|
-
truncate: () => Promise.resolve(),
|
|
687
|
+
append: () => onAdmit(() => Promise.reject(new Error("Entity event history is disabled."))),
|
|
688
|
+
backward: () => onAdmit(() => Promise.resolve([])),
|
|
689
|
+
truncate: () => onAdmit(() => Promise.resolve()),
|
|
528
690
|
close: () => undefined,
|
|
529
691
|
};
|
|
530
692
|
}
|