@event-driven-io/emmett-sqlite 0.42.0-beta.1 → 0.42.0-beta.2
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/dist/index.cjs +236 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -3
- package/dist/index.d.ts +15 -3
- package/dist/index.js +222 -34
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -36,6 +36,19 @@ var sqliteConnection = (options) => {
|
|
|
36
36
|
}
|
|
37
37
|
);
|
|
38
38
|
}),
|
|
39
|
+
batchCommand: async (sqls) => {
|
|
40
|
+
for (const sql2 of sqls) {
|
|
41
|
+
await new Promise((resolve, reject) => {
|
|
42
|
+
db.run(sql2, [], (err) => {
|
|
43
|
+
if (err) {
|
|
44
|
+
reject(err);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
resolve();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
},
|
|
39
52
|
query: (sql2, params) => new Promise((resolve, reject) => {
|
|
40
53
|
db.all(sql2, _nullishCoalesce(params, () => ( [])), (err, result) => {
|
|
41
54
|
if (err) {
|
|
@@ -413,6 +426,10 @@ var deepEquals = (left, right) => {
|
|
|
413
426
|
var isEquatable = (left) => {
|
|
414
427
|
return left !== null && left !== void 0 && typeof left === "object" && "equals" in left && typeof left["equals"] === "function";
|
|
415
428
|
};
|
|
429
|
+
var toNormalizedString = (value) => value.toString().padStart(19, "0");
|
|
430
|
+
var bigInt = {
|
|
431
|
+
toNormalizedString
|
|
432
|
+
};
|
|
416
433
|
var ParseError = class extends Error {
|
|
417
434
|
constructor(text) {
|
|
418
435
|
super(`Cannot parse! ${text}`);
|
|
@@ -604,6 +621,42 @@ var sqliteRawSQLProjection = (options) => {
|
|
|
604
621
|
// src/eventStore/projections/sqliteProjectionSpec.ts
|
|
605
622
|
|
|
606
623
|
|
|
624
|
+
// src/eventStore/schema/migrations/0_41_0/0_41_0.snapshot.ts
|
|
625
|
+
var schema_0_41_0 = [
|
|
626
|
+
`CREATE TABLE IF NOT EXISTS emt_streams(
|
|
627
|
+
stream_id TEXT NOT NULL,
|
|
628
|
+
stream_position BIGINT NOT NULL DEFAULT 0,
|
|
629
|
+
partition TEXT NOT NULL DEFAULT 'global',
|
|
630
|
+
stream_type TEXT NOT NULL,
|
|
631
|
+
stream_metadata JSONB NOT NULL,
|
|
632
|
+
is_archived BOOLEAN NOT NULL DEFAULT FALSE,
|
|
633
|
+
PRIMARY KEY (stream_id, partition, is_archived),
|
|
634
|
+
UNIQUE (stream_id, partition, is_archived)
|
|
635
|
+
)`,
|
|
636
|
+
`CREATE TABLE IF NOT EXISTS emt_messages(
|
|
637
|
+
stream_id TEXT NOT NULL,
|
|
638
|
+
stream_position BIGINT NOT NULL,
|
|
639
|
+
partition TEXT NOT NULL DEFAULT 'global',
|
|
640
|
+
message_kind CHAR(1) NOT NULL DEFAULT 'E',
|
|
641
|
+
message_data JSONB NOT NULL,
|
|
642
|
+
message_metadata JSONB NOT NULL,
|
|
643
|
+
message_schema_version TEXT NOT NULL,
|
|
644
|
+
message_type TEXT NOT NULL,
|
|
645
|
+
message_id TEXT NOT NULL,
|
|
646
|
+
is_archived BOOLEAN NOT NULL DEFAULT FALSE,
|
|
647
|
+
global_position INTEGER PRIMARY KEY,
|
|
648
|
+
created DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
649
|
+
UNIQUE (stream_id, stream_position, partition, is_archived)
|
|
650
|
+
)`,
|
|
651
|
+
`CREATE TABLE IF NOT EXISTS emt_subscriptions(
|
|
652
|
+
subscription_id TEXT NOT NULL,
|
|
653
|
+
version INTEGER NOT NULL DEFAULT 1,
|
|
654
|
+
partition TEXT NOT NULL DEFAULT 'global',
|
|
655
|
+
last_processed_position BIGINT NOT NULL,
|
|
656
|
+
PRIMARY KEY (subscription_id, partition, version)
|
|
657
|
+
)`
|
|
658
|
+
];
|
|
659
|
+
|
|
607
660
|
// src/eventStore/schema/typing.ts
|
|
608
661
|
var emmettPrefix = "emt";
|
|
609
662
|
var globalTag = "global";
|
|
@@ -631,10 +684,106 @@ var messagesTable = {
|
|
|
631
684
|
isArchived: columns.isArchived
|
|
632
685
|
}
|
|
633
686
|
};
|
|
634
|
-
var
|
|
635
|
-
name: `${emmettPrefix}
|
|
687
|
+
var processorsTable = {
|
|
688
|
+
name: `${emmettPrefix}_processors`
|
|
689
|
+
};
|
|
690
|
+
var projectionsTable = {
|
|
691
|
+
name: `${emmettPrefix}_projections`
|
|
692
|
+
};
|
|
693
|
+
|
|
694
|
+
// src/eventStore/schema/migrations/0_42_0/0_42_0.migration.ts
|
|
695
|
+
var migration_0_42_0_SQLs = [
|
|
696
|
+
`CREATE TABLE IF NOT EXISTS ${processorsTable.name}(
|
|
697
|
+
processor_id TEXT NOT NULL,
|
|
698
|
+
version INTEGER NOT NULL DEFAULT 1,
|
|
699
|
+
partition TEXT NOT NULL DEFAULT '${globalTag}',
|
|
700
|
+
status TEXT NOT NULL DEFAULT 'stopped',
|
|
701
|
+
last_processed_checkpoint TEXT NOT NULL,
|
|
702
|
+
processor_instance_id TEXT DEFAULT 'emt:unknown',
|
|
703
|
+
PRIMARY KEY (processor_id, partition, version)
|
|
704
|
+
)`,
|
|
705
|
+
`CREATE TABLE IF NOT EXISTS ${projectionsTable.name}(
|
|
706
|
+
name TEXT NOT NULL,
|
|
707
|
+
version INTEGER NOT NULL DEFAULT 1,
|
|
708
|
+
partition TEXT NOT NULL DEFAULT '${globalTag}',
|
|
709
|
+
type CHAR(1) NOT NULL,
|
|
710
|
+
kind TEXT NOT NULL,
|
|
711
|
+
status TEXT NOT NULL,
|
|
712
|
+
definition JSONB NOT NULL DEFAULT '{}',
|
|
713
|
+
PRIMARY KEY (name, partition, version)
|
|
714
|
+
)`,
|
|
715
|
+
`INSERT INTO ${processorsTable.name}
|
|
716
|
+
(processor_id, version, partition, status, last_processed_checkpoint, processor_instance_id)
|
|
717
|
+
SELECT
|
|
718
|
+
subscription_id,
|
|
719
|
+
version,
|
|
720
|
+
partition,
|
|
721
|
+
'stopped',
|
|
722
|
+
printf('%019d', last_processed_position),
|
|
723
|
+
'emt:unknown'
|
|
724
|
+
FROM emt_subscriptions`,
|
|
725
|
+
`DROP TABLE emt_subscriptions`
|
|
726
|
+
];
|
|
727
|
+
var migration_0_42_0_FromSubscriptionsToProcessors = async (connection) => {
|
|
728
|
+
await connection.withTransaction(async () => {
|
|
729
|
+
const tableExists = await connection.querySingle(
|
|
730
|
+
"SELECT name FROM sqlite_master WHERE type='table' AND name='emt_subscriptions'"
|
|
731
|
+
);
|
|
732
|
+
if (!tableExists) {
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
await connection.batchCommand(migration_0_42_0_SQLs);
|
|
736
|
+
});
|
|
636
737
|
};
|
|
637
738
|
|
|
739
|
+
// src/eventStore/schema/migrations/0_42_0/0_42_0.snapshot.ts
|
|
740
|
+
var schema_0_42_0 = [
|
|
741
|
+
`CREATE TABLE IF NOT EXISTS emt_streams(
|
|
742
|
+
stream_id TEXT NOT NULL,
|
|
743
|
+
stream_position BIGINT NOT NULL DEFAULT 0,
|
|
744
|
+
partition TEXT NOT NULL DEFAULT 'global',
|
|
745
|
+
stream_type TEXT NOT NULL,
|
|
746
|
+
stream_metadata JSONB NOT NULL,
|
|
747
|
+
is_archived BOOLEAN NOT NULL DEFAULT FALSE,
|
|
748
|
+
PRIMARY KEY (stream_id, partition, is_archived),
|
|
749
|
+
UNIQUE (stream_id, partition, is_archived)
|
|
750
|
+
)`,
|
|
751
|
+
`CREATE TABLE IF NOT EXISTS emt_messages(
|
|
752
|
+
stream_id TEXT NOT NULL,
|
|
753
|
+
stream_position BIGINT NOT NULL,
|
|
754
|
+
partition TEXT NOT NULL DEFAULT 'global',
|
|
755
|
+
message_kind CHAR(1) NOT NULL DEFAULT 'E',
|
|
756
|
+
message_data JSONB NOT NULL,
|
|
757
|
+
message_metadata JSONB NOT NULL,
|
|
758
|
+
message_schema_version TEXT NOT NULL,
|
|
759
|
+
message_type TEXT NOT NULL,
|
|
760
|
+
message_id TEXT NOT NULL,
|
|
761
|
+
is_archived BOOLEAN NOT NULL DEFAULT FALSE,
|
|
762
|
+
global_position INTEGER PRIMARY KEY,
|
|
763
|
+
created DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
764
|
+
UNIQUE (stream_id, stream_position, partition, is_archived)
|
|
765
|
+
)`,
|
|
766
|
+
`CREATE TABLE IF NOT EXISTS emt_processors(
|
|
767
|
+
processor_id TEXT NOT NULL,
|
|
768
|
+
version INTEGER NOT NULL DEFAULT 1,
|
|
769
|
+
partition TEXT NOT NULL DEFAULT 'global',
|
|
770
|
+
status TEXT NOT NULL DEFAULT 'stopped',
|
|
771
|
+
last_processed_checkpoint TEXT NOT NULL,
|
|
772
|
+
processor_instance_id TEXT DEFAULT 'emt:unknown',
|
|
773
|
+
PRIMARY KEY (processor_id, partition, version)
|
|
774
|
+
)`,
|
|
775
|
+
`CREATE TABLE IF NOT EXISTS emt_projections(
|
|
776
|
+
name TEXT NOT NULL,
|
|
777
|
+
version INTEGER NOT NULL DEFAULT 1,
|
|
778
|
+
partition TEXT NOT NULL DEFAULT 'global',
|
|
779
|
+
type CHAR(1) NOT NULL,
|
|
780
|
+
kind TEXT NOT NULL,
|
|
781
|
+
status TEXT NOT NULL,
|
|
782
|
+
definition JSONB NOT NULL DEFAULT '{}',
|
|
783
|
+
PRIMARY KEY (name, partition, version)
|
|
784
|
+
)`
|
|
785
|
+
];
|
|
786
|
+
|
|
638
787
|
// src/eventStore/schema/tables.ts
|
|
639
788
|
var sql = (sql2) => sql2;
|
|
640
789
|
var streamsTableSQL = sql(
|
|
@@ -667,30 +816,46 @@ var messagesTableSQL = sql(
|
|
|
667
816
|
);
|
|
668
817
|
`
|
|
669
818
|
);
|
|
670
|
-
var
|
|
819
|
+
var processorsTableSQL = sql(
|
|
820
|
+
`
|
|
821
|
+
CREATE TABLE IF NOT EXISTS ${processorsTable.name}(
|
|
822
|
+
processor_id TEXT NOT NULL,
|
|
823
|
+
version INTEGER NOT NULL DEFAULT 1,
|
|
824
|
+
partition TEXT NOT NULL DEFAULT '${globalTag}',
|
|
825
|
+
status TEXT NOT NULL DEFAULT 'stopped',
|
|
826
|
+
last_processed_checkpoint TEXT NOT NULL,
|
|
827
|
+
processor_instance_id TEXT DEFAULT 'emt:unknown',
|
|
828
|
+
PRIMARY KEY (processor_id, partition, version)
|
|
829
|
+
);
|
|
830
|
+
`
|
|
831
|
+
);
|
|
832
|
+
var projectionsTableSQL = sql(
|
|
671
833
|
`
|
|
672
|
-
CREATE TABLE IF NOT EXISTS ${
|
|
673
|
-
|
|
674
|
-
version
|
|
675
|
-
partition
|
|
676
|
-
|
|
677
|
-
|
|
834
|
+
CREATE TABLE IF NOT EXISTS ${projectionsTable.name}(
|
|
835
|
+
name TEXT NOT NULL,
|
|
836
|
+
version INTEGER NOT NULL DEFAULT 1,
|
|
837
|
+
partition TEXT NOT NULL DEFAULT '${globalTag}',
|
|
838
|
+
type CHAR(1) NOT NULL,
|
|
839
|
+
kind TEXT NOT NULL,
|
|
840
|
+
status TEXT NOT NULL,
|
|
841
|
+
definition JSONB NOT NULL DEFAULT '{}',
|
|
842
|
+
PRIMARY KEY (name, partition, version)
|
|
678
843
|
);
|
|
679
844
|
`
|
|
680
845
|
);
|
|
681
846
|
var schemaSQL = [
|
|
682
847
|
streamsTableSQL,
|
|
683
848
|
messagesTableSQL,
|
|
684
|
-
|
|
849
|
+
processorsTableSQL,
|
|
850
|
+
projectionsTableSQL
|
|
685
851
|
];
|
|
686
852
|
var createEventStoreSchema = async (connection, hooks) => {
|
|
687
853
|
await connection.withTransaction(async () => {
|
|
854
|
+
await migration_0_42_0_FromSubscriptionsToProcessors(connection);
|
|
688
855
|
if (_optionalChain([hooks, 'optionalAccess', _20 => _20.onBeforeSchemaCreated])) {
|
|
689
856
|
await hooks.onBeforeSchemaCreated({ connection });
|
|
690
857
|
}
|
|
691
|
-
|
|
692
|
-
await connection.command(sql2);
|
|
693
|
-
}
|
|
858
|
+
await connection.batchCommand(schemaSQL);
|
|
694
859
|
});
|
|
695
860
|
if (_optionalChain([hooks, 'optionalAccess', _21 => _21.onAfterSchemaCreated])) {
|
|
696
861
|
await hooks.onAfterSchemaCreated();
|
|
@@ -1033,16 +1198,16 @@ var readProcessorCheckpoint = async (db, options) => {
|
|
|
1033
1198
|
const result = await singleOrNull(
|
|
1034
1199
|
db.query(
|
|
1035
1200
|
sql(
|
|
1036
|
-
`SELECT
|
|
1037
|
-
FROM ${
|
|
1038
|
-
WHERE partition = ? AND
|
|
1201
|
+
`SELECT last_processed_checkpoint
|
|
1202
|
+
FROM ${processorsTable.name}
|
|
1203
|
+
WHERE partition = ? AND processor_id = ?
|
|
1039
1204
|
LIMIT 1`
|
|
1040
1205
|
),
|
|
1041
1206
|
[_nullishCoalesce(_optionalChain([options, 'optionalAccess', _40 => _40.partition]), () => ( defaultTag)), options.processorId]
|
|
1042
1207
|
)
|
|
1043
1208
|
);
|
|
1044
1209
|
return {
|
|
1045
|
-
lastProcessedPosition: result !== null ? BigInt(result.
|
|
1210
|
+
lastProcessedPosition: result !== null ? BigInt(result.last_processed_checkpoint) : null
|
|
1046
1211
|
};
|
|
1047
1212
|
};
|
|
1048
1213
|
|
|
@@ -1091,17 +1256,26 @@ var readStream = async (db, streamId, options) => {
|
|
|
1091
1256
|
};
|
|
1092
1257
|
|
|
1093
1258
|
// src/eventStore/schema/storeProcessorCheckpoint.ts
|
|
1094
|
-
async function storeSubscriptionCheckpointSQLite(db, processorId, version, position, checkPosition, partition) {
|
|
1259
|
+
async function storeSubscriptionCheckpointSQLite(db, processorId, version, position, checkPosition, partition, processorInstanceId) {
|
|
1260
|
+
processorInstanceId ??= "emt:unknown";
|
|
1095
1261
|
if (checkPosition !== null) {
|
|
1096
1262
|
const updateResult = await db.command(
|
|
1097
1263
|
sql(`
|
|
1098
|
-
UPDATE ${
|
|
1099
|
-
SET
|
|
1100
|
-
|
|
1101
|
-
|
|
1264
|
+
UPDATE ${processorsTable.name}
|
|
1265
|
+
SET
|
|
1266
|
+
last_processed_checkpoint = ?,
|
|
1267
|
+
processor_instance_id = ?
|
|
1268
|
+
WHERE processor_id = ?
|
|
1269
|
+
AND last_processed_checkpoint = ?
|
|
1102
1270
|
AND partition = ?
|
|
1103
1271
|
`),
|
|
1104
|
-
[
|
|
1272
|
+
[
|
|
1273
|
+
bigInt.toNormalizedString(position),
|
|
1274
|
+
processorInstanceId,
|
|
1275
|
+
processorId,
|
|
1276
|
+
bigInt.toNormalizedString(checkPosition),
|
|
1277
|
+
partition
|
|
1278
|
+
]
|
|
1105
1279
|
);
|
|
1106
1280
|
if (updateResult.changes > 0) {
|
|
1107
1281
|
return 1;
|
|
@@ -1109,15 +1283,16 @@ async function storeSubscriptionCheckpointSQLite(db, processorId, version, posit
|
|
|
1109
1283
|
const current_position = await singleOrNull(
|
|
1110
1284
|
db.query(
|
|
1111
1285
|
sql(
|
|
1112
|
-
`SELECT
|
|
1113
|
-
WHERE
|
|
1286
|
+
`SELECT last_processed_checkpoint FROM ${processorsTable.name}
|
|
1287
|
+
WHERE processor_id = ? AND partition = ?`
|
|
1114
1288
|
),
|
|
1115
1289
|
[processorId, partition]
|
|
1116
1290
|
)
|
|
1117
1291
|
);
|
|
1118
|
-
|
|
1292
|
+
const currentPosition = current_position && _optionalChain([current_position, 'optionalAccess', _42 => _42.last_processed_checkpoint]) !== null ? BigInt(current_position.last_processed_checkpoint) : null;
|
|
1293
|
+
if (currentPosition === position) {
|
|
1119
1294
|
return 0;
|
|
1120
|
-
} else if (position !== null &&
|
|
1295
|
+
} else if (position !== null && currentPosition !== null && currentPosition > position) {
|
|
1121
1296
|
return 2;
|
|
1122
1297
|
} else {
|
|
1123
1298
|
return 2;
|
|
@@ -1127,9 +1302,15 @@ async function storeSubscriptionCheckpointSQLite(db, processorId, version, posit
|
|
|
1127
1302
|
try {
|
|
1128
1303
|
await db.command(
|
|
1129
1304
|
sql(
|
|
1130
|
-
`INSERT INTO ${
|
|
1305
|
+
`INSERT INTO ${processorsTable.name} (processor_id, version, last_processed_checkpoint, partition, processor_instance_id) VALUES (?, ?, ?, ?, ?)`
|
|
1131
1306
|
),
|
|
1132
|
-
[
|
|
1307
|
+
[
|
|
1308
|
+
processorId,
|
|
1309
|
+
version,
|
|
1310
|
+
bigInt.toNormalizedString(position),
|
|
1311
|
+
partition,
|
|
1312
|
+
processorInstanceId
|
|
1313
|
+
]
|
|
1133
1314
|
);
|
|
1134
1315
|
return 1;
|
|
1135
1316
|
} catch (err) {
|
|
@@ -1139,12 +1320,13 @@ async function storeSubscriptionCheckpointSQLite(db, processorId, version, posit
|
|
|
1139
1320
|
const current = await singleOrNull(
|
|
1140
1321
|
db.query(
|
|
1141
1322
|
sql(
|
|
1142
|
-
`SELECT
|
|
1323
|
+
`SELECT last_processed_checkpoint FROM ${processorsTable.name} WHERE processor_id = ? AND partition = ?`
|
|
1143
1324
|
),
|
|
1144
1325
|
[processorId, partition]
|
|
1145
1326
|
)
|
|
1146
1327
|
);
|
|
1147
|
-
|
|
1328
|
+
const currentPosition = current && _optionalChain([current, 'optionalAccess', _43 => _43.last_processed_checkpoint]) !== null ? BigInt(current.last_processed_checkpoint) : null;
|
|
1329
|
+
if (currentPosition === position) {
|
|
1148
1330
|
return 0;
|
|
1149
1331
|
} else {
|
|
1150
1332
|
return 2;
|
|
@@ -1174,12 +1356,12 @@ var genericSQLiteProcessor = (options) => {
|
|
|
1174
1356
|
const { eachMessage } = options;
|
|
1175
1357
|
let isActive = true;
|
|
1176
1358
|
const getDb = (context) => {
|
|
1177
|
-
const fileName = _nullishCoalesce(context.fileName, () => ( _optionalChain([options, 'access',
|
|
1359
|
+
const fileName = _nullishCoalesce(context.fileName, () => ( _optionalChain([options, 'access', _44 => _44.connectionOptions, 'optionalAccess', _45 => _45.fileName])));
|
|
1178
1360
|
if (!fileName)
|
|
1179
1361
|
throw new EmmettError(
|
|
1180
1362
|
`SQLite processor '${options.processorId}' is missing file name. Ensure that you passed it through options`
|
|
1181
1363
|
);
|
|
1182
|
-
const connection = _nullishCoalesce(_nullishCoalesce(context.connection, () => ( _optionalChain([options, 'access',
|
|
1364
|
+
const connection = _nullishCoalesce(_nullishCoalesce(context.connection, () => ( _optionalChain([options, 'access', _46 => _46.connectionOptions, 'optionalAccess', _47 => _47.connection]))), () => ( sqliteConnection({ fileName })));
|
|
1183
1365
|
return { connection, fileName };
|
|
1184
1366
|
};
|
|
1185
1367
|
return {
|
|
@@ -1281,7 +1463,7 @@ var sqliteEventStoreConsumer = (options) => {
|
|
|
1281
1463
|
})
|
|
1282
1464
|
);
|
|
1283
1465
|
return result.some(
|
|
1284
|
-
(r) => r.status === "fulfilled" && _optionalChain([r, 'access',
|
|
1466
|
+
(r) => r.status === "fulfilled" && _optionalChain([r, 'access', _48 => _48.value, 'optionalAccess', _49 => _49.type]) !== "STOP"
|
|
1285
1467
|
) ? void 0 : {
|
|
1286
1468
|
type: "STOP"
|
|
1287
1469
|
};
|
|
@@ -1289,8 +1471,8 @@ var sqliteEventStoreConsumer = (options) => {
|
|
|
1289
1471
|
const messagePooler = currentMessagePuller = sqliteEventStoreMessageBatchPuller({
|
|
1290
1472
|
pool,
|
|
1291
1473
|
eachBatch,
|
|
1292
|
-
batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess',
|
|
1293
|
-
pullingFrequencyInMs: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess',
|
|
1474
|
+
batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _50 => _50.batchSize]), () => ( DefaultSQLiteEventStoreProcessorBatchSize)),
|
|
1475
|
+
pullingFrequencyInMs: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _51 => _51.pullingFrequencyInMs]), () => ( DefaultSQLiteEventStoreProcessorPullingFrequencyInMs))
|
|
1294
1476
|
});
|
|
1295
1477
|
const stop = async () => {
|
|
1296
1478
|
if (!isRunning) return;
|
|
@@ -1347,13 +1529,13 @@ var getSQLiteEventStore = (options) => {
|
|
|
1347
1529
|
const pool = _nullishCoalesce(options.pool, () => ( SQLiteConnectionPool(options)));
|
|
1348
1530
|
let migrateSchema = void 0;
|
|
1349
1531
|
const inlineProjections = (_nullishCoalesce(options.projections, () => ( []))).filter(({ type }) => type === "inline").map(({ projection: projection2 }) => projection2);
|
|
1350
|
-
const onBeforeCommitHook = _optionalChain([options, 'access',
|
|
1532
|
+
const onBeforeCommitHook = _optionalChain([options, 'access', _52 => _52.hooks, 'optionalAccess', _53 => _53.onBeforeCommit]);
|
|
1351
1533
|
const withConnection = async (handler) => pool.withConnection(async (database) => {
|
|
1352
1534
|
await ensureSchemaExists(database);
|
|
1353
1535
|
return await handler(database);
|
|
1354
1536
|
});
|
|
1355
1537
|
if (options) {
|
|
1356
|
-
autoGenerateSchema = _optionalChain([options, 'access',
|
|
1538
|
+
autoGenerateSchema = _optionalChain([options, 'access', _54 => _54.schema, 'optionalAccess', _55 => _55.autoMigration]) === void 0 || _optionalChain([options, 'access', _56 => _56.schema, 'optionalAccess', _57 => _57.autoMigration]) !== "None";
|
|
1357
1539
|
}
|
|
1358
1540
|
const migrate = (connection) => {
|
|
1359
1541
|
if (!migrateSchema) {
|
|
@@ -1364,11 +1546,11 @@ var getSQLiteEventStore = (options) => {
|
|
|
1364
1546
|
await projection2.init(context);
|
|
1365
1547
|
}
|
|
1366
1548
|
}
|
|
1367
|
-
if (_optionalChain([options, 'access',
|
|
1549
|
+
if (_optionalChain([options, 'access', _58 => _58.hooks, 'optionalAccess', _59 => _59.onBeforeSchemaCreated])) {
|
|
1368
1550
|
await options.hooks.onBeforeSchemaCreated(context);
|
|
1369
1551
|
}
|
|
1370
1552
|
},
|
|
1371
|
-
onAfterSchemaCreated: _optionalChain([options, 'access',
|
|
1553
|
+
onAfterSchemaCreated: _optionalChain([options, 'access', _60 => _60.hooks, 'optionalAccess', _61 => _61.onAfterSchemaCreated])
|
|
1372
1554
|
});
|
|
1373
1555
|
}
|
|
1374
1556
|
return migrateSchema;
|
|
@@ -1380,7 +1562,7 @@ var getSQLiteEventStore = (options) => {
|
|
|
1380
1562
|
return {
|
|
1381
1563
|
async aggregateStream(streamName, options2) {
|
|
1382
1564
|
const { evolve, initialState, read } = options2;
|
|
1383
|
-
const expectedStreamVersion = _optionalChain([read, 'optionalAccess',
|
|
1565
|
+
const expectedStreamVersion = _optionalChain([read, 'optionalAccess', _62 => _62.expectedStreamVersion]);
|
|
1384
1566
|
let state = initialState();
|
|
1385
1567
|
if (typeof streamName !== "string") {
|
|
1386
1568
|
throw new Error("Stream name is not string");
|
|
@@ -1428,7 +1610,7 @@ var getSQLiteEventStore = (options) => {
|
|
|
1428
1610
|
throw new ExpectedVersionConflictError(
|
|
1429
1611
|
-1n,
|
|
1430
1612
|
//TODO: Return actual version in case of error
|
|
1431
|
-
_nullishCoalesce(_optionalChain([options2, 'optionalAccess',
|
|
1613
|
+
_nullishCoalesce(_optionalChain([options2, 'optionalAccess', _63 => _63.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
|
|
1432
1614
|
);
|
|
1433
1615
|
return {
|
|
1434
1616
|
nextExpectedStreamVersion: appendResult.nextStreamPosition,
|
|
@@ -1464,7 +1646,7 @@ var SQLiteProjectionSpec = {
|
|
|
1464
1646
|
const allEvents = [];
|
|
1465
1647
|
const run = async (connection2) => {
|
|
1466
1648
|
let globalPosition = 0n;
|
|
1467
|
-
const numberOfTimes = _nullishCoalesce(_optionalChain([options2, 'optionalAccess',
|
|
1649
|
+
const numberOfTimes = _nullishCoalesce(_optionalChain([options2, 'optionalAccess', _64 => _64.numberOfTimes]), () => ( 1));
|
|
1468
1650
|
for (const event of [
|
|
1469
1651
|
...givenEvents,
|
|
1470
1652
|
...Array.from({ length: numberOfTimes }).flatMap(() => events)
|
|
@@ -1521,18 +1703,18 @@ var SQLiteProjectionSpec = {
|
|
|
1521
1703
|
if (!isErrorConstructor(args[0])) {
|
|
1522
1704
|
assertTrue(
|
|
1523
1705
|
args[0](error),
|
|
1524
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
1706
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _65 => _65.toString, 'call', _66 => _66()])}`
|
|
1525
1707
|
);
|
|
1526
1708
|
return;
|
|
1527
1709
|
}
|
|
1528
1710
|
assertTrue(
|
|
1529
1711
|
error instanceof args[0],
|
|
1530
|
-
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess',
|
|
1712
|
+
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess', _67 => _67.toString, 'call', _68 => _68()])}`
|
|
1531
1713
|
);
|
|
1532
1714
|
if (args[1]) {
|
|
1533
1715
|
assertTrue(
|
|
1534
1716
|
args[1](error),
|
|
1535
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
1717
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _69 => _69.toString, 'call', _70 => _70()])}`
|
|
1536
1718
|
);
|
|
1537
1719
|
}
|
|
1538
1720
|
} finally {
|
|
@@ -1551,7 +1733,7 @@ var eventInStream = (streamName, event) => {
|
|
|
1551
1733
|
...event,
|
|
1552
1734
|
metadata: {
|
|
1553
1735
|
..._nullishCoalesce(event.metadata, () => ( {})),
|
|
1554
|
-
streamName: _nullishCoalesce(_optionalChain([event, 'access',
|
|
1736
|
+
streamName: _nullishCoalesce(_optionalChain([event, 'access', _71 => _71.metadata, 'optionalAccess', _72 => _72.streamName]), () => ( streamName))
|
|
1555
1737
|
}
|
|
1556
1738
|
};
|
|
1557
1739
|
};
|
|
@@ -1607,5 +1789,11 @@ var expectSQL = {
|
|
|
1607
1789
|
|
|
1608
1790
|
|
|
1609
1791
|
|
|
1610
|
-
|
|
1792
|
+
|
|
1793
|
+
|
|
1794
|
+
|
|
1795
|
+
|
|
1796
|
+
|
|
1797
|
+
|
|
1798
|
+
exports.InMemorySQLiteDatabase = InMemorySQLiteDatabase; exports.InMemorySharedCacheSQLiteDatabase = InMemorySharedCacheSQLiteDatabase; exports.SQLiteConnectionPool = SQLiteConnectionPool; exports.SQLiteEventStoreDefaultStreamVersion = SQLiteEventStoreDefaultStreamVersion; exports.SQLiteProjectionSpec = SQLiteProjectionSpec; exports.appendToStream = appendToStream; exports.assertSQLQueryResultMatches = assertSQLQueryResultMatches; exports.createEventStoreSchema = createEventStoreSchema; exports.defaultTag = defaultTag; exports.emmettPrefix = emmettPrefix; exports.eventInStream = eventInStream; exports.eventsInStream = eventsInStream; exports.expectSQL = expectSQL; exports.getSQLiteEventStore = getSQLiteEventStore; exports.globalNames = globalNames; exports.globalTag = globalTag; exports.handleProjections = handleProjections; exports.isSQLiteError = isSQLiteError; exports.messagesTable = messagesTable; exports.messagesTableSQL = messagesTableSQL; exports.migration_0_42_0_FromSubscriptionsToProcessors = migration_0_42_0_FromSubscriptionsToProcessors; exports.migration_0_42_0_SQLs = migration_0_42_0_SQLs; exports.newEventsInStream = newEventsInStream; exports.processorsTable = processorsTable; exports.processorsTableSQL = processorsTableSQL; exports.projectionsTable = projectionsTable; exports.projectionsTableSQL = projectionsTableSQL; exports.readLastMessageGlobalPosition = readLastMessageGlobalPosition; exports.readMessagesBatch = readMessagesBatch; exports.readProcessorCheckpoint = readProcessorCheckpoint; exports.readStream = readStream; exports.schemaSQL = schemaSQL; exports.schema_0_41_0 = schema_0_41_0; exports.schema_0_42_0 = schema_0_42_0; exports.sql = sql; exports.sqliteConnection = sqliteConnection; exports.sqliteProjection = sqliteProjection; exports.sqliteRawBatchSQLProjection = sqliteRawBatchSQLProjection; exports.sqliteRawSQLProjection = sqliteRawSQLProjection; exports.storeProcessorCheckpoint = storeProcessorCheckpoint; exports.streamsTable = streamsTable; exports.streamsTableSQL = streamsTableSQL;
|
|
1611
1799
|
//# sourceMappingURL=index.cjs.map
|