@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.
- package/config-schema.json +6 -2
- package/dist/adapter.d.mts +3 -3
- package/dist/adapter.mjs +5 -4
- package/dist/batch-Ms5p9lKq.mjs +9777 -0
- package/dist/cli.d.mts +55 -33
- package/dist/cli.mjs +4 -4
- package/dist/command.mjs +530 -271
- package/dist/d1.d.mts +2 -10
- package/dist/d1.mjs +0 -0
- package/dist/{for-adapters-t3-LukJQ.d.mts → for-adapters-BT2GDjIA.d.mts} +8 -6
- package/dist/{for-adapters-Ch6CoHD4.mjs → for-adapters-BbIMUNcz.mjs} +46 -10
- package/dist/{for-adapters-D_Iu0gS_.mjs → for-adapters-C-MQxaIx.mjs} +3 -5
- package/dist/{generated-model-Cnt0Ot9q.mjs → generated-model-DJA8vmNE.mjs} +705 -508
- package/dist/identifiers-Dh5DFACX.mjs +989 -0
- package/dist/index-D5getfHx.d.mts +242 -0
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +5 -4
- package/dist/metadata-CzntpYzC.d.mts +182 -0
- package/dist/{plugin-Cyoej7qV.mjs → plugin-CZPDqguF.mjs} +211 -112
- package/dist/{plugin-XOHYndhP.mjs → plugin-Cf-5Z0_h.mjs} +148 -52
- package/dist/postgresql.d.mts +1 -9
- package/dist/postgresql.mjs +42 -26
- package/dist/src-BAVZKQ7J.mjs +46 -0
- package/dist/{storage-override-CpbkdIqE.mjs → storage-override-0ZgeP2sc.mjs} +61 -28
- package/dist/validations-BSZ5gVeI.d.mts +2024 -0
- package/llms-full.txt +2326 -229
- package/package.json +1 -1
- package/skills/active-record/SKILL.md +24 -15
- package/dist/adapter-AGKp6wfO.d.mts +0 -1326
- package/dist/batch-BS_WseLf.mjs +0 -4255
- package/dist/epoch-storage-o2aoOH7H.mjs +0 -112
- package/dist/index-CyCJuM96.d.mts +0 -149
- package/dist/src-la_KkjCS.mjs +0 -1
package/dist/d1.d.mts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
//#region src/adapters/d1/adapter.d.ts
|
|
1
|
+
import { C as QueryEvent$1, D as SchemaAdapter, O as AnyDatabase, w as QueryListener$1 } from "./validations-BSZ5gVeI.mjs";
|
|
2
|
+
import { i as ActiveRecordError } from "./index-D5getfHx.mjs";
|
|
4
3
|
/** The D1 database a generated schema's Models query: `adapter: d1({ binding: "DB" })`. */
|
|
5
4
|
export declare function d1({ binding }: {
|
|
6
5
|
binding: string;
|
|
7
6
|
}): SchemaAdapter;
|
|
8
|
-
//#endregion
|
|
9
|
-
//#region src/adapters/d1/database.d.ts
|
|
10
7
|
/** What `onQuery` hears about a statement: its Model, SQL, bound values, timing, and D1's `meta`. */
|
|
11
8
|
type QueryEvent = QueryEvent$1<D1Meta>;
|
|
12
9
|
/** Hears each statement's `QueryEvent`, with D1's `meta`. */
|
|
@@ -35,14 +32,10 @@ export declare class Database extends AnyDatabase {
|
|
|
35
32
|
bookmark(): D1SessionBookmark | null;
|
|
36
33
|
}
|
|
37
34
|
export declare function connect(binding: D1Database, options?: ConnectOptions): Database;
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region src/adapters/d1/errors.d.ts
|
|
40
35
|
/** `bookmark()` was called on a Database opened without a `session`. */
|
|
41
36
|
export declare class NoSession extends ActiveRecordError {
|
|
42
37
|
name: string;
|
|
43
38
|
}
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/adapters/d1/with-session.d.ts
|
|
46
39
|
/** How `withSession` opens the request's Database, and where its bookmark travels. */
|
|
47
40
|
type SessionOptions = Omit<ConnectOptions, "session"> & {
|
|
48
41
|
/** Where a request with no bookmark starts its Session: `"first-unconstrained"` unless set. */
|
|
@@ -64,5 +57,4 @@ type Handler = (db: Database) => Response | Promise<Response>;
|
|
|
64
57
|
*/
|
|
65
58
|
export declare function withSession(request: Request, binding: D1Database, fn: Handler): Promise<Response>;
|
|
66
59
|
export declare function withSession(request: Request, binding: D1Database, options: SessionOptions, fn: Handler): Promise<Response>;
|
|
67
|
-
//#endregion
|
|
68
60
|
export type { ConnectOptions, QueryEvent, QueryListener, SessionOptions };
|
package/dist/d1.mjs
CHANGED
|
Binary file
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { O as AnyDatabase } from "./validations-BSZ5gVeI.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Bytes as hex text, two digits each, for SQL that reads bytes from JSON (`unhex`, `\\x…`). The
|
|
4
|
+
* digits' character codes are written into one array and decoded once: mapping each byte to a
|
|
5
|
+
* string of its own takes many times the memory and time, which a large file can't afford.
|
|
6
|
+
*/
|
|
7
|
+
declare function hexOf(bytes: Uint8Array): string;
|
|
3
8
|
/**
|
|
4
9
|
* The request's database for a query on `binding` outside a Worker, or a `NoDatabase` saying what
|
|
5
10
|
* to do. `connect` is how the adapter's docs open one, such as `connect(env.DB)`.
|
|
6
11
|
*/
|
|
7
12
|
declare function onlyRequested(requested: readonly AnyDatabase[], binding: string | undefined, connect: string): AnyDatabase;
|
|
8
|
-
//#endregion
|
|
9
|
-
//#region src/workers-env.d.ts
|
|
10
13
|
/** A Worker's `env`: its bindings and variables, by name. */
|
|
11
14
|
type WorkersEnv = Record<string, unknown>;
|
|
12
15
|
/**
|
|
@@ -17,5 +20,4 @@ type WorkersEnv = Record<string, unknown>;
|
|
|
17
20
|
declare function workersEnv(load: () => Promise<{
|
|
18
21
|
env: unknown;
|
|
19
22
|
}>): Promise<WorkersEnv | undefined>;
|
|
20
|
-
|
|
21
|
-
export { workersEnv as n, onlyRequested as r, WorkersEnv as t };
|
|
23
|
+
export { hexOf as i, workersEnv as n, onlyRequested as r, WorkersEnv as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { C as pluralize, E as underscore, i as digitsProblem } from "./identifiers-Dh5DFACX.mjs";
|
|
2
|
+
import { f as byName, o as exportName } from "./storage-override-0ZgeP2sc.mjs";
|
|
3
|
+
// cli/generate/migration-plan.ts
|
|
4
4
|
/** What to do, read from a migration's name: `create_products`, `add_sku_to_products`, …; else empty. */
|
|
5
5
|
function migrationPlan(name) {
|
|
6
6
|
const words = underscore(name);
|
|
@@ -24,8 +24,7 @@ function migrationPlan(name) {
|
|
|
24
24
|
function indexName(table, column) {
|
|
25
25
|
return `index_${table}_on_${column}`;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
//#region cli/generate/migration-sql.ts
|
|
27
|
+
// cli/generate/migration-sql.ts
|
|
29
28
|
/** A name as SQL: quoted only when the database reserves it, so migrations stay readable. */
|
|
30
29
|
function quotedName(dialect, name) {
|
|
31
30
|
return dialect.reserved.has(name) ? `"${name}"` : name;
|
|
@@ -35,6 +34,12 @@ function literal(value) {
|
|
|
35
34
|
if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
|
|
36
35
|
return typeof value === "number" ? String(value) : `'${value.replaceAll("'", "''")}'`;
|
|
37
36
|
}
|
|
37
|
+
/** A column's type, with a decimal's precision and scale: `NUMERIC(10, 2)` (#398). */
|
|
38
|
+
function sizedType(column, dialect) {
|
|
39
|
+
const type = dialect.types[column.type];
|
|
40
|
+
if (column.precision === void 0) return type;
|
|
41
|
+
return `${type}(${column.scale === void 0 ? `${column.precision}` : `${column.precision}, ${column.scale}`})`;
|
|
42
|
+
}
|
|
38
43
|
/** A column's definition, as `CREATE TABLE` and `ADD COLUMN` write it. */
|
|
39
44
|
function definition(column, { dialect, keys }, notNull) {
|
|
40
45
|
const name = quotedName(dialect, column.name);
|
|
@@ -43,7 +48,7 @@ function definition(column, { dialect, keys }, notNull) {
|
|
|
43
48
|
const target = quotedName(dialect, column.references);
|
|
44
49
|
return `${name} ${type}${notNull ? " NOT NULL" : ""} REFERENCES ${target} (id)`;
|
|
45
50
|
}
|
|
46
|
-
const parts = [name, dialect
|
|
51
|
+
const parts = [name, sizedType(column, dialect)];
|
|
47
52
|
if (notNull) parts.push("NOT NULL");
|
|
48
53
|
if (column.default !== void 0) parts.push(`DEFAULT ${literal(column.default)}`);
|
|
49
54
|
const check = dialect.check?.(column, name);
|
|
@@ -135,8 +140,40 @@ function migrationSql(change, dialect) {
|
|
|
135
140
|
notes
|
|
136
141
|
};
|
|
137
142
|
}
|
|
138
|
-
|
|
139
|
-
|
|
143
|
+
// cli/schema/decimal-digits.ts
|
|
144
|
+
/**
|
|
145
|
+
* `spec` with a decimal's precision and scale, as a column's type gives them: neither when the
|
|
146
|
+
* column has no precision, and the scale only when it's given. Digits no `NUMERIC(p, s)` has (a
|
|
147
|
+
* precision past 1000, a scale past the precision) leave both off, so the Model stays valid.
|
|
148
|
+
*/
|
|
149
|
+
function withDigits(spec, precision, scale) {
|
|
150
|
+
if (spec.type !== "decimal" || precision === void 0 || precision === null) return spec;
|
|
151
|
+
const digits = {
|
|
152
|
+
precision,
|
|
153
|
+
...scale !== void 0 && scale !== null && { scale }
|
|
154
|
+
};
|
|
155
|
+
return digitsProblem(digits) === void 0 ? {
|
|
156
|
+
...spec,
|
|
157
|
+
...digits
|
|
158
|
+
} : spec;
|
|
159
|
+
}
|
|
160
|
+
// cli/schema/generated-enum.ts
|
|
161
|
+
/** A string spec with the names its column is restricted to, as a generated enum; any other spec as it is. */
|
|
162
|
+
function withGeneratedEnum(spec, names) {
|
|
163
|
+
if (names === void 0 || spec.type !== "string") return spec;
|
|
164
|
+
return {
|
|
165
|
+
...spec,
|
|
166
|
+
enum: names,
|
|
167
|
+
scopes: false,
|
|
168
|
+
instanceMethods: false
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/** A CHECK's list of SQL string literals as their text, each once: `'a', 'it''s', 'a'` → `["a", "it's"]`. */
|
|
172
|
+
function namesInList(list) {
|
|
173
|
+
const texts = [...list.matchAll(/'((?:[^']|'')*)'/g)].map((match) => match[1]);
|
|
174
|
+
return [...new Set(texts.map((text) => text.replaceAll("''", "'")))];
|
|
175
|
+
}
|
|
176
|
+
// cli/schema/tables.ts
|
|
140
177
|
const noFindings = () => ({
|
|
141
178
|
errors: [],
|
|
142
179
|
notes: [],
|
|
@@ -236,5 +273,4 @@ function generatedSchema(read, reading) {
|
|
|
236
273
|
textDates
|
|
237
274
|
};
|
|
238
275
|
}
|
|
239
|
-
|
|
240
|
-
export { migrationPlan as a, indexName as i, migrationSql as n, quotedName as r, generatedSchema as t };
|
|
276
|
+
export { migrationSql as a, migrationPlan as c, withDigits as i, namesInList as n, quotedName as o, withGeneratedEnum as r, indexName as s, generatedSchema as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { z as NoDatabase } from "./identifiers-Dh5DFACX.mjs";
|
|
2
|
+
// src/request-database.ts
|
|
3
3
|
/**
|
|
4
4
|
* The request's database for a query on `binding` outside a Worker, or a `NoDatabase` saying what
|
|
5
5
|
* to do. `connect` is how the adapter's docs open one, such as `connect(env.DB)`.
|
|
@@ -9,8 +9,7 @@ function onlyRequested(requested, binding, connect) {
|
|
|
9
9
|
const reason = requested.length > 1 ? "withDatabase was given several, and outside a Worker a binding can't tell which" : binding === void 0 ? "its Model's base class holds no generated schema, which names its binding" : `the binding ${binding} is only there inside a Worker`;
|
|
10
10
|
throw new NoDatabase(`No database for this query: ${reason}. Wrap the code in withDatabase(${connect}, …), or use db.model(Model)`);
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
//#region src/workers-env.ts
|
|
12
|
+
// src/workers-env.ts
|
|
14
13
|
/** Whether importing `cloudflare:workers` failed because this isn't a Worker (Node, scripts). */
|
|
15
14
|
function isOutsideWorker(error) {
|
|
16
15
|
const { code, message } = error;
|
|
@@ -29,5 +28,4 @@ async function workersEnv(load) {
|
|
|
29
28
|
throw error;
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
|
-
//#endregion
|
|
33
31
|
export { onlyRequested as n, workersEnv as t };
|