zitejs 0.10.0-start.19 → 0.10.0-start.20

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.
Files changed (42) hide show
  1. package/dist/cjs/check/index.js +21 -6
  2. package/dist/cjs/check/start/routeTree.d.ts +1 -0
  3. package/dist/cjs/check/start/routeTree.js +3 -3
  4. package/dist/cjs/check/start/sourceRules.js +309 -47
  5. package/dist/cjs/runtime/index.d.ts +2 -2
  6. package/dist/cjs/start/entries.d.ts +2 -1
  7. package/dist/cjs/start/entries.js +2 -1
  8. package/dist/esm/check/index.js +21 -6
  9. package/dist/esm/check/start/routeTree.d.ts +1 -0
  10. package/dist/esm/check/start/routeTree.js +1 -1
  11. package/dist/esm/check/start/sourceRules.js +309 -47
  12. package/dist/esm/runtime/index.d.ts +2 -2
  13. package/dist/esm/start/airtable/dispatch.js +23 -5
  14. package/dist/esm/start/airtable/formulas.d.ts +1 -0
  15. package/dist/esm/start/airtable/formulas.js +43 -20
  16. package/dist/esm/start/data/transformations.d.ts +0 -31
  17. package/dist/esm/start/data/transformations.js +0 -56
  18. package/dist/esm/start/describe.d.ts +2 -1
  19. package/dist/esm/start/describe.js +13 -17
  20. package/dist/esm/start/entries.d.ts +2 -1
  21. package/dist/esm/start/entries.js +2 -1
  22. package/dist/esm/start/errors.d.ts +12 -0
  23. package/dist/esm/start/errors.js +42 -0
  24. package/dist/esm/start/index.d.ts +6 -0
  25. package/dist/esm/start/index.js +16 -8
  26. package/dist/esm/start/instance.d.ts +1 -1
  27. package/dist/esm/start/instance.js +35 -8
  28. package/dist/esm/start/outbound.js +1 -13
  29. package/dist/esm/start/registrationHash.d.ts +22 -0
  30. package/dist/esm/start/registrationHash.js +470 -0
  31. package/dist/esm/start/router.js +41 -3
  32. package/dist/esm/start/server.d.ts +6 -12
  33. package/dist/esm/start/server.js +41 -12
  34. package/dist/esm/start/types.d.ts +2 -11
  35. package/dist/esm/start/version.d.ts +1 -1
  36. package/dist/esm/start/version.js +1 -1
  37. package/dist/esm/start/vite.js +51 -7
  38. package/dist/esm/start/worker.d.ts +1 -6
  39. package/dist/esm/start/worker.js +1 -9
  40. package/dist/esm/start/workflow.d.ts +8 -1
  41. package/dist/esm/start/workflow.test-d.js +7 -0
  42. package/package.json +1 -1
@@ -4,7 +4,8 @@ export declare const START_INSTANCE_ENTRY = ".zite/start.ts";
4
4
  export type StartTarget = "cloudflare" | "node";
5
5
  /**
6
6
  * The server entry every Start app builds with. Platform-owned: regenerated,
7
- * never edited. On Workers it's an entrypoint the host can also call over RPC.
7
+ * never edited. On Workers it's an entrypoint, so the host can hand each fetch
8
+ * its props; on Node, a plain fetch handler.
8
9
  */
9
10
  export declare const renderStartServerEntry: (target?: StartTarget) => string;
10
11
  /** The start instance: the platform's middleware, then the app's own `src/start.ts` when it has one. */
@@ -11,7 +11,8 @@ exports.START_INSTANCE_ENTRY = ".zite/start.ts";
11
11
  const APP_START_FILES = ["src/start.ts", "src/start.tsx"];
12
12
  /**
13
13
  * The server entry every Start app builds with. Platform-owned: regenerated,
14
- * never edited. On Workers it's an entrypoint the host can also call over RPC.
14
+ * never edited. On Workers it's an entrypoint, so the host can hand each fetch
15
+ * its props; on Node, a plain fetch handler.
15
16
  */
16
17
  const renderStartServerEntry = (target = "cloudflare") => target === "cloudflare"
17
18
  ? `// Generated by zitejs for TanStack Start apps. The platform owns this file.
@@ -123,6 +123,12 @@ const isInternalApp = (appPath) => {
123
123
  return false;
124
124
  }
125
125
  };
126
+ /**
127
+ * tsgo's Node launcher rethrows its compiler's kill: an exit of 1 with Node's
128
+ * `Error: Command failed: …/tsgo …` dump, `signal: 'SIGKILL'` included. Matched
129
+ * at line start, since `--pretty` quotes source lines that could hold either.
130
+ */
131
+ const launcherKill = (output) => /^Error: Command failed: \S*tsgo\b/m.test(output) ? output.match(/\bsignal: '(SIG[A-Z]+)'/)?.[1] : undefined;
126
132
  /**
127
133
  * Runs a tool to its answer, or says why it gave none: a kill (a signal, or an
128
134
  * exit of 128 and up with nothing printed) is a sandbox limit, not the app's.
@@ -132,8 +138,9 @@ export function runTool(file, args, cwd) {
132
138
  const output = (result.stderr ?? '') + (result.stdout ?? '');
133
139
  if (result.error)
134
140
  return { ok: false, unchecked: `couldn't run: ${result.error.message}` };
