ezship 0.1.11 → 0.1.13
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/README.md +56 -8
- package/access.d.mts +120 -0
- package/access.mjs +987 -0
- package/account.d.mts +19 -0
- package/account.mjs +91 -0
- package/bindings.mjs +136 -0
- package/commands.d.mts +672 -0
- package/commands.mjs +8098 -0
- package/connections.d.mts +61 -0
- package/connections.mjs +312 -0
- package/cron.d.mts +17 -0
- package/cron.mjs +124 -0
- package/documents.d.mts +26 -0
- package/documents.mjs +242 -0
- package/editor-types.json.gz +0 -0
- package/editor.mjs +212 -0
- package/ez.mjs +1300 -2
- package/local-fetch.mjs +57 -0
- package/package.json +82 -6
- package/schema.d.mts +369 -0
- package/schema.mjs +3099 -0
- package/session.d.mts +20 -0
- package/session.mjs +142 -0
- package/shape.d.mts +14 -0
- package/shape.mjs +312 -0
- package/signup.d.mts +11 -0
- package/signup.mjs +42 -0
- package/types.d.mts +879 -0
- package/update-check.mjs +105 -0
- package/workflow.d.mts +63 -0
- package/workflow.mjs +450 -0
package/local-fetch.mjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Browsers map *.localhost to loopback; Node's OS resolver does not always do so.
|
|
2
|
+
// Preserve the Instance's URL/Host header while sending local HTTP directly to loopback.
|
|
3
|
+
import { request as httpRequest } from "node:http";
|
|
4
|
+
import { Readable } from "node:stream";
|
|
5
|
+
import { pipeline } from "node:stream/promises";
|
|
6
|
+
|
|
7
|
+
/** @param {string | URL | Request} input @param {RequestInit} [init] @returns {Promise<Response>} */
|
|
8
|
+
export function localFetch(input, init) {
|
|
9
|
+
const url = new URL(input instanceof Request ? input.url : input);
|
|
10
|
+
if (url.protocol !== "http:" || !url.hostname.endsWith(".localhost")) return fetch(input, init);
|
|
11
|
+
const request = new Request(input, init);
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const headers = Object.fromEntries(request.headers);
|
|
14
|
+
headers.host = url.host;
|
|
15
|
+
const outgoing = httpRequest(
|
|
16
|
+
{
|
|
17
|
+
hostname: "127.0.0.1",
|
|
18
|
+
port: url.port || 80,
|
|
19
|
+
path: url.pathname + url.search,
|
|
20
|
+
method: request.method,
|
|
21
|
+
headers,
|
|
22
|
+
signal: request.signal,
|
|
23
|
+
},
|
|
24
|
+
(incoming) => {
|
|
25
|
+
const headers = new Headers();
|
|
26
|
+
for (let i = 0; i < incoming.rawHeaders.length; i += 2)
|
|
27
|
+
headers.append(incoming.rawHeaders[i], incoming.rawHeaders[i + 1]);
|
|
28
|
+
const status = incoming.statusCode ?? 500;
|
|
29
|
+
if (
|
|
30
|
+
status >= 300 &&
|
|
31
|
+
status < 400 &&
|
|
32
|
+
headers.has("location") &&
|
|
33
|
+
request.redirect !== "manual"
|
|
34
|
+
) {
|
|
35
|
+
incoming.resume();
|
|
36
|
+
reject(new Error("Instance requests do not follow redirects."));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const empty = request.method === "HEAD" || [204, 205, 304].includes(status);
|
|
40
|
+
if (empty) incoming.resume();
|
|
41
|
+
resolve(
|
|
42
|
+
new Response(
|
|
43
|
+
empty ? null : /** @type {ReadableStream<Uint8Array>} */ (Readable.toWeb(incoming)),
|
|
44
|
+
{ status, headers },
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
outgoing.on("error", reject);
|
|
50
|
+
if (request.body)
|
|
51
|
+
void pipeline(
|
|
52
|
+
Readable.fromWeb(/** @type {import("node:stream/web").ReadableStream} */ (request.body)),
|
|
53
|
+
outgoing,
|
|
54
|
+
).catch((error) => outgoing.destroy(error));
|
|
55
|
+
else outgoing.end();
|
|
56
|
+
});
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,99 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ezship",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "ez, the ezship command line.
|
|
3
|
+
"version": "0.1.13",
|
|
4
|
+
"description": "ez, the ezship command line. The same files as @ezship/cli.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"bin": {
|
|
7
7
|
"ez": "ez.mjs"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"ez.mjs",
|
|
11
|
+
"editor.mjs",
|
|
12
|
+
"bindings.mjs",
|
|
13
|
+
"editor-types.json.gz",
|
|
14
|
+
"local-fetch.mjs",
|
|
15
|
+
"commands.mjs",
|
|
16
|
+
"commands.d.mts",
|
|
17
|
+
"schema.mjs",
|
|
18
|
+
"schema.d.mts",
|
|
19
|
+
"access.mjs",
|
|
20
|
+
"access.d.mts",
|
|
21
|
+
"shape.mjs",
|
|
22
|
+
"shape.d.mts",
|
|
23
|
+
"session.mjs",
|
|
24
|
+
"session.d.mts",
|
|
25
|
+
"types.d.mts",
|
|
11
26
|
"README.md",
|
|
12
|
-
"LICENSE"
|
|
27
|
+
"LICENSE",
|
|
28
|
+
"account.mjs",
|
|
29
|
+
"account.d.mts",
|
|
30
|
+
"connections.mjs",
|
|
31
|
+
"connections.d.mts",
|
|
32
|
+
"signup.mjs",
|
|
33
|
+
"signup.d.mts",
|
|
34
|
+
"cron.mjs",
|
|
35
|
+
"cron.d.mts",
|
|
36
|
+
"workflow.mjs",
|
|
37
|
+
"workflow.d.mts",
|
|
38
|
+
"documents.mjs",
|
|
39
|
+
"documents.d.mts",
|
|
40
|
+
"update-check.mjs"
|
|
13
41
|
],
|
|
14
42
|
"type": "module",
|
|
43
|
+
"exports": {
|
|
44
|
+
"./signup": {
|
|
45
|
+
"types": "./signup.d.mts",
|
|
46
|
+
"default": "./signup.mjs"
|
|
47
|
+
},
|
|
48
|
+
".": "./ez.mjs",
|
|
49
|
+
"./connections": {
|
|
50
|
+
"types": "./connections.d.mts",
|
|
51
|
+
"default": "./connections.mjs"
|
|
52
|
+
},
|
|
53
|
+
"./contract": {
|
|
54
|
+
"types": "./commands.d.mts",
|
|
55
|
+
"default": "./commands.mjs"
|
|
56
|
+
},
|
|
57
|
+
"./schema": {
|
|
58
|
+
"types": "./schema.d.mts",
|
|
59
|
+
"default": "./schema.mjs"
|
|
60
|
+
},
|
|
61
|
+
"./access": {
|
|
62
|
+
"types": "./access.d.mts",
|
|
63
|
+
"default": "./access.mjs"
|
|
64
|
+
},
|
|
65
|
+
"./types": {
|
|
66
|
+
"types": "./types.d.mts"
|
|
67
|
+
},
|
|
68
|
+
"./account": {
|
|
69
|
+
"types": "./account.d.mts",
|
|
70
|
+
"default": "./account.mjs"
|
|
71
|
+
},
|
|
72
|
+
"./shape": {
|
|
73
|
+
"types": "./shape.d.mts",
|
|
74
|
+
"default": "./shape.mjs"
|
|
75
|
+
},
|
|
76
|
+
"./session": {
|
|
77
|
+
"types": "./session.d.mts",
|
|
78
|
+
"default": "./session.mjs"
|
|
79
|
+
},
|
|
80
|
+
"./cron": {
|
|
81
|
+
"types": "./cron.d.mts",
|
|
82
|
+
"default": "./cron.mjs"
|
|
83
|
+
},
|
|
84
|
+
"./workflow": {
|
|
85
|
+
"types": "./workflow.d.mts",
|
|
86
|
+
"default": "./workflow.mjs"
|
|
87
|
+
},
|
|
88
|
+
"./documents": {
|
|
89
|
+
"types": "./documents.d.mts",
|
|
90
|
+
"default": "./documents.mjs"
|
|
91
|
+
}
|
|
92
|
+
},
|
|
15
93
|
"scripts": {
|
|
94
|
+
"check": "bun check --no-script",
|
|
16
95
|
"test": "bun test --parallel --timeout=0 ./*.test.mjs"
|
|
17
96
|
},
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"@ezship/cli": "^0.1.11"
|
|
20
|
-
},
|
|
21
97
|
"engines": {
|
|
22
98
|
"node": ">=20"
|
|
23
99
|
}
|
package/schema.d.mts
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
// Hand-written declarations for cli/schema.mjs. Keep in step with the JSDoc there.
|
|
2
|
+
|
|
3
|
+
/** A JSON column's parsed TYPE (docs/adr/0078); `Column.shape` holds its printed form. */
|
|
4
|
+
export type { Shape } from "./shape.d.mts";
|
|
5
|
+
import type { IntegrityChange } from "./types.d.mts";
|
|
6
|
+
|
|
7
|
+
export type ColumnType =
|
|
8
|
+
| "TEXT"
|
|
9
|
+
| "INTEGER"
|
|
10
|
+
| "REAL"
|
|
11
|
+
| "BOOLEAN"
|
|
12
|
+
| "TIMESTAMP"
|
|
13
|
+
| "DATE"
|
|
14
|
+
| "MONEY"
|
|
15
|
+
| "JSON"
|
|
16
|
+
| "FILE"
|
|
17
|
+
| "MEMBER";
|
|
18
|
+
export type StorageType = "TEXT" | "INTEGER" | "REAL";
|
|
19
|
+
export type Policy = "member" | "none";
|
|
20
|
+
export type Column = {
|
|
21
|
+
type: ColumnType;
|
|
22
|
+
required: boolean;
|
|
23
|
+
ref: string | null;
|
|
24
|
+
values: string[] | null;
|
|
25
|
+
/** `INTEGER SEQUENCE` (docs/adr/0046): numbered per Table by the platform; present only when declared. */
|
|
26
|
+
sequence?: true;
|
|
27
|
+
/** `JSON TYPE '<shape>'` (docs/adr/0078): the printed shape; present only when declared. */
|
|
28
|
+
shape?: string;
|
|
29
|
+
/** `DEFAULT <value>` (docs/adr/0097): what an insert omitting the column stores; present only when declared. */
|
|
30
|
+
default?: ColumnDefault;
|
|
31
|
+
/** `REFERENCES <table> ON DELETE RESTRICT` (docs/adr/0109): the referenced row cannot be deleted while referenced. */
|
|
32
|
+
onDelete?: "restrict";
|
|
33
|
+
/** `LABEL '<label>'` (docs/adr/0109): how forms and lists name the column; present only when declared. */
|
|
34
|
+
label?: string;
|
|
35
|
+
/** The comment on the column's line (docs/adr/0109); present only when written. */
|
|
36
|
+
doc?: string;
|
|
37
|
+
};
|
|
38
|
+
/** A declared default (docs/adr/0097): a literal, the insert's time, or the inserting Member. */
|
|
39
|
+
export type ColumnDefault =
|
|
40
|
+
| { kind: "value"; value: string | number | boolean }
|
|
41
|
+
| { kind: "now" }
|
|
42
|
+
| { kind: "me" };
|
|
43
|
+
/** A default a Global Push adds, changes or removes, each side printed as declared (null: none). */
|
|
44
|
+
export type DefaultChange = {
|
|
45
|
+
table: string;
|
|
46
|
+
column: string;
|
|
47
|
+
from: string | null;
|
|
48
|
+
to: string | null;
|
|
49
|
+
};
|
|
50
|
+
export type Table = {
|
|
51
|
+
columns: Record<string, Column>;
|
|
52
|
+
indexes: string[][];
|
|
53
|
+
/** `CREATE UNIQUE INDEX` column lists (docs/adr/0046); absent in Declarations that predate it. */
|
|
54
|
+
unique?: string[][];
|
|
55
|
+
read?: Policy;
|
|
56
|
+
write?: Policy;
|
|
57
|
+
/** Set on a History Table (docs/adr/0040): the Table it records. Never declared. */
|
|
58
|
+
history?: string;
|
|
59
|
+
/** Built-in read surface; never accepted in an authored schema. */
|
|
60
|
+
view?: "actors";
|
|
61
|
+
/** `LABEL '<singular>' ['<plural>']` (docs/adr/0109): how a row and the Table are named. */
|
|
62
|
+
label?: string;
|
|
63
|
+
plural?: string;
|
|
64
|
+
/** `DISPLAY (<columns>)` (docs/adr/0109): the one or two columns a reference to a row reads by. */
|
|
65
|
+
display?: string[];
|
|
66
|
+
/** `SINGLETON` (docs/adr/0109): at most one row, enforced by the Host for every writer. */
|
|
67
|
+
singleton?: true;
|
|
68
|
+
/** `EXACTLY ONE OF (<columns>)` (docs/adr/0109): every row sets exactly one of these columns. */
|
|
69
|
+
exactlyOne?: string[];
|
|
70
|
+
};
|
|
71
|
+
/** The parsed schema captured by a Site or Preview from global/db/schema.sql. */
|
|
72
|
+
export type Declaration = { tables: Record<string, Table> };
|
|
73
|
+
export type ParseError = { error: string; line: number };
|
|
74
|
+
|
|
75
|
+
export const SCHEMA_FILE: "db/schema.sql";
|
|
76
|
+
export const RESERVED_DIR: "db/";
|
|
77
|
+
export const TABLE_PREFIX: "data_";
|
|
78
|
+
export const PLATFORM_PREFIX: "data_ez_";
|
|
79
|
+
/** The App Database operations a server function's `db` sends to the Host, with the argument counts it accepts. */
|
|
80
|
+
export const DATABASE_OPERATIONS: Readonly<
|
|
81
|
+
Record<
|
|
82
|
+
"list" | "query" | "aggregate" | "get" | "insert" | "update" | "delete" | "transition",
|
|
83
|
+
readonly number[]
|
|
84
|
+
>
|
|
85
|
+
>;
|
|
86
|
+
/** One of `DATABASE_OPERATIONS`: a method every `db` has, in a page and on the Host. */
|
|
87
|
+
export type DatabaseOperation = keyof typeof DATABASE_OPERATIONS;
|
|
88
|
+
/** The longest Push message and write reason (docs/adr/0093), in characters. */
|
|
89
|
+
export const MAX_MESSAGE_CHARS: 500;
|
|
90
|
+
/** A Push message or write reason as stored: trimmed, null when absent or blank. */
|
|
91
|
+
export function messageText(
|
|
92
|
+
value: unknown,
|
|
93
|
+
what: string,
|
|
94
|
+
): { text: string | null } | { error: string };
|
|
95
|
+
export const SYSTEM_COLUMNS: readonly string[];
|
|
96
|
+
/** Table History (docs/adr/0040). */
|
|
97
|
+
export const HISTORY_SUFFIX: "_history";
|
|
98
|
+
export const HISTORY_OPEN: 253402300799999;
|
|
99
|
+
export const HISTORY_OPS: readonly ["seed", "insert", "update", "delete"];
|
|
100
|
+
export const HISTORY_COLUMNS: Readonly<
|
|
101
|
+
Record<"row_id" | "op" | "valid_from" | "valid_to" | "by" | "version" | "why", ColumnType>
|
|
102
|
+
>;
|
|
103
|
+
export function historyName(table: string): string;
|
|
104
|
+
export function historyParent(name: string, names: readonly string[]): string | null;
|
|
105
|
+
export const NAME_RE: RegExp;
|
|
106
|
+
export const VALUE_RE: RegExp;
|
|
107
|
+
/** What a FILE column holds (docs/adr/0047): an Attachment id. */
|
|
108
|
+
export const ATTACHMENT_ID_RE: RegExp;
|
|
109
|
+
/** What a MEMBER column holds (docs/adr/0098): `user:<id>`. */
|
|
110
|
+
export const MEMBER_ID_RE: RegExp;
|
|
111
|
+
/** A Member group's name (docs/adr/0098). */
|
|
112
|
+
export const GROUP_RE: RegExp;
|
|
113
|
+
/** The most distinct groups an Instance's roster holds (docs/adr/0098). */
|
|
114
|
+
export const MAX_GROUPS: 50;
|
|
115
|
+
/** The Host's groups (docs/adr/0110): held through the Builder roster, never assigned or declared. */
|
|
116
|
+
export const RESERVED_GROUPS: readonly ["ez-admin", "ez-builder"];
|
|
117
|
+
/** Whether a group name is the Host's (`ez-` prefixed): no one assigns or declares it. */
|
|
118
|
+
export function isReservedGroup(name: string): boolean;
|
|
119
|
+
export const RULES: {
|
|
120
|
+
types: Record<ColumnType, StorageType>;
|
|
121
|
+
policies: readonly Policy[];
|
|
122
|
+
refused: Record<string, string>;
|
|
123
|
+
reservedNames: readonly string[];
|
|
124
|
+
limits: { tablesPerInstance: number; columnsPerTable: number; valuesPerCheck: number };
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export function parseSchema(sql: string): Declaration | ParseError;
|
|
128
|
+
/** Authored global schemas exclude NOT NULL; parseSchema also reads retained legacy declarations. */
|
|
129
|
+
export function parseGlobalSchema(sql: string): Declaration | ParseError;
|
|
130
|
+
export function schemaChangeError(previous: Declaration, next: Declaration): string | null;
|
|
131
|
+
|
|
132
|
+
export type LiveTable = {
|
|
133
|
+
columns: Record<string, StorageType>;
|
|
134
|
+
indexes: string[][];
|
|
135
|
+
/** The unique indexes' column lists (docs/adr/0046). */
|
|
136
|
+
unique?: string[][];
|
|
137
|
+
};
|
|
138
|
+
/** GET /api/i/:instance/db/schema: what exists, and every Site's registered Declaration. */
|
|
139
|
+
export type LiveSchema = {
|
|
140
|
+
live: { tables: Record<string, LiveTable> };
|
|
141
|
+
declarations: Record<string, Record<string, Table>>;
|
|
142
|
+
};
|
|
143
|
+
export type Conflict = {
|
|
144
|
+
table: string;
|
|
145
|
+
column: string;
|
|
146
|
+
mine: string;
|
|
147
|
+
theirs: string;
|
|
148
|
+
site: string | null;
|
|
149
|
+
};
|
|
150
|
+
export type PlanSummary = { created: string[]; added: string[]; indexed: string[] };
|
|
151
|
+
export type Plan = { statements: string[]; conflicts: Conflict[]; summary: PlanSummary };
|
|
152
|
+
|
|
153
|
+
export function physicalName(instance: string, table: string): string;
|
|
154
|
+
export function indexName(
|
|
155
|
+
instance: string,
|
|
156
|
+
table: string,
|
|
157
|
+
cols: string[],
|
|
158
|
+
unique?: boolean,
|
|
159
|
+
): string;
|
|
160
|
+
export function indexColumns(
|
|
161
|
+
instance: string,
|
|
162
|
+
table: string,
|
|
163
|
+
name: string,
|
|
164
|
+
): { columns: string[]; unique: boolean } | null;
|
|
165
|
+
export function describeColumn(column: Column, name?: string): string;
|
|
166
|
+
export function printDefault(d: ColumnDefault): string;
|
|
167
|
+
export function storedDefault(
|
|
168
|
+
d: ColumnDefault,
|
|
169
|
+
context: { now: number; me?: string | null },
|
|
170
|
+
): string | number | null;
|
|
171
|
+
export function defaultChanges(previous: Declaration, next: Declaration): DefaultChange[];
|
|
172
|
+
export function createTableStatements(instance: string, table: string, def: Table): string[];
|
|
173
|
+
export function storageColumns(def: Table): Record<string, StorageType>;
|
|
174
|
+
export function lookupIndexStatements(instance: string, table: string): string[];
|
|
175
|
+
export function historyStatements(
|
|
176
|
+
instance: string,
|
|
177
|
+
table: string,
|
|
178
|
+
columns: Record<string, StorageType>,
|
|
179
|
+
): string[];
|
|
180
|
+
export function bookkeepingTriggerStatements(
|
|
181
|
+
instance: string,
|
|
182
|
+
table: string,
|
|
183
|
+
columns: Record<string, StorageType>,
|
|
184
|
+
sequences?: string[],
|
|
185
|
+
): string[];
|
|
186
|
+
export function sequenceTriggerStatements(
|
|
187
|
+
instance: string,
|
|
188
|
+
table: string,
|
|
189
|
+
column: string,
|
|
190
|
+
): string[];
|
|
191
|
+
export function seedHistoryStatement(
|
|
192
|
+
instance: string,
|
|
193
|
+
table: string,
|
|
194
|
+
columns: Record<string, StorageType>,
|
|
195
|
+
): string;
|
|
196
|
+
export function installHistoryStatements(
|
|
197
|
+
instance: string,
|
|
198
|
+
table: string,
|
|
199
|
+
columns: Record<string, StorageType>,
|
|
200
|
+
): string[];
|
|
201
|
+
export function checkTriggerStatements(
|
|
202
|
+
instance: string,
|
|
203
|
+
table: string,
|
|
204
|
+
column: string,
|
|
205
|
+
values: string[],
|
|
206
|
+
): string[];
|
|
207
|
+
export function newUniqueIndexes(
|
|
208
|
+
live: LiveSchema["live"],
|
|
209
|
+
decl: Declaration,
|
|
210
|
+
): { table: string; columns: string[] }[];
|
|
211
|
+
export function planSchema(
|
|
212
|
+
schema: LiveSchema,
|
|
213
|
+
mine: Declaration,
|
|
214
|
+
instance: string,
|
|
215
|
+
siteId: string,
|
|
216
|
+
): Plan | { error: string };
|
|
217
|
+
|
|
218
|
+
export type WhereOp = "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "like";
|
|
219
|
+
export type Where =
|
|
220
|
+
| { column: string; op: WhereOp; value: string | number }
|
|
221
|
+
/** An empty list matches nothing (docs/adr/0102). */
|
|
222
|
+
| { column: string; op: "in"; value: (string | number)[] }
|
|
223
|
+
/** None of the values, NULL included; an empty list matches every row (docs/adr/0115). */
|
|
224
|
+
| { column: string; op: "nin"; value: (string | number)[] }
|
|
225
|
+
| { column: string; op: "null"; value: boolean }
|
|
226
|
+
/** An id list or JSON string[] column holding the value (docs/adr/0102). */
|
|
227
|
+
| { column: string; op: "has"; value: string }
|
|
228
|
+
/** Any branch passes; each branch is an AND of its items. */
|
|
229
|
+
| { op: "or"; items: Where[][] }
|
|
230
|
+
/** The row `column` references (any of them, for an id list: `many`) passes `where` in `table`. */
|
|
231
|
+
| { column: string; op: "via"; table: string; many: boolean; where: Where[] };
|
|
232
|
+
/**
|
|
233
|
+
* One include (docs/adr/0102): `row` and `rows` follow the row's `column` (a reference, an id list), `actor`
|
|
234
|
+
* a MEMBER column or created_by/updated_by to `actors`, `children` the rows of `table` whose `column`
|
|
235
|
+
* references this one. `columns` null is every column; `id` always comes. Lands on the row as `field`.
|
|
236
|
+
*/
|
|
237
|
+
export type Include = {
|
|
238
|
+
field: string;
|
|
239
|
+
kind: "row" | "rows" | "actor" | "children";
|
|
240
|
+
column: string;
|
|
241
|
+
table: string;
|
|
242
|
+
columns: string[] | null;
|
|
243
|
+
include: Include[];
|
|
244
|
+
};
|
|
245
|
+
export type Query = {
|
|
246
|
+
where: Where[];
|
|
247
|
+
order: [string, "asc" | "desc", ("first" | "last")?][];
|
|
248
|
+
limit: number;
|
|
249
|
+
offset: number;
|
|
250
|
+
/** `scope: false` (docs/adr/0098): past the active scope. */
|
|
251
|
+
unscoped?: true;
|
|
252
|
+
include?: Include[];
|
|
253
|
+
};
|
|
254
|
+
export type StorageRow = Record<string, string | number | null>;
|
|
255
|
+
export type Aggregate = Query & { group: string[]; sum: string[] };
|
|
256
|
+
export const ACTORS_TABLE: Table;
|
|
257
|
+
export function checkAggregate(
|
|
258
|
+
q: unknown,
|
|
259
|
+
table: Table,
|
|
260
|
+
tables?: Record<string, Table>,
|
|
261
|
+
): Aggregate | { error: string };
|
|
262
|
+
|
|
263
|
+
export const QUERY_MAX_LIMIT: 1000;
|
|
264
|
+
export const QUERY_DEFAULT_LIMIT: 100;
|
|
265
|
+
export function effectivePolicies(table: Table): { read: Policy; write: Policy };
|
|
266
|
+
export function historyTable(parent: string, def: Table): Table;
|
|
267
|
+
export function withHistory(declared: Record<string, Table>): Record<string, Table>;
|
|
268
|
+
export function columnTypeOf(table: Table, name: string): ColumnType | null;
|
|
269
|
+
export function checkQuery(
|
|
270
|
+
q: unknown,
|
|
271
|
+
table: Table,
|
|
272
|
+
tables?: Record<string, Table>,
|
|
273
|
+
): Query | { error: string };
|
|
274
|
+
/** The Tables a query reads besides its own (docs/adr/0102). */
|
|
275
|
+
export function queryTables(q: Query): string[];
|
|
276
|
+
/** Where an include lands on a row of `table` (docs/adr/0102). */
|
|
277
|
+
export function includeField(table: Table, key: string, kind: Include["kind"]): string;
|
|
278
|
+
/** The children a reverse include brings per row, at most. */
|
|
279
|
+
export const MAX_CHILDREN: 100;
|
|
280
|
+
export function checkRow(
|
|
281
|
+
body: unknown,
|
|
282
|
+
table: Table,
|
|
283
|
+
mode: "insert" | "update",
|
|
284
|
+
): { row: StorageRow } | { error: string };
|
|
285
|
+
export function fromStorage(row: Record<string, unknown>, table: Table): Record<string, unknown>;
|
|
286
|
+
|
|
287
|
+
export const SQL_MAX_ROWS: 10000;
|
|
288
|
+
export function checkSql(
|
|
289
|
+
statement: string,
|
|
290
|
+
tables: { app: string[]; other: string[] },
|
|
291
|
+
instance: string,
|
|
292
|
+
):
|
|
293
|
+
| { kind: "read"; sql: string; tables: string[] }
|
|
294
|
+
| { kind: "write"; sql: string; tables: string[]; verb: "INSERT" | "UPDATE" | "DELETE" }
|
|
295
|
+
| { error: string };
|
|
296
|
+
export function helpDb(): string;
|
|
297
|
+
/** `ez help access`'s access.sql reference. */
|
|
298
|
+
export function helpAccess(): string;
|
|
299
|
+
export function renderSchema(schema: LiveSchema): string;
|
|
300
|
+
|
|
301
|
+
export const TYPES_HEADER: string;
|
|
302
|
+
export function aliasName(table: string): string;
|
|
303
|
+
|
|
304
|
+
/** One column as the record components see it (docs/adr/0109). */
|
|
305
|
+
export type ColumnInfo = {
|
|
306
|
+
name: string;
|
|
307
|
+
type: ColumnType;
|
|
308
|
+
/** The declared LABEL, else the name humanised. */
|
|
309
|
+
label: string;
|
|
310
|
+
doc?: string;
|
|
311
|
+
/** The Table a reference or id list (`many`) points at. */
|
|
312
|
+
ref?: string;
|
|
313
|
+
many?: true;
|
|
314
|
+
values?: string[];
|
|
315
|
+
shape?: string;
|
|
316
|
+
default?: ColumnDefault;
|
|
317
|
+
sequence?: true;
|
|
318
|
+
/** `ON DELETE RESTRICT`. */
|
|
319
|
+
restrict?: true;
|
|
320
|
+
};
|
|
321
|
+
/** One Table as the record components see it (docs/adr/0109). */
|
|
322
|
+
export type TableInfo = {
|
|
323
|
+
name: string;
|
|
324
|
+
/** How one row is named ("Dealer"), and the Table ("Dealers"). */
|
|
325
|
+
label: string;
|
|
326
|
+
plural: string;
|
|
327
|
+
/** The columns a reference to a row reads by: DISPLAY, else the first TEXT column; empty means the id. */
|
|
328
|
+
display: string[];
|
|
329
|
+
singleton: boolean;
|
|
330
|
+
exactlyOne: string[];
|
|
331
|
+
unique: string[][];
|
|
332
|
+
/** Declared order. */
|
|
333
|
+
columns: ColumnInfo[];
|
|
334
|
+
/** Every scalar reference column, of any Table, that points at this one. */
|
|
335
|
+
referencedBy: { table: string; column: string; restrict: boolean }[];
|
|
336
|
+
};
|
|
337
|
+
export type SchemaDescriptor = { tables: Record<string, TableInfo> };
|
|
338
|
+
export function describeSchema(decl: Declaration): SchemaDescriptor;
|
|
339
|
+
/** The SINGLETON, EXACTLY ONE OF and ON DELETE RESTRICT a Push adds or removes (docs/adr/0109). */
|
|
340
|
+
export function integrityChanges(previous: Declaration, next: Declaration): IntegrityChange[];
|
|
341
|
+
export function humanize(name: string): string;
|
|
342
|
+
export function pluralLabel(label: string): string;
|
|
343
|
+
/**
|
|
344
|
+
* `db/types.d.ts` for a declaration. `workflows` (docs/adr/0103), read from `workflows/<table>.ts` files,
|
|
345
|
+
* type each workflow's column as its states, never null, and declare `Workflows`.
|
|
346
|
+
*/
|
|
347
|
+
export function generateTypes(
|
|
348
|
+
declaration: Declaration,
|
|
349
|
+
workflows?: Record<string, { column: string; states: string[]; actions: string[] }>,
|
|
350
|
+
): string;
|
|
351
|
+
/** Why a stored value fails the column's DATE or JSON TYPE rule, or null (docs/adr/0078). */
|
|
352
|
+
export function storedValueError(column: Column, stored: unknown, name: string): string | null;
|
|
353
|
+
/** New TEXT columns named status, type or *_type without a CHECK list (schema-untyped-enum). */
|
|
354
|
+
export function untypedEnums(
|
|
355
|
+
next: Declaration,
|
|
356
|
+
previous: Declaration,
|
|
357
|
+
sql: string,
|
|
358
|
+
): { table: string; column: string; line: number }[];
|
|
359
|
+
/** New REAL columns named like money (price, amount_due) and not a ratio of it (schema-real-money, ADR 0107). */
|
|
360
|
+
export function realMoney(
|
|
361
|
+
next: Declaration,
|
|
362
|
+
previous: Declaration,
|
|
363
|
+
sql: string,
|
|
364
|
+
): { table: string; column: string; line: number }[];
|
|
365
|
+
/** Columns `next` tightens for stored values: TEXT to DATE, a JSON TYPE added or changed. */
|
|
366
|
+
export function tightenedColumns(
|
|
367
|
+
previous: Declaration,
|
|
368
|
+
next: Declaration,
|
|
369
|
+
): { table: string; column: string; def: Column }[];
|