zitejs 0.9.103 → 0.9.104

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.
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCaller = void 0;
4
+ var index_js_1 = require("../caller/index.js");
5
+ Object.defineProperty(exports, "createCaller", { enumerable: true, get: function () { return index_js_1.createCaller; } });
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTableClient = void 0;
4
+ var index_js_1 = require("../runtime/index.js");
5
+ Object.defineProperty(exports, "createTableClient", { enumerable: true, get: function () { return index_js_1.createTableClient; } });
@@ -14,48 +14,73 @@ const AUTH_USERS_TABLE_ID = "zite_user";
14
14
  /**
15
15
  * What a field's value looks like when a record is READ back.
16
16
  *
17
- * `| null` on the nullable ones is load-bearing, not pedantry: every field
18
- * column is created nullable with no default (`recordsTableManager`), and only
19
- * the six text types get their NULL rewritten to `''` on the way out
20
- * (`normalizeEmptyStringFields` keys on `emptyValue === ''`). The product's own
21
- * test asserts `fld_number` and `fld_checkbox` read back as `null`. Typing them
22
- * non-null let `task.estimate.toFixed(2)` compile and throw.
17
+ * **These are deliberately optimistic, and that is load-bearing.** Every column
18
+ * is nullable with no default (`recordsTableManager`) and only the six text
19
+ * types get NULL rewritten to `''`, so the wire really does answer `null` for
20
+ * the rest. They are typed `T | undefined` anyway, matching the pre-monorepo
21
+ * SDK — `| null` appears zero times in its generator.
22
+ *
23
+ * Two things have been tried and both broke apps, so before "fixing" this:
24
+ *
25
+ * 1. **Typing the truth** (`9a44ab3`). 7880 of 7880 audited 1.0 endpoints
26
+ * declare an `outputSchema` written as a mirror of this type with every cell
27
+ * `.optional()`, and `createEndpoint` constrains `execute`'s return against
28
+ * it. `| null` fails the app's typecheck on lines nobody edited — 52 of 144
29
+ * apps, ~2,100 sites.
30
+ * 2. **Making the runtime emit `undefined`** so the type becomes true. The
31
+ * idiom that breaks is `.filter(m => m.homeScore !== null)`, which silently
32
+ * becomes a no-op and lets empty rows through: wrong results, no error.
33
+ * 10 of 328 exported apps do exactly this.
34
+ *
35
+ * TODO: make these accurate in a deliberate zitejs major, once apps are
36
+ * migrated. Each app pins its own version, so the change only reaches apps that
37
+ * opt in by bumping — which is the only way to do it without breaking (2).
38
+ *
39
+ * Writes are unaffected — `null` is how you clear a cell. See
40
+ * `FIELD_INPUT_TYPE_MAP` and `withNull`.
23
41
  */
24
42
  const FIELD_TYPE_MAP = {
25
- // Text: NULL is rewritten to '' on read, so these genuinely can't be null.
43
+ // Text: NULL is rewritten to '' on read, so these are never even absent.
26
44
  single_line_text: "string",
27
45
  long_text: "string",
28
46
  rich_text: "string",
29
47
  email: "string",
30
48
  url: "string",
31
49
  phone_number: "string",
32
- number: "number | null",
33
- currency: "number | null",
34
- percent: "number | null",
35
- rating: "number | null",
50
+ number: "number",
51
+ currency: "number",
52
+ percent: "number",
53
+ rating: "number",
36
54
  // DECIMAL seconds, unlike Airtable's, which is formatted to "HH:mm:ss".
37
- duration: "number | null",
38
- checkbox: "boolean | null",
39
- single_select: "string | null",
40
- multiple_select: "string[] | null",
41
- date: "string | null",
42
- datetime: "string | null",
43
- attachments: "ZiteAttachment[] | null",
55
+ // 1.0 typed this `string`, which was simply wrong — base-runner groups it
56
+ // with the numeric types — so it stays a number rather than reverting.
57
+ duration: "number",
58
+ checkbox: "boolean",
59
+ single_select: "string",
60
+ multiple_select: "string[]",
61
+ date: "string",
62
+ datetime: "string",
63
+ attachments: "ZiteAttachment[]",
44
64
  // `string | string[]`, matching the pre-monorepo type. base-runner does force
45
65
  // an array on read today, but 1.0 code is written with `typeof x === 'string'`
46
66
  // guards — narrowing to `string[]` turns those branches into `never` and
47
67
  // fails the app's typecheck for no gain.
48
68
  linked_record: "string | string[]",
49
69
  user: "string | string[]",
50
- lookup: "unknown",
51
- rollup: "unknown",
70
+ // `any`, not `unknown`, and deliberately: these are values the platform
71
+ // cannot type — a lookup is whatever the far side holds. 1.0 said `any`, and
72
+ // `unknown` buys nothing because there is no narrowing an app could have
73
+ // written in advance: `sum + (x || 0)` is a TS2365 on `unknown`, and the
74
+ // guarded spellings already narrowed fine under `any`.
75
+ lookup: "any",
76
+ rollup: "any",
52
77
  autonumber: "number",
53
78
  // JSONB change metadata (`{ type: "PublicAPI", apiKeyId: 3 }`), not a string.
54
- source: "unknown",
55
- formula: "unknown",
79
+ source: "any",
80
+ formula: "any",
56
81
  created_at: "string",
57
82
  updated_at: "string",
58
- updated_by: "string | null",
83
+ updated_by: "string",
59
84
  };
