@event-driven-io/dumbo 0.13.0-beta.4 → 0.13.0-beta.40
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 +397 -0
- package/dist/cloudflare.cjs.map +1 -0
- package/dist/cloudflare.d.cts +99 -0
- package/dist/cloudflare.d.ts +99 -0
- package/dist/cloudflare.js +361 -0
- package/dist/cloudflare.js.map +1 -0
- package/dist/core-BG__WVn6.js +2262 -0
- package/dist/core-BG__WVn6.js.map +1 -0
- package/dist/core-BchvTX3G.js +379 -0
- package/dist/core-BchvTX3G.js.map +1 -0
- package/dist/core-CWZb0zOY.cjs +588 -0
- package/dist/core-CWZb0zOY.cjs.map +1 -0
- package/dist/core-D-smW7cm.cjs +3243 -0
- package/dist/core-D-smW7cm.cjs.map +1 -0
- package/dist/core-DXCRR5A9.cjs +450 -0
- package/dist/core-DXCRR5A9.cjs.map +1 -0
- package/dist/core-DlV8ua1P.js +451 -0
- package/dist/core-DlV8ua1P.js.map +1 -0
- package/dist/index-BDSQvDH2.d.cts +1585 -0
- package/dist/index-BdWFmDhJ.d.cts +68 -0
- package/dist/{index-C0h0c380.d.cts → index-BgFHGsuP.d.ts} +122 -75
- package/dist/index-DaP2fTEX.d.ts +67 -0
- package/dist/{index-C2z_XBn6.d.ts → index-N2ly5shv.d.cts} +122 -75
- package/dist/index-S_wp0Eaf.d.cts +67 -0
- package/dist/index-cxtbLiju.d.ts +68 -0
- package/dist/index-zkszkJqP.d.ts +1585 -0
- package/dist/index.cjs +219 -270
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -127
- package/dist/index.d.ts +3 -127
- package/dist/index.js +56 -269
- package/dist/index.js.map +1 -1
- package/dist/pg.cjs +373 -659
- package/dist/pg.cjs.map +1 -1
- package/dist/pg.d.cts +140 -153
- package/dist/pg.d.ts +140 -153
- package/dist/pg.js +326 -658
- package/dist/pg.js.map +1 -1
- package/dist/postgreSQLMetadata-BTz6vdwE.js +65 -0
- package/dist/postgreSQLMetadata-BTz6vdwE.js.map +1 -0
- package/dist/postgreSQLMetadata-WGXySO7a.cjs +118 -0
- package/dist/postgreSQLMetadata-WGXySO7a.cjs.map +1 -0
- package/dist/postgresql.cjs +25 -0
- package/dist/postgresql.d.cts +3 -0
- package/dist/postgresql.d.ts +3 -0
- package/dist/postgresql.js +4 -0
- package/dist/sqlite.cjs +30 -0
- package/dist/sqlite.d.cts +3 -0
- package/dist/sqlite.d.ts +3 -0
- package/dist/sqlite.js +4 -0
- package/dist/sqlite3.cjs +437 -273
- package/dist/sqlite3.cjs.map +1 -1
- package/dist/sqlite3.d.cts +92 -70
- package/dist/sqlite3.d.ts +92 -70
- package/dist/sqlite3.js +402 -272
- package/dist/sqlite3.js.map +1 -1
- package/dist/sqliteMetadata-7qBjsMBN.js +29 -0
- package/dist/sqliteMetadata-7qBjsMBN.js.map +1 -0
- package/dist/sqliteMetadata-PJTRPIZ1.cjs +46 -0
- package/dist/sqliteMetadata-PJTRPIZ1.cjs.map +1 -0
- package/package.json +60 -37
- package/dist/chunk-32AL3EAS.cjs +0 -47
- package/dist/chunk-32AL3EAS.cjs.map +0 -1
- package/dist/chunk-6IHCIJ7S.js +0 -47
- package/dist/chunk-6IHCIJ7S.js.map +0 -1
- package/dist/chunk-IYEHOE4S.cjs +0 -405
- package/dist/chunk-IYEHOE4S.cjs.map +0 -1
- package/dist/chunk-N7RWT46K.js +0 -2011
- package/dist/chunk-N7RWT46K.js.map +0 -1
- package/dist/chunk-OJ34O3Q2.cjs +0 -2011
- package/dist/chunk-OJ34O3Q2.cjs.map +0 -1
- package/dist/chunk-XVV3OOQX.js +0 -405
- package/dist/chunk-XVV3OOQX.js.map +0 -1
- package/dist/columnProcessors-BX-sH7ah.d.cts +0 -8
- package/dist/columnProcessors-DMPpTPqM.d.ts +0 -8
- package/dist/connectionString-B1wm0TFc.d.cts +0 -1271
- package/dist/connectionString-B1wm0TFc.d.ts +0 -1271
- package/dist/d1.cjs +0 -277
- package/dist/d1.cjs.map +0 -1
- package/dist/d1.d.cts +0 -72
- package/dist/d1.d.ts +0 -72
- package/dist/d1.js +0 -277
- package/dist/d1.js.map +0 -1
package/dist/chunk-N7RWT46K.js
DELETED
|
@@ -1,2011 +0,0 @@
|
|
|
1
|
-
// src/core/drivers/index.ts
|
|
2
|
-
function toDatabaseDriverType(databaseType, driverName) {
|
|
3
|
-
return `${databaseType}:${driverName}`;
|
|
4
|
-
}
|
|
5
|
-
function fromDatabaseDriverType(databaseDriverType) {
|
|
6
|
-
const parts = databaseDriverType.split(":");
|
|
7
|
-
return {
|
|
8
|
-
databaseType: parts[0],
|
|
9
|
-
driverName: parts[1]
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
function getDatabaseDriverName(databaseDriverType) {
|
|
13
|
-
const { driverName } = fromDatabaseDriverType(databaseDriverType);
|
|
14
|
-
return driverName;
|
|
15
|
-
}
|
|
16
|
-
function getDatabaseType(databaseDriverType) {
|
|
17
|
-
const { databaseType } = fromDatabaseDriverType(databaseDriverType);
|
|
18
|
-
return databaseType;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// src/core/serializer/json/index.ts
|
|
22
|
-
var bigIntReplacer = (_key, value) => {
|
|
23
|
-
return typeof value === "bigint" ? value.toString() : value;
|
|
24
|
-
};
|
|
25
|
-
var bigIntReviver = (_key, value) => {
|
|
26
|
-
if (typeof value === "string" && /^[+-]?\d+n?$/.test(value)) {
|
|
27
|
-
return BigInt(value);
|
|
28
|
-
}
|
|
29
|
-
return value;
|
|
30
|
-
};
|
|
31
|
-
var composeJSONReplacers = (...replacers) => (key, value) => (
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
33
|
-
replacers.reduce((accValue, replacer) => replacer(key, accValue), value)
|
|
34
|
-
);
|
|
35
|
-
var composeJSONRevivers = (...revivers) => (key, value) => (
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
37
|
-
revivers.reduce((accValue, reviver) => reviver(key, accValue), value)
|
|
38
|
-
);
|
|
39
|
-
var JSONReplacer = (opts) => opts?.disableBigIntSerialization == true ? opts.replacer ? opts.replacer : void 0 : opts?.replacer ? composeJSONReplacers(JSONReplacers.bigInt, opts.replacer) : JSONReplacers.bigInt;
|
|
40
|
-
var JSONReviver = (opts) => opts?.disableBigIntSerialization == true ? opts.reviver ? opts.reviver : void 0 : opts?.reviver ? composeJSONRevivers(JSONRevivers.bigInt, opts.reviver) : JSONRevivers.bigInt;
|
|
41
|
-
var JSONReplacers = {
|
|
42
|
-
bigInt: bigIntReplacer
|
|
43
|
-
};
|
|
44
|
-
var JSONRevivers = {
|
|
45
|
-
bigInt: bigIntReviver
|
|
46
|
-
};
|
|
47
|
-
var jsonSerializer = (options) => {
|
|
48
|
-
const defaultReplacer = JSONReplacer(options);
|
|
49
|
-
const defaultReviver = JSONReviver(options);
|
|
50
|
-
return {
|
|
51
|
-
serialize: (object, options2) => JSON.stringify(object, options2 ? JSONReplacer(options2) : defaultReplacer),
|
|
52
|
-
deserialize: (payload, options2) => JSON.parse(payload, options2 ? JSONReviver(options2) : defaultReviver)
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
var JSONSerializer = jsonSerializer({ disableBigIntSerialization: false });
|
|
56
|
-
var RawJSONSerializer = jsonSerializer({ disableBigIntSerialization: true });
|
|
57
|
-
|
|
58
|
-
// src/core/sql/parametrizedSQL/parametrizedSQL.ts
|
|
59
|
-
var ParametrizedSQLBuilder = ({
|
|
60
|
-
mapParamPlaceholder
|
|
61
|
-
}) => {
|
|
62
|
-
const sql = [];
|
|
63
|
-
const params = [];
|
|
64
|
-
return {
|
|
65
|
-
addSQL(str) {
|
|
66
|
-
sql.push(str);
|
|
67
|
-
return this;
|
|
68
|
-
},
|
|
69
|
-
addParam(value) {
|
|
70
|
-
sql.push(mapParamPlaceholder(params.length, value));
|
|
71
|
-
params.push(value);
|
|
72
|
-
return this;
|
|
73
|
-
},
|
|
74
|
-
addParams(values) {
|
|
75
|
-
const placeholders = values.map(
|
|
76
|
-
(value, i) => mapParamPlaceholder(params.length + i, value)
|
|
77
|
-
);
|
|
78
|
-
this.addSQL(`(${placeholders.join(", ")})`);
|
|
79
|
-
params.push(...values);
|
|
80
|
-
return this;
|
|
81
|
-
},
|
|
82
|
-
build() {
|
|
83
|
-
return {
|
|
84
|
-
query: sql.join(""),
|
|
85
|
-
params
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
// src/core/sql/tokens/sqlToken.ts
|
|
92
|
-
var SQLToken = (sqlTokenType, map) => {
|
|
93
|
-
const factory = (input) => {
|
|
94
|
-
let props;
|
|
95
|
-
if (map !== void 0) {
|
|
96
|
-
props = map(input);
|
|
97
|
-
} else if (input === void 0 || input === null) {
|
|
98
|
-
props = {};
|
|
99
|
-
} else if (typeof input === "object" && !Array.isArray(input)) {
|
|
100
|
-
props = input;
|
|
101
|
-
} else {
|
|
102
|
-
throw new Error(
|
|
103
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
104
|
-
`Cannot create SQLToken of type ${sqlTokenType} with input: ${input}`
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
sqlTokenType,
|
|
109
|
-
[sqlTokenType]: true,
|
|
110
|
-
...props
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
const check = (token) => SQLToken.check(token) && token.sqlTokenType === sqlTokenType;
|
|
114
|
-
return { from: factory, check, type: sqlTokenType };
|
|
115
|
-
};
|
|
116
|
-
SQLToken.check = (token) => token !== null && typeof token === "object" && "sqlTokenType" in token;
|
|
117
|
-
var SQLIdentifier = SQLToken(
|
|
118
|
-
"SQL_IDENTIFIER",
|
|
119
|
-
(value) => ({
|
|
120
|
-
value
|
|
121
|
-
})
|
|
122
|
-
);
|
|
123
|
-
var SQLPlain = SQLToken("SQL_RAW", (value) => ({
|
|
124
|
-
value
|
|
125
|
-
}));
|
|
126
|
-
var SQLLiteral = SQLToken(
|
|
127
|
-
"SQL_LITERAL",
|
|
128
|
-
(value) => ({
|
|
129
|
-
value
|
|
130
|
-
})
|
|
131
|
-
);
|
|
132
|
-
var SQLArray = SQLToken("SQL_ARRAY", (value) => ({
|
|
133
|
-
value
|
|
134
|
-
}));
|
|
135
|
-
var SQLIn = SQLToken(
|
|
136
|
-
"SQL_IN",
|
|
137
|
-
({ column, values }) => ({
|
|
138
|
-
column: SQLIdentifier.from(column),
|
|
139
|
-
values: SQLArray.from(values)
|
|
140
|
-
})
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
// src/core/sql/tokens/columnTokens.ts
|
|
144
|
-
var ColumnTypeToken = (sqlTokenType, jsTypeName, map) => {
|
|
145
|
-
const factory = (input) => {
|
|
146
|
-
let props;
|
|
147
|
-
if (map !== void 0) {
|
|
148
|
-
props = map(input);
|
|
149
|
-
} else if (input === void 0 || input === null) {
|
|
150
|
-
props = {};
|
|
151
|
-
} else if (typeof input === "object" && !Array.isArray(input)) {
|
|
152
|
-
props = input;
|
|
153
|
-
} else {
|
|
154
|
-
throw new Error(
|
|
155
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
156
|
-
`Cannot create SQLToken of type ${sqlTokenType} with input: ${input}`
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
return {
|
|
160
|
-
sqlTokenType,
|
|
161
|
-
[sqlTokenType]: true,
|
|
162
|
-
jsTypeName,
|
|
163
|
-
...props
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
|
-
const check = (token) => SQLToken.check(token) && token.sqlTokenType === sqlTokenType;
|
|
167
|
-
return { from: factory, check, type: sqlTokenType };
|
|
168
|
-
};
|
|
169
|
-
var SerialToken = ColumnTypeToken(
|
|
170
|
-
"SQL_COLUMN_SERIAL",
|
|
171
|
-
"value_type:js:number"
|
|
172
|
-
);
|
|
173
|
-
var BigSerialToken = ColumnTypeToken(
|
|
174
|
-
"SQL_COLUMN_BIGSERIAL",
|
|
175
|
-
"value_type:js:bigint"
|
|
176
|
-
);
|
|
177
|
-
var IntegerToken = ColumnTypeToken(
|
|
178
|
-
"SQL_COLUMN_INTEGER",
|
|
179
|
-
"value_type:js:number"
|
|
180
|
-
);
|
|
181
|
-
var BigIntegerToken = ColumnTypeToken(
|
|
182
|
-
"SQL_COLUMN_BIGINT",
|
|
183
|
-
"value_type:js:bigint"
|
|
184
|
-
);
|
|
185
|
-
var JSONBToken = {
|
|
186
|
-
type: "SQL_COLUMN_JSONB",
|
|
187
|
-
from: () => {
|
|
188
|
-
return {
|
|
189
|
-
sqlTokenType: "SQL_COLUMN_JSONB",
|
|
190
|
-
["SQL_COLUMN_JSONB"]: true
|
|
191
|
-
};
|
|
192
|
-
},
|
|
193
|
-
check: (token) => SQLToken.check(token) && token.sqlTokenType === "SQL_COLUMN_JSONB"
|
|
194
|
-
};
|
|
195
|
-
var TimestampToken = ColumnTypeToken(
|
|
196
|
-
"SQL_COLUMN_TIMESTAMP",
|
|
197
|
-
"value_type:js:date"
|
|
198
|
-
);
|
|
199
|
-
var TimestamptzToken = ColumnTypeToken(
|
|
200
|
-
"SQL_COLUMN_TIMESTAMPTZ",
|
|
201
|
-
"value_type:js:date"
|
|
202
|
-
);
|
|
203
|
-
var VarcharToken = ColumnTypeToken(
|
|
204
|
-
"SQL_COLUMN_VARCHAR",
|
|
205
|
-
"value_type:js:string",
|
|
206
|
-
(length) => ({
|
|
207
|
-
length: length ?? "max",
|
|
208
|
-
jsTypeName: "value_type:js:string"
|
|
209
|
-
})
|
|
210
|
-
);
|
|
211
|
-
var AutoIncrementSQLColumnToken = ColumnTypeToken(
|
|
212
|
-
"SQL_COLUMN_AUTO_INCREMENT",
|
|
213
|
-
"value_type:js:bigint"
|
|
214
|
-
);
|
|
215
|
-
var SQLColumnTypeTokens = {
|
|
216
|
-
AutoIncrement: AutoIncrementSQLColumnToken,
|
|
217
|
-
BigInteger: BigIntegerToken,
|
|
218
|
-
BigSerial: BigSerialToken,
|
|
219
|
-
Integer: IntegerToken,
|
|
220
|
-
JSONB: JSONBToken,
|
|
221
|
-
Serial: SerialToken,
|
|
222
|
-
Timestamp: TimestampToken,
|
|
223
|
-
Timestamptz: TimestamptzToken,
|
|
224
|
-
Varchar: VarcharToken
|
|
225
|
-
};
|
|
226
|
-
var SQLColumnTypeTokensFactory = {
|
|
227
|
-
AutoIncrement: AutoIncrementSQLColumnToken.from,
|
|
228
|
-
BigInteger: BigIntegerToken.from(),
|
|
229
|
-
BigSerial: BigSerialToken.from(),
|
|
230
|
-
Integer: IntegerToken.from(),
|
|
231
|
-
JSONB: JSONBToken.from,
|
|
232
|
-
Serial: SerialToken.from(),
|
|
233
|
-
Timestamp: TimestampToken.from(),
|
|
234
|
-
Timestamptz: TimestamptzToken.from(),
|
|
235
|
-
Varchar: VarcharToken.from
|
|
236
|
-
};
|
|
237
|
-
var SQLColumnToken = SQLToken("SQL_COLUMN");
|
|
238
|
-
|
|
239
|
-
// src/core/sql/processors/sqlProcessor.ts
|
|
240
|
-
var SQLProcessor = (options) => options;
|
|
241
|
-
|
|
242
|
-
// src/core/sql/processors/defaultProcessors.ts
|
|
243
|
-
var ExpandArrayProcessor = SQLProcessor({
|
|
244
|
-
canHandle: "SQL_ARRAY",
|
|
245
|
-
handle: (token, { builder, mapper }) => {
|
|
246
|
-
if (token.value.length === 0) {
|
|
247
|
-
throw new Error(
|
|
248
|
-
"Empty arrays are not supported. If you're using it with SELECT IN statement Use SQL.in(column, array) helper instead."
|
|
249
|
-
);
|
|
250
|
-
}
|
|
251
|
-
builder.addParams(mapper.mapValue(token.value));
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
var ExpandSQLInProcessor = SQLProcessor({
|
|
255
|
-
canHandle: "SQL_IN",
|
|
256
|
-
handle: (token, context) => {
|
|
257
|
-
const { builder, mapper, processorsRegistry } = context;
|
|
258
|
-
const { values: inValues, column } = token;
|
|
259
|
-
if (inValues.value.length === 0) {
|
|
260
|
-
builder.addParam(mapper.mapValue(false));
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
builder.addSQL(mapper.mapValue(column.value));
|
|
264
|
-
builder.addSQL(` IN `);
|
|
265
|
-
const arrayProcessor = processorsRegistry.get(SQLArray.type);
|
|
266
|
-
if (!arrayProcessor) {
|
|
267
|
-
throw new Error(
|
|
268
|
-
"No sql processor registered for an array. Cannot expand IN statement"
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
arrayProcessor.handle(inValues, { builder, mapper, processorsRegistry });
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
var FormatIdentifierProcessor = SQLProcessor({
|
|
275
|
-
canHandle: "SQL_IDENTIFIER",
|
|
276
|
-
handle: (token, { builder, mapper }) => {
|
|
277
|
-
builder.addSQL(mapper.mapValue(token));
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
var MapLiteralProcessor = SQLProcessor({
|
|
281
|
-
canHandle: "SQL_LITERAL",
|
|
282
|
-
handle: (token, { builder, mapper }) => builder.addParam(mapper.mapValue(token.value))
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
// src/core/sql/processors/sqlProcessorRegistry.ts
|
|
286
|
-
var SQLProcessorsRegistry = (options) => {
|
|
287
|
-
const processors = options ? new Map(options.from.all()) : /* @__PURE__ */ new Map();
|
|
288
|
-
function register(...args) {
|
|
289
|
-
if (args.length === 1 && typeof args[0] === "object" && !Array.isArray(args[0])) {
|
|
290
|
-
Object.entries(args[0]).forEach(
|
|
291
|
-
([_, processor]) => {
|
|
292
|
-
processors.set(processor.canHandle, processor);
|
|
293
|
-
}
|
|
294
|
-
);
|
|
295
|
-
} else {
|
|
296
|
-
args.forEach(
|
|
297
|
-
(p) => processors.set(p.canHandle, p)
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
return registry;
|
|
301
|
-
}
|
|
302
|
-
const registry = {
|
|
303
|
-
register,
|
|
304
|
-
get: (tokenType) => {
|
|
305
|
-
return processors.get(tokenType) ?? null;
|
|
306
|
-
},
|
|
307
|
-
all: () => processors
|
|
308
|
-
};
|
|
309
|
-
return registry;
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
// src/core/sql/processors/columnProcessors.ts
|
|
313
|
-
var mapDefaultSQLColumnProcessors = (mapColumnType) => ({
|
|
314
|
-
AutoIncrement: SQLProcessor({
|
|
315
|
-
canHandle: "SQL_COLUMN_AUTO_INCREMENT",
|
|
316
|
-
handle: (token, context) => {
|
|
317
|
-
mapColumnType(token, context);
|
|
318
|
-
}
|
|
319
|
-
}),
|
|
320
|
-
BigInteger: SQLProcessor({
|
|
321
|
-
canHandle: "SQL_COLUMN_BIGINT",
|
|
322
|
-
handle: (token, context) => mapColumnType(token, context)
|
|
323
|
-
}),
|
|
324
|
-
BigSerial: SQLProcessor({
|
|
325
|
-
canHandle: "SQL_COLUMN_BIGSERIAL",
|
|
326
|
-
handle: (token, context) => mapColumnType(token, context)
|
|
327
|
-
}),
|
|
328
|
-
Serial: SQLProcessor({
|
|
329
|
-
canHandle: "SQL_COLUMN_SERIAL",
|
|
330
|
-
handle: (token, context) => mapColumnType(token, context)
|
|
331
|
-
}),
|
|
332
|
-
Integer: SQLProcessor({
|
|
333
|
-
canHandle: "SQL_COLUMN_INTEGER",
|
|
334
|
-
handle: (token, context) => mapColumnType(token, context)
|
|
335
|
-
}),
|
|
336
|
-
JSONB: SQLProcessor({
|
|
337
|
-
canHandle: "SQL_COLUMN_JSONB",
|
|
338
|
-
handle: (token, context) => mapColumnType(token, context)
|
|
339
|
-
}),
|
|
340
|
-
Timestamp: SQLProcessor({
|
|
341
|
-
canHandle: "SQL_COLUMN_TIMESTAMP",
|
|
342
|
-
handle: (token, context) => mapColumnType(token, context)
|
|
343
|
-
}),
|
|
344
|
-
Timestamptz: SQLProcessor({
|
|
345
|
-
canHandle: "SQL_COLUMN_TIMESTAMPTZ",
|
|
346
|
-
handle: (token, context) => mapColumnType(token, context)
|
|
347
|
-
}),
|
|
348
|
-
Varchar: SQLProcessor({
|
|
349
|
-
canHandle: "SQL_COLUMN_VARCHAR",
|
|
350
|
-
handle: (token, context) => mapColumnType(token, context)
|
|
351
|
-
})
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
// src/core/sql/processors/index.ts
|
|
355
|
-
var defaultProcessorsRegistry = globalThis.defaultProcessorsRegistry = globalThis.defaultProcessorsRegistry ?? SQLProcessorsRegistry().register(
|
|
356
|
-
FormatIdentifierProcessor,
|
|
357
|
-
MapLiteralProcessor,
|
|
358
|
-
ExpandArrayProcessor,
|
|
359
|
-
ExpandSQLInProcessor
|
|
360
|
-
);
|
|
361
|
-
|
|
362
|
-
// src/core/sql/tokenizedSQL/tokenizedSQL.ts
|
|
363
|
-
var TokenizedSQLBuilder = () => {
|
|
364
|
-
const sqlChunks = [];
|
|
365
|
-
const sqlTokens = [];
|
|
366
|
-
return {
|
|
367
|
-
addSQL(str) {
|
|
368
|
-
sqlChunks.push(str);
|
|
369
|
-
},
|
|
370
|
-
addSQLs(str) {
|
|
371
|
-
sqlChunks.push(...str);
|
|
372
|
-
},
|
|
373
|
-
addToken(value) {
|
|
374
|
-
sqlTokens.push(value);
|
|
375
|
-
},
|
|
376
|
-
addTokens(vals) {
|
|
377
|
-
sqlTokens.push(...vals);
|
|
378
|
-
},
|
|
379
|
-
build() {
|
|
380
|
-
return sqlChunks.length > 0 ? {
|
|
381
|
-
__brand: "tokenized-sql",
|
|
382
|
-
sqlChunks,
|
|
383
|
-
sqlTokens
|
|
384
|
-
} : TokenizedSQL.empty;
|
|
385
|
-
}
|
|
386
|
-
};
|
|
387
|
-
};
|
|
388
|
-
var TokenizedSQL = (strings, values) => {
|
|
389
|
-
const builder = TokenizedSQLBuilder();
|
|
390
|
-
for (let i = 0; i < strings.length; i++) {
|
|
391
|
-
if (strings[i] !== "") builder.addSQL(strings[i]);
|
|
392
|
-
if (i >= values.length) break;
|
|
393
|
-
const value = values[i];
|
|
394
|
-
if (isTokenizedSQL(value)) {
|
|
395
|
-
builder.addSQLs(value.sqlChunks);
|
|
396
|
-
builder.addTokens(value.sqlTokens);
|
|
397
|
-
} else if (SQLPlain.check(value)) {
|
|
398
|
-
builder.addSQL(value.value);
|
|
399
|
-
} else {
|
|
400
|
-
builder.addSQL(TokenizedSQL.paramPlaceholder);
|
|
401
|
-
builder.addToken(
|
|
402
|
-
SQLToken.check(value) ? value : Array.isArray(value) ? SQLArray.from(value) : SQLLiteral.from(value)
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
return builder.build();
|
|
407
|
-
};
|
|
408
|
-
var isTokenizedSQL = (value) => {
|
|
409
|
-
return value !== null && typeof value === "object" && "__brand" in value && value.__brand === "tokenized-sql";
|
|
410
|
-
};
|
|
411
|
-
TokenizedSQL.paramPlaceholder = `__P__`;
|
|
412
|
-
TokenizedSQL.empty = {
|
|
413
|
-
__brand: "tokenized-sql",
|
|
414
|
-
sqlChunks: [""],
|
|
415
|
-
sqlTokens: []
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
// src/core/sql/sql.ts
|
|
419
|
-
function SQL(strings, ...values) {
|
|
420
|
-
const parametrized = TokenizedSQL(strings, values);
|
|
421
|
-
return parametrized;
|
|
422
|
-
}
|
|
423
|
-
var isSQL = (value) => {
|
|
424
|
-
if (value === void 0 || value === null) {
|
|
425
|
-
return false;
|
|
426
|
-
}
|
|
427
|
-
return isTokenizedSQL(value);
|
|
428
|
-
};
|
|
429
|
-
var emptySQL = {
|
|
430
|
-
__brand: "tokenized-sql",
|
|
431
|
-
sqlChunks: [""],
|
|
432
|
-
sqlTokens: []
|
|
433
|
-
};
|
|
434
|
-
var mergeSQL = (sqls, separator = " ") => {
|
|
435
|
-
const parametrized = sqls.filter((sql) => !isEmpty(sql)).map((sql) => sql);
|
|
436
|
-
const params = parametrized.flatMap((p) => p.sqlTokens);
|
|
437
|
-
const sqlChunks = parametrized.flatMap(
|
|
438
|
-
(p, i) => i == parametrized.length - 1 || separator === "" ? p.sqlChunks : [...p.sqlChunks, separator]
|
|
439
|
-
);
|
|
440
|
-
const merged = sqlChunks.length > 0 ? {
|
|
441
|
-
__brand: "tokenized-sql",
|
|
442
|
-
sqlChunks,
|
|
443
|
-
sqlTokens: params
|
|
444
|
-
} : TokenizedSQL.empty;
|
|
445
|
-
return merged;
|
|
446
|
-
};
|
|
447
|
-
var concatSQL = (...sqls) => mergeSQL(sqls, "");
|
|
448
|
-
var isEmpty = (sql) => {
|
|
449
|
-
if (isTokenizedSQL(sql)) {
|
|
450
|
-
const parametrized = sql;
|
|
451
|
-
return parametrized.sqlChunks.every((chunk) => chunk.trim() === "") && parametrized.sqlTokens.length === 0;
|
|
452
|
-
}
|
|
453
|
-
return false;
|
|
454
|
-
};
|
|
455
|
-
SQL.EMPTY = emptySQL;
|
|
456
|
-
SQL.concat = concatSQL;
|
|
457
|
-
SQL.merge = mergeSQL;
|
|
458
|
-
SQL.format = (sql, formatter, options) => formatSQL(sql, formatter, options);
|
|
459
|
-
SQL.describe = (sql, formatter, options) => describeSQL(sql, formatter, options);
|
|
460
|
-
SQL.in = (column, values) => SQLIn.from({ column, values });
|
|
461
|
-
SQL.identifier = SQLIdentifier.from;
|
|
462
|
-
SQL.plain = SQLPlain.from;
|
|
463
|
-
SQL.check = {
|
|
464
|
-
isSQL,
|
|
465
|
-
isTokenizedSQL: (value) => isTokenizedSQL(value),
|
|
466
|
-
isEmpty,
|
|
467
|
-
isIdentifier: SQLIdentifier.check,
|
|
468
|
-
isPlain: SQLPlain.check,
|
|
469
|
-
isSQLIn: SQLIn.check
|
|
470
|
-
};
|
|
471
|
-
var columnFactory = SQLColumnToken.from;
|
|
472
|
-
columnFactory.type = SQLColumnTypeTokensFactory;
|
|
473
|
-
SQL.column = columnFactory;
|
|
474
|
-
|
|
475
|
-
// src/core/sql/valueMappers/reservedSqlWords.ts
|
|
476
|
-
var ansiSqlReservedMap = {
|
|
477
|
-
ALL: true,
|
|
478
|
-
AND: true,
|
|
479
|
-
ANY: true,
|
|
480
|
-
ARRAY: true,
|
|
481
|
-
AS: true,
|
|
482
|
-
ASC: true,
|
|
483
|
-
AUTHORIZATION: true,
|
|
484
|
-
BETWEEN: true,
|
|
485
|
-
BINARY: true,
|
|
486
|
-
BOTH: true,
|
|
487
|
-
CASE: true,
|
|
488
|
-
CAST: true,
|
|
489
|
-
CHECK: true,
|
|
490
|
-
COLLATE: true,
|
|
491
|
-
COLUMN: true,
|
|
492
|
-
CONSTRAINT: true,
|
|
493
|
-
CREATE: true,
|
|
494
|
-
CROSS: true,
|
|
495
|
-
CURRENT_DATE: true,
|
|
496
|
-
CURRENT_TIME: true,
|
|
497
|
-
CURRENT_TIMESTAMP: true,
|
|
498
|
-
CURRENT_USER: true,
|
|
499
|
-
DEFAULT: true,
|
|
500
|
-
DEFERRABLE: true,
|
|
501
|
-
DESC: true,
|
|
502
|
-
DISTINCT: true,
|
|
503
|
-
DO: true,
|
|
504
|
-
ELSE: true,
|
|
505
|
-
END: true,
|
|
506
|
-
EXCEPT: true,
|
|
507
|
-
FALSE: true,
|
|
508
|
-
FOR: true,
|
|
509
|
-
FOREIGN: true,
|
|
510
|
-
FROM: true,
|
|
511
|
-
FULL: true,
|
|
512
|
-
GRANT: true,
|
|
513
|
-
GROUP: true,
|
|
514
|
-
HAVING: true,
|
|
515
|
-
IN: true,
|
|
516
|
-
INITIALLY: true,
|
|
517
|
-
INNER: true,
|
|
518
|
-
INTERSECT: true,
|
|
519
|
-
INTO: true,
|
|
520
|
-
IS: true,
|
|
521
|
-
JOIN: true,
|
|
522
|
-
LEADING: true,
|
|
523
|
-
LEFT: true,
|
|
524
|
-
LIKE: true,
|
|
525
|
-
LOCALTIME: true,
|
|
526
|
-
LOCALTIMESTAMP: true,
|
|
527
|
-
NATURAL: true,
|
|
528
|
-
NEW: true,
|
|
529
|
-
NOT: true,
|
|
530
|
-
NULL: true,
|
|
531
|
-
NULLS: true,
|
|
532
|
-
OLD: true,
|
|
533
|
-
ON: true,
|
|
534
|
-
ONLY: true,
|
|
535
|
-
OPEN: true,
|
|
536
|
-
OR: true,
|
|
537
|
-
ORDER: true,
|
|
538
|
-
OUTER: true,
|
|
539
|
-
OVERLAPS: true,
|
|
540
|
-
PARTITION: true,
|
|
541
|
-
PLACING: true,
|
|
542
|
-
PRIMARY: true,
|
|
543
|
-
REFERENCES: true,
|
|
544
|
-
RIGHT: true,
|
|
545
|
-
SELECT: true,
|
|
546
|
-
SESSION_USER: true,
|
|
547
|
-
SIMILAR: true,
|
|
548
|
-
SOME: true,
|
|
549
|
-
TABLE: true,
|
|
550
|
-
THEN: true,
|
|
551
|
-
TO: true,
|
|
552
|
-
TRAILING: true,
|
|
553
|
-
TRUE: true,
|
|
554
|
-
UNION: true,
|
|
555
|
-
UNIQUE: true,
|
|
556
|
-
USER: true,
|
|
557
|
-
USING: true,
|
|
558
|
-
WHEN: true,
|
|
559
|
-
WHERE: true,
|
|
560
|
-
WITH: true,
|
|
561
|
-
WITHOUT: true,
|
|
562
|
-
ADD: true,
|
|
563
|
-
ALTER: true,
|
|
564
|
-
ARE: true,
|
|
565
|
-
AT: true,
|
|
566
|
-
BEGIN: true,
|
|
567
|
-
BY: true,
|
|
568
|
-
CASCADE: true,
|
|
569
|
-
CLOSE: true,
|
|
570
|
-
COMMIT: true,
|
|
571
|
-
CONNECT: true,
|
|
572
|
-
CONTINUE: true,
|
|
573
|
-
CORRESPONDING: true,
|
|
574
|
-
CURSOR: true,
|
|
575
|
-
DEALLOCATE: true,
|
|
576
|
-
DECLARE: true,
|
|
577
|
-
DELETE: true,
|
|
578
|
-
DESCRIBE: true,
|
|
579
|
-
DISCONNECT: true,
|
|
580
|
-
DROP: true,
|
|
581
|
-
ESCAPE: true,
|
|
582
|
-
EXECUTE: true,
|
|
583
|
-
EXISTS: true,
|
|
584
|
-
FETCH: true,
|
|
585
|
-
FIRST: true,
|
|
586
|
-
FLOAT: true,
|
|
587
|
-
GET: true,
|
|
588
|
-
GLOBAL: true,
|
|
589
|
-
GO: true,
|
|
590
|
-
GOTO: true,
|
|
591
|
-
HOUR: true,
|
|
592
|
-
IMMEDIATE: true,
|
|
593
|
-
INDICATOR: true,
|
|
594
|
-
INPUT: true,
|
|
595
|
-
INSERT: true,
|
|
596
|
-
INT: true,
|
|
597
|
-
INTEGER: true,
|
|
598
|
-
INTERVAL: true,
|
|
599
|
-
LANGUAGE: true,
|
|
600
|
-
LAST: true,
|
|
601
|
-
LOCAL: true,
|
|
602
|
-
MATCH: true,
|
|
603
|
-
MINUTE: true,
|
|
604
|
-
MODULE: true,
|
|
605
|
-
MONTH: true,
|
|
606
|
-
NATIONAL: true,
|
|
607
|
-
NEXT: true,
|
|
608
|
-
NO: true,
|
|
609
|
-
OF: true,
|
|
610
|
-
OUTPUT: true,
|
|
611
|
-
PARTIAL: true,
|
|
612
|
-
PREPARE: true,
|
|
613
|
-
PRESERVE: true,
|
|
614
|
-
PRIOR: true,
|
|
615
|
-
PRIVILEGES: true,
|
|
616
|
-
PROCEDURE: true,
|
|
617
|
-
PUBLIC: true,
|
|
618
|
-
READ: true,
|
|
619
|
-
REAL: true,
|
|
620
|
-
RESTRICT: true,
|
|
621
|
-
REVOKE: true,
|
|
622
|
-
ROLLBACK: true,
|
|
623
|
-
ROWS: true,
|
|
624
|
-
SCHEMA: true,
|
|
625
|
-
SCROLL: true,
|
|
626
|
-
SECOND: true,
|
|
627
|
-
SECTION: true,
|
|
628
|
-
SET: true,
|
|
629
|
-
SIZE: true,
|
|
630
|
-
SMALLINT: true,
|
|
631
|
-
SQL: true,
|
|
632
|
-
SQLCODE: true,
|
|
633
|
-
SQLERROR: true,
|
|
634
|
-
SQLSTATE: true,
|
|
635
|
-
TEMPORARY: true,
|
|
636
|
-
TIMEZONE_HOUR: true,
|
|
637
|
-
TIMEZONE_MINUTE: true,
|
|
638
|
-
TRANSACTION: true,
|
|
639
|
-
TRANSLATE: true,
|
|
640
|
-
TRANSLATION: true,
|
|
641
|
-
UNKNOWN: true,
|
|
642
|
-
UPDATE: true,
|
|
643
|
-
VALUE: true,
|
|
644
|
-
VALUES: true,
|
|
645
|
-
VARCHAR: true,
|
|
646
|
-
VARYING: true,
|
|
647
|
-
VIEW: true,
|
|
648
|
-
WHENEVER: true,
|
|
649
|
-
WORK: true,
|
|
650
|
-
WRITE: true,
|
|
651
|
-
YEAR: true,
|
|
652
|
-
ZONE: true
|
|
653
|
-
};
|
|
654
|
-
|
|
655
|
-
// src/core/sql/valueMappers/sqlValueMapper.ts
|
|
656
|
-
var ANSISQLParamPlaceholder = "?";
|
|
657
|
-
var ANSISQLIdentifierQuote = '"';
|
|
658
|
-
var mapANSISQLParamPlaceholder = () => ANSISQLParamPlaceholder;
|
|
659
|
-
var isReserved = (value, reserved) => !!reserved[value.toUpperCase()];
|
|
660
|
-
var mapSQLIdentifier = (value, options) => {
|
|
661
|
-
if (value === void 0 || value === null) {
|
|
662
|
-
throw new Error("SQL identifier cannot be null or undefined");
|
|
663
|
-
}
|
|
664
|
-
const ident = value.toString().slice(0);
|
|
665
|
-
const quoteSign = options?.quote ?? ANSISQLIdentifierQuote;
|
|
666
|
-
if (/^[a-z_][a-z0-9_$]*$/.test(ident) && !isReserved(ident, options?.reservedWords ?? ansiSqlReservedMap)) {
|
|
667
|
-
return ident;
|
|
668
|
-
}
|
|
669
|
-
let quoted = quoteSign;
|
|
670
|
-
for (let i = 0; i < ident.length; i++) {
|
|
671
|
-
const c = ident[i];
|
|
672
|
-
quoted += c === quoteSign ? c + c : c;
|
|
673
|
-
}
|
|
674
|
-
quoted += quoteSign;
|
|
675
|
-
return quoted;
|
|
676
|
-
};
|
|
677
|
-
var DefaultMapSQLParamValueOptions = {
|
|
678
|
-
mapPlaceholder: mapANSISQLParamPlaceholder,
|
|
679
|
-
mapIdentifier: mapSQLIdentifier
|
|
680
|
-
};
|
|
681
|
-
var SQLValueMapper = (options) => {
|
|
682
|
-
const mapSQLParamValueOptions = {
|
|
683
|
-
...DefaultMapSQLParamValueOptions,
|
|
684
|
-
...options ?? {}
|
|
685
|
-
};
|
|
686
|
-
const resultMapper = {
|
|
687
|
-
mapValue: (value) => mapSQLParamValue(value, mapSQLParamValueOptions),
|
|
688
|
-
mapPlaceholder: mapSQLParamValueOptions.mapPlaceholder,
|
|
689
|
-
mapIdentifier: mapSQLParamValueOptions.mapIdentifier
|
|
690
|
-
};
|
|
691
|
-
return resultMapper;
|
|
692
|
-
};
|
|
693
|
-
function mapSQLParamValue(value, options) {
|
|
694
|
-
if (value === null || value === void 0) {
|
|
695
|
-
return null;
|
|
696
|
-
} else if (typeof value === "number") {
|
|
697
|
-
return value;
|
|
698
|
-
} else if (typeof value === "string") {
|
|
699
|
-
return value;
|
|
700
|
-
} else if (Array.isArray(value)) {
|
|
701
|
-
const mapValue = options?.mapValue ?? mapSQLParamValue;
|
|
702
|
-
return options?.mapArray ? options.mapArray(value, mapValue) : value.map((item) => mapValue(item, options));
|
|
703
|
-
} else if (typeof value === "boolean") {
|
|
704
|
-
return options?.mapBoolean ? options.mapBoolean(value) : value;
|
|
705
|
-
} else if (typeof value === "bigint") {
|
|
706
|
-
return options?.mapBigInt ? options.mapBigInt(value) : value.toString();
|
|
707
|
-
} else if (value instanceof Date) {
|
|
708
|
-
return options?.mapDate ? options.mapDate(value) : value.toISOString();
|
|
709
|
-
} else if (SQL.check.isIdentifier(value)) {
|
|
710
|
-
return (options?.mapIdentifier ?? mapSQLIdentifier)(value.value);
|
|
711
|
-
} else if (typeof value === "object") {
|
|
712
|
-
return options?.mapObject ? options.mapObject(value) : `${JSONSerializer.serialize(value).replace(/'/g, "''")}`;
|
|
713
|
-
} else {
|
|
714
|
-
return JSONSerializer.serialize(value);
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
// src/core/sql/formatters/sqlFormatter.ts
|
|
719
|
-
var SQLFormatter2 = ({
|
|
720
|
-
format,
|
|
721
|
-
describe,
|
|
722
|
-
valueMapper: valueMapperOptions,
|
|
723
|
-
processorsRegistry
|
|
724
|
-
}) => {
|
|
725
|
-
const valueMapper = SQLValueMapper(valueMapperOptions);
|
|
726
|
-
const options = {
|
|
727
|
-
builder: ParametrizedSQLBuilder({
|
|
728
|
-
mapParamPlaceholder: valueMapper.mapPlaceholder
|
|
729
|
-
}),
|
|
730
|
-
mapper: valueMapper,
|
|
731
|
-
processorsRegistry: processorsRegistry ?? defaultProcessorsRegistry
|
|
732
|
-
};
|
|
733
|
-
const resultFormatter = {
|
|
734
|
-
format: format ?? ((sql, methodOptions) => formatSQL(sql, resultFormatter, {
|
|
735
|
-
...options,
|
|
736
|
-
...methodOptions ?? {}
|
|
737
|
-
})),
|
|
738
|
-
describe: describe ?? ((sql, methodOptions) => describeSQL(sql, resultFormatter, {
|
|
739
|
-
...options,
|
|
740
|
-
...methodOptions ?? {}
|
|
741
|
-
})),
|
|
742
|
-
valueMapper
|
|
743
|
-
};
|
|
744
|
-
return resultFormatter;
|
|
745
|
-
};
|
|
746
|
-
var dumboSQLFormatters = globalThis.dumboSQLFormatters = globalThis.dumboSQLFormatters ?? {};
|
|
747
|
-
var registerFormatter = (dialect, formatter) => {
|
|
748
|
-
dumboSQLFormatters[dialect] = formatter;
|
|
749
|
-
};
|
|
750
|
-
var getFormatter = (dialect) => {
|
|
751
|
-
const formatterKey = dialect;
|
|
752
|
-
if (!dumboSQLFormatters[formatterKey]) {
|
|
753
|
-
throw new Error(`No SQL formatter registered for dialect: ${dialect}`);
|
|
754
|
-
}
|
|
755
|
-
return dumboSQLFormatters[formatterKey];
|
|
756
|
-
};
|
|
757
|
-
function formatSQL(sql, formatter, context) {
|
|
758
|
-
const mapper = context?.mapper == void 0 ? formatter.valueMapper : {
|
|
759
|
-
...formatter.valueMapper,
|
|
760
|
-
...context.mapper
|
|
761
|
-
};
|
|
762
|
-
const processorsRegistry = context?.processorsRegistry ?? defaultProcessorsRegistry;
|
|
763
|
-
const merged = Array.isArray(sql) ? SQL.merge(sql, "\n") : sql;
|
|
764
|
-
if (!isTokenizedSQL(merged)) {
|
|
765
|
-
throw new Error("Expected TokenizedSQL, got string-based SQL");
|
|
766
|
-
}
|
|
767
|
-
const builder = ParametrizedSQLBuilder({
|
|
768
|
-
mapParamPlaceholder: mapper.mapPlaceholder
|
|
769
|
-
});
|
|
770
|
-
let paramIndex = 0;
|
|
771
|
-
for (let i = 0; i < merged.sqlChunks.length; i++) {
|
|
772
|
-
const sqlChunk = merged.sqlChunks[i];
|
|
773
|
-
if (sqlChunk !== TokenizedSQL.paramPlaceholder) {
|
|
774
|
-
builder.addSQL(sqlChunk);
|
|
775
|
-
continue;
|
|
776
|
-
}
|
|
777
|
-
const token = merged.sqlTokens[paramIndex++];
|
|
778
|
-
const processor = processorsRegistry.get(token.sqlTokenType);
|
|
779
|
-
if (!processor) {
|
|
780
|
-
throw new Error(
|
|
781
|
-
`No SQL processor registered for token type: ${token.sqlTokenType}`
|
|
782
|
-
);
|
|
783
|
-
}
|
|
784
|
-
processor.handle(token, {
|
|
785
|
-
builder,
|
|
786
|
-
processorsRegistry,
|
|
787
|
-
mapper
|
|
788
|
-
});
|
|
789
|
-
}
|
|
790
|
-
return builder.build();
|
|
791
|
-
}
|
|
792
|
-
var describeSQL = (sql, formatter, options) => formatSQL(sql, formatter, {
|
|
793
|
-
...options ?? {},
|
|
794
|
-
mapper: {
|
|
795
|
-
mapPlaceholder: (_, value) => JSONSerializer.serialize(value)
|
|
796
|
-
}
|
|
797
|
-
}).query;
|
|
798
|
-
|
|
799
|
-
// src/core/execute/execute.ts
|
|
800
|
-
var mapColumnToJSON = (column, options) => ({
|
|
801
|
-
[column]: (value) => {
|
|
802
|
-
if (typeof value === "string") {
|
|
803
|
-
try {
|
|
804
|
-
return JSONSerializer.deserialize(value, options);
|
|
805
|
-
} catch {
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
return value;
|
|
809
|
-
}
|
|
810
|
-
});
|
|
811
|
-
var mapColumnToBigint = (column) => ({
|
|
812
|
-
[column]: (value) => {
|
|
813
|
-
if (typeof value === "number" || typeof value === "string") {
|
|
814
|
-
return BigInt(value);
|
|
815
|
-
}
|
|
816
|
-
return value;
|
|
817
|
-
}
|
|
818
|
-
});
|
|
819
|
-
var mapSQLQueryResult = (result, mapping) => {
|
|
820
|
-
if (typeof result !== "object" || result === null) return result;
|
|
821
|
-
const mappedResult = {
|
|
822
|
-
...result
|
|
823
|
-
};
|
|
824
|
-
for (const column of Object.keys(mapping)) {
|
|
825
|
-
if (column in mappedResult) {
|
|
826
|
-
mappedResult[column] = mapping[column](mappedResult[column]);
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
return mappedResult;
|
|
830
|
-
};
|
|
831
|
-
var sqlExecutor = (sqlExecutor2, options) => ({
|
|
832
|
-
query: (sql, queryOptions) => executeInNewDbClient(
|
|
833
|
-
(client) => sqlExecutor2.query(client, sql, queryOptions),
|
|
834
|
-
options
|
|
835
|
-
),
|
|
836
|
-
batchQuery: (sqls, queryOptions) => executeInNewDbClient(
|
|
837
|
-
(client) => sqlExecutor2.batchQuery(client, sqls, queryOptions),
|
|
838
|
-
options
|
|
839
|
-
),
|
|
840
|
-
command: (sql, commandOptions) => executeInNewDbClient(
|
|
841
|
-
(client) => sqlExecutor2.command(client, sql, commandOptions),
|
|
842
|
-
options
|
|
843
|
-
),
|
|
844
|
-
batchCommand: (sqls, commandOptions) => executeInNewDbClient(
|
|
845
|
-
(client) => sqlExecutor2.batchCommand(client, sqls, commandOptions),
|
|
846
|
-
options
|
|
847
|
-
)
|
|
848
|
-
});
|
|
849
|
-
var sqlExecutorInNewConnection = (options) => ({
|
|
850
|
-
query: (sql, queryOptions) => executeInNewConnection(
|
|
851
|
-
(connection) => connection.execute.query(sql, queryOptions),
|
|
852
|
-
options
|
|
853
|
-
),
|
|
854
|
-
batchQuery: (sqls, queryOptions) => executeInNewConnection(
|
|
855
|
-
(connection) => connection.execute.batchQuery(sqls, queryOptions),
|
|
856
|
-
options
|
|
857
|
-
),
|
|
858
|
-
command: (sql, commandOptions) => executeInNewConnection(
|
|
859
|
-
(connection) => connection.execute.command(sql, commandOptions),
|
|
860
|
-
options
|
|
861
|
-
),
|
|
862
|
-
batchCommand: (sqls, commandOptions) => executeInNewConnection(
|
|
863
|
-
(connection) => connection.execute.batchCommand(sqls, commandOptions),
|
|
864
|
-
options
|
|
865
|
-
)
|
|
866
|
-
});
|
|
867
|
-
var sqlExecutorInAmbientConnection = (options) => ({
|
|
868
|
-
query: (sql, queryOptions) => executeInAmbientConnection(
|
|
869
|
-
(connection) => connection.execute.query(sql, queryOptions),
|
|
870
|
-
options
|
|
871
|
-
),
|
|
872
|
-
batchQuery: (sqls, queryOptions) => executeInAmbientConnection(
|
|
873
|
-
(connection) => connection.execute.batchQuery(sqls, queryOptions),
|
|
874
|
-
options
|
|
875
|
-
),
|
|
876
|
-
command: (sql, commandOptions) => executeInAmbientConnection(
|
|
877
|
-
(connection) => connection.execute.command(sql, commandOptions),
|
|
878
|
-
options
|
|
879
|
-
),
|
|
880
|
-
batchCommand: (sqls, commandOptions) => executeInAmbientConnection(
|
|
881
|
-
(connection) => connection.execute.batchCommand(sqls, commandOptions),
|
|
882
|
-
options
|
|
883
|
-
)
|
|
884
|
-
});
|
|
885
|
-
var executeInNewDbClient = async (handle, options) => {
|
|
886
|
-
const { connect, close } = options;
|
|
887
|
-
const client = await connect();
|
|
888
|
-
try {
|
|
889
|
-
return await handle(client);
|
|
890
|
-
} catch (error) {
|
|
891
|
-
if (close) await close(client, error);
|
|
892
|
-
throw error;
|
|
893
|
-
}
|
|
894
|
-
};
|
|
895
|
-
var executeInNewConnection = async (handle, options) => {
|
|
896
|
-
const connection = await options.connection();
|
|
897
|
-
try {
|
|
898
|
-
return await handle(connection);
|
|
899
|
-
} finally {
|
|
900
|
-
await connection.close();
|
|
901
|
-
}
|
|
902
|
-
};
|
|
903
|
-
var executeInAmbientConnection = async (handle, options) => {
|
|
904
|
-
const connection = await options.connection();
|
|
905
|
-
try {
|
|
906
|
-
return await handle(connection);
|
|
907
|
-
} finally {
|
|
908
|
-
}
|
|
909
|
-
};
|
|
910
|
-
|
|
911
|
-
// src/core/connections/transaction.ts
|
|
912
|
-
var toTransactionResult = (transactionResult) => transactionResult !== void 0 && transactionResult !== null && typeof transactionResult === "object" && "success" in transactionResult ? transactionResult : { success: true, result: transactionResult };
|
|
913
|
-
var executeInTransaction = async (transaction, handle) => {
|
|
914
|
-
await transaction.begin();
|
|
915
|
-
try {
|
|
916
|
-
const { success, result } = toTransactionResult(await handle(transaction));
|
|
917
|
-
if (success) await transaction.commit();
|
|
918
|
-
else await transaction.rollback();
|
|
919
|
-
return result;
|
|
920
|
-
} catch (e) {
|
|
921
|
-
await transaction.rollback();
|
|
922
|
-
throw e;
|
|
923
|
-
}
|
|
924
|
-
};
|
|
925
|
-
var transactionFactoryWithDbClient = (connect, initTransaction) => {
|
|
926
|
-
let currentTransaction = void 0;
|
|
927
|
-
const getOrInitCurrentTransaction = (options) => currentTransaction ?? (currentTransaction = initTransaction(connect(), {
|
|
928
|
-
close: () => {
|
|
929
|
-
currentTransaction = void 0;
|
|
930
|
-
return Promise.resolve();
|
|
931
|
-
},
|
|
932
|
-
...options ?? {}
|
|
933
|
-
}));
|
|
934
|
-
return {
|
|
935
|
-
transaction: getOrInitCurrentTransaction,
|
|
936
|
-
withTransaction: (handle, options) => executeInTransaction(getOrInitCurrentTransaction(options), handle)
|
|
937
|
-
};
|
|
938
|
-
};
|
|
939
|
-
var wrapInConnectionClosure = async (connection, handle) => {
|
|
940
|
-
try {
|
|
941
|
-
return await handle();
|
|
942
|
-
} finally {
|
|
943
|
-
await connection.close();
|
|
944
|
-
}
|
|
945
|
-
};
|
|
946
|
-
var transactionFactoryWithNewConnection = (connect) => ({
|
|
947
|
-
transaction: (options) => {
|
|
948
|
-
const connection = connect();
|
|
949
|
-
const transaction = connection.transaction(options);
|
|
950
|
-
return {
|
|
951
|
-
...transaction,
|
|
952
|
-
commit: () => wrapInConnectionClosure(connection, () => transaction.commit()),
|
|
953
|
-
rollback: () => wrapInConnectionClosure(connection, () => transaction.rollback())
|
|
954
|
-
};
|
|
955
|
-
},
|
|
956
|
-
withTransaction: (handle, options) => {
|
|
957
|
-
const connection = connect();
|
|
958
|
-
return wrapInConnectionClosure(
|
|
959
|
-
connection,
|
|
960
|
-
() => connection.withTransaction(handle, options)
|
|
961
|
-
);
|
|
962
|
-
}
|
|
963
|
-
});
|
|
964
|
-
var transactionFactoryWithAmbientConnection = (connect) => ({
|
|
965
|
-
transaction: (options) => {
|
|
966
|
-
const connection = connect();
|
|
967
|
-
const transaction = connection.transaction(options);
|
|
968
|
-
return {
|
|
969
|
-
...transaction,
|
|
970
|
-
commit: () => transaction.commit(),
|
|
971
|
-
rollback: () => transaction.rollback()
|
|
972
|
-
};
|
|
973
|
-
},
|
|
974
|
-
withTransaction: (handle, options) => {
|
|
975
|
-
const connection = connect();
|
|
976
|
-
return connection.withTransaction(handle, options);
|
|
977
|
-
}
|
|
978
|
-
});
|
|
979
|
-
|
|
980
|
-
// src/core/connections/connection.ts
|
|
981
|
-
var createAmbientConnection = (options) => {
|
|
982
|
-
const { driverType, client, executor, initTransaction } = options;
|
|
983
|
-
const clientPromise = Promise.resolve(client);
|
|
984
|
-
const closePromise = Promise.resolve();
|
|
985
|
-
const open = () => clientPromise;
|
|
986
|
-
const close = () => closePromise;
|
|
987
|
-
const connection = {
|
|
988
|
-
driverType,
|
|
989
|
-
open,
|
|
990
|
-
close,
|
|
991
|
-
...transactionFactoryWithDbClient(
|
|
992
|
-
open,
|
|
993
|
-
initTransaction(() => typedConnection)
|
|
994
|
-
),
|
|
995
|
-
execute: sqlExecutor(executor(), { connect: open })
|
|
996
|
-
};
|
|
997
|
-
const typedConnection = connection;
|
|
998
|
-
return typedConnection;
|
|
999
|
-
};
|
|
1000
|
-
var createSingletonConnection = (options) => {
|
|
1001
|
-
const { driverType, connect, close, initTransaction, executor } = options;
|
|
1002
|
-
let client = null;
|
|
1003
|
-
let connectPromise = null;
|
|
1004
|
-
const getClient = async () => {
|
|
1005
|
-
if (client) return client;
|
|
1006
|
-
if (!connectPromise) {
|
|
1007
|
-
connectPromise = connect().then((c) => {
|
|
1008
|
-
client = c;
|
|
1009
|
-
return c;
|
|
1010
|
-
});
|
|
1011
|
-
}
|
|
1012
|
-
return connectPromise;
|
|
1013
|
-
};
|
|
1014
|
-
const connection = {
|
|
1015
|
-
driverType,
|
|
1016
|
-
open: getClient,
|
|
1017
|
-
close: () => client ? close(client) : Promise.resolve(),
|
|
1018
|
-
...transactionFactoryWithDbClient(
|
|
1019
|
-
getClient,
|
|
1020
|
-
initTransaction(() => typedConnection)
|
|
1021
|
-
),
|
|
1022
|
-
execute: sqlExecutor(executor(), { connect: getClient })
|
|
1023
|
-
};
|
|
1024
|
-
const typedConnection = connection;
|
|
1025
|
-
return typedConnection;
|
|
1026
|
-
};
|
|
1027
|
-
var createTransientConnection = (options) => {
|
|
1028
|
-
const { driverType, open, close, initTransaction, executor } = options;
|
|
1029
|
-
const connection = {
|
|
1030
|
-
driverType,
|
|
1031
|
-
open,
|
|
1032
|
-
close,
|
|
1033
|
-
...transactionFactoryWithDbClient(
|
|
1034
|
-
open,
|
|
1035
|
-
initTransaction(() => typedConnection)
|
|
1036
|
-
),
|
|
1037
|
-
execute: sqlExecutor(executor(), { connect: open })
|
|
1038
|
-
};
|
|
1039
|
-
const typedConnection = connection;
|
|
1040
|
-
return typedConnection;
|
|
1041
|
-
};
|
|
1042
|
-
var createConnection = (options) => {
|
|
1043
|
-
const { driverType, connect, close, initTransaction, executor } = options;
|
|
1044
|
-
let client = null;
|
|
1045
|
-
let connectPromise = null;
|
|
1046
|
-
const getClient = async () => {
|
|
1047
|
-
if (client) return client;
|
|
1048
|
-
if (!connectPromise) {
|
|
1049
|
-
connectPromise = connect().then((c) => {
|
|
1050
|
-
client = c;
|
|
1051
|
-
return c;
|
|
1052
|
-
});
|
|
1053
|
-
}
|
|
1054
|
-
return connectPromise;
|
|
1055
|
-
};
|
|
1056
|
-
const connection = {
|
|
1057
|
-
driverType,
|
|
1058
|
-
open: getClient,
|
|
1059
|
-
close: () => client ? close(client) : Promise.resolve(),
|
|
1060
|
-
...transactionFactoryWithDbClient(
|
|
1061
|
-
getClient,
|
|
1062
|
-
initTransaction(() => typedConnection)
|
|
1063
|
-
),
|
|
1064
|
-
execute: sqlExecutor(executor(), { connect: getClient })
|
|
1065
|
-
};
|
|
1066
|
-
const typedConnection = connection;
|
|
1067
|
-
return typedConnection;
|
|
1068
|
-
};
|
|
1069
|
-
|
|
1070
|
-
// src/core/connections/pool.ts
|
|
1071
|
-
var createAmbientConnectionPool = (options) => {
|
|
1072
|
-
const { driverType, connection } = options;
|
|
1073
|
-
return createConnectionPool({
|
|
1074
|
-
driverType,
|
|
1075
|
-
getConnection: () => connection,
|
|
1076
|
-
execute: connection.execute,
|
|
1077
|
-
transaction: (options2) => connection.transaction(options2),
|
|
1078
|
-
withTransaction: (handle, options2) => connection.withTransaction(handle, options2)
|
|
1079
|
-
});
|
|
1080
|
-
};
|
|
1081
|
-
var createSingletonConnectionPool = (options) => {
|
|
1082
|
-
const { driverType, getConnection } = options;
|
|
1083
|
-
let connection = null;
|
|
1084
|
-
const getExistingOrNewConnection = () => connection ?? (connection = getConnection());
|
|
1085
|
-
const getExistingOrNewConnectionAsync = () => Promise.resolve(getExistingOrNewConnection());
|
|
1086
|
-
const result = {
|
|
1087
|
-
driverType,
|
|
1088
|
-
connection: getExistingOrNewConnectionAsync,
|
|
1089
|
-
execute: sqlExecutorInAmbientConnection({
|
|
1090
|
-
driverType,
|
|
1091
|
-
connection: getExistingOrNewConnectionAsync
|
|
1092
|
-
}),
|
|
1093
|
-
withConnection: (handle) => executeInAmbientConnection(handle, {
|
|
1094
|
-
connection: getExistingOrNewConnectionAsync
|
|
1095
|
-
}),
|
|
1096
|
-
...transactionFactoryWithAmbientConnection(getExistingOrNewConnection),
|
|
1097
|
-
close: () => {
|
|
1098
|
-
return connection !== null ? connection.close() : Promise.resolve();
|
|
1099
|
-
}
|
|
1100
|
-
};
|
|
1101
|
-
return result;
|
|
1102
|
-
};
|
|
1103
|
-
var createSingletonClientPool = (options) => {
|
|
1104
|
-
const { driverType, dbClient } = options;
|
|
1105
|
-
return createSingletonConnectionPool({
|
|
1106
|
-
getConnection: () => options.connectionFactory({ dbClient }),
|
|
1107
|
-
driverType
|
|
1108
|
-
});
|
|
1109
|
-
};
|
|
1110
|
-
var createAlwaysNewConnectionPool = (options) => {
|
|
1111
|
-
const { driverType, getConnection, connectionOptions } = options;
|
|
1112
|
-
return createConnectionPool({
|
|
1113
|
-
driverType,
|
|
1114
|
-
getConnection: () => connectionOptions ? getConnection(connectionOptions) : getConnection()
|
|
1115
|
-
});
|
|
1116
|
-
};
|
|
1117
|
-
var createConnectionPool = (pool) => {
|
|
1118
|
-
const { driverType, getConnection } = pool;
|
|
1119
|
-
const connection = "connection" in pool ? pool.connection : () => Promise.resolve(getConnection());
|
|
1120
|
-
const withConnection = "withConnection" in pool ? pool.withConnection : (handle) => executeInNewConnection(handle, {
|
|
1121
|
-
connection
|
|
1122
|
-
});
|
|
1123
|
-
const close = "close" in pool ? pool.close : () => Promise.resolve();
|
|
1124
|
-
const execute = "execute" in pool ? pool.execute : sqlExecutorInNewConnection({
|
|
1125
|
-
driverType,
|
|
1126
|
-
connection
|
|
1127
|
-
});
|
|
1128
|
-
const transaction = "transaction" in pool && "withTransaction" in pool ? {
|
|
1129
|
-
transaction: pool.transaction,
|
|
1130
|
-
withTransaction: pool.withTransaction
|
|
1131
|
-
} : transactionFactoryWithNewConnection(getConnection);
|
|
1132
|
-
const result = {
|
|
1133
|
-
driverType,
|
|
1134
|
-
connection,
|
|
1135
|
-
withConnection,
|
|
1136
|
-
close,
|
|
1137
|
-
execute,
|
|
1138
|
-
...transaction
|
|
1139
|
-
};
|
|
1140
|
-
return result;
|
|
1141
|
-
};
|
|
1142
|
-
|
|
1143
|
-
// src/core/schema/sqlMigration.ts
|
|
1144
|
-
var sqlMigration = (name, sqls) => ({
|
|
1145
|
-
name,
|
|
1146
|
-
sqls
|
|
1147
|
-
});
|
|
1148
|
-
|
|
1149
|
-
// src/core/schema/schemaComponent.ts
|
|
1150
|
-
var schemaComponent = (key, options) => {
|
|
1151
|
-
const componentsMap = new Map(
|
|
1152
|
-
options.components?.map((comp) => [comp.schemaComponentKey, comp])
|
|
1153
|
-
);
|
|
1154
|
-
const migrations = [...options.migrations ?? []];
|
|
1155
|
-
return {
|
|
1156
|
-
schemaComponentKey: key,
|
|
1157
|
-
components: componentsMap,
|
|
1158
|
-
get migrations() {
|
|
1159
|
-
return [
|
|
1160
|
-
...migrations,
|
|
1161
|
-
...Array.from(componentsMap.values()).flatMap((c) => c.migrations)
|
|
1162
|
-
];
|
|
1163
|
-
},
|
|
1164
|
-
addComponent: (component) => {
|
|
1165
|
-
componentsMap.set(component.schemaComponentKey, component);
|
|
1166
|
-
migrations.push(...component.migrations);
|
|
1167
|
-
return component;
|
|
1168
|
-
},
|
|
1169
|
-
addMigration: (migration) => {
|
|
1170
|
-
migrations.push(migration);
|
|
1171
|
-
}
|
|
1172
|
-
};
|
|
1173
|
-
};
|
|
1174
|
-
var isSchemaComponentOfType = (component, prefix) => component.schemaComponentKey.startsWith(prefix);
|
|
1175
|
-
var filterSchemaComponentsOfType = (components, prefix) => mapSchemaComponentsOfType(components, prefix);
|
|
1176
|
-
var mapSchemaComponentsOfType = (components, prefix, keyMapper) => new Map(
|
|
1177
|
-
Array.from(components.entries()).filter(([urn]) => urn.startsWith(prefix)).map(([urn, component]) => [
|
|
1178
|
-
keyMapper ? keyMapper(component) : urn,
|
|
1179
|
-
component
|
|
1180
|
-
])
|
|
1181
|
-
);
|
|
1182
|
-
var findSchemaComponentsOfType = (root, prefix) => {
|
|
1183
|
-
const results = [];
|
|
1184
|
-
const traverse = (component) => {
|
|
1185
|
-
if (component.schemaComponentKey.startsWith(prefix)) {
|
|
1186
|
-
results.push(component);
|
|
1187
|
-
}
|
|
1188
|
-
for (const child of component.components.values()) {
|
|
1189
|
-
traverse(child);
|
|
1190
|
-
}
|
|
1191
|
-
};
|
|
1192
|
-
traverse(root);
|
|
1193
|
-
return results;
|
|
1194
|
-
};
|
|
1195
|
-
|
|
1196
|
-
// src/core/schema/components/columnSchemaComponent.ts
|
|
1197
|
-
var ColumnURNType = "sc:dumbo:column";
|
|
1198
|
-
var ColumnURN = ({
|
|
1199
|
-
name
|
|
1200
|
-
}) => `${ColumnURNType}:${name}`;
|
|
1201
|
-
var columnSchemaComponent = (params) => {
|
|
1202
|
-
const {
|
|
1203
|
-
columnName,
|
|
1204
|
-
type,
|
|
1205
|
-
notNull,
|
|
1206
|
-
unique,
|
|
1207
|
-
primaryKey,
|
|
1208
|
-
default: defaultValue,
|
|
1209
|
-
...schemaOptions
|
|
1210
|
-
} = params;
|
|
1211
|
-
const sc = schemaComponent(ColumnURN({ name: columnName }), schemaOptions);
|
|
1212
|
-
const result = {
|
|
1213
|
-
...sc,
|
|
1214
|
-
columnName,
|
|
1215
|
-
notNull,
|
|
1216
|
-
unique,
|
|
1217
|
-
primaryKey,
|
|
1218
|
-
defaultValue,
|
|
1219
|
-
sqlTokenType: "SQL_COLUMN",
|
|
1220
|
-
name: columnName,
|
|
1221
|
-
type
|
|
1222
|
-
};
|
|
1223
|
-
return result;
|
|
1224
|
-
};
|
|
1225
|
-
|
|
1226
|
-
// src/core/schema/components/indexSchemaComponent.ts
|
|
1227
|
-
var IndexURNType = "sc:dumbo:index";
|
|
1228
|
-
var IndexURN = ({ name }) => `${IndexURNType}:${name}`;
|
|
1229
|
-
var indexSchemaComponent = ({
|
|
1230
|
-
indexName,
|
|
1231
|
-
columnNames,
|
|
1232
|
-
isUnique,
|
|
1233
|
-
...migrationsOrComponents
|
|
1234
|
-
}) => {
|
|
1235
|
-
const sc = schemaComponent(IndexURN({ name: indexName }), {
|
|
1236
|
-
migrations: migrationsOrComponents.migrations ?? [],
|
|
1237
|
-
components: [...migrationsOrComponents.components ?? []]
|
|
1238
|
-
});
|
|
1239
|
-
return {
|
|
1240
|
-
...sc,
|
|
1241
|
-
indexName,
|
|
1242
|
-
get columnNames() {
|
|
1243
|
-
return columnNames;
|
|
1244
|
-
},
|
|
1245
|
-
addColumn: (column) => columnNames.push(typeof column === "string" ? column : column.columnName),
|
|
1246
|
-
isUnique
|
|
1247
|
-
};
|
|
1248
|
-
};
|
|
1249
|
-
|
|
1250
|
-
// src/core/schema/components/tableSchemaComponent.ts
|
|
1251
|
-
var TableURNType = "sc:dumbo:table";
|
|
1252
|
-
var TableURN = ({ name }) => `${TableURNType}:${name}`;
|
|
1253
|
-
var tableSchemaComponent = ({
|
|
1254
|
-
tableName,
|
|
1255
|
-
columns,
|
|
1256
|
-
primaryKey,
|
|
1257
|
-
relationships,
|
|
1258
|
-
...migrationsOrComponents
|
|
1259
|
-
}) => {
|
|
1260
|
-
columns ??= {};
|
|
1261
|
-
relationships ??= {};
|
|
1262
|
-
const base = schemaComponent(TableURN({ name: tableName }), {
|
|
1263
|
-
migrations: migrationsOrComponents.migrations ?? [],
|
|
1264
|
-
components: [
|
|
1265
|
-
...migrationsOrComponents.components ?? [],
|
|
1266
|
-
...Object.values(columns)
|
|
1267
|
-
]
|
|
1268
|
-
});
|
|
1269
|
-
return {
|
|
1270
|
-
...base,
|
|
1271
|
-
tableName,
|
|
1272
|
-
primaryKey: primaryKey ?? [],
|
|
1273
|
-
relationships,
|
|
1274
|
-
get columns() {
|
|
1275
|
-
const columnsMap = mapSchemaComponentsOfType(
|
|
1276
|
-
base.components,
|
|
1277
|
-
ColumnURNType,
|
|
1278
|
-
(c) => c.columnName
|
|
1279
|
-
);
|
|
1280
|
-
return Object.assign(columnsMap, columns);
|
|
1281
|
-
},
|
|
1282
|
-
get indexes() {
|
|
1283
|
-
return mapSchemaComponentsOfType(
|
|
1284
|
-
base.components,
|
|
1285
|
-
IndexURNType,
|
|
1286
|
-
(c) => c.indexName
|
|
1287
|
-
);
|
|
1288
|
-
},
|
|
1289
|
-
addColumn: (column) => base.addComponent(column),
|
|
1290
|
-
addIndex: (index) => base.addComponent(index)
|
|
1291
|
-
};
|
|
1292
|
-
};
|
|
1293
|
-
|
|
1294
|
-
// src/core/schema/components/databaseSchemaSchemaComponent.ts
|
|
1295
|
-
var DatabaseSchemaURNType = "sc:dumbo:database_schema";
|
|
1296
|
-
var DatabaseSchemaURN = ({
|
|
1297
|
-
name
|
|
1298
|
-
}) => `${DatabaseSchemaURNType}:${name}`;
|
|
1299
|
-
var databaseSchemaSchemaComponent = ({
|
|
1300
|
-
schemaName,
|
|
1301
|
-
tables,
|
|
1302
|
-
...migrationsOrComponents
|
|
1303
|
-
}) => {
|
|
1304
|
-
const base = schemaComponent(DatabaseSchemaURN({ name: schemaName }), {
|
|
1305
|
-
migrations: migrationsOrComponents.migrations ?? [],
|
|
1306
|
-
components: [
|
|
1307
|
-
...migrationsOrComponents.components ?? [],
|
|
1308
|
-
...Object.values(tables ?? {})
|
|
1309
|
-
]
|
|
1310
|
-
});
|
|
1311
|
-
return {
|
|
1312
|
-
...base,
|
|
1313
|
-
schemaName,
|
|
1314
|
-
get tables() {
|
|
1315
|
-
const tablesMap = mapSchemaComponentsOfType(
|
|
1316
|
-
base.components,
|
|
1317
|
-
TableURNType,
|
|
1318
|
-
(c) => c.tableName
|
|
1319
|
-
);
|
|
1320
|
-
return Object.assign(tablesMap, tables);
|
|
1321
|
-
},
|
|
1322
|
-
addTable: (table) => base.addComponent(
|
|
1323
|
-
typeof table === "string" ? tableSchemaComponent({ tableName: table }) : table
|
|
1324
|
-
)
|
|
1325
|
-
};
|
|
1326
|
-
};
|
|
1327
|
-
|
|
1328
|
-
// src/core/schema/components/databaseSchemaComponent.ts
|
|
1329
|
-
var DatabaseURNType = "sc:dumbo:database";
|
|
1330
|
-
var DatabaseURN = ({ name }) => `${DatabaseURNType}:${name}`;
|
|
1331
|
-
var databaseSchemaComponent = ({
|
|
1332
|
-
databaseName,
|
|
1333
|
-
schemas,
|
|
1334
|
-
...migrationsOrComponents
|
|
1335
|
-
}) => {
|
|
1336
|
-
schemas ??= {};
|
|
1337
|
-
const base = schemaComponent(DatabaseURN({ name: databaseName }), {
|
|
1338
|
-
migrations: migrationsOrComponents.migrations ?? [],
|
|
1339
|
-
components: [
|
|
1340
|
-
...migrationsOrComponents.components ?? [],
|
|
1341
|
-
...Object.values(schemas)
|
|
1342
|
-
]
|
|
1343
|
-
});
|
|
1344
|
-
return {
|
|
1345
|
-
...base,
|
|
1346
|
-
databaseName,
|
|
1347
|
-
get schemas() {
|
|
1348
|
-
const schemasMap = mapSchemaComponentsOfType(
|
|
1349
|
-
base.components,
|
|
1350
|
-
DatabaseSchemaURNType,
|
|
1351
|
-
(c) => c.schemaName
|
|
1352
|
-
);
|
|
1353
|
-
return Object.assign(schemasMap, schemas);
|
|
1354
|
-
},
|
|
1355
|
-
addSchema: (schema) => base.addComponent(
|
|
1356
|
-
typeof schema === "string" ? databaseSchemaSchemaComponent({ schemaName: schema }) : schema
|
|
1357
|
-
)
|
|
1358
|
-
};
|
|
1359
|
-
};
|
|
1360
|
-
|
|
1361
|
-
// src/core/schema/components/relationships/relationshipTypes.ts
|
|
1362
|
-
var relationship = (columns, references, type) => {
|
|
1363
|
-
return {
|
|
1364
|
-
columns,
|
|
1365
|
-
references,
|
|
1366
|
-
type
|
|
1367
|
-
};
|
|
1368
|
-
};
|
|
1369
|
-
|
|
1370
|
-
// src/core/schema/components/index.ts
|
|
1371
|
-
var schemaComponentURN = {
|
|
1372
|
-
database: DatabaseURN,
|
|
1373
|
-
schema: DatabaseSchemaURN,
|
|
1374
|
-
table: TableURN,
|
|
1375
|
-
column: ColumnURN,
|
|
1376
|
-
index: IndexURN,
|
|
1377
|
-
extractName: (urn) => {
|
|
1378
|
-
const parts = urn.split(":");
|
|
1379
|
-
return parts[parts.length - 1] || "";
|
|
1380
|
-
}
|
|
1381
|
-
};
|
|
1382
|
-
|
|
1383
|
-
// src/core/schema/dumboSchema/dumboSchema.ts
|
|
1384
|
-
var DEFAULT_DATABASE_NAME = "__default_database__";
|
|
1385
|
-
var DEFAULT_DATABASE_SCHEMA_NAME = "__default_database_schema__";
|
|
1386
|
-
var dumboColumn = (name, type, options) => columnSchemaComponent({
|
|
1387
|
-
columnName: name,
|
|
1388
|
-
type,
|
|
1389
|
-
...options
|
|
1390
|
-
});
|
|
1391
|
-
var dumboIndex = (name, columnNames, options) => indexSchemaComponent({
|
|
1392
|
-
indexName: name,
|
|
1393
|
-
columnNames,
|
|
1394
|
-
isUnique: options?.unique ?? false,
|
|
1395
|
-
...options
|
|
1396
|
-
});
|
|
1397
|
-
var dumboTable = (name, definition) => {
|
|
1398
|
-
const { columns, indexes, primaryKey, relationships, ...options } = definition;
|
|
1399
|
-
const components = [...indexes ? Object.values(indexes) : []];
|
|
1400
|
-
return tableSchemaComponent({
|
|
1401
|
-
tableName: name,
|
|
1402
|
-
columns: columns ?? {},
|
|
1403
|
-
primaryKey: primaryKey ?? [],
|
|
1404
|
-
...relationships !== void 0 ? { relationships } : {},
|
|
1405
|
-
components,
|
|
1406
|
-
...options
|
|
1407
|
-
});
|
|
1408
|
-
};
|
|
1409
|
-
function dumboDatabaseSchema(nameOrTables, tables, options) {
|
|
1410
|
-
const schemaName = typeof nameOrTables === "string" ? nameOrTables : DEFAULT_DATABASE_SCHEMA_NAME;
|
|
1411
|
-
const tablesMap = (typeof nameOrTables === "string" ? tables : nameOrTables) ?? {};
|
|
1412
|
-
return databaseSchemaSchemaComponent({
|
|
1413
|
-
schemaName,
|
|
1414
|
-
tables: tablesMap,
|
|
1415
|
-
...options
|
|
1416
|
-
});
|
|
1417
|
-
}
|
|
1418
|
-
dumboDatabaseSchema.from = (schemaName, tableNames) => {
|
|
1419
|
-
const tables = tableNames.reduce(
|
|
1420
|
-
(acc, tableName) => {
|
|
1421
|
-
acc[tableName] = dumboTable(tableName, {});
|
|
1422
|
-
return acc;
|
|
1423
|
-
},
|
|
1424
|
-
{}
|
|
1425
|
-
);
|
|
1426
|
-
return schemaName ? dumboDatabaseSchema(schemaName, tables) : dumboDatabaseSchema(tables);
|
|
1427
|
-
};
|
|
1428
|
-
function dumboDatabase(nameOrSchemas, schemasOrOptions, options) {
|
|
1429
|
-
const databaseName = typeof nameOrSchemas === "string" ? nameOrSchemas : DEFAULT_DATABASE_NAME;
|
|
1430
|
-
const schemasOrSchema = typeof nameOrSchemas === "string" ? schemasOrOptions ?? {} : nameOrSchemas;
|
|
1431
|
-
const schemaMap = "schemaComponentKey" in schemasOrSchema && isSchemaComponentOfType(
|
|
1432
|
-
schemasOrSchema,
|
|
1433
|
-
"sc:dumbo:database_schema"
|
|
1434
|
-
) ? {
|
|
1435
|
-
[DEFAULT_DATABASE_SCHEMA_NAME]: schemasOrSchema
|
|
1436
|
-
} : schemasOrSchema;
|
|
1437
|
-
const dbOptions = typeof nameOrSchemas === "string" ? options : schemasOrOptions;
|
|
1438
|
-
return databaseSchemaComponent({
|
|
1439
|
-
databaseName,
|
|
1440
|
-
schemas: schemaMap,
|
|
1441
|
-
...dbOptions
|
|
1442
|
-
});
|
|
1443
|
-
}
|
|
1444
|
-
dumboDatabase.from = (databaseName, schemaNames) => {
|
|
1445
|
-
const schemas = schemaNames.reduce(
|
|
1446
|
-
(acc, schemaName) => {
|
|
1447
|
-
acc[schemaName] = dumboDatabaseSchema(
|
|
1448
|
-
schemaName,
|
|
1449
|
-
{}
|
|
1450
|
-
);
|
|
1451
|
-
return acc;
|
|
1452
|
-
},
|
|
1453
|
-
{}
|
|
1454
|
-
);
|
|
1455
|
-
return databaseName ? dumboDatabase(databaseName, schemas) : dumboDatabase(schemas);
|
|
1456
|
-
};
|
|
1457
|
-
dumboDatabase.defaultName = DEFAULT_DATABASE_NAME;
|
|
1458
|
-
dumboDatabaseSchema.defaultName = DEFAULT_DATABASE_SCHEMA_NAME;
|
|
1459
|
-
var dumboSchema = {
|
|
1460
|
-
database: dumboDatabase,
|
|
1461
|
-
schema: dumboDatabaseSchema,
|
|
1462
|
-
table: dumboTable,
|
|
1463
|
-
column: dumboColumn,
|
|
1464
|
-
index: dumboIndex
|
|
1465
|
-
};
|
|
1466
|
-
|
|
1467
|
-
// src/core/locks/databaseLock.ts
|
|
1468
|
-
var defaultDatabaseLockOptions = {
|
|
1469
|
-
timeoutMs: 1e4
|
|
1470
|
-
};
|
|
1471
|
-
var NoDatabaseLock = {
|
|
1472
|
-
acquire: () => Promise.resolve(),
|
|
1473
|
-
tryAcquire: () => Promise.resolve(true),
|
|
1474
|
-
release: () => Promise.resolve(true),
|
|
1475
|
-
withAcquire: (_execute, handle, _options) => handle()
|
|
1476
|
-
};
|
|
1477
|
-
|
|
1478
|
-
// src/core/query/mappers.ts
|
|
1479
|
-
var mapRows = async (getResult, map) => {
|
|
1480
|
-
const result = await getResult;
|
|
1481
|
-
return result.rows.map(map);
|
|
1482
|
-
};
|
|
1483
|
-
var toCamelCase = (snakeStr) => snakeStr.replace(/_([a-z])/g, (g) => g[1]?.toUpperCase() ?? "");
|
|
1484
|
-
var mapToCamelCase = (obj) => {
|
|
1485
|
-
const newObj = {};
|
|
1486
|
-
for (const key in obj) {
|
|
1487
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
1488
|
-
newObj[toCamelCase(key)] = obj[key];
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
return newObj;
|
|
1492
|
-
};
|
|
1493
|
-
|
|
1494
|
-
// src/core/query/selectors.ts
|
|
1495
|
-
var firstOrNull = async (getResult) => {
|
|
1496
|
-
const result = await getResult;
|
|
1497
|
-
return result.rows.length > 0 ? result.rows[0] ?? null : null;
|
|
1498
|
-
};
|
|
1499
|
-
var first = async (getResult) => {
|
|
1500
|
-
const result = await getResult;
|
|
1501
|
-
if (result.rows.length === 0)
|
|
1502
|
-
throw new Error("Query didn't return any result");
|
|
1503
|
-
return result.rows[0];
|
|
1504
|
-
};
|
|
1505
|
-
var singleOrNull = async (getResult) => {
|
|
1506
|
-
const result = await getResult;
|
|
1507
|
-
if (result.rows.length > 1) throw new Error("Query had more than one result");
|
|
1508
|
-
return result.rows.length > 0 ? result.rows[0] ?? null : null;
|
|
1509
|
-
};
|
|
1510
|
-
var single = async (getResult) => {
|
|
1511
|
-
const result = await getResult;
|
|
1512
|
-
if (result.rows.length === 0)
|
|
1513
|
-
throw new Error("Query didn't return any result");
|
|
1514
|
-
if (result.rows.length > 1) throw new Error("Query had more than one result");
|
|
1515
|
-
return result.rows[0];
|
|
1516
|
-
};
|
|
1517
|
-
var count = async (getResult) => {
|
|
1518
|
-
const result = await single(getResult);
|
|
1519
|
-
return Number(result.count);
|
|
1520
|
-
};
|
|
1521
|
-
var exists = async (getResult) => {
|
|
1522
|
-
const result = await single(getResult);
|
|
1523
|
-
return result.exists === true || result.exists === 1;
|
|
1524
|
-
};
|
|
1525
|
-
|
|
1526
|
-
// src/core/tracing/printing/color.ts
|
|
1527
|
-
import ansis from "ansis";
|
|
1528
|
-
var enableColors = true;
|
|
1529
|
-
var color = {
|
|
1530
|
-
set level(value) {
|
|
1531
|
-
enableColors = value === 1;
|
|
1532
|
-
},
|
|
1533
|
-
hex: (value) => (text) => enableColors ? ansis.hex(value)(text) : text,
|
|
1534
|
-
red: (value) => enableColors ? ansis.red(value) : value,
|
|
1535
|
-
green: (value) => enableColors ? ansis.green(value) : value,
|
|
1536
|
-
blue: (value) => enableColors ? ansis.blue(value) : value,
|
|
1537
|
-
cyan: (value) => enableColors ? ansis.cyan(value) : value,
|
|
1538
|
-
yellow: (value) => enableColors ? ansis.yellow(value) : value
|
|
1539
|
-
};
|
|
1540
|
-
var color_default = color;
|
|
1541
|
-
|
|
1542
|
-
// src/core/tracing/printing/pretty.ts
|
|
1543
|
-
var TWO_SPACES = " ";
|
|
1544
|
-
var COLOR_STRING = color_default.hex("#98c379");
|
|
1545
|
-
var COLOR_KEY = color_default.hex("#61afef");
|
|
1546
|
-
var COLOR_NUMBER_OR_DATE = color_default.hex("#d19a66");
|
|
1547
|
-
var COLOR_BOOLEAN = color_default.hex("#c678dd");
|
|
1548
|
-
var COLOR_NULL_OR_UNDEFINED = color_default.hex("#c678dd");
|
|
1549
|
-
var COLOR_BRACKETS = color_default.hex("#abb2bf");
|
|
1550
|
-
var processString = (str, indent, handleMultiline) => {
|
|
1551
|
-
if (handleMultiline && str.includes("\n")) {
|
|
1552
|
-
const lines = str.split("\n");
|
|
1553
|
-
const indentedLines = lines.map(
|
|
1554
|
-
(line) => indent + TWO_SPACES + COLOR_STRING(line)
|
|
1555
|
-
);
|
|
1556
|
-
return COLOR_STRING('"') + "\n" + indentedLines.join("\n") + "\n" + indent + COLOR_STRING('"');
|
|
1557
|
-
}
|
|
1558
|
-
return COLOR_STRING(`"${str}"`);
|
|
1559
|
-
};
|
|
1560
|
-
var shouldPrint = (obj) => typeof obj !== "function" && typeof obj !== "symbol";
|
|
1561
|
-
var formatJson = (obj, indentLevel = 0, handleMultiline = false) => {
|
|
1562
|
-
const indent = TWO_SPACES.repeat(indentLevel);
|
|
1563
|
-
if (obj === null) return COLOR_NULL_OR_UNDEFINED("null");
|
|
1564
|
-
if (obj === void 0) return COLOR_NULL_OR_UNDEFINED("undefined");
|
|
1565
|
-
if (typeof obj === "string")
|
|
1566
|
-
return processString(obj, indent, handleMultiline);
|
|
1567
|
-
if (typeof obj === "number" || typeof obj === "bigint" || obj instanceof Date)
|
|
1568
|
-
return COLOR_NUMBER_OR_DATE(String(obj));
|
|
1569
|
-
if (typeof obj === "boolean") return COLOR_BOOLEAN(String(obj));
|
|
1570
|
-
if (obj instanceof Error) {
|
|
1571
|
-
const errorObj = {};
|
|
1572
|
-
const propNames = Object.getOwnPropertyNames(obj);
|
|
1573
|
-
propNames.forEach((key) => {
|
|
1574
|
-
errorObj[key] = obj[key];
|
|
1575
|
-
});
|
|
1576
|
-
return formatJson(errorObj, indentLevel, handleMultiline);
|
|
1577
|
-
}
|
|
1578
|
-
if (obj instanceof Promise) {
|
|
1579
|
-
return COLOR_STRING("Promise {pending}");
|
|
1580
|
-
}
|
|
1581
|
-
if (Array.isArray(obj)) {
|
|
1582
|
-
const arrayItems = obj.map(
|
|
1583
|
-
(item) => formatJson(item, indentLevel + 1, handleMultiline)
|
|
1584
|
-
);
|
|
1585
|
-
return `${COLOR_BRACKETS("[")}
|
|
1586
|
-
${indent} ${arrayItems.join(
|
|
1587
|
-
`,
|
|
1588
|
-
${indent} `
|
|
1589
|
-
)}
|
|
1590
|
-
${indent}${COLOR_BRACKETS("]")}`;
|
|
1591
|
-
}
|
|
1592
|
-
const entries = Object.entries(obj).filter(([_, value]) => shouldPrint(value)).map(
|
|
1593
|
-
([key, value]) => `${COLOR_KEY(`"${key}"`)}: ${formatJson(
|
|
1594
|
-
value,
|
|
1595
|
-
indentLevel + 1,
|
|
1596
|
-
handleMultiline
|
|
1597
|
-
)}`
|
|
1598
|
-
);
|
|
1599
|
-
return `${COLOR_BRACKETS("{")}
|
|
1600
|
-
${indent} ${entries.join(
|
|
1601
|
-
`,
|
|
1602
|
-
${indent} `
|
|
1603
|
-
)}
|
|
1604
|
-
${indent}${COLOR_BRACKETS("}")}`;
|
|
1605
|
-
};
|
|
1606
|
-
var prettyJson = (obj, options) => formatJson(obj, 0, options?.handleMultiline);
|
|
1607
|
-
|
|
1608
|
-
// src/core/tracing/index.ts
|
|
1609
|
-
var tracer = () => {
|
|
1610
|
-
};
|
|
1611
|
-
var LogLevel = {
|
|
1612
|
-
DISABLED: "DISABLED",
|
|
1613
|
-
INFO: "INFO",
|
|
1614
|
-
LOG: "LOG",
|
|
1615
|
-
WARN: "WARN",
|
|
1616
|
-
ERROR: "ERROR"
|
|
1617
|
-
};
|
|
1618
|
-
var LogStyle = {
|
|
1619
|
-
RAW: "RAW",
|
|
1620
|
-
PRETTY: "PRETTY"
|
|
1621
|
-
};
|
|
1622
|
-
var shouldLog = (logLevel) => {
|
|
1623
|
-
const definedLogLevel = process.env.DUMBO_LOG_LEVEL ?? LogLevel.DISABLED;
|
|
1624
|
-
if (definedLogLevel === LogLevel.ERROR && logLevel === LogLevel.ERROR)
|
|
1625
|
-
return true;
|
|
1626
|
-
if (definedLogLevel === LogLevel.WARN && [LogLevel.ERROR, LogLevel.WARN].includes(logLevel))
|
|
1627
|
-
return true;
|
|
1628
|
-
if (definedLogLevel === LogLevel.LOG && [LogLevel.ERROR, LogLevel.WARN, LogLevel.LOG].includes(logLevel))
|
|
1629
|
-
return true;
|
|
1630
|
-
if (definedLogLevel === LogLevel.INFO && [LogLevel.ERROR, LogLevel.WARN, LogLevel.LOG, LogLevel.INFO].includes(
|
|
1631
|
-
logLevel
|
|
1632
|
-
))
|
|
1633
|
-
return true;
|
|
1634
|
-
return false;
|
|
1635
|
-
};
|
|
1636
|
-
var nulloTraceEventRecorder = () => {
|
|
1637
|
-
};
|
|
1638
|
-
var getTraceEventFormatter = (logStyle) => (event) => {
|
|
1639
|
-
switch (logStyle) {
|
|
1640
|
-
case "RAW":
|
|
1641
|
-
return JSONSerializer.serialize(event);
|
|
1642
|
-
case "PRETTY":
|
|
1643
|
-
return prettyJson(event, { handleMultiline: true });
|
|
1644
|
-
}
|
|
1645
|
-
};
|
|
1646
|
-
var getTraceEventRecorder = (logLevel, logStyle) => {
|
|
1647
|
-
const format = getTraceEventFormatter(logStyle);
|
|
1648
|
-
switch (logLevel) {
|
|
1649
|
-
case "DISABLED":
|
|
1650
|
-
return nulloTraceEventRecorder;
|
|
1651
|
-
case "INFO":
|
|
1652
|
-
return (event) => console.info(format(event));
|
|
1653
|
-
case "LOG":
|
|
1654
|
-
return (event) => console.log(format(event));
|
|
1655
|
-
case "WARN":
|
|
1656
|
-
return (event) => console.warn(format(event));
|
|
1657
|
-
case "ERROR":
|
|
1658
|
-
return (event) => console.error(format(event));
|
|
1659
|
-
}
|
|
1660
|
-
};
|
|
1661
|
-
var recordTraceEvent = (logLevel, eventName, attributes) => {
|
|
1662
|
-
if (!shouldLog(LogLevel.LOG)) return;
|
|
1663
|
-
const event = {
|
|
1664
|
-
name: eventName,
|
|
1665
|
-
timestamp: (/* @__PURE__ */ new Date()).getTime(),
|
|
1666
|
-
...attributes
|
|
1667
|
-
};
|
|
1668
|
-
const record = getTraceEventRecorder(
|
|
1669
|
-
logLevel,
|
|
1670
|
-
process.env.DUMBO_LOG_STYLE ?? "RAW"
|
|
1671
|
-
);
|
|
1672
|
-
record(event);
|
|
1673
|
-
};
|
|
1674
|
-
tracer.info = (eventName, attributes) => recordTraceEvent(LogLevel.INFO, eventName, attributes);
|
|
1675
|
-
tracer.warn = (eventName, attributes) => recordTraceEvent(LogLevel.WARN, eventName, attributes);
|
|
1676
|
-
tracer.log = (eventName, attributes) => recordTraceEvent(LogLevel.LOG, eventName, attributes);
|
|
1677
|
-
tracer.error = (eventName, attributes) => recordTraceEvent(LogLevel.ERROR, eventName, attributes);
|
|
1678
|
-
|
|
1679
|
-
// src/core/schema/migrators/schemaComponentMigrator.ts
|
|
1680
|
-
var { AutoIncrement, Varchar, Timestamp } = SQL.column.type;
|
|
1681
|
-
var migrationTableSQL = SQL`
|
|
1682
|
-
CREATE TABLE IF NOT EXISTS migrations (
|
|
1683
|
-
id ${AutoIncrement({ primaryKey: true })},
|
|
1684
|
-
name ${Varchar(255)} NOT NULL UNIQUE,
|
|
1685
|
-
application ${Varchar(255)} NOT NULL DEFAULT 'default',
|
|
1686
|
-
sql_hash ${Varchar(64)} NOT NULL,
|
|
1687
|
-
timestamp ${Timestamp} NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
1688
|
-
);
|
|
1689
|
-
`;
|
|
1690
|
-
var migrationTableSchemaComponent = schemaComponent(
|
|
1691
|
-
"dumbo:schema-component:migrations-table",
|
|
1692
|
-
{
|
|
1693
|
-
migrations: [sqlMigration("dumbo:migrationTable:001", [migrationTableSQL])]
|
|
1694
|
-
}
|
|
1695
|
-
);
|
|
1696
|
-
var SchemaComponentMigrator = (component, dumbo) => {
|
|
1697
|
-
const completedMigrations = [];
|
|
1698
|
-
return {
|
|
1699
|
-
component,
|
|
1700
|
-
run: async (options) => {
|
|
1701
|
-
const pendingMigrations = component.migrations.filter(
|
|
1702
|
-
(m) => !completedMigrations.includes(
|
|
1703
|
-
`${component.schemaComponentKey}:${m.name}`
|
|
1704
|
-
)
|
|
1705
|
-
);
|
|
1706
|
-
if (pendingMigrations.length === 0) return;
|
|
1707
|
-
await runSQLMigrations(dumbo, pendingMigrations, options);
|
|
1708
|
-
completedMigrations.push(
|
|
1709
|
-
...pendingMigrations.map(
|
|
1710
|
-
(m) => `${component.schemaComponentKey}:${m.name}`
|
|
1711
|
-
)
|
|
1712
|
-
);
|
|
1713
|
-
}
|
|
1714
|
-
};
|
|
1715
|
-
};
|
|
1716
|
-
|
|
1717
|
-
// src/core/schema/migrators/migrator.ts
|
|
1718
|
-
var MIGRATIONS_LOCK_ID = 999956789;
|
|
1719
|
-
var defaultMigratorOptions = globalThis.defaultMigratorOptions = globalThis.defaultMigratorOptions ?? {};
|
|
1720
|
-
var registerDefaultMigratorOptions = (databaseType, options) => {
|
|
1721
|
-
defaultMigratorOptions[databaseType] = options;
|
|
1722
|
-
};
|
|
1723
|
-
var getDefaultMigratorOptionsFromRegistry = (databaseType) => {
|
|
1724
|
-
if (!defaultMigratorOptions[databaseType]) {
|
|
1725
|
-
throw new Error(
|
|
1726
|
-
`No default migrator options registered for database type: ${databaseType}`
|
|
1727
|
-
);
|
|
1728
|
-
}
|
|
1729
|
-
return defaultMigratorOptions[databaseType];
|
|
1730
|
-
};
|
|
1731
|
-
var runSQLMigrations = (pool, migrations, partialOptions) => pool.withTransaction(async ({ execute }) => {
|
|
1732
|
-
const databaseType = fromDatabaseDriverType(pool.driverType).databaseType;
|
|
1733
|
-
const defaultOptions = getDefaultMigratorOptionsFromRegistry(databaseType);
|
|
1734
|
-
partialOptions ??= {};
|
|
1735
|
-
const options = {
|
|
1736
|
-
...defaultOptions,
|
|
1737
|
-
...partialOptions,
|
|
1738
|
-
schema: {
|
|
1739
|
-
...defaultOptions.schema,
|
|
1740
|
-
...partialOptions?.schema ?? {}
|
|
1741
|
-
},
|
|
1742
|
-
lock: {
|
|
1743
|
-
...defaultOptions.lock,
|
|
1744
|
-
...partialOptions?.lock,
|
|
1745
|
-
options: {
|
|
1746
|
-
lockId: MIGRATIONS_LOCK_ID,
|
|
1747
|
-
...defaultOptions.lock?.options,
|
|
1748
|
-
...partialOptions?.lock?.options
|
|
1749
|
-
}
|
|
1750
|
-
},
|
|
1751
|
-
dryRun: defaultOptions.dryRun ?? partialOptions?.dryRun
|
|
1752
|
-
};
|
|
1753
|
-
const { databaseLock: _, ...rest } = options.lock ?? {};
|
|
1754
|
-
const databaseLock = options.lock?.databaseLock ?? NoDatabaseLock;
|
|
1755
|
-
const lockOptions = {
|
|
1756
|
-
lockId: MIGRATIONS_LOCK_ID,
|
|
1757
|
-
...rest
|
|
1758
|
-
};
|
|
1759
|
-
const migrationTable = options.schema?.migrationTable ?? migrationTableSchemaComponent;
|
|
1760
|
-
const coreMigrations = migrationTable.migrations;
|
|
1761
|
-
await databaseLock.withAcquire(
|
|
1762
|
-
execute,
|
|
1763
|
-
async () => {
|
|
1764
|
-
for (const migration of coreMigrations) {
|
|
1765
|
-
await execute.batchCommand(migration.sqls);
|
|
1766
|
-
}
|
|
1767
|
-
for (const migration of migrations) {
|
|
1768
|
-
await runSQLMigration(databaseType, execute, migration);
|
|
1769
|
-
}
|
|
1770
|
-
},
|
|
1771
|
-
lockOptions
|
|
1772
|
-
);
|
|
1773
|
-
return { success: options.dryRun ? false : true, result: void 0 };
|
|
1774
|
-
});
|
|
1775
|
-
var runSQLMigration = async (databaseType, execute, migration) => {
|
|
1776
|
-
const sqls = combineMigrations(migration);
|
|
1777
|
-
const sqlHash = await getMigrationHash(migration, getFormatter(databaseType));
|
|
1778
|
-
try {
|
|
1779
|
-
const newMigration = {
|
|
1780
|
-
name: migration.name,
|
|
1781
|
-
sqlHash
|
|
1782
|
-
};
|
|
1783
|
-
const wasMigrationApplied = await ensureMigrationWasNotAppliedYet(
|
|
1784
|
-
execute,
|
|
1785
|
-
newMigration
|
|
1786
|
-
);
|
|
1787
|
-
if (wasMigrationApplied) return;
|
|
1788
|
-
await execute.batchCommand(sqls);
|
|
1789
|
-
await recordMigration(execute, newMigration);
|
|
1790
|
-
} catch (error) {
|
|
1791
|
-
tracer.error("migration-error", {
|
|
1792
|
-
migationName: migration.name,
|
|
1793
|
-
error
|
|
1794
|
-
});
|
|
1795
|
-
throw error;
|
|
1796
|
-
}
|
|
1797
|
-
};
|
|
1798
|
-
var getMigrationHash = async (sqlMigration2, sqlFormatter) => {
|
|
1799
|
-
const content = sqlFormatter.describe(sqlMigration2.sqls);
|
|
1800
|
-
const encoder = new TextEncoder();
|
|
1801
|
-
const data = encoder.encode(content);
|
|
1802
|
-
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
1803
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
1804
|
-
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1805
|
-
};
|
|
1806
|
-
var combineMigrations = (...migration) => migration.flatMap((m) => m.sqls);
|
|
1807
|
-
var ensureMigrationWasNotAppliedYet = async (execute, migration) => {
|
|
1808
|
-
const result = await singleOrNull(
|
|
1809
|
-
execute.query(
|
|
1810
|
-
SQL`SELECT sql_hash FROM migrations WHERE name = ${migration.name}`
|
|
1811
|
-
)
|
|
1812
|
-
);
|
|
1813
|
-
if (result === null) return false;
|
|
1814
|
-
const { sqlHash } = mapToCamelCase(result);
|
|
1815
|
-
if (sqlHash !== migration.sqlHash) {
|
|
1816
|
-
throw new Error(
|
|
1817
|
-
`Migration hash mismatch for "${migration.name}". Aborting migration.`
|
|
1818
|
-
);
|
|
1819
|
-
}
|
|
1820
|
-
return true;
|
|
1821
|
-
};
|
|
1822
|
-
var recordMigration = async (execute, migration) => {
|
|
1823
|
-
await execute.command(
|
|
1824
|
-
SQL`
|
|
1825
|
-
INSERT INTO migrations (name, sql_hash)
|
|
1826
|
-
VALUES (${migration.name}, ${migration.sqlHash})`
|
|
1827
|
-
);
|
|
1828
|
-
};
|
|
1829
|
-
|
|
1830
|
-
// src/core/index.ts
|
|
1831
|
-
SQL.columnN = Object.assign(dumboSchema.column, {
|
|
1832
|
-
type: SQLColumnTypeTokensFactory
|
|
1833
|
-
});
|
|
1834
|
-
|
|
1835
|
-
// src/core/drivers/databaseDriver.ts
|
|
1836
|
-
var canHandleDriverWithConnectionString = (driver, tryParseConnectionString) => (options) => {
|
|
1837
|
-
if ("driverType" in options) return options.driverType === driver;
|
|
1838
|
-
if ("connectionString" in options && typeof options.connectionString === "string")
|
|
1839
|
-
return tryParseConnectionString(options.connectionString) !== null;
|
|
1840
|
-
return false;
|
|
1841
|
-
};
|
|
1842
|
-
var DumboDatabaseDriverRegistry = () => {
|
|
1843
|
-
const drivers = /* @__PURE__ */ new Map();
|
|
1844
|
-
const register = (driverType, plugin) => {
|
|
1845
|
-
const entry = drivers.get(driverType);
|
|
1846
|
-
if (entry && (typeof entry !== "function" || typeof plugin === "function")) {
|
|
1847
|
-
return;
|
|
1848
|
-
}
|
|
1849
|
-
drivers.set(driverType, plugin);
|
|
1850
|
-
};
|
|
1851
|
-
const getDriver = (options) => options.driverType ? drivers.get(options.driverType) : [...drivers.values()].find(
|
|
1852
|
-
(d) => typeof d !== "function" && d.canHandle(options)
|
|
1853
|
-
);
|
|
1854
|
-
const tryResolve = async (options) => {
|
|
1855
|
-
const driver = getDriver(options);
|
|
1856
|
-
if (!driver) return null;
|
|
1857
|
-
if (typeof driver !== "function") return driver;
|
|
1858
|
-
const plugin = await driver();
|
|
1859
|
-
register(plugin.driverType, plugin);
|
|
1860
|
-
return plugin;
|
|
1861
|
-
};
|
|
1862
|
-
const tryGet = (options) => {
|
|
1863
|
-
const driver = getDriver(options);
|
|
1864
|
-
return driver && typeof driver !== "function" ? driver : null;
|
|
1865
|
-
};
|
|
1866
|
-
const has = (driverType) => drivers.has(driverType);
|
|
1867
|
-
return {
|
|
1868
|
-
register,
|
|
1869
|
-
tryResolve,
|
|
1870
|
-
tryGet,
|
|
1871
|
-
has,
|
|
1872
|
-
get databaseDriverTypes() {
|
|
1873
|
-
return Array.from(drivers.keys());
|
|
1874
|
-
}
|
|
1875
|
-
};
|
|
1876
|
-
};
|
|
1877
|
-
var dumboDatabaseDriverRegistry = globalThis.dumboDatabaseDriverRegistry = globalThis.dumboDatabaseDriverRegistry ?? DumboDatabaseDriverRegistry();
|
|
1878
|
-
|
|
1879
|
-
export {
|
|
1880
|
-
canHandleDriverWithConnectionString,
|
|
1881
|
-
DumboDatabaseDriverRegistry,
|
|
1882
|
-
dumboDatabaseDriverRegistry,
|
|
1883
|
-
toDatabaseDriverType,
|
|
1884
|
-
fromDatabaseDriverType,
|
|
1885
|
-
getDatabaseDriverName,
|
|
1886
|
-
getDatabaseType,
|
|
1887
|
-
composeJSONReplacers,
|
|
1888
|
-
composeJSONRevivers,
|
|
1889
|
-
JSONReplacer,
|
|
1890
|
-
JSONReviver,
|
|
1891
|
-
JSONReplacers,
|
|
1892
|
-
JSONRevivers,
|
|
1893
|
-
jsonSerializer,
|
|
1894
|
-
JSONSerializer,
|
|
1895
|
-
RawJSONSerializer,
|
|
1896
|
-
ParametrizedSQLBuilder,
|
|
1897
|
-
SQLToken,
|
|
1898
|
-
SQLIdentifier,
|
|
1899
|
-
SQLPlain,
|
|
1900
|
-
SQLLiteral,
|
|
1901
|
-
SQLArray,
|
|
1902
|
-
SQLIn,
|
|
1903
|
-
ColumnTypeToken,
|
|
1904
|
-
SerialToken,
|
|
1905
|
-
BigSerialToken,
|
|
1906
|
-
IntegerToken,
|
|
1907
|
-
BigIntegerToken,
|
|
1908
|
-
JSONBToken,
|
|
1909
|
-
TimestampToken,
|
|
1910
|
-
TimestamptzToken,
|
|
1911
|
-
VarcharToken,
|
|
1912
|
-
AutoIncrementSQLColumnToken,
|
|
1913
|
-
SQLColumnTypeTokens,
|
|
1914
|
-
SQLColumnTypeTokensFactory,
|
|
1915
|
-
SQLColumnToken,
|
|
1916
|
-
SQLProcessor,
|
|
1917
|
-
ExpandArrayProcessor,
|
|
1918
|
-
ExpandSQLInProcessor,
|
|
1919
|
-
FormatIdentifierProcessor,
|
|
1920
|
-
MapLiteralProcessor,
|
|
1921
|
-
SQLProcessorsRegistry,
|
|
1922
|
-
mapDefaultSQLColumnProcessors,
|
|
1923
|
-
defaultProcessorsRegistry,
|
|
1924
|
-
TokenizedSQL,
|
|
1925
|
-
isTokenizedSQL,
|
|
1926
|
-
SQL,
|
|
1927
|
-
isSQL,
|
|
1928
|
-
ansiSqlReservedMap,
|
|
1929
|
-
ANSISQLParamPlaceholder,
|
|
1930
|
-
ANSISQLIdentifierQuote,
|
|
1931
|
-
mapANSISQLParamPlaceholder,
|
|
1932
|
-
mapSQLIdentifier,
|
|
1933
|
-
DefaultMapSQLParamValueOptions,
|
|
1934
|
-
SQLValueMapper,
|
|
1935
|
-
mapSQLParamValue,
|
|
1936
|
-
SQLFormatter2 as SQLFormatter,
|
|
1937
|
-
registerFormatter,
|
|
1938
|
-
getFormatter,
|
|
1939
|
-
formatSQL,
|
|
1940
|
-
describeSQL,
|
|
1941
|
-
mapColumnToJSON,
|
|
1942
|
-
mapColumnToBigint,
|
|
1943
|
-
mapSQLQueryResult,
|
|
1944
|
-
sqlExecutor,
|
|
1945
|
-
sqlExecutorInNewConnection,
|
|
1946
|
-
sqlExecutorInAmbientConnection,
|
|
1947
|
-
executeInNewDbClient,
|
|
1948
|
-
executeInNewConnection,
|
|
1949
|
-
executeInAmbientConnection,
|
|
1950
|
-
executeInTransaction,
|
|
1951
|
-
transactionFactoryWithDbClient,
|
|
1952
|
-
transactionFactoryWithNewConnection,
|
|
1953
|
-
transactionFactoryWithAmbientConnection,
|
|
1954
|
-
createAmbientConnection,
|
|
1955
|
-
createSingletonConnection,
|
|
1956
|
-
createTransientConnection,
|
|
1957
|
-
createConnection,
|
|
1958
|
-
createAmbientConnectionPool,
|
|
1959
|
-
createSingletonConnectionPool,
|
|
1960
|
-
createSingletonClientPool,
|
|
1961
|
-
createAlwaysNewConnectionPool,
|
|
1962
|
-
createConnectionPool,
|
|
1963
|
-
sqlMigration,
|
|
1964
|
-
schemaComponent,
|
|
1965
|
-
isSchemaComponentOfType,
|
|
1966
|
-
filterSchemaComponentsOfType,
|
|
1967
|
-
mapSchemaComponentsOfType,
|
|
1968
|
-
findSchemaComponentsOfType,
|
|
1969
|
-
ColumnURNType,
|
|
1970
|
-
ColumnURN,
|
|
1971
|
-
columnSchemaComponent,
|
|
1972
|
-
IndexURNType,
|
|
1973
|
-
IndexURN,
|
|
1974
|
-
indexSchemaComponent,
|
|
1975
|
-
TableURNType,
|
|
1976
|
-
TableURN,
|
|
1977
|
-
tableSchemaComponent,
|
|
1978
|
-
DatabaseSchemaURNType,
|
|
1979
|
-
DatabaseSchemaURN,
|
|
1980
|
-
databaseSchemaSchemaComponent,
|
|
1981
|
-
DatabaseURNType,
|
|
1982
|
-
DatabaseURN,
|
|
1983
|
-
databaseSchemaComponent,
|
|
1984
|
-
relationship,
|
|
1985
|
-
schemaComponentURN,
|
|
1986
|
-
dumboSchema,
|
|
1987
|
-
defaultDatabaseLockOptions,
|
|
1988
|
-
NoDatabaseLock,
|
|
1989
|
-
mapRows,
|
|
1990
|
-
toCamelCase,
|
|
1991
|
-
mapToCamelCase,
|
|
1992
|
-
firstOrNull,
|
|
1993
|
-
first,
|
|
1994
|
-
singleOrNull,
|
|
1995
|
-
single,
|
|
1996
|
-
count,
|
|
1997
|
-
exists,
|
|
1998
|
-
color,
|
|
1999
|
-
prettyJson,
|
|
2000
|
-
tracer,
|
|
2001
|
-
LogLevel,
|
|
2002
|
-
LogStyle,
|
|
2003
|
-
migrationTableSchemaComponent,
|
|
2004
|
-
SchemaComponentMigrator,
|
|
2005
|
-
MIGRATIONS_LOCK_ID,
|
|
2006
|
-
registerDefaultMigratorOptions,
|
|
2007
|
-
getDefaultMigratorOptionsFromRegistry,
|
|
2008
|
-
runSQLMigrations,
|
|
2009
|
-
combineMigrations
|
|
2010
|
-
};
|
|
2011
|
-
//# sourceMappingURL=chunk-N7RWT46K.js.map
|