@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.
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-ReqVoCfa.mjs +9559 -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/epoch-storage-CDlQZcBB.mjs +988 -0
  11. package/dist/{for-adapters-t3-LukJQ.d.mts → for-adapters-B0xMP6Dq.d.mts} +8 -6
  12. package/dist/{for-adapters-D_Iu0gS_.mjs → for-adapters-CfXMGeOu.mjs} +3 -5
  13. package/dist/{for-adapters-Ch6CoHD4.mjs → for-adapters-DhNV1mWf.mjs} +46 -10
  14. package/dist/{generated-model-Cnt0Ot9q.mjs → generated-model-g5oWsDKE.mjs} +728 -540
  15. package/dist/index-BATasvJa.d.mts +241 -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-wOSILvSB.mjs} +211 -112
  20. package/dist/{plugin-XOHYndhP.mjs → plugin-x5-d3TSN.mjs} +148 -52
  21. package/dist/postgresql.d.mts +1 -9
  22. package/dist/postgresql.mjs +42 -26
  23. package/dist/src-D56_3odT.mjs +46 -0
  24. package/dist/{storage-override-CpbkdIqE.mjs → storage-override-n4w1cS_M.mjs} +61 -28
  25. package/dist/validations-DHDVV8hB.d.mts +1996 -0
  26. package/llms-full.txt +2354 -363
  27. package/package.json +1 -1
  28. package/skills/active-record/SKILL.md +22 -14
  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
package/dist/cli.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- //#region cli/generate/columns.d.ts
2
- type ColumnType = "string" | "integer" | "real" | "boolean" | "datetime" | "json" | "references";
1
+ import { a as AttributeType } from "./metadata-CzntpYzC.mjs";
2
+ type ColumnType = "string" | "integer" | "real" | "decimal" | "boolean" | "datetime" | "date" | "time" | "json" | "binary" | "references";
3
3
  /** One column as the generators' syntax gives it: `email:string!:unique`, `user:references`. */
