@event-driven-io/dumbo 0.12.3 → 0.12.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +118 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +31 -15
- package/dist/index.d.ts +31 -15
- package/dist/index.js +111 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2,38 +2,122 @@
|
|
|
2
2
|
var bigIntReplacer = (_key, value) => {
|
|
3
3
|
return typeof value === "bigint" ? value.toString() : value;
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
var dateReplacer = (_key, value) => {
|
|
6
|
+
return value instanceof Date ? value.toISOString() : value;
|
|
7
|
+
};
|
|
8
|
+
var isFirstLetterNumeric = (str) => {
|
|
9
|
+
const c = str.charCodeAt(0);
|
|
10
|
+
return c >= 48 && c <= 57;
|
|
11
|
+
};
|
|
12
|
+
var isFirstLetterNumericOrMinus = (str) => {
|
|
13
|
+
const c = str.charCodeAt(0);
|
|
14
|
+
return c >= 48 && c <= 57 || c === 45;
|
|
15
|
+
};
|
|
16
|
+
var bigIntReviver = (_key, value, context) => {
|
|
17
|
+
if (typeof value === "number" && Number.isInteger(value) && !Number.isSafeInteger(value)) {
|
|
18
|
+
try {
|
|
19
|
+
return BigInt(_nullishCoalesce(_optionalChain([context, 'optionalAccess', _2 => _2.source]), () => ( value.toString())));
|
|
20
|
+
} catch (e2) {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (typeof value === "string" && value.length > 15) {
|
|
25
|
+
if (isFirstLetterNumericOrMinus(value)) {
|
|
26
|
+
const num = Number(value);
|
|
27
|
+
if (Number.isFinite(num) && !Number.isSafeInteger(num)) {
|
|
28
|
+
try {
|
|
29
|
+
return BigInt(value);
|
|
30
|
+
} catch (e3) {
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
8
34
|
}
|
|
9
35
|
return value;
|
|
10
36
|
};
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
37
|
+
var dateReviver = (_key, value) => {
|
|
38
|
+
if (typeof value === "string" && value.length === 24 && isFirstLetterNumeric(value) && value[10] === "T" && value[23] === "Z") {
|
|
39
|
+
const date = new Date(value);
|
|
40
|
+
if (!isNaN(date.getTime())) {
|
|
41
|
+
return date;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return value;
|
|
45
|
+
};
|
|
46
|
+
var composeJSONReplacers = (...replacers) => {
|
|
47
|
+
const filteredReplacers = replacers.filter((r) => r !== void 0);
|
|
48
|
+
if (filteredReplacers.length === 0) return void 0;
|
|
49
|
+
return (key2, value) => (
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
51
|
+
filteredReplacers.reduce(
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
53
|
+
(accValue, replacer) => replacer(key2, accValue),
|
|
54
|
+
value
|
|
55
|
+
)
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
var composeJSONRevivers = (...revivers) => {
|
|
59
|
+
const filteredRevivers = revivers.filter((r) => r !== void 0);
|
|
60
|
+
if (filteredRevivers.length === 0) return void 0;
|
|
61
|
+
return (key2, value, context) => (
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
63
|
+
filteredRevivers.reduce(
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
65
|
+
(accValue, reviver) => reviver(key2, accValue, context),
|
|
66
|
+
value
|
|
67
|
+
)
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
var JSONReplacer = (opts) => composeJSONReplacers(
|
|
71
|
+
_optionalChain([opts, 'optionalAccess', _3 => _3.parseBigInts]) === true ? JSONReplacers.bigInt : void 0,
|
|
72
|
+
_optionalChain([opts, 'optionalAccess', _4 => _4.parseDates]) === true ? JSONReplacers.date : void 0,
|
|
73
|
+
_optionalChain([opts, 'optionalAccess', _5 => _5.replacer])
|
|
14
74
|
);
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
75
|
+
var JSONReviver = (opts) => composeJSONRevivers(
|
|
76
|
+
_optionalChain([opts, 'optionalAccess', _6 => _6.parseBigInts]) === true ? JSONRevivers.bigInt : void 0,
|
|
77
|
+
_optionalChain([opts, 'optionalAccess', _7 => _7.parseDates]) === true ? JSONRevivers.date : void 0,
|
|
78
|
+
_optionalChain([opts, 'optionalAccess', _8 => _8.reviver])
|
|
18
79
|
);
|
|
19
|
-
var JSONReplacer = (opts) => _optionalChain([opts, 'optionalAccess', _2 => _2.disableBigIntSerialization]) == true ? opts.replacer ? opts.replacer : void 0 : _optionalChain([opts, 'optionalAccess', _3 => _3.replacer]) ? composeJSONReplacers(JSONReplacers.bigInt, opts.replacer) : JSONReplacers.bigInt;
|
|
20
|
-
var JSONReviver = (opts) => _optionalChain([opts, 'optionalAccess', _4 => _4.disableBigIntSerialization]) == true ? opts.reviver ? opts.reviver : void 0 : _optionalChain([opts, 'optionalAccess', _5 => _5.reviver]) ? composeJSONRevivers(JSONRevivers.bigInt, opts.reviver) : JSONRevivers.bigInt;
|
|
21
80
|
var JSONReplacers = {
|
|
22
|
-
bigInt: bigIntReplacer
|
|
81
|
+
bigInt: bigIntReplacer,
|
|
82
|
+
date: dateReplacer
|
|
23
83
|
};
|
|
24
84
|
var JSONRevivers = {
|
|
25
|
-
bigInt: bigIntReviver
|
|
85
|
+
bigInt: bigIntReviver,
|
|
86
|
+
date: dateReviver
|
|
26
87
|
};
|
|
27
88
|
var jsonSerializer = (options) => {
|
|
28
89
|
const defaultReplacer = JSONReplacer(options);
|
|
29
90
|
const defaultReviver = JSONReviver(options);
|
|
30
91
|
return {
|
|
31
|
-
serialize: (object,
|
|
32
|
-
|
|
92
|
+
serialize: (object, serializerOptions) => JSON.stringify(
|
|
93
|
+
object,
|
|
94
|
+
serializerOptions ? JSONReplacer(serializerOptions) : defaultReplacer
|
|
95
|
+
),
|
|
96
|
+
deserialize: (payload, deserializerOptions) => JSON.parse(
|
|
97
|
+
payload,
|
|
98
|
+
deserializerOptions ? JSONReviver(deserializerOptions) : defaultReviver
|
|
99
|
+
)
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
var JSONSerializer = jsonSerializer({ parseBigInts: true });
|
|
103
|
+
var RawJSONSerializer = jsonSerializer();
|
|
104
|
+
var JSONCodec = (options) => {
|
|
105
|
+
const serializer = "serializer" in options ? options.serializer : jsonSerializer(
|
|
106
|
+
"serializerOptions" in options ? options.serializerOptions : void 0
|
|
107
|
+
);
|
|
108
|
+
const upcast = _nullishCoalesce(options.upcast, () => ( ((doc) => doc)));
|
|
109
|
+
const downcast = _nullishCoalesce(options.downcast, () => ( ((doc) => doc)));
|
|
110
|
+
return {
|
|
111
|
+
decode: (payload, decodeOptions) => {
|
|
112
|
+
const deserialized = decodeOptions ? serializer.deserialize(payload, decodeOptions) : serializer.deserialize(payload);
|
|
113
|
+
return upcast(deserialized);
|
|
114
|
+
},
|
|
115
|
+
encode: (object, encodeOptions) => {
|
|
116
|
+
const downcasted = downcast(object);
|
|
117
|
+
return encodeOptions ? serializer.serialize(downcasted, encodeOptions) : serializer.serialize(downcasted);
|
|
118
|
+
}
|
|
33
119
|
};
|
|
34
120
|
};
|
|
35
|
-
var JSONSerializer = jsonSerializer({ disableBigIntSerialization: false });
|
|
36
|
-
var RawJSONSerializer = jsonSerializer({ disableBigIntSerialization: true });
|
|
37
121
|
|
|
38
122
|
// src/core/sql/pg-format/reserved.ts
|
|
39
123
|
var reservedMap = {
|
|
@@ -581,7 +665,7 @@ var mapRows = async (getResult, map) => {
|
|
|
581
665
|
const result = await getResult;
|
|
582
666
|
return result.rows.map(map);
|
|
583
667
|
};
|
|
584
|
-
var toCamelCase = (snakeStr) => snakeStr.replace(/_([a-z])/g, (g) => _nullishCoalesce(_optionalChain([g, 'access',
|
|
668
|
+
var toCamelCase = (snakeStr) => snakeStr.replace(/_([a-z])/g, (g) => _nullishCoalesce(_optionalChain([g, 'access', _9 => _9[1], 'optionalAccess', _10 => _10.toUpperCase, 'call', _11 => _11()]), () => ( "")));
|
|
585
669
|
var mapToCamelCase = (obj) => {
|
|
586
670
|
const newObj = {};
|
|
587
671
|
for (const key2 in obj) {
|
|
@@ -808,7 +892,7 @@ ${indent} `
|
|
|
808
892
|
)}
|
|
809
893
|
${indent}${COLOR_BRACKETS("}")}`;
|
|
810
894
|
};
|
|
811
|
-
var prettyJson = (obj, options) => formatJson(obj, 0, _optionalChain([options, 'optionalAccess',
|
|
895
|
+
var prettyJson = (obj, options) => formatJson(obj, 0, _optionalChain([options, 'optionalAccess', _12 => _12.handleMultiline]));
|
|
812
896
|
|
|
813
897
|
// src/core/tracing/index.ts
|
|
814
898
|
var tracer = () => {
|
|
@@ -918,7 +1002,7 @@ var runPostgreSQLMigrations = (pool, migrations, options) => runSQLMigrations(po
|
|
|
918
1002
|
lockId: MIGRATIONS_LOCK_ID
|
|
919
1003
|
}
|
|
920
1004
|
},
|
|
921
|
-
dryRun: _optionalChain([options, 'optionalAccess',
|
|
1005
|
+
dryRun: _optionalChain([options, 'optionalAccess', _13 => _13.dryRun])
|
|
922
1006
|
});
|
|
923
1007
|
|
|
924
1008
|
// src/postgres/core/schema/schema.ts
|
|
@@ -1058,8 +1142,8 @@ async function batch(client, sqlOrSqls, options) {
|
|
|
1058
1142
|
const results = Array(
|
|
1059
1143
|
sqls.length
|
|
1060
1144
|
);
|
|
1061
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
1062
|
-
await client.query(`SET statement_timeout = ${_optionalChain([options, 'optionalAccess',
|
|
1145
|
+
if (_optionalChain([options, 'optionalAccess', _14 => _14.timeoutMs])) {
|
|
1146
|
+
await client.query(`SET statement_timeout = ${_optionalChain([options, 'optionalAccess', _15 => _15.timeoutMs])}`);
|
|
1063
1147
|
}
|
|
1064
1148
|
for (let i = 0; i < sqls.length; i++) {
|
|
1065
1149
|
tracer.info("db:sql:query", { sql: sqls[i] });
|
|
@@ -1080,12 +1164,12 @@ var nodePostgresTransaction = (connection) => (getClient, options) => ({
|
|
|
1080
1164
|
commit: async () => {
|
|
1081
1165
|
const client = await getClient;
|
|
1082
1166
|
await client.query("COMMIT");
|
|
1083
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
1167
|
+
if (_optionalChain([options, 'optionalAccess', _16 => _16.close])) await _optionalChain([options, 'optionalAccess', _17 => _17.close, 'call', _18 => _18(client)]);
|
|
1084
1168
|
},
|
|
1085
1169
|
rollback: async (error) => {
|
|
1086
1170
|
const client = await getClient;
|
|
1087
1171
|
await client.query("ROLLBACK");
|
|
1088
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
1172
|
+
if (_optionalChain([options, 'optionalAccess', _19 => _19.close])) await _optionalChain([options, 'optionalAccess', _20 => _20.close, 'call', _21 => _21(client, error)]);
|
|
1089
1173
|
},
|
|
1090
1174
|
execute: sqlExecutor(nodePostgresSQLExecutor(), {
|
|
1091
1175
|
connect: () => getClient
|
|
@@ -1143,18 +1227,19 @@ var checkConnection = async (connectionString) => {
|
|
|
1143
1227
|
// src/postgres/pg/serialization/index.ts
|
|
1144
1228
|
|
|
1145
1229
|
var arePgTypesSet = false;
|
|
1146
|
-
var setNodePostgresTypeParser = () => {
|
|
1147
|
-
if (arePgTypesSet) return;
|
|
1230
|
+
var setNodePostgresTypeParser = (options) => {
|
|
1231
|
+
if (arePgTypesSet && !_optionalChain([options, 'optionalAccess', _22 => _22.force])) return;
|
|
1148
1232
|
arePgTypesSet = true;
|
|
1149
1233
|
_pg2.default.types.setTypeParser(20, (val) => BigInt(val));
|
|
1150
|
-
_pg2.default.types.setTypeParser(3802, (val) =>
|
|
1151
|
-
_pg2.default.types.setTypeParser(114, (val) =>
|
|
1234
|
+
_pg2.default.types.setTypeParser(3802, (val) => JSONSerializer.deserialize(val));
|
|
1235
|
+
_pg2.default.types.setTypeParser(114, (val) => JSONSerializer.deserialize(val));
|
|
1152
1236
|
};
|
|
1153
|
-
var
|
|
1237
|
+
var setNodePostgresTypeRawParser = (options) => {
|
|
1238
|
+
if (arePgTypesSet && !_optionalChain([options, 'optionalAccess', _23 => _23.force])) return;
|
|
1154
1239
|
arePgTypesSet = true;
|
|
1155
1240
|
_pg2.default.types.setTypeParser(20, (val) => BigInt(val));
|
|
1156
|
-
_pg2.default.types.setTypeParser(3802, (val) =>
|
|
1157
|
-
_pg2.default.types.setTypeParser(114, (val) =>
|
|
1241
|
+
_pg2.default.types.setTypeParser(3802, (val) => RawJSONSerializer.deserialize(val));
|
|
1242
|
+
_pg2.default.types.setTypeParser(114, (val) => RawJSONSerializer.deserialize(val));
|
|
1158
1243
|
};
|
|
1159
1244
|
|
|
1160
1245
|
// src/postgres/pg/connections/pool.ts
|
|
@@ -1388,5 +1473,6 @@ var dumbo = (options) => connectionPool(options);
|
|
|
1388
1473
|
|
|
1389
1474
|
|
|
1390
1475
|
|
|
1391
|
-
|
|
1476
|
+
|
|
1477
|
+
exports.AdvisoryLock = AdvisoryLock; exports.JSONCodec = JSONCodec; exports.JSONReplacer = JSONReplacer; exports.JSONReplacers = JSONReplacers; exports.JSONReviver = JSONReviver; exports.JSONRevivers = JSONRevivers; exports.JSONSerializer = JSONSerializer; exports.LogLevel = LogLevel; exports.LogStyle = LogStyle; exports.MIGRATIONS_LOCK_ID = MIGRATIONS_LOCK_ID; exports.NodePostgresConnectorType = NodePostgresConnectorType; exports.RawJSONSerializer = RawJSONSerializer; exports.SQL = SQL; exports.acquireAdvisoryLock = acquireAdvisoryLock; exports.advisoryLock = advisoryLock; exports.checkConnection = checkConnection; exports.color = color; exports.combineMigrations = combineMigrations; exports.composeJSONReplacers = composeJSONReplacers; exports.composeJSONRevivers = composeJSONRevivers; exports.connectionPool = connectionPool; exports.count = count; exports.createConnection = createConnection; exports.createConnectionPool = createConnectionPool; exports.defaultDatabaseLockOptions = defaultDatabaseLockOptions; exports.defaultPostgreSQLConenctionString = defaultPostgreSQLConenctionString; exports.defaultPostgreSqlDatabase = defaultPostgreSqlDatabase; exports.dumbo = dumbo; exports.endAllPools = endAllPools; exports.endPool = endPool; exports.executeInNewConnection = executeInNewConnection; exports.executeInNewDbClient = executeInNewDbClient; exports.executeInTransaction = executeInTransaction; exports.exists = exists; exports.first = first; exports.firstOrNull = firstOrNull; exports.functionExists = functionExists; exports.functionExistsSQL = functionExistsSQL; exports.getDatabaseNameOrDefault = getDatabaseNameOrDefault; exports.getPool = getPool; exports.identifier = identifier; exports.isNodePostgresClient = isNodePostgresClient; exports.isNodePostgresNativePool = isNodePostgresNativePool; exports.isNodePostgresPoolClient = isNodePostgresPoolClient; exports.isSQL = isSQL; exports.jsonSerializer = jsonSerializer; exports.literal = literal; exports.mapRows = mapRows; exports.mapToCamelCase = mapToCamelCase; exports.migrationTableSchemaComponent = migrationTableSchemaComponent; exports.nodePostgresAmbientClientPool = nodePostgresAmbientClientPool; exports.nodePostgresAmbientConnectionPool = nodePostgresAmbientConnectionPool; exports.nodePostgresAmbientNativePool = nodePostgresAmbientNativePool; exports.nodePostgresClientConnection = nodePostgresClientConnection; exports.nodePostgresClientPool = nodePostgresClientPool; exports.nodePostgresConnection = nodePostgresConnection; exports.nodePostgresExecute = nodePostgresExecute; exports.nodePostgresNativePool = nodePostgresNativePool; exports.nodePostgresPool = nodePostgresPool; exports.nodePostgresPoolClientConnection = nodePostgresPoolClientConnection; exports.nodePostgresSQLExecutor = nodePostgresSQLExecutor; exports.nodePostgresTransaction = nodePostgresTransaction; exports.onEndPool = onEndPool; exports.plainString = plainString; exports.postgresPool = postgresPool; exports.prettyJson = prettyJson; exports.rawSql = rawSql; exports.releaseAdvisoryLock = releaseAdvisoryLock; exports.runPostgreSQLMigrations = runPostgreSQLMigrations; exports.runSQLMigrations = runSQLMigrations; exports.schemaComponent = schemaComponent; exports.setNodePostgresTypeParser = setNodePostgresTypeParser; exports.setNodePostgresTypeRawParser = setNodePostgresTypeRawParser; exports.single = single; exports.singleOrNull = singleOrNull; exports.sql = sql; exports.sqlExecutor = sqlExecutor; exports.sqlExecutorInNewConnection = sqlExecutorInNewConnection; exports.sqlMigration = sqlMigration; exports.tableExists = tableExists; exports.tableExistsSQL = tableExistsSQL; exports.toCamelCase = toCamelCase; exports.tracer = tracer; exports.transactionFactoryWithDbClient = transactionFactoryWithDbClient; exports.transactionFactoryWithNewConnection = transactionFactoryWithNewConnection; exports.tryAcquireAdvisoryLock = tryAcquireAdvisoryLock;
|
|
1392
1478
|
//# sourceMappingURL=index.cjs.map
|