135
- if (result.signal)
136
- return { ok: false, unchecked: `killed by ${result.signal}` };
141
+ const signal = result.signal ?? (result.status !== 0 ? launcherKill(output) : undefined);
142
+ if (signal)
143
+ return { ok: false, unchecked: `killed by ${signal}` };
137
144
  if (result.status !== null && result.status >= 128 && !output.trim()) {
138
145
  return { ok: false, unchecked: `exited ${result.status} with no output` };
139
146
  }
@@ -171,10 +178,18 @@ async function checkStartApp(reporter, app, appPath) {
171
178
  }
172
179
  const { sourceProblems } = await import('./start/sourceRules.js');
173
180
  const root = sourceRootOf(appPath);
174
- const hints = sourceProblems(readAppSources(appPath), {
175
- internal: isInternalApp(appPath),
176
- kind: root && { apps: 'app', automations: 'automation' }[root],
177
- });
181
+ let hints;
182
+ try {
183
+ hints = sourceProblems(readAppSources(appPath), {
184
+ internal: isInternalApp(appPath),
185
+ kind: root && { apps: 'app', automations: 'automation' }[root],
186
+ });
187
+ }
188
+ catch (err) {
189
+ // A rule's own bug is nothing for the app to fix, and mustn't cost the report the steps before it.
190
+ reporter.step(app, 'source', { ok: false, unchecked: `source rules failed: ${err instanceof Error ? err.message : String(err)}` });
191
+ return;
192
+ }
178
193
  reporter.step(app, 'source', { ok: !hints.some(p => p.severity === 'error') });
179
194
  reporter.problems(app, hints);
180
195
  }
@@ -1,3 +1,4 @@
1
+ export declare const ENTRY_EXTENSIONS: string[];
1
2
  /** Start's footer (start-plugin-core route-tree-footer), which types the router and start instance for `@tanstack/react-start`. */
2
3
  export declare const startRouteTreeFooter: (generatedRouteTree: string, routerFile: string, startFile: string | undefined) => string[];