4
4
  interface ColumnArg {
5
5
  /** The column's name, in snake_case (`user_id` for `user:references`). */
@@ -9,12 +9,13 @@ interface ColumnArg {
9
9
  index: "none" | "index" | "unique";
10
10
  /** A literal default, from `=value`. */
11
11
  default?: string | number | boolean;
12
+ /** A decimal's digits in all and after the point, from `decimal{10,2}` (#398). */
13
+ precision?: number;
14
+ scale?: number;
12
15
  /** For `references`: the table it points at, and the `belongsTo` it suggests. */
13
16
  references?: string;
14
17
  association?: string;
15
18
  }
16
- //#endregion
17
- //#region cli/project/migrations.d.ts
18
19
  interface Migration {
19
20
  /** The file's name, relative to the migrations folder, which orders it. */
20
21
  name: string;
@@ -28,13 +29,11 @@ export declare function byName(a: string, b: string): number;
28
29
  * equals; a path that's the start of another comes first.
29
30
  */
30
31
  export declare function byVersion(a: string, b: string): number;
31
- //#endregion
32
- //#region cli/adapter.d.ts
33
32
  /** One database a project declares, and where its migrations are. */
34
33
  interface DatabaseConfig {
35
34
  /** Its name in the app's config, which a generated schema names: its **Binding** (`DB`). */
36
35
  binding: string;
37
- /** Relative to the config file. */
36
+ /** Relative to its config file's folder. */
38
37
  migrationsDir: string;
39
38
  /** A glob for migrations in nested folders, from the config's `patternSetting`. */
40
39
  migrationsPattern?: string;
@@ -42,6 +41,11 @@ interface DatabaseConfig {
42
41
  migrationsTable?: string;
43
42
  /** The database's entry as the config has it. */
44
43
  entry: Record<string, unknown>;
44
+ /**
45
+ * The file that declares it, when it isn't the config's own: the adapter's config file that its
46
+ * entry in `active-record.jsonc` names (#306).
47
+ */
48
+ configFile?: string;
45
49
  }
46
50
  /**
47
51
  * The databases a project's `active-record.jsonc` names, each with its entry as the file has it
@@ -53,7 +57,10 @@ interface ProjectDatabases {
53
57
  /** Each database's entry, by binding, in the file's order. */
54
58
  databases: Readonly<Record<string, Record<string, unknown>>>;
55
59
  }
56
- /** A project's config: the file, its folder, and its databases, or why it can't be read. */
60
+ /**
61
+ * A project's config: the file, its folder, and its databases, or why it can't be read. A
62
+ * database's own `configFile`, when it has one, is its file in place of this one.
63
+ */
57
64
  type ConfigResult = {
58
65
  ok: true;
59
66
  file: string;
@@ -65,7 +72,6 @@ type ConfigResult = {
65
72
  ok: false;
66
73
  error: string;
67
74
  };
68
- type AttributeType = "string" | "integer" | "real" | "boolean" | "datetime" | "json";
69
75
  /** A default the generated spec carries: a literal value, or a date. */
70
76
  type Default = {
71
77
  literal: unknown;
@@ -80,6 +86,16 @@ interface Spec {
80
86
  default?: Default;
81
87
  /** A key made in code by the Model's `generateId` (#99). */
82
88
  generateId?: true;
89
+ /** A decimal's digits in all, from `NUMERIC(10, 2)` (#398). */
90
+ precision?: number;
91
+ /** A decimal's digits after the point, from `NUMERIC(10, 2)` (#398). */
92
+ scale?: number;
93
+ /** A generated enum's names, which the database restricts the column to (#64). */
94
+ enum?: readonly string[];
95
+ /** `false` on a generated enum: its scopes wait for the Model's override (#64). */
96
+ scopes?: false;
97
+ /** `false` on a generated enum: its record methods wait for the Model's override (#64). */
98
+ instanceMethods?: false;
83
99
  }
84
100
  /** One table, ready to generate: its attributes in column order. */
85
101
  interface GeneratedTable {
@@ -190,7 +206,8 @@ interface CliAdapter {
190
206
  /**
191
207
  * The entries `init` writes, from what's in `dir` (the folder `active-record.jsonc` goes in),
192
208
  * such as another tool's config. Undefined when nothing there points to this adapter, unless
193
- * `--adapter` `named` it, when it writes what it can.
209
+ * `--adapter` `named` it as an adapter the file doesn't use yet, when it writes what it can (a
210
+ * guess included).
194
211
  */
195
212
  init(dir: string, named: boolean): InitResult;
196
213
  /**
@@ -221,13 +238,6 @@ interface CliAdapter {
221
238
  remote: boolean;
222
239
  }, io: MigrateOutput): Promise<number>;
223
240
  }
224
- /** The project's adapter, as the command uses it: its plugin, reading the project's databases. */
225
- type ProjectAdapter = Omit<CliAdapter, "databases"> & {
226
- /** The project's databases, or why they can't be read. */
227
- databases(): ConfigResult;
228
- };
229
- //#endregion
230
- //#region cli/generate/migration-plan.d.ts
231
241
  /** What a migration's name says it does (`CreateProducts`, `AddSkuToProducts`, …), with its table plural. */
232
242
  type MigrationPlan = {
233
243
  kind: "create" | "add" | "remove";
@@ -240,8 +250,6 @@ type MigrationPlan = {
240
250
  export declare function migrationPlan(name: string): MigrationPlan;
241
251
  /** The index the generators name a column's index by: `index_products_on_sku`. */
242
252
  export declare function indexName(table: string, column: string): string;
243
- //#endregion
244
- //#region cli/generate/migration-sql.d.ts
245
253
  /** What a migration's SQL takes from its database: its names, types and keys, and what it can't do. */
246
254
  interface MigrationDialect {
247
255
  /** The words the database reserves, which a table or column named one is quoted for. */
@@ -269,14 +277,10 @@ export declare function quotedName(dialect: MigrationDialect, name: string): str
269
277
  * type it guessed.
270
278
  */
271
279
  export declare function migrationSql(change: MigrationChange, dialect: MigrationDialect): MigrationResult;
272
- //#endregion
273
- //#region cli/project/config-file.d.ts
274
280
  /** The project's config file's name, which `--config` replaces. */
275
281
  export declare const configFileName = "active-record.jsonc";
276
282
  /** JSON with `//` and `/* *\/` comments and trailing commas. */
277
283
  export declare function parseJsonc(text: string): unknown;
278
- //#endregion
279
- //#region cli/project/names.d.ts
280
284
  /** A column's attribute: camelCase, keeping any leading underscores (`_secret` stays). */
281
285
  export declare function attributeName(column: string): string;
282
286
  /**
@@ -287,12 +291,35 @@ export declare function attributeName(column: string): string;
287
291
  export declare function exportName(table: string): string;
288
292
  /** `"A"`, `"A or B"`, `"A, B or C"`, or with `"and"`, `"A, B and C"`. */
289
293
  export declare function listed(names: readonly string[], last?: "or" | "and"): string;
290
- //#endregion
291
- //#region cli/schema/storage-override.d.ts
294
+ /** A decimal's precision and scale, as `NUMERIC(10, 2)` gives them (#398). */
295
+ interface DecimalDigits {
296
+ precision?: number;
297
+ scale?: number;
298
+ }
299
+ declare const castDefaultTypes: readonly ["decimal", "date", "time"];
300
+ /** The attribute types whose literal default is cast as an assigned value is. */
301
+ type CastDefaultType = (typeof castDefaultTypes)[number];
302
+ /** Whether a type's literal default is cast as an assigned value is. */
303
+ export declare function isCastDefaultType(type: string): type is CastDefaultType;
304
+ /**
305
+ * 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"`),
306
+ * or undefined for text the type can't hold, whose default then stays with the database.
307
+ */
308
+ export declare function castDefault(type: CastDefaultType, text: string, digits?: DecimalDigits): {
309
+ literal: string;
310
+ } | undefined;
311
+ /**
312
+ * `spec` with a decimal's precision and scale, as a column's type gives them: neither when the
313
+ * column has no precision, and the scale only when it's given. Digits no `NUMERIC(p, s)` has (a
314
+ * precision past 1000, a scale past the precision) leave both off, so the Model stays valid.
315
+ */
316
+ export declare function withDigits(spec: Spec, precision?: number | null, scale?: number | null): Spec;
317
+ /** A string spec with the names its column is restricted to, as a generated enum; any other spec as it is. */
318
+ export declare function withGeneratedEnum(spec: Spec, names: readonly string[] | undefined): Spec;
319
+ /** A CHECK's list of SQL string literals as their text, each once: `'a', 'it''s', 'a'` → `["a", "it's"]`. */
320
+ export declare function namesInList(list: string): string[];
292
321
  /** The override that reads a Unix time as a `Date`, for a note; with Drizzle's modes named if asked. */
293
322
  export declare function storageOverride(withDrizzleModes: boolean): string;
294
- //#endregion
295
- //#region cli/schema/tables.d.ts
296
323
  /** What a column became, or why it can't be one, plus a note when its type was guessed. */
297
324
  type Converted = {
298
325
  ok: true;
@@ -329,17 +356,12 @@ interface Reading<C extends ReadColumn> {
329
356
  * result only changes with the schema), or every error that stops them.
330
357
  */
331
358
  export declare function generatedSchema<C extends ReadColumn>(read: readonly ReadTable<C>[], reading: Reading<C>): SchemaResult;
332
- //#endregion
333
- //#region src/inflections.d.ts
334
359
  /** Rails' `pluralize`: `category` → `categories`, `person` → `people`, `sheep` → `sheep`. */
335
360
  export declare function pluralize(word: string): string;
336
- //#endregion
337
- //#region src/naming.d.ts
338
361
  /**
339
362
  * Converts a camelCase attribute name to its snake_case column name, treating
340
363
  * a run of capitals as one word (Rails' `underscore`): `htmlURL` → `html_url`,
341
364
  * `userID` → `user_id`, `sha256Hash` → `sha256_hash`.
342
365
  */
343
366
  export declare function underscore(name: string): string;
344
- //#endregion
345
- export type { ChosenDatabase, CliAdapter, ColumnArg, ConfigResult, Converted, DatabaseConfig, Default, GeneratedTable, InitResult, MigrateOutput, Migration, MigrationChange, MigrationDialect, MigrationPlan, MigrationResult, OpenBinding, ProjectAdapter, ProjectDatabases, ReadColumn, ReadTable, Reading, RemoteTarget, SchemaOptions, SchemaResult, Spec };
367
+ export type { CastDefaultType, ChosenDatabase, CliAdapter, ColumnArg, ConfigResult, Converted, DatabaseConfig, Default, GeneratedTable, InitResult, MigrateOutput, Migration, MigrationChange, MigrationDialect, MigrationPlan, MigrationResult, OpenBinding, ProjectDatabases, ReadColumn, ReadTable, Reading, RemoteTarget, SchemaOptions, SchemaResult, Spec };
package/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as underscore, n as pluralize } from "./epoch-storage-o2aoOH7H.mjs";
2
- import { a as migrationPlan, i as indexName, n as migrationSql, r as quotedName, t as generatedSchema } from "./for-adapters-Ch6CoHD4.mjs";
3
- import { c as configFileName, d as byName, f as byVersion, i as exportName, l as parseJsonc, n as attributeName, o as listed, t as storageOverride } from "./storage-override-CpbkdIqE.mjs";
4
- export { attributeName, byName, byVersion, configFileName, exportName, generatedSchema, indexName, listed, migrationPlan, migrationSql, parseJsonc, pluralize, quotedName, storageOverride, underscore };
1
+ import { C as pluralize, E as underscore } from "./epoch-storage-CDlQZcBB.mjs";
2
+ import { a as migrationSql, c as migrationPlan, 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 { f as byName, i as attributeName, l as configFileName, n as castDefault, o as exportName, p as byVersion, r as isCastDefaultType, s as listed, t as storageOverride, u as parseJsonc } from "./storage-override-n4w1cS_M.mjs";
4
+ export { attributeName, byName, byVersion, castDefault, configFileName, exportName, generatedSchema, indexName, isCastDefaultType, listed, migrationPlan, migrationSql, namesInList, parseJsonc, pluralize, quotedName, storageOverride, underscore, withDigits, withGeneratedEnum };