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