@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
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
//#region src/naming.ts
|
|
2
|
-
/**
|
|
3
|
-
* Converts a camelCase attribute name to its snake_case column name, treating
|
|
4
|
-
* a run of capitals as one word (Rails' `underscore`): `htmlURL` → `html_url`,
|
|
5
|
-
* `userID` → `user_id`, `sha256Hash` → `sha256_hash`.
|
|
6
|
-
*/
|
|
7
|
-
function underscore(name) {
|
|
8
|
-
return name.replace(/(?<=[a-z\d])(?=[A-Z])|(?<=[A-Z\d])(?=[A-Z][a-z])/g, "_").toLowerCase();
|
|
9
|
-
}
|
|
10
|
-
/** A snake_case name as a camelCase attribute: `api_key` → `apiKey`. */
|
|
11
|
-
function camelize(name) {
|
|
12
|
-
return name.replace(/_([a-z\d])/g, (_, letter) => letter.toUpperCase());
|
|
13
|
-
}
|
|
14
|
-
//#endregion
|
|
15
|
-
//#region src/inflections.ts
|
|
16
|
-
/** Words whose plural no rule makes: singular, then plural. */
|
|
17
|
-
const IRREGULARS = [
|
|
18
|
-
["person", "people"],
|
|
19
|
-
["man", "men"],
|
|
20
|
-
["child", "children"],
|
|
21
|
-
["sex", "sexes"],
|
|
22
|
-
["move", "moves"],
|
|
23
|
-
["zombie", "zombies"]
|
|
24
|
-
];
|
|
25
|
-
/** Plural rules in Rails' order of definition. The last one that matches wins, as in Rails. */
|
|
26
|
-
const PLURALS = [
|
|
27
|
-
[/$/, "s"],
|
|
28
|
-
[/s$/i, "s"],
|
|
29
|
-
[/^(ax|test)is$/i, "$1es"],
|
|
30
|
-
[/(octop|vir)us$/i, "$1i"],
|
|
31
|
-
[/(octop|vir)i$/i, "$1i"],
|
|
32
|
-
[/(alias|status)$/i, "$1es"],
|
|
33
|
-
[/(bu)s$/i, "$1ses"],
|
|
34
|
-
[/(buffal|tomat)o$/i, "$1oes"],
|
|
35
|
-
[/([ti])um$/i, "$1a"],
|
|
36
|
-
[/([ti])a$/i, "$1a"],
|
|
37
|
-
[/sis$/i, "ses"],
|
|
38
|
-
[/(?:([^f])fe|([lr])f)$/i, "$1$2ves"],
|
|
39
|
-
[/(hive)$/i, "$1s"],
|
|
40
|
-
[/([^aeiouy]|qu)y$/i, "$1ies"],
|
|
41
|
-
[/(x|ch|ss|sh)$/i, "$1es"],
|
|
42
|
-
[/(matr|vert|ind)(?:ix|ex)$/i, "$1ices"],
|
|
43
|
-
[/^(m|l)ouse$/i, "$1ice"],
|
|
44
|
-
[/^(m|l)ice$/i, "$1ice"],
|
|
45
|
-
[/^(ox)$/i, "$1en"],
|
|
46
|
-
[/^(oxen)$/i, "$1"],
|
|
47
|
-
[/(quiz)$/i, "$1zes"],
|
|
48
|
-
...IRREGULARS.flatMap(([singular, plural]) => irregular(singular, plural, plural))
|
|
49
|
-
];
|
|
50
|
-
/** Singular rules, likewise in Rails' order. */
|
|
51
|
-
const SINGULARS = [
|
|
52
|
-
[/s$/i, ""],
|
|
53
|
-
[/(ss)$/i, "$1"],
|
|
54
|
-
[/(n)ews$/i, "$1ews"],
|
|
55
|
-
[/([ti])a$/i, "$1um"],
|
|
56
|
-
[/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, "$1sis"],
|
|
57
|
-
[/(^analy)(sis|ses)$/i, "$1sis"],
|
|
58
|
-
[/([^f])ves$/i, "$1fe"],
|
|
59
|
-
[/(hive)s$/i, "$1"],
|
|
60
|
-
[/(tive)s$/i, "$1"],
|
|
61
|
-
[/([lr])ves$/i, "$1f"],
|
|
62
|
-
[/([^aeiouy]|qu)ies$/i, "$1y"],
|
|
63
|
-
[/(s)eries$/i, "$1eries"],
|
|
64
|
-
[/(m)ovies$/i, "$1ovie"],
|
|
65
|
-
[/(x|ch|ss|sh)es$/i, "$1"],
|
|
66
|
-
[/^(m|l)ice$/i, "$1ouse"],
|
|
67
|
-
[/(bus)(es)?$/i, "$1"],
|
|
68
|
-
[/(o)es$/i, "$1"],
|
|
69
|
-
[/(shoe)s$/i, "$1"],
|
|
70
|
-
[/(cris|test)(is|es)$/i, "$1is"],
|
|
71
|
-
[/^(a)x[ie]s$/i, "$1xis"],
|
|
72
|
-
[/(octop|vir)(us|i)$/i, "$1us"],
|
|
73
|
-
[/(alias|status)(es)?$/i, "$1"],
|
|
74
|
-
[/^(ox)en/i, "$1"],
|
|
75
|
-
[/(vert|ind)ices$/i, "$1ex"],
|
|
76
|
-
[/(matr)ices$/i, "$1ix"],
|
|
77
|
-
[/(quiz)zes$/i, "$1"],
|
|
78
|
-
[/(database)s$/i, "$1"],
|
|
79
|
-
...IRREGULARS.flatMap(([singular, plural]) => irregular(singular, plural, singular))
|
|
80
|
-
];
|
|
81
|
-
/** Words with no plural, matched as the last word (Rails' `\b<word>\z`). */
|
|
82
|
-
const UNCOUNTABLE = /\b(?:equipment|information|rice|money|species|series|fish|sheep|jeans|police)$/i;
|
|
83
|
-
/**
|
|
84
|
-
* Rails' `irregular`: rules turning either form into `into` (the plural for plural rules, the
|
|
85
|
-
* singular for singular ones), keeping the first letter's case.
|
|
86
|
-
*/
|
|
87
|
-
function irregular(singular, plural, into) {
|
|
88
|
-
return [[new RegExp(`(${singular[0]})${singular.slice(1)}$`, "i"), `$1${into.slice(1)}`], [new RegExp(`(${plural[0]})${plural.slice(1)}$`, "i"), `$1${into.slice(1)}`]];
|
|
89
|
-
}
|
|
90
|
-
/** Applies the last rule that matches, as Rails does; uncountable words stay as they are. */
|
|
91
|
-
function inflect(word, rules) {
|
|
92
|
-
if (word === "" || UNCOUNTABLE.test(word)) return word;
|
|
93
|
-
for (let index = rules.length - 1; index >= 0; index--) {
|
|
94
|
-
const [pattern, replacement] = rules[index];
|
|
95
|
-
if (pattern.test(word)) return word.replace(pattern, replacement);
|
|
96
|
-
}
|
|
97
|
-
return word;
|
|
98
|
-
}
|
|
99
|
-
/** Rails' `pluralize`: `category` → `categories`, `person` → `people`, `sheep` → `sheep`. */
|
|
100
|
-
function pluralize(word) {
|
|
101
|
-
return inflect(word, PLURALS);
|
|
102
|
-
}
|
|
103
|
-
/** Rails' `singularize`: `categories` → `category`, `people` → `person`, `line_items` → `line_item`. */
|
|
104
|
-
function singularize(word) {
|
|
105
|
-
return inflect(word, SINGULARS);
|
|
106
|
-
}
|
|
107
|
-
//#endregion
|
|
108
|
-
//#region src/epoch-storage.ts
|
|
109
|
-
/** A datetime held in an `INTEGER` column as seconds or milliseconds since 1970. */
|
|
110
|
-
const epochStorages = ["unixSeconds", "unixMilliseconds"];
|
|
111
|
-
//#endregion
|
|
112
|
-
export { underscore as a, camelize as i, pluralize as n, singularize as r, epochStorages as t };
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { a as underscore, i as camelize, t as epochStorages } from "./epoch-storage-o2aoOH7H.mjs";
|
|
2
|
-
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
3
|
-
import { join, relative, sep } from "node:path";
|
|
4
|
-
//#region cli/project/paths.ts
|
|
5
|
-
/** A relative path with forward slashes, as Wrangler names migrations on every system. */
|
|
6
|
-
function slashed(path) {
|
|
7
|
-
return path.split(sep).join("/");
|
|
8
|
-
}
|
|
9
|
-
/** A module path from one file's folder to another file, as an import writes it (`../db/schema`). */
|
|
10
|
-
function importPath(fromDir, to) {
|
|
11
|
-
const path = slashed(relative(fromDir, to)).replace(/\.ts$/, "");
|
|
12
|
-
return path.startsWith(".") ? path : `./${path}`;
|
|
13
|
-
}
|
|
14
|
-
/** A path as printed: relative to the project, with forward slashes. */
|
|
15
|
-
function shown(cwd, path) {
|
|
16
|
-
return slashed(relative(cwd, path)) || ".";
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region cli/project/migrations.ts
|
|
20
|
-
/** Plain character order, the same on every machine (unlike `localeCompare`). */
|
|
21
|
-
function byName(a, b) {
|
|
22
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
23
|
-
}
|
|
24
|
-
/** A database's migrations, in the order Wrangler applies them: by file name. */
|
|
25
|
-
function migrationsOf(target) {
|
|
26
|
-
const { migrationsPattern } = target.database;
|
|
27
|
-
return (migrationsPattern === void 0 ? readdirSync(target.migrationsDir).filter((name) => name.endsWith(".sql")) : process.getBuiltinModule("node:fs").globSync(migrationsPattern, { cwd: target.configDir }).map((path) => slashed(relative(target.migrationsDir, join(target.configDir, path))))).sort(byName).map((name) => ({
|
|
28
|
-
name,
|
|
29
|
-
sql: readFileSync(join(target.migrationsDir, name), "utf8")
|
|
30
|
-
}));
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Whether a database's migrations are in folders (`migrations/0000_init/migration.sql`, as
|
|
34
|
-
* Drizzle writes them) with no `migrations_pattern` in the config to find them.
|
|
35
|
-
*/
|
|
36
|
-
function hasNestedMigrations(target) {
|
|
37
|
-
const dir = target.migrationsDir;
|
|
38
|
-
if (target.database.migrationsPattern !== void 0 || !existsSync(dir)) return false;
|
|
39
|
-
const entries = readdirSync(dir, { withFileTypes: true });
|
|
40
|
-
if (entries.some((entry) => entry.isFile() && entry.name.endsWith(".sql"))) return false;
|
|
41
|
-
return entries.some((entry) => entry.isDirectory() && existsSync(join(dir, entry.name, "migration.sql")));
|
|
42
|
-
}
|
|
43
|
-
//#endregion
|
|
44
|
-
//#region cli/project/names.ts
|
|
45
|
-
/** Whether a name can be written bare: as a `const`, or as an object key without quotes. */
|
|
46
|
-
function isIdentifier(name) {
|
|
47
|
-
return /^[\p{L}_$][\p{L}\p{N}_$]*$/u.test(name);
|
|
48
|
-
}
|
|
49
|
-
/** A column's attribute: camelCase, keeping any leading underscores (`_secret` stays). */
|
|
50
|
-
function attributeName(column) {
|
|
51
|
-
const lead = /^_*/.exec(column)[0];
|
|
52
|
-
return lead + camelize(column.slice(lead.length));
|
|
53
|
-
}
|
|
54
|
-
/** Words JavaScript doesn't allow as a `const` name, and the generated file's own names. */
|
|
55
|
-
const reserved = new Set("break case catch class const continue debugger default delete do else enum export extends false finally for function if import in instanceof new null return super switch this throw true try typeof var void while with yield let static implements interface package private protected public await arguments eval tables".split(" "));
|
|
56
|
-
/**
|
|
57
|
-
* The `const` a table is exported as: its words in camelCase (`line_items` → `lineItems`),
|
|
58
|
-
* never a reserved word (`default` → `defaultTable`) or starting with a digit (`2fa` →
|
|
59
|
-
* `table2fa`).
|
|
60
|
-
*/
|
|
61
|
-
function exportName(table) {
|
|
62
|
-
const name = table.split(/[^\p{L}\p{N}]+/u).filter(Boolean).map((word, index) => index === 0 ? word : word[0].toUpperCase() + word.slice(1)).join("");
|
|
63
|
-
if (name === "" || /^\p{N}/u.test(name)) return `table${name}`;
|
|
64
|
-
return reserved.has(name) ? `${name}Table` : name;
|
|
65
|
-
}
|
|
66
|
-
/** A class name from any spelling: `line_item`, `lineItem` → `LineItem`. */
|
|
67
|
-
function classify(name) {
|
|
68
|
-
const camel = camelize(underscore(name));
|
|
69
|
-
return camel.charAt(0).toUpperCase() + camel.slice(1);
|
|
70
|
-
}
|
|
71
|
-
/** A Model's module, in kebab-case: `LineItem` → `line-item` (its file is `line-item.ts`). */
|
|
72
|
-
function moduleName(className) {
|
|
73
|
-
return underscore(className).replaceAll("_", "-");
|
|
74
|
-
}
|
|
75
|
-
/** `"A"`, `"A or B"`, `"A, B or C"`. */
|
|
76
|
-
function listed(names) {
|
|
77
|
-
return names.length < 2 ? names.join("") : `${names.slice(0, -1).join(", ")} or ${names.at(-1)}`;
|
|
78
|
-
}
|
|
79
|
-
//#endregion
|
|
80
|
-
//#region cli/schema/storage-override.ts
|
|
81
|
-
/** Drizzle's `mode` for each epoch storage, which a note names for a reader with its schema open. */
|
|
82
|
-
const drizzleModes = {
|
|
83
|
-
unixSeconds: "\"timestamp\"",
|
|
84
|
-
unixMilliseconds: "\"timestamp_ms\""
|
|
85
|
-
};
|
|
86
|
-
/** The override that reads a Unix time as a `Date`, for a note; with Drizzle's modes named if asked. */
|
|
87
|
-
function storageOverride(withDrizzleModes) {
|
|
88
|
-
return `{ type: "datetime", storage: ${epochStorages.map((storage) => withDrizzleModes ? `"${storage}" (${drizzleModes[storage]})` : `"${storage}"`).join(" or ")} }`;
|
|
89
|
-
}
|
|
90
|
-
//#endregion
|
|
91
|
-
export { isIdentifier as a, byName as c, importPath as d, shown as f, exportName as i, hasNestedMigrations as l, attributeName as n, listed as o, slashed as p, classify as r, moduleName as s, storageOverride as t, migrationsOf as u };
|