@event-driven-io/emmett-sqlite 0.43.0-beta.5 → 0.43.0-beta.7
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/cloudflare.d.cts +1 -1
- package/dist/cloudflare.d.ts +1 -1
- package/dist/index.cjs +336 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -4
- package/dist/index.d.ts +88 -4
- package/dist/index.js +348 -35
- package/dist/index.js.map +1 -1
- package/dist/sqlite3.d.cts +1 -1
- package/dist/sqlite3.d.ts +1 -1
- package/dist/{sqliteProjection-DBJa19a5.d.cts → sqliteProjection-BZi2wy1K.d.cts} +3 -3
- package/dist/{sqliteProjection-DBJa19a5.d.ts → sqliteProjection-BZi2wy1K.d.ts} +3 -3
- package/package.json +5 -5
package/dist/cloudflare.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { D1Database } from '@cloudflare/workers-types';
|
|
2
2
|
import { d1DumboDriver, D1PoolOptions } from '@event-driven-io/dumbo/cloudflare';
|
|
3
|
-
import { E as EventStoreDriver, S as SQLiteEventStoreOptions } from './sqliteProjection-
|
|
3
|
+
import { E as EventStoreDriver, S as SQLiteEventStoreOptions } from './sqliteProjection-BZi2wy1K.cjs';
|
|
4
4
|
import '@event-driven-io/dumbo';
|
|
5
5
|
import '@event-driven-io/dumbo/sqlite';
|
|
6
6
|
import '@event-driven-io/emmett';
|
package/dist/cloudflare.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { D1Database } from '@cloudflare/workers-types';
|
|
2
2
|
import { d1DumboDriver, D1PoolOptions } from '@event-driven-io/dumbo/cloudflare';
|
|
3
|
-
import { E as EventStoreDriver, S as SQLiteEventStoreOptions } from './sqliteProjection-
|
|
3
|
+
import { E as EventStoreDriver, S as SQLiteEventStoreOptions } from './sqliteProjection-BZi2wy1K.js';
|
|
4
4
|
import '@event-driven-io/dumbo';
|
|
5
5
|
import '@event-driven-io/dumbo/sqlite';
|
|
6
6
|
import '@event-driven-io/emmett';
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,131 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;//
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/eventStore/projections/pongo/pongoProjections.ts
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _pongo = require('@event-driven-io/pongo');
|
|
5
|
+
var pongoProjection = ({
|
|
6
|
+
name,
|
|
7
|
+
kind,
|
|
8
|
+
version,
|
|
9
|
+
truncate,
|
|
10
|
+
handle,
|
|
11
|
+
canHandle,
|
|
12
|
+
eventsOptions
|
|
13
|
+
}) => sqliteProjection({
|
|
14
|
+
name,
|
|
15
|
+
version,
|
|
16
|
+
kind: _nullishCoalesce(kind, () => ( "emt:projections:postgresql:pongo:generic")),
|
|
17
|
+
canHandle,
|
|
18
|
+
eventsOptions,
|
|
19
|
+
handle: async (events, context) => {
|
|
20
|
+
const { connection } = context;
|
|
21
|
+
const driver = await pongoDriverRegistry.tryResolve(
|
|
22
|
+
context.driverType
|
|
23
|
+
);
|
|
24
|
+
const pongo = _pongo.pongoClient.call(void 0, {
|
|
25
|
+
driver,
|
|
26
|
+
connectionOptions: { connection }
|
|
27
|
+
});
|
|
28
|
+
try {
|
|
29
|
+
await handle(events, {
|
|
30
|
+
...context,
|
|
31
|
+
pongo
|
|
32
|
+
});
|
|
33
|
+
} finally {
|
|
34
|
+
await pongo.close();
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
truncate: truncate ? async (context) => {
|
|
38
|
+
const { connection } = context;
|
|
39
|
+
const driver = await pongoDriverRegistry.tryResolve(
|
|
40
|
+
context.driverType
|
|
41
|
+
);
|
|
42
|
+
const pongo = _pongo.pongoClient.call(void 0, {
|
|
43
|
+
driver,
|
|
44
|
+
connectionOptions: { connection }
|
|
45
|
+
});
|
|
46
|
+
try {
|
|
47
|
+
await truncate({
|
|
48
|
+
...context,
|
|
49
|
+
pongo
|
|
50
|
+
});
|
|
51
|
+
} finally {
|
|
52
|
+
await pongo.close();
|
|
53
|
+
}
|
|
54
|
+
} : void 0
|
|
55
|
+
});
|
|
56
|
+
var pongoMultiStreamProjection = (options) => {
|
|
57
|
+
const { collectionName, getDocumentId, canHandle } = options;
|
|
58
|
+
const collectionNameWithVersion = options.version && options.version > 0 ? `${collectionName}_v${options.version}` : collectionName;
|
|
59
|
+
return pongoProjection({
|
|
60
|
+
name: collectionNameWithVersion,
|
|
61
|
+
version: options.version,
|
|
62
|
+
kind: _nullishCoalesce(options.kind, () => ( "emt:projections:postgresql:pongo:multi_stream")),
|
|
63
|
+
eventsOptions: options.eventsOptions,
|
|
64
|
+
handle: async (events, { pongo }) => {
|
|
65
|
+
const collection = pongo.db().collection(
|
|
66
|
+
collectionNameWithVersion,
|
|
67
|
+
options.collectionOptions
|
|
68
|
+
);
|
|
69
|
+
for (const event of events) {
|
|
70
|
+
await collection.handle(getDocumentId(event), async (document) => {
|
|
71
|
+
return "initialState" in options ? await options.evolve(
|
|
72
|
+
_nullishCoalesce(document, () => ( options.initialState())),
|
|
73
|
+
event
|
|
74
|
+
) : await options.evolve(
|
|
75
|
+
document,
|
|
76
|
+
event
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
canHandle,
|
|
82
|
+
truncate: async (context) => {
|
|
83
|
+
const { connection } = context;
|
|
84
|
+
const driver = await pongoDriverRegistry.tryResolve(
|
|
85
|
+
context.driverType
|
|
86
|
+
);
|
|
87
|
+
const pongo = _pongo.pongoClient.call(void 0, {
|
|
88
|
+
driver,
|
|
89
|
+
connectionOptions: { connection }
|
|
90
|
+
});
|
|
91
|
+
try {
|
|
92
|
+
await pongo.db().collection(
|
|
93
|
+
collectionNameWithVersion,
|
|
94
|
+
options.collectionOptions
|
|
95
|
+
).deleteMany();
|
|
96
|
+
} finally {
|
|
97
|
+
await pongo.close();
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
init: async (context) => {
|
|
101
|
+
const { connection } = context;
|
|
102
|
+
const driver = await pongoDriverRegistry.tryResolve(
|
|
103
|
+
context.driverType
|
|
104
|
+
);
|
|
105
|
+
const pongo = _pongo.pongoClient.call(void 0, {
|
|
106
|
+
connectionOptions: { connection },
|
|
107
|
+
driver
|
|
108
|
+
});
|
|
109
|
+
try {
|
|
110
|
+
await pongo.db().collection(
|
|
111
|
+
collectionNameWithVersion,
|
|
112
|
+
options.collectionOptions
|
|
113
|
+
).schema.migrate();
|
|
114
|
+
} finally {
|
|
115
|
+
await pongo.close();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
var pongoSingleStreamProjection = (options) => {
|
|
121
|
+
return pongoMultiStreamProjection({
|
|
122
|
+
...options,
|
|
123
|
+
kind: "emt:projections:postgresql:pongo:single_stream",
|
|
124
|
+
getDocumentId: _nullishCoalesce(options.getDocumentId, () => ( ((event) => event.metadata.streamName)))
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// ../emmett/dist/chunk-AZDDB5SF.js
|
|
2
129
|
var isNumber = (val) => typeof val === "number" && val === val;
|
|
3
130
|
var isString = (val) => typeof val === "string";
|
|
4
131
|
var isErrorConstructor = (expect) => {
|
|
@@ -49,6 +176,7 @@ var ConcurrencyError = class _ConcurrencyError extends EmmettError {
|
|
|
49
176
|
// ../emmett/dist/index.js
|
|
50
177
|
var _uuid = require('uuid');
|
|
51
178
|
|
|
179
|
+
|
|
52
180
|
var _asyncretry = require('async-retry'); var _asyncretry2 = _interopRequireDefault(_asyncretry);
|
|
53
181
|
|
|
54
182
|
|
|
@@ -559,6 +687,15 @@ var isSubset = (superObj, subObj) => {
|
|
|
559
687
|
var assertFails = (message2) => {
|
|
560
688
|
throw new AssertionError(_nullishCoalesce(message2, () => ( "That should not ever happened, right?")));
|
|
561
689
|
};
|
|
690
|
+
var assertDeepEqual = (actual, expected, message2) => {
|
|
691
|
+
if (!deepEquals(actual, expected))
|
|
692
|
+
throw new AssertionError(
|
|
693
|
+
_nullishCoalesce(message2, () => ( `subObj:
|
|
694
|
+
${JSONParser.stringify(expected)}
|
|
695
|
+
is not equal to
|
|
696
|
+
${JSONParser.stringify(actual)}`))
|
|
697
|
+
);
|
|
698
|
+
};
|
|
562
699
|
function assertTrue(condition, message2) {
|
|
563
700
|
if (condition !== true)
|
|
564
701
|
throw new AssertionError(_nullishCoalesce(message2, () => ( `Condition is false`)));
|
|
@@ -580,6 +717,13 @@ function assertNotEqual(obj, other, message2) {
|
|
|
580
717
|
_nullishCoalesce(message2, () => ( `Objects are equal: ${JSONParser.stringify(obj)}`))
|
|
581
718
|
);
|
|
582
719
|
}
|
|
720
|
+
function assertIsNotNull(result) {
|
|
721
|
+
assertNotEqual(result, null);
|
|
722
|
+
assertOk(result);
|
|
723
|
+
}
|
|
724
|
+
function assertIsNull(result) {
|
|
725
|
+
assertEqual(result, null);
|
|
726
|
+
}
|
|
583
727
|
var assertThatArray = (array) => {
|
|
584
728
|
return {
|
|
585
729
|
isEmpty: () => assertEqual(
|
|
@@ -923,6 +1067,143 @@ var workflowProcessor = (options) => {
|
|
|
923
1067
|
});
|
|
924
1068
|
};
|
|
925
1069
|
|
|
1070
|
+
// src/eventStore/projections/pongo/pongoProjectionSpec.ts
|
|
1071
|
+
|
|
1072
|
+
|
|
1073
|
+
|
|
1074
|
+
var withCollection = async (handle, options) => {
|
|
1075
|
+
const { connection, inDatabase, inCollection } = options;
|
|
1076
|
+
const driver = await pongoDriverRegistry.tryResolve(
|
|
1077
|
+
connection.driverType
|
|
1078
|
+
);
|
|
1079
|
+
const pongo = _pongo.pongoClient.call(void 0, {
|
|
1080
|
+
connectionOptions: { connection },
|
|
1081
|
+
driver
|
|
1082
|
+
});
|
|
1083
|
+
try {
|
|
1084
|
+
const collection = pongo.db(inDatabase).collection(inCollection);
|
|
1085
|
+
return handle(collection);
|
|
1086
|
+
} finally {
|
|
1087
|
+
await pongo.close();
|
|
1088
|
+
}
|
|
1089
|
+
};
|
|
1090
|
+
var withoutIdAndVersion = (doc) => {
|
|
1091
|
+
const { _id, _version, ...without } = doc;
|
|
1092
|
+
return without;
|
|
1093
|
+
};
|
|
1094
|
+
var assertDocumentsEqual = (actual, expected) => {
|
|
1095
|
+
if ("_id" in expected)
|
|
1096
|
+
assertEqual(
|
|
1097
|
+
expected._id,
|
|
1098
|
+
actual._id,
|
|
1099
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1100
|
+
`Document ids are not matching! Expected: ${expected._id}, Actual: ${actual._id}`
|
|
1101
|
+
);
|
|
1102
|
+
return assertDeepEqual(
|
|
1103
|
+
withoutIdAndVersion(actual),
|
|
1104
|
+
withoutIdAndVersion(expected)
|
|
1105
|
+
);
|
|
1106
|
+
};
|
|
1107
|
+
var documentExists = (document, options) => (assertOptions) => withCollection(
|
|
1108
|
+
async (collection) => {
|
|
1109
|
+
const result = await collection.findOne(
|
|
1110
|
+
"withId" in options ? { _id: options.withId } : options.matchingFilter
|
|
1111
|
+
);
|
|
1112
|
+
assertIsNotNull(result);
|
|
1113
|
+
assertDocumentsEqual(result, document);
|
|
1114
|
+
},
|
|
1115
|
+
{ ...options, ...assertOptions }
|
|
1116
|
+
);
|
|
1117
|
+
var documentsAreTheSame = (documents, options) => (assertOptions) => withCollection(
|
|
1118
|
+
async (collection) => {
|
|
1119
|
+
const result = await collection.find(
|
|
1120
|
+
"withId" in options ? { _id: options.withId } : options.matchingFilter
|
|
1121
|
+
);
|
|
1122
|
+
assertEqual(
|
|
1123
|
+
documents.length,
|
|
1124
|
+
result.length,
|
|
1125
|
+
"Different Documents Count than expected"
|
|
1126
|
+
);
|
|
1127
|
+
for (let i = 0; i < documents.length; i++) {
|
|
1128
|
+
assertThatArray(result).contains(documents[i]);
|
|
1129
|
+
}
|
|
1130
|
+
},
|
|
1131
|
+
{ ...options, ...assertOptions }
|
|
1132
|
+
);
|
|
1133
|
+
var documentsMatchingHaveCount = (expectedCount, options) => (assertOptions) => withCollection(
|
|
1134
|
+
async (collection) => {
|
|
1135
|
+
const result = await collection.find(
|
|
1136
|
+
"withId" in options ? { _id: options.withId } : options.matchingFilter
|
|
1137
|
+
);
|
|
1138
|
+
assertEqual(
|
|
1139
|
+
expectedCount,
|
|
1140
|
+
result.length,
|
|
1141
|
+
"Different Documents Count than expected"
|
|
1142
|
+
);
|
|
1143
|
+
},
|
|
1144
|
+
{ ...options, ...assertOptions }
|
|
1145
|
+
);
|
|
1146
|
+
var documentMatchingExists = (options) => (assertOptions) => withCollection(
|
|
1147
|
+
async (collection) => {
|
|
1148
|
+
const result = await collection.find(
|
|
1149
|
+
"withId" in options ? { _id: options.withId } : options.matchingFilter
|
|
1150
|
+
);
|
|
1151
|
+
assertThatArray(result).isNotEmpty();
|
|
1152
|
+
},
|
|
1153
|
+
{ ...options, ...assertOptions }
|
|
1154
|
+
);
|
|
1155
|
+
var documentDoesNotExist = (options) => (assertOptions) => withCollection(
|
|
1156
|
+
async (collection) => {
|
|
1157
|
+
const result = await collection.findOne(
|
|
1158
|
+
"withId" in options ? { _id: options.withId } : options.matchingFilter
|
|
1159
|
+
);
|
|
1160
|
+
assertIsNull(result);
|
|
1161
|
+
},
|
|
1162
|
+
{ ...options, ...assertOptions }
|
|
1163
|
+
);
|
|
1164
|
+
var expectPongoDocuments = {
|
|
1165
|
+
fromCollection: (collectionName) => {
|
|
1166
|
+
return {
|
|
1167
|
+
withId: (id) => {
|
|
1168
|
+
return {
|
|
1169
|
+
toBeEqual: (document) => documentExists(document, {
|
|
1170
|
+
withId: id,
|
|
1171
|
+
inCollection: collectionName
|
|
1172
|
+
}),
|
|
1173
|
+
toExist: () => documentMatchingExists({
|
|
1174
|
+
withId: id,
|
|
1175
|
+
inCollection: collectionName
|
|
1176
|
+
}),
|
|
1177
|
+
notToExist: () => documentDoesNotExist({
|
|
1178
|
+
withId: id,
|
|
1179
|
+
inCollection: collectionName
|
|
1180
|
+
})
|
|
1181
|
+
};
|
|
1182
|
+
},
|
|
1183
|
+
matching: (filter) => {
|
|
1184
|
+
return {
|
|
1185
|
+
toBeTheSame: (documents) => documentsAreTheSame(documents, {
|
|
1186
|
+
matchingFilter: filter,
|
|
1187
|
+
inCollection: collectionName
|
|
1188
|
+
}),
|
|
1189
|
+
toHaveCount: (expectedCount) => documentsMatchingHaveCount(expectedCount, {
|
|
1190
|
+
matchingFilter: filter,
|
|
1191
|
+
inCollection: collectionName
|
|
1192
|
+
}),
|
|
1193
|
+
toExist: () => documentMatchingExists({
|
|
1194
|
+
matchingFilter: filter,
|
|
1195
|
+
inCollection: collectionName
|
|
1196
|
+
}),
|
|
1197
|
+
notToExist: () => documentDoesNotExist({
|
|
1198
|
+
matchingFilter: filter,
|
|
1199
|
+
inCollection: collectionName
|
|
1200
|
+
})
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
|
|
926
1207
|
// src/eventStore/projections/sqliteProjection.ts
|
|
927
1208
|
var handleProjections = async (options) => {
|
|
928
1209
|
const {
|
|
@@ -1540,8 +1821,6 @@ var readProcessorCheckpoint = async (execute, options) => {
|
|
|
1540
1821
|
// src/eventStore/SQLiteEventStore.ts
|
|
1541
1822
|
|
|
1542
1823
|
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
1824
|
// src/eventStore/consumers/messageBatchProcessing/index.ts
|
|
1546
1825
|
var DefaultSQLiteEventStoreProcessorBatchSize = 100;
|
|
1547
1826
|
var DefaultSQLiteEventStoreProcessorPullingFrequencyInMs = 50;
|
|
@@ -1927,10 +2206,6 @@ var getSQLiteEventStore = (options) => {
|
|
|
1927
2206
|
let migrateSchema = void 0;
|
|
1928
2207
|
const inlineProjections = (_nullishCoalesce(options.projections, () => ( []))).filter(({ type }) => type === "inline").map(({ projection: projection2 }) => projection2);
|
|
1929
2208
|
const onBeforeCommitHook = _optionalChain([options, 'access', _98 => _98.hooks, 'optionalAccess', _99 => _99.onBeforeCommit]);
|
|
1930
|
-
const withConnection = (handler, options2) => pool.withConnection(async (connection) => {
|
|
1931
|
-
await ensureSchemaExists(connection);
|
|
1932
|
-
return await handler(connection);
|
|
1933
|
-
}, options2);
|
|
1934
2209
|
if (options) {
|
|
1935
2210
|
autoGenerateSchema = _optionalChain([options, 'access', _100 => _100.schema, 'optionalAccess', _101 => _101.autoMigration]) === void 0 || _optionalChain([options, 'access', _102 => _102.schema, 'optionalAccess', _103 => _103.autoMigration]) !== "None";
|
|
1936
2211
|
}
|
|
@@ -1961,21 +2236,23 @@ var getSQLiteEventStore = (options) => {
|
|
|
1961
2236
|
}
|
|
1962
2237
|
return migrateSchema;
|
|
1963
2238
|
};
|
|
1964
|
-
const ensureSchemaExists = (
|
|
2239
|
+
const ensureSchemaExists = () => {
|
|
1965
2240
|
if (!autoGenerateSchema) return Promise.resolve();
|
|
1966
|
-
return migrate(connection);
|
|
2241
|
+
return pool.withConnection((connection) => migrate(connection));
|
|
1967
2242
|
};
|
|
1968
2243
|
return {
|
|
1969
2244
|
async aggregateStream(streamName, options2) {
|
|
2245
|
+
await ensureSchemaExists();
|
|
1970
2246
|
const { evolve, initialState, read } = options2;
|
|
1971
2247
|
const expectedStreamVersion = _optionalChain([read, 'optionalAccess', _108 => _108.expectedStreamVersion]);
|
|
1972
2248
|
let state = initialState();
|
|
1973
2249
|
if (typeof streamName !== "string") {
|
|
1974
2250
|
throw new Error("Stream name is not string");
|
|
1975
2251
|
}
|
|
1976
|
-
const result = await
|
|
1977
|
-
|
|
1978
|
-
|
|
2252
|
+
const result = await readStream(
|
|
2253
|
+
pool.execute,
|
|
2254
|
+
streamName,
|
|
2255
|
+
read
|
|
1979
2256
|
);
|
|
1980
2257
|
const currentStreamVersion = result.currentStreamVersion;
|
|
1981
2258
|
assertExpectedVersionMatchesCurrent(
|
|
@@ -1993,14 +2270,19 @@ var getSQLiteEventStore = (options) => {
|
|
|
1993
2270
|
streamExists: result.streamExists
|
|
1994
2271
|
};
|
|
1995
2272
|
},
|
|
1996
|
-
readStream: async (streamName, options2) =>
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2273
|
+
readStream: async (streamName, options2) => {
|
|
2274
|
+
await ensureSchemaExists();
|
|
2275
|
+
return readStream(
|
|
2276
|
+
pool.execute,
|
|
2277
|
+
streamName,
|
|
2278
|
+
options2
|
|
2279
|
+
);
|
|
2280
|
+
},
|
|
2000
2281
|
appendToStream: async (streamName, events, appendOptions) => {
|
|
2282
|
+
await ensureSchemaExists();
|
|
2001
2283
|
const [firstPart, ...rest] = streamName.split("-");
|
|
2002
2284
|
const streamType = firstPart && rest.length > 0 ? firstPart : unknownTag2;
|
|
2003
|
-
const appendResult = await withConnection(
|
|
2285
|
+
const appendResult = await pool.withConnection(
|
|
2004
2286
|
(connection) => appendToStream(connection, streamName, streamType, events, {
|
|
2005
2287
|
...appendOptions,
|
|
2006
2288
|
onBeforeCommit: async (messages, context) => {
|
|
@@ -2030,17 +2312,39 @@ var getSQLiteEventStore = (options) => {
|
|
|
2030
2312
|
createdNewStream: appendResult.nextStreamPosition >= BigInt(events.length)
|
|
2031
2313
|
};
|
|
2032
2314
|
},
|
|
2033
|
-
streamExists(streamName, options2) {
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
{ readonly: true }
|
|
2037
|
-
);
|
|
2315
|
+
async streamExists(streamName, options2) {
|
|
2316
|
+
await ensureSchemaExists();
|
|
2317
|
+
return streamExists(pool.execute, streamName, options2);
|
|
2038
2318
|
},
|
|
2039
2319
|
consumer: (consumerOptions) => sqliteEventStoreConsumer({
|
|
2040
2320
|
..._nullishCoalesce(options, () => ( {})),
|
|
2041
2321
|
..._nullishCoalesce(consumerOptions, () => ( {})),
|
|
2042
2322
|
pool
|
|
2043
2323
|
}),
|
|
2324
|
+
async withSession(callback) {
|
|
2325
|
+
return await pool.withConnection(async (connection) => {
|
|
2326
|
+
const sessionStore = getSQLiteEventStore({
|
|
2327
|
+
...options,
|
|
2328
|
+
pool: _dumbo.dumbo.call(void 0, {
|
|
2329
|
+
...options.driver.mapToDumboOptions(options),
|
|
2330
|
+
connection
|
|
2331
|
+
}),
|
|
2332
|
+
transactionOptions: {
|
|
2333
|
+
allowNestedTransactions: true,
|
|
2334
|
+
mode: "session_based"
|
|
2335
|
+
},
|
|
2336
|
+
schema: {
|
|
2337
|
+
...options.schema,
|
|
2338
|
+
autoMigration: "None"
|
|
2339
|
+
}
|
|
2340
|
+
});
|
|
2341
|
+
await ensureSchemaExists();
|
|
2342
|
+
return callback({
|
|
2343
|
+
eventStore: sessionStore,
|
|
2344
|
+
close: () => Promise.resolve()
|
|
2345
|
+
});
|
|
2346
|
+
});
|
|
2347
|
+
},
|
|
2044
2348
|
close: () => pool.close(),
|
|
2045
2349
|
schema: {
|
|
2046
2350
|
sql: () => schemaSQL.join(""),
|
|
@@ -2305,5 +2609,14 @@ var createEventStoreSchema = async (pool, hooks) => {
|
|
|
2305
2609
|
|
|
2306
2610
|
|
|
2307
2611
|
|
|
2308
|
-
|
|
2612
|
+
|
|
2613
|
+
|
|
2614
|
+
|
|
2615
|
+
|
|
2616
|
+
|
|
2617
|
+
|
|
2618
|
+
|
|
2619
|
+
|
|
2620
|
+
|
|
2621
|
+
exports.SQLiteEventStoreDefaultStreamVersion = SQLiteEventStoreDefaultStreamVersion; exports.SQLiteProjectionSpec = SQLiteProjectionSpec; exports.appendToStream = appendToStream; exports.assertSQLQueryResultMatches = assertSQLQueryResultMatches; exports.createEventStoreSchema = createEventStoreSchema; exports.defaultTag = defaultTag2; exports.documentDoesNotExist = documentDoesNotExist; exports.documentExists = documentExists; exports.documentMatchingExists = documentMatchingExists; exports.documentsAreTheSame = documentsAreTheSame; exports.documentsMatchingHaveCount = documentsMatchingHaveCount; exports.emmettPrefix = emmettPrefix2; exports.eventInStream = eventInStream; exports.eventsInStream = eventsInStream; exports.expectPongoDocuments = expectPongoDocuments; exports.expectSQL = expectSQL; exports.getSQLiteEventStore = getSQLiteEventStore; exports.globalNames = globalNames; exports.globalTag = globalTag; exports.handleProjections = handleProjections; 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.pongoMultiStreamProjection = pongoMultiStreamProjection; exports.pongoProjection = pongoProjection; exports.pongoSingleStreamProjection = pongoSingleStreamProjection; 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.sqliteProjection = sqliteProjection; exports.sqliteRawBatchSQLProjection = sqliteRawBatchSQLProjection; exports.sqliteRawSQLProjection = sqliteRawSQLProjection; exports.storeProcessorCheckpoint = storeProcessorCheckpoint; exports.streamExists = streamExists; exports.streamsTable = streamsTable; exports.streamsTableSQL = streamsTableSQL; exports.unknownTag = unknownTag2;
|
|
2309
2622
|
//# sourceMappingURL=index.cjs.map
|