@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.
Files changed (53) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +243 -0
  3. package/REFERENCE.md +140 -0
  4. package/dist/index.d.ts +3 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +15 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/mysql/column-mapping.d.ts +27 -0
  9. package/dist/mysql/column-mapping.d.ts.map +1 -0
  10. package/dist/mysql/column-mapping.js +94 -0
  11. package/dist/mysql/column-mapping.js.map +1 -0
  12. package/dist/mysql/delivery-cleanup.d.ts +37 -0
  13. package/dist/mysql/delivery-cleanup.d.ts.map +1 -0
  14. package/dist/mysql/delivery-cleanup.js +108 -0
  15. package/dist/mysql/delivery-cleanup.js.map +1 -0
  16. package/dist/mysql/entity-commit.d.ts +79 -0
  17. package/dist/mysql/entity-commit.d.ts.map +1 -0
  18. package/dist/mysql/entity-commit.js +123 -0
  19. package/dist/mysql/entity-commit.js.map +1 -0
  20. package/dist/mysql/entity-history.d.ts +123 -0
  21. package/dist/mysql/entity-history.d.ts.map +1 -0
  22. package/dist/mysql/entity-history.js +347 -0
  23. package/dist/mysql/entity-history.js.map +1 -0
  24. package/dist/mysql/errors.d.ts +25 -0
  25. package/dist/mysql/errors.d.ts.map +1 -0
  26. package/dist/mysql/errors.js +44 -0
  27. package/dist/mysql/errors.js.map +1 -0
  28. package/dist/mysql/id-column.d.ts +36 -0
  29. package/dist/mysql/id-column.d.ts.map +1 -0
  30. package/dist/mysql/id-column.js +113 -0
  31. package/dist/mysql/id-column.js.map +1 -0
  32. package/dist/mysql/record-storage.d.ts +379 -0
  33. package/dist/mysql/record-storage.d.ts.map +1 -0
  34. package/dist/mysql/record-storage.js +941 -0
  35. package/dist/mysql/record-storage.js.map +1 -0
  36. package/dist/mysql/storage-factory.d.ts +218 -0
  37. package/dist/mysql/storage-factory.d.ts.map +1 -0
  38. package/dist/mysql/storage-factory.js +477 -0
  39. package/dist/mysql/storage-factory.js.map +1 -0
  40. package/dist/mysql/table-resolver.d.ts +34 -0
  41. package/dist/mysql/table-resolver.d.ts.map +1 -0
  42. package/dist/mysql/table-resolver.js +87 -0
  43. package/dist/mysql/table-resolver.js.map +1 -0
  44. package/dist/mysql/table-spec.d.ts +88 -0
  45. package/dist/mysql/table-spec.d.ts.map +1 -0
  46. package/dist/mysql/table-spec.js +105 -0
  47. package/dist/mysql/table-spec.js.map +1 -0
  48. package/dist/mysql/testing.d.ts +47 -0
  49. package/dist/mysql/testing.d.ts.map +1 -0
  50. package/dist/mysql/testing.js +111 -0
  51. package/dist/mysql/testing.js.map +1 -0
  52. package/dist/tsconfig.tsbuildinfo +1 -0
  53. package/package.json +38 -0
