@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
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
//#region cli/generate/columns.d.ts
|
|
2
|
+
type ColumnType = "string" | "integer" | "real" | "boolean" | "datetime" | "json" | "references";
|
|
3
|
+
/** One column as the generators' syntax gives it: `email:string!:unique`, `user:references`. */
|
|
4
|
+
interface ColumnArg {
|
|
5
|
+
/** The column's name, in snake_case (`user_id` for `user:references`). */
|
|
6
|
+
name: string;
|
|
7
|
+
type: ColumnType;
|
|
8
|
+
notNull: boolean;
|
|
9
|
+
index: "none" | "index" | "unique";
|
|
10
|
+
/** A literal default, from `=value`. */
|
|
11
|
+
default?: string | number | boolean;
|
|
12
|
+
/** For `references`: the table it points at, and the `belongsTo` it suggests. */
|
|
13
|
+
references?: string;
|
|
14
|
+
association?: string;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region cli/project/migrations.d.ts
|
|
18
|
+
interface Migration {
|
|
19
|
+
/** The file's name, as Wrangler orders and records it. */
|
|
20
|
+
name: string;
|
|
21
|
+
sql: string;
|
|
22
|
+
}
|
|
23
|
+
/** Plain character order, the same on every machine (unlike `localeCompare`). */
|
|
24
|
+
export declare function byName(a: string, b: string): number;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region cli/adapter.d.ts
|
|
27
|
+
/** One database a project declares, and where its migrations are. */
|
|
28
|
+
interface DatabaseConfig {
|
|
29
|
+
/** Its name in the app's config, which a generated schema names: its **Binding** (`DB`). */
|
|
30
|
+
binding: string;
|
|
31
|
+
/** Relative to the config file. */
|
|
32
|
+
migrationsDir: string;
|
|
33
|
+
/** A glob for nested migration layouts (D1's `migrations_pattern`). */
|
|
34
|
+
migrationsPattern?: string;
|
|
35
|
+
/** The adapter's record of applied migrations, left out of the schema. */
|
|
36
|
+
migrationsTable?: string;
|
|
37
|
+
/** The database's entry as the config has it. */
|
|
38
|
+
entry: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
/** A project's config: the file, its folder, and its databases, or why it can't be read. */
|
|
41
|
+
type ConfigResult = {
|
|
42
|
+
ok: true;
|
|
43
|
+
file: string;
|
|
44
|
+
dir: string;
|
|
45
|
+
databases: DatabaseConfig[];
|
|
46
|
+
accountId?: string;
|
|
47
|
+
} | {
|
|
48
|
+
ok: false;
|
|
49
|
+
error: string;
|
|
50
|
+
};
|
|
51
|
+
type AttributeType = "string" | "integer" | "real" | "boolean" | "datetime" | "json";
|
|
52
|
+
/** A default the generated spec carries: a literal value, or a date. */
|
|
53
|
+
type Default = {
|
|
54
|
+
literal: unknown;
|
|
55
|
+
} | {
|
|
56
|
+
date: string;
|
|
57
|
+
};
|
|
58
|
+
/** One attribute as the generated schema declares it, the shape `Model.define({...})` takes. */
|
|
59
|
+
interface Spec {
|
|
60
|
+
type: AttributeType;
|
|
61
|
+
null?: false;
|
|
62
|
+
column?: string;
|
|
63
|
+
default?: Default;
|
|
64
|
+
/** A key made in code by the Model's `generateId` (#99). */
|
|
65
|
+
generateId?: true;
|
|
66
|
+
}
|
|
67
|
+
/** One table, ready to generate: its attributes in column order. */
|
|
68
|
+
interface GeneratedTable {
|
|
69
|
+
name: string;
|
|
70
|
+
/** The `const` it's exported as in the generated file. */
|
|
71
|
+
exportName: string;
|
|
72
|
+
primaryKey: string;
|
|
73
|
+
/** The migration that created or last changed it. */
|
|
74
|
+
lastChangedBy: string;
|
|
75
|
+
attributes: Record<string, Spec>;
|
|
76
|
+
}
|
|
77
|
+
/** A database's tables, read from its migrations, with notes for a person, or why they can't be. */
|
|
78
|
+
type SchemaResult = {
|
|
79
|
+
ok: true;
|
|
80
|
+
tables: GeneratedTable[];
|
|
81
|
+
notes: string[];
|
|
82
|
+
textDates: string[];
|
|
83
|
+
} | {
|
|
84
|
+
ok: false;
|
|
85
|
+
errors: string[];
|
|
86
|
+
};
|
|
87
|
+
/** What `g model` and `g migration` ask an adapter for: a migration's SQL, and its file's name. */
|
|
88
|
+
interface MigrationChange {
|
|
89
|
+
/** The migration's name, as Rails reads it (`CreateProducts`, `AddSkuToProducts`, …). */
|
|
90
|
+
name: string;
|
|
91
|
+
columns: readonly ColumnArg[];
|
|
92
|
+
/** Each existing table's key type, for the columns that reference it. */
|
|
93
|
+
keys: ReadonlyMap<string, KeyType>;
|
|
94
|
+
/** The migrations already in the folder, by path, for the new one's number. */
|
|
95
|
+
existing: readonly string[];
|
|
96
|
+
/** `--id integer`, and `--no-timestamps` as `timestamps: false`. */
|
|
97
|
+
options: {
|
|
98
|
+
integerId?: boolean;
|
|
99
|
+
timestamps?: boolean;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** A table's key type, which a column referencing it takes. */
|
|
103
|
+
type KeyType = "TEXT" | "INTEGER";
|
|
104
|
+
/** A migration's file name and SQL, or why it can't be written. */
|
|
105
|
+
type MigrationResult = {
|
|
106
|
+
ok: true;
|
|
107
|
+
file: string;
|
|
108
|
+
sql: string;
|
|
109
|
+
} | {
|
|
110
|
+
ok: false;
|
|
111
|
+
error: string;
|
|
112
|
+
};
|
|
113
|
+
/** The database a command acts on, and the config file that declares it. */
|
|
114
|
+
interface ChosenDatabase {
|
|
115
|
+
binding: string;
|
|
116
|
+
/** Its entry, as the config has it. */
|
|
117
|
+
entry: Record<string, unknown>;
|
|
118
|
+
configFile: string;
|
|
119
|
+
/** The config's account, which a config of the adapter's own would lose (D1's `account_id`). */
|
|
120
|
+
accountId?: string;
|
|
121
|
+
}
|
|
122
|
+
/** A remote database, named for a person to confirm before anything reaches it. */
|
|
123
|
+
interface RemoteTarget {
|
|
124
|
+
/** What the person types to confirm: its name. */
|
|
125
|
+
name: string;
|
|
126
|
+
/** "Remote database DB (shop, id 1a2b)". */
|
|
127
|
+
description: string;
|
|
128
|
+
/** A line more, when the remote database isn't the one a person would expect. */
|
|
129
|
+
note?: string;
|
|
130
|
+
}
|
|
131
|
+
/** An open database for the console, what to tell the person about it, and how to close it. */
|
|
132
|
+
interface OpenBinding {
|
|
133
|
+
/** What the project's `connect` takes: on D1, the `D1Database` binding, as `env.DB`. */
|
|
134
|
+
binding: unknown;
|
|
135
|
+
description: string;
|
|
136
|
+
dispose: () => Promise<void>;
|
|
137
|
+
}
|
|
138
|
+
/** Where `migrate` writes what the adapter's own tool prints. */
|
|
139
|
+
interface MigrateOutput {
|
|
140
|
+
output: (text: string) => void;
|
|
141
|
+
}
|
|
142
|
+
/** An adapter's plugin for the `active-record` command, from its `/cli` entry (ADR-0016). */
|
|
143
|
+
interface CliAdapter {
|
|
144
|
+
/** The name `--adapter` takes: `d1`. */
|
|
145
|
+
readonly name: string;
|
|
146
|
+
/** The project's databases, from its config, or why they can't be read. */
|
|
147
|
+
databases(cwd: string, configPath?: string): ConfigResult;
|
|
148
|
+
/** A database's tables, from its migrations applied in order. */
|
|
149
|
+
readSchema(migrations: readonly Migration[], options: {
|
|
150
|
+
migrationsTable?: string;
|
|
151
|
+
}): SchemaResult;
|
|
152
|
+
/** A migration's SQL, and its file name after the existing ones. */
|
|
153
|
+
migration(change: MigrationChange): MigrationResult;
|
|
154
|
+
/**
|
|
155
|
+
* The remote database `chosen` names, or why it has none: the one the console opens, or the one
|
|
156
|
+
* `migrate` applies migrations to, which needn't be the same (D1's preview database).
|
|
157
|
+
*/
|
|
158
|
+
remote(chosen: ChosenDatabase, use: "open" | "migrate"): RemoteTarget | string;
|
|
159
|
+
/** Opens the database for the console: the local one, or with `remote`, the real one. */
|
|
160
|
+
open(cwd: string, chosen: ChosenDatabase, options: {
|
|
161
|
+
remote: boolean;
|
|
162
|
+
}): Promise<OpenBinding | string>;
|
|
163
|
+
/** Applies the pending migrations, locally or with `remote` to the real database; the exit code. */
|
|
164
|
+
migrate(cwd: string, chosen: ChosenDatabase, options: {
|
|
165
|
+
remote: boolean;
|
|
166
|
+
}, io: MigrateOutput): Promise<number>;
|
|
167
|
+
}
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region cli/project/names.d.ts
|
|
170
|
+
/** A column's attribute: camelCase, keeping any leading underscores (`_secret` stays). */
|
|
171
|
+
export declare function attributeName(column: string): string;
|
|
172
|
+
/**
|
|
173
|
+
* The `const` a table is exported as: its words in camelCase (`line_items` → `lineItems`),
|
|
174
|
+
* never a reserved word (`default` → `defaultTable`) or starting with a digit (`2fa` →
|
|
175
|
+
* `table2fa`).
|
|
176
|
+
*/
|
|
177
|
+
export declare function exportName(table: string): string;
|
|
178
|
+
/** `"A"`, `"A or B"`, `"A, B or C"`. */
|
|
179
|
+
export declare function listed(names: readonly string[]): string;
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region cli/schema/storage-override.d.ts
|
|
182
|
+
/** The override that reads a Unix time as a `Date`, for a note; with Drizzle's modes named if asked. */
|
|
183
|
+
export declare function storageOverride(withDrizzleModes: boolean): string;
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/inflections.d.ts
|
|
186
|
+
/** Rails' `pluralize`: `category` → `categories`, `person` → `people`, `sheep` → `sheep`. */
|
|
187
|
+
export declare function pluralize(word: string): string;
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/naming.d.ts
|
|
190
|
+
/**
|
|
191
|
+
* Converts a camelCase attribute name to its snake_case column name, treating
|
|
192
|
+
* a run of capitals as one word (Rails' `underscore`): `htmlURL` → `html_url`,
|
|
193
|
+
* `userID` → `user_id`, `sha256Hash` → `sha256_hash`.
|
|
194
|
+
*/
|
|
195
|
+
export declare function underscore(name: string): string;
|
|
196
|
+
//#endregion
|
|
197
|
+
export type { ChosenDatabase, CliAdapter, ColumnArg, ConfigResult, DatabaseConfig, Default, GeneratedTable, KeyType, MigrateOutput, Migration, MigrationChange, MigrationResult, OpenBinding, RemoteTarget, SchemaResult, Spec };
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as underscore, n as pluralize } from "./epoch-storage-o2aoOH7H.mjs";
|
|
2
|
+
import { c as byName, i as exportName, n as attributeName, o as listed, t as storageOverride } from "./storage-override-BYBYP8Mj.mjs";
|
|
3
|
+
export { attributeName, byName, exportName, listed, pluralize, storageOverride, underscore };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|