@forestfuture/active-record 0.7.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/config-schema.json +6 -2
- package/dist/adapter.d.mts +3 -3
- package/dist/adapter.mjs +5 -4
- package/dist/batch-ReqVoCfa.mjs +9559 -0
- package/dist/cli.d.mts +55 -33
- package/dist/cli.mjs +4 -4
- package/dist/command.mjs +530 -271
- package/dist/d1.d.mts +2 -10
- package/dist/d1.mjs +0 -0
- package/dist/epoch-storage-CDlQZcBB.mjs +988 -0
- package/dist/{for-adapters-t3-LukJQ.d.mts → for-adapters-B0xMP6Dq.d.mts} +8 -6
- package/dist/{for-adapters-D_Iu0gS_.mjs → for-adapters-CfXMGeOu.mjs} +3 -5
- package/dist/{for-adapters-Ch6CoHD4.mjs → for-adapters-DhNV1mWf.mjs} +46 -10
- package/dist/{generated-model-Cnt0Ot9q.mjs → generated-model-g5oWsDKE.mjs} +728 -540
- package/dist/index-BATasvJa.d.mts +241 -0
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +5 -4
- package/dist/metadata-CzntpYzC.d.mts +182 -0
- package/dist/{plugin-Cyoej7qV.mjs → plugin-wOSILvSB.mjs} +211 -112
- package/dist/{plugin-XOHYndhP.mjs → plugin-x5-d3TSN.mjs} +148 -52
- package/dist/postgresql.d.mts +1 -9
- package/dist/postgresql.mjs +42 -26
- package/dist/src-D56_3odT.mjs +46 -0
- package/dist/{storage-override-CpbkdIqE.mjs → storage-override-n4w1cS_M.mjs} +61 -28
- package/dist/validations-DHDVV8hB.d.mts +1996 -0
- package/llms-full.txt +2354 -363
- package/package.json +1 -1
- package/skills/active-record/SKILL.md +22 -14
- package/dist/adapter-AGKp6wfO.d.mts +0 -1326
- package/dist/batch-BS_WseLf.mjs +0 -4255
- package/dist/epoch-storage-o2aoOH7H.mjs +0 -112
- package/dist/index-CyCJuM96.d.mts +0 -149
- package/dist/src-la_KkjCS.mjs +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { E as underscore, T as camelize, g as reservedWords, l as uncastable, o as castValue, t as epochStorages } from "./epoch-storage-CDlQZcBB.mjs";
|
|
2
2
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
4
|
-
|
|
4
|
+
// cli/project/paths.ts
|
|
5
5
|
/** A relative path with forward slashes, as migrations are named on every system. */
|
|
6
6
|
function slashed(path) {
|
|
7
7
|
return path.split(sep).join("/");
|
|
@@ -15,8 +15,7 @@ function importPath(fromDir, to) {
|
|
|
15
15
|
function shown(cwd, path) {
|
|
16
16
|
return slashed(relative(cwd, path)) || ".";
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
//#region cli/project/migrations.ts
|
|
18
|
+
// cli/project/migrations.ts
|
|
20
19
|
/** Plain character order, the same on every machine (unlike `localeCompare`). */
|
|
21
20
|
function byName(a, b) {
|
|
22
21
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
@@ -65,29 +64,49 @@ function hasNestedMigrations(target) {
|
|
|
65
64
|
if (entries.some((entry) => entry.isFile() && entry.name.endsWith(".sql"))) return false;
|
|
66
65
|
return entries.some((entry) => entry.isDirectory() && existsSync(join(dir, entry.name, "migration.sql")));
|
|
67
66
|
}
|
|
68
|
-
|
|
69
|
-
//#region cli/project/config-file.ts
|
|
67
|
+
// cli/project/config-file.ts
|
|
70
68
|
/** The project's config file's name, which `--config` replaces. */
|
|
71
69
|
const configFileName = "active-record.jsonc";
|
|
72
70
|
/** JSON with `//` and `/* *\/` comments and trailing commas. */
|
|
73
71
|
function parseJsonc(text) {
|
|
74
|
-
|
|
72
|
+
const kept = new KeptText();
|
|
75
73
|
for (let index = 0; index < text.length; index++) {
|
|
76
74
|
const char = text[index];
|
|
75
|
+
const comment = char === "/" ? endOfComment(text, index) : void 0;
|
|
77
76
|
if (char === "\"") {
|
|
78
77
|
const end = endOfString(text, index);
|
|
79
|
-
|
|
78
|
+
kept.add(text.slice(index, end));
|
|
80
79
|
index = end - 1;
|
|
81
|
-
} else if (
|
|
82
|
-
|
|
83
|
-
if (index < 0) break;
|
|
84
|
-
} else if (text.startsWith("/*", index)) {
|
|
85
|
-
const end = text.indexOf("*/", index + 2);
|
|
86
|
-
if (end < 0) throw new SyntaxError("Unterminated /* comment");
|
|
87
|
-
index = end + 1;
|
|
88
|
-
} else out += char;
|
|
80
|
+
} else if (comment !== void 0) index = comment - 1;
|
|
81
|
+
else kept.add(char);
|
|
89
82
|
}
|
|
90
|
-
return JSON.parse(
|
|
83
|
+
return JSON.parse(kept.text());
|
|
84
|
+
}
|
|
85
|
+
/** The text JSON.parse reads: what parseJsonc keeps of JSONC, less its trailing commas. */
|
|
86
|
+
var KeptText = class {
|
|
87
|
+
#parts = [];
|
|
88
|
+
/** Where the last comma is, while only whitespace has come after it. */
|
|
89
|
+
#trailingComma = -1;
|
|
90
|
+
/** Keeps a string literal or a character outside one. */
|
|
91
|
+
add(part) {
|
|
92
|
+
if ((part === "}" || part === "]") && this.#trailingComma >= 0) this.#parts[this.#trailingComma] = "";
|
|
93
|
+
if (!/^\s$/.test(part)) this.#trailingComma = part === "," ? this.#parts.length : -1;
|
|
94
|
+
this.#parts.push(part);
|
|
95
|
+
}
|
|
96
|
+
text() {
|
|
97
|
+
return this.#parts.join("");
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
/** Just past the comment starting at `start`, keeping a line comment's newline; undefined when none does. */
|
|
101
|
+
function endOfComment(text, start) {
|
|
102
|
+
if (text.startsWith("//", start)) {
|
|
103
|
+
const newline = text.indexOf("\n", start);
|
|
104
|
+
return newline < 0 ? text.length : newline;
|
|
105
|
+
}
|
|
106
|
+
if (!text.startsWith("/*", start)) return void 0;
|
|
107
|
+
const end = text.indexOf("*/", start + 2);
|
|
108
|
+
if (end < 0) throw new SyntaxError("Unterminated /* comment");
|
|
109
|
+
return end + 2;
|
|
91
110
|
}
|
|
92
111
|
/** Just past the string literal starting at `start`. */
|
|
93
112
|
function endOfString(text, start) {
|
|
@@ -135,19 +154,14 @@ function projectDatabases(cwd, configPath) {
|
|
|
135
154
|
databases
|
|
136
155
|
};
|
|
137
156
|
}
|
|
138
|
-
|
|
139
|
-
//#region cli/project/names.ts
|
|
140
|
-
/** Whether a name can be written bare: as a `const`, or as an object key without quotes. */
|
|
141
|
-
function isIdentifier(name) {
|
|
142
|
-
return /^[\p{L}_$][\p{L}\p{N}_$]*$/u.test(name);
|
|
143
|
-
}
|
|
157
|
+
// cli/project/names.ts
|
|
144
158
|
/** A column's attribute: camelCase, keeping any leading underscores (`_secret` stays). */
|
|
145
159
|
function attributeName(column) {
|
|
146
160
|
const lead = /^_*/.exec(column)[0];
|
|
147
161
|
return lead + camelize(column.slice(lead.length));
|
|
148
162
|
}
|
|
149
163
|
/** Words JavaScript doesn't allow as a `const` name, and the generated file's own names. */
|
|
150
|
-
const reserved =
|
|
164
|
+
const reserved = /* @__PURE__ */ new Set([...reservedWords, "tables"]);
|
|
151
165
|
/**
|
|
152
166
|
* The `const` a table is exported as: its words in camelCase (`line_items` → `lineItems`),
|
|
153
167
|
* never a reserved word (`default` → `defaultTable`) or starting with a digit (`2fa` →
|
|
@@ -172,8 +186,28 @@ function listed(names, last = "or") {
|
|
|
172
186
|
if (names.length < 2) return names.join("");
|
|
173
187
|
return `${names.slice(0, -1).join(", ")} ${last} ${names.at(-1)}`;
|
|
174
188
|
}
|
|
175
|
-
|
|
176
|
-
|
|
189
|
+
// cli/schema/cast-default.ts
|
|
190
|
+
const castDefaultTypes = [
|
|
191
|
+
"decimal",
|
|
192
|
+
"date",
|
|
193
|
+
"time"
|
|
194
|
+
];
|
|
195
|
+
/** Whether a type's literal default is cast as an assigned value is. */
|
|
196
|
+
function isCastDefaultType(type) {
|
|
197
|
+
return castDefaultTypes.includes(type);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* A literal default's text as the attribute's value, with a decimal's `digits` (#398) (`1.50` → `"1.5"`, `'09:30'` → `"09:30:00"`),
|
|
201
|
+
* or undefined for text the type can't hold, whose default then stays with the database.
|
|
202
|
+
*/
|
|
203
|
+
function castDefault(type, text, digits = {}) {
|
|
204
|
+
const value = castValue({
|
|
205
|
+
type,
|
|
206
|
+
...digits
|
|
207
|
+
}, text);
|
|
208
|
+
return value === uncastable ? void 0 : { literal: value };
|
|
209
|
+
}
|
|
210
|
+
// cli/schema/storage-override.ts
|
|
177
211
|
/** Drizzle's `mode` for each epoch storage, which a note names for a reader with its schema open. */
|
|
178
212
|
const drizzleModes = {
|
|
179
213
|
unixSeconds: "\"timestamp\"",
|
|
@@ -183,5 +217,4 @@ const drizzleModes = {
|
|
|
183
217
|
function storageOverride(withDrizzleModes) {
|
|
184
218
|
return `{ type: "datetime", storage: ${epochStorages.map((storage) => withDrizzleModes ? `"${storage}" (${drizzleModes[storage]})` : `"${storage}"`).join(" or ")} }`;
|
|
185
219
|
}
|
|
186
|
-
|
|
187
|
-
export { shown as _, isIdentifier as a, configFileName as c, byName as d, byVersion as f, importPath as g, migrationsOf as h, exportName as i, parseJsonc as l, leadingNumber as m, attributeName as n, listed as o, hasNestedMigrations as p, classify as r, moduleName as s, storageOverride as t, projectDatabases as u, slashed as v };
|
|
220
|
+
export { importPath as _, classify as a, moduleName as c, projectDatabases as d, byName as f, migrationsOf as g, leadingNumber as h, attributeName as i, configFileName as l, hasNestedMigrations as m, castDefault as n, exportName as o, byVersion as p, isCastDefaultType as r, listed as s, storageOverride as t, parseJsonc as u, shown as v, slashed as y };
|