@forestfuture/active-record 0.0.0 → 0.6.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/LICENSE +21 -0
- package/README.md +26 -2
- package/dist/adapter-BSvFhTDf.d.mts +1293 -0
- package/dist/adapter.d.mts +2 -0
- package/dist/adapter.mjs +3 -0
- package/dist/batch-DBeYk5wx.mjs +4171 -0
- package/dist/cli.d.mts +197 -0
- package/dist/cli.mjs +3 -0
- package/dist/command.d.mts +1 -0
- package/dist/command.mjs +2157 -0
- package/dist/epoch-storage-o2aoOH7H.mjs +112 -0
- package/dist/generated-model-CfDggoVN.mjs +1853 -0
- package/dist/index.d.mts +143 -0
- package/dist/index.mjs +3 -0
- package/dist/storage-override-BYBYP8Mj.mjs +91 -0
- package/llms-full.txt +4397 -0
- package/package.json +42 -4
- package/skills/active-record/SKILL.md +88 -0
|
@@ -0,0 +1,112 @@
|
|
|
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 };
|