@event-driven-io/pongo 0.17.0-alpha.6 → 0.17.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/chunk-4BL6YWLW.cjs +872 -0
- package/dist/chunk-4BL6YWLW.cjs.map +1 -0
- package/dist/chunk-ECQ2CKZE.cjs +330 -0
- package/dist/chunk-ECQ2CKZE.cjs.map +1 -0
- package/dist/chunk-EYQDS752.js +364 -0
- package/dist/chunk-EYQDS752.js.map +1 -0
- package/dist/{chunk-OO7GMTMP.js → chunk-NCNRRYVE.js} +573 -876
- package/dist/chunk-NCNRRYVE.js.map +1 -0
- package/dist/chunk-WH26IXHN.js +10 -0
- package/dist/chunk-WH26IXHN.js.map +1 -0
- package/dist/chunk-WKW4LGF6.cjs +10 -0
- package/dist/chunk-WKW4LGF6.cjs.map +1 -0
- package/dist/chunk-Y7LRKJLJ.js +330 -0
- package/dist/chunk-Y7LRKJLJ.js.map +1 -0
- package/dist/chunk-ZPWKWNK2.cjs +364 -0
- package/dist/chunk-ZPWKWNK2.cjs.map +1 -0
- package/dist/cli.cjs +112 -36
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +110 -34
- package/dist/cli.js.map +1 -1
- package/dist/d1.cjs +54 -0
- package/dist/d1.cjs.map +1 -0
- package/dist/d1.d.cts +11 -0
- package/dist/d1.d.ts +11 -0
- package/dist/d1.js +54 -0
- package/dist/d1.js.map +1 -0
- package/dist/index-BJopB-em.d.cts +7 -0
- package/dist/index-G5DECNb_.d.ts +7 -0
- package/dist/index.cjs +3 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -18
- package/dist/index.d.ts +58 -18
- package/dist/index.js +14 -17
- package/dist/pg-73DOKU64.js +11 -0
- package/dist/pg-73DOKU64.js.map +1 -0
- package/dist/pg-I267A7IL.cjs +11 -0
- package/dist/pg-I267A7IL.cjs.map +1 -0
- package/dist/pg.cjs +4 -3
- package/dist/pg.cjs.map +1 -1
- package/dist/pg.d.cts +36 -6
- package/dist/pg.d.ts +36 -6
- package/dist/pg.js +10 -9
- package/dist/pongoCollectionSchemaComponent-t_e9n2Wc.d.cts +426 -0
- package/dist/pongoCollectionSchemaComponent-t_e9n2Wc.d.ts +426 -0
- package/dist/shim.cjs +43 -8
- package/dist/shim.cjs.map +1 -1
- package/dist/shim.d.cts +12 -9
- package/dist/shim.d.ts +12 -9
- package/dist/shim.js +40 -5
- package/dist/shim.js.map +1 -1
- package/dist/sqlite3.cjs +66 -1
- package/dist/sqlite3.cjs.map +1 -1
- package/dist/sqlite3.d.cts +13 -1
- package/dist/sqlite3.d.ts +13 -1
- package/dist/sqlite3.js +65 -0
- package/dist/sqlite3.js.map +1 -1
- package/package.json +34 -12
- package/README.md +0 -230
- package/dist/chunk-AV4SHJQB.cjs +0 -1175
- package/dist/chunk-AV4SHJQB.cjs.map +0 -1
- package/dist/chunk-OO7GMTMP.js.map +0 -1
- package/dist/pg-BfTNWLV9.d.ts +0 -39
- package/dist/pg-C9NmCQe7.d.cts +0 -39
- package/dist/pongoClient-D8jPedlZ.d.cts +0 -364
- package/dist/pongoClient-D8jPedlZ.d.ts +0 -364
|
@@ -0,0 +1,872 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return 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; }// src/core/collection/pongoCollection.ts
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _dumbo = require('@event-driven-io/dumbo');
|
|
7
|
+
var _uuid = require('uuid');
|
|
8
|
+
|
|
9
|
+
// src/core/collection/pongoCollectionSchema.ts
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
// src/core/collection/pongoCollectionSchemaComponent.ts
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var PongoCollectionSchemaComponent = ({
|
|
17
|
+
definition,
|
|
18
|
+
migrationsOrSchemaComponents,
|
|
19
|
+
sqlBuilder
|
|
20
|
+
}) => ({
|
|
21
|
+
..._dumbo.schemaComponent.call(void 0,
|
|
22
|
+
`sc:pongo:collection:${definition.name}`,
|
|
23
|
+
migrationsOrSchemaComponents
|
|
24
|
+
),
|
|
25
|
+
sqlBuilder,
|
|
26
|
+
definition,
|
|
27
|
+
collectionName: definition.name
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// src/core/collection/query.ts
|
|
31
|
+
var QueryOperators = {
|
|
32
|
+
$eq: "$eq",
|
|
33
|
+
$gt: "$gt",
|
|
34
|
+
$gte: "$gte",
|
|
35
|
+
$lt: "$lt",
|
|
36
|
+
$lte: "$lte",
|
|
37
|
+
$ne: "$ne",
|
|
38
|
+
$in: "$in",
|
|
39
|
+
$nin: "$nin",
|
|
40
|
+
$elemMatch: "$elemMatch",
|
|
41
|
+
$all: "$all",
|
|
42
|
+
$size: "$size"
|
|
43
|
+
};
|
|
44
|
+
var OperatorMap = {
|
|
45
|
+
$gt: ">",
|
|
46
|
+
$gte: ">=",
|
|
47
|
+
$lt: "<",
|
|
48
|
+
$lte: "<=",
|
|
49
|
+
$ne: "!="
|
|
50
|
+
};
|
|
51
|
+
var isOperator = (key) => key.startsWith("$");
|
|
52
|
+
var hasOperators = (value) => Object.keys(value).some(isOperator);
|
|
53
|
+
|
|
54
|
+
// src/core/database/pongoDatabaseCache.ts
|
|
55
|
+
var PongoDatabaseCache = ({
|
|
56
|
+
driver,
|
|
57
|
+
typedSchema
|
|
58
|
+
}) => {
|
|
59
|
+
const dbClients = /* @__PURE__ */ new Map();
|
|
60
|
+
const getDatabaseDefinition = (dbName) => Object.values(_nullishCoalesce(_optionalChain([typedSchema, 'optionalAccess', _ => _.dbs]), () => ( {}))).find((d) => d.name === dbName);
|
|
61
|
+
return {
|
|
62
|
+
getOrCreate: (createOptions) => {
|
|
63
|
+
const dbName = _nullishCoalesce(createOptions.databaseName, () => ( (driver.getDatabaseNameOrDefault ? driver.getDatabaseNameOrDefault(createOptions) : "db:default")));
|
|
64
|
+
const existing = dbClients.get(dbName);
|
|
65
|
+
if (existing) return existing;
|
|
66
|
+
const definition = getDatabaseDefinition(createOptions.databaseName);
|
|
67
|
+
const newDb = driver.databaseFactory({
|
|
68
|
+
...createOptions,
|
|
69
|
+
databaseName: dbName,
|
|
70
|
+
schema: {
|
|
71
|
+
...createOptions.schema,
|
|
72
|
+
...definition ? { definition } : {}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
dbClients.set(dbName, newDb);
|
|
76
|
+
return newDb;
|
|
77
|
+
},
|
|
78
|
+
all: () => Array.from(dbClients.values()),
|
|
79
|
+
forAll: (func) => {
|
|
80
|
+
return Promise.all(
|
|
81
|
+
Array.from(dbClients.values()).map((v) => v).map(func)
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/core/database/pongoDatabaseSchemaComponent.ts
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
// src/core/typing/entries.ts
|
|
93
|
+
var objectEntries = (obj) => Object.entries(obj).map(([key, value]) => [key, value]);
|
|
94
|
+
|
|
95
|
+
// src/core/typing/operations.ts
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
// src/core/errors/index.ts
|
|
102
|
+
var isNumber = (val) => typeof val === "number" && val === val;
|
|
103
|
+
var isString = (val) => typeof val === "string";
|
|
104
|
+
var PongoError = class _PongoError extends Error {
|
|
105
|
+
|
|
106
|
+
constructor(options) {
|
|
107
|
+
const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options : 500;
|
|
108
|
+
const message = options && typeof options === "object" && "message" in options ? options.message : isString(options) ? options : `Error with status code '${errorCode}' ocurred during Pongo processing`;
|
|
109
|
+
super(message);
|
|
110
|
+
this.errorCode = errorCode;
|
|
111
|
+
Object.setPrototypeOf(this, _PongoError.prototype);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
var ConcurrencyError = class _ConcurrencyError extends PongoError {
|
|
115
|
+
constructor(message) {
|
|
116
|
+
super({
|
|
117
|
+
errorCode: 412,
|
|
118
|
+
message: _nullishCoalesce(message, () => ( `Expected document state does not match current one!`))
|
|
119
|
+
});
|
|
120
|
+
Object.setPrototypeOf(this, _ConcurrencyError.prototype);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// src/core/typing/operations.ts
|
|
125
|
+
var ObjectId = (value) => _nullishCoalesce(value, () => ( _uuid.v7.call(void 0, )));
|
|
126
|
+
var DOCUMENT_EXISTS = "DOCUMENT_EXISTS";
|
|
127
|
+
var DOCUMENT_DOES_NOT_EXIST = "DOCUMENT_DOES_NOT_EXIST";
|
|
128
|
+
var NO_CONCURRENCY_CHECK = "NO_CONCURRENCY_CHECK";
|
|
129
|
+
var isGeneralExpectedDocumentVersion = (version) => version === "DOCUMENT_DOES_NOT_EXIST" || version === "DOCUMENT_EXISTS" || version === "NO_CONCURRENCY_CHECK";
|
|
130
|
+
var expectedVersionValue = (version) => version === void 0 || isGeneralExpectedDocumentVersion(version) ? null : version;
|
|
131
|
+
var expectedVersion = (version) => {
|
|
132
|
+
return version ? BigInt(version) : NO_CONCURRENCY_CHECK;
|
|
133
|
+
};
|
|
134
|
+
var operationResult = (result, options) => {
|
|
135
|
+
const operationResult2 = {
|
|
136
|
+
...result,
|
|
137
|
+
acknowledged: true,
|
|
138
|
+
successful: result.successful,
|
|
139
|
+
assertSuccessful: (errorMessage) => {
|
|
140
|
+
const { successful } = result;
|
|
141
|
+
const { operationName, collectionName } = options;
|
|
142
|
+
if (!successful)
|
|
143
|
+
throw new ConcurrencyError(
|
|
144
|
+
_nullishCoalesce(errorMessage, () => ( `${operationName} on ${collectionName} failed. Expected document state does not match current one! Result: ${_dumbo.JSONSerializer.serialize(result)}!`))
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
if (_optionalChain([options, 'access', _2 => _2.errors, 'optionalAccess', _3 => _3.throwOnOperationFailures]))
|
|
149
|
+
operationResult2.assertSuccessful();
|
|
150
|
+
return operationResult2;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// src/core/schema/index.ts
|
|
154
|
+
var pongoCollectionSchema = (name) => ({
|
|
155
|
+
name
|
|
156
|
+
});
|
|
157
|
+
pongoCollectionSchema.from = (collectionNames) => collectionNames.reduce(
|
|
158
|
+
(acc, collectionName) => (acc[collectionName] = pongoSchema.collection(collectionName), acc),
|
|
159
|
+
{}
|
|
160
|
+
);
|
|
161
|
+
function pongoDbSchema(nameOrCollections, collections) {
|
|
162
|
+
if (collections === void 0) {
|
|
163
|
+
if (typeof nameOrCollections === "string") {
|
|
164
|
+
throw new Error("You need to provide colleciton definition");
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
collections: nameOrCollections
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
return nameOrCollections && typeof nameOrCollections === "string" ? {
|
|
171
|
+
name: nameOrCollections,
|
|
172
|
+
collections
|
|
173
|
+
} : { collections };
|
|
174
|
+
}
|
|
175
|
+
pongoDbSchema.from = (databaseName, collectionNames) => databaseName ? pongoDbSchema(databaseName, pongoCollectionSchema.from(collectionNames)) : pongoDbSchema(pongoCollectionSchema.from(collectionNames));
|
|
176
|
+
var pongoClientSchema = (dbs) => ({
|
|
177
|
+
dbs
|
|
178
|
+
});
|
|
179
|
+
var pongoSchema = {
|
|
180
|
+
client: pongoClientSchema,
|
|
181
|
+
db: pongoDbSchema,
|
|
182
|
+
collection: pongoCollectionSchema
|
|
183
|
+
};
|
|
184
|
+
var proxyPongoDbWithSchema = (pongoDb, dbSchema, collections) => {
|
|
185
|
+
const collectionNames = Object.keys(dbSchema.collections);
|
|
186
|
+
for (const collectionName of collectionNames) {
|
|
187
|
+
collections.set(collectionName, pongoDb.collection(collectionName));
|
|
188
|
+
}
|
|
189
|
+
return new Proxy(
|
|
190
|
+
pongoDb,
|
|
191
|
+
{
|
|
192
|
+
get(target, prop) {
|
|
193
|
+
return _nullishCoalesce(collections.get(prop), () => ( target[prop]));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
};
|
|
198
|
+
var proxyClientWithSchema = (client, schema) => {
|
|
199
|
+
if (!schema)
|
|
200
|
+
return client;
|
|
201
|
+
const dbNames = Object.keys(schema.dbs);
|
|
202
|
+
return new Proxy(
|
|
203
|
+
client,
|
|
204
|
+
{
|
|
205
|
+
get(target, prop) {
|
|
206
|
+
if (dbNames.includes(prop)) return client.db(_optionalChain([schema, 'access', _4 => _4.dbs, 'access', _5 => _5[prop], 'optionalAccess', _6 => _6.name]));
|
|
207
|
+
return target[prop];
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
);
|
|
211
|
+
};
|
|
212
|
+
var toDbSchemaMetadata = (schema) => ({
|
|
213
|
+
name: schema.name,
|
|
214
|
+
collections: objectEntries(schema.collections).map((c) => ({
|
|
215
|
+
name: c[1].name
|
|
216
|
+
}))
|
|
217
|
+
});
|
|
218
|
+
var toClientSchemaMetadata = (schema) => {
|
|
219
|
+
const databases = objectEntries(schema.dbs).map(
|
|
220
|
+
(e) => toDbSchemaMetadata(e[1])
|
|
221
|
+
);
|
|
222
|
+
return {
|
|
223
|
+
databases,
|
|
224
|
+
database: (name) => databases.find((db) => db.name === name)
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// src/core/database/pongoDatabaseSchemaComponent.ts
|
|
229
|
+
var PongoDatabaseSchemaComponent = ({
|
|
230
|
+
definition,
|
|
231
|
+
collectionFactory
|
|
232
|
+
}) => {
|
|
233
|
+
const collections = _nullishCoalesce(Object.values(definition.collections).map(collectionFactory), () => ( []));
|
|
234
|
+
return {
|
|
235
|
+
..._dumbo.schemaComponent.call(void 0, `sc:dumbo:database:${definition.name}`, {
|
|
236
|
+
components: collections
|
|
237
|
+
}),
|
|
238
|
+
definition,
|
|
239
|
+
collections,
|
|
240
|
+
collection: (schema) => {
|
|
241
|
+
const existing = collections.find(
|
|
242
|
+
(c) => c.collectionName === schema.name
|
|
243
|
+
);
|
|
244
|
+
if (existing) return existing;
|
|
245
|
+
const newCollection = collectionFactory(
|
|
246
|
+
pongoSchema.collection(schema.name)
|
|
247
|
+
);
|
|
248
|
+
collections.push(newCollection);
|
|
249
|
+
definition.collections[schema.name] = schema;
|
|
250
|
+
return newCollection;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
// src/core/database/pongoDb.ts
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
var PongoDatabase = (options) => {
|
|
260
|
+
const { databaseName, schemaComponent: schemaComponent3, pool } = options;
|
|
261
|
+
const collections = /* @__PURE__ */ new Map();
|
|
262
|
+
const command = async (sql, options2) => (await transactionExecutorOrDefault(db, options2, pool.execute)).command(sql);
|
|
263
|
+
const query = async (sql, options2) => (await transactionExecutorOrDefault(db, options2, pool.execute)).query(
|
|
264
|
+
sql
|
|
265
|
+
);
|
|
266
|
+
const driverType = pool.driverType;
|
|
267
|
+
const db = {
|
|
268
|
+
driverType,
|
|
269
|
+
databaseName,
|
|
270
|
+
connect: () => Promise.resolve(),
|
|
271
|
+
close: () => pool.close(),
|
|
272
|
+
collections: () => [...collections.values()],
|
|
273
|
+
collection: (collectionName) => _nullishCoalesce(collections.get(collectionName), () => ( pongoCollection({
|
|
274
|
+
collectionName,
|
|
275
|
+
db,
|
|
276
|
+
pool,
|
|
277
|
+
schemaComponent: schemaComponent3.collection(
|
|
278
|
+
pongoSchema.collection(collectionName)
|
|
279
|
+
),
|
|
280
|
+
schema: options.schema ? options.schema : {},
|
|
281
|
+
errors: options.errors ? options.errors : {}
|
|
282
|
+
}))),
|
|
283
|
+
transaction: () => pool.transaction(),
|
|
284
|
+
withTransaction: (handle) => pool.withTransaction(handle),
|
|
285
|
+
schema: {
|
|
286
|
+
component: schemaComponent3,
|
|
287
|
+
migrate: () => _dumbo.runSQLMigrations.call(void 0, pool, schemaComponent3.migrations)
|
|
288
|
+
},
|
|
289
|
+
sql: {
|
|
290
|
+
async query(sql, options2) {
|
|
291
|
+
const result = await query(sql, options2);
|
|
292
|
+
return result.rows;
|
|
293
|
+
},
|
|
294
|
+
async command(sql, options2) {
|
|
295
|
+
return command(sql, options2);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
const dbSchema = _optionalChain([options, 'optionalAccess', _7 => _7.schema, 'optionalAccess', _8 => _8.definition]);
|
|
300
|
+
if (dbSchema) {
|
|
301
|
+
return proxyPongoDbWithSchema(db, dbSchema, collections);
|
|
302
|
+
}
|
|
303
|
+
return db;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
// src/core/drivers/databaseDriver.ts
|
|
307
|
+
var PongoDatabaseDriverRegistry = () => {
|
|
308
|
+
const drivers = /* @__PURE__ */ new Map();
|
|
309
|
+
const register = (driverType, driver) => {
|
|
310
|
+
const entry = drivers.get(driverType);
|
|
311
|
+
if (entry && (typeof entry !== "function" || typeof driver === "function")) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
drivers.set(driverType, driver);
|
|
315
|
+
};
|
|
316
|
+
const tryResolve = async (driverType) => {
|
|
317
|
+
const entry = drivers.get(driverType);
|
|
318
|
+
if (!entry) return null;
|
|
319
|
+
if (typeof entry !== "function") return entry;
|
|
320
|
+
const driver = await entry();
|
|
321
|
+
register(driverType, driver);
|
|
322
|
+
return driver;
|
|
323
|
+
};
|
|
324
|
+
const tryGet = (driverType) => {
|
|
325
|
+
const entry = drivers.get(driverType);
|
|
326
|
+
return entry && typeof entry !== "function" ? entry : null;
|
|
327
|
+
};
|
|
328
|
+
const has = (driverType) => drivers.has(driverType);
|
|
329
|
+
return {
|
|
330
|
+
register,
|
|
331
|
+
tryResolve,
|
|
332
|
+
tryGet,
|
|
333
|
+
has,
|
|
334
|
+
get databaseDriverTypes() {
|
|
335
|
+
return Array.from(drivers.keys());
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
var pongoDatabaseDriverRegistry = globalThis.pongoDatabaseDriverRegistry = _nullishCoalesce(globalThis.pongoDatabaseDriverRegistry, () => ( PongoDatabaseDriverRegistry()));
|
|
340
|
+
|
|
341
|
+
// src/core/pongoTransaction.ts
|
|
342
|
+
var pongoTransaction = (options) => {
|
|
343
|
+
let isCommitted = false;
|
|
344
|
+
let isRolledBack = false;
|
|
345
|
+
let databaseName = null;
|
|
346
|
+
let transaction = null;
|
|
347
|
+
return {
|
|
348
|
+
enlistDatabase: async (db) => {
|
|
349
|
+
if (transaction && databaseName !== db.databaseName)
|
|
350
|
+
throw new Error(
|
|
351
|
+
"There's already other database assigned to transaction"
|
|
352
|
+
);
|
|
353
|
+
if (transaction && databaseName === db.databaseName) return transaction;
|
|
354
|
+
databaseName = db.databaseName;
|
|
355
|
+
transaction = db.transaction();
|
|
356
|
+
await transaction.begin();
|
|
357
|
+
return transaction;
|
|
358
|
+
},
|
|
359
|
+
commit: async () => {
|
|
360
|
+
if (!transaction) throw new Error("No database transaction started!");
|
|
361
|
+
if (isCommitted) return;
|
|
362
|
+
if (isRolledBack) throw new Error("Transaction is not active!");
|
|
363
|
+
isCommitted = true;
|
|
364
|
+
await transaction.commit();
|
|
365
|
+
transaction = null;
|
|
366
|
+
},
|
|
367
|
+
rollback: async (error) => {
|
|
368
|
+
if (!transaction) throw new Error("No database transaction started!");
|
|
369
|
+
if (isCommitted) throw new Error("Cannot rollback commited transaction!");
|
|
370
|
+
if (isRolledBack) return;
|
|
371
|
+
isRolledBack = true;
|
|
372
|
+
await transaction.rollback(error);
|
|
373
|
+
transaction = null;
|
|
374
|
+
},
|
|
375
|
+
databaseName,
|
|
376
|
+
isStarting: false,
|
|
377
|
+
isCommitted,
|
|
378
|
+
get isActive() {
|
|
379
|
+
return !isCommitted && !isRolledBack;
|
|
380
|
+
},
|
|
381
|
+
get sqlExecutor() {
|
|
382
|
+
if (transaction === null)
|
|
383
|
+
throw new Error("No database transaction was started");
|
|
384
|
+
return transaction.execute;
|
|
385
|
+
},
|
|
386
|
+
options
|
|
387
|
+
};
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
// src/core/pongoSession.ts
|
|
391
|
+
var isActive = (transaction) => _optionalChain([transaction, 'optionalAccess', _9 => _9.isActive]) === true;
|
|
392
|
+
function assertInActiveTransaction(transaction) {
|
|
393
|
+
if (!isActive(transaction)) throw new Error("No active transaction exists!");
|
|
394
|
+
}
|
|
395
|
+
function assertNotInActiveTransaction(transaction) {
|
|
396
|
+
if (isActive(transaction))
|
|
397
|
+
throw new Error("Active transaction already exists!");
|
|
398
|
+
}
|
|
399
|
+
var pongoSession = (options) => {
|
|
400
|
+
const explicit = _optionalChain([options, 'optionalAccess', _10 => _10.explicit]) === true;
|
|
401
|
+
const defaultTransactionOptions = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _11 => _11.defaultTransactionOptions]), () => ( {
|
|
402
|
+
get snapshotEnabled() {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
}));
|
|
406
|
+
let transaction = null;
|
|
407
|
+
let hasEnded = false;
|
|
408
|
+
const startTransaction = (options2) => {
|
|
409
|
+
assertNotInActiveTransaction(transaction);
|
|
410
|
+
transaction = pongoTransaction(_nullishCoalesce(options2, () => ( defaultTransactionOptions)));
|
|
411
|
+
};
|
|
412
|
+
const commitTransaction = async () => {
|
|
413
|
+
assertInActiveTransaction(transaction);
|
|
414
|
+
await transaction.commit();
|
|
415
|
+
};
|
|
416
|
+
const abortTransaction = async () => {
|
|
417
|
+
assertInActiveTransaction(transaction);
|
|
418
|
+
await transaction.rollback();
|
|
419
|
+
};
|
|
420
|
+
const endSession = async () => {
|
|
421
|
+
if (hasEnded) return;
|
|
422
|
+
hasEnded = true;
|
|
423
|
+
if (isActive(transaction)) await transaction.rollback();
|
|
424
|
+
};
|
|
425
|
+
const session = {
|
|
426
|
+
get hasEnded() {
|
|
427
|
+
return hasEnded;
|
|
428
|
+
},
|
|
429
|
+
explicit,
|
|
430
|
+
defaultTransactionOptions: _nullishCoalesce(defaultTransactionOptions, () => ( {
|
|
431
|
+
get snapshotEnabled() {
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
})),
|
|
435
|
+
get transaction() {
|
|
436
|
+
return transaction;
|
|
437
|
+
},
|
|
438
|
+
get snapshotEnabled() {
|
|
439
|
+
return defaultTransactionOptions.snapshotEnabled;
|
|
440
|
+
},
|
|
441
|
+
endSession,
|
|
442
|
+
incrementTransactionNumber: () => {
|
|
443
|
+
},
|
|
444
|
+
inTransaction: () => isActive(transaction),
|
|
445
|
+
startTransaction,
|
|
446
|
+
commitTransaction,
|
|
447
|
+
abortTransaction,
|
|
448
|
+
withTransaction: async (fn, options2) => {
|
|
449
|
+
startTransaction(options2);
|
|
450
|
+
try {
|
|
451
|
+
const result = await fn(session);
|
|
452
|
+
await commitTransaction();
|
|
453
|
+
return result;
|
|
454
|
+
} catch (error) {
|
|
455
|
+
await abortTransaction();
|
|
456
|
+
throw error;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
return session;
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
// src/core/pongoClient.ts
|
|
464
|
+
var pongoClient = (options) => {
|
|
465
|
+
const { driver, schema, errors, ...connectionOptions } = options;
|
|
466
|
+
const dbClients = PongoDatabaseCache({
|
|
467
|
+
driver,
|
|
468
|
+
typedSchema: _optionalChain([schema, 'optionalAccess', _12 => _12.definition])
|
|
469
|
+
});
|
|
470
|
+
const pongoClient2 = {
|
|
471
|
+
driverType: driver.driverType,
|
|
472
|
+
connect: async () => {
|
|
473
|
+
await dbClients.forAll((db) => db.connect());
|
|
474
|
+
return pongoClient2;
|
|
475
|
+
},
|
|
476
|
+
close: async () => {
|
|
477
|
+
await dbClients.forAll((db) => db.close());
|
|
478
|
+
},
|
|
479
|
+
db: (dbName) => {
|
|
480
|
+
const db = dbClients.getOrCreate({
|
|
481
|
+
...connectionOptions,
|
|
482
|
+
databaseName: dbName,
|
|
483
|
+
errors
|
|
484
|
+
});
|
|
485
|
+
return db;
|
|
486
|
+
},
|
|
487
|
+
startSession: pongoSession,
|
|
488
|
+
withSession: async (callback) => {
|
|
489
|
+
const session = pongoSession();
|
|
490
|
+
try {
|
|
491
|
+
return await callback(session);
|
|
492
|
+
} finally {
|
|
493
|
+
await session.endSession();
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
return proxyClientWithSchema(pongoClient2, _optionalChain([schema, 'optionalAccess', _13 => _13.definition]));
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
// src/core/utils/deepEquals.ts
|
|
501
|
+
var deepEquals = (left, right) => {
|
|
502
|
+
if (isEquatable(left)) {
|
|
503
|
+
return left.equals(right);
|
|
504
|
+
}
|
|
505
|
+
if (Array.isArray(left)) {
|
|
506
|
+
return Array.isArray(right) && left.length === right.length && left.every((val, index) => deepEquals(val, right[index]));
|
|
507
|
+
}
|
|
508
|
+
if (typeof left !== "object" || typeof right !== "object" || left === null || right === null) {
|
|
509
|
+
return left === right;
|
|
510
|
+
}
|
|
511
|
+
if (Array.isArray(right)) return false;
|
|
512
|
+
const keys1 = Object.keys(left);
|
|
513
|
+
const keys2 = Object.keys(right);
|
|
514
|
+
if (keys1.length !== keys2.length || !keys1.every((key) => keys2.includes(key)))
|
|
515
|
+
return false;
|
|
516
|
+
for (const key in left) {
|
|
517
|
+
if (left[key] instanceof Function && right[key] instanceof Function)
|
|
518
|
+
continue;
|
|
519
|
+
const isEqual = deepEquals(left[key], right[key]);
|
|
520
|
+
if (!isEqual) {
|
|
521
|
+
return false;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
return true;
|
|
525
|
+
};
|
|
526
|
+
var isEquatable = (left) => {
|
|
527
|
+
return left && typeof left === "object" && "equals" in left && typeof left["equals"] === "function";
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
// src/core/collection/pongoCollection.ts
|
|
531
|
+
var enlistIntoTransactionIfActive = async (db, options) => {
|
|
532
|
+
const transaction = _optionalChain([options, 'optionalAccess', _14 => _14.session, 'optionalAccess', _15 => _15.transaction]);
|
|
533
|
+
if (!transaction || !transaction.isActive) return null;
|
|
534
|
+
return await transaction.enlistDatabase(db);
|
|
535
|
+
};
|
|
536
|
+
var transactionExecutorOrDefault = async (db, options, defaultSqlExecutor) => {
|
|
537
|
+
const existingTransaction = await enlistIntoTransactionIfActive(db, options);
|
|
538
|
+
return _nullishCoalesce(_optionalChain([existingTransaction, 'optionalAccess', _16 => _16.execute]), () => ( defaultSqlExecutor));
|
|
539
|
+
};
|
|
540
|
+
var columnMapping = {
|
|
541
|
+
mapping: {
|
|
542
|
+
..._dumbo.mapColumnToJSON.call(void 0, "data")
|
|
543
|
+
//...mapColumnToJSON('metadata'),
|
|
544
|
+
//...mapColumnToBigint('_version'),
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
var pongoCollection = ({
|
|
548
|
+
db,
|
|
549
|
+
collectionName,
|
|
550
|
+
pool,
|
|
551
|
+
schemaComponent: schemaComponent3,
|
|
552
|
+
schema,
|
|
553
|
+
errors
|
|
554
|
+
}) => {
|
|
555
|
+
const SqlFor = schemaComponent3.sqlBuilder;
|
|
556
|
+
const sqlExecutor = pool.execute;
|
|
557
|
+
const command = async (sql, options) => (await transactionExecutorOrDefault(db, options, sqlExecutor)).command(sql);
|
|
558
|
+
const query = async (sql, options) => (await transactionExecutorOrDefault(db, options, sqlExecutor)).query(
|
|
559
|
+
sql,
|
|
560
|
+
columnMapping
|
|
561
|
+
);
|
|
562
|
+
let shouldMigrate = _optionalChain([schema, 'optionalAccess', _17 => _17.autoMigration]) !== "None";
|
|
563
|
+
const createCollection = (options) => {
|
|
564
|
+
shouldMigrate = false;
|
|
565
|
+
if (_optionalChain([options, 'optionalAccess', _18 => _18.session])) return command(SqlFor.createCollection(), options);
|
|
566
|
+
else return command(SqlFor.createCollection());
|
|
567
|
+
};
|
|
568
|
+
const ensureCollectionCreated = (options) => {
|
|
569
|
+
if (!shouldMigrate) {
|
|
570
|
+
return Promise.resolve();
|
|
571
|
+
}
|
|
572
|
+
return createCollection(options);
|
|
573
|
+
};
|
|
574
|
+
const collection = {
|
|
575
|
+
dbName: db.databaseName,
|
|
576
|
+
collectionName,
|
|
577
|
+
createCollection: async (options) => {
|
|
578
|
+
await createCollection(options);
|
|
579
|
+
},
|
|
580
|
+
insertOne: async (document, options) => {
|
|
581
|
+
await ensureCollectionCreated(options);
|
|
582
|
+
const _id = _nullishCoalesce(document._id, () => ( _uuid.v7.call(void 0, )));
|
|
583
|
+
const _version = _nullishCoalesce(document._version, () => ( 1n));
|
|
584
|
+
const result = await command(
|
|
585
|
+
SqlFor.insertOne({
|
|
586
|
+
...document,
|
|
587
|
+
_id,
|
|
588
|
+
_version
|
|
589
|
+
}),
|
|
590
|
+
options
|
|
591
|
+
);
|
|
592
|
+
const successful = (_nullishCoalesce(result.rowCount, () => ( 0))) > 0;
|
|
593
|
+
return operationResult(
|
|
594
|
+
{
|
|
595
|
+
successful,
|
|
596
|
+
insertedId: successful ? _id : null,
|
|
597
|
+
nextExpectedVersion: _version
|
|
598
|
+
},
|
|
599
|
+
{ operationName: "insertOne", collectionName, errors }
|
|
600
|
+
);
|
|
601
|
+
},
|
|
602
|
+
insertMany: async (documents, options) => {
|
|
603
|
+
await ensureCollectionCreated(options);
|
|
604
|
+
const rows = documents.map((doc) => ({
|
|
605
|
+
...doc,
|
|
606
|
+
_id: _nullishCoalesce(doc._id, () => ( _uuid.v7.call(void 0, ))),
|
|
607
|
+
_version: _nullishCoalesce(doc._version, () => ( 1n))
|
|
608
|
+
}));
|
|
609
|
+
const result = await command(
|
|
610
|
+
SqlFor.insertMany(rows),
|
|
611
|
+
options
|
|
612
|
+
);
|
|
613
|
+
return operationResult(
|
|
614
|
+
{
|
|
615
|
+
successful: result.rowCount === rows.length,
|
|
616
|
+
insertedCount: _nullishCoalesce(result.rowCount, () => ( 0)),
|
|
617
|
+
insertedIds: result.rows.map((d) => d._id)
|
|
618
|
+
},
|
|
619
|
+
{ operationName: "insertMany", collectionName, errors }
|
|
620
|
+
);
|
|
621
|
+
},
|
|
622
|
+
updateOne: async (filter, update, options) => {
|
|
623
|
+
await ensureCollectionCreated(options);
|
|
624
|
+
const result = await command(
|
|
625
|
+
SqlFor.updateOne(filter, update, options),
|
|
626
|
+
options
|
|
627
|
+
);
|
|
628
|
+
return operationResult(
|
|
629
|
+
{
|
|
630
|
+
successful: result.rows.length > 0 && result.rows[0].modified === result.rows[0].matched,
|
|
631
|
+
modifiedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _19 => _19.rows, 'access', _20 => _20[0], 'optionalAccess', _21 => _21.modified]), () => ( 0))),
|
|
632
|
+
matchedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _22 => _22.rows, 'access', _23 => _23[0], 'optionalAccess', _24 => _24.matched]), () => ( 0))),
|
|
633
|
+
nextExpectedVersion: BigInt(_nullishCoalesce(_optionalChain([result, 'access', _25 => _25.rows, 'access', _26 => _26[0], 'optionalAccess', _27 => _27.version]), () => ( 0n)))
|
|
634
|
+
},
|
|
635
|
+
{ operationName: "updateOne", collectionName, errors }
|
|
636
|
+
);
|
|
637
|
+
},
|
|
638
|
+
replaceOne: async (filter, document, options) => {
|
|
639
|
+
await ensureCollectionCreated(options);
|
|
640
|
+
const result = await command(
|
|
641
|
+
SqlFor.replaceOne(filter, document, options),
|
|
642
|
+
options
|
|
643
|
+
);
|
|
644
|
+
return operationResult(
|
|
645
|
+
{
|
|
646
|
+
successful: result.rows.length > 0 && result.rows[0].modified > 0,
|
|
647
|
+
modifiedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _28 => _28.rows, 'access', _29 => _29[0], 'optionalAccess', _30 => _30.modified]), () => ( 0))),
|
|
648
|
+
matchedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _31 => _31.rows, 'access', _32 => _32[0], 'optionalAccess', _33 => _33.matched]), () => ( 0))),
|
|
649
|
+
nextExpectedVersion: BigInt(_nullishCoalesce(_optionalChain([result, 'access', _34 => _34.rows, 'access', _35 => _35[0], 'optionalAccess', _36 => _36.version]), () => ( 0n)))
|
|
650
|
+
},
|
|
651
|
+
{ operationName: "replaceOne", collectionName, errors }
|
|
652
|
+
);
|
|
653
|
+
},
|
|
654
|
+
updateMany: async (filter, update, options) => {
|
|
655
|
+
await ensureCollectionCreated(options);
|
|
656
|
+
const result = await command(SqlFor.updateMany(filter, update), options);
|
|
657
|
+
return operationResult(
|
|
658
|
+
{
|
|
659
|
+
successful: true,
|
|
660
|
+
modifiedCount: _nullishCoalesce(result.rowCount, () => ( 0)),
|
|
661
|
+
matchedCount: _nullishCoalesce(result.rowCount, () => ( 0))
|
|
662
|
+
},
|
|
663
|
+
{ operationName: "updateMany", collectionName, errors }
|
|
664
|
+
);
|
|
665
|
+
},
|
|
666
|
+
deleteOne: async (filter, options) => {
|
|
667
|
+
await ensureCollectionCreated(options);
|
|
668
|
+
const result = await command(
|
|
669
|
+
SqlFor.deleteOne(_nullishCoalesce(filter, () => ( {})), options),
|
|
670
|
+
options
|
|
671
|
+
);
|
|
672
|
+
return operationResult(
|
|
673
|
+
{
|
|
674
|
+
successful: result.rows.length > 0 && result.rows[0].deleted > 0,
|
|
675
|
+
deletedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _37 => _37.rows, 'access', _38 => _38[0], 'optionalAccess', _39 => _39.deleted]), () => ( 0))),
|
|
676
|
+
matchedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _40 => _40.rows, 'access', _41 => _41[0], 'optionalAccess', _42 => _42.matched]), () => ( 0)))
|
|
677
|
+
},
|
|
678
|
+
{ operationName: "deleteOne", collectionName, errors }
|
|
679
|
+
);
|
|
680
|
+
},
|
|
681
|
+
deleteMany: async (filter, options) => {
|
|
682
|
+
await ensureCollectionCreated(options);
|
|
683
|
+
const result = await command(SqlFor.deleteMany(_nullishCoalesce(filter, () => ( {}))), options);
|
|
684
|
+
return operationResult(
|
|
685
|
+
{
|
|
686
|
+
successful: (_nullishCoalesce(result.rowCount, () => ( 0))) > 0,
|
|
687
|
+
deletedCount: _nullishCoalesce(result.rowCount, () => ( 0)),
|
|
688
|
+
matchedCount: _nullishCoalesce(result.rowCount, () => ( 0))
|
|
689
|
+
},
|
|
690
|
+
{ operationName: "deleteMany", collectionName, errors }
|
|
691
|
+
);
|
|
692
|
+
},
|
|
693
|
+
findOne: async (filter, options) => {
|
|
694
|
+
await ensureCollectionCreated(options);
|
|
695
|
+
const result = await query(SqlFor.findOne(_nullishCoalesce(filter, () => ( {}))), options);
|
|
696
|
+
return _nullishCoalesce(_optionalChain([result, 'access', _43 => _43.rows, 'access', _44 => _44[0], 'optionalAccess', _45 => _45.data]), () => ( null));
|
|
697
|
+
},
|
|
698
|
+
findOneAndDelete: async (filter, options) => {
|
|
699
|
+
await ensureCollectionCreated(options);
|
|
700
|
+
const existingDoc = await collection.findOne(filter, options);
|
|
701
|
+
if (existingDoc === null) return null;
|
|
702
|
+
await collection.deleteOne(filter, options);
|
|
703
|
+
return existingDoc;
|
|
704
|
+
},
|
|
705
|
+
findOneAndReplace: async (filter, replacement, options) => {
|
|
706
|
+
await ensureCollectionCreated(options);
|
|
707
|
+
const existingDoc = await collection.findOne(filter, options);
|
|
708
|
+
if (existingDoc === null) return null;
|
|
709
|
+
await collection.replaceOne(filter, replacement, options);
|
|
710
|
+
return existingDoc;
|
|
711
|
+
},
|
|
712
|
+
findOneAndUpdate: async (filter, update, options) => {
|
|
713
|
+
await ensureCollectionCreated(options);
|
|
714
|
+
const existingDoc = await collection.findOne(filter, options);
|
|
715
|
+
if (existingDoc === null) return null;
|
|
716
|
+
await collection.updateOne(filter, update, options);
|
|
717
|
+
return existingDoc;
|
|
718
|
+
},
|
|
719
|
+
handle: async (id, handle, options) => {
|
|
720
|
+
const { expectedVersion: version, ...operationOptions } = _nullishCoalesce(options, () => ( {}));
|
|
721
|
+
await ensureCollectionCreated(options);
|
|
722
|
+
const byId = { _id: id };
|
|
723
|
+
const existing = await collection.findOne(
|
|
724
|
+
byId,
|
|
725
|
+
options
|
|
726
|
+
);
|
|
727
|
+
const expectedVersion2 = expectedVersionValue(version);
|
|
728
|
+
if (existing == null && version === "DOCUMENT_EXISTS" || existing == null && expectedVersion2 != null || existing != null && version === "DOCUMENT_DOES_NOT_EXIST" || existing != null && expectedVersion2 !== null && existing._version !== expectedVersion2) {
|
|
729
|
+
return operationResult(
|
|
730
|
+
{
|
|
731
|
+
successful: false,
|
|
732
|
+
document: existing
|
|
733
|
+
},
|
|
734
|
+
{ operationName: "handle", collectionName, errors }
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
const result = await handle(
|
|
738
|
+
existing !== null ? { ...existing } : null
|
|
739
|
+
);
|
|
740
|
+
if (deepEquals(existing, result))
|
|
741
|
+
return operationResult(
|
|
742
|
+
{
|
|
743
|
+
successful: true,
|
|
744
|
+
document: existing
|
|
745
|
+
},
|
|
746
|
+
{ operationName: "handle", collectionName, errors }
|
|
747
|
+
);
|
|
748
|
+
if (!existing && result) {
|
|
749
|
+
const newDoc = { ...result, _id: id };
|
|
750
|
+
const insertResult = await collection.insertOne(
|
|
751
|
+
{ ...newDoc, _id: id },
|
|
752
|
+
{
|
|
753
|
+
...operationOptions,
|
|
754
|
+
expectedVersion: "DOCUMENT_DOES_NOT_EXIST"
|
|
755
|
+
}
|
|
756
|
+
);
|
|
757
|
+
return {
|
|
758
|
+
...insertResult,
|
|
759
|
+
document: {
|
|
760
|
+
...newDoc,
|
|
761
|
+
_version: insertResult.nextExpectedVersion
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
if (existing && !result) {
|
|
766
|
+
const deleteResult = await collection.deleteOne(byId, {
|
|
767
|
+
...operationOptions,
|
|
768
|
+
expectedVersion: _nullishCoalesce(expectedVersion2, () => ( "DOCUMENT_EXISTS"))
|
|
769
|
+
});
|
|
770
|
+
return { ...deleteResult, document: null };
|
|
771
|
+
}
|
|
772
|
+
if (existing && result) {
|
|
773
|
+
const replaceResult = await collection.replaceOne(byId, result, {
|
|
774
|
+
...operationOptions,
|
|
775
|
+
expectedVersion: _nullishCoalesce(expectedVersion2, () => ( "DOCUMENT_EXISTS"))
|
|
776
|
+
});
|
|
777
|
+
return {
|
|
778
|
+
...replaceResult,
|
|
779
|
+
document: {
|
|
780
|
+
...result,
|
|
781
|
+
_version: replaceResult.nextExpectedVersion
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
return operationResult(
|
|
786
|
+
{
|
|
787
|
+
successful: true,
|
|
788
|
+
document: existing
|
|
789
|
+
},
|
|
790
|
+
{ operationName: "handle", collectionName, errors }
|
|
791
|
+
);
|
|
792
|
+
},
|
|
793
|
+
find: async (filter, options) => {
|
|
794
|
+
await ensureCollectionCreated(options);
|
|
795
|
+
const result = await query(SqlFor.find(_nullishCoalesce(filter, () => ( {})), options));
|
|
796
|
+
return result.rows.map((row) => row.data);
|
|
797
|
+
},
|
|
798
|
+
countDocuments: async (filter, options) => {
|
|
799
|
+
await ensureCollectionCreated(options);
|
|
800
|
+
const { count } = await _dumbo.single.call(void 0,
|
|
801
|
+
query(SqlFor.countDocuments(_nullishCoalesce(filter, () => ( {}))))
|
|
802
|
+
);
|
|
803
|
+
return count;
|
|
804
|
+
},
|
|
805
|
+
drop: async (options) => {
|
|
806
|
+
await ensureCollectionCreated(options);
|
|
807
|
+
const result = await command(SqlFor.drop());
|
|
808
|
+
return (_nullishCoalesce(_optionalChain([result, 'optionalAccess', _46 => _46.rowCount]), () => ( 0))) > 0;
|
|
809
|
+
},
|
|
810
|
+
rename: async (newName, options) => {
|
|
811
|
+
await ensureCollectionCreated(options);
|
|
812
|
+
await command(SqlFor.rename(newName));
|
|
813
|
+
collectionName = newName;
|
|
814
|
+
return collection;
|
|
815
|
+
},
|
|
816
|
+
sql: {
|
|
817
|
+
async query(sql, options) {
|
|
818
|
+
await ensureCollectionCreated(options);
|
|
819
|
+
const result = await query(sql, options);
|
|
820
|
+
return result.rows;
|
|
821
|
+
},
|
|
822
|
+
async command(sql, options) {
|
|
823
|
+
await ensureCollectionCreated(options);
|
|
824
|
+
return command(sql, options);
|
|
825
|
+
}
|
|
826
|
+
},
|
|
827
|
+
schema: {
|
|
828
|
+
component: schemaComponent3,
|
|
829
|
+
migrate: () => _dumbo.runSQLMigrations.call(void 0, pool, schemaComponent3.migrations)
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
return collection;
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
exports.transactionExecutorOrDefault = transactionExecutorOrDefault; exports.pongoCollection = pongoCollection; exports.PongoCollectionSchemaComponent = PongoCollectionSchemaComponent; exports.QueryOperators = QueryOperators; exports.OperatorMap = OperatorMap; exports.isOperator = isOperator; exports.hasOperators = hasOperators; exports.PongoDatabaseCache = PongoDatabaseCache; exports.objectEntries = objectEntries; exports.isNumber = isNumber; exports.isString = isString; exports.PongoError = PongoError; exports.ConcurrencyError = ConcurrencyError; exports.ObjectId = ObjectId; exports.DOCUMENT_EXISTS = DOCUMENT_EXISTS; exports.DOCUMENT_DOES_NOT_EXIST = DOCUMENT_DOES_NOT_EXIST; exports.NO_CONCURRENCY_CHECK = NO_CONCURRENCY_CHECK; exports.isGeneralExpectedDocumentVersion = isGeneralExpectedDocumentVersion; exports.expectedVersionValue = expectedVersionValue; exports.expectedVersion = expectedVersion; exports.operationResult = operationResult; exports.pongoSchema = pongoSchema; exports.proxyPongoDbWithSchema = proxyPongoDbWithSchema; exports.proxyClientWithSchema = proxyClientWithSchema; exports.toDbSchemaMetadata = toDbSchemaMetadata; exports.toClientSchemaMetadata = toClientSchemaMetadata; exports.PongoDatabaseSchemaComponent = PongoDatabaseSchemaComponent; exports.PongoDatabase = PongoDatabase; exports.PongoDatabaseDriverRegistry = PongoDatabaseDriverRegistry; exports.pongoDatabaseDriverRegistry = pongoDatabaseDriverRegistry; exports.pongoTransaction = pongoTransaction; exports.pongoSession = pongoSession; exports.pongoClient = pongoClient; exports.deepEquals = deepEquals; exports.isEquatable = isEquatable;
|
|
872
|
+
//# sourceMappingURL=chunk-4BL6YWLW.cjs.map
|