@spine-event-engine/storage-mysql 2.0.0-snapshot.13
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/LICENSE +201 -0
- package/README.md +243 -0
- package/REFERENCE.md +140 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/mysql/column-mapping.d.ts +27 -0
- package/dist/mysql/column-mapping.d.ts.map +1 -0
- package/dist/mysql/column-mapping.js +94 -0
- package/dist/mysql/column-mapping.js.map +1 -0
- package/dist/mysql/delivery-cleanup.d.ts +37 -0
- package/dist/mysql/delivery-cleanup.d.ts.map +1 -0
- package/dist/mysql/delivery-cleanup.js +108 -0
- package/dist/mysql/delivery-cleanup.js.map +1 -0
- package/dist/mysql/entity-commit.d.ts +79 -0
- package/dist/mysql/entity-commit.d.ts.map +1 -0
- package/dist/mysql/entity-commit.js +123 -0
- package/dist/mysql/entity-commit.js.map +1 -0
- package/dist/mysql/entity-history.d.ts +123 -0
- package/dist/mysql/entity-history.d.ts.map +1 -0
- package/dist/mysql/entity-history.js +347 -0
- package/dist/mysql/entity-history.js.map +1 -0
- package/dist/mysql/errors.d.ts +25 -0
- package/dist/mysql/errors.d.ts.map +1 -0
- package/dist/mysql/errors.js +44 -0
- package/dist/mysql/errors.js.map +1 -0
- package/dist/mysql/id-column.d.ts +36 -0
- package/dist/mysql/id-column.d.ts.map +1 -0
- package/dist/mysql/id-column.js +113 -0
- package/dist/mysql/id-column.js.map +1 -0
- package/dist/mysql/record-storage.d.ts +379 -0
- package/dist/mysql/record-storage.d.ts.map +1 -0
- package/dist/mysql/record-storage.js +941 -0
- package/dist/mysql/record-storage.js.map +1 -0
- package/dist/mysql/storage-factory.d.ts +218 -0
- package/dist/mysql/storage-factory.d.ts.map +1 -0
- package/dist/mysql/storage-factory.js +477 -0
- package/dist/mysql/storage-factory.js.map +1 -0
- package/dist/mysql/table-resolver.d.ts +34 -0
- package/dist/mysql/table-resolver.d.ts.map +1 -0
- package/dist/mysql/table-resolver.js +87 -0
- package/dist/mysql/table-resolver.js.map +1 -0
- package/dist/mysql/table-spec.d.ts +88 -0
- package/dist/mysql/table-spec.d.ts.map +1 -0
- package/dist/mysql/table-spec.js +105 -0
- package/dist/mysql/table-spec.js.map +1 -0
- package/dist/mysql/testing.d.ts +47 -0
- package/dist/mysql/testing.d.ts.map +1 -0
- package/dist/mysql/testing.js +111 -0
- package/dist/mysql/testing.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Message } from "@bufbuild/protobuf";
|
|
2
|
+
import type { GenMessage } from "@bufbuild/protobuf/codegenv2";
|
|
3
|
+
import type { RecordColumn, RecordColumnType } from "@spine-event-engine/storage";
|
|
4
|
+
/**
|
|
5
|
+
* Describes the private physical identity for one record family.
|
|
6
|
+
*/
|
|
7
|
+
export interface MysqlResolvedTable {
|
|
8
|
+
/**
|
|
9
|
+
* Names the physical table.
|
|
10
|
+
*/
|
|
11
|
+
readonly tableName: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Maps a declared storage column value type to its native MySQL type.
|
|
15
|
+
*
|
|
16
|
+
* @param type Retains the generated Protobuf value type.
|
|
17
|
+
* @returns Returns the native MySQL type.
|
|
18
|
+
*/
|
|
19
|
+
export declare function mysqlColumnType(type: RecordColumnType): string;
|
|
20
|
+
/**
|
|
21
|
+
* Describes one public MySQL column in a resolved record-family table.
|
|
22
|
+
*/
|
|
23
|
+
export interface MysqlColumnSpec {
|
|
24
|
+
/**
|
|
25
|
+
* Names the physical column.
|
|
26
|
+
*/
|
|
27
|
+
readonly name: string;
|
|
28
|
+
/**
|
|
29
|
+
* Specifies the canonical native MySQL type.
|
|
30
|
+
*/
|
|
31
|
+
readonly mysqlType: string;
|
|
32
|
+
/**
|
|
33
|
+
* Controls whether the column accepts null values.
|
|
34
|
+
*/
|
|
35
|
+
readonly nullable: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Supplies an optional canonical SQL default expression.
|
|
38
|
+
*/
|
|
39
|
+
readonly defaultSql?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Describes the public resolved MySQL layout for one record family.
|
|
43
|
+
*/
|
|
44
|
+
export interface MysqlTableSpec<I, R extends Message> {
|
|
45
|
+
/**
|
|
46
|
+
* Names the physical table.
|
|
47
|
+
*/
|
|
48
|
+
readonly tableName: string;
|
|
49
|
+
/**
|
|
50
|
+
* Identifies the record source Protobuf type.
|
|
51
|
+
*/
|
|
52
|
+
readonly sourceType: GenMessage<Message>;
|
|
53
|
+
/**
|
|
54
|
+
* Identifies the stored record Protobuf type.
|
|
55
|
+
*/
|
|
56
|
+
readonly recordType: GenMessage<R>;
|
|
57
|
+
/**
|
|
58
|
+
* Identifies the storage ID type.
|
|
59
|
+
*/
|
|
60
|
+
readonly idType: I extends Message ? GenMessage<I> : string;
|
|
61
|
+
/**
|
|
62
|
+
* Names the optional storage group.
|
|
63
|
+
*/
|
|
64
|
+
readonly groupName?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Lists canonical table columns.
|
|
67
|
+
*/
|
|
68
|
+
readonly columns: readonly MysqlColumnSpec[];
|
|
69
|
+
/**
|
|
70
|
+
* Lists primary-key column names in order.
|
|
71
|
+
*/
|
|
72
|
+
readonly primaryKey: readonly string[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Builds the canonical public layout for one resolved record family.
|
|
76
|
+
*
|
|
77
|
+
* @param input Identifies the resolved family and its declared columns.
|
|
78
|
+
* @returns Returns the canonical table layout.
|
|
79
|
+
*/
|
|
80
|
+
export declare function resolvedMysqlTableSpec<I, R extends Message>(input: {
|
|
81
|
+
readonly tableName: string;
|
|
82
|
+
readonly sourceType: GenMessage<Message>;
|
|
83
|
+
readonly recordType: GenMessage<R>;
|
|
84
|
+
readonly idType: I extends Message ? GenMessage<I> : string;
|
|
85
|
+
readonly groupName?: string;
|
|
86
|
+
readonly declaredColumns: readonly RecordColumn<R>[];
|
|
87
|
+
}): MysqlTableSpec<I, R>;
|
|
88
|
+
//# sourceMappingURL=table-spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-spec.d.ts","sourceRoot":"","sources":["../../src/mysql/table-spec.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAIlF;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAGjC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAiC9D;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAG9B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO;IAGlD;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAEzC;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IAEnC;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,SAAS,OAAO,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;IAE5D;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,CAAC;IAE7C;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;CACxC;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,KAAK,EAAE;IAClE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IACzC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,CAAC,SAAS,OAAO,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;IAC5D,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,eAAe,EAAE,SAAS,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;CACtD,GAAG,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAgBvB"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026, CodeMatters. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
5
|
+
* in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
10
|
+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
11
|
+
* or implied. See the License for the specific language governing permissions and limitations under
|
|
12
|
+
* the License.
|
|
13
|
+
*/
|
|
14
|
+
import { ScalarType } from "@bufbuild/protobuf";
|
|
15
|
+
import { MysqlIdColumn } from "./id-column.js";
|
|
16
|
+
/**
|
|
17
|
+
* Maps a declared storage column value type to its native MySQL type.
|
|
18
|
+
*
|
|
19
|
+
* @param type Retains the generated Protobuf value type.
|
|
20
|
+
* @returns Returns the native MySQL type.
|
|
21
|
+
*/
|
|
22
|
+
export function mysqlColumnType(type) {
|
|
23
|
+
switch (type.kind) {
|
|
24
|
+
case "enum":
|
|
25
|
+
return "INT";
|
|
26
|
+
case "message":
|
|
27
|
+
if (type.message.typeName === "google.protobuf.Timestamp")
|
|
28
|
+
return "BIGINT";
|
|
29
|
+
if (type.message.typeName === "spine.core.Version")
|
|
30
|
+
return "INT";
|
|
31
|
+
return "TEXT";
|
|
32
|
+
case "scalar":
|
|
33
|
+
switch (type.scalar) {
|
|
34
|
+
case ScalarType.STRING:
|
|
35
|
+
return "TEXT";
|
|
36
|
+
case ScalarType.INT32:
|
|
37
|
+
case ScalarType.SINT32:
|
|
38
|
+
case ScalarType.SFIXED32:
|
|
39
|
+
case ScalarType.UINT32:
|
|
40
|
+
case ScalarType.FIXED32:
|
|
41
|
+
return "INT";
|
|
42
|
+
case ScalarType.INT64:
|
|
43
|
+
case ScalarType.SINT64:
|
|
44
|
+
case ScalarType.SFIXED64:
|
|
45
|
+
case ScalarType.UINT64:
|
|
46
|
+
case ScalarType.FIXED64:
|
|
47
|
+
return "BIGINT";
|
|
48
|
+
case ScalarType.BOOL:
|
|
49
|
+
return "BOOLEAN";
|
|
50
|
+
case ScalarType.BYTES:
|
|
51
|
+
return "BLOB";
|
|
52
|
+
case ScalarType.FLOAT:
|
|
53
|
+
case ScalarType.DOUBLE:
|
|
54
|
+
throw new Error("Spine JVM JDBC does not support floating-point record columns.");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Builds the canonical public layout for one resolved record family.
|
|
60
|
+
*
|
|
61
|
+
* @param input Identifies the resolved family and its declared columns.
|
|
62
|
+
* @returns Returns the canonical table layout.
|
|
63
|
+
*/
|
|
64
|
+
export function resolvedMysqlTableSpec(input) {
|
|
65
|
+
return {
|
|
66
|
+
tableName: input.tableName,
|
|
67
|
+
sourceType: input.sourceType,
|
|
68
|
+
recordType: input.recordType,
|
|
69
|
+
idType: input.idType,
|
|
70
|
+
...(input.groupName === undefined ? {} : { groupName: input.groupName }),
|
|
71
|
+
columns: [
|
|
72
|
+
{ name: "ID", mysqlType: new MysqlIdColumn(input.idType).mysqlType, nullable: false },
|
|
73
|
+
{ name: "bytes", mysqlType: "BLOB", nullable: false },
|
|
74
|
+
...input.declaredColumns.map((column) => mysqlColumnSpec(input.recordType, input.groupName, column)),
|
|
75
|
+
],
|
|
76
|
+
primaryKey: ["ID"],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function mysqlColumnSpec(recordType, groupName, column) {
|
|
80
|
+
const entityDefault = entityAttributeDefault(recordType, groupName, column);
|
|
81
|
+
return {
|
|
82
|
+
name: column.name,
|
|
83
|
+
mysqlType: mysqlColumnType(column.type),
|
|
84
|
+
nullable: entityDefault === undefined,
|
|
85
|
+
...(entityDefault === undefined ? {} : { defaultSql: entityDefault }),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function entityAttributeDefault(recordType, groupName, column) {
|
|
89
|
+
if (recordType.typeName !== "spine.server.entity.EntityRecord" || groupName !== undefined)
|
|
90
|
+
return undefined;
|
|
91
|
+
switch (column.name) {
|
|
92
|
+
case "archived":
|
|
93
|
+
case "deleted":
|
|
94
|
+
return column.type.kind === "scalar" && column.type.scalar === ScalarType.BOOL
|
|
95
|
+
? "false"
|
|
96
|
+
: undefined;
|
|
97
|
+
case "version":
|
|
98
|
+
return column.type.kind === "message" && column.type.message.typeName === "spine.core.Version"
|
|
99
|
+
? "0"
|
|
100
|
+
: undefined;
|
|
101
|
+
default:
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=table-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-spec.js","sourceRoot":"","sources":["../../src/mysql/table-spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAc/C;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAAsB;IACpD,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,MAAM;YACT,OAAO,KAAK,CAAC;QACf,KAAK,SAAS;YACZ,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,KAAK,2BAA2B;gBAAE,OAAO,QAAQ,CAAC;YAC3E,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,KAAK,oBAAoB;gBAAE,OAAO,KAAK,CAAC;YACjE,OAAO,MAAM,CAAC;QAChB,KAAK,QAAQ;YACX,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;gBACpB,KAAK,UAAU,CAAC,MAAM;oBACpB,OAAO,MAAM,CAAC;gBAChB,KAAK,UAAU,CAAC,KAAK,CAAC;gBACtB,KAAK,UAAU,CAAC,MAAM,CAAC;gBACvB,KAAK,UAAU,CAAC,QAAQ,CAAC;gBACzB,KAAK,UAAU,CAAC,MAAM,CAAC;gBACvB,KAAK,UAAU,CAAC,OAAO;oBACrB,OAAO,KAAK,CAAC;gBACf,KAAK,UAAU,CAAC,KAAK,CAAC;gBACtB,KAAK,UAAU,CAAC,MAAM,CAAC;gBACvB,KAAK,UAAU,CAAC,QAAQ,CAAC;gBACzB,KAAK,UAAU,CAAC,MAAM,CAAC;gBACvB,KAAK,UAAU,CAAC,OAAO;oBACrB,OAAO,QAAQ,CAAC;gBAClB,KAAK,UAAU,CAAC,IAAI;oBAClB,OAAO,SAA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E,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC;QACvC,QAAQ,EAAE,aAAa,KAAK,SAAS;QACrC,GAAG,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;KACtE,CAAC;AACJ,CAAC;AAED,SAAS,sBAAsB,CAC7B,UAAyB,EACzB,SAA6B,EAC7B,MAAuB;IAEvB,IAAI,UAAU,CAAC,QAAQ,KAAK,kCAAkC,IAAI,SAAS,KAAK,SAAS;QACvF,OAAO,SAAS,CAAC;IACnB,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,UAAU,CAAC;QAChB,KAAK,SAAS;YACZ,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,KAAK,UAAU,CAAC,IAAI;gBAC5E,CAAC,CAAC,OAAO;gBACT,CAAC,CAAC,SAAS,CAAC;QAChB,KAAK,SAAS;YACZ,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,KAAK,oBAAoB;gBAC5F,CAAC,CAAC,GAAG;gBACL,CAAC,CAAC,SAAS,CAAC;QAChB;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Message } from "@bufbuild/protobuf";
|
|
2
|
+
import { StringifierRegistry } from "@spine-event-engine/core";
|
|
3
|
+
import { type EntityStorageInput } from "@spine-event-engine/storage/provider";
|
|
4
|
+
import type { RecordSpec, StorageGroup } from "@spine-event-engine/storage";
|
|
5
|
+
import type { Pool } from "mysql2/promise";
|
|
6
|
+
/**
|
|
7
|
+
* Resolves the default table name for a record-family integration test.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
* @param spec Describes the record family.
|
|
11
|
+
* @param group Identifies an optional storage group.
|
|
12
|
+
* @returns The default physical table name.
|
|
13
|
+
*/
|
|
14
|
+
export declare function mysqlRecordTableName<I, R extends Message>(spec: RecordSpec<I, R>, group?: StorageGroup): string;
|
|
15
|
+
/**
|
|
16
|
+
* Resolves the default tables used by an Entity-family integration test.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
* @param input Describes the Entity family and enabled histories.
|
|
20
|
+
* @returns The current and enabled history table names.
|
|
21
|
+
*/
|
|
22
|
+
export declare function mysqlEntityTables<I, S extends Message>(input: EntityStorageInput<I, S>): readonly string[];
|
|
23
|
+
/**
|
|
24
|
+
* Reads the current Entity record for a provider integration test.
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
* @param pool Queries the test database.
|
|
28
|
+
* @param input Identifies the Entity family.
|
|
29
|
+
* @param id Identifies the current Entity row.
|
|
30
|
+
* @param stringifiers Converts message-valued identifiers using the factory's mapping.
|
|
31
|
+
* @returns Resolves to the current record, or `undefined` when it is absent.
|
|
32
|
+
*/
|
|
33
|
+
export declare function mysqlCurrentRecord<I, S extends Message>(pool: Pool, input: EntityStorageInput<I, S>, id: I, stringifiers?: StringifierRegistry): Promise<import("@spine-event-engine/proto/generated/spine/server/entity/entity_pb.js").EntityRecord | undefined>;
|
|
34
|
+
/**
|
|
35
|
+
* Returns retained state and diagnostic record counts for one Entity in a provider test.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
* @param pool Queries the test database.
|
|
39
|
+
* @param input Identifies the Entity family.
|
|
40
|
+
* @param id Identifies the Entity whose histories are counted.
|
|
41
|
+
* @returns Resolves to the matching state and diagnostic counts.
|
|
42
|
+
*/
|
|
43
|
+
export declare function mysqlHistoryCounts<I, S extends Message>(pool: Pool, input: EntityStorageInput<I, S>, id: I): Promise<{
|
|
44
|
+
readonly states: number;
|
|
45
|
+
readonly events: number;
|
|
46
|
+
}>;
|
|
47
|
+
//# sourceMappingURL=testing.d.ts.map
|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E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAqB/D"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026, CodeMatters. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
5
|
+
* in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
10
|
+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
11
|
+
* or implied. See the License for the specific language governing permissions and limitations under
|
|
12
|
+
* the License.
|
|
13
|
+
*/
|
|
14
|
+
import { fromBinary, toBinary } from "@bufbuild/protobuf";
|
|
15
|
+
import { AnySchema } from "@bufbuild/protobuf/wkt";
|
|
16
|
+
import { EventSchema } from "@spine-event-engine/proto";
|
|
17
|
+
import { StringifierRegistry } from "@spine-event-engine/core";
|
|
18
|
+
import { EntityRecordSchema } from "@spine-event-engine/proto/generated/spine/server/entity/entity_pb.js";
|
|
19
|
+
import { eventHistorySpec, stateHistorySpec, } from "@spine-event-engine/storage/provider";
|
|
20
|
+
import { MysqlTableResolver } from "./table-resolver.js";
|
|
21
|
+
import { MysqlIdColumn } from "./id-column.js";
|
|
22
|
+
/**
|
|
23
|
+
* Resolves the default table name for a record-family integration test.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
* @param spec Describes the record family.
|
|
27
|
+
* @param group Identifies an optional storage group.
|
|
28
|
+
* @returns The default physical table name.
|
|
29
|
+
*/
|
|
30
|
+
export function mysqlRecordTableName(spec, group) {
|
|
31
|
+
return new MysqlTableResolver().resolve(spec.sourceType.typeName, group?.name, undefined, spec.recordType.typeName).tableName;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Resolves the default tables used by an Entity-family integration test.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
* @param input Describes the Entity family and enabled histories.
|
|
38
|
+
* @returns The current and enabled history table names.
|
|
39
|
+
*/
|
|
40
|
+
export function mysqlEntityTables(input) {
|
|
41
|
+
const tables = [
|
|
42
|
+
new MysqlTableResolver().resolve(input.sourceType.typeName, undefined, undefined, EntityRecordSchema.typeName).tableName,
|
|
43
|
+
];
|
|
44
|
+
if (input.stateHistory) {
|
|
45
|
+
const state = stateHistorySpec(input.stateSchema);
|
|
46
|
+
tables.push(mysqlRecordTableName(state.spec, state.group));
|
|
47
|
+
}
|
|
48
|
+
if (input.eventHistory) {
|
|
49
|
+
const event = eventHistorySpec(input.stateSchema);
|
|
50
|
+
tables.push(mysqlRecordTableName(event.spec, event.group));
|
|
51
|
+
}
|
|
52
|
+
return tables;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Reads the current Entity record for a provider integration test.
|
|
56
|
+
*
|
|
57
|
+
* @internal
|
|
58
|
+
* @param pool Queries the test database.
|
|
59
|
+
* @param input Identifies the Entity family.
|
|
60
|
+
* @param id Identifies the current Entity row.
|
|
61
|
+
* @param stringifiers Converts message-valued identifiers using the factory's mapping.
|
|
62
|
+
* @returns Resolves to the current record, or `undefined` when it is absent.
|
|
63
|
+
*/
|
|
64
|
+
export async function mysqlCurrentRecord(pool, input, id, stringifiers = new StringifierRegistry()) {
|
|
65
|
+
const table = mysqlEntityTables(input)[0];
|
|
66
|
+
if (table === undefined)
|
|
67
|
+
throw new Error("Current Entity table is missing.");
|
|
68
|
+
const [rows] = await pool.query(`SELECT bytes FROM \`${table}\` WHERE ID=?`, [new MysqlIdColumn(input.recordSpec.idType, stringifiers).value(id)]);
|
|
69
|
+
return rows[0] === undefined ? undefined : fromBinary(EntityRecordSchema, rows[0].bytes);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Returns retained state and diagnostic record counts for one Entity in a provider test.
|
|
73
|
+
*
|
|
74
|
+
* @internal
|
|
75
|
+
* @param pool Queries the test database.
|
|
76
|
+
* @param input Identifies the Entity family.
|
|
77
|
+
* @param id Identifies the Entity whose histories are counted.
|
|
78
|
+
* @returns Resolves to the matching state and diagnostic counts.
|
|
79
|
+
*/
|
|
80
|
+
export async function mysqlHistoryCounts(pool, input, id) {
|
|
81
|
+
const packedId = input.id.pack(id);
|
|
82
|
+
let states = 0;
|
|
83
|
+
if (input.stateHistory) {
|
|
84
|
+
const state = stateHistorySpec(input.stateSchema);
|
|
85
|
+
const rows = await recordBytes(pool, input, state.spec, state.group);
|
|
86
|
+
states = rows.filter((bytes) => {
|
|
87
|
+
const record = fromBinary(EntityRecordSchema, bytes);
|
|
88
|
+
return sameAny(record.entityId, packedId);
|
|
89
|
+
}).length;
|
|
90
|
+
}
|
|
91
|
+
let events = 0;
|
|
92
|
+
if (input.eventHistory) {
|
|
93
|
+
const event = eventHistorySpec(input.stateSchema);
|
|
94
|
+
const rows = await recordBytes(pool, input, event.spec, event.group);
|
|
95
|
+
events = rows.filter((bytes) => {
|
|
96
|
+
const record = fromBinary(EventSchema, bytes);
|
|
97
|
+
return sameAny(record.context?.producerId, packedId);
|
|
98
|
+
}).length;
|
|
99
|
+
}
|
|
100
|
+
return { states, events };
|
|
101
|
+
}
|
|
102
|
+
async function recordBytes(pool, input, spec, group) {
|
|
103
|
+
const table = mysqlRecordTableName(spec, group);
|
|
104
|
+
const [rows] = await pool.query(`SELECT bytes FROM \`${table}\``);
|
|
105
|
+
return rows.map((row) => row.bytes);
|
|
106
|
+
}
|
|
107
|
+
function sameAny(left, right) {
|
|
108
|
+
return (left !== undefined &&
|
|
109
|
+
Buffer.compare(toBinary(AnySchema, left), toBinary(AnySchema, right)) === 0);
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing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