@event-driven-io/emmett-sqlite 0.43.0-beta.6 → 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 +291 -2
- 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 +289 -0
- package/dist/index.js.map +1 -1
- package/dist/sqlite3.d.cts +1 -1
- package/dist/sqlite3.d.ts +1 -1
- package/dist/{sqliteProjection-D6WKeuhb.d.cts → sqliteProjection-BZi2wy1K.d.cts} +1 -1
- package/dist/{sqliteProjection-D6WKeuhb.d.ts → sqliteProjection-BZi2wy1K.d.ts} +1 -1
- package/package.json +3 -3
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) => {
|
|
@@ -560,6 +687,15 @@ var isSubset = (superObj, subObj) => {
|
|
|
560
687
|
var assertFails = (message2) => {
|
|
561
688
|
throw new AssertionError(_nullishCoalesce(message2, () => ( "That should not ever happened, right?")));
|
|
562
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
|
+
};
|
|
563
699
|
function assertTrue(condition, message2) {
|
|
564
700
|
if (condition !== true)
|
|
565
701
|
throw new AssertionError(_nullishCoalesce(message2, () => ( `Condition is false`)));
|
|
@@ -581,6 +717,13 @@ function assertNotEqual(obj, other, message2) {
|
|
|
581
717
|
_nullishCoalesce(message2, () => ( `Objects are equal: ${JSONParser.stringify(obj)}`))
|
|
582
718
|
);
|
|
583
719
|
}
|
|
720
|
+
function assertIsNotNull(result) {
|
|
721
|
+
assertNotEqual(result, null);
|
|
722
|
+
assertOk(result);
|
|
723
|
+
}
|
|
724
|
+
function assertIsNull(result) {
|
|
725
|
+
assertEqual(result, null);
|
|
726
|
+
}
|
|
584
727
|
var assertThatArray = (array) => {
|
|
585
728
|
return {
|
|
586
729
|
isEmpty: () => assertEqual(
|
|
@@ -924,6 +1067,143 @@ var workflowProcessor = (options) => {
|
|
|
924
1067
|
});
|
|
925
1068
|
};
|
|
926
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
|
+
|
|
927
1207
|
// src/eventStore/projections/sqliteProjection.ts
|
|
928
1208
|
var handleProjections = async (options) => {
|
|
929
1209
|
const {
|
|
@@ -2329,5 +2609,14 @@ var createEventStoreSchema = async (pool, hooks) => {
|
|
|
2329
2609
|
|
|
2330
2610
|
|
|
2331
2611
|
|
|
2332
|
-
|
|
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;
|
|
2333
2622
|
//# sourceMappingURL=index.cjs.map
|