zitejs 0.10.0-start.2 → 0.10.0-start.21

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 (188) hide show
  1. package/dist/cjs/auth/actions.d.ts +28 -0
  2. package/dist/cjs/auth/actions.js +93 -0
  3. package/dist/cjs/auth/client.d.ts +357 -0
  4. package/dist/cjs/auth/client.js +66 -0
  5. package/dist/cjs/auth/index.d.ts +2 -249
  6. package/dist/cjs/auth/index.js +11 -108
  7. package/dist/cjs/auth/index.test.js +48 -0
  8. package/dist/cjs/auth/previewClaim.d.ts +7 -0
  9. package/dist/cjs/auth/previewClaim.js +16 -0
  10. package/dist/cjs/auth/profileUpdates.d.ts +9 -0
  11. package/dist/cjs/auth/profileUpdates.js +11 -0
  12. package/dist/cjs/backend/index.d.ts +121 -3
  13. package/dist/cjs/backend/index.test.js +58 -0
  14. package/dist/cjs/bundle/index.d.ts +8 -0
  15. package/dist/cjs/bundle/index.js +9 -8
  16. package/dist/cjs/check/index.d.ts +45 -1
  17. package/dist/cjs/check/index.js +198 -109
  18. package/dist/cjs/check/start/problem.d.ts +11 -0
  19. package/dist/cjs/check/start/problem.js +5 -0
  20. package/dist/cjs/check/start/routeTree.d.ts +9 -0
  21. package/dist/cjs/check/start/routeTree.js +111 -0
  22. package/dist/cjs/check/start/sourceRules.d.ts +8 -0
  23. package/dist/cjs/check/start/sourceRules.js +1159 -0
  24. package/dist/cjs/check/start/tsgo.d.ts +2 -0
  25. package/dist/cjs/check/start/tsgo.js +35 -0
  26. package/dist/cjs/cli.js +1 -1
  27. package/dist/cjs/client/index.d.ts +24 -0
  28. package/dist/cjs/dev/index.js +14 -4
  29. package/dist/cjs/integrations/rules.d.ts +13 -0
  30. package/dist/cjs/integrations/rules.js +31 -0
  31. package/dist/cjs/integrations/rules.test.js +1 -0
  32. package/dist/cjs/internal/appMode.d.ts +3 -0
  33. package/dist/cjs/internal/appMode.js +15 -0
  34. package/dist/cjs/runtime/index.d.ts +64 -25
  35. package/dist/cjs/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
  36. package/dist/cjs/runtime/sendEmailParamsTypes.test-d.js +33 -0
  37. package/dist/cjs/start/entries.d.ts +10 -4
  38. package/dist/cjs/start/entries.js +23 -6
  39. package/dist/cjs/steps/index.d.ts +78 -0
  40. package/dist/cjs/steps/index.js +507 -0
  41. package/dist/cjs/steps/index.test.d.ts +1 -0
  42. package/dist/cjs/steps/index.test.js +635 -0
  43. package/dist/cjs/sync/index.js +2 -1
  44. package/dist/cjs/sync/lib.d.ts +10 -3
  45. package/dist/cjs/sync/lib.js +44 -25
  46. package/dist/cjs/sync/lib.test.js +116 -36
  47. package/dist/cjs/types/fields.d.ts +8 -1
  48. package/dist/cjs/types/fields.js +7 -1
  49. package/dist/cjs/types/tables.d.ts +16 -0
  50. package/dist/cjs/upload/index.js +12 -2
  51. package/dist/cjs/upload/index.test.js +39 -0
  52. package/dist/cjs/vite/index.js +8 -3
  53. package/dist/cjs/vite/index.test.js +10 -2
  54. package/dist/esm/auth/actions.d.ts +28 -0
  55. package/dist/esm/auth/actions.js +55 -0
  56. package/dist/esm/auth/client.d.ts +357 -0
  57. package/dist/esm/auth/client.js +62 -0
  58. package/dist/esm/auth/index.d.ts +2 -249
  59. package/dist/esm/auth/index.js +2 -103
  60. package/dist/esm/auth/index.test.js +48 -0
  61. package/dist/esm/auth/previewClaim.d.ts +7 -0
  62. package/dist/esm/auth/previewClaim.js +12 -0
  63. package/dist/esm/auth/profileUpdates.d.ts +9 -0
  64. package/dist/esm/auth/profileUpdates.js +6 -0
  65. package/dist/esm/backend/index.d.ts +121 -3
  66. package/dist/esm/backend/index.test.js +58 -0
  67. package/dist/esm/bundle/index.d.ts +8 -0
  68. package/dist/esm/bundle/index.js +8 -8
  69. package/dist/esm/check/index.d.ts +45 -1
  70. package/dist/esm/check/index.js +198 -113
  71. package/dist/esm/check/start/problem.d.ts +11 -0
  72. package/dist/esm/check/start/problem.js +1 -0
  73. package/dist/esm/check/start/routeTree.d.ts +9 -0
  74. package/dist/esm/check/start/routeTree.js +70 -0
  75. package/dist/esm/check/start/sourceRules.d.ts +8 -0
  76. package/dist/esm/check/start/sourceRules.js +1156 -0
  77. package/dist/esm/check/start/tsgo.d.ts +2 -0
  78. package/dist/esm/check/start/tsgo.js +29 -0
  79. package/dist/esm/cli.js +1 -1
  80. package/dist/esm/client/index.d.ts +24 -0
  81. package/dist/esm/dev/index.js +16 -6
  82. package/dist/esm/integrations/rules.d.ts +13 -0
  83. package/dist/esm/integrations/rules.js +31 -0
  84. package/dist/esm/integrations/rules.test.js +1 -0
  85. package/dist/esm/internal/appMode.d.ts +3 -0
  86. package/dist/esm/internal/appMode.js +10 -0
  87. package/dist/esm/runtime/index.d.ts +64 -25
  88. package/dist/esm/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
  89. package/dist/esm/runtime/sendEmailParamsTypes.test-d.js +31 -0
  90. package/dist/esm/start/aiUsage.d.ts +23 -0
  91. package/dist/esm/start/aiUsage.js +146 -0
  92. package/dist/esm/start/airtable/arrayFields.d.ts +10 -0
  93. package/dist/esm/start/airtable/arrayFields.js +30 -0
  94. package/dist/esm/start/airtable/dispatch.d.ts +54 -0
  95. package/dist/esm/start/airtable/dispatch.js +483 -0
  96. package/dist/esm/start/airtable/formulas.d.ts +70 -0
  97. package/dist/esm/start/airtable/formulas.js +260 -0
  98. package/dist/esm/start/airtable/index.d.ts +8 -0
  99. package/dist/esm/start/airtable/index.js +54 -0
  100. package/dist/esm/start/authHooks.d.ts +7 -0
  101. package/dist/esm/start/authHooks.js +10 -0
  102. package/dist/esm/start/authHooksModule.d.ts +1 -0
  103. package/dist/esm/start/authHooksModule.js +3 -0
  104. package/dist/esm/start/clientErrorMessage.test.d.ts +1 -0
  105. package/dist/esm/start/clientErrorMessage.test.js +105 -0
  106. package/dist/esm/start/credentials.d.ts +2 -0
  107. package/dist/esm/start/credentials.js +2 -0
  108. package/dist/esm/start/data/baseRunner.d.ts +92 -0
  109. package/dist/esm/start/data/baseRunner.js +83 -0
  110. package/dist/esm/start/data/dispatch.d.ts +16 -0
  111. package/dist/esm/start/data/dispatch.js +198 -0
  112. package/dist/esm/start/data/index.d.ts +15 -0
  113. package/dist/esm/start/data/index.js +58 -0
  114. package/dist/esm/start/data/sqlNameMappings.d.ts +58 -0
  115. package/dist/esm/start/data/sqlNameMappings.js +92 -0
  116. package/dist/esm/start/data/transformations.d.ts +97 -0
  117. package/dist/esm/start/data/transformations.js +262 -0
  118. package/dist/esm/start/data/types.d.ts +91 -0
  119. package/dist/esm/start/data/types.js +14 -0
  120. package/dist/esm/start/describe.d.ts +42 -5
  121. package/dist/esm/start/describe.js +77 -23
  122. package/dist/esm/start/entries.d.ts +10 -4
  123. package/dist/esm/start/entries.js +21 -5
  124. package/dist/esm/start/errors.d.ts +63 -0
  125. package/dist/esm/start/errors.js +146 -0
  126. package/dist/esm/start/errors.test.d.ts +1 -0
  127. package/dist/esm/start/errors.test.js +23 -0
  128. package/dist/esm/start/factories.test-d.d.ts +2 -0
  129. package/dist/esm/start/factories.test-d.js +20 -0
  130. package/dist/esm/start/host.d.ts +2 -2
  131. package/dist/esm/start/index.d.ts +32 -27
  132. package/dist/esm/start/index.js +79 -47
  133. package/dist/esm/start/instance.d.ts +4 -4
  134. package/dist/esm/start/instance.js +54 -11
  135. package/dist/esm/start/outbound.d.ts +11 -0
  136. package/dist/esm/start/outbound.js +400 -0
  137. package/dist/esm/start/previewClaim.d.ts +7 -0
  138. package/dist/esm/start/previewClaim.js +23 -0
  139. package/dist/esm/start/problems.js +1 -1
  140. package/dist/esm/start/quiet.d.ts +2 -0
  141. package/dist/esm/start/quiet.js +27 -0
  142. package/dist/esm/start/redactSecrets.d.ts +15 -0
  143. package/dist/esm/start/redactSecrets.js +154 -0
  144. package/dist/esm/start/redactSecrets.test.d.ts +1 -0
  145. package/dist/esm/start/redactSecrets.test.js +151 -0
  146. package/dist/esm/start/registration.d.ts +13 -0
  147. package/dist/esm/start/registration.js +21 -0
  148. package/dist/esm/start/registrationHash.d.ts +22 -0
  149. package/dist/esm/start/registrationHash.js +470 -0
  150. package/dist/esm/start/router.d.ts +25 -4
  151. package/dist/esm/start/router.js +169 -11
  152. package/dist/esm/start/runLog.d.ts +7 -4
  153. package/dist/esm/start/runLog.js +64 -6
  154. package/dist/esm/start/scope.d.ts +4 -4
  155. package/dist/esm/start/server.d.ts +40 -36
  156. package/dist/esm/start/server.js +322 -49
  157. package/dist/esm/start/steps.d.ts +28 -0
  158. package/dist/esm/start/steps.js +97 -0
  159. package/dist/esm/start/types.d.ts +179 -6
  160. package/dist/esm/start/version.d.ts +1 -0
  161. package/dist/esm/start/version.js +2 -0
  162. package/dist/esm/start/vite.js +91 -14
  163. package/dist/esm/start/worker.d.ts +6 -0
  164. package/dist/esm/start/worker.js +12 -0
  165. package/dist/esm/start/workflow.d.ts +46 -12
  166. package/dist/esm/start/workflow.js +10 -3
  167. package/dist/esm/start/workflow.test-d.js +50 -8
  168. package/dist/esm/start/workflowModules.js +1 -1
  169. package/dist/esm/start/workflowRun.d.ts +26 -8
  170. package/dist/esm/start/workflowRun.js +39 -8
  171. package/dist/esm/steps/index.d.ts +78 -0
  172. package/dist/esm/steps/index.js +502 -0
  173. package/dist/esm/steps/index.test.d.ts +1 -0
  174. package/dist/esm/steps/index.test.js +633 -0
  175. package/dist/esm/sync/index.js +2 -1
  176. package/dist/esm/sync/lib.d.ts +10 -3
  177. package/dist/esm/sync/lib.js +44 -25
  178. package/dist/esm/sync/lib.test.js +116 -36
  179. package/dist/esm/types/fields.d.ts +8 -1
  180. package/dist/esm/types/fields.js +6 -0
  181. package/dist/esm/types/tables.d.ts +16 -0
  182. package/dist/esm/upload/index.js +12 -2
  183. package/dist/esm/upload/index.test.js +39 -0
  184. package/dist/esm/vite/index.js +8 -3
  185. package/dist/esm/vite/index.test.js +10 -2
  186. package/package.json +37 -16
  187. package/dist/cjs/start/problems.d.ts +0 -19
  188. package/dist/cjs/start/problems.js +0 -11