60
85
  /**
61
86
  * Field types whose WRITE shape differs from their read shape — the API accepts
@@ -214,9 +239,9 @@ function tsTypeForSchemaField(def, variant = "read") {
214
239
  .map((o) => `"${o.label.replace(/"/g, '\\"')}"`)
215
240
  .join(" | ");
216
241
  const union = `${literals} | string`;
217
- const read = def.type === "multiple_select"
218
- ? `(${union})[] | null`
219
- : `${union} | null`;
242
+ // No `| null` on the read side — see FIELD_TYPE_MAP. The write side keeps
243
+ // it below, since null is how a select cell is cleared.
244
+ const read = def.type === "multiple_select" ? `(${union})[]` : union;
220
245
  if (variant === "write") {
221
246
  return def.type === "multiple_select"
222
247
  ? `${union} | (${union})[] | null`
@@ -0,0 +1,2 @@
1
+ export { createCaller } from '../caller/index.js';
2
+ export type { EndpointConfig } from '../caller/index.js';
@@ -0,0 +1 @@
1
+ export { createCaller } from '../caller/index.js';
package/dist/esm/cli.js CHANGED
File without changes
@@ -0,0 +1,2 @@
1
+ export { createTableClient } from '../runtime/index.js';
2
+ export type { TableClient } from '../runtime/index.js';
@@ -0,0 +1 @@
1
+ export { createTableClient } from '../runtime/index.js';
@@ -3,48 +3,73 @@ const AUTH_USERS_TABLE_ID = "zite_user";
3
3
  /**
4
4
  * What a field's value looks like when a record is READ back.
5
5
  *
6
- * `| null` on the nullable ones is load-bearing, not pedantry: every field
7
- * column is created nullable with no default (`recordsTableManager`), and only
8
- * the six text types get their NULL rewritten to `''` on the way out
9
- * (`normalizeEmptyStringFields` keys on `emptyValue === ''`). The product's own
10
- * test asserts `fld_number` and `fld_checkbox` read back as `null`. Typing them
11
- * non-null let `task.estimate.toFixed(2)` compile and throw.
6
+ * **These are deliberately optimistic, and that is load-bearing.** Every column
7
+ * is nullable with no default (`recordsTableManager`) and only the six text
8
+ * types get NULL rewritten to `''`, so the wire really does answer `null` for
9
+ * the rest. They are typed `T | undefined` anyway, matching the pre-monorepo
10
+ * SDK — `| null` appears zero times in its generator.
11
+ *
12
+ * Two things have been tried and both broke apps, so before "fixing" this:
13
+ *
14
+ * 1. **Typing the truth** (`9a44ab3`). 7880 of 7880 audited 1.0 endpoints
15
+ * declare an `outputSchema` written as a mirror of this type with every cell
16
+ * `.optional()`, and `createEndpoint` constrains `execute`'s return against
17
+ * it. `| null` fails the app's typecheck on lines nobody edited — 52 of 144
18
+ * apps, ~2,100 sites.
19
+ * 2. **Making the runtime emit `undefined`** so the type becomes true. The
20
+ * idiom that breaks is `.filter(m => m.homeScore !== null)`, which silently
21
+ * becomes a no-op and lets empty rows through: wrong results, no error.
22
+ * 10 of 328 exported apps do exactly this.
23
+ *
24
+ * TODO: make these accurate in a deliberate zitejs major, once apps are
25
+ * migrated. Each app pins its own version, so the change only reaches apps that
26
+ * opt in by bumping — which is the only way to do it without breaking (2).
27
+ *
28
+ * Writes are unaffected — `null` is how you clear a cell. See
29
+ * `FIELD_INPUT_TYPE_MAP` and `withNull`.
12
30
  */
