@event-driven-io/dumbo 0.12.3 → 0.12.4

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 CHANGED
@@ -2,38 +2,118 @@
2
2
  var bigIntReplacer = (_key, value) => {
3
3
  return typeof value === "bigint" ? value.toString() : value;
4
4
  };
5
- var bigIntReviver = (_key, value) => {
6
- if (typeof value === "string" && /^[+-]?\d+n?$/.test(value)) {
7
- return BigInt(value);
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.isSafeInteger(value)) {
18
+ return BigInt(_nullishCoalesce(_optionalChain([context, 'optionalAccess', _2 => _2.source]), () => ( value.toString())));
19
+ }
20
+ if (typeof value === "string" && value.length > 15) {
21
+ if (isFirstLetterNumericOrMinus(value)) {
22
+ const num = Number(value);
23
+ if (Number.isFinite(num) && !Number.isSafeInteger(num)) {
24
+ try {
25
+ return BigInt(value);
26
+ } catch (e2) {
27
+ }
28
+ }
29
+ }
8
30
  }
9
31
  return value;
10
32
  };
11
- var composeJSONReplacers = (...replacers) => (key2, value) => (
12
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
13
- replacers.reduce((accValue, replacer) => replacer(key2, accValue), value)
33
+ var dateReviver = (_key, value) => {
34
+ if (typeof value === "string" && value.length === 24 && isFirstLetterNumeric(value) && value[10] === "T" && value[23] === "Z") {
35
+ const date = new Date(value);
36
+ if (!isNaN(date.getTime())) {
37
+ return date;
38
+ }
39
+ }
40
+ return value;
41
+ };
42
+ var composeJSONReplacers = (...replacers) => {
43
+ const filteredReplacers = replacers.filter((r) => r !== void 0);
44
+ if (filteredReplacers.length === 0) return void 0;
45
+ return (key2, value) => (
46
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
47
+ filteredReplacers.reduce(
48
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
49
+ (accValue, replacer) => replacer(key2, accValue),
50
+ value
51
+ )
52
+ );
53
+ };
54
+ var composeJSONRevivers = (...revivers) => {
55
+ const filteredRevivers = revivers.filter((r) => r !== void 0);
56
+ if (filteredRevivers.length === 0) return void 0;
57
+ return (key2, value, context) => (
58
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
59
+ filteredRevivers.reduce(
60
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
61
+ (accValue, reviver) => reviver(key2, accValue, context),
62
+ value
63
+ )
64
+ );
65
+ };
66
+ var JSONReplacer = (opts) => composeJSONReplacers(
67
+ _optionalChain([opts, 'optionalAccess', _3 => _3.parseBigInts]) === true ? JSONReplacers.bigInt : void 0,
68
+ _optionalChain([opts, 'optionalAccess', _4 => _4.parseDates]) === true ? JSONReplacers.date : void 0,
69
+ _optionalChain([opts, 'optionalAccess', _5 => _5.replacer])
14
70
  );
15
- var composeJSONRevivers = (...revivers) => (key2, value) => (
16
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
17
- revivers.reduce((accValue, reviver) => reviver(key2, accValue), value)
71
+ var JSONReviver = (opts) => composeJSONRevivers(
72
+ _optionalChain([opts, 'optionalAccess', _6 => _6.parseBigInts]) === true ? JSONRevivers.bigInt : void 0,
73
+ _optionalChain([opts, 'optionalAccess', _7 => _7.parseDates]) === true ? JSONRevivers.date : void 0,
74
+ _optionalChain([opts, 'optionalAccess', _8 => _8.reviver])
18
75
  );
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
76
  var JSONReplacers = {
22
- bigInt: bigIntReplacer
77
+ bigInt: bigIntReplacer,
78
+ date: dateReplacer
23
79
  };
24
80
  var JSONRevivers = {
25
- bigInt: bigIntReviver
81
+ bigInt: bigIntReviver,
82
+ date: dateReviver
26
83
  };
27
84
  var jsonSerializer = (options) => {
28
85
  const defaultReplacer = JSONReplacer(options);
29
86
  const defaultReviver = JSONReviver(options);
30
87
  return {
31
- serialize: (object, options2) => JSON.stringify(object, options2 ? JSONReplacer(options2) : defaultReplacer),
32
- deserialize: (payload, options2) => JSON.parse(payload, options2 ? JSONReviver(options2) : defaultReviver)
88
+ serialize: (object, serializerOptions) => JSON.stringify(
89
+ object,
90
+ serializerOptions ? JSONReplacer(serializerOptions) : defaultReplacer
91
+ ),
92
+ deserialize: (payload, deserializerOptions) => JSON.parse(
93
+ payload,
94
+ deserializerOptions ? JSONReviver(deserializerOptions) : defaultReviver
95
+ )
96
+ };
97
+ };
98
+ var JSONSerializer = jsonSerializer({ parseBigInts: true });
99
+ var RawJSONSerializer = jsonSerializer();
100
+ var JSONCodec = (options) => {
101
+ const serializer = "serializer" in options ? options.serializer : jsonSerializer(
102
+ "serializerOptions" in options ? options.serializerOptions : void 0
103
+ );
104
+ const upcast = _nullishCoalesce(options.upcast, () => ( ((doc) => doc)));
105
+ const downcast = _nullishCoalesce(options.downcast, () => ( ((doc) => doc)));
106
+ return {
107
+ decode: (payload, decodeOptions) => {
108
+ const deserialized = decodeOptions ? serializer.deserialize(payload, decodeOptions) : serializer.deserialize(payload);
109
+ return upcast(deserialized);
110
+ },
111
+ encode: (object, encodeOptions) => {
112
+ const downcasted = downcast(object);
113
+ return encodeOptions ? serializer.serialize(downcasted, encodeOptions) : serializer.serialize(downcasted);
114
+ }
33
115
  };
34
116
  };
35
- var JSONSerializer = jsonSerializer({ disableBigIntSerialization: false });
36
- var RawJSONSerializer = jsonSerializer({ disableBigIntSerialization: true });
37
117
 
38
118
  // src/core/sql/pg-format/reserved.ts
39
119
  var reservedMap = {
@@ -581,7 +661,7 @@ var mapRows = async (getResult, map) => {
581
661
  const result = await getResult;
582
662
  return result.rows.map(map);
583
663
  };
584
- var toCamelCase = (snakeStr) => snakeStr.replace(/_([a-z])/g, (g) => _nullishCoalesce(_optionalChain([g, 'access', _6 => _6[1], 'optionalAccess', _7 => _7.toUpperCase, 'call', _8 => _8()]), () => ( "")));
664
+ var toCamelCase = (snakeStr) => snakeStr.replace(/_([a-z])/g, (g) => _nullishCoalesce(_optionalChain([g, 'access', _9 => _9[1], 'optionalAccess', _10 => _10.toUpperCase, 'call', _11 => _11()]), () => ( "")));
585
665
  var mapToCamelCase = (obj) => {
586
666
  const newObj = {};
587
667
  for (const key2 in obj) {
@@ -808,7 +888,7 @@ ${indent} `
808
888
  )}
809
889
  ${indent}${COLOR_BRACKETS("}")}`;
810
890
  };
811
- var prettyJson = (obj, options) => formatJson(obj, 0, _optionalChain([options, 'optionalAccess', _9 => _9.handleMultiline]));
891
+ var prettyJson = (obj, options) => formatJson(obj, 0, _optionalChain([options, 'optionalAccess', _12 => _12.handleMultiline]));
812
892
 
813
893
  // src/core/tracing/index.ts
814
894
  var tracer = () => {
@@ -918,7 +998,7 @@ var runPostgreSQLMigrations = (pool, migrations, options) => runSQLMigrations(po
918
998
  lockId: MIGRATIONS_LOCK_ID
919
999
  }
920
1000
  },
921
- dryRun: _optionalChain([options, 'optionalAccess', _10 => _10.dryRun])
1001
+ dryRun: _optionalChain([options, 'optionalAccess', _13 => _13.dryRun])
922
1002
  });
923
1003
 
924
1004
  // src/postgres/core/schema/schema.ts
@@ -1058,8 +1138,8 @@ async function batch(client, sqlOrSqls, options) {
1058
1138
  const results = Array(
1059
1139
  sqls.length
1060
1140
  );
1061
- if (_optionalChain([options, 'optionalAccess', _11 => _11.timeoutMs])) {
1062
- await client.query(`SET statement_timeout = ${_optionalChain([options, 'optionalAccess', _12 => _12.timeoutMs])}`);
1141
+ if (_optionalChain([options, 'optionalAccess', _14 => _14.timeoutMs])) {
1142
+ await client.query(`SET statement_timeout = ${_optionalChain([options, 'optionalAccess', _15 => _15.timeoutMs])}`);
1063
1143
  }
1064
1144
  for (let i = 0; i < sqls.length; i++) {
1065
1145
  tracer.info("db:sql:query", { sql: sqls[i] });
@@ -1080,12 +1160,12 @@ var nodePostgresTransaction = (connection) => (getClient, options) => ({
1080
1160
  commit: async () => {
1081
1161
  const client = await getClient;
1082
1162
  await client.query("COMMIT");
1083
- if (_optionalChain([options, 'optionalAccess', _13 => _13.close])) await _optionalChain([options, 'optionalAccess', _14 => _14.close, 'call', _15 => _15(client)]);
1163
+ if (_optionalChain([options, 'optionalAccess', _16 => _16.close])) await _optionalChain([options, 'optionalAccess', _17 => _17.close, 'call', _18 => _18(client)]);
1084
1164
  },
1085
1165
  rollback: async (error) => {
1086
1166
  const client = await getClient;
1087
1167
  await client.query("ROLLBACK");
1088
- if (_optionalChain([options, 'optionalAccess', _16 => _16.close])) await _optionalChain([options, 'optionalAccess', _17 => _17.close, 'call', _18 => _18(client, error)]);
1168
+ if (_optionalChain([options, 'optionalAccess', _19 => _19.close])) await _optionalChain([options, 'optionalAccess', _20 => _20.close, 'call', _21 => _21(client, error)]);
1089
1169
  },
1090
1170
  execute: sqlExecutor(nodePostgresSQLExecutor(), {
1091
1171
  connect: () => getClient
@@ -1143,18 +1223,19 @@ var checkConnection = async (connectionString) => {
1143
1223
  // src/postgres/pg/serialization/index.ts
1144
1224
 
1145
1225
  var arePgTypesSet = false;
1146
- var setNodePostgresTypeParser = () => {
1147
- if (arePgTypesSet) return;
1226
+ var setNodePostgresTypeParser = (options) => {
1227
+ if (arePgTypesSet && !_optionalChain([options, 'optionalAccess', _22 => _22.force])) return;
1148
1228
  arePgTypesSet = true;
1149
1229
  _pg2.default.types.setTypeParser(20, (val) => BigInt(val));
1150
- _pg2.default.types.setTypeParser(3802, (val) => RawJSONSerializer.deserialize(val));
1151
- _pg2.default.types.setTypeParser(114, (val) => RawJSONSerializer.deserialize(val));
1230
+ _pg2.default.types.setTypeParser(3802, (val) => JSONSerializer.deserialize(val));
1231
+ _pg2.default.types.setTypeParser(114, (val) => JSONSerializer.deserialize(val));
1152
1232
  };
1153
- var setNodePostgresTypeParserWithBigInt = () => {
1233
+ var setNodePostgresTypeRawParser = (options) => {
1234
+ if (arePgTypesSet && !_optionalChain([options, 'optionalAccess', _23 => _23.force])) return;
1154
1235
  arePgTypesSet = true;
1155
1236
  _pg2.default.types.setTypeParser(20, (val) => BigInt(val));
1156
- _pg2.default.types.setTypeParser(3802, (val) => JSONSerializer.deserialize(val));
1157
- _pg2.default.types.setTypeParser(114, (val) => JSONSerializer.deserialize(val));
1237
+ _pg2.default.types.setTypeParser(3802, (val) => RawJSONSerializer.deserialize(val));
1238
+ _pg2.default.types.setTypeParser(114, (val) => RawJSONSerializer.deserialize(val));
1158
1239
  };
1159
1240
 
1160
1241
  // src/postgres/pg/connections/pool.ts
@@ -1388,5 +1469,6 @@ var dumbo = (options) => connectionPool(options);
1388
1469
 
1389
1470
 
1390
1471
 
1391
- exports.AdvisoryLock = AdvisoryLock; 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.setNodePostgresTypeParserWithBigInt = setNodePostgresTypeParserWithBigInt; 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;
1472
+
1473
+ 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
1474
  //# sourceMappingURL=index.cjs.map