@@ -0,0 +1,347 @@
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 { create, fromBinary } from "@bufbuild/protobuf";
15
+ import { EntityStateKeySchema, } from "@spine-event-engine/proto/generated/spine/server/entity/state_key_pb.js";
16
+ import { RecordSpec } from "@spine-event-engine/storage";
17
+ import { eventHistorySpec, stateHistorySpec, } from "@spine-event-engine/storage/provider";
18
+ import { MysqlRecordStorage } from "./record-storage.js";
19
+ /**
20
+ * Provides MySQL-backed Entity current and history storage.
21
+ */
22
+ export class MysqlEntityStorage {
23
+ onClose;
24
+ // prettier-ignore
25
+ /**
26
+ * Exposes current Entity records.
27
+ */
28
+ current;
29
+ #current;
30
+ #states;
31
+ #events;
32
+ /**
33
+ * Exposes Entity state history records.
34
+ */
35
+ states;
36
+ /**
37
+ * Exposes Entity event history records.
38
+ */
39
+ events;
40
+ #open = true;
41
+ /**
42
+ * Creates MySQL-backed Entity storage handles.
43
+ *
44
+ * @param input Configures the Entity storage families.
45
+ * @param open Opens one record-family storage handle.
46
+ * @param onClose Removes this Entity handle from its factory.
47
+ */
48
+ constructor(input, open, onClose = () => undefined) {
49
+ this.onClose = onClose;
50
+ this.#current = new CurrentStorage(input, open(input.recordSpec));
51
+ this.current = this.#current;
52
+ const states = input.stateHistory ? stateHistorySpec(input.stateSchema) : undefined;
53
+ const events = input.eventHistory ? eventHistorySpec(input.stateSchema) : undefined;
54
+ this.#states =
55
+ states === undefined ? undefined : new States(input, open(states.spec, states.group));
56
+ this.#events =
57
+ events === undefined ? undefined : new Events(input, open(events.spec, events.group));
58
+ this.states = this.#states ?? disabledStates();
59
+ this.events = this.#events ?? disabledEvents();
60
+ }
61
+ /**
62
+ * Reads the current Entity record while the coordinator owns its row lock.
63
+ *
64
+ * @param id Identifies the Entity.
65
+ * @returns Resolves to the current record when present.
66
+ */
67
+ readCurrentLocked(id) {
68
+ return this.#current.readLocked(id);
69
+ }
70
+ /**
71
+ * Returns whether this Entity storage handle accepts operations.
72
+ *
73
+ * @returns Returns whether the handle is open.
74
+ */
75
+ isOpen() {
76
+ return this.#open;
77
+ }
78
+ /**
79
+ * Closes the history record-family handles.
80
+ */
81
+ close() {
82
+ if (!this.#open)
83
+ return;
84
+ this.#open = false;
85
+ this.#current.close();
86
+ this.states.close();
87
+ this.events.close();
88
+ this.onClose();
89
+ }
90
+ /**
91
+ * Binds all Entity handles to one connection for work.
92
+ *
93
+ * @param connection Provides the coordinator-owned connection.
94
+ * @param work Performs the bound storage work.
95
+ * @returns Returns the work result.
96
+ */
97
+ async withConnection(connection, work) {
98
+ return this.#current.withConnection(connection, () => this.#states === undefined
99
+ ? this.#events === undefined
100
+ ? work()
101
+ : this.#events.withConnection(connection, work)
102
+ : this.#states.withConnection(connection, () => this.#events === undefined ? work() : this.#events.withConnection(connection, work)));
103
+ }
104
+ /**
105
+ * Returns the physical tables used by the Entity families.
106
+ *
107
+ * @returns Returns the resolved table names.
108
+ */
109
+ tableNames() {
110
+ const result = [this.#current.tableName()];
111
+ if (this.#states !== undefined)
112
+ result.push(this.#states.tableName());
113
+ if (this.#events !== undefined)
114
+ result.push(this.#events.tableName());
115
+ return result;
116
+ }
117
+ /**
118
+ * Prepares every Entity record-family table.
119
+ *
120
+ * @returns Resolves after the tables are ready.
121
+ */
122
+ async prepare() {
123
+ await this.#current.prepare();
124
+ await this.#states?.prepare();
125
+ await this.#events?.prepare();
126
+ }
127
+ /**
128
+ * Checks immutable state and diagnostic records before a nontransactional write.
129
+ *
130
+ * @param states Lists state history records to check.
131
+ * @param diagnostics Lists diagnostic history records to check.
132
+ * @returns Resolves when every record is compatible.
133
+ */
134
+ async preflightImmutable(states, diagnostics) {
135
+ for (const state of states)
136
+ await this.#states?.assertImmutable(state);
137
+ for (const diagnostic of diagnostics)
138
+ await this.#events?.assertImmutable(diagnostic);
139
+ }
140
+ /**
141
+ * Exposes the private MySQL operations required by atomic Entity commit.
142
+ *
143
+ * @internal
144
+ * @returns Returns the private Entity-family commit capability.
145
+ */
146
+ commitCapability() {
147
+ return {
148
+ prepare: () => this.prepare(),
149
+ tableNames: () => this.tableNames(),
150
+ withConnection: (connection, work) => this.withConnection(connection, work),
151
+ readCurrentLocked: (id) => this.#current.readLocked(id),
152
+ preflightImmutable: (states, diagnostics) => this.preflightImmutable(states, diagnostics),
153
+ appendStateImmutable: (record) => this.#states?.appendImmutable(record) ?? Promise.resolve(),
154
+ appendDiagnosticImmutable: (record) => this.#events?.appendImmutable(record) ?? Promise.resolve(),
155
+ };
156
+ }
157
+ }
158
+ class CurrentStorage {
159
+ input;
160
+ records;
161
+ constructor(input, records) {
162
+ this.input = input;
163
+ this.records = records;
164
+ }
165
+ read(id) {
166
+ return this.records.read(id);
167
+ }
168
+ readLocked(id) {
169
+ return this.records.readLocked(id);
170
+ }
171
+ write(record) {
172
+ return this.records.write(record);
173
+ }
174
+ async query(plan) {
175
+ const entries = await this.records.queryPlanEntries(plan);
176
+ return entries.map((entry) => {
177
+ if (entry.record.entityId === undefined)
178
+ throw new Error("EntityRecord requires entityId.");
179
+ const id = this.input.id.unpack(entry.record.entityId);
180
+ if (id === undefined)
181
+ throw new Error("EntityRecord ID does not match storage.");
182
+ return {
183
+ id,
184
+ record: entry.record,
185
+ columns: new Map(this.input.columns.map((column) => [column.name, column.valueIn(entry.record)])),
186
+ };
187
+ });
188
+ }
189
+ withConnection(connection, work) {
190
+ return this.records.withConnection(connection, work);
191
+ }
192
+ tableName() {
193
+ return this.records.tableName;
194
+ }
195
+ prepare() {
196
+ return this.records.prepare();
197
+ }
198
+ close() {
199
+ this.records.close();
200
+ }
201
+ }
202
+ class States {
203
+ input;
204
+ records;
205
+ constructor(input, records) {
206
+ this.input = input;
207
+ this.records = records;
208
+ }
209
+ append(record) {
210
+ return this.records.write(record);
211
+ }
212
+ appendImmutable(record) {
213
+ return this.records.writeImmutable(record);
214
+ }
215
+ async backward(id, depth, startingFromVersion) {
216
+ const all = await this.records.query({ sort: [{ field: "version", direction: "desc" }] });
217
+ return all
218
+ .filter((record) => record.entityId !== undefined &&
219
+ sameEntityId(this.input, record.entityId, id) &&
220
+ (startingFromVersion === undefined ||
221
+ BigInt(record.version?.number ?? 0) <= startingFromVersion))
222
+ .slice(0, depth);
223
+ }
224
+ async stateAt(id, time) {
225
+ const records = await this.backward(id, Number.MAX_SAFE_INTEGER);
226
+ const found = records.find((record) => {
227
+ const timestamp = record.version?.timestamp;
228
+ return (timestamp !== undefined &&
229
+ (timestamp.seconds < time.seconds ||
230
+ (timestamp.seconds === time.seconds && timestamp.nanos <= time.nanos)));
231
+ });
232
+ return found?.state === undefined
233
+ ? undefined
234
+ : fromBinary(this.input.stateSchema, found.state.value);
235
+ }
236
+ async trim(id, keep) {
237
+ const records = await this.backward(id, Number.MAX_SAFE_INTEGER);
238
+ for (const record of records.slice(keep)) {
239
+ if (record.entityId !== undefined)
240
+ await this.records.delete(create(EntityStateKeySchema, {
241
+ entityId: record.entityId,
242
+ version: record.version?.number ?? 0,
243
+ }));
244
+ }
245
+ }
246
+ async truncate(olderThan) {
247
+ const all = await this.records.query();
248
+ for (const record of all) {
249
+ const timestamp = record.version?.timestamp;
250
+ if (timestamp !== undefined &&
251
+ (timestamp.seconds < olderThan.seconds ||
252
+ (timestamp.seconds === olderThan.seconds && timestamp.nanos < olderThan.nanos)) &&
253
+ record.entityId !== undefined)
254
+ await this.records.delete(create(EntityStateKeySchema, {
255
+ entityId: record.entityId,
256
+ version: record.version?.number ?? 0,
257
+ }));
258
+ }
259
+ }
260
+ close() {
261
+ this.records.close();
262
+ }
263
+ withConnection(connection, work) {
264
+ return this.records.withConnection(connection, work);
265
+ }
266
+ tableName() {
267
+ return this.records.tableName;
268
+ }
269
+ assertImmutable(record) {
270
+ return this.records.assertImmutable(record);
271
+ }
272
+ prepare() {
273
+ return this.records.prepare();
274
+ }
275
+ }
276
+ class Events {
277
+ input;
278
+ records;
279
+ constructor(input, records) {
280
+ this.input = input;
281
+ this.records = records;
282
+ }
283
+ append(record) {
284
+ return this.records.write(record);
285
+ }
286
+ appendImmutable(record) {
287
+ return this.records.writeImmutable(record);
288
+ }
289
+ async backward(id, depth, startingFromVersion) {
290
+ const all = await this.records.query({ sort: [{ field: "version", direction: "desc" }] });
291
+ return all
292
+ .filter((event) => event.context?.producerId !== undefined &&
293
+ sameEntityId(this.input, event.context.producerId, id) &&
294
+ (startingFromVersion === undefined ||
295
+ BigInt(event.context.version?.number ?? 0) <= startingFromVersion))
296
+ .slice(0, depth);
297
+ }
298
+ async truncate(olderThan) {
299
+ const all = await this.records.query();
300
+ for (const event of all) {
301
+ const timestamp = event.context?.timestamp;
302
+ if (event.id !== undefined &&
303
+ timestamp !== undefined &&
304
+ (timestamp.seconds < olderThan.seconds ||
305
+ (timestamp.seconds === olderThan.seconds && timestamp.nanos < olderThan.nanos)))
306
+ await this.records.delete(event.id);
307
+ }
308
+ }
309
+ close() {
310
+ this.records.close();
311
+ }
312
+ withConnection(connection, work) {
313
+ return this.records.withConnection(connection, work);
314
+ }
315
+ tableName() {
316
+ return this.records.tableName;
317
+ }
318
+ assertImmutable(record) {
319
+ return this.records.assertImmutable(record);
320
+ }
321
+ prepare() {
322
+ return this.records.prepare();
323
+ }
324
+ }
325
+ function disabledStates() {
326
+ return {
327
+ append: () => Promise.reject(new Error("Entity state history is disabled.")),
328
+ backward: () => Promise.resolve([]),
329
+ stateAt: () => Promise.resolve(undefined),
330
+ trim: () => Promise.resolve(),
331
+ truncate: () => Promise.resolve(),
332
+ close: () => undefined,
333
+ };
334
+ }
335
+ function disabledEvents() {
336
+ return {
337
+ append: () => Promise.reject(new Error("Entity event history is disabled.")),
338
+ backward: () => Promise.resolve([]),
339
+ truncate: () => Promise.resolve(),
340
+ close: () => undefined,
341
+ };
342
+ }
343
+ function sameEntityId(input, packed, expected) {
344
+ const decoded = input.id.unpack(packed);
345
+ return decoded !== undefined && input.id.key(decoded) === input.id.key(expected);
346
+ }
347
+ //# sourceMappingURL=entity-history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-history.js","sourceRoot":"","sources":["../../src/mysql/entity-history.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAgB,MAAM,oBAAoB,CAAC;AAItE,OAAO,EACL,oBAAoB,GAErB,MAAM,yEAAyE,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,GAKjB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAiDzD;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAmCV;IAlCnB,kB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,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;QACzC,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE;QAC7B,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE;QACjC,KAAK,EAAE,GAAG,EAAE,CAAC,SAAS;KACvB,CAAC;AACJ,CAAC;AACD,SAAS,cAAc;IACrB,OAAO;QACL,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QAC5E,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACnC,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE;QACjC,KAAK,EAAE,GAAG,EAAE,CAAC,SAAS;KACvB,CAAC;AACJ,CAAC;AACD,SAAS,YAAY,CACnB,KAA+B,EAC/B,MAA6C,EAC7C,QAAW;IAEX,MAAM,OAAO,GAAG,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACxC,OAAO,OAAO,KAAK,SAAS,IAAI,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACnF,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Reports an incompatible MySQL record-family schema without database details.
3
+ */
4
+ export declare class MysqlStorageSchemaError extends Error {
5
+ }
6
+ /**
7
+ * Reports stored record data that cannot be decoded without database details.
8
+ */
9
+ export declare class MysqlStorageDataError extends Error {
10
+ }
11
+ /**
12
+ * Reports a MySQL storage operation failure without database details.
13
+ */
14
+ export declare class MysqlStorageOperationError extends Error {
15
+ }
16
+ /**
17
+ * Converts an unknown failure to one public provider error without exposing driver details.
18
+ *
19
+ * @param type Constructs the public error type.
20
+ * @param message Describes the failed provider operation.
21
+ * @param error Supplies the unknown underlying failure.
22
+ * @returns The existing public provider error or a newly constructed public error.
23
+ */
24
+ export declare function mysqlError<E extends Error>(type: new (message: string) => E, message: string, error: unknown): E;
25
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/mysql/errors.ts"],"names":[],"mappings":"AAcA;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;CAAG;AAErD;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;CAAG;AAEnD;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;CAAG;AAExD;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,KAAK,EACxC,IAAI,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC,EAChC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,OAAO,GACb,CAAC,CAMH"}
@@ -0,0 +1,44 @@
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
+ /**
15
+ * Reports an incompatible MySQL record-family schema without database details.
16
+ */
17
+ export class MysqlStorageSchemaError extends Error {
18
+ }
19
+ /**
20
+ * Reports stored record data that cannot be decoded without database details.
21
+ */
22
+ export class MysqlStorageDataError extends Error {
23
+ }
24
+ /**
25
+ * Reports a MySQL storage operation failure without database details.
26
+ */
27
+ export class MysqlStorageOperationError extends Error {
28
+ }
29
+ /**
30
+ * Converts an unknown failure to one public provider error without exposing driver details.
31
+ *
32
+ * @param type Constructs the public error type.
33
+ * @param message Describes the failed provider operation.
34
+ * @param error Supplies the unknown underlying failure.
35
+ * @returns The existing public provider error or a newly constructed public error.
36
+ */
37
+ export function mysqlError(type, message, error) {
38
+ return error instanceof MysqlStorageSchemaError ||
39
+ error instanceof MysqlStorageDataError ||
40
+ error instanceof MysqlStorageOperationError
41
+ ? error
42
+ : new type(message);
43
+ }
44
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/mysql/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;CAAG;AAErD;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;CAAG;AAEnD;;GAEG;AACH,MAAM,OAAO,0BAA2B,SAAQ,KAAK;CAAG;AAExD;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CACxB,IAAgC,EAChC,OAAe,EACf,KAAc;IAEd,OAAO,KAAK,YAAY,uBAAuB;QAC7C,KAAK,YAAY,qBAAqB;QACtC,KAAK,YAAY,0BAA0B;QAC3C,CAAC,CAAE,KAAW;QACd,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;AACxB,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type { Message } from "@bufbuild/protobuf";
2
+ import type { GenMessage } from "@bufbuild/protobuf/codegenv2";
3
+ import { StringifierRegistry } from "@spine-event-engine/core";
4
+ type MysqlIdType<I> = I extends Message ? GenMessage<I> : string;
5
+ /**
6
+ * Converts one declared record ID to and from Spine JVM JDBC values.
7
+ */
8
+ export declare class MysqlIdColumn<I> {
9
+ #private;
10
+ private readonly type;
11
+ /**
12
+ * The canonical MySQL ID column type.
13
+ */
14
+ readonly mysqlType: string;
15
+ /**
16
+ * Creates an ID conversion from the declared record ID type.
17
+ *
18
+ * @param type The message schema or supported primitive kind.
19
+ * @param stringifiers The schema-bound message stringifiers.
20
+ */
21
+ constructor(type: MysqlIdType<I>, stringifiers?: StringifierRegistry);
22
+ /**
23
+ * Converts a logical ID to a MySQL parameter.
24
+ * @param id The logical record ID.
25
+ * @returns The JVM-compatible MySQL value.
26
+ */
27
+ value(id: I): unknown;
28
+ /**
29
+ * Converts a MySQL value back to the logical ID.
30
+ * @param value The selected MySQL value.
31
+ * @returns The logical record ID.
32
+ */
33
+ read(value: unknown): I;
34
+ }
35
+ export {};
36
+ //# sourceMappingURL=id-column.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-column.d.ts","sourceRoot":"","sources":["../../src/mysql/id-column.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,KAAK,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;AAEjE;;GAEG;AACH,qBAAa,aAAa,CAAC,CAAC;;IAgBxB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAZvB;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B;;;;;OAKG;gBAEgB,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EACrC,YAAY,GAAE,mBAA+C;IAM/D;;;;OAIG;IACH,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO;IAOrB;;;;OAIG;IACH,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC;CAuBxB"}
@@ -0,0 +1,113 @@
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 { StringifierRegistry } from "@spine-event-engine/core";
15
+ /**
16
+ * Converts one declared record ID to and from Spine JVM JDBC values.
17
+ */
18
+ export class MysqlIdColumn {
19
+ type;
20
+ #stringifiers;
21
+ // prettier-ignore
22
+ /**
23
+ * The canonical MySQL ID column type.
24
+ */
25
+ mysqlType;
26
+ /**
27
+ * Creates an ID conversion from the declared record ID type.
28
+ *
29
+ * @param type The message schema or supported primitive kind.
30
+ * @param stringifiers The schema-bound message stringifiers.
31
+ */
32
+ constructor(type, stringifiers = new StringifierRegistry()) {
33
+ this.type = type;
34
+ this.#stringifiers = new StringifierRegistry(stringifiers);
35
+ this.mysqlType = MysqlIdTypes.mysqlType(type);
36
+ }
37
+ /**
38
+ * Converts a logical ID to a MySQL parameter.
39
+ * @param id The logical record ID.
40
+ * @returns The JVM-compatible MySQL value.
41
+ */
42
+ value(id) {
43
+ if (typeof this.type !== "string")
44
+ return MysqlIdTypes.text(this.#stringifiers.forMessage(this.type).toString(id));
45
+ MysqlIdTypes.validate(this.type, id);
46
+ return this.type === "string" ? MysqlIdTypes.text(id) : id;
47
+ }
48
+ /**
49
+ * Converts a MySQL value back to the logical ID.
50
+ * @param value The selected MySQL value.
51
+ * @returns The logical record ID.
52
+ */
53
+ read(value) {
54
+ if (typeof this.type !== "string") {
55
+ if (typeof value !== "string")
56
+ throw new Error("MySQL message ID is not text.");
57
+ return this.#stringifiers.forMessage(this.type).fromString(value);
58
+ }
59
+ switch (this.type) {
60
+ case "string":
61
+ if (typeof value !== "string")
62
+ throw new Error("MySQL string ID is invalid.");
63
+ return value;
64
+ case "int32": {
65
+ const number = typeof value === "number" ? value : Number(value);
66
+ MysqlIdTypes.validate("int32", number);
67
+ return number;
68
+ }
69
+ case "int64": {
70
+ const integer = typeof value === "bigint" ? value : BigInt(value);
71
+ MysqlIdTypes.validate("int64", integer);
72
+ return integer;
73
+ }
74
+ default:
75
+ throw new Error(`MySQL storage does not support primitive ID kind "${this.type}".`);
76
+ }
77
+ }
78
+ }
79
+ const MysqlIdTypes = Object.freeze({
80
+ text(value) {
81
+ if (value.length > 512)
82
+ throw new Error("MySQL storage identifier is too large.");
83
+ return value;
84
+ },
85
+ mysqlType(type) {
86
+ if (typeof type !== "string")
87
+ return "VARCHAR(512)";
88
+ switch (type) {
89
+ case "string":
90
+ return "VARCHAR(512)";
91
+ case "int32":
92
+ return "INT";
93
+ case "int64":
94
+ return "BIGINT";
95
+ default:
96
+ throw new Error(`MySQL storage does not support primitive ID kind "${type}".`);
97
+ }
98
+ },
99
+ validate(type, value) {
100
+ if (type === "string" && typeof value === "string")
101
+ return;
102
+ if (type === "int32" &&
103
+ typeof value === "number" &&
104
+ Number.isInteger(value) &&
105
+ value >= -(2 ** 31) &&
106
+ value < 2 ** 31)
107
+ return;
108
+ if (type === "int64" && typeof value === "bigint" && value >= -(1n << 63n) && value < 1n << 63n)
109
+ return;
110
+ throw new Error(`MySQL ${type} ID is invalid.`);
111
+ },
112
+ });
113
+ //# sourceMappingURL=id-column.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-column.js","sourceRoot":"","sources":["../../src/mysql/id-column.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAI/D;;GAEG;AACH,MAAM,OAAO,aAAa;IAgBL;IAfV,aAAa,CAAsB;IAC5C,kBAAkB;IAElB;;OAEG;IACM,SAAS,CAAS;IAE3B;;;;;OAKG;IACH,YACmB,IAAoB,EACrC,eAAoC,IAAI,mBAAmB,EAAE;QAD5C,SAAI,GAAJ,IAAI,CAAgB;QAGrC,IAAI,CAAC,aAAa,GAAG,IAAI,mBAAmB,CA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