@event-driven-io/dumbo 0.13.0-beta.45 → 0.13.0-beta.47
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.cjs +432 -69
- package/dist/cloudflare.cjs.map +1 -1
- package/dist/cloudflare.d.cts +2 -2
- package/dist/cloudflare.d.ts +2 -2
- package/dist/cloudflare.js +432 -69
- package/dist/cloudflare.js.map +1 -1
- package/dist/{index-B5krjjrh.d.ts → index-4hcCG4SA.d.ts} +66 -30
- package/dist/{index-BaLXbc2l.d.ts → index-B7366zWR.d.ts} +1 -1
- package/dist/{index-_dj3upBo.d.cts → index-BJ-dm7dG.d.cts} +66 -30
- package/dist/{index-kYttgYkC.d.cts → index-BkJ1pipM.d.cts} +1 -1
- package/dist/{index-C9B46a1u.d.ts → index-CQokD3za.d.cts} +2 -2
- package/dist/{index-BoLWBnxd.d.cts → index-DIJv-L6M.d.ts} +2 -2
- package/dist/index.cjs +523 -269
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +522 -270
- package/dist/index.js.map +1 -1
- package/dist/pg.cjs +168 -28
- package/dist/pg.cjs.map +1 -1
- package/dist/pg.d.cts +2 -2
- package/dist/pg.d.ts +2 -2
- package/dist/pg.js +168 -28
- package/dist/pg.js.map +1 -1
- package/dist/postgresql.cjs +4 -0
- package/dist/postgresql.cjs.map +1 -1
- package/dist/postgresql.d.cts +2 -2
- package/dist/postgresql.d.ts +2 -2
- package/dist/postgresql.js +4 -0
- package/dist/postgresql.js.map +1 -1
- package/dist/sqlite.cjs +429 -68
- package/dist/sqlite.cjs.map +1 -1
- package/dist/sqlite.d.cts +2 -2
- package/dist/sqlite.d.ts +2 -2
- package/dist/sqlite.js +429 -68
- package/dist/sqlite.js.map +1 -1
- package/dist/sqlite3.cjs +639 -343
- package/dist/sqlite3.cjs.map +1 -1
- package/dist/sqlite3.d.cts +10 -10
- package/dist/sqlite3.d.ts +10 -10
- package/dist/sqlite3.js +639 -343
- package/dist/sqlite3.js.map +1 -1
- package/package.json +1 -1
package/dist/pg.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as DatabaseTransaction,
|
|
2
|
-
import { S as parseDatabaseName, _ as releaseAdvisoryLock, a as PostgreSQLExpandSQLInProcessor, b as PostgreSQLConnectionString, c as defaultPostgreSqlDatabase, d as tableExists, f as tableExistsSQL, g as advisoryLock, h as acquireAdvisoryLock, i as PostgreSQLArrayProcessor, l as functionExists, m as AdvisoryLock, n as PostgreSQLDriverType, o as PostgreSQLJSON, p as DefaultPostgreSQLMigratorOptions, r as postgreSQLColumnProcessors, s as pgFormatter, t as PostgreSQLDatabaseName, u as functionExistsSQL, v as tryAcquireAdvisoryLock, x as defaultPostgreSQLConnectionString, y as mapPostgresError } from "./index-
|
|
1
|
+
import { $ as DatabaseTransaction, Ct as DumboDatabaseDriver, Fo as JSONSerializationOptions, Lo as JSONSerializer, N as AnyConnection, P as Connection, et as DatabaseTransactionOptions, r as postgreSQLMetadata, tn as DbSQLExecutor, y as ConnectionPool } from "./index-BJ-dm7dG.cjs";
|
|
2
|
+
import { S as parseDatabaseName, _ as releaseAdvisoryLock, a as PostgreSQLExpandSQLInProcessor, b as PostgreSQLConnectionString, c as defaultPostgreSqlDatabase, d as tableExists, f as tableExistsSQL, g as advisoryLock, h as acquireAdvisoryLock, i as PostgreSQLArrayProcessor, l as functionExists, m as AdvisoryLock, n as PostgreSQLDriverType, o as PostgreSQLJSON, p as DefaultPostgreSQLMigratorOptions, r as postgreSQLColumnProcessors, s as pgFormatter, t as PostgreSQLDatabaseName, u as functionExistsSQL, v as tryAcquireAdvisoryLock, x as defaultPostgreSQLConnectionString, y as mapPostgresError } from "./index-BkJ1pipM.cjs";
|
|
3
3
|
import pg from "pg";
|
|
4
4
|
|
|
5
5
|
//#region src/storage/postgresql/pg/connections/transaction.d.ts
|
package/dist/pg.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as DatabaseTransaction,
|
|
2
|
-
import { S as parseDatabaseName, _ as releaseAdvisoryLock, a as PostgreSQLExpandSQLInProcessor, b as PostgreSQLConnectionString, c as defaultPostgreSqlDatabase, d as tableExists, f as tableExistsSQL, g as advisoryLock, h as acquireAdvisoryLock, i as PostgreSQLArrayProcessor, l as functionExists, m as AdvisoryLock, n as PostgreSQLDriverType, o as PostgreSQLJSON, p as DefaultPostgreSQLMigratorOptions, r as postgreSQLColumnProcessors, s as pgFormatter, t as PostgreSQLDatabaseName, u as functionExistsSQL, v as tryAcquireAdvisoryLock, x as defaultPostgreSQLConnectionString, y as mapPostgresError } from "./index-
|
|
1
|
+
import { $ as DatabaseTransaction, Ct as DumboDatabaseDriver, Fo as JSONSerializationOptions, Lo as JSONSerializer, N as AnyConnection, P as Connection, et as DatabaseTransactionOptions, r as postgreSQLMetadata, tn as DbSQLExecutor, y as ConnectionPool } from "./index-4hcCG4SA.js";
|
|
2
|
+
import { S as parseDatabaseName, _ as releaseAdvisoryLock, a as PostgreSQLExpandSQLInProcessor, b as PostgreSQLConnectionString, c as defaultPostgreSqlDatabase, d as tableExists, f as tableExistsSQL, g as advisoryLock, h as acquireAdvisoryLock, i as PostgreSQLArrayProcessor, l as functionExists, m as AdvisoryLock, n as PostgreSQLDriverType, o as PostgreSQLJSON, p as DefaultPostgreSQLMigratorOptions, r as postgreSQLColumnProcessors, s as pgFormatter, t as PostgreSQLDatabaseName, u as functionExistsSQL, v as tryAcquireAdvisoryLock, x as defaultPostgreSQLConnectionString, y as mapPostgresError } from "./index-B7366zWR.js";
|
|
3
3
|
import pg from "pg";
|
|
4
4
|
|
|
5
5
|
//#region src/storage/postgresql/pg/connections/transaction.d.ts
|
package/dist/pg.js
CHANGED
|
@@ -290,6 +290,91 @@ const mapPostgresError = (error) => {
|
|
|
290
290
|
});
|
|
291
291
|
};
|
|
292
292
|
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region src/core/taskProcessing/abort.ts
|
|
295
|
+
const never = { signal: new AbortController().signal };
|
|
296
|
+
const from = (options) => options?.abort ?? never;
|
|
297
|
+
const getSignal = (abort) => "signal" in abort ? abort.signal : abort;
|
|
298
|
+
const reason = (abort) => {
|
|
299
|
+
const signal = getSignal(abort);
|
|
300
|
+
return signal.reason instanceof Error ? signal.reason : new DumboError(typeof signal.reason === "string" ? signal.reason : "Operation aborted");
|
|
301
|
+
};
|
|
302
|
+
const scope = (parent, onAbort) => {
|
|
303
|
+
const controller = new AbortController();
|
|
304
|
+
return {
|
|
305
|
+
abort: (reason) => controller.abort(reason),
|
|
306
|
+
dispose: onAbortSignal(parent, (reason) => {
|
|
307
|
+
controller.abort(reason);
|
|
308
|
+
onAbort?.(reason);
|
|
309
|
+
}),
|
|
310
|
+
signal: controller.signal
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
const execute = (operation, options) => {
|
|
314
|
+
const abort = options?.abort;
|
|
315
|
+
if (!abort) return operation();
|
|
316
|
+
const signal = abort.signal;
|
|
317
|
+
if (signal.aborted) return Promise.reject(reason(abort));
|
|
318
|
+
return new Promise((resolve, reject) => {
|
|
319
|
+
let finished = false;
|
|
320
|
+
const rejectOnAbort = () => {
|
|
321
|
+
if (finished) return;
|
|
322
|
+
finished = true;
|
|
323
|
+
reject(reason(abort));
|
|
324
|
+
};
|
|
325
|
+
signal.addEventListener("abort", rejectOnAbort, { once: true });
|
|
326
|
+
let operationPromise;
|
|
327
|
+
try {
|
|
328
|
+
operationPromise = operation();
|
|
329
|
+
} catch (error) {
|
|
330
|
+
finished = true;
|
|
331
|
+
signal.removeEventListener("abort", rejectOnAbort);
|
|
332
|
+
reject(error);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
operationPromise.then((result) => {
|
|
336
|
+
if (finished) return;
|
|
337
|
+
finished = true;
|
|
338
|
+
signal.removeEventListener("abort", rejectOnAbort);
|
|
339
|
+
resolve(result);
|
|
340
|
+
}).catch((error) => {
|
|
341
|
+
if (finished) return;
|
|
342
|
+
finished = true;
|
|
343
|
+
signal.removeEventListener("abort", rejectOnAbort);
|
|
344
|
+
reject(error);
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
};
|
|
348
|
+
const throwIfAborted = (options) => {
|
|
349
|
+
const abort = options?.abort;
|
|
350
|
+
if (abort?.signal.aborted) throw reason(abort);
|
|
351
|
+
};
|
|
352
|
+
const rejectIfAborted = (options) => {
|
|
353
|
+
const abort = options?.abort;
|
|
354
|
+
return abort?.signal.aborted ? Promise.reject(reason(abort)) : void 0;
|
|
355
|
+
};
|
|
356
|
+
const onAbortSignal = (abort, handle) => {
|
|
357
|
+
if (!abort) return () => {};
|
|
358
|
+
const signal = abort.signal;
|
|
359
|
+
if (signal.aborted) {
|
|
360
|
+
handle(reason(abort));
|
|
361
|
+
return () => {};
|
|
362
|
+
}
|
|
363
|
+
const abortListener = () => handle(reason(abort));
|
|
364
|
+
signal.addEventListener("abort", abortListener, { once: true });
|
|
365
|
+
return () => signal.removeEventListener("abort", abortListener);
|
|
366
|
+
};
|
|
367
|
+
const Abort = {
|
|
368
|
+
execute,
|
|
369
|
+
from,
|
|
370
|
+
never,
|
|
371
|
+
onAbort: onAbortSignal,
|
|
372
|
+
reason,
|
|
373
|
+
rejectIfAborted,
|
|
374
|
+
scope,
|
|
375
|
+
throwIfAborted
|
|
376
|
+
};
|
|
377
|
+
|
|
293
378
|
//#endregion
|
|
294
379
|
//#region src/core/execute/execute.ts
|
|
295
380
|
const mapSQLQueryResult = (result, mapping) => {
|
|
@@ -314,20 +399,45 @@ var BatchCommandNoChangesError = class BatchCommandNoChangesError extends DumboE
|
|
|
314
399
|
}
|
|
315
400
|
};
|
|
316
401
|
const sqlExecutor = (sqlExecutor, options) => ({
|
|
317
|
-
query: (sql, queryOptions) => executeInNewDbClient((client) => sqlExecutor.query(client, sql, queryOptions),
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
402
|
+
query: (sql, queryOptions) => executeInNewDbClient((client) => sqlExecutor.query(client, sql, queryOptions), {
|
|
403
|
+
...options,
|
|
404
|
+
...queryOptions
|
|
405
|
+
}),
|
|
406
|
+
batchQuery: (sqls, queryOptions) => executeInNewDbClient((client) => sqlExecutor.batchQuery(client, sqls, queryOptions), {
|
|
407
|
+
...options,
|
|
408
|
+
...queryOptions
|
|
409
|
+
}),
|
|
410
|
+
command: (sql, commandOptions) => executeInNewDbClient((client) => sqlExecutor.command(client, sql, commandOptions), {
|
|
411
|
+
...options,
|
|
412
|
+
...commandOptions
|
|
413
|
+
}),
|
|
414
|
+
batchCommand: (sqls, commandOptions) => executeInNewDbClient((client) => sqlExecutor.batchCommand(client, sqls, commandOptions), {
|
|
415
|
+
...options,
|
|
416
|
+
...commandOptions
|
|
417
|
+
})
|
|
321
418
|
});
|
|
322
419
|
const sqlExecutorInNewConnection = (options) => ({
|
|
323
|
-
query: (sql, queryOptions) => executeInNewConnection((connection) => connection.execute.query(sql, queryOptions),
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
420
|
+
query: (sql, queryOptions) => executeInNewConnection((connection) => connection.execute.query(sql, queryOptions), {
|
|
421
|
+
...options,
|
|
422
|
+
...queryOptions
|
|
423
|
+
}),
|
|
424
|
+
batchQuery: (sqls, queryOptions) => executeInNewConnection((connection) => connection.execute.batchQuery(sqls, queryOptions), {
|
|
425
|
+
...options,
|
|
426
|
+
...queryOptions
|
|
427
|
+
}),
|
|
428
|
+
command: (sql, commandOptions) => executeInNewConnection((connection) => connection.execute.command(sql, commandOptions), {
|
|
429
|
+
...options,
|
|
430
|
+
...commandOptions
|
|
431
|
+
}),
|
|
432
|
+
batchCommand: (sqls, commandOptions) => executeInNewConnection((connection) => connection.execute.batchCommand(sqls, commandOptions), {
|
|
433
|
+
...options,
|
|
434
|
+
...commandOptions
|
|
435
|
+
})
|
|
327
436
|
});
|
|
328
437
|
const executeInNewDbClient = async (handle, options) => {
|
|
438
|
+
Abort.throwIfAborted(options);
|
|
329
439
|
const { connect, close } = options;
|
|
330
|
-
const client = await connect();
|
|
440
|
+
const client = await connect({ abort: Abort.from(options) });
|
|
331
441
|
try {
|
|
332
442
|
return await handle(client);
|
|
333
443
|
} catch (error) {
|
|
@@ -336,7 +446,8 @@ const executeInNewDbClient = async (handle, options) => {
|
|
|
336
446
|
}
|
|
337
447
|
};
|
|
338
448
|
const executeInNewConnection = async (handle, options) => {
|
|
339
|
-
|
|
449
|
+
Abort.throwIfAborted(options);
|
|
450
|
+
const connection = await options.connection({ abort: Abort.from(options) });
|
|
340
451
|
try {
|
|
341
452
|
return await handle(connection);
|
|
342
453
|
} finally {
|
|
@@ -409,10 +520,10 @@ const toTransactionResult = (transactionResult) => transactionResult !== void 0
|
|
|
409
520
|
success: true,
|
|
410
521
|
result: transactionResult
|
|
411
522
|
};
|
|
412
|
-
const executeInTransaction = async (transaction, handle) => {
|
|
523
|
+
const executeInTransaction = async (transaction, handle, context = { abort: Abort.never }) => {
|
|
413
524
|
await transaction.begin();
|
|
414
525
|
try {
|
|
415
|
-
const { success, result } = toTransactionResult(await handle(transaction));
|
|
526
|
+
const { success, result } = toTransactionResult(await handle(transaction, context));
|
|
416
527
|
if (success) await transaction.commit();
|
|
417
528
|
else await transaction.rollback();
|
|
418
529
|
return result;
|
|
@@ -421,18 +532,32 @@ const executeInTransaction = async (transaction, handle) => {
|
|
|
421
532
|
throw e;
|
|
422
533
|
}
|
|
423
534
|
};
|
|
535
|
+
const executeInNestedTransaction = async (transaction, handle, options, context) => {
|
|
536
|
+
Abort.throwIfAborted(options);
|
|
537
|
+
if (!(options?.allowNestedTransactions ?? transaction._transactionOptions.allowNestedTransactions ?? false)) throw new InvalidOperationError("Cannot start a nested transaction: allowNestedTransactions is false. Set transactionOptions: { allowNestedTransactions: true } on your pool or connection.");
|
|
538
|
+
return executeInTransaction(transaction, handle, context);
|
|
539
|
+
};
|
|
424
540
|
const transactionFactoryWithDbClient = (connect, initTransaction) => {
|
|
425
541
|
let currentTransaction = void 0;
|
|
426
|
-
const getOrInitCurrentTransaction = (options) =>
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
542
|
+
const getOrInitCurrentTransaction = (options) => {
|
|
543
|
+
Abort.throwIfAborted(options);
|
|
544
|
+
if (currentTransaction) return currentTransaction;
|
|
545
|
+
currentTransaction = initTransaction(connect({ abort: Abort.from(options) }), {
|
|
546
|
+
close: () => {
|
|
547
|
+
currentTransaction = void 0;
|
|
548
|
+
return Promise.resolve();
|
|
549
|
+
},
|
|
550
|
+
...options ?? {}
|
|
551
|
+
});
|
|
552
|
+
return currentTransaction;
|
|
553
|
+
};
|
|
433
554
|
return {
|
|
434
555
|
transaction: getOrInitCurrentTransaction,
|
|
435
|
-
withTransaction: (handle, options) =>
|
|
556
|
+
withTransaction: (handle, options) => {
|
|
557
|
+
const abortRejection = Abort.rejectIfAborted(options);
|
|
558
|
+
if (abortRejection) return abortRejection;
|
|
559
|
+
return executeInTransaction(getOrInitCurrentTransaction(options), handle, { abort: Abort.from(options) });
|
|
560
|
+
}
|
|
436
561
|
};
|
|
437
562
|
};
|
|
438
563
|
const wrapInConnectionClosure = async (connection, handle) => {
|
|
@@ -444,7 +569,8 @@ const wrapInConnectionClosure = async (connection, handle) => {
|
|
|
444
569
|
};
|
|
445
570
|
const transactionFactoryWithNewConnection = (connect) => ({
|
|
446
571
|
transaction: (options) => {
|
|
447
|
-
|
|
572
|
+
Abort.throwIfAborted(options);
|
|
573
|
+
const connection = connect({ abort: Abort.from(options) });
|
|
448
574
|
const transaction = connection.transaction(options);
|
|
449
575
|
return {
|
|
450
576
|
...transaction,
|
|
@@ -453,7 +579,9 @@ const transactionFactoryWithNewConnection = (connect) => ({
|
|
|
453
579
|
};
|
|
454
580
|
},
|
|
455
581
|
withTransaction: (handle, options) => {
|
|
456
|
-
const
|
|
582
|
+
const abortRejection = Abort.rejectIfAborted(options);
|
|
583
|
+
if (abortRejection) return abortRejection;
|
|
584
|
+
const connection = connect({ abort: Abort.from(options) });
|
|
457
585
|
const withTx = connection.withTransaction;
|
|
458
586
|
return wrapInConnectionClosure(connection, () => withTx(handle, options));
|
|
459
587
|
}
|
|
@@ -465,9 +593,10 @@ const createConnection = (options) => {
|
|
|
465
593
|
const { driverType, connect, close, initTransaction, executor, serializer } = options;
|
|
466
594
|
let client = null;
|
|
467
595
|
let connectPromise = null;
|
|
468
|
-
const getClient = async () => {
|
|
596
|
+
const getClient = async (context) => {
|
|
597
|
+
Abort.throwIfAborted(context);
|
|
469
598
|
if (client) return client;
|
|
470
|
-
if (!connectPromise) connectPromise = connect().then((c) => {
|
|
599
|
+
if (!connectPromise) connectPromise = connect(context ?? { abort: Abort.never }).then((c) => {
|
|
471
600
|
client = c;
|
|
472
601
|
return c;
|
|
473
602
|
});
|
|
@@ -493,7 +622,10 @@ const createAmbientConnectionPool = (options) => {
|
|
|
493
622
|
getConnection: () => connection,
|
|
494
623
|
execute: connection.execute,
|
|
495
624
|
transaction: (options) => connection.transaction(options),
|
|
496
|
-
withConnection: (handle,
|
|
625
|
+
withConnection: (handle, options) => {
|
|
626
|
+
Abort.throwIfAborted(options);
|
|
627
|
+
return handle(connection, { abort: Abort.from(options) });
|
|
628
|
+
},
|
|
497
629
|
withTransaction: (handle, options) => {
|
|
498
630
|
const withTx = connection.withTransaction;
|
|
499
631
|
return withTx(handle, options);
|
|
@@ -502,11 +634,17 @@ const createAmbientConnectionPool = (options) => {
|
|
|
502
634
|
};
|
|
503
635
|
const createConnectionPool = (pool) => {
|
|
504
636
|
const { driverType, getConnection } = pool;
|
|
505
|
-
const connection = "connection" in pool ? pool.connection : () =>
|
|
637
|
+
const connection = "connection" in pool ? pool.connection : (options) => {
|
|
638
|
+
Abort.throwIfAborted(options);
|
|
639
|
+
return Promise.resolve(getConnection({ abort: Abort.from(options) }));
|
|
640
|
+
};
|
|
506
641
|
return {
|
|
507
642
|
driverType,
|
|
508
643
|
connection,
|
|
509
|
-
withConnection: "withConnection" in pool ? pool.withConnection : (handle,
|
|
644
|
+
withConnection: "withConnection" in pool ? pool.withConnection : (handle, options) => executeInNewConnection((connection) => handle(connection, { abort: Abort.from(options) }), {
|
|
645
|
+
connection,
|
|
646
|
+
...options
|
|
647
|
+
}),
|
|
510
648
|
close: "close" in pool ? pool.close : () => Promise.resolve(),
|
|
511
649
|
execute: "execute" in pool ? pool.execute : sqlExecutorInNewConnection({
|
|
512
650
|
driverType,
|
|
@@ -2150,18 +2288,20 @@ const pgTransaction = (connection, serializer) => (getClient, options) => {
|
|
|
2150
2288
|
allowNestedTransactions,
|
|
2151
2289
|
useSavepoints: options?.useSavepoints ?? false
|
|
2152
2290
|
});
|
|
2153
|
-
|
|
2291
|
+
const transaction = {
|
|
2154
2292
|
connection: connection(),
|
|
2155
2293
|
driverType: PgDriverType,
|
|
2156
2294
|
begin: tx.begin,
|
|
2157
2295
|
commit: tx.commit,
|
|
2158
2296
|
rollback: tx.rollback,
|
|
2159
2297
|
execute: sqlExecutor(pgSQLExecutor({ serializer }), { connect: () => getClient }),
|
|
2298
|
+
withTransaction: (handle, options) => executeInNestedTransaction(transaction, handle, options),
|
|
2160
2299
|
_transactionOptions: {
|
|
2161
2300
|
...options ?? {},
|
|
2162
2301
|
allowNestedTransactions
|
|
2163
2302
|
}
|
|
2164
2303
|
};
|
|
2304
|
+
return transaction;
|
|
2165
2305
|
};
|
|
2166
2306
|
|
|
2167
2307
|
//#endregion
|