@@ -0,0 +1,470 @@
1
+ // cyrb53: enough to tell when the code changed, which is all publish asks.
2
+ const sourceHash = (text) => {
3
+ let h1 = 0xdeadbeef;
4
+ let h2 = 0x41c6ce57;
5
+ for (let i = 0; i < text.length; i++) {
6
+ const ch = text.charCodeAt(i);
7
+ h1 = Math.imul(h1 ^ ch, 2654435761);
8
+ h2 = Math.imul(h2 ^ ch, 1597334677);
9
+ }
10
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
11
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
12
+ return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(16).padStart(14, "0");
13
+ };
14
+ export const registrationHash = (subscribe, unsubscribe) => sourceHash(`${subscribe}\n${unsubscribe ?? ""}`);
15
+ const KEYWORDS = new Set(("async await break case catch class const continue debugger default delete do else export extends false finally for " +
16
+ "function if import in instanceof let new null of return static super switch this throw true try typeof undefined var " +
17
+ "void while with yield").split(" "));
18
+ const IDENTIFIER = /[A-Za-z_$][\w$]*/y;
19
+ const NUMBER = /[0-9][\w.]*/y;
20
+ const QUOTED = /"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/y;
21
+ // A template literal's text up to its end or its next `${`.
22
+ const TEMPLATE_TEXT = /(?:[^`\\$]|\\.|\$(?!\{))*(?:`|\$\{)?/y;
23
+ /**
24
+ * A built function's text with its identifiers numbered in order of first appearance, so the minifier's renaming
25
+ * alone can't change it. Literals, property names and object keys, which it doesn't rename, stay.
26
+ */
27
+ export const canonicalNames = (text) => {
28
+ const names = new Map();
29
+ // The brace depth each open template expression closes at.
30
+ const templates = [];
31
+ let depth = 0;
32
+ let out = "";
33
+ let i = 0;
34
+ const take = (pattern) => {
35
+ pattern.lastIndex = i;
36
+ const token = pattern.exec(text)?.[0] ?? text[i];
37
+ i += token.length;
38
+ return token;
39
+ };
40
+ const templateText = () => {
41
+ const token = take(TEMPLATE_TEXT);
42
+ out += token;
43
+ if (token.endsWith("${"))
44
+ templates.push(depth++);
45
+ };
46
+ while (i < text.length) {
47
+ const ch = text[i];
48
+ if (ch === "`") {
49
+ out += take(/`/y);
50
+ templateText();
51
+ }
52
+ else if (ch === "}" && templates.at(-1) === depth - 1) {
53
+ templates.pop();
54
+ depth--;
55
+ out += take(/\}/y);
56
+ templateText();
57
+ }
58
+ else if (ch === '"' || ch === "'") {
59
+ out += take(QUOTED);
60
+ }
61
+ else if (/[0-9]/.test(ch)) {
62
+ out += take(NUMBER);
63
+ }
64
+ else if (/[A-Za-z_$]/.test(ch)) {
65
+ const start = i;
66
+ const token = take(IDENTIFIER);
67
+ let before = start - 1;
68
+ while (/\s/.test(text[before] ?? ""))
69
+ before--;
70
+ let after = i;
71
+ while (/\s/.test(text[after] ?? ""))
72
+ after++;
73
+ const property = text[before] === "." && text[before - 1] !== ".";
74
+ const key = (text[before] === "{" || text[before] === ",") && text[after] === ":";
75
+ if (KEYWORDS.has(token) || property || key) {
76
+ out += token;
77
+ }
78
+ else {
79
+ if (!names.has(token))
80
+ names.set(token, `$${names.size}`);
81
+ out += names.get(token);
82
+ }
83
+ }
84
+ else {
85
+ if (ch === "{")
86
+ depth++;
87
+ if (ch === "}")
88
+ depth--;
89
+ out += take(/[^]/y);
90
+ }
91
+ }
92
+ return out;
93
+ };
94
+ const WRAPPERS = new Set(["ParenthesizedExpression", "TSAsExpression", "TSSatisfiesExpression", "TSNonNullExpression"]);
95
+ const DECLARATIONS = new Set(["FunctionDeclaration", "ClassDeclaration", "TSEnumDeclaration"]);
96
+ // Types run nothing, so they're neither followed nor hashed.
97
+ const TYPE_KEYS = new Set(["typeAnnotation", "returnType", "typeParameters", "typeArguments", "superTypeArguments", "implements"]);
98
+ const TYPE_NODES = new Set(["TSInterfaceDeclaration", "TSTypeAliasDeclaration", "TSDeclareFunction"]);
99
+ const KEYED = new Set(["Property", "MethodDefinition", "PropertyDefinition", "AccessorProperty"]);
100
+ const LABELED = new Set(["LabeledStatement", "BreakStatement", "ContinueStatement"]);
101
+ const FUNCTIONS = new Set(["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"]);
102
+ const isNode = (value) => typeof value?.type === "string";
103
+ const nameOf = (node) => {
104
+ const n = node;
105
+ return n?.type === "Identifier" ? n.name : n?.type === "Literal" && typeof n.value === "string" ? n.value : undefined;
106
+ };
107
+ const patternNames = (pattern) => {
108
+ if (!isNode(pattern))
109
+ return [];
110
+ switch (pattern.type) {
111
+ case "Identifier":
112
+ return [pattern.name];
113
+ case "ObjectPattern":
114
+ return pattern.properties.flatMap((p) => patternNames(p.type === "RestElement" ? p.argument : p.value));
115
+ case "ArrayPattern":
116
+ return pattern.elements.flatMap(patternNames);
117
+ case "AssignmentPattern":
118
+ return patternNames(pattern.left);
119
+ case "RestElement":
120
+ return patternNames(pattern.argument);
121
+ default:
122
+ return [];
123
+ }
124
+ };
125
+ const moduleOf = (file, code, program) => {
126
+ const bindings = new Map();
127
+ const exports = new Map();
128
+ const stars = [];
129
+ const declare = (declaration) => {
130
+ if (declaration?.type === "VariableDeclaration") {
131
+ return declaration.declarations.flatMap((declarator) => {
132
+ const names = patternNames(declarator.id);
133
+ const value = declarator.id.type === "Identifier" ? declarator.init : undefined;
134
+ for (const name of names)
135
+ bindings.set(name, { node: declarator, value });
136
+ return names;
137
+ });
138
+ }
139
+ const name = nameOf(declaration?.id);
140
+ if (!declaration || !name || !DECLARATIONS.has(declaration.type))
141
+ return [];
142
+ bindings.set(name, { node: declaration, value: declaration });
143
+ return [name];
144
+ };
145
+ for (const statement of (program?.body ?? [])) {
146
+ const source = statement.source?.value;
147
+ if (statement.type === "ImportDeclaration") {
148
+ if (statement.importKind === "type")
149
+ continue;
150
+ for (const specifier of statement.specifiers) {
151
+ if (specifier.importKind === "type")
152
+ continue;
153
+ const name = specifier.type === "ImportNamespaceSpecifier" ? "*" : specifier.type === "ImportDefaultSpecifier" ? "default" : nameOf(specifier.imported);
154
+ if (name)
155
+ bindings.set(nameOf(specifier.local), { source: source, name });
156
+ }
157
+ }
158
+ else if (statement.type === "ExportAllDeclaration") {
159
+ if (statement.exportKind === "type")
160
+ continue;
161
+ const as = nameOf(statement.exported);
162
+ if (as)
163
+ exports.set(as, { source: source, name: "*" });
164
+ else
165
+ stars.push(source);
166
+ }
167
+ else if (statement.type === "ExportNamedDeclaration") {
168
+ if (statement.exportKind === "type")
169
+ continue;
170
+ for (const name of declare(statement.declaration))
171
+ exports.set(name, { local: name });
172
+ for (const specifier of statement.specifiers ?? []) {
173
+ const local = nameOf(specifier.local);
174
+ const as = nameOf(specifier.exported);
175
+ if (local && as && specifier.exportKind !== "type")
176
+ exports.set(as, source ? { source, name: local } : { local });
177
+ }
178
+ }
179
+ else if (statement.type === "ExportDefaultDeclaration") {
180
+ const declaration = statement.declaration;
181
+ const [name] = declare(declaration);
182
+ if (!name)
183
+ bindings.set("*default*", { node: declaration, value: declaration });
184
+ exports.set("default", { local: name ?? "*default*" });
185
+ }
186
+ else {
187
+ declare(statement);
188
+ }
189
+ }
190
+ return { file, code, bindings, exports, stars };
191
+ };
192
+ // `object.member` of a const object literal written whole: only that property, so a generated client's other
193
+ // tables, say, stay out of the hash.
194
+ const propertyOf = (object, member) => {
195
+ while (object && WRAPPERS.has(object.type))
196
+ object = object.expression;
197
+ const properties = object?.type === "ObjectExpression" ? object.properties : [];
198
+ if (properties.some((p) => p.type !== "Property" || p.computed))
199
+ return undefined;
200
+ return properties.find((p) => nameOf(p.key) === member);
201
+ };
202
+ const isPropertyName = (parent, key) => !!parent &&
203
+ ((parent.type === "MemberExpression" && key === "property" && !parent.computed) ||
204
+ (KEYED.has(parent.type) && key === "key" && !parent.computed) ||
205
+ (LABELED.has(parent.type) && key === "label") ||
206
+ parent.type === "MetaProperty");
207
+ // The names a function binds for its whole body: its parameters, its `var`s, and what its body declares directly.
208
+ // A name an inner block declares is left out, so a module-level name it shadows there still counts: hashing too much
209
+ // registers once more, hashing too little never registers again.
210
+ const boundIn = (fn) => {
211
+ const names = [...fn.params.flatMap(patternNames), ...patternNames(fn.type === "FunctionExpression" ? fn.id : undefined)];
212
+ const body = fn.body;
213
+ for (const statement of body.type === "BlockStatement" ? body.body : []) {
214
+ if (statement.type === "VariableDeclaration")
215
+ for (const declarator of statement.declarations)
216
+ names.push(...patternNames(declarator.id));
217
+ if (DECLARATIONS.has(statement.type))
218
+ names.push(...patternNames(statement.id));
219
+ }
220
+ const vars = (value) => {
221
+ if (Array.isArray(value))
222
+ return value.forEach(vars);
223
+ if (!isNode(value) || FUNCTIONS.has(value.type))
224
+ return;
225
+ if (value.type === "VariableDeclaration" && value.kind === "var") {
226
+ for (const declarator of value.declarations)
227
+ names.push(...patternNames(declarator.id));
228
+ }
229
+ for (const child of Object.values(value))
230
+ if (child && typeof child === "object")
231
+ vars(child);
232
+ };
233
+ vars(body);
234
+ return names;
235
+ };
236
+ // The names a node's code reads from outside itself, and its text without types.
237
+ const scan = (code, root) => {
238
+ const references = [];
239
+ const types = [];
240
+ const visit = (value, scope, parent, key) => {
241
+ if (Array.isArray(value)) {
242
+ for (const item of value)
243
+ visit(item, scope, parent, key);
244
+ return;
245
+ }
246
+ if (!isNode(value))
247
+ return;
248
+ if (FUNCTIONS.has(value.type))
249
+ scope = new Set([...scope, ...boundIn(value)]);
250
+ if ((key && TYPE_KEYS.has(key)) || TYPE_NODES.has(value.type)) {
251
+ types.push(value);
252
+ }
253
+ else if (value.type === "Identifier") {
254
+ if (!isPropertyName(parent, key) && !scope.has(value.name))
255
+ references.push({ name: value.name });
256
+ if (isNode(value.typeAnnotation))
257
+ types.push(value.typeAnnotation);
258
+ }
259
+ else if (value.type === "MemberExpression" && !value.computed && value.object.type === "Identifier") {
260
+ const name = value.object.name;
261
+ if (!scope.has(name))
262
+ references.push({ name, member: nameOf(value.property) });
263
+ }
264
+ else {
265
+ for (const [childKey, child] of Object.entries(value))
266
+ if (child && typeof child === "object")
267
+ visit(child, scope, value, childKey);
268
+ }
269
+ };
270
+ visit(root, new Set());
271
+ let text = "";
272
+ let at = root.start;
273
+ for (const type of types.sort((a, b) => a.start - b.start)) {
274
+ if (type.start < at)
275
+ continue;
276
+ text += code.slice(at, type.start);
277
+ at = type.end;
278
+ }
279
+ return { references, text: text + code.slice(at, root.end) };
280
+ };
281
+ /** `automation id -> registration hash` for each provider trigger the module at `file` exports. */
282
+ export async function registrationHashes(file, source) {
283
+ const modules = new Map();
284
+ const open = (target) => {
285
+ if (!modules.has(target)) {
286
+ const loaded = source.load(target);
287
+ modules.set(target, loaded ? moduleOf(target, loaded.code, loaded.program) : null);
288
+ }
289
+ return modules.get(target);
290
+ };
291
+ const resolved = new Map();
292
+ const imported = (from, specifier) => {
293
+ const key = `${from.file}\0${specifier}`;
294
+ if (!resolved.has(key))
295
+ resolved.set(key, source.resolve(specifier, from.file).then((target) => (target ? open(target) : null)));
296
+ return resolved.get(key);
297
+ };
298
+ // Everything a module exports, by name: its own, then each `export *` module's but `default`.
299
+ const exportsOf = async (module, visited = new Set()) => {
300
+ const all = new Map();
301
+ for (const [name, exported] of module.exports)
302
+ all.set(name, { module, ...exported });
303
+ visited.add(module);
304
+ for (const star of module.stars) {
305
+ const target = await imported(module, star);
306
+ if (!target || visited.has(target))
307
+ continue;
308
+ for (const [name, exported] of await exportsOf(target, visited))
309
+ if (name !== "default" && !all.has(name))
310
+ all.set(name, exported);
311
+ }
312
+ return all;
313
+ };
314
+ const isNamespace = (module, node) => {
315
+ const binding = module.bindings.get(nameOf(node) ?? "");
316
+ return !!binding && "name" in binding && binding.name === "*";
317
+ };
318
+ // The one walk through bindings, imports and re-exports. `member` picks a namespace's export, or a const object's
319
+ // property; `visited` ends a cycle.
320
+ const declarationOf = async (module, name, member, visited) => {
321
+ const binding = module.bindings.get(name);
322
+ const key = `${module.file}#${name}`;
323
+ if (!binding || visited.has(key))
324
+ return undefined;
325
+ visited.add(key);
326
+ if ("source" in binding)
327
+ return importOf(module, binding, member, visited);
328
+ const property = member ? propertyOf(binding.value, member) : undefined;
329
+ return { kind: "declared", module, node: property ?? binding.node, value: property ? property.value : binding.value };
330
+ };
331
+ const importOf = async (module, { source: specifier, name }, member, visited) => {
332
+ const target = await imported(module, specifier);
333
+ if (!target)
334
+ return { kind: "text", text: `${specifier}#${name}` };
335
+ if (name !== "*")
336
+ return exportOf(target, name, member, visited);
337
+ return member ? exportOf(target, member, undefined, visited) : { kind: "namespace", module: target };
338
+ };
339
+ const exportOf = async (module, name, member, visited) => {
340
+ const key = `${module.file}>${name}`;
341
+ if (visited.has(key))
342
+ return undefined;
343
+ visited.add(key);
344
+ const found = (await exportsOf(module)).get(name);
345
+ // One this can't place, or a module that doesn't parse: its whole source stands in.
346
+ if (!found)
347
+ return { kind: "text", text: module.code };
348
+ if ("local" in found)
349
+ return declarationOf(found.module, found.local, member, visited);
350
+ return importOf(found.module, found, member, visited);
351
+ };
352
+ const valueAt = (target) => target?.kind === "declared" && target.value ? { module: target.module, node: target.value } : undefined;
353
+ // A value as written, through parentheses, type assertions, consts, imports, re-exports and namespaces.
354
+ const valueOf = async (at, visited = new Set()) => {
355
+ let node = at?.node;
356
+ while (node && WRAPPERS.has(node.type))
357
+ node = node.expression;
358
+ if (!at || !node)
359
+ return undefined;
360
+ const { module } = at;
361
+ if (node.type === "Identifier")
362
+ return valueOf(valueAt(await declarationOf(module, node.name, undefined, visited)), visited);
363
+ if (node.type !== "MemberExpression" || node.computed || !isNamespace(module, node.object))
364
+ return { module, node };
365
+ return valueOf(valueAt(await declarationOf(module, nameOf(node.object), nameOf(node.property), visited)), visited);
366
+ };
367
+ const isFactory = (module, callee) => {
368
+ if (callee.type === "MemberExpression") {
369
+ return !callee.computed && nameOf(callee.property) === "createAutomation" && isNamespace(module, callee.object);
370
+ }
371
+ const binding = module.bindings.get(nameOf(callee) ?? "");
372
+ return !!binding && "name" in binding && binding.name === "createAutomation";
373
+ };
374
+ // `createAutomation(config).handler(fn)`, down to its config.
375
+ const configOf = async (at, visited = new Set()) => {
376
+ if (!at || visited.has(at.node))
377
+ return undefined;
378
+ visited.add(at.node);
379
+ const { module, node } = at;
380
+ if (node.type === "CallExpression") {
381
+ const callee = node.callee;
382
+ if (isFactory(module, callee))
383
+ return valueOf({ module, node: node.arguments[0] });
384
+ return configOf(await valueOf({ module, node: callee }), visited);
385
+ }
386
+ return node.type === "MemberExpression" ? configOf(await valueOf({ module, node: node.object }), visited) : undefined;
387
+ };
388
+ // A property as written, through spreads; "unknown" when the object or a spread after it can't be read.
389
+ const property = async (object, key, visited = new Set()) => {
390
+ if (object?.node.type !== "ObjectExpression" || visited.has(object.node))
391
+ return "unknown";
392
+ // The objects on this path only: one two spreads share is read twice, and only a cycle is unknown.
393
+ visited.add(object.node);
394
+ try {
395
+ for (const p of [...object.node.properties].reverse()) {
396
+ if (p.type === "SpreadElement") {
397
+ const found = await property(await valueOf({ module: object.module, node: p.argument }), key, visited);
398
+ if (found !== "absent")
399
+ return found;
400
+ }
401
+ else if (p.computed) {
402
+ return "unknown";
403
+ }
404
+ else if (nameOf(p.key) === key) {
405
+ return { module: object.module, node: p.value };
406
+ }
407
+ }
408
+ return "absent";
409
+ }
410
+ finally {
411
+ visited.delete(object.node);
412
+ }
413
+ };
414
+ // The code and everything it reaches: the module-level declarations it names, followed into the modules it
415
+ // imports them from. A package stands in by its name.
416
+ const reached = async (start) => {
417
+ const pieces = [];
418
+ const seen = new Set();
419
+ const once = (key) => !seen.has(key) && !!seen.add(key);
420
+ const follow = async (target) => {
421
+ if (target?.kind === "declared") {
422
+ const { module, node } = target;
423
+ if (!once(`${module.file}:${node.start}:${node.end}`))
424
+ return;
425
+ const { references, text } = scan(module.code, node);
426
+ pieces.push(text);
427
+ for (const { name, member } of references)
428
+ await follow(await declarationOf(module, name, member, new Set()));
429
+ }
430
+ else if (target?.kind === "namespace") {
431
+ if (!once(`${target.module.file}#*`))
432
+ return;
433
+ for (const name of (await exportsOf(target.module)).keys())
434
+ await follow(await exportOf(target.module, name, undefined, new Set()));
435
+ }
436
+ else if (target && once(target.text)) {
437
+ pieces.push(target.text);
438
+ }
439
+ };
440
+ await follow({ kind: "declared", ...start });
441
+ return pieces.join("\n");
442
+ };
443
+ const hashOf = async (root, name) => {
444
+ const config = await configOf(await valueOf(valueAt(await exportOf(root, name, undefined, new Set()))));
445
+ // Not a createAutomation this can read: describe hashes the built functions.
446
+ if (!config)
447
+ return undefined;
448
+ const trigger = await property(config, "trigger");
449
+ if (trigger === "absent")
450
+ return undefined;
451
+ if (trigger === "unknown")
452
+ return registrationHash(await reached(config), undefined);
453
+ const declared = await valueOf(trigger);
454
+ const subscribe = await property(declared, "subscribe");
455
+ const unsubscribe = await property(declared, "unsubscribe");
456
+ if (subscribe === "absent")
457
+ return undefined;
458
+ if (subscribe === "unknown" || unsubscribe === "unknown")
459
+ return registrationHash(await reached(trigger), undefined);
460
+ return registrationHash(await reached(subscribe), unsubscribe === "absent" ? undefined : await reached(unsubscribe));
461
+ };
462
+ const found = new Map();
463
+ const root = open(file);
464
+ for (const name of root ? (await exportsOf(root)).keys() : []) {
465
+ const hash = await hashOf(root, name);
466
+ if (hash)
467
+ found.set(name, hash);
468
+ }
469
+ return found;
470
+ }
@@ -1,17 +1,38 @@
1
+ import { QueryClient } from "@tanstack/react-query";
1
2
  import { type AnyRoute, type RouterConstructorOptions, type RouterHistory } from "@tanstack/react-router";
2
- import type { User } from "./types.js";
3
+ import { type ProfileChanges } from "../auth/profileUpdates.js";
4
+ import type { HostMode, User } from "./types.js";
5
+ export declare const QUERY_STALE_TIME_MS = 30000;
3
6
  /** The router context every Zite app's root route declares: `createRootRouteWithContext<ZiteRouterContext>()`. */
4
7
  export type ZiteRouterContext = {
5
8
  user: User | null;
9
+ queryClient: QueryClient;
6
10
  };
7
11
  type Dehydrated = {
8
12
  user: User | null;
13
+ mode?: HostMode;
9
14
  };
15
+ /** @internal What a page carries to the browser beside its queries: the signed-in user, and the mode it was served in. */
16
+ export declare const dehydrateZite: (context: ZiteRouterContext) => Dehydrated;
17
+ /** @internal The user after a profile edit, named as the host names them: first and last name, else the email. */
18
+ export declare const withProfile: (user: User, changes: ProfileChanges) => User;
19
+ /** @internal In the browser: `updateProfile` from zitejs/auth updates the router's user and reruns its guards and loaders. */
20
+ export declare const refreshOnProfileUpdate: (router: {
21
+ invalidate: () => Promise<void>;
22
+ }, context: ZiteRouterContext) => void;
23
+ /** @internal Takes in what the page carried. */
24
+ export declare const hydrateZite: (context: ZiteRouterContext, dehydrated: Dehydrated) => void;
10
25
  type ZiteRouterOptions<TRouteTree extends AnyRoute> = Omit<RouterConstructorOptions<TRouteTree, "never", false, RouterHistory, Dehydrated>, "context" | "dehydrate" | "hydrate">;
11
26
  /**
12
- * The router for `src/router.tsx`. The signed-in user is in `context.user`: on
13
- * the server from the platform, in the browser from the page it rendered, so
14
- * no request asks for it again.
27
+ * @internal Tells the editor's preview the page crashed, as classic's runtime reports an emptied #root: a Start page
28
+ * has none, and an error a route's boundary catches is the crash. Being signed out isn't one.
29
+ */
30
+ export declare const reportCrash: (error: unknown) => void;
31
+ /**
32
+ * The router for `src/router.tsx`. The signed-in user is in `context.user`: on the server from the platform, in the
33
+ * browser from the page it rendered, so no request asks for it again. `context.queryClient` is new for each request
34
+ * on the server, so a page never renders with another visitor's cached queries, and its queries reach the browser
35
+ * with the page.
15
36
  */
16
37
  export declare function createZiteRouter<TRouteTree extends AnyRoute>(options: ZiteRouterOptions<TRouteTree>): import("@tanstack/router-core").RouterCore<TRouteTree, "never", false, RouterHistory, Dehydrated>;
17
38
  export {};