@teable/app 6.0.1 → 6.1.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/dist/build/cli.js +2 -2
- package/dist/build/index.d.ts +9 -0
- package/dist/build/index.js +2 -2
- package/dist/chunks/{YGOAZOUE.js → A27ZPYPU.js} +1 -1
- package/dist/chunks/{33OZ5YAY.js → APGIRZ24.js} +44 -4
- package/dist/chunks/{N7LBNIRZ.js → NOOZYN7X.js} +5 -2
- package/dist/chunks/{TXLTJKEX.js → V7ENYEWD.js} +6 -1
- package/dist/chunks/{VMIIUPHE.js → WKI563UT.js} +2 -0
- package/dist/client.js +2 -2
- package/dist/dev/host.js +1 -1
- package/dist/index.js +3 -3
- package/dist/protocol.d.ts +32 -0
- package/dist/protocol.js +3 -1
- package/dist/schema.d.ts +6 -1
- package/dist/schema.js +2 -2
- package/dist/server/app.d.ts +16 -1
- package/dist/testing.js +4 -4
- package/dist/worker.js +2 -2
- package/package.json +1 -1
package/dist/build/cli.js
CHANGED
package/dist/build/index.d.ts
CHANGED
|
@@ -131,6 +131,15 @@ export declare function teable(options?: TeableOptions): {
|
|
|
131
131
|
};
|
|
132
132
|
};
|
|
133
133
|
}>;
|
|
134
|
+
/** The pages name the app they are built for: a deploy to another app refuses them. */
|
|
135
|
+
transformIndexHtml(): {
|
|
136
|
+
tag: string;
|
|
137
|
+
attrs: {
|
|
138
|
+
name: string;
|
|
139
|
+
content: string;
|
|
140
|
+
};
|
|
141
|
+
injectTo: string;
|
|
142
|
+
}[];
|
|
134
143
|
configureServer(server: DevServer): (() => void) | undefined;
|
|
135
144
|
};
|
|
136
145
|
export {};
|
package/dist/build/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
describeTables
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./NOOZYN7X.js";
|
|
4
4
|
import {
|
|
5
5
|
CAPABILITIES,
|
|
6
6
|
PROTOCOL_VERSION,
|
|
7
7
|
admit,
|
|
8
8
|
isPageAccess
|
|
9
|
-
} from "./
|
|
9
|
+
} from "./WKI563UT.js";
|
|
10
10
|
|
|
11
11
|
// src/server/errors.ts
|
|
12
12
|
import { z } from "zod";
|
|
@@ -807,6 +807,7 @@ function createApp(options) {
|
|
|
807
807
|
output: def.output,
|
|
808
808
|
access: def.access ?? "editor",
|
|
809
809
|
description: def.description,
|
|
810
|
+
edits: def.edits,
|
|
810
811
|
handler: def.handler
|
|
811
812
|
};
|
|
812
813
|
},
|
|
@@ -873,9 +874,11 @@ function defineApp(schema, migrations, methods, { capabilities, pages }) {
|
|
|
873
874
|
throw new Error(`Table "${table.name}" uses the reserved prefix ${RESERVED_PREFIX}`);
|
|
874
875
|
}
|
|
875
876
|
}
|
|
877
|
+
const exported = new Map(Object.entries(schema).map(([key, value]) => [value, key]));
|
|
878
|
+
const tableOf = (table) => tables.find((t) => t.key === exported.get(table));
|
|
876
879
|
const manifest = {
|
|
877
880
|
protocol: PROTOCOL_VERSION,
|
|
878
|
-
methods: Object.entries(methods).map(([name, m]) => describeMethod(name, m)),
|
|
881
|
+
methods: Object.entries(methods).map(([name, m]) => describeMethod(name, m, tableOf)),
|
|
879
882
|
tables,
|
|
880
883
|
capabilities: [...new Set(capabilities)],
|
|
881
884
|
pages
|
|
@@ -1020,7 +1023,7 @@ function capabilitiesFrom(env) {
|
|
|
1020
1023
|
CAPABILITIES.map((name) => [name, each(name)])
|
|
1021
1024
|
);
|
|
1022
1025
|
}
|
|
1023
|
-
function describeMethod(name, method) {
|
|
1026
|
+
function describeMethod(name, method, tableOf) {
|
|
1024
1027
|
const input = z2.toJSONSchema(method.input, {
|
|
1025
1028
|
io: "input",
|
|
1026
1029
|
unrepresentable: "any"
|
|
@@ -1028,6 +1031,13 @@ function describeMethod(name, method) {
|
|
|
1028
1031
|
if (input.type !== "object") {
|
|
1029
1032
|
throw new Error(`Method "${name}" input must be a z.object(...)`);
|
|
1030
1033
|
}
|
|
1034
|
+
if (method.kind === "write" && method.edits !== void 0) {
|
|
1035
|
+
const table = tableOf(method.edits);
|
|
1036
|
+
if (!table) throw new Error(`Method "${name}" edits a table the app's schema does not export`);
|
|
1037
|
+
checkEdits(name, input, table);
|
|
1038
|
+
const edits = { "x-teable-edits": table.name };
|
|
1039
|
+
Object.assign(input, edits);
|
|
1040
|
+
}
|
|
1031
1041
|
const info = { name, kind: method.kind, access: method.access, input };
|
|
1032
1042
|
if (method.description !== void 0) info.description = method.description;
|
|
1033
1043
|
if (method.kind !== "task" && method.output !== void 0) {
|
|
@@ -1041,6 +1051,36 @@ function describeMethod(name, method) {
|
|
|
1041
1051
|
}
|
|
1042
1052
|
return info;
|
|
1043
1053
|
}
|
|
1054
|
+
var isSchema = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1055
|
+
function checkEdits(name, input, table) {
|
|
1056
|
+
const refuse = (why) => new Error(`Method "${name}" edits ${table.name}: ${why}`);
|
|
1057
|
+
const properties = isSchema(input.properties) ? input.properties : {};
|
|
1058
|
+
const required = new Set(Array.isArray(input.required) ? input.required : []);
|
|
1059
|
+
const key = table.columns.filter((column) => column.primaryKey);
|
|
1060
|
+
if (key.length === 0) throw refuse("it has no primary key to say which row an edit is of");
|
|
1061
|
+
for (const column of key) {
|
|
1062
|
+
if (!required.has(column.key)) {
|
|
1063
|
+
throw refuse(`its input must require "${column.key}", the row's primary key`);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
let columns = 0;
|
|
1067
|
+
for (const [property, schema] of Object.entries(properties)) {
|
|
1068
|
+
const column = table.columns.find((c) => c.key === property);
|
|
1069
|
+
if (!column) {
|
|
1070
|
+
throw refuse(`"${property}" is not one of its columns, and an edit sends only columns`);
|
|
1071
|
+
}
|
|
1072
|
+
if (column.primaryKey) continue;
|
|
1073
|
+
if (column.generated) throw refuse(`"${property}" is computed by SQLite, so nothing sets it`);
|
|
1074
|
+
if (required.has(property)) {
|
|
1075
|
+
throw refuse(`"${property}" must be optional, since an edit sends only what changed`);
|
|
1076
|
+
}
|
|
1077
|
+
if (isSchema(schema) && "default" in schema) {
|
|
1078
|
+
throw refuse(`"${property}" must have no default, or an edit without it would set it`);
|
|
1079
|
+
}
|
|
1080
|
+
columns++;
|
|
1081
|
+
}
|
|
1082
|
+
if (columns === 0) throw refuse("its input takes none of its columns but the primary key");
|
|
1083
|
+
}
|
|
1044
1084
|
function outputSchema(output) {
|
|
1045
1085
|
return z2.toJSONSchema(output, {
|
|
1046
1086
|
io: "output",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_CURRENCY,
|
|
3
3
|
currencyDigits
|
|
4
|
-
} from "./
|
|
4
|
+
} from "./WKI563UT.js";
|
|
5
5
|
|
|
6
6
|
// src/schema.ts
|
|
7
7
|
import { getTableColumns, getTableName, is } from "drizzle-orm";
|
|
@@ -47,7 +47,10 @@ function schemaOf(target) {
|
|
|
47
47
|
}
|
|
48
48
|
function valuesOf(column, reference) {
|
|
49
49
|
const { kind, currency, references } = describeColumn(column.name, column, reference, false);
|
|
50
|
-
const keywords = {
|
|
50
|
+
const keywords = {
|
|
51
|
+
"x-teable-kind": kind,
|
|
52
|
+
"x-teable-column": { table: getTableName(column.table), column: column.name }
|
|
53
|
+
};
|
|
51
54
|
if (currency !== void 0) keywords["x-teable-currency"] = currency;
|
|
52
55
|
if (references !== void 0) keywords["x-teable-references"] = references;
|
|
53
56
|
const meaning = currency === void 0 ? {} : { description: moneyMeaning(currency) };
|
|
@@ -3,9 +3,10 @@ import {
|
|
|
3
3
|
APP_COMPATIBILITY_DATE,
|
|
4
4
|
ASSETS_HEADER,
|
|
5
5
|
DEV_PATHS,
|
|
6
|
+
PAGES_APP_META,
|
|
6
7
|
SESSION_PATH,
|
|
7
8
|
checkAccess
|
|
8
|
-
} from "./
|
|
9
|
+
} from "./WKI563UT.js";
|
|
9
10
|
|
|
10
11
|
// src/build/index.ts
|
|
11
12
|
import { existsSync, readFileSync } from "node:fs";
|
|
@@ -178,6 +179,10 @@ function teable(options = {}) {
|
|
|
178
179
|
server: { proxy: { [APPS_PATH]: proxy, ...remote ? {} : { [SESSION_PATH]: proxy } } }
|
|
179
180
|
};
|
|
180
181
|
},
|
|
182
|
+
/** The pages name the app they are built for: a deploy to another app refuses them. */
|
|
183
|
+
transformIndexHtml() {
|
|
184
|
+
return [{ tag: "meta", attrs: { name: PAGES_APP_META, content: appId }, injectTo: "head" }];
|
|
185
|
+
},
|
|
181
186
|
configureServer(server) {
|
|
182
187
|
if (!workerd && !options.remote) return;
|
|
183
188
|
if (options.remote) {
|
|
@@ -77,6 +77,7 @@ function fileKeyPath(key) {
|
|
|
77
77
|
}
|
|
78
78
|
var DEPLOY_HEADERS = { commit: "X-Teable-Commit", message: "X-Teable-Message" };
|
|
79
79
|
var DEPLOY_PARTS = { server: "server", worker: "worker", pages: "pages" };
|
|
80
|
+
var PAGES_APP_META = "teable-app";
|
|
80
81
|
function checkAccess(caller, access) {
|
|
81
82
|
if (caller.kind === "system") return null;
|
|
82
83
|
if (access === "internal") return "FORBIDDEN";
|
|
@@ -124,6 +125,7 @@ export {
|
|
|
124
125
|
fileKeyPath,
|
|
125
126
|
DEPLOY_HEADERS,
|
|
126
127
|
DEPLOY_PARTS,
|
|
128
|
+
PAGES_APP_META,
|
|
127
129
|
checkAccess,
|
|
128
130
|
admit,
|
|
129
131
|
isMember,
|
package/dist/client.js
CHANGED
package/dist/dev/host.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createApp,
|
|
3
3
|
fail
|
|
4
|
-
} from "./chunks/
|
|
5
|
-
import "./chunks/
|
|
6
|
-
import "./chunks/
|
|
4
|
+
} from "./chunks/APGIRZ24.js";
|
|
5
|
+
import "./chunks/NOOZYN7X.js";
|
|
6
|
+
import "./chunks/WKI563UT.js";
|
|
7
7
|
|
|
8
8
|
// src/index.ts
|
|
9
9
|
import { z } from "zod";
|
package/dist/protocol.d.ts
CHANGED
|
@@ -314,6 +314,32 @@ export type Result<T> = {
|
|
|
314
314
|
ok: false;
|
|
315
315
|
error: AppErrorShape;
|
|
316
316
|
};
|
|
317
|
+
/**
|
|
318
|
+
* What methods' JSON Schemas tell the builder beside `KindKeywords`, so its
|
|
319
|
+
* Data view edits rows in place and starts writes from a row: the column a
|
|
320
|
+
* value is, and the table a write edits. The host passes schemas through and
|
|
321
|
+
* reads neither, so they are not part of the host ↔ app contract above: an
|
|
322
|
+
* app built without them shows its rows read-only, with no row actions.
|
|
323
|
+
*/
|
|
324
|
+
export interface EditKeywords {
|
|
325
|
+
/**
|
|
326
|
+
* On a value of a column (`schemaOf`): that column, by its SQLite names, as
|
|
327
|
+
* `x-teable-references` names the column a reference points at. In an
|
|
328
|
+
* output, the column the value is read from; in an input, the column it
|
|
329
|
+
* names a row by (its table's primary key) or is written to.
|
|
330
|
+
*/
|
|
331
|
+
"x-teable-column": {
|
|
332
|
+
table: string;
|
|
333
|
+
column: string;
|
|
334
|
+
};
|
|
335
|
+
/**
|
|
336
|
+
* On the input of a write that edits one row of a table (`edits` in
|
|
337
|
+
* `app.write`): the table's SQLite name. The input holds the row's primary
|
|
338
|
+
* key, and any of its other columns as optional properties with no
|
|
339
|
+
* default, each under its column's key; the write sets those it is given.
|
|
340
|
+
*/
|
|
341
|
+
"x-teable-edits": string;
|
|
342
|
+
}
|
|
317
343
|
/** The currency of a `money` column that names none. */
|
|
318
344
|
export declare const DEFAULT_CURRENCY = "USD";
|
|
319
345
|
/**
|
|
@@ -450,6 +476,12 @@ export declare const DEPLOY_PARTS: {
|
|
|
450
476
|
readonly worker: "worker";
|
|
451
477
|
readonly pages: "pages";
|
|
452
478
|
};
|
|
479
|
+
/**
|
|
480
|
+
* The `<meta>` name under which an app's built `index.html` names the app it
|
|
481
|
+
* was built for, as `teable()` writes it. A deploy refuses pages built for
|
|
482
|
+
* another app: they would call that app's API, not this one's.
|
|
483
|
+
*/
|
|
484
|
+
export declare const PAGES_APP_META = "teable-app";
|
|
453
485
|
/**
|
|
454
486
|
* `POST {APPS_PATH}/:appId/rollback` with `{ "to": <version> }` deploys that
|
|
455
487
|
* version's bundle again, as a new version. Its answer (201) is a deploy's,
|
package/dist/protocol.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
ERROR_CODES,
|
|
11
11
|
ERROR_STATUS,
|
|
12
12
|
FILE_NAME_HEADER,
|
|
13
|
+
PAGES_APP_META,
|
|
13
14
|
PROTOCOL_VERSION,
|
|
14
15
|
SESSION_PATH,
|
|
15
16
|
SPACE_ROLES,
|
|
@@ -21,7 +22,7 @@ import {
|
|
|
21
22
|
isExposed,
|
|
22
23
|
isMember,
|
|
23
24
|
isPageAccess
|
|
24
|
-
} from "./chunks/
|
|
25
|
+
} from "./chunks/WKI563UT.js";
|
|
25
26
|
export {
|
|
26
27
|
APPS_PATH,
|
|
27
28
|
APP_COMPATIBILITY_DATE,
|
|
@@ -34,6 +35,7 @@ export {
|
|
|
34
35
|
ERROR_CODES,
|
|
35
36
|
ERROR_STATUS,
|
|
36
37
|
FILE_NAME_HEADER,
|
|
38
|
+
PAGES_APP_META,
|
|
37
39
|
PROTOCOL_VERSION,
|
|
38
40
|
SESSION_PATH,
|
|
39
41
|
SPACE_ROLES,
|
package/dist/schema.d.ts
CHANGED
|
@@ -33,10 +33,15 @@ type RowShape<T extends SQLiteTable> = {
|
|
|
33
33
|
* The zod schema of a column's values, for method outputs: what Drizzle reads
|
|
34
34
|
* from the column (null too, unless it is NOT NULL). It carries the column's
|
|
35
35
|
* kind into the JSON Schema callers see (`KindKeywords`), so they tell money
|
|
36
|
-
* from a plain number, and know its currency
|
|
36
|
+
* from a plain number, and know its currency, and names the column
|
|
37
|
+
* (`EditKeywords`), so the builder can edit a row it shows with the write
|
|
38
|
+
* that edits its table. Given a table, its rows. In an input, a table's key
|
|
39
|
+
* names the row a write acts on, and the builder starts the write from that
|
|
40
|
+
* row.
|
|
37
41
|
*
|
|
38
42
|
* output: z.array(schemaOf(skus)),
|
|
39
43
|
* output: z.object({ orders: z.number().int(), revenue: schemaOf(orders.amount) }),
|
|
44
|
+
* input: z.object({ orderId: schemaOf(orders.id) }),
|
|
40
45
|
*/
|
|
41
46
|
export declare function schemaOf<T extends SQLiteTable>(table: T): z.ZodObject<RowShape<T>>;
|
|
42
47
|
export declare function schemaOf<C extends SQLiteColumn>(column: C): z.ZodType<ValueOf<C>, ValueOf<C>>;
|
package/dist/schema.js
CHANGED
package/dist/server/app.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { DurableObject } from "cloudflare:workers";
|
|
2
2
|
import { type DrizzleSqliteDODatabase } from "drizzle-orm/durable-sqlite";
|
|
3
|
+
import type { SQLiteTable } from "drizzle-orm/sqlite-core";
|
|
3
4
|
import { z } from "zod";
|
|
4
5
|
import { type Access, type AppFacet, type AppManifest, type Caller, type Capabilities, type Capability, type PageAccess } from "../protocol.js";
|
|
5
6
|
import { type Migrations } from "./migrations.js";
|
|
6
7
|
type Schema = Record<string, unknown>;
|
|
8
|
+
/** The tables a schema module exports. */
|
|
9
|
+
type TableOf<S extends Schema> = Extract<S[keyof S], SQLiteTable>;
|
|
7
10
|
/** The Drizzle database handed to read and write handlers. */
|
|
8
11
|
export type Database<S extends Schema> = DrizzleSqliteDODatabase<S>;
|
|
9
12
|
export type InputSchema = z.ZodType<unknown, Record<string, unknown>>;
|
|
@@ -63,6 +66,8 @@ export interface WriteMethod<In extends InputSchema, R, A extends Access = Acces
|
|
|
63
66
|
output: OutputSchema | undefined;
|
|
64
67
|
access: A;
|
|
65
68
|
description: string | undefined;
|
|
69
|
+
/** The table one of whose rows it edits, as the builder's grid edits rows (`edits`). */
|
|
70
|
+
edits: SQLiteTable | undefined;
|
|
66
71
|
handler(ctx: WriteContext<Schema, z.output<In>>): R;
|
|
67
72
|
}
|
|
68
73
|
export interface TaskMethod<In extends InputSchema> {
|
|
@@ -111,7 +116,17 @@ export declare function createApp<S extends Schema>(options: {
|
|
|
111
116
|
/** Read data. Synchronous and read-only: a read that writes is rolled back and fails. */
|
|
112
117
|
read<R, In extends InputSchema = typeof emptyInput, A extends Access = "viewer", Out extends OutputSchema | undefined = undefined>(def: Common<In> & MethodOptions<ReadContext<S, z.output<In>>, R, A, Out> & MustBeSync<R>): ReadMethod<In, Given<Out, R>, A>;
|
|
113
118
|
/** Change data. Synchronous and atomic: if it throws, nothing it wrote is kept. */
|
|
114
|
-
write<R, In extends InputSchema = typeof emptyInput, A extends Access = "editor", Out extends OutputSchema | undefined = undefined>(def: Common<In> & MethodOptions<WriteContext<S, z.output<In>>, R, A, Out> & MustBeSync<R>
|
|
119
|
+
write<R, In extends InputSchema = typeof emptyInput, A extends Access = "editor", Out extends OutputSchema | undefined = undefined>(def: Common<In> & MethodOptions<WriteContext<S, z.output<In>>, R, A, Out> & MustBeSync<R> & {
|
|
120
|
+
/**
|
|
121
|
+
* The table one of whose rows this write edits, for a write that
|
|
122
|
+
* sets the columns it is given: then the builder's Data view edits
|
|
123
|
+
* that table's rows in place with it, as a page wires it to the
|
|
124
|
+
* grid. Its input holds the row's primary key, and any of its other
|
|
125
|
+
* columns as optional properties with no default, each under its
|
|
126
|
+
* column's key; `define()` refuses anything else.
|
|
127
|
+
*/
|
|
128
|
+
edits?: TableOf<S>;
|
|
129
|
+
}): WriteMethod<In, Given<Out, R>, A>;
|
|
115
130
|
/** Async work outside transactions: external services, multi-step flows. Retried on failure. */
|
|
116
131
|
task<In extends InputSchema = typeof emptyInput>(def: Common<In> & {
|
|
117
132
|
maxAttempts?: number;
|
package/dist/testing.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
methodName
|
|
3
|
-
} from "./chunks/
|
|
4
|
-
import "./chunks/
|
|
3
|
+
} from "./chunks/APGIRZ24.js";
|
|
4
|
+
import "./chunks/NOOZYN7X.js";
|
|
5
5
|
import {
|
|
6
6
|
MethodError
|
|
7
|
-
} from "./chunks/
|
|
7
|
+
} from "./chunks/A27ZPYPU.js";
|
|
8
8
|
import {
|
|
9
9
|
ERROR_STATUS
|
|
10
|
-
} from "./chunks/
|
|
10
|
+
} from "./chunks/WKI563UT.js";
|
|
11
11
|
|
|
12
12
|
// src/testing.ts
|
|
13
13
|
var OWNER = { kind: "user", userId: "test-owner", role: "owner", via: "api" };
|
package/dist/worker.js
CHANGED