13
31
  const FIELD_TYPE_MAP = {
14
- // Text: NULL is rewritten to '' on read, so these genuinely can't be null.
32
+ // Text: NULL is rewritten to '' on read, so these are never even absent.
15
33
  single_line_text: "string",
16
34
  long_text: "string",
17
35
  rich_text: "string",
18
36
  email: "string",
19
37
  url: "string",
20
38
  phone_number: "string",
21
- number: "number | null",
22
- currency: "number | null",
23
- percent: "number | null",
24
- rating: "number | null",
39
+ number: "number",
40
+ currency: "number",
41
+ percent: "number",
42
+ rating: "number",
25
43
  // DECIMAL seconds, unlike Airtable's, which is formatted to "HH:mm:ss".
26
- duration: "number | null",
27
- checkbox: "boolean | null",
28
- single_select: "string | null",
29
- multiple_select: "string[] | null",
30
- date: "string | null",
31
- datetime: "string | null",
32
- attachments: "ZiteAttachment[] | null",
44
+ // 1.0 typed this `string`, which was simply wrong — base-runner groups it
45
+ // with the numeric types — so it stays a number rather than reverting.
46
+ duration: "number",
47
+ checkbox: "boolean",
48
+ single_select: "string",
49
+ multiple_select: "string[]",
50
+ date: "string",
51
+ datetime: "string",
52
+ attachments: "ZiteAttachment[]",
33
53
  // `string | string[]`, matching the pre-monorepo type. base-runner does force
34
54
  // an array on read today, but 1.0 code is written with `typeof x === 'string'`
35
55
  // guards — narrowing to `string[]` turns those branches into `never` and
36
56
  // fails the app's typecheck for no gain.
37
57
  linked_record: "string | string[]",
38
58
  user: "string | string[]",
39
- lookup: "unknown",
40
- rollup: "unknown",
59
+ // `any`, not `unknown`, and deliberately: these are values the platform
60
+ // cannot type — a lookup is whatever the far side holds. 1.0 said `any`, and
61
+ // `unknown` buys nothing because there is no narrowing an app could have
62
+ // written in advance: `sum + (x || 0)` is a TS2365 on `unknown`, and the
63
+ // guarded spellings already narrowed fine under `any`.
64
+ lookup: "any",
65
+ rollup: "any",
41
66
  autonumber: "number",
42
67
  // JSONB change metadata (`{ type: "PublicAPI", apiKeyId: 3 }`), not a string.
43
- source: "unknown",
44
- formula: "unknown",
68
+ source: "any",
69
+ formula: "any",
45
70
  created_at: "string",
46
71
  updated_at: "string",
47
- updated_by: "string | null",
72
+ updated_by: "string",
48
73
  };
49
74
  /**
50
75
  * Field types whose WRITE shape differs from their read shape — the API accepts
@@ -203,9 +228,9 @@ function tsTypeForSchemaField(def, variant = "read") {
203
228
  .map((o) => `"${o.label.replace(/"/g, '\\"')}"`)
204
229
  .join(" | ");
205
230
  const union = `${literals} | string`;
206
- const read = def.type === "multiple_select"
207
- ? `(${union})[] | null`
208
- : `${union} | null`;
231
+ // No `| null` on the read side — see FIELD_TYPE_MAP. The write side keeps
232
+ // it below, since null is how a select cell is cleared.
233
+ const read = def.type === "multiple_select" ? `(${union})[]` : union;
209
234
  if (variant === "write") {
210
235
  return def.type === "multiple_select"
211
236
  ? `${union} | (${union})[] | null`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.9.103",
3
+ "version": "0.9.104",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",