@forestfuture/active-record 0.6.0 → 0.8.0
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/README.md +5 -4
- package/config-schema.json +60 -0
- package/dist/adapter.d.mts +3 -2
- package/dist/adapter.mjs +5 -3
- package/dist/batch-ReqVoCfa.mjs +9559 -0
- package/dist/cli.d.mts +216 -46
- package/dist/cli.mjs +4 -3
- package/dist/command.mjs +1102 -529
- package/dist/d1.d.mts +60 -0
- package/dist/d1.mjs +334 -0
- package/dist/epoch-storage-CDlQZcBB.mjs +988 -0
- package/dist/for-adapters-B0xMP6Dq.d.mts +23 -0
- package/dist/for-adapters-CfXMGeOu.mjs +31 -0
- package/dist/for-adapters-DhNV1mWf.mjs +276 -0
- package/dist/{generated-model-CfDggoVN.mjs → generated-model-g5oWsDKE.mjs} +732 -540
- package/dist/index-BATasvJa.d.mts +241 -0
- package/dist/index.d.mts +4 -143
- package/dist/index.mjs +5 -3
- package/dist/metadata-CzntpYzC.d.mts +182 -0
- package/dist/plugin-wOSILvSB.mjs +699 -0
- package/dist/plugin-x5-d3TSN.mjs +1035 -0
- package/dist/postgresql.d.mts +64 -0
- package/dist/postgresql.mjs +604 -0
- package/dist/src-D56_3odT.mjs +46 -0
- package/dist/storage-override-n4w1cS_M.mjs +220 -0
- package/dist/validations-DHDVV8hB.d.mts +1996 -0
- package/llms-full.txt +3283 -656
- package/package.json +25 -2
- package/skills/active-record/SKILL.md +24 -16
- package/dist/adapter-BSvFhTDf.d.mts +0 -1293
- package/dist/batch-DBeYk5wx.mjs +0 -4171
- package/dist/epoch-storage-o2aoOH7H.mjs +0 -112
- package/dist/storage-override-BYBYP8Mj.mjs +0 -91
|
@@ -0,0 +1,699 @@
|
|
|
1
|
+
import { i as attributeName, n as castDefault, s as listed, t as storageOverride, u as parseJsonc } from "./storage-override-n4w1cS_M.mjs";
|
|
2
|
+
import { a as migrationSql, i as withDigits, n as namesInList, o as quotedName, r as withGeneratedEnum, s as indexName, t as generatedSchema } from "./for-adapters-DhNV1mWf.mjs";
|
|
3
|
+
import { E as underscore } from "./epoch-storage-CDlQZcBB.mjs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
7
|
+
import { createJiti } from "jiti";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { spawn } from "node:child_process";
|
|
11
|
+
// cli/adapters/d1/remote.ts
|
|
12
|
+
const text = (value) => typeof value === "string" && value !== "" ? value : void 0;
|
|
13
|
+
/**
|
|
14
|
+
* The remote database this binding's entry points at, or why there's none: for the console,
|
|
15
|
+
* `preview_database_id` when there is one, as `wrangler dev` opens it, or else `database_id`; for
|
|
16
|
+
* `migrate`, always `database_id`, the one `wrangler d1 migrations apply --remote` changes.
|
|
17
|
+
*/
|
|
18
|
+
function remoteTarget({ binding, entry, configFile }, use = "open") {
|
|
19
|
+
const previewId = use === "open" ? text(entry["preview_database_id"]) : void 0;
|
|
20
|
+
const id = previewId ?? text(entry["database_id"]);
|
|
21
|
+
if (id === void 0) return `${binding} has no database_id in ${basename(configFile)}, which --remote needs`;
|
|
22
|
+
const name = text(entry["database_name"]) ?? binding;
|
|
23
|
+
const target = {
|
|
24
|
+
name,
|
|
25
|
+
description: `Remote ${previewId === void 0 ? "database" : "preview database"} ${binding} (${name}, id ${id})`
|
|
26
|
+
};
|
|
27
|
+
return previewId === void 0 ? target : {
|
|
28
|
+
...target,
|
|
29
|
+
note: "That is the config's preview_database_id, which Wrangler opens in place of database_id."
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// cli/adapters/d1/wrangler.ts
|
|
33
|
+
/** The names a Wrangler config has, in the order Wrangler looks for them. */
|
|
34
|
+
const candidates = [
|
|
35
|
+
"wrangler.jsonc",
|
|
36
|
+
"wrangler.json",
|
|
37
|
+
"wrangler.toml"
|
|
38
|
+
];
|
|
39
|
+
/** A TOML basic string's contents, its escapes decoded (`\\` → `\`, `\u00e9` → `é`). */
|
|
40
|
+
function basicString(body) {
|
|
41
|
+
return JSON.parse(`"${body.replace(/\\U([0-9a-fA-F]{8})/g, (_, hex) => {
|
|
42
|
+
return JSON.stringify(String.fromCodePoint(Number.parseInt(hex, 16))).slice(1, -1);
|
|
43
|
+
})}"`);
|
|
44
|
+
}
|
|
45
|
+
/** A TOML line's `key = "string"` as `[key, value]`, or undefined for any other line. */
|
|
46
|
+
function tomlPair(line) {
|
|
47
|
+
const pair = /^([\w-]+)\s*=\s*(?:"((?:[^"\\]|\\.)*)"|'([^']*)')/.exec(line);
|
|
48
|
+
if (pair === null) return void 0;
|
|
49
|
+
return [pair[1], pair[2] === void 0 ? pair[3] : basicString(pair[2])];
|
|
50
|
+
}
|
|
51
|
+
/** The `[[d1_databases]]` entries and top-level `account_id` of a wrangler.toml: the keys read. */
|
|
52
|
+
function parseToml(text) {
|
|
53
|
+
const databases = [];
|
|
54
|
+
const topLevel = {};
|
|
55
|
+
let current = topLevel;
|
|
56
|
+
for (const line of text.split("\n").map((each) => each.trim())) {
|
|
57
|
+
if (line.startsWith("[")) {
|
|
58
|
+
current = /^\[\[\s*d1_databases\s*\]\](\s*#.*)?$/.test(line) ? {} : void 0;
|
|
59
|
+
if (current !== void 0) databases.push(current);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const pair = tomlPair(line);
|
|
63
|
+
if (current !== void 0 && pair !== void 0) current[pair[0]] = pair[1];
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
d1_databases: databases,
|
|
67
|
+
account_id: topLevel.account_id
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** The parsed config file, or why it couldn't be read. */
|
|
71
|
+
function parsed(file) {
|
|
72
|
+
const text = readFileSync(file, "utf8");
|
|
73
|
+
try {
|
|
74
|
+
return file.endsWith(".toml") ? parseToml(text) : parseJsonc(text);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
return `${basename(file)} couldn't be read: ${error.message}`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** A config entry as a database: its binding, and its migrations' folder, pattern and table. */
|
|
80
|
+
function databaseOf(entry) {
|
|
81
|
+
const database = {
|
|
82
|
+
binding: String(entry.binding),
|
|
83
|
+
migrationsDir: typeof entry.migrations_dir === "string" ? entry.migrations_dir : "migrations",
|
|
84
|
+
entry
|
|
85
|
+
};
|
|
86
|
+
if (typeof entry.migrations_pattern === "string") database.migrationsPattern = entry.migrations_pattern;
|
|
87
|
+
if (typeof entry.migrations_table === "string") database.migrationsTable = entry.migrations_table;
|
|
88
|
+
return database;
|
|
89
|
+
}
|
|
90
|
+
/** The Wrangler config in `dir`: `wrangler.jsonc`, `wrangler.json` or `wrangler.toml`, if any. */
|
|
91
|
+
function wranglerConfigIn(dir) {
|
|
92
|
+
return candidates.map((each) => join(dir, each)).find((path) => existsSync(path));
|
|
93
|
+
}
|
|
94
|
+
/** The Wrangler config's `d1_databases` entries, each with a binding, or why they can't be read. */
|
|
95
|
+
function d1Entries(file) {
|
|
96
|
+
const config = parsed(file);
|
|
97
|
+
if (typeof config === "string") return config;
|
|
98
|
+
const entries = config.d1_databases ?? [];
|
|
99
|
+
if (entries.some((entry) => typeof entry.binding !== "string")) return `${basename(file)} has a d1_databases entry with no binding`;
|
|
100
|
+
return entries;
|
|
101
|
+
}
|
|
102
|
+
/** The account a Wrangler config names (`account_id`), if it names one and can be read. */
|
|
103
|
+
function accountIdIn(configFile) {
|
|
104
|
+
const config = parsed(configFile);
|
|
105
|
+
if (typeof config === "string") return void 0;
|
|
106
|
+
return typeof config.account_id === "string" ? config.account_id : void 0;
|
|
107
|
+
}
|
|
108
|
+
// cli/adapters/d1/installed-wrangler.ts
|
|
109
|
+
/**
|
|
110
|
+
* `specifier` (`wrangler`, or a file of its package) as it resolves from the folder of the
|
|
111
|
+
* database's Wrangler config, or else from `cwd`; undefined when it resolves from neither.
|
|
112
|
+
*/
|
|
113
|
+
function resolveWrangler(cwd, configFile, specifier) {
|
|
114
|
+
for (const from of [dirname(configFile), cwd]) try {
|
|
115
|
+
return createJiti(`${from}/`).esmResolve(specifier);
|
|
116
|
+
} catch {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// cli/adapters/d1/binding.ts
|
|
121
|
+
/**
|
|
122
|
+
* A Wrangler config holding only this D1 binding, in a folder of its own. `getPlatformProxy`
|
|
123
|
+
* starts every binding a config declares, so the project's own config would bring its Durable
|
|
124
|
+
* Objects, services and secrets (with their warnings, or failures) into a console that only
|
|
125
|
+
* needs the database. The entry is the project's, verbatim, so Wrangler names the same local D1;
|
|
126
|
+
* the `account_id` is carried so a remote proxy signs in to the project's account.
|
|
127
|
+
*/
|
|
128
|
+
function d1OnlyConfig(entry, accountId) {
|
|
129
|
+
const dir = mkdtempSync(join(tmpdir(), "d1-record-console-"));
|
|
130
|
+
const file = join(dir, "wrangler.jsonc");
|
|
131
|
+
writeFileSync(file, JSON.stringify({
|
|
132
|
+
name: "d1-record-console",
|
|
133
|
+
account_id: accountId,
|
|
134
|
+
d1_databases: [entry]
|
|
135
|
+
}));
|
|
136
|
+
return {
|
|
137
|
+
file,
|
|
138
|
+
remove: () => rmSync(dir, {
|
|
139
|
+
recursive: true,
|
|
140
|
+
force: true
|
|
141
|
+
})
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/** The project's own wrangler, loaded (the Worker's, beside its config, first); or why it can't be. */
|
|
145
|
+
async function projectWrangler(cwd, configFile) {
|
|
146
|
+
const file = resolveWrangler(cwd, configFile, "wrangler");
|
|
147
|
+
if (file === void 0) return "wrangler isn't installed here (install it, then run active-record console again)";
|
|
148
|
+
try {
|
|
149
|
+
return createRequire(import.meta.url)(fileURLToPath(file));
|
|
150
|
+
} catch (error) {
|
|
151
|
+
return `Couldn't load wrangler: ${error.message}`;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async function open(cwd, { binding, configFile }, opening) {
|
|
155
|
+
const wrangler = await projectWrangler(cwd, configFile);
|
|
156
|
+
if (typeof wrangler === "string") return wrangler;
|
|
157
|
+
const config = d1OnlyConfig(opening.entry, accountIdIn(configFile));
|
|
158
|
+
let proxy;
|
|
159
|
+
try {
|
|
160
|
+
proxy = await wrangler.getPlatformProxy({
|
|
161
|
+
configPath: config.file,
|
|
162
|
+
persist: opening.persist,
|
|
163
|
+
remoteBindings: opening.remoteBindings
|
|
164
|
+
});
|
|
165
|
+
} catch (error) {
|
|
166
|
+
config.remove();
|
|
167
|
+
return opening.failure(binding, error.message);
|
|
168
|
+
}
|
|
169
|
+
process.once("exit", config.remove);
|
|
170
|
+
return {
|
|
171
|
+
binding: proxy.env[binding],
|
|
172
|
+
description: opening.describe(binding),
|
|
173
|
+
dispose: async () => {
|
|
174
|
+
process.off("exit", config.remove);
|
|
175
|
+
try {
|
|
176
|
+
await proxy.dispose();
|
|
177
|
+
} finally {
|
|
178
|
+
config.remove();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* The chosen binding on the project's local D1, in the `.wrangler/state` beside the config that
|
|
185
|
+
* `wrangler dev` and `wrangler d1 migrations apply --local` use (`getPlatformProxy`'s own default
|
|
186
|
+
* is relative to the working directory, which can be anywhere). `remoteBindings: false` keeps it
|
|
187
|
+
* local even for a binding the config marks `remote: true`, which Wrangler would otherwise use.
|
|
188
|
+
*/
|
|
189
|
+
function openLocalBinding(cwd, chosen) {
|
|
190
|
+
return open(cwd, chosen, {
|
|
191
|
+
entry: chosen.entry,
|
|
192
|
+
persist: { path: join(dirname(chosen.configFile), ".wrangler/state/v3") },
|
|
193
|
+
remoteBindings: false,
|
|
194
|
+
describe: (binding) => `Local database ${binding} (.wrangler/state)`,
|
|
195
|
+
failure: (binding, reason) => `Wrangler couldn't open ${binding}: ${reason}`
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
const signInHint = "Sign in with 'wrangler login', or set CLOUDFLARE_API_TOKEN (and CLOUDFLARE_ACCOUNT_ID).";
|
|
199
|
+
/**
|
|
200
|
+
* The chosen binding on the project's real D1, through Wrangler's remote proxy: its entry is
|
|
201
|
+
* marked `remote: true` whatever the config says, since asking for `--remote` is the consent.
|
|
202
|
+
* Nothing is kept locally. Which database that is follows Wrangler: `preview_database_id` first.
|
|
203
|
+
*/
|
|
204
|
+
function openRemoteBinding(cwd, chosen) {
|
|
205
|
+
const target = remoteTarget(chosen);
|
|
206
|
+
if (typeof target === "string") return Promise.resolve(target);
|
|
207
|
+
return open(cwd, chosen, {
|
|
208
|
+
entry: {
|
|
209
|
+
...chosen.entry,
|
|
210
|
+
remote: true
|
|
211
|
+
},
|
|
212
|
+
persist: false,
|
|
213
|
+
remoteBindings: true,
|
|
214
|
+
describe: () => target.description,
|
|
215
|
+
failure: (binding, reason) => `Wrangler couldn't open ${binding} remotely: ${reason}\n${signInHint}`
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
// cli/adapters/d1/databases.ts
|
|
219
|
+
/**
|
|
220
|
+
* A path as a message names it: relative to `active-record.jsonc`'s folder, with forward slashes,
|
|
221
|
+
* and that folder itself as `.`.
|
|
222
|
+
*/
|
|
223
|
+
function shown(project, path) {
|
|
224
|
+
return relative(project.dir, path).split(sep).join("/") || ".";
|
|
225
|
+
}
|
|
226
|
+
/** The Wrangler config a database's entry names with `wranglerConfig`, or why it can't be read. */
|
|
227
|
+
function namedConfig(binding, named, project) {
|
|
228
|
+
const setting = `${basename(project.file)}: databases.${binding}.wranglerConfig`;
|
|
229
|
+
if (typeof named !== "string") return { error: `${setting} isn't a string` };
|
|
230
|
+
const file = resolve(project.dir, named);
|
|
231
|
+
const settingNames = `${setting} names ${shown(project, file)}`;
|
|
232
|
+
const stat = statSync(file, { throwIfNoEntry: false });
|
|
233
|
+
if (stat === void 0) return { error: `${settingNames}, which isn't there` };
|
|
234
|
+
if (stat.isDirectory()) return { error: `${settingNames}, which is a folder; name its ${listed(candidates)}` };
|
|
235
|
+
return { file };
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* A database's Wrangler config: the one its entry names, or else `beside`, the one beside the file.
|
|
239
|
+
*/
|
|
240
|
+
function configOf(binding, entry, project, beside) {
|
|
241
|
+
if (entry.wranglerConfig !== void 0) return namedConfig(binding, entry.wranglerConfig, project);
|
|
242
|
+
if (beside !== void 0) return { file: beside };
|
|
243
|
+
return { error: `No ${listed(candidates)} beside ${basename(project.file)}` };
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* A note for the D1 databases a Wrangler config has that `active-record.jsonc` doesn't name, which
|
|
247
|
+
* the command leaves out, so one added to Wrangler's config alone isn't missed in silence (#301).
|
|
248
|
+
* `init` adds those in the config beside the file; one elsewhere is added by hand (#306).
|
|
249
|
+
*/
|
|
250
|
+
function unnamed(entries, project, file, beside) {
|
|
251
|
+
const left = entries.map((entry) => String(entry.binding)).filter((binding) => !Object.hasOwn(project.databases, binding));
|
|
252
|
+
if (left.length === 0) return [];
|
|
253
|
+
const one = left.length === 1;
|
|
254
|
+
const which = `the D1 database${one ? "" : "s"} ${listed(left, "and")}`;
|
|
255
|
+
const path = shown(project, file);
|
|
256
|
+
const add = file === beside ? `run \`npx active-record init\` to add ${one ? "it" : "them"}` : `add ${one ? "it" : "each"} with "wranglerConfig": ${JSON.stringify(path)}`;
|
|
257
|
+
return [`${path} has ${which}, which ${basename(project.file)} doesn't name; ${add}`];
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* The D1 databases a project's `active-record.jsonc` names, each as its Wrangler config declares
|
|
261
|
+
* it: the config its entry's `wranglerConfig` names, relative to the file, or else `wrangler.jsonc`,
|
|
262
|
+
* `wrangler.json` or `wrangler.toml` beside the file. Wrangler's other D1 databases are left out.
|
|
263
|
+
*/
|
|
264
|
+
function readDatabases(project) {
|
|
265
|
+
const name = basename(project.file);
|
|
266
|
+
const beside = wranglerConfigIn(project.dir);
|
|
267
|
+
const entriesByConfig = /* @__PURE__ */ new Map();
|
|
268
|
+
const databases = [];
|
|
269
|
+
for (const [binding, settings] of Object.entries(project.databases)) {
|
|
270
|
+
const found = configOf(binding, settings, project, beside);
|
|
271
|
+
if ("error" in found) return {
|
|
272
|
+
ok: false,
|
|
273
|
+
error: found.error
|
|
274
|
+
};
|
|
275
|
+
const entries = entriesByConfig.get(found.file) ?? d1Entries(found.file);
|
|
276
|
+
if (typeof entries === "string") return {
|
|
277
|
+
ok: false,
|
|
278
|
+
error: entries
|
|
279
|
+
};
|
|
280
|
+
entriesByConfig.set(found.file, entries);
|
|
281
|
+
const entry = entries.find((each) => each.binding === binding);
|
|
282
|
+
if (entry === void 0) return {
|
|
283
|
+
ok: false,
|
|
284
|
+
error: `${name} names ${binding}, which isn't in ${shown(project, found.file)}'s d1_databases`
|
|
285
|
+
};
|
|
286
|
+
databases.push({
|
|
287
|
+
...databaseOf(entry),
|
|
288
|
+
configFile: found.file
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
const notes = [...entriesByConfig].flatMap(([file, entries]) => unnamed(entries, project, file, beside));
|
|
292
|
+
return {
|
|
293
|
+
ok: true,
|
|
294
|
+
file: project.file,
|
|
295
|
+
dir: project.dir,
|
|
296
|
+
databases,
|
|
297
|
+
notes
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
// cli/adapters/d1/init.ts
|
|
301
|
+
/**
|
|
302
|
+
* The D1 databases in the Wrangler config in `dir`, each as an entry with nothing but its
|
|
303
|
+
* adapter: Wrangler's config keeps the rest. Undefined when there are none, unless `--adapter` named D1.
|
|
304
|
+
*/
|
|
305
|
+
function init(dir, named) {
|
|
306
|
+
const file = wranglerConfigIn(dir);
|
|
307
|
+
if (file === void 0) {
|
|
308
|
+
if (!named) return void 0;
|
|
309
|
+
return "No wrangler.jsonc, wrangler.json or wrangler.toml here: declare your D1 database in one first";
|
|
310
|
+
}
|
|
311
|
+
const entries = d1Entries(file);
|
|
312
|
+
if (typeof entries === "string") return entries;
|
|
313
|
+
if (entries.length === 0) return named ? `${basename(file)} has no d1_databases: declare your database there first` : void 0;
|
|
314
|
+
return { databases: Object.fromEntries(entries.map((entry) => [String(entry.binding), {}])) };
|
|
315
|
+
}
|
|
316
|
+
// cli/adapters/d1/migrate.ts
|
|
317
|
+
/** The project's own Wrangler's command line script (the Worker's, beside its config, first), or why there's none. */
|
|
318
|
+
function wranglerBin(cwd, configFile) {
|
|
319
|
+
const manifest = resolveWrangler(cwd, configFile, "wrangler/package.json");
|
|
320
|
+
if (manifest === void 0) return ["wrangler isn't installed here (install it, then run active-record migrate again)"];
|
|
321
|
+
return join(dirname(fileURLToPath(manifest)), "bin", "wrangler.js");
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Runs `wrangler d1 migrations apply <binding>`, `--local` or `--remote`, with the project's
|
|
325
|
+
* config, as a person would. What Wrangler prints goes to `io`; it resolves to Wrangler's exit code.
|
|
326
|
+
*/
|
|
327
|
+
function migrate(cwd, { binding, configFile }, { remote }, io) {
|
|
328
|
+
const bin = wranglerBin(cwd, configFile);
|
|
329
|
+
if (Array.isArray(bin)) {
|
|
330
|
+
io.output(`${bin[0]}\n`);
|
|
331
|
+
return Promise.resolve(1);
|
|
332
|
+
}
|
|
333
|
+
const args = [
|
|
334
|
+
bin,
|
|
335
|
+
"d1",
|
|
336
|
+
"migrations",
|
|
337
|
+
"apply",
|
|
338
|
+
binding,
|
|
339
|
+
remote ? "--remote" : "--local",
|
|
340
|
+
"--config",
|
|
341
|
+
configFile
|
|
342
|
+
];
|
|
343
|
+
const child = spawn(process.execPath, args, {
|
|
344
|
+
cwd: dirname(configFile),
|
|
345
|
+
env: {
|
|
346
|
+
...process.env,
|
|
347
|
+
CI: "1"
|
|
348
|
+
},
|
|
349
|
+
stdio: [
|
|
350
|
+
"ignore",
|
|
351
|
+
"pipe",
|
|
352
|
+
"pipe"
|
|
353
|
+
]
|
|
354
|
+
});
|
|
355
|
+
child.stdout.on("data", (chunk) => io.output(chunk.toString()));
|
|
356
|
+
child.stderr.on("data", (chunk) => io.output(chunk.toString()));
|
|
357
|
+
return new Promise((resolve) => {
|
|
358
|
+
child.on("error", (error) => {
|
|
359
|
+
io.output(`Couldn't run wrangler: ${error.message}\n`);
|
|
360
|
+
resolve(1);
|
|
361
|
+
});
|
|
362
|
+
child.on("close", (code) => resolve(code ?? 1));
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
// cli/adapters/d1/migration.ts
|
|
366
|
+
/** SQLite's SQL for a generated migration. */
|
|
367
|
+
const sqlite = {
|
|
368
|
+
reserved: new Set("abort action add after all alter always analyze and as asc attach autoincrement before begin between by cascade case cast check collate column commit conflict constraint create cross current current_date current_time current_timestamp database default deferrable deferred delete desc detach distinct do drop each else end escape except exclude exclusive exists explain fail filter first following for foreign from full generated glob group groups having if ignore immediate in index indexed initially inner insert instead intersect into is isnull join key last left like limit match materialized natural no not nothing notnull null nulls of offset on or order others outer over partition plan pragma preceding primary query raise range recursive references regexp reindex release rename replace restrict returning right rollback row rows savepoint select set table temp temporary then ties to transaction trigger unbounded union unique update using vacuum values view virtual when where window with without".split(" ")),
|
|
369
|
+
types: {
|
|
370
|
+
string: "TEXT",
|
|
371
|
+
integer: "INTEGER",
|
|
372
|
+
real: "REAL",
|
|
373
|
+
decimal: "DECIMAL",
|
|
374
|
+
boolean: "BOOLEAN",
|
|
375
|
+
datetime: "DATETIME",
|
|
376
|
+
date: "DATE",
|
|
377
|
+
time: "TIME",
|
|
378
|
+
json: "TEXT",
|
|
379
|
+
binary: "BLOB"
|
|
380
|
+
},
|
|
381
|
+
key: (integerId) => integerId ? "id INTEGER PRIMARY KEY" : "id TEXT PRIMARY KEY NOT NULL",
|
|
382
|
+
timestampType: "DATETIME",
|
|
383
|
+
guessedKeyType: "TEXT",
|
|
384
|
+
check: (column, name) => column.type === "json" ? `CHECK (json_valid(${name}))` : void 0,
|
|
385
|
+
addRefusal: (table, column) => column.type !== "references" && column.notNull && column.default === void 0 ? `${table}.${column.name}: SQLite can't add a NOT NULL column without a default; give one (${column.name}:${column.type}!=…) or leave out the !` : void 0,
|
|
386
|
+
dropColumn: (table, column) => `DROP INDEX IF EXISTS ${indexName(table, column)};\nALTER TABLE ${quotedName(sqlite, table)} DROP COLUMN ${quotedName(sqlite, column)};\n`
|
|
387
|
+
};
|
|
388
|
+
/** A migration's SQL, for SQLite as D1 runs it, with a note for each key type it guessed. */
|
|
389
|
+
function migration(change) {
|
|
390
|
+
return migrationSql(change, sqlite);
|
|
391
|
+
}
|
|
392
|
+
// cli/adapters/d1/checks.ts
|
|
393
|
+
/**
|
|
394
|
+
* A column name as SQLite takes it: bare, or quoted with "", ``, or [], on one line and at most
|
|
395
|
+
* 128 characters, so an unclosed quote can't make a search scan the rest of the text each time.
|
|
396
|
+
*/
|
|
397
|
+
const columnName = String.raw`(?:"[^"\n]{1,128}"|\x60[^\x60\n]{1,128}\x60|\[[^\]\n]{1,128}\]|\w+)`;
|
|
398
|
+
/** A list of SQL string literals: `'draft', 'it''s'`. */
|
|
399
|
+
const stringList = String.raw`'(?:[^']|'')*'(?:\s*,\s*'(?:[^']|'')*')*`;
|
|
400
|
+
/**
|
|
401
|
+
* `CHECK (status IN ('draft', 'published'))`, or with `status IS NULL OR` before it or
|
|
402
|
+
* `OR status IS NULL` after it: the columns named, and the list.
|
|
403
|
+
*/
|
|
404
|
+
const inCheck = new RegExp(String.raw`CHECK\s*\(\s*(?:(${columnName})\s+IS\s+NULL\s+OR\s+)?(${columnName})\s+IN\s*\(\s*(${stringList})\s*\)(?:\s+OR\s+(${columnName})\s+IS\s+NULL)?\s*\)`, "gi");
|
|
405
|
+
/**
|
|
406
|
+
* A string literal or a name quoted any of SQLite's ways, kept, or a comment, dropped: whichever
|
|
407
|
+
* starts first, so a `'` or `--` inside a name doesn't start or hide anything. An unclosed `[`,
|
|
408
|
+
* like an unclosed block comment, runs to the end, so a run of them isn't rescanned from each.
|
|
409
|
+
*/
|
|
410
|
+
const literalOrComment = /'(?:[^']|'')*'|"(?:[^"]|"")*"|`(?:[^`]|``)*`|\[[^\]]*\]?|--[^\n]*|\/\*[\s\S]*?(?:\*\/|$)/g;
|
|
411
|
+
/** A definition without its comments, which SQLite keeps in it: `a TEXT -- CHECK (…)` → `a TEXT `. */
|
|
412
|
+
function withoutComments(definition) {
|
|
413
|
+
return definition.replace(literalOrComment, (token) => token.startsWith("--") || token.startsWith("/*") ? " " : token);
|
|
414
|
+
}
|
|
415
|
+
/** A column name as a key, as SQLite compares them: unquoted, any case. `"Status"` → `status`. */
|
|
416
|
+
function columnKey(name) {
|
|
417
|
+
return (/^["`[]/.test(name) ? name.slice(1, -1) : name).toLowerCase();
|
|
418
|
+
}
|
|
419
|
+
/** The column a match restricts, unless its `IS NULL` names another one. */
|
|
420
|
+
function restricted(match) {
|
|
421
|
+
const column = columnKey(match[2]);
|
|
422
|
+
return [match[1], match[4]].filter((name) => name !== void 0).map(columnKey).every((name) => name === column) ? column : void 0;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Each column a table's definition restricts to a list of strings, with the list, by its name in
|
|
426
|
+
* lower case. A column two lists restrict isn't one: which list holds isn't the schema's to say.
|
|
427
|
+
*/
|
|
428
|
+
function checkedNames(definition) {
|
|
429
|
+
const lists = /* @__PURE__ */ new Map();
|
|
430
|
+
for (const match of withoutComments(definition).matchAll(inCheck)) {
|
|
431
|
+
const column = restricted(match);
|
|
432
|
+
if (column === void 0) continue;
|
|
433
|
+
lists.set(column, lists.has(column) ? void 0 : namesInList(match[3]));
|
|
434
|
+
}
|
|
435
|
+
return new Map([...lists].filter((entry) => entry[1] !== void 0));
|
|
436
|
+
}
|
|
437
|
+
// cli/adapters/d1/conventions.ts
|
|
438
|
+
const declaredTypes = [
|
|
439
|
+
[/^BOOL/, "boolean"],
|
|
440
|
+
[/^(DATETIME|TIMESTAMP)$/, "datetime"],
|
|
441
|
+
[/^DATE$/, "date"],
|
|
442
|
+
[/^TIME$/, "time"],
|
|
443
|
+
[/^(NUMERIC|DECIMAL)$/, "decimal"],
|
|
444
|
+
[/^JSON$/, "json"],
|
|
445
|
+
[/^BLOB$/, "binary"],
|
|
446
|
+
[/INT/, "integer"],
|
|
447
|
+
[/CHAR|CLOB|TEXT/, "string"],
|
|
448
|
+
[/REAL|FLOA|DOUB/, "real"]
|
|
449
|
+
];
|
|
450
|
+
/** The declared type's name, without its size or precision: `VARCHAR(40)` → `VARCHAR`. */
|
|
451
|
+
function baseType(declared) {
|
|
452
|
+
const open = declared.indexOf("(");
|
|
453
|
+
const close = declared.lastIndexOf(")");
|
|
454
|
+
return (open !== -1 && close > open ? declared.slice(0, open) + declared.slice(close + 1) : declared).toUpperCase().trim();
|
|
455
|
+
}
|
|
456
|
+
/** A default that's a number or an epoch function, which a datetime in ISO text wouldn't hold. */
|
|
457
|
+
const epochDefault = /^\(?\s*-?\d+(\.\d+)?\s*\)?$|unixepoch|strftime\s*\(\s*'%s'/i;
|
|
458
|
+
/** A note for a datetime column whose default looks like a Unix time (#73). */
|
|
459
|
+
function epochDefaultNote(column, type) {
|
|
460
|
+
if (type !== "datetime" || column.defaultValue === null) return void 0;
|
|
461
|
+
if (!epochDefault.test(column.defaultValue.trim())) return void 0;
|
|
462
|
+
return `${column.table}.${column.name}: a datetime with a number as its default; if it holds a Unix time, override it in its Model as ${storageOverride(false)}`;
|
|
463
|
+
}
|
|
464
|
+
/** A column's attribute type: its declared type first, then its name for plain TEXT/INTEGER. */
|
|
465
|
+
function typeOf(column) {
|
|
466
|
+
return typeOfDeclared(column, baseType(column.declaredType || (column.referencedType ?? "")), `${column.table}.${column.name}`);
|
|
467
|
+
}
|
|
468
|
+
/** The attribute type for a supported declared type; a guess (`string`) comes with a note (#159). */
|
|
469
|
+
function typeOfDeclared(column, declared, where) {
|
|
470
|
+
const matched = declaredTypes.find(([pattern]) => pattern.test(declared))?.[1];
|
|
471
|
+
if ((matched === void 0 || matched === "string") && column.jsonChecked) return { type: "json" };
|
|
472
|
+
if (matched === void 0) return {
|
|
473
|
+
type: "string",
|
|
474
|
+
note: unmatchedNote(declared, where)
|
|
475
|
+
};
|
|
476
|
+
return declared === "TEXT" || declared === "INTEGER" ? refinedByName(column, matched, where) : { type: matched };
|
|
477
|
+
}
|
|
478
|
+
/** A note for a column whose declared type is none of the types SQLite gives an affinity (#159). */
|
|
479
|
+
function unmatchedNote(declared, where) {
|
|
480
|
+
return `${where}: ${declared === "" ? "has no declared type" : `is declared ${declared}`}, so it's read as a string; a number in it fails when the record loads, so override it in its Model with the type it holds`;
|
|
481
|
+
}
|
|
482
|
+
/** A column declared exactly TEXT or INTEGER, refined by its name (Rails' conventions). */
|
|
483
|
+
function refinedByName(column, type, where) {
|
|
484
|
+
if (type === "string" && column.name.endsWith("_at")) return { type: "datetime" };
|
|
485
|
+
const prefix = /^(is|has)_/.exec(column.name)?.[1];
|
|
486
|
+
if (type === "integer" && prefix !== void 0 && !column.primaryKey) return {
|
|
487
|
+
type: "boolean",
|
|
488
|
+
note: `${where}: INTEGER read as boolean, from its ${prefix}_ name`
|
|
489
|
+
};
|
|
490
|
+
return { type };
|
|
491
|
+
}
|
|
492
|
+
/** A quoted SQL string literal's text: `'it''s'` → `it's`; undefined if it isn't one. */
|
|
493
|
+
function quoted(value) {
|
|
494
|
+
return /^'(?:[^']|'')*'$/.test(value) ? value.slice(1, -1).replaceAll("''", "'") : void 0;
|
|
495
|
+
}
|
|
496
|
+
function booleanDefault(value) {
|
|
497
|
+
if (/^(TRUE|1)$/i.test(value)) return { literal: true };
|
|
498
|
+
return /^(FALSE|0)$/i.test(value) ? { literal: false } : void 0;
|
|
499
|
+
}
|
|
500
|
+
/** A number, when JavaScript holds it exactly; larger integers are left to D1. */
|
|
501
|
+
function numberDefault(value, type) {
|
|
502
|
+
if (type === "integer" && /^(TRUE|FALSE)$/i.test(value)) return { literal: /^TRUE$/i.test(value) ? 1 : 0 };
|
|
503
|
+
if (!/^-?\d+(\.\d+)?$/.test(value)) return void 0;
|
|
504
|
+
const number = Number(value);
|
|
505
|
+
return type === "integer" && !Number.isSafeInteger(number) ? void 0 : { literal: number };
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* A quoted default's text as the attribute's: a string's as it is, a date's or a time's in its
|
|
509
|
+
* one form (#391), a datetime's as its date, and a json column's as its JSON.
|
|
510
|
+
*/
|
|
511
|
+
function textDefault(text, type) {
|
|
512
|
+
if (type === "string") return { literal: text };
|
|
513
|
+
if (type === "date" || type === "time") return castDefault(type, text);
|
|
514
|
+
if (type === "datetime") return Number.isNaN(Date.parse(text)) ? void 0 : { date: text };
|
|
515
|
+
try {
|
|
516
|
+
return { literal: JSON.parse(text) };
|
|
517
|
+
} catch {
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
/** A SQL literal default as a value of the attribute's type; undefined for anything else. */
|
|
522
|
+
function literalDefault(sql, { type, precision, scale }) {
|
|
523
|
+
if (sql === null || type === "binary") return void 0;
|
|
524
|
+
const value = sql.trim();
|
|
525
|
+
if (type === "boolean") return booleanDefault(value);
|
|
526
|
+
if (type === "integer" || type === "real") return numberDefault(value, type);
|
|
527
|
+
if (type === "decimal") return castDefault(type, quoted(value) ?? value, {
|
|
528
|
+
precision,
|
|
529
|
+
scale
|
|
530
|
+
});
|
|
531
|
+
const text = quoted(value);
|
|
532
|
+
return text === void 0 ? void 0 : textDefault(text, type);
|
|
533
|
+
}
|
|
534
|
+
/** A default that SQLite writes as date text with a space (`2026-10-12 06:38:30`), not ISO. */
|
|
535
|
+
const dateTextDefault = /^\(?\s*(current_timestamp|datetime\s*\(\s*'now'[^)]*\))\s*\)?$/i;
|
|
536
|
+
/** Whether a datetime column's default writes SQLite's date text, which sorts apart from ISO (#143). */
|
|
537
|
+
function hasDateTextDefault(column, type) {
|
|
538
|
+
return type === "datetime" && dateTextDefault.test(column.defaultValue?.trim() ?? "");
|
|
539
|
+
}
|
|
540
|
+
/** A column's spec: nullability, a mapped column name, and its default or generated key. */
|
|
541
|
+
function specOf(column, type, attribute) {
|
|
542
|
+
const spec = withSizeDigits({ type }, column.declaredType);
|
|
543
|
+
if (column.notNull || column.primaryKey) spec.null = false;
|
|
544
|
+
if (underscore(attribute) !== column.name) spec.column = column.name;
|
|
545
|
+
const defaultValue = literalDefault(column.defaultValue, spec);
|
|
546
|
+
if (defaultValue !== void 0) spec.default = defaultValue;
|
|
547
|
+
else if (column.primaryKey && type === "string") spec.generateId = true;
|
|
548
|
+
return withGeneratedEnum(spec, column.restrictedTo);
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* A decimal's precision and scale from its declared type's size: `DECIMAL(10, 2)` gives 10 and
|
|
552
|
+
* 2, `NUMERIC(6)` a precision of 6 (#398). A size that isn't whole numbers gives neither.
|
|
553
|
+
*/
|
|
554
|
+
function withSizeDigits(spec, declared) {
|
|
555
|
+
const open = declared.indexOf("(");
|
|
556
|
+
const close = declared.indexOf(")", open);
|
|
557
|
+
if (open === -1 || close === -1) return spec;
|
|
558
|
+
const digits = declared.slice(open + 1, close).split(",").map((part) => part.trim());
|
|
559
|
+
if (digits.length > 2 || !digits.every((part) => /^\d+$/.test(part))) return spec;
|
|
560
|
+
const [precision, scale] = digits.map(Number);
|
|
561
|
+
return withDigits(spec, precision, scale);
|
|
562
|
+
}
|
|
563
|
+
/** A column as an attribute, by the conventions (#66): name, type, nullability and default. */
|
|
564
|
+
function convert(column) {
|
|
565
|
+
const { type, note: typeNote } = typeOf(column);
|
|
566
|
+
const note = typeNote ?? epochDefaultNote(column, type);
|
|
567
|
+
const attribute = attributeName(column.name);
|
|
568
|
+
return {
|
|
569
|
+
ok: true,
|
|
570
|
+
attribute,
|
|
571
|
+
spec: specOf(column, type, attribute),
|
|
572
|
+
...note !== void 0 && { note },
|
|
573
|
+
...hasDateTextDefault(column, type) && { textDate: true }
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
// cli/adapters/d1/schema.ts
|
|
577
|
+
/** Each table's definition (`CREATE TABLE …`), by name. */
|
|
578
|
+
function definitions(db) {
|
|
579
|
+
const rows = db.prepare("SELECT name, sql FROM sqlite_master WHERE type = 'table'").all();
|
|
580
|
+
return new Map(rows.map((row) => [String(row.name), String(row.sql)]));
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Applies the migrations in order to an in-memory SQLite database, noting which one last
|
|
584
|
+
* changed each table. A migration that fails is reported by its file name.
|
|
585
|
+
*/
|
|
586
|
+
function applied(migrations) {
|
|
587
|
+
const changedBy = /* @__PURE__ */ new Map();
|
|
588
|
+
const { DatabaseSync: Database } = process.getBuiltinModule("node:sqlite");
|
|
589
|
+
const db = new Database(":memory:");
|
|
590
|
+
let before = definitions(db);
|
|
591
|
+
for (const { name, sql } of migrations) {
|
|
592
|
+
try {
|
|
593
|
+
db.exec(sql);
|
|
594
|
+
} catch (error) {
|
|
595
|
+
return {
|
|
596
|
+
changedBy,
|
|
597
|
+
error: `${name}: ${error.message}`
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
const after = definitions(db);
|
|
601
|
+
for (const [table, definition] of after) if (before.get(table) !== definition) changedBy.set(table, name);
|
|
602
|
+
before = after;
|
|
603
|
+
}
|
|
604
|
+
return {
|
|
605
|
+
db,
|
|
606
|
+
changedBy
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* The tables a Model can be built on: not SQLite's, Cloudflare's or Wrangler's own, and not a
|
|
611
|
+
* virtual table (full-text search, say) or the shadow tables SQLite keeps for one.
|
|
612
|
+
*/
|
|
613
|
+
function ownTables(all, migrationsTable) {
|
|
614
|
+
const virtual = [...all].filter(([, sql]) => /^CREATE\s+VIRTUAL\s+TABLE/i.test(sql)).map(([name]) => name);
|
|
615
|
+
const shadow = (name) => virtual.some((table) => name === table || name.startsWith(`${table}_`));
|
|
616
|
+
const internal = (name) => name.startsWith("sqlite_") || name.startsWith("_cf_") || name === migrationsTable;
|
|
617
|
+
return [...all].filter(([name]) => !internal(name) && !shadow(name));
|
|
618
|
+
}
|
|
619
|
+
/** The columns `json_valid` checks in a table's definition: `CHECK (json_valid(settings))`. */
|
|
620
|
+
function jsonChecked(definition) {
|
|
621
|
+
return new Set([...definition.matchAll(/json_valid\(\s*(?:"([^"]+)"|`([^`]+)`|\[([^\]]+)\]|(\w+))\s*\)/gi)].map((match) => match.slice(1).find(Boolean)));
|
|
622
|
+
}
|
|
623
|
+
/** The declared type of each column a foreign key references, by the referencing column. */
|
|
624
|
+
function referencedTypes(db, table) {
|
|
625
|
+
const keys = db.prepare("SELECT \"from\", \"table\", \"to\" FROM pragma_foreign_key_list(?)").all(table);
|
|
626
|
+
const types = /* @__PURE__ */ new Map();
|
|
627
|
+
for (const key of keys) {
|
|
628
|
+
const target = db.prepare("SELECT name, type, pk FROM pragma_table_info(?)").all(String(key.table)).find((column) => key.to === null ? Number(column.pk) > 0 : column.name === key.to);
|
|
629
|
+
if (target !== void 0) types.set(String(key.from), String(target.type));
|
|
630
|
+
}
|
|
631
|
+
return types;
|
|
632
|
+
}
|
|
633
|
+
/** A table's columns, as the conventions read them. */
|
|
634
|
+
function columnsOf(db, table, definition) {
|
|
635
|
+
const json = jsonChecked(definition);
|
|
636
|
+
const lists = checkedNames(definition);
|
|
637
|
+
const referenced = referencedTypes(db, table);
|
|
638
|
+
return db.prepare("SELECT name, type, \"notnull\", dflt_value, pk FROM pragma_table_info(?)").all(table).map((row) => ({
|
|
639
|
+
table,
|
|
640
|
+
name: String(row.name),
|
|
641
|
+
declaredType: String(row.type),
|
|
642
|
+
notNull: row.notnull === 1,
|
|
643
|
+
defaultValue: row.dflt_value === null ? null : String(row.dflt_value),
|
|
644
|
+
primaryKey: Number(row.pk) > 0,
|
|
645
|
+
jsonChecked: json.has(String(row.name)),
|
|
646
|
+
referencedType: referenced.get(String(row.name)),
|
|
647
|
+
restrictedTo: lists.get(String(row.name).toLowerCase())
|
|
648
|
+
}));
|
|
649
|
+
}
|
|
650
|
+
/** The error for a table without a primary key, saying what D1 takes. */
|
|
651
|
+
const missingKey = (name) => `${name}: no primary key; Active Record needs one (id INTEGER PRIMARY KEY, or id TEXT PRIMARY KEY)`;
|
|
652
|
+
/**
|
|
653
|
+
* The tables a project's migrations make, by active-record's conventions (#66): applied in order to
|
|
654
|
+
* an in-memory SQLite database (`node:sqlite`), then read column by column. Tables are in
|
|
655
|
+
* alphabetical order and columns in the table's order, so the result only changes with the
|
|
656
|
+
* schema. SQLite's, Cloudflare's and Wrangler's own tables, and views, are left out.
|
|
657
|
+
*/
|
|
658
|
+
function schemaOf(migrations, options = {}) {
|
|
659
|
+
const { db, changedBy, error } = applied(migrations);
|
|
660
|
+
if (db === void 0) return {
|
|
661
|
+
ok: false,
|
|
662
|
+
errors: [error]
|
|
663
|
+
};
|
|
664
|
+
const migrationsTable = options.migrationsTable ?? "d1_migrations";
|
|
665
|
+
const tables = ownTables(definitions(db), migrationsTable).map(([name, definition]) => ({
|
|
666
|
+
name,
|
|
667
|
+
columns: columnsOf(db, name, definition),
|
|
668
|
+
lastChangedBy: changedBy.get(name)
|
|
669
|
+
}));
|
|
670
|
+
db.close();
|
|
671
|
+
return generatedSchema(tables, {
|
|
672
|
+
convert,
|
|
673
|
+
missingKey
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
// cli/adapters/d1/plugin.ts
|
|
677
|
+
/**
|
|
678
|
+
* Why this Node can't read D1 migrations: no node:sqlite, unflagged from 22.13 and 23.4.
|
|
679
|
+
* `getBuiltinModule` itself is there: the command checks for it before it loads a plugin.
|
|
680
|
+
*/
|
|
681
|
+
function unsupported() {
|
|
682
|
+
if (process.getBuiltinModule("node:sqlite") !== void 0) return void 0;
|
|
683
|
+
return `The D1 adapter needs Node 22.13 or later (23.4 on Node 23), for node:sqlite (this is Node ${process.versions.node})`;
|
|
684
|
+
}
|
|
685
|
+
/** D1, as the command line sees it: Wrangler's config and migrations, SQLite's schema, and its bindings. */
|
|
686
|
+
const cli = {
|
|
687
|
+
name: "d1",
|
|
688
|
+
patternSetting: "migrations_pattern",
|
|
689
|
+
unsupported,
|
|
690
|
+
init,
|
|
691
|
+
databases: readDatabases,
|
|
692
|
+
readSchema: async (migrations, options) => schemaOf(migrations, options),
|
|
693
|
+
migration,
|
|
694
|
+
remote: (chosen, use) => remoteTarget(chosen, use),
|
|
695
|
+
stateFolder: ({ configFile }) => join(dirname(configFile), ".wrangler"),
|
|
696
|
+
open: (cwd, chosen, { remote }) => remote ? openRemoteBinding(cwd, chosen) : openLocalBinding(cwd, chosen),
|
|
697
|
+
migrate
|
|
698
|
+
};
|
|
699
|
+
export { cli };
|