3
4
  /**
@@ -6,7 +6,7 @@ import path from "node:path";
6
6
  import { pathToFileURL } from "node:url";
7
7
  import { START_INSTANCE_ENTRY } from "../../start/entries.js";
8
8
  // As Start resolves its entries (start-plugin-core resolve-entries).
9
- const ENTRY_EXTENSIONS = [".ts", ".js", ".mts", ".mjs", ".tsx", ".jsx"];
9
+ export const ENTRY_EXTENSIONS = [".ts", ".js", ".mts", ".mjs", ".tsx", ".jsx"];
10
10
  const resolveEntry = (srcDirectory, name) => {
11
11
  const base = path.resolve(srcDirectory, name);
12
12
  if (existsSync(base) && statSync(base).isFile())
@@ -3,6 +3,7 @@
3
3
  // and only where the code shows it for sure, what that build would refuse. A
4
4
  // file that doesn't parse is skipped; the typecheck reports it.
5
5
  import { parse } from "@babel/parser";
6
+ import { ENTRY_EXTENSIONS } from "./routeTree.js";
6
7
  const isNode = (value) => typeof value === "object" && value !== null && typeof value.type === "string";
7
8
  const SKIP_KEYS = new Set(["loc", "start", "end", "extra", "leadingComments", "trailingComments", "innerComments", "range"]);
8
9
  const walk = (node, visit, ancestors = []) => {
@@ -92,6 +93,80 @@ const isTopLevelDeclarator = (ancestors) => {
92
93
  return false;
93
94
  return outer?.type === "Program" || (outer?.type === "ExportNamedDeclaration" && program?.type === "Program");
94
95
  };
96
+ // TypeScript nodes that hold runtime code; under any other TS node a name is a type.
97
+ const VALUE_TS_NODES = new Set([
98
+ "TSAsExpression",
99
+ "TSSatisfiesExpression",
100
+ "TSNonNullExpression",
101
+ "TSInstantiationExpression",
102
+ "TSTypeAssertion",
103
+ "TSEnumDeclaration",
104
+ "TSEnumBody",
105
+ "TSEnumMember",
106
+ "TSModuleDeclaration",
107
+ "TSModuleBlock",
108
+ "TSExportAssignment",
109
+ "TSParameterProperty",
110
+ ]);
111
+ const isPropertyName = (node, parent) => !!parent &&
112
+ !parent.computed &&
113
+ (parent.key === node ||
114
+ (parent.property === node && ["MemberExpression", "OptionalMemberExpression", "JSXMemberExpression"].includes(parent.type)) ||
115
+ (parent.type === "ExportSpecifier" && parent.exported === node) ||
116
+ parent.type === "JSXAttribute");
117
+ // `export type { T }` and `export { type T }`, which the build erases with the import.
118
+ const isTypeExport = (ancestors) => {
119
+ const [specifier, declaration] = [ancestors.at(-1), ancestors.at(-2)];
120
+ return specifier?.type === "ExportSpecifier" && (specifier.exportKind === "type" || declaration?.exportKind === "type");
121
+ };
122
+ /** Each name the file reads as a value, outside its imports. */
123
+ const forEachValueName = (program, visit) => {
124
+ for (const statement of program.body) {
125
+ if (statement.type === "ImportDeclaration")
126
+ continue;
127
+ walk(statement, (node, ancestors) => {
128
+ if (node.type !== "Identifier" && node.type !== "JSXIdentifier")
129
+ return;
130
+ if (isPropertyName(node, ancestors.at(-1)) || isTypeExport(ancestors))
131
+ return;
132
+ if (ancestors.some((a) => a.type.startsWith("TS") && !VALUE_TS_NODES.has(a.type)))
133
+ return;
134
+ visit(node, ancestors);
135
+ });
136
+ }
137
+ };
138
+ const valueNames = (program) => {
139
+ const names = new Set();
140
+ forEachValueName(program, (node) => names.add(node.name));
141
+ return names;
142
+ };
143
+ /** What a file reads off a namespace import, `ns.name` or `const { name } = ns`; "all" when it uses it any other way. */
144
+ const namespaceReads = (file, namespace) => {
145
+ const names = [];
146
+ let all = false;
147
+ forEachValueName(file.program, (node, ancestors) => {
148
+ if (node.name !== namespace)
149
+ return;
150
+ const parent = ancestors.at(-1);
151
+ const pattern = parent?.type === "VariableDeclarator" && parent.init === node ? parent.id : undefined;
152
+ if (parent && ["MemberExpression", "OptionalMemberExpression", "JSXMemberExpression"].includes(parent.type) && parent.object === node && !parent.computed) {
153
+ names.push(parent.property.name);
154
+ }
155
+ else if (pattern?.type === "ObjectPattern") {
156
+ for (const property of pattern.properties) {
157
+ const key = property.type === "ObjectProperty" && !property.computed ? nameOf(property.key) : undefined;
158
+ if (key)
159
+ names.push(key);
160
+ else
161
+ all = true;
162
+ }
163
+ }
164
+ else {
165
+ all = true;
166
+ }
167
+ });
168
+ return all ? "all" : names;
169
+ };
95
170
  const parseFile = (path, code) => {
96
171
  try {
97
172
  const ast = parse(code, {
@@ -108,35 +183,79 @@ const parseFile = (path, code) => {
108
183
  const local = nameOf(specifier.local);
109
184
  if (!local)
110
185
  continue;
111
- const imported = specifier.type === "ImportSpecifier" ? (nameOf(specifier.imported) ?? local) : "default";
186
+ const imported = specifier.type === "ImportSpecifier"
187
+ ? (nameOf(specifier.imported) ?? local)
188
+ : specifier.type === "ImportNamespaceSpecifier"
189
+ ? "*"
190
+ : "default";
112
191
  imports.set(local, { source, imported });
113
192
  }
114
193
  }
115
- return { path, program: ast.program, imports };
194
+ return { path, program: ast.program, imports, values: valueNames(ast.program) };
116
195
  }
117
196
  catch {
118
197
  return undefined;
119
198
  }
120
199
  };
121
200
  const FACTORIES = ["signedInFn", "publicFn", "createServerFn"];
201
+ /** The names a file declares at the top level, or re-exports with `export … from`. */
202
+ const declaredNames = (file) => {
203
+ const names = new Set();
204
+ for (const statement of file.program.body) {
205
+ const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
206
+ if (declaration?.type === "VariableDeclaration") {
207
+ for (const declarator of declaration.declarations)
208
+ names.add(nameOf(declarator.id) ?? "");
209
+ }
210
+ if (statement.type === "ExportNamedDeclaration" && statement.source) {
211
+ for (const specifier of statement.specifiers)
212
+ names.add(nameOf(specifier.exported) ?? "");
213
+ }
214
+ }
215
+ return names;
216
+ };
122
217
  /**
123
- * The names a server function can start from, app-wide, each with the factory
124
- * it comes from: zitejs's, TanStack's raw one, and the app's own built from them
125
- * (`export const managerFn = signedInFn.middleware([role("manager")])`).
218
+ * The names a server function can start from, each with the factory it comes
219
+ * from: zitejs's, TanStack's raw one, and the app's own built from them
220
+ * (`export const managerFn = signedInFn.middleware([role("manager")])`). A name
221
+ * is the file's own, or the one its import names in the app file declaring it;
222
+ * only a name no app file is known to declare (a factory, a name behind
223
+ * `export *`) is looked up app-wide.
126
224
  */
127
- const factoryNames = (files) => {
128
- const names = new Map(FACTORIES.map((factory) => [factory, factory]));
225
+ const factoryNames = (files, paths) => {
226
+ const byName = new Map(FACTORIES.map((factory) => [factory, { factory, method: false }]));
227
+ const declared = new Map(files.map((file) => [file.path, declaredNames(file)]));
228
+ const byFile = new Map(files.map((file) => [file.path, new Map()]));
229
+ const exportedBy = (from, source, name) => {
230
+ const target = resolveImport(from, source, paths);
231
+ return target && declared.get(target).has(name) ? byFile.get(target).get(name) : byName.get(name);
232
+ };
233
+ const builderOf = (file, name) => {
234
+ if (!name)
235
+ return undefined;
236
+ if (declared.get(file.path).has(name))
237
+ return byFile.get(file.path).get(name);
238
+ const imported = file.imports.get(name);
239
+ return imported ? exportedBy(file.path, imported.source, imported.imported) : byName.get(name);
240
+ };
241
+ const add = (file, name, builder) => {
242
+ byFile.get(file.path).set(name, builder);
243
+ if (!byName.has(name))
244
+ byName.set(name, builder);
245
+ };
129
246
  for (let changed = true; changed;) {
130
247
  changed = false;
131
248
  for (const file of files) {
132
- const factoryOf = (local) => names.get(file.imports.get(local)?.imported ?? local);
249
+ const own = byFile.get(file.path);
133
250
  for (const statement of file.program.body) {
134
251
  if (statement.type === "ExportNamedDeclaration" && statement.source) {
135
252
  for (const specifier of statement.specifiers) {
136
253
  const exported = nameOf(specifier.exported);
137
- const factory = names.get(nameOf(specifier.local) ?? "");
138
- if (exported && factory && !names.has(exported)) {
139
- names.set(exported, factory);
254
+ if (!exported || own.has(exported))
255
+ continue;
256
+ const builder = exportedBy(file.path, statement.source.value, nameOf(specifier.local) ?? "");
257
+ if (builder) {
258
+ add(file, exported, builder);
140
259
  changed = true;
141
260
  }
142
261
  }
@@ -147,20 +266,88 @@ const factoryNames = (files) => {
147
266
  for (const declarator of declaration.declarations) {
148
267
  const name = nameOf(declarator.id);
149
268
  const init = declarator.init;
150
- if (!name || !init || names.has(name) || isHandlerCall(unwrap(init)))
269
+ if (!name || !init || own.has(name) || isHandlerCall(unwrap(init)))
151
270
  continue;
152
- const { root } = chainOf(init);
153
- const factory = root && factoryOf(root);
154
- if (factory) {
155
- names.set(name, factory);
271
+ const { root, calls } = chainOf(init);
272
+ const parent = builderOf(file, root);
273
+ if (parent) {
274
+ add(file, name, { factory: parent.factory, method: parent.method || hasMethodOption(calls) });
156
275
  changed = true;
157
276
  }
158
277
  }
159
278
  }
160
279
  }
161
280
  }
281
+ return builderOf;
282
+ };
283
+ /** A file's server functions: its top-level consts that are a factory's `.handler(…)`. */
284
+ const serverFnNames = (file, factories) => {
285
+ const names = new Set();
286
+ for (const statement of file.program.body) {
287
+ const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
288
+ if (declaration?.type !== "VariableDeclaration")
289
+ continue;
290
+ for (const declarator of declaration.declarations) {
291
+ const name = nameOf(declarator.id);
292
+ const init = declarator.init ? unwrap(declarator.init) : undefined;
293
+ const root = init && isHandlerCall(init) ? chainOf(init).root : undefined;
294
+ if (name && factories(file, root))
295
+ names.add(name);
296
+ }
297
+ }
162
298
  return names;
163
299
  };
300
+ /** The server functions a module exports, by exported name, followed through its re-exports. */
301
+ const exportedServerFns = (files, paths, serverFns) => {
302
+ const byPath = new Map(files.map((file) => [file.path, file]));
303
+ const found = new Map();
304
+ const exportsOf = (path) => {
305
+ const known = found.get(path);
306
+ if (known)
307
+ return known;
308
+ const names = new Set();
309
+ found.set(path, names);
310
+ const file = byPath.get(path);
311
+ const local = serverFns.get(path);
312
+ const exportsAt = (source) => {
313
+ const target = resolveImport(path, source, paths);
314
+ return target ? exportsOf(target) : new Set();
315
+ };
316
+ for (const statement of file.program.body) {
317
+ if (statement.exportKind === "type")
318
+ continue;
319
+ if (statement.type === "ExportAllDeclaration") {
320
+ for (const name of exportsAt(statement.source.value))
321
+ if (name !== "default")
322
+ names.add(name);
323
+ }
324
+ if (statement.type !== "ExportNamedDeclaration")
325
+ continue;
326
+ const declaration = statement.declaration;
327
+ if (declaration?.type === "VariableDeclaration") {
328
+ for (const declarator of declaration.declarations) {
329
+ const name = nameOf(declarator.id);
330
+ if (name && local.has(name))
331
+ names.add(name);
332
+ }
333
+ }
334
+ const reexported = statement.source ? exportsAt(statement.source.value) : undefined;
335
+ for (const specifier of statement.specifiers) {
336
+ if (specifier.type !== "ExportSpecifier" || specifier.exportKind === "type")
337
+ continue;
338
+ const name = nameOf(specifier.local) ?? "";
339
+ const imported = file.imports.get(name);
340
+ const serverFn = reexported
341
+ ? reexported.has(name)
342
+ : local.has(name) || (!!imported && exportsAt(imported.source).has(imported.imported));
343
+ if (serverFn)
344
+ names.add(nameOf(specifier.exported) ?? name);
345
+ }
346
+ }
347
+ return names;
348
+ };
349
+ return exportsOf;
350
+ };
164
351
  const OWNER_INPUTS = ["userId", "ownerId"];
165
352
  /** An owner id a function's validator takes as input: `.validator(z.object({ userId: … }))`. */
166
353
  const ownerInput = (calls) => {
@@ -187,17 +374,53 @@ const callsCreateWorkflow = (program) => {
187
374
  return found;
188
375
  };
189
376
  const isServerReachable = (path, callsWorkflow) => /\.(functions|server)\.tsx?$/.test(path) || path.startsWith("src/routes/api/") || path === "src/start.ts" || callsWorkflow;
190
- /** The names an import brings in as values; types are erased, so they never reach the runtime. */
191
- const valueImports = (statement) => {
377
+ /**
378
+ * Whether an imported name survives to the build's resolver. In a TypeScript
379
+ * file, the transform drops a name the file reads only as a type, or not at all,
380
+ * written with `type` or not; a .js or .jsx file keeps every import.
381
+ */
382
+ const keepsImport = (file, local) => !/\.[cm]?tsx?$/.test(file.path) || file.values.has(local);
383
+ /** The names an import brings in as values. */
384
+ const valueImports = (file, statement) => {
192
385
  if (statement.importKind === "type")
193
386
  return [];
194
- const specifiers = statement.specifiers.filter((s) => s.importKind !== "type");
387
+ const specifiers = statement.specifiers.filter((s) => s.importKind !== "type" && keepsImport(file, nameOf(s.local) ?? ""));
195
388
  if (statement.specifiers.length === 0)
196
389
  return "all";
197
390
  if (specifiers.some((s) => s.type !== "ImportSpecifier"))
198
391
  return "all";
199
392
  return specifiers.map((s) => nameOf(s.imported) ?? "");
200
393
  };
394
+ /** The names an import reads as values, by the names its module exports them under; "all" when it can't tell. */
395
+ const importedReads = (file, statement) => {
396
+ if (statement.importKind === "type")
397
+ return [];
398
+ const names = [];
399
+ for (const specifier of statement.specifiers) {
400
+ const local = nameOf(specifier.local) ?? "";
401
+ if (specifier.importKind === "type" || !file.values.has(local))
402
+ continue;
403
+ if (specifier.type === "ImportSpecifier")
404
+ names.push(nameOf(specifier.imported) ?? local);
405
+ if (specifier.type === "ImportNamespaceSpecifier") {
406
+ const reads = namespaceReads(file, local);
407
+ if (reads === "all")
408
+ return "all";
409
+ names.push(...reads);
410
+ }
411
+ }
412
+ return names;
413
+ };
414
+ /** The names an `export … from` passes on as values; undefined for any other statement. */
415
+ const valueReexports = (statement) => {
416
+ if ((statement.type !== "ExportNamedDeclaration" && statement.type !== "ExportAllDeclaration") || !statement.source)
417
+ return undefined;
418
+ if (statement.exportKind === "type")
419
+ return [];
420
+ if (statement.type === "ExportAllDeclaration")
421
+ return "all";
422
+ return statement.specifiers.filter((s) => s.exportKind !== "type").map((s) => nameOf(s.exported) ?? "");
423
+ };
201
424
  const MUTATING_METHODS = new Set(["set", "add", "push", "unshift", "splice", "delete", "clear"]);
202
425
  const isContainer = (init) => !!init &&
203
426
  ((init.type === "NewExpression" && ["Map", "Set"].includes(nameOf(init.callee) ?? "")) ||
@@ -328,9 +551,12 @@ const fileRoutes = (files) => files.flatMap((file) => {
328
551
  return found;
329
552
  });
330
553
  const segments = (id) => id.split("/").filter(Boolean);
554
+ // An index route ('/api/') sits beside its siblings, as a child of the route at its path ('/api').
331
555
  const isAncestor = (ancestor, id) => {
556
+ if (ancestor.endsWith("/"))
557
+ return false;
332
558
  const outer = segments(ancestor);
333
- const inner = segments(id);
559
+ const inner = id.endsWith("/") ? [...segments(id), ""] : segments(id);
334
560
  return outer.length < inner.length && outer.every((segment, i) => segment === inner[i]);
335
561
  };
336
562
  /** As TanStack shows a route's path: no pathless layouts or groups. */
@@ -442,6 +668,16 @@ const workflowProblems = (files, kind) => {
442
668
  const trigger = config?.type === "ObjectExpression" ? readProperty(file, config, "trigger") : undefined;
443
669
  if (trigger?.type !== "ObjectExpression")
444
670
  return;
671
+ if (["table", "form"].some((key) => propertyNamed(trigger, key))) {
672
+ problems.push({
673
+ rule: "trigger-unsupported",
674
+ severity: "error",
675
+ file: file.path,
676
+ ...(lineOf(node) && { line: lineOf(node) }),
677
+ message: `automation ${id}: a Start automation can't take a database or form trigger yet`,
678
+ });
679
+ return;
680
+ }
445
681
  if (["every", "events", "subscribe"].some((key) => readProperty(file, trigger, key) !== undefined))
446
682
  return;
447
683
  problems.push({
@@ -529,6 +765,8 @@ const workflowProblems = (files, kind) => {
529
765
  const SERVER_ONLY_IMPORTS = [/^zitejs\/db$/, /^zitejs\/integrations(\/|$)/, /^zitejs\/email$/, /(^|\/)\.zite\/db(\.ts)?$/, /(^|\/)\.zite\/integrations(\/|$)/];
530
766
  const isServerOnlyFile = (path) => /\.server(\.[^/]*)?$/.test(path.split("/").pop() ?? "");
531
767
  const SOURCE_EXTENSIONS = ["", ".ts", ".tsx", ".js", ".jsx", ".mts", ".mjs", "/index.ts", "/index.tsx", "/index.js"];
768
+ // As TypeScript and Vite read a .js specifier: the TypeScript file it compiles from.
769
+ const TS_FOR_JS = { ".js": [".ts", ".tsx"], ".jsx": [".tsx"], ".mjs": [".mts"], ".cjs": [".cts"] };
532
770
  /** The app file an import names, by relative path or the `~/` and `@/` aliases for src/. */
533
771
  const resolveImport = (from, source, paths) => {
534
772
  const base = /^[~@]\//.test(source)
@@ -536,7 +774,11 @@ const resolveImport = (from, source, paths) => {
536
774
  : source.startsWith(".")
537
775
  ? posixJoin(from.split("/").slice(0, -1).join("/"), source)
538
776
  : undefined;
539
- return base === undefined ? undefined : SOURCE_EXTENSIONS.map((extension) => base + extension).find((path) => paths.has(path));
777
+ if (base === undefined)
778
+ return undefined;
779
+ const js = /\.[cm]?jsx?$/.exec(base)?.[0];
780
+ const typescript = js ? (TS_FOR_JS[js] ?? []).map((extension) => base.slice(0, -js.length) + extension) : [];
781
+ return [...SOURCE_EXTENSIONS.map((extension) => base + extension), ...typescript].find((path) => paths.has(path));
540
782
  };
541
783
  const posixJoin = (dir, relative) => {
542
784
  const parts = dir ? dir.split("/") : [];
@@ -556,7 +798,7 @@ const definesServerCode = (file, factories) => {
556
798
  return;
557
799
  if (node.type === "CallExpression" && isHandlerCall(node)) {
558
800
  const { root } = chainOf(node);
559
- found = !!root && factories.has(file.imports.get(root)?.imported ?? root);
801
+ found = !!factories(file, root);
560
802
  }
561
803
  if ((node.type === "ObjectProperty" || node.type === "ObjectMethod") && nameOf(node.key) === "server")
562
804
  found = true;
@@ -565,15 +807,15 @@ const definesServerCode = (file, factories) => {
565
807
  };
566
808
  /**
567
809
  * Page code that imports server-only modules, which the build refuses: followed
568
- * from the routes through plain modules, never into a *.functions.* file, whose
569
- * handlers the browser never gets, nor into or out of a file that defines
570
- * server code itself.
810
+ * from the routes through plain modules' imports and re-exports, never into a
811
+ * *.functions.* file, whose handlers the browser never gets, nor into or out of
812
+ * a file that defines server code itself.
571
813
  */
572
- const serverImportProblems = (files, factories) => {
814
+ const serverImportProblems = (files, factories, routerPath) => {
573
815
  const byPath = new Map(files.map((file) => [file.path, file]));
574
816
  const paths = new Set(byPath.keys());
575
817
  const problems = [];
576
- const pageRoots = files.filter((file) => file.path === "src/router.tsx" || (file.path.startsWith("src/routes/") && !file.path.startsWith("src/routes/api/")));
818
+ const pageRoots = files.filter((file) => file.path === routerPath || (file.path.startsWith("src/routes/") && !file.path.startsWith("src/routes/api/")));
577
819
  const seen = new Set();
578
820
  const visit = (file) => {
579
821
  if (seen.has(file.path))
@@ -582,10 +824,8 @@ const serverImportProblems = (files, factories) => {
582
824
  if (definesServerCode(file, factories))
583
825
  return;
584
826
  for (const statement of file.program.body) {
585
- if (statement.type !== "ImportDeclaration")
586
- continue;
587
- const values = valueImports(statement);
588
- if (values !== "all" && values.length === 0)
827
+ const values = statement.type === "ImportDeclaration" ? valueImports(file, statement) : valueReexports(statement);
828
+ if (values === undefined || (values !== "all" && values.length === 0))
589
829
  continue;
590
830
  const source = statement.source.value;
591
831
  const target = resolveImport(file.path, source, paths);
@@ -606,29 +846,42 @@ const serverImportProblems = (files, factories) => {
606
846
  pageRoots.forEach(visit);
607
847
  return problems;
608
848
  };
849
+ const callsCreateZiteRouter = (file) => callsAny(file.program, (callee) => {
850
+ if (callee.type === "Identifier")
851
+ return (file.imports.get(callee.name)?.imported ?? callee.name) === "createZiteRouter";
852
+ const namespace = callee.type === "MemberExpression" && !callee.computed && nameOf(callee.property) === "createZiteRouter"
853
+ ? file.imports.get(nameOf(callee.object) ?? "")
854
+ : undefined;
855
+ return namespace?.imported === "*" && namespace.source === "zitejs/start";
856
+ });
609
857
  /** Every source hint for one Start app, given its files by app-relative path. */
610
858
  export function sourceProblems(sources, { internal = false, kind } = {}) {
611
859
  const files = Object.entries(sources)
612
860
  .filter(([path]) => /\.[cm]?[jt]sx?$/.test(path) && !path.endsWith("routeTree.gen.ts") && !path.endsWith(".d.ts"))
613
861
  .flatMap(([path, code]) => parseFile(path, code) ?? []);
614
- const factories = factoryNames(files);
615
862
  const problems = [];
616
863
  const report = (rule, severity, file, node, message) => problems.push({ rule, severity, file, ...(node && lineOf(node) && { line: lineOf(node) }), message });
617
864
  const serverFnFiles = new Map();
618
- if (!sources["src/router.tsx"]?.includes("createZiteRouter(")) {
865
+ const paths = new Set(files.map((file) => file.path));
866
+ const factories = factoryNames(files, paths);
867
+ const serverFns = new Map(files.map((file) => [file.path, serverFnNames(file, factories)]));
868
+ const serverFnExports = exportedServerFns(files, paths, serverFns);
869
+ // As Start finds it. One that doesn't parse is the typecheck's to report.
870
+ const routerPath = ENTRY_EXTENSIONS.map((extension) => `src/router${extension}`).find((path) => sources[path] !== undefined);
871
+ const router = files.find((file) => file.path === routerPath);
872
+ if (!routerPath || (router && !callsCreateZiteRouter(router))) {
619
873
  problems.push({
620
874
  rule: "router-file",
621
875
  severity: "error",
622
- file: "src/router.tsx",
623
- message: "export getRouter from src/router.tsx, built with createZiteRouter from zitejs/start, which gives pages the signed-in user",
876
+ file: routerPath ?? "src/router.tsx",
877
+ message: `export getRouter from ${routerPath ?? "src/router.tsx"}, built with createZiteRouter from zitejs/start, which gives pages the signed-in user`,
624
878
  });
625
879
  }
626
880
  for (const file of files) {
627
881
  const { path, program } = file;
628
- const factoryRoot = (root) => !!root && factories.has(file.imports.get(root)?.imported ?? root);
629
882
  const callsWorkflow = callsCreateWorkflow(program);
630
883
  const serverReachable = isServerReachable(path, callsWorkflow);
631
- const localServerFns = new Set();
884
+ const localServerFns = serverFns.get(path);
632
885
  const moduleContainers = new Map();
633
886
  for (const statement of program.body) {
634
887
  const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
@@ -639,8 +892,6 @@ export function sourceProblems(sources, { internal = false, kind } = {}) {
639
892
  const init = declarator.init ? unwrap(declarator.init) : undefined;
640
893
  if (!name || !init)
641
894
  continue;
642
- if (isHandlerCall(init) && factoryRoot(chainOf(init).root))
643
- localServerFns.add(name);
644
895
  if (serverReachable && declaration.kind === "const" && isContainer(init))
645
896
  moduleContainers.set(name, false);
646
897
  }
@@ -653,7 +904,7 @@ export function sourceProblems(sources, { internal = false, kind } = {}) {
653
904
  for (const statement of program.body) {
654
905
  if (statement.type === "ImportDeclaration") {
655
906
  const source = statement.source.value;
656
- const values = valueImports(statement);
907
+ const values = valueImports(file, statement);
657
908
  for (const [module, instead] of Object.entries(CLASSIC_IMPORTS)) {
658
909
  const refused = values === "all" || values.length > 0;
659
910
  if (importsModule(source, module) && refused) {
@@ -664,9 +915,18 @@ export function sourceProblems(sources, { internal = false, kind } = {}) {
664
915
  report("cloudflare-env", "error", path, statement, "read the app's environment from process.env, not cloudflare:workers");
665
916
  }
666
917
  const typeOnly = values !== "all" && values.length === 0;
667
- if (callsWorkflow && !typeOnly && (/\.functions(\.[jt]sx?)?$/.test(source) || importsModule(source, "@tanstack/react-start/server"))) {
918
+ // Loading a module is fine without a request; only calling one of its server functions isn't.
919
+ const target = callsWorkflow ? resolveImport(path, source, paths) : undefined;
920
+ const unresolvedFunctions = !target && /\.functions(\.[jt]sx?)?$/.test(source);
921
+ if (callsWorkflow && !typeOnly && (importsModule(source, "@tanstack/react-start/server") || unresolvedFunctions)) {
668
922
  report("workflow-imports", "error", path, statement, `an automation runs without a page request, so it can't use ${source}; move what it needs into a *.server.ts helper`);
669
923
  }
924
+ const targetFns = target ? serverFnExports(target) : new Set();
925
+ const reads = targetFns.size > 0 ? importedReads(file, statement) : [];
926
+ const called = reads === "all" ? [...targetFns] : [...new Set(reads)].filter((name) => targetFns.has(name));
927
+ if (called.length > 0) {
928
+ report("workflow-imports", "error", path, statement, `an automation runs without a page request, so it can't call ${called.join(", ")} from ${source}; move what it needs into a *.server.ts helper`);
929
+ }
670
930
  }
671
931
  const exported = statement.type === "ExportNamedDeclaration" ? statement.declaration : undefined;
672
932
  const exportedNames = exported?.type === "FunctionDeclaration"
@@ -685,7 +945,8 @@ export function sourceProblems(sources, { internal = false, kind } = {}) {
685
945
  const parent = ancestors.at(-1);
686
946
  if (node.type === "CallExpression" && isHandlerCall(node)) {
687
947
  const { root, calls } = chainOf(node);
688
- if (factoryRoot(root)) {
948
+ const builder = factories(file, root);
949
+ if (builder) {
689
950
  const declarator = parent?.type === "VariableDeclarator" ? parent : undefined;
690
951
  const name = nameOf(declarator?.id);
691
952
  if (!declarator || !isTopLevelDeclarator(ancestors)) {
@@ -694,10 +955,10 @@ export function sourceProblems(sources, { internal = false, kind } = {}) {
694
955
  else if (name) {
695
956
  serverFnFiles.set(name, [...(serverFnFiles.get(name) ?? []), path]);
696
957
  }
697
- if (!hasMethodOption(calls)) {
958
+ const { factory, method } = builder;
959
+ if (!method && !hasMethodOption(calls)) {
698
960
  report("method-missing", "error", path, node, `call ${root} with { method: 'GET' | 'POST', description } before .handler()`);
699
961
  }
700
- const factory = factories.get(file.imports.get(root)?.imported ?? root);
701
962
  const subject = `function ${name ?? "this function"}`;
702
963
  if (factory === "createServerFn") {
703
964
  report("raw-server-fn", "error", path, node, `${subject}: define it with signedInFn or publicFn from zitejs/start`);
@@ -757,8 +1018,9 @@ export function sourceProblems(sources, { internal = false, kind } = {}) {
757
1018
  report("classic-construct", "error", path, node, "createEndpoint is classic's; in a Start app, server code is a signedInFn/publicFn server function");
758
1019
  }
759
1020
  if (node.type === "CallExpression" && nameOf(node.callee) === "redirect") {
760
- const options = node.arguments[0];
761
- const href = options?.type === "ObjectExpression" ? propertyNamed(options, "href") : undefined;
1021
+ const argument = node.arguments[0];
1022
+ const options = argument?.type === "ObjectExpression" ? argument : undefined;
1023
+ const href = options && propertyNamed(options, "href");
762
1024
  const value = href && href.value;
763
1025
  const toLogin = !!value && (nameOf(value) === "loginHref" || callsAny(value, (callee) => nameOf(callee) === "loginHref"));
764
1026
  const reload = options && propertyNamed(options, "reloadDocument");
@@ -829,7 +1091,7 @@ export function sourceProblems(sources, { internal = false, kind } = {}) {
829
1091
  }
830
1092
  });
831
1093
  }
832
- problems.push(...routeProblems(files, internal), ...workflowProblems(files, kind), ...serverImportProblems(files, factories));
1094
+ problems.push(...routeProblems(files, internal), ...workflowProblems(files, kind), ...serverImportProblems(files, factories, routerPath));
833
1095
  for (const [name, paths] of serverFnFiles) {
834
1096
  const distinct = [...new Set(paths)];
835
1097
  if (distinct.length > 1) {
@@ -45,8 +45,8 @@ export type FilterOperators<V> = FilterCondition<V> | V;
45
45
  * NOT `equals`, despite `formulas.ts` having a `case 'equals'`: that case only
46
46
  * fires for the bare-value shorthand. `equals` is absent from
47
47
  * `WhereConditionOperators`, so `isNestedCondition` doesn't recognize the
48
- * object, the whole `{ equals: … }` is stringified as the operand, and Airtable
49
- * 422s on `{Email}=[object Object]`.
48
+ * object, the whole `{ equals: … }` is taken as the value, and the filter
49
+ * fails.
50
50
  *
51
51
  * One operator per field on this path — `formulas.ts` reads
52
52
  * `Object.keys(condition)[0]` and drops the rest, unlike the Zite DB filter