@forestfuture/active-record 0.7.0 → 0.8.1

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.
Files changed (33) hide show
  1. package/config-schema.json +6 -2
  2. package/dist/adapter.d.mts +3 -3
  3. package/dist/adapter.mjs +5 -4
  4. package/dist/batch-Ms5p9lKq.mjs +9777 -0
  5. package/dist/cli.d.mts +55 -33
  6. package/dist/cli.mjs +4 -4
  7. package/dist/command.mjs +530 -271
  8. package/dist/d1.d.mts +2 -10
  9. package/dist/d1.mjs +0 -0
  10. package/dist/{for-adapters-t3-LukJQ.d.mts → for-adapters-BT2GDjIA.d.mts} +8 -6
  11. package/dist/{for-adapters-Ch6CoHD4.mjs → for-adapters-BbIMUNcz.mjs} +46 -10
  12. package/dist/{for-adapters-D_Iu0gS_.mjs → for-adapters-C-MQxaIx.mjs} +3 -5
  13. package/dist/{generated-model-Cnt0Ot9q.mjs → generated-model-DJA8vmNE.mjs} +705 -508
  14. package/dist/identifiers-Dh5DFACX.mjs +989 -0
  15. package/dist/index-D5getfHx.d.mts +242 -0
  16. package/dist/index.d.mts +4 -3
  17. package/dist/index.mjs +5 -4
  18. package/dist/metadata-CzntpYzC.d.mts +182 -0
  19. package/dist/{plugin-Cyoej7qV.mjs → plugin-CZPDqguF.mjs} +211 -112
  20. package/dist/{plugin-XOHYndhP.mjs → plugin-Cf-5Z0_h.mjs} +148 -52
  21. package/dist/postgresql.d.mts +1 -9
  22. package/dist/postgresql.mjs +42 -26
  23. package/dist/src-BAVZKQ7J.mjs +46 -0
  24. package/dist/{storage-override-CpbkdIqE.mjs → storage-override-0ZgeP2sc.mjs} +61 -28
  25. package/dist/validations-BSZ5gVeI.d.mts +2024 -0
  26. package/llms-full.txt +2326 -229
  27. package/package.json +1 -1
  28. package/skills/active-record/SKILL.md +24 -15
  29. package/dist/adapter-AGKp6wfO.d.mts +0 -1326
  30. package/dist/batch-BS_WseLf.mjs +0 -4255
  31. package/dist/epoch-storage-o2aoOH7H.mjs +0 -112
  32. package/dist/index-CyCJuM96.d.mts +0 -149
  33. package/dist/src-la_KkjCS.mjs +0 -1
@@ -1,7 +1,7 @@
1
- import { a as underscore, i as camelize, t as epochStorages } from "./epoch-storage-o2aoOH7H.mjs";
1
+ import { E as underscore, T as camelize, c as castValue, d as uncastable, n as reservedWords, r as epochStorages } from "./identifiers-Dh5DFACX.mjs";
2
2
  import { existsSync, readFileSync, readdirSync } from "node:fs";
3
3
  import { basename, dirname, join, relative, resolve, sep } from "node:path";
4
- //#region cli/project/paths.ts
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
- //#endregion
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
- //#endregion
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
- let out = "";
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
- out += text.slice(index, end);
78
+ kept.add(text.slice(index, end));
80
79
  index = end - 1;
81
- } else if (text.startsWith("//", index)) {
82
- index = text.indexOf("\n", index) - 1;
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(out.replace(/,(\s*[}\]])/g, "$1"));
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
- //#endregion
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 = 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(" "));
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
- //#endregion
176
- //#region cli/schema/storage-override.ts
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
- //#endregion
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 };