@event-driven-io/dumbo 0.13.0-beta.35 → 0.13.0-beta.36
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 +379 -434
- package/dist/cloudflare.cjs.map +1 -1
- package/dist/cloudflare.d.cts +36 -29
- package/dist/cloudflare.d.ts +36 -29
- package/dist/cloudflare.js +343 -434
- package/dist/cloudflare.js.map +1 -1
- package/dist/core-BeyC5tHn.js +519 -0
- package/dist/core-BeyC5tHn.js.map +1 -0
- package/dist/core-Bf2ujUFy.js +379 -0
- package/dist/core-Bf2ujUFy.js.map +1 -0
- package/dist/core-BgYtAxCm.cjs +3237 -0
- package/dist/core-BgYtAxCm.cjs.map +1 -0
- package/dist/core-DDo4m0Z_.js +2262 -0
- package/dist/core-DDo4m0Z_.js.map +1 -0
- package/dist/core-DmbB4qMn.cjs +656 -0
- package/dist/core-DmbB4qMn.cjs.map +1 -0
- package/dist/core-Go_IA78L.cjs +450 -0
- package/dist/core-Go_IA78L.cjs.map +1 -0
- package/dist/{connectionString-Dch_MIRU.d.cts → index-BDSQvDH2.d.cts} +1010 -922
- package/dist/index-BdWFmDhJ.d.cts +68 -0
- package/dist/index-D1jryNqo.d.ts +198 -0
- package/dist/index-DaP2fTEX.d.ts +67 -0
- package/dist/index-DqVvUav9.d.cts +198 -0
- package/dist/index-S_wp0Eaf.d.cts +67 -0
- package/dist/index-cxtbLiju.d.ts +68 -0
- package/dist/{connectionString-Dch_MIRU.d.ts → index-zkszkJqP.d.ts} +1010 -922
- package/dist/index.cjs +212 -359
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -132
- package/dist/index.d.ts +3 -132
- package/dist/index.js +52 -361
- package/dist/index.js.map +1 -1
- package/dist/pg.cjs +366 -431
- package/dist/pg.cjs.map +1 -1
- package/dist/pg.d.cts +83 -72
- package/dist/pg.d.ts +83 -72
- package/dist/pg.js +320 -431
- package/dist/pg.js.map +1 -1
- package/dist/postgreSQLMetadata-LqX-Z_wo.cjs +118 -0
- package/dist/postgreSQLMetadata-LqX-Z_wo.cjs.map +1 -0
- package/dist/postgreSQLMetadata-zMq8yJo_.js +65 -0
- package/dist/postgreSQLMetadata-zMq8yJo_.js.map +1 -0
- package/dist/postgresql.cjs +25 -50
- package/dist/postgresql.d.cts +3 -61
- package/dist/postgresql.d.ts +3 -61
- package/dist/postgresql.js +4 -50
- package/dist/sqlite.cjs +30 -60
- package/dist/sqlite.d.cts +3 -190
- package/dist/sqlite.d.ts +3 -190
- package/dist/sqlite.js +4 -60
- package/dist/sqlite3.cjs +312 -380
- package/dist/sqlite3.cjs.map +1 -1
- package/dist/sqlite3.d.cts +79 -77
- package/dist/sqlite3.d.ts +79 -77
- package/dist/sqlite3.js +276 -378
- package/dist/sqlite3.js.map +1 -1
- package/dist/sqliteMetadata-BoQ7Sc9I.js +29 -0
- package/dist/sqliteMetadata-BoQ7Sc9I.js.map +1 -0
- package/dist/sqliteMetadata-D_2pKeCC.cjs +46 -0
- package/dist/sqliteMetadata-D_2pKeCC.cjs.map +1 -0
- package/package.json +12 -12
- package/dist/chunk-33P5766L.js +0 -83
- package/dist/chunk-33P5766L.js.map +0 -1
- package/dist/chunk-4MMMEDQ7.cjs +0 -2944
- package/dist/chunk-4MMMEDQ7.cjs.map +0 -1
- package/dist/chunk-6HAHSSPW.js +0 -701
- package/dist/chunk-6HAHSSPW.js.map +0 -1
- package/dist/chunk-GNH5XC6D.cjs +0 -481
- package/dist/chunk-GNH5XC6D.cjs.map +0 -1
- package/dist/chunk-H2JBS7HM.js +0 -2944
- package/dist/chunk-H2JBS7HM.js.map +0 -1
- package/dist/chunk-JIZGCEPE.cjs +0 -701
- package/dist/chunk-JIZGCEPE.cjs.map +0 -1
- package/dist/chunk-NJI6PJFZ.cjs +0 -83
- package/dist/chunk-NJI6PJFZ.cjs.map +0 -1
- package/dist/chunk-RQ3KKMTP.cjs +0 -34
- package/dist/chunk-RQ3KKMTP.cjs.map +0 -1
- package/dist/chunk-UK7MXVS2.js +0 -34
- package/dist/chunk-UK7MXVS2.js.map +0 -1
- package/dist/chunk-Y5TD53QE.js +0 -481
- package/dist/chunk-Y5TD53QE.js.map +0 -1
- package/dist/columnProcessors-Be2uMYjS.d.cts +0 -8
- package/dist/columnProcessors-D0ivj_SU.d.ts +0 -8
- package/dist/postgresql.cjs.map +0 -1
- package/dist/postgresql.js.map +0 -1
- package/dist/sqlite.cjs.map +0 -1
- package/dist/sqlite.js.map +0 -1
package/dist/cloudflare.cjs
CHANGED
|
@@ -1,456 +1,401 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
session: newSession,
|
|
69
|
-
serializer
|
|
70
|
-
})
|
|
71
|
-
);
|
|
72
|
-
},
|
|
73
|
-
query: async (sql, _options) => {
|
|
74
|
-
const { query, params } = _chunkJIZGCEPEcjs.sqliteFormatter.format(sql, { serializer });
|
|
75
|
-
const stmt = execute.prepare(query);
|
|
76
|
-
const bound = _optionalChain([params, 'optionalAccess', _ => _.length]) ? stmt.bind(...params) : stmt;
|
|
77
|
-
const { results } = await bound.all();
|
|
78
|
-
return { rowCount: _nullishCoalesce(_optionalChain([results, 'optionalAccess', _2 => _2.length]), () => ( 0)), rows: _nullishCoalesce(results, () => ( [])) };
|
|
79
|
-
},
|
|
80
|
-
batchQuery: async (sqls, _options) => {
|
|
81
|
-
const statements = sqls.map((sql) => {
|
|
82
|
-
const { query, params } = _chunkJIZGCEPEcjs.sqliteFormatter.format(sql, { serializer });
|
|
83
|
-
const stmt = execute.prepare(query);
|
|
84
|
-
return _optionalChain([params, 'optionalAccess', _3 => _3.length]) ? stmt.bind(...params) : stmt;
|
|
85
|
-
});
|
|
86
|
-
const results = await execute.batch(statements);
|
|
87
|
-
return results.map((result) => ({
|
|
88
|
-
rowCount: _nullishCoalesce(_optionalChain([result, 'access', _4 => _4.results, 'optionalAccess', _5 => _5.length]), () => ( 0)),
|
|
89
|
-
rows: _nullishCoalesce(result.results, () => ( []))
|
|
90
|
-
}));
|
|
91
|
-
},
|
|
92
|
-
command: async (sql, _options) => {
|
|
93
|
-
const { query, params } = _chunkJIZGCEPEcjs.sqliteFormatter.format(sql, { serializer });
|
|
94
|
-
const stmt = execute.prepare(query);
|
|
95
|
-
const bound = _optionalChain([params, 'optionalAccess', _6 => _6.length]) ? stmt.bind(...params) : stmt;
|
|
96
|
-
const result = await bound.run();
|
|
97
|
-
return {
|
|
98
|
-
rowCount: _nullishCoalesce(_optionalChain([result, 'access', _7 => _7.meta, 'optionalAccess', _8 => _8.changes]), () => ( 0)),
|
|
99
|
-
rows: _nullishCoalesce(result.results, () => ( []))
|
|
100
|
-
};
|
|
101
|
-
},
|
|
102
|
-
batchCommand: async (sqls, options2) => {
|
|
103
|
-
const statements = sqls.map((sql) => {
|
|
104
|
-
const { query, params } = _chunkJIZGCEPEcjs.sqliteFormatter.format(sql, { serializer });
|
|
105
|
-
const stmt = execute.prepare(query);
|
|
106
|
-
return _optionalChain([params, 'optionalAccess', _9 => _9.length]) ? stmt.bind(...params) : stmt;
|
|
107
|
-
});
|
|
108
|
-
const batchResults = await execute.batch(statements);
|
|
109
|
-
return batchResults.map((result, i) => {
|
|
110
|
-
const qr = {
|
|
111
|
-
rowCount: _nullishCoalesce(_optionalChain([result, 'access', _10 => _10.meta, 'optionalAccess', _11 => _11.changes]), () => ( 0)),
|
|
112
|
-
rows: _nullishCoalesce(result.results, () => ( []))
|
|
113
|
-
};
|
|
114
|
-
if (_optionalChain([options2, 'optionalAccess', _12 => _12.assertChanges]) && (_nullishCoalesce(qr.rowCount, () => ( 0))) === 0) {
|
|
115
|
-
throw new (0, _chunk4MMMEDQ7cjs.BatchCommandNoChangesError)(i);
|
|
116
|
-
}
|
|
117
|
-
return qr;
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
};
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_core = require('./core-BgYtAxCm.cjs');
|
|
3
|
+
const require_sqliteMetadata = require('./sqliteMetadata-D_2pKeCC.cjs');
|
|
4
|
+
const require_core$1 = require('./core-DmbB4qMn.cjs');
|
|
5
|
+
|
|
6
|
+
//#region src/storage/sqlite/d1/connections/d1Client.ts
|
|
7
|
+
const d1Client = (options) => {
|
|
8
|
+
const { database, session, serializer } = options;
|
|
9
|
+
const execute = session ?? database;
|
|
10
|
+
return {
|
|
11
|
+
database,
|
|
12
|
+
session,
|
|
13
|
+
connect: () => Promise.resolve(),
|
|
14
|
+
close: () => Promise.resolve(),
|
|
15
|
+
withSession: async (constraintOrBookmark) => {
|
|
16
|
+
const newSession = constraintOrBookmark ? database.withSession(constraintOrBookmark) : database.withSession();
|
|
17
|
+
return Promise.resolve(d1Client({
|
|
18
|
+
database,
|
|
19
|
+
session: newSession,
|
|
20
|
+
serializer
|
|
21
|
+
}));
|
|
22
|
+
},
|
|
23
|
+
query: async (sql, _options) => {
|
|
24
|
+
const { query, params } = require_core$1.sqliteFormatter.format(sql, { serializer });
|
|
25
|
+
const stmt = execute.prepare(query);
|
|
26
|
+
const { results } = await (params?.length ? stmt.bind(...params) : stmt).all();
|
|
27
|
+
return {
|
|
28
|
+
rowCount: results?.length ?? 0,
|
|
29
|
+
rows: results ?? []
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
batchQuery: async (sqls, _options) => {
|
|
33
|
+
const statements = sqls.map((sql) => {
|
|
34
|
+
const { query, params } = require_core$1.sqliteFormatter.format(sql, { serializer });
|
|
35
|
+
const stmt = execute.prepare(query);
|
|
36
|
+
return params?.length ? stmt.bind(...params) : stmt;
|
|
37
|
+
});
|
|
38
|
+
return (await execute.batch(statements)).map((result) => ({
|
|
39
|
+
rowCount: result.results?.length ?? 0,
|
|
40
|
+
rows: result.results ?? []
|
|
41
|
+
}));
|
|
42
|
+
},
|
|
43
|
+
command: async (sql, _options) => {
|
|
44
|
+
const { query, params } = require_core$1.sqliteFormatter.format(sql, { serializer });
|
|
45
|
+
const stmt = execute.prepare(query);
|
|
46
|
+
const result = await (params?.length ? stmt.bind(...params) : stmt).run();
|
|
47
|
+
return {
|
|
48
|
+
rowCount: result.meta?.changes ?? 0,
|
|
49
|
+
rows: result.results ?? []
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
batchCommand: async (sqls, options) => {
|
|
53
|
+
const statements = sqls.map((sql) => {
|
|
54
|
+
const { query, params } = require_core$1.sqliteFormatter.format(sql, { serializer });
|
|
55
|
+
const stmt = execute.prepare(query);
|
|
56
|
+
return params?.length ? stmt.bind(...params) : stmt;
|
|
57
|
+
});
|
|
58
|
+
return (await execute.batch(statements)).map((result, i) => {
|
|
59
|
+
const qr = {
|
|
60
|
+
rowCount: result.meta?.changes ?? 0,
|
|
61
|
+
rows: result.results ?? []
|
|
62
|
+
};
|
|
63
|
+
if (options?.assertChanges && (qr.rowCount ?? 0) === 0) throw new require_core.BatchCommandNoChangesError(i);
|
|
64
|
+
return qr;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
121
68
|
};
|
|
122
69
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/storage/sqlite/d1/errors/errorMapper.ts
|
|
72
|
+
const getErrorMessage = (error) => error instanceof Error ? error.message : void 0;
|
|
73
|
+
const asError = (error) => error instanceof Error ? error : void 0;
|
|
74
|
+
/**
|
|
75
|
+
* Determines the constraint subtype from the error message.
|
|
76
|
+
*
|
|
77
|
+
* D1 embeds the SQLite constraint detail in the message string, e.g.:
|
|
78
|
+
* "D1_ERROR: UNIQUE constraint failed: users.email"
|
|
79
|
+
* "D1_ERROR: SQLITE_CONSTRAINT: FOREIGN KEY constraint failed"
|
|
80
|
+
*/
|
|
81
|
+
const mapConstraintError = (message, innerError) => {
|
|
82
|
+
const upperMessage = message?.toUpperCase() ?? "";
|
|
83
|
+
if (upperMessage.includes("UNIQUE") || upperMessage.includes("PRIMARY KEY")) return new require_core.UniqueConstraintError(message, innerError);
|
|
84
|
+
if (upperMessage.includes("FOREIGN KEY")) return new require_core.ForeignKeyViolationError(message, innerError);
|
|
85
|
+
if (upperMessage.includes("NOT NULL")) return new require_core.NotNullViolationError(message, innerError);
|
|
86
|
+
if (upperMessage.includes("CHECK")) return new require_core.CheckViolationError(message, innerError);
|
|
87
|
+
return new require_core.IntegrityConstraintViolationError(message, innerError);
|
|
137
88
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
89
|
+
const isConstraintMessage = (upper) => upper.includes("CONSTRAINT") || upper.includes("UNIQUE") || upper.includes("PRIMARY KEY") || upper.includes("FOREIGN KEY") || upper.includes("NOT NULL");
|
|
90
|
+
/** Extracts the first `SQLITE_<CODE>` token from a message string. */
|
|
91
|
+
const SQLITE_CODE_RE = /SQLITE_([A-Z]+)/;
|
|
92
|
+
const extractEmbeddedSqliteCode = (message) => {
|
|
93
|
+
const match = SQLITE_CODE_RE.exec(message);
|
|
94
|
+
return match ? `SQLITE_${match[1]}` : void 0;
|
|
143
95
|
};
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return new (0, _chunk4MMMEDQ7cjs.InvalidOperationError)(message, innerError);
|
|
180
|
-
case "SQLITE_MISUSE":
|
|
181
|
-
return new (0, _chunk4MMMEDQ7cjs.InvalidOperationError)(message, innerError);
|
|
182
|
-
case "SQLITE_AUTH":
|
|
183
|
-
return new (0, _chunk4MMMEDQ7cjs.InvalidOperationError)(message, innerError);
|
|
184
|
-
case "SQLITE_PERM":
|
|
185
|
-
return new (0, _chunk4MMMEDQ7cjs.InvalidOperationError)(message, innerError);
|
|
186
|
-
case "SQLITE_SCHEMA":
|
|
187
|
-
return new (0, _chunk4MMMEDQ7cjs.InvalidOperationError)(message, innerError);
|
|
188
|
-
case "SQLITE_ABORT":
|
|
189
|
-
return new (0, _chunk4MMMEDQ7cjs.SerializationError)(message, innerError);
|
|
190
|
-
case "SQLITE_INTERRUPT":
|
|
191
|
-
return new (0, _chunk4MMMEDQ7cjs.SerializationError)(message, innerError);
|
|
192
|
-
}
|
|
193
|
-
return void 0;
|
|
96
|
+
/**
|
|
97
|
+
* Maps a `SQLITE_*` code found in the D1 message to a DumboError.
|
|
98
|
+
*
|
|
99
|
+
* D1 sometimes forwards raw SQLite result codes from the C++ layer, e.g.:
|
|
100
|
+
* "D1_ERROR: SQLITE_BUSY: database is locked"
|
|
101
|
+
* "SQLITE_READONLY: attempt to write a readonly database"
|
|
102
|
+
*
|
|
103
|
+
* See https://www.sqlite.org/rescode.html for the full code list.
|
|
104
|
+
*/
|
|
105
|
+
const mapEmbeddedSqliteCode = (code, message, innerError) => {
|
|
106
|
+
switch (code) {
|
|
107
|
+
case "SQLITE_CONSTRAINT": return mapConstraintError(message, innerError);
|
|
108
|
+
case "SQLITE_BUSY": return new require_core.LockNotAvailableError(message, innerError);
|
|
109
|
+
case "SQLITE_LOCKED": return new require_core.DeadlockError(message, innerError);
|
|
110
|
+
case "SQLITE_PROTOCOL": return new require_core.LockNotAvailableError(message, innerError);
|
|
111
|
+
case "SQLITE_CANTOPEN": return new require_core.ConnectionError(message, innerError);
|
|
112
|
+
case "SQLITE_NOTADB": return new require_core.ConnectionError(message, innerError);
|
|
113
|
+
case "SQLITE_NOMEM": return new require_core.InsufficientResourcesError(message, innerError);
|
|
114
|
+
case "SQLITE_FULL": return new require_core.InsufficientResourcesError(message, innerError);
|
|
115
|
+
case "SQLITE_IOERR": return new require_core.SystemError(message, innerError);
|
|
116
|
+
case "SQLITE_CORRUPT": return new require_core.SystemError(message, innerError);
|
|
117
|
+
case "SQLITE_INTERNAL": return new require_core.SystemError(message, innerError);
|
|
118
|
+
case "SQLITE_NOLFS": return new require_core.SystemError(message, innerError);
|
|
119
|
+
case "SQLITE_TOOBIG": return new require_core.DataError(message, innerError);
|
|
120
|
+
case "SQLITE_MISMATCH": return new require_core.DataError(message, innerError);
|
|
121
|
+
case "SQLITE_RANGE": return new require_core.DataError(message, innerError);
|
|
122
|
+
case "SQLITE_ERROR": return new require_core.InvalidOperationError(message, innerError);
|
|
123
|
+
case "SQLITE_READONLY": return new require_core.InvalidOperationError(message, innerError);
|
|
124
|
+
case "SQLITE_MISUSE": return new require_core.InvalidOperationError(message, innerError);
|
|
125
|
+
case "SQLITE_AUTH": return new require_core.InvalidOperationError(message, innerError);
|
|
126
|
+
case "SQLITE_PERM": return new require_core.InvalidOperationError(message, innerError);
|
|
127
|
+
case "SQLITE_SCHEMA": return new require_core.InvalidOperationError(message, innerError);
|
|
128
|
+
case "SQLITE_ABORT": return new require_core.SerializationError(message, innerError);
|
|
129
|
+
case "SQLITE_INTERRUPT": return new require_core.SerializationError(message, innerError);
|
|
130
|
+
}
|
|
194
131
|
};
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Maps a Cloudflare D1 error to a typed DumboError.
|
|
134
|
+
*
|
|
135
|
+
* Unlike node-sqlite3, D1 throws **plain `Error` objects** with no `code`
|
|
136
|
+
* property. All error information is embedded in `error.message`, using
|
|
137
|
+
* well-known prefixes from the `workerd` runtime:
|
|
138
|
+
*
|
|
139
|
+
* | Prefix | Meaning |
|
|
140
|
+
* |-----------------------|----------------------------------------------|
|
|
141
|
+
* | `D1_ERROR:` | General D1 / SQLite error |
|
|
142
|
+
* | `D1_EXEC_ERROR:` | Error during `.exec()` batch |
|
|
143
|
+
* | `D1_TYPE_ERROR:` | Type mismatch (e.g. `undefined` vs `null`) |
|
|
144
|
+
* | `D1_COLUMN_NOTFOUND` | Referenced column does not exist |
|
|
145
|
+
* | `D1_DUMP_ERROR:` | Error during database dump |
|
|
146
|
+
* | `D1_SESSION_ERROR:` | Session bookmark / constraint error |
|
|
147
|
+
*
|
|
148
|
+
* D1 also surfaces platform-level messages (no prefix) for transient errors:
|
|
149
|
+
* - "Network connection lost."
|
|
150
|
+
* - "D1 DB is overloaded. Too many requests queued."
|
|
151
|
+
* - "Memory limit would be exceeded by this operation."
|
|
152
|
+
* - "Cannot resolve D1 DB due to transient issue on remote node."
|
|
153
|
+
* - "D1 DB reset because its code was updated."
|
|
154
|
+
*
|
|
155
|
+
* Reference:
|
|
156
|
+
* - https://developers.cloudflare.com/d1/platform/client-api/
|
|
157
|
+
* - https://github.com/cloudflare/workerd (src/cloudflare/internal/d1-api.ts)
|
|
158
|
+
*
|
|
159
|
+
* Falls back to a generic DumboError (500) if the error is not a recognized D1 error.
|
|
160
|
+
*/
|
|
161
|
+
const mapD1Error = (error) => {
|
|
162
|
+
if (require_core.DumboError.isInstanceOf(error)) return error;
|
|
163
|
+
const message = getErrorMessage(error);
|
|
164
|
+
if (!message) return new require_core.DumboError({
|
|
165
|
+
errorCode: 500,
|
|
166
|
+
message: error instanceof Error ? error.message : String(error),
|
|
167
|
+
innerError: asError(error)
|
|
168
|
+
});
|
|
169
|
+
const innerError = asError(error);
|
|
170
|
+
const upper = message.toUpperCase();
|
|
171
|
+
if (upper.startsWith("D1_TYPE_ERROR")) return new require_core.DataError(message, innerError);
|
|
172
|
+
if (upper.startsWith("D1_COLUMN_NOTFOUND")) return new require_core.DataError(message, innerError);
|
|
173
|
+
if (upper.startsWith("D1_DUMP_ERROR")) return new require_core.SystemError(message, innerError);
|
|
174
|
+
if (upper.startsWith("D1_SESSION_ERROR")) return new require_core.ConnectionError(message, innerError);
|
|
175
|
+
if (isConstraintMessage(upper)) return mapConstraintError(message, innerError);
|
|
176
|
+
if (upper.includes("NETWORK CONNECTION LOST") || upper.includes("CANNOT RESOLVE D1 DB DUE TO TRANSIENT ISSUE") || upper.includes("D1 DB RESET BECAUSE")) return new require_core.ConnectionError(message, innerError);
|
|
177
|
+
if (upper.includes("D1 DB IS OVERLOADED") || upper.includes("TOO MANY REQUESTS") || upper.includes("MEMORY LIMIT WOULD BE EXCEEDED")) return new require_core.InsufficientResourcesError(message, innerError);
|
|
178
|
+
if (upper.startsWith("D1_ERROR") || upper.startsWith("D1_EXEC_ERROR")) {
|
|
179
|
+
const embeddedCode = extractEmbeddedSqliteCode(message);
|
|
180
|
+
if (embeddedCode) {
|
|
181
|
+
const mapped = mapEmbeddedSqliteCode(embeddedCode, message, innerError);
|
|
182
|
+
if (mapped) return mapped;
|
|
183
|
+
}
|
|
184
|
+
return new require_core.InvalidOperationError(message, innerError);
|
|
185
|
+
}
|
|
186
|
+
const embeddedCode = extractEmbeddedSqliteCode(message);
|
|
187
|
+
if (embeddedCode) {
|
|
188
|
+
const mapped = mapEmbeddedSqliteCode(embeddedCode, message, innerError);
|
|
189
|
+
if (mapped) return mapped;
|
|
190
|
+
}
|
|
191
|
+
return new require_core.DumboError({
|
|
192
|
+
errorCode: 500,
|
|
193
|
+
message,
|
|
194
|
+
innerError
|
|
195
|
+
});
|
|
239
196
|
};
|
|
240
197
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/storage/sqlite/d1/execute/d1SqlExecutor.ts
|
|
200
|
+
const d1SQLExecutor = () => ({
|
|
201
|
+
driverType: "SQLite:d1",
|
|
202
|
+
formatter: require_core$1.sqliteFormatter,
|
|
203
|
+
query: async (client, sql, options) => {
|
|
204
|
+
try {
|
|
205
|
+
return await client.query(sql, options);
|
|
206
|
+
} catch (error) {
|
|
207
|
+
require_core.tracer.error("db:sql:query:execute:error", { error });
|
|
208
|
+
throw mapD1Error(error);
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
batchQuery: async (client, sqls, options) => {
|
|
212
|
+
try {
|
|
213
|
+
return await client.batchQuery(sqls, options);
|
|
214
|
+
} catch (error) {
|
|
215
|
+
require_core.tracer.error("db:sql:batch_query:execute:error", { error });
|
|
216
|
+
throw mapD1Error(error);
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
command: async (client, sql, options) => {
|
|
220
|
+
try {
|
|
221
|
+
return await client.command(sql, options);
|
|
222
|
+
} catch (error) {
|
|
223
|
+
require_core.tracer.error("db:sql:command:execute:error", { error });
|
|
224
|
+
throw mapD1Error(error);
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
batchCommand: async (client, sqls, options) => {
|
|
228
|
+
try {
|
|
229
|
+
return await client.batchCommand(sqls, options);
|
|
230
|
+
} catch (error) {
|
|
231
|
+
require_core.tracer.error("db:sql:batch_command:execute:error", { error });
|
|
232
|
+
throw mapD1Error(error);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
277
235
|
});
|
|
278
236
|
|
|
279
|
-
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region src/storage/sqlite/d1/transactions/d1Transaction.ts
|
|
280
239
|
var D1TransactionNotSupportedError = class extends Error {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
this.name = "D1TransactionNotSupportedError";
|
|
286
|
-
}
|
|
240
|
+
constructor() {
|
|
241
|
+
super("D1 does not support SQL transactions (BEGIN/COMMIT/ROLLBACK/SAVEPOINT). Use { mode: \"session_based\" } to opt-in to session+batch semantics, or use connection.execute.batchCommand() for atomic multi-statement execution.");
|
|
242
|
+
this.name = "D1TransactionNotSupportedError";
|
|
243
|
+
}
|
|
287
244
|
};
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
"Transaction has not been started. Call begin() first."
|
|
350
|
-
);
|
|
351
|
-
}
|
|
352
|
-
return Promise.resolve(sessionClient);
|
|
353
|
-
}
|
|
354
|
-
}),
|
|
355
|
-
_transactionOptions: _nullishCoalesce(options, () => ( {}))
|
|
356
|
-
};
|
|
245
|
+
const d1Transaction = (connection, serializer, defaultOptions) => (getClient, options) => {
|
|
246
|
+
const transactionCounter = require_core$1.transactionNestingCounter();
|
|
247
|
+
const allowNestedTransactions = options?.allowNestedTransactions ?? defaultOptions?.allowNestedTransactions;
|
|
248
|
+
const mode = options?.mode ?? defaultOptions?.mode;
|
|
249
|
+
let client = null;
|
|
250
|
+
let sessionClient = null;
|
|
251
|
+
const getDatabaseClient = async () => {
|
|
252
|
+
if (client) return Promise.resolve(client);
|
|
253
|
+
client = await getClient;
|
|
254
|
+
return client;
|
|
255
|
+
};
|
|
256
|
+
return {
|
|
257
|
+
connection: connection(),
|
|
258
|
+
driverType: D1DriverType,
|
|
259
|
+
begin: async function() {
|
|
260
|
+
if (mode !== "session_based") throw new D1TransactionNotSupportedError();
|
|
261
|
+
const client = await getDatabaseClient();
|
|
262
|
+
if (allowNestedTransactions) {
|
|
263
|
+
if (transactionCounter.level >= 1) {
|
|
264
|
+
transactionCounter.increment();
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
transactionCounter.increment();
|
|
268
|
+
}
|
|
269
|
+
sessionClient = await client.withSession(options?.d1Session);
|
|
270
|
+
},
|
|
271
|
+
commit: async function() {
|
|
272
|
+
const client = await getDatabaseClient();
|
|
273
|
+
try {
|
|
274
|
+
if (allowNestedTransactions) {
|
|
275
|
+
if (transactionCounter.level > 1) {
|
|
276
|
+
transactionCounter.decrement();
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
transactionCounter.reset();
|
|
280
|
+
}
|
|
281
|
+
sessionClient = null;
|
|
282
|
+
} finally {
|
|
283
|
+
if (options?.close) await options?.close(client);
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
rollback: async function(error) {
|
|
287
|
+
const client = await getDatabaseClient();
|
|
288
|
+
try {
|
|
289
|
+
if (allowNestedTransactions) {
|
|
290
|
+
if (transactionCounter.level > 1) {
|
|
291
|
+
transactionCounter.decrement();
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
sessionClient = null;
|
|
296
|
+
} finally {
|
|
297
|
+
if (options?.close) await options?.close(client, error);
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
execute: require_core.sqlExecutor(d1SQLExecutor(), { connect: () => {
|
|
301
|
+
if (!sessionClient) throw new Error("Transaction has not been started. Call begin() first.");
|
|
302
|
+
return Promise.resolve(sessionClient);
|
|
303
|
+
} }),
|
|
304
|
+
_transactionOptions: options ?? {}
|
|
305
|
+
};
|
|
357
306
|
};
|
|
358
307
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
return await handle(sessionConnection);
|
|
387
|
-
} finally {
|
|
388
|
-
await sessionConnection.close();
|
|
389
|
-
}
|
|
390
|
-
};
|
|
391
|
-
return connection;
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region src/storage/sqlite/d1/connections/d1Connection.ts
|
|
310
|
+
const D1DriverType = "SQLite:d1";
|
|
311
|
+
const d1Connection = (options) => {
|
|
312
|
+
const connection = options.connection ?? options.transaction?.connection ?? { ...require_core$1.sqliteAmbientClientConnection({
|
|
313
|
+
driverType: "SQLite:d1",
|
|
314
|
+
client: options.client ?? d1Client(options),
|
|
315
|
+
initTransaction: (connection) => d1Transaction(connection, options.serializer, options.transactionOptions),
|
|
316
|
+
serializer: options.serializer,
|
|
317
|
+
errorMapper: mapD1Error
|
|
318
|
+
}) };
|
|
319
|
+
connection.d1Session = async (constraintOrBookmark) => {
|
|
320
|
+
const sessionClient = await (await connection.open()).withSession(constraintOrBookmark);
|
|
321
|
+
return d1Connection({
|
|
322
|
+
...options,
|
|
323
|
+
client: sessionClient
|
|
324
|
+
});
|
|
325
|
+
};
|
|
326
|
+
connection.withD1Session = async (handle, options) => {
|
|
327
|
+
const sessionConnection = await connection.d1Session(options);
|
|
328
|
+
try {
|
|
329
|
+
return await handle(sessionConnection);
|
|
330
|
+
} finally {
|
|
331
|
+
await sessionConnection.close();
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
return connection;
|
|
392
335
|
};
|
|
393
336
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
337
|
+
//#endregion
|
|
338
|
+
//#region src/storage/sqlite/d1/pool/d1ConnectionPool.ts
|
|
339
|
+
const d1Pool = (options) => require_core.createSingletonConnectionPool({
|
|
340
|
+
driverType: D1DriverType,
|
|
341
|
+
getConnection: () => d1Connection({
|
|
342
|
+
...options,
|
|
343
|
+
serializer: require_core.JSONSerializer.from(options)
|
|
344
|
+
})
|
|
401
345
|
});
|
|
402
346
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region src/storage/sqlite/d1/index.ts
|
|
349
|
+
const d1DumboDriver = {
|
|
350
|
+
driverType: D1DriverType,
|
|
351
|
+
createPool: (options) => d1Pool(options),
|
|
352
|
+
sqlFormatter: require_core$1.sqliteFormatter,
|
|
353
|
+
defaultMigratorOptions: require_core$1.DefaultSQLiteMigratorOptions,
|
|
354
|
+
canHandle: (options) => {
|
|
355
|
+
return options.driverType === "SQLite:d1" && "database" in options;
|
|
356
|
+
},
|
|
357
|
+
databaseMetadata: require_sqliteMetadata.sqliteMetadata
|
|
413
358
|
};
|
|
414
|
-
|
|
415
|
-
|
|
359
|
+
const useD1DumboDriver = () => {
|
|
360
|
+
require_core.dumboDatabaseDriverRegistry.register(D1DriverType, d1DumboDriver);
|
|
416
361
|
};
|
|
417
362
|
useD1DumboDriver();
|
|
418
363
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
exports.
|
|
364
|
+
//#endregion
|
|
365
|
+
exports.D1DriverType = D1DriverType;
|
|
366
|
+
exports.D1TransactionNotSupportedError = D1TransactionNotSupportedError;
|
|
367
|
+
exports.DEFAULT_SQLITE_PRAGMA_OPTIONS = require_core$1.DEFAULT_SQLITE_PRAGMA_OPTIONS;
|
|
368
|
+
exports.DefaultSQLiteMigratorOptions = require_core$1.DefaultSQLiteMigratorOptions;
|
|
369
|
+
exports.InMemorySQLiteDatabase = require_core$1.InMemorySQLiteDatabase;
|
|
370
|
+
exports.SQLiteConnectionString = require_core$1.SQLiteConnectionString;
|
|
371
|
+
exports.SQLiteDatabaseName = require_core$1.SQLiteDatabaseName;
|
|
372
|
+
exports.d1Client = d1Client;
|
|
373
|
+
exports.d1Connection = d1Connection;
|
|
374
|
+
exports.d1DumboDriver = d1DumboDriver;
|
|
375
|
+
exports.d1Pool = d1Pool;
|
|
376
|
+
exports.d1SQLExecutor = d1SQLExecutor;
|
|
377
|
+
exports.d1Transaction = d1Transaction;
|
|
378
|
+
exports.defaultSQLiteDatabase = require_sqliteMetadata.defaultSQLiteDatabase;
|
|
379
|
+
exports.isInMemoryDatabase = require_core$1.isInMemoryDatabase;
|
|
380
|
+
exports.isSQLiteError = require_core$1.isSQLiteError;
|
|
381
|
+
exports.mapD1Error = mapD1Error;
|
|
382
|
+
exports.mapSqliteError = require_core$1.mapSqliteError;
|
|
383
|
+
exports.parsePragmasFromConnectionString = require_core$1.parsePragmasFromConnectionString;
|
|
384
|
+
exports.sqliteAlwaysNewConnectionPool = require_core$1.sqliteAlwaysNewConnectionPool;
|
|
385
|
+
exports.sqliteAmbientClientConnection = require_core$1.sqliteAmbientClientConnection;
|
|
386
|
+
exports.sqliteAmbientConnectionPool = require_core$1.sqliteAmbientConnectionPool;
|
|
387
|
+
exports.sqliteClientConnection = require_core$1.sqliteClientConnection;
|
|
388
|
+
exports.sqliteConnection = require_core$1.sqliteConnection;
|
|
389
|
+
exports.sqliteExecute = require_core$1.sqliteExecute;
|
|
390
|
+
exports.sqliteFormatter = require_core$1.sqliteFormatter;
|
|
391
|
+
exports.sqliteMetadata = require_sqliteMetadata.sqliteMetadata;
|
|
392
|
+
exports.sqlitePool = require_core$1.sqlitePool;
|
|
393
|
+
exports.sqlitePoolClientConnection = require_core$1.sqlitePoolClientConnection;
|
|
394
|
+
exports.sqliteSQLExecutor = require_core$1.sqliteSQLExecutor;
|
|
395
|
+
exports.sqliteSingletonConnectionPool = require_core$1.sqliteSingletonConnectionPool;
|
|
396
|
+
exports.sqliteTransaction = require_core$1.sqliteTransaction;
|
|
397
|
+
exports.tableExists = require_sqliteMetadata.tableExists;
|
|
398
|
+
exports.toSqlitePoolOptions = require_core$1.toSqlitePoolOptions;
|
|
399
|
+
exports.transactionNestingCounter = require_core$1.transactionNestingCounter;
|
|
400
|
+
exports.useD1DumboDriver = useD1DumboDriver;
|
|
456
401
|
//# sourceMappingURL=cloudflare.cjs.map
|