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,262 @@
1
+ /**
2
+ * Database Record Transformation Utilities
3
+ *
4
+ * Shared transformation functions for converting between:
5
+ * - SDK field names ↔ database field IDs
6
+ * - LLM-friendly formats ↔ database formats
7
+ *
8
+ * Used by both workflow-runner and cloudflare-lambda.
9
+ */
10
+ // =============================================================================
11
+ // Reverse Lookup Helpers
12
+ // =============================================================================
13
+ /**
14
+ * Build reverse lookup map: sdkName → fieldId
15
+ */
16
+ export function buildSdkNameToFieldIdMap(fieldMappings) {
17
+ const map = {};
18
+ if (!fieldMappings)
19
+ return map;
20
+ for (const [fieldId, fieldInfo] of Object.entries(fieldMappings)) {
21
+ if (fieldInfo?.mapping?.sdkName) {
22
+ map[fieldInfo.mapping.sdkName] = fieldId;
23
+ // Also add lowercase version for case-insensitive lookup
24
+ map[fieldInfo.mapping.sdkName.toLowerCase()] = fieldId;
25
+ }
26
+ }
27
+ return map;
28
+ }
29
+ // =============================================================================
30
+ // Filter Transformations
31
+ // =============================================================================
32
+ /**
33
+ * Transform SDK field names to database field IDs in filters
34
+ */
35
+ export function transformFiltersToFieldIds(filters, fieldMappings) {
36
+ if (!fieldMappings)
37
+ return filters;
38
+ const sdkNameToFieldId = buildSdkNameToFieldIdMap(fieldMappings);
39
+ const transformed = {};
40
+ for (const [key, value] of Object.entries(filters)) {
41
+ const fieldId = sdkNameToFieldId[key] || sdkNameToFieldId[key.toLowerCase()] || key;
42
+ transformed[fieldId] = value;
43
+ }
44
+ return transformed;
45
+ }
46
+ // =============================================================================
47
+ // Record Input Transformations (SDK → Database)
48
+ // =============================================================================
49
+ /**
50
+ * Transform record data to use field IDs instead of field names.
51
+ *
52
+ * LLMs often use human-readable field names, but the database expects field IDs.
53
+ * Uses a three-step fallback:
54
+ * 1. Check if key is already a valid field ID
55
+ * 2. Match by field name (case-insensitive)
56
+ * 3. Match by SDK name from field mappings
57
+ *
58
+ * @param recordData - The record data with potentially mixed keys
59
+ * @param table - Table definition for field name lookups (optional)
60
+ * @param fieldMappings - SDK name mappings (optional)
61
+ */
62
+ export function transformFieldNamesToIds(recordData, table, fieldMappings) {
63
+ if (!recordData)
64
+ return recordData;
65
+ // If no table definition, fall back to simple SDK name mapping
66
+ if (!table) {
67
+ return transformRecordToFieldIds(recordData, fieldMappings);
68
+ }
69
+ const transformedRecord = {};
70
+ for (const [key, value] of Object.entries(recordData)) {
71
+ // Step 1: Check if it's already a field ID
72
+ const existsAsFieldId = table.fields.some(f => f.id === key);
73
+ if (existsAsFieldId) {
74
+ transformedRecord[key] = value;
75
+ continue;
76
+ }
77
+ // Step 2: Try to find field by name (case-insensitive)
78
+ const fieldByName = table.fields.find(f => f.name.toLowerCase() === key.toLowerCase());
79
+ if (fieldByName) {
80
+ transformedRecord[fieldByName.id] = value;
81
+ continue;
82
+ }
83
+ // Step 3: Try using field mappings (SDK name to field ID)
84
+ if (fieldMappings) {
85
+ const fieldId = Object.keys(fieldMappings).find(id => fieldMappings[id]?.mapping?.sdkName?.toLowerCase() ===
86
+ key.toLowerCase());
87
+ if (fieldId) {
88
+ transformedRecord[fieldId] = value;
89
+ continue;
90
+ }
91
+ }
92
+ // If no mapping found, keep the original key (might be a valid field ID)
93
+ transformedRecord[key] = value;
94
+ }
95
+ return transformedRecord;
96
+ }
97
+ /**
98
+ * Simple transformation using only field mappings (no table definition).
99
+ * Used when table metadata is not available.
100
+ */
101
+ export function transformRecordToFieldIds(recordData, fieldMappings) {
102
+ if (!recordData || !fieldMappings)
103
+ return recordData;
104
+ const sdkNameToFieldId = buildSdkNameToFieldIdMap(fieldMappings);
105
+ const result = {};
106
+ for (const [key, value] of Object.entries(recordData)) {
107
+ // Skip id field
108
+ if (key === 'id' || key === 'recordID') {
109
+ continue;
110
+ }
111
+ const fieldId = sdkNameToFieldId[key] || sdkNameToFieldId[key.toLowerCase()] || key;
112
+ result[fieldId] = value;
113
+ }
114
+ return result;
115
+ }
116
+ /**
117
+ * Transform linked record fields to ensure they are arrays.
118
+ *
119
+ * Handles common LLM mistakes:
120
+ * - Passing a string instead of an array of record IDs
121
+ * - Passing null/undefined instead of an empty array
122
+ * - Passing literal strings like "null" or "undefined"
123
+ *
124
+ * @param recordData - Record data (should already have field IDs as keys)
125
+ * @param table - Table definition for field type lookups
126
+ */
127
+ export function transformLinkedRecordFields(recordData, table) {
128
+ if (!recordData || !table)
129
+ return recordData;
130
+ const transformedRecord = {};
131
+ for (const [key, value] of Object.entries(recordData)) {
132
+ const field = table.fields.find(f => f.id === key);
133
+ if (field?.type === 'linked_record') {
134
+ if (typeof value === 'string') {
135
+ // Filter out LLM-generated placeholder strings
136
+ const cleanValue = value.trim();
137
+ if (cleanValue === '' ||
138
+ cleanValue === 'null' ||
139
+ cleanValue === 'undefined') {
140
+ transformedRecord[key] = [];
141
+ }
142
+ else {
143
+ transformedRecord[key] = [cleanValue];
144
+ }
145
+ }
146
+ else if (value == null) {
147
+ // Convert null/undefined to empty array
148
+ transformedRecord[key] = [];
149
+ }
150
+ else if (Array.isArray(value)) {
151
+ // Filter out any null/undefined/"null"/"undefined" entries
152
+ transformedRecord[key] = value.filter(v => v != null && v !== 'null' && v !== 'undefined');
153
+ }
154
+ else {
155
+ transformedRecord[key] = value;
156
+ }
157
+ }
158
+ else {
159
+ transformedRecord[key] = value;
160
+ }
161
+ }
162
+ return transformedRecord;
163
+ }
164
+ // =============================================================================
165
+ // Record Output Transformations (Database → SDK)
166
+ // =============================================================================
167
+ /**
168
+ * Transform database record to use SDK field names
169
+ *
170
+ * @param record - Raw database record with field IDs
171
+ * @param fieldMappings - SDK name mappings
172
+ */
173
+ export function transformRecordToSdkNames(record, fieldMappings) {
174
+ if (!record)
175
+ return undefined;
176
+ const result = { id: record.id };
177
+ if (!fieldMappings) {
178
+ const { id: _ignoredId, ...dataWithoutId } = record.data;
179
+ return { ...result, ...dataWithoutId };
180
+ }
181
+ for (const [fieldId, value] of Object.entries(record.data)) {
182
+ const mapping = fieldMappings[fieldId];
183
+ const sdkName = mapping?.mapping?.sdkName || fieldId;
184
+ if (sdkName === 'id') {
185
+ continue;
186
+ }
187
+ result[sdkName] = value;
188
+ }
189
+ return result;
190
+ }
191
+ /**
192
+ * Transform an array of SDK field names to field IDs.
193
+ *
194
+ * Used for the `fields` parameter in findOne/findAll to select which fields to return.
195
+ * Uses the same three-step fallback as transformFieldNamesToIds:
196
+ * 1. Check if name is already a valid field ID
197
+ * 2. Match by field name (case-insensitive)
198
+ * 3. Match by SDK name from field mappings
199
+ *
200
+ * @param fields - Array of SDK field names (e.g. ['customerName', 'email'])
201
+ * @param table - Table definition for field name lookups (optional)
202
+ * @param fieldMappings - SDK name mappings (optional)
203
+ * @returns Array of field IDs, or undefined if input is undefined
204
+ */
205
+ export function transformFieldsToFieldIds(fields, table, fieldMappings) {
206
+ if (!fields)
207
+ return undefined;
208
+ const sdkNameToFieldId = buildSdkNameToFieldIdMap(fieldMappings);
209
+ return fields.map(name => {
210
+ // Step 1: Check if it's already a field ID
211
+ if (table?.fields.some(f => f.id === name)) {
212
+ return name;
213
+ }
214
+ // Step 2: Match by human-readable field name (case-insensitive)
215
+ if (table) {
216
+ const fieldByName = table.fields.find(f => f.name.toLowerCase() === name.toLowerCase());
217
+ if (fieldByName)
218
+ return fieldByName.id;
219
+ }
220
+ // Step 3: Match by SDK name from field mappings
221
+ return (sdkNameToFieldId[name] || sdkNameToFieldId[name.toLowerCase()] || name);
222
+ });
223
+ }
224
+ /**
225
+ * Resolve the field references in a sort spec to field IDs.
226
+ *
227
+ * Sort arrives from app code using SDK names (`closeDate`), but base-runner
228
+ * resolves sort fields by field ID or display name only, and silently skips one
229
+ * it cannot match. Running the references through the same resolution order as
230
+ * `fields` is what makes a sort on a multi-word field ("Close date" ->
231
+ * `closeDate`) actually apply instead of being dropped without an error.
232
+ *
233
+ * System sort fields (`id`, `createdAt`, `updatedAt`) have no mapping and fall
234
+ * through unchanged, which is what base-runner expects.
235
+ */
236
+ export function transformSortToFieldIds(sort, table, fieldMappings) {
237
+ if (!sort)
238
+ return undefined;
239
+ const entries = typeof sort === 'string'
240
+ ? [{ field: sort, direction: 'asc' }]
241
+ : sort;
242
+ if (entries.length === 0)
243
+ return undefined;
244
+ const resolved = transformFieldsToFieldIds(entries.map(entry => entry.field), table, fieldMappings);
245
+ return entries.map((entry, index) => ({
246
+ field: resolved?.[index] ?? entry.field,
247
+ direction: entry.direction ?? 'asc',
248
+ }));
249
+ }
250
+ /**
251
+ * Transform matchOn field names to field IDs
252
+ */
253
+ export function transformMatchOnFields(matchOn, fieldMappings) {
254
+ if (!matchOn || !fieldMappings)
255
+ return matchOn;
256
+ const sdkNameToFieldId = buildSdkNameToFieldIdMap(fieldMappings);
257
+ return matchOn.map(fieldName => {
258
+ return (sdkNameToFieldId[fieldName] ||
259
+ sdkNameToFieldId[fieldName.toLowerCase()] ||
260
+ fieldName);
261
+ });
262
+ }
@@ -0,0 +1,91 @@
1
+ export type BaseTable = {
2
+ id: string;
3
+ name: string;
4
+ deletedAt?: string | null;
5
+ fields: Array<{
6
+ id: string;
7
+ name: string;
8
+ type: string;
9
+ deletedAt?: string | null;
10
+ template?: {
11
+ tableId?: string;
12
+ isInverse?: boolean;
13
+ } & Record<string, unknown>;
14
+ }>;
15
+ };
16
+ export type GetBaseResponseType = {
17
+ id: string;
18
+ name: string;
19
+ tables: BaseTable[];
20
+ };
21
+ export interface FindOneResponseType {
22
+ id: string;
23
+ data: Record<string, unknown>;
24
+ fields?: Record<string, unknown>;
25
+ }
26
+ export interface FindAllResponseType {
27
+ records: FindOneResponseType[];
28
+ offset?: string;
29
+ hasMore: boolean;
30
+ total?: number;
31
+ }
32
+ export interface BulkCreateResponseType {
33
+ success?: boolean;
34
+ records: FindOneResponseType[];
35
+ }
36
+ export type LegacyRecordsFilterClauseType = Record<string, unknown>;
37
+ /** Simplified table definition for SDK transformations. */
38
+ export interface SimpleTableDefinition {
39
+ id: string;
40
+ name: string;
41
+ fields: Array<{
42
+ id: string;
43
+ name: string;
44
+ type: string;
45
+ template?: unknown;
46
+ }>;
47
+ }
48
+ /** Field mappings for transforming between SDK names and field IDs */
49
+ export type FieldMappings = Record<string, {
50
+ mapping: {
51
+ sdkName: string;
52
+ };
53
+ }>;
54
+ /** A record after transformation. */
55
+ export interface DatabaseRecord {
56
+ id: string;
57
+ [key: string]: unknown;
58
+ }
59
+ /** The build's tables' and fields' SDK names, by id (`projectConfig.nameMappings`). */
60
+ export type DataNameMappings = {
61
+ tables: Record<string, {
62
+ mapping: {
63
+ sdkName: string;
64
+ };
65
+ fields: Record<string, {
66
+ mapping: {
67
+ sdkName: string;
68
+ };
69
+ }>;
70
+ }>;
71
+ };
72
+ /** base-runner's rename map for SQL, which `buildSdkNameMappingsForBase` builds. */
73
+ export interface NameMappings {
74
+ tables: Record<string, {
75
+ displayName: string;
76
+ fields: Record<string, string>;
77
+ }>;
78
+ linkTables: Record<string, {
79
+ displayName: string;
80
+ sourceIdColumnAlias: string;
81
+ targetIdColumnAlias: string;
82
+ }>;
83
+ }
84
+ /** Marks an error as our fault rather than the app's. */
85
+ export declare const ZITE_PLATFORM_FAULT_FLAG = "zitePlatformFault";
86
+ /** base-runner's refusal, with its status. */
87
+ export declare class DatabasesApiError extends Error {
88
+ readonly statusCode: number;
89
+ readonly statusText: string;
90
+ constructor(message: string, statusCode: number, statusText: string);
91
+ }
@@ -0,0 +1,14 @@
1
+ // Ported from restly's packages/workflow-edge/src/databases/types.ts: the shapes base-runner answers with.
2
+ /** Marks an error as our fault rather than the app's. */
3
+ export const ZITE_PLATFORM_FAULT_FLAG = "zitePlatformFault";
4
+ /** base-runner's refusal, with its status. */
5
+ export class DatabasesApiError extends Error {
6
+ statusCode;
7
+ statusText;
8
+ constructor(message, statusCode, statusText) {
9
+ super(message);
10
+ this.name = "DatabasesApiError";
11
+ this.statusCode = statusCode;
12
+ this.statusText = statusText;
13
+ }
14
+ }
@@ -1,8 +1,11 @@
1
+ import type { ZiteTrigger } from "../backend/index.js";
2
+ import { type AuthHookName } from "./authHooks.js";
1
3
  import type { LoadedWorkflow } from "./workflowRun.js";
2
- import type { WorkflowConfig } from "./workflow.js";
4
+ import type { AutomationConfig } from "./workflow.js";
3
5
  export type Access = {
4
6
  kind: "signedIn" | "anyone" | "webhook" | "none";
5
7
  roles: string[];
8
+ paused?: true;
6
9
  };
7
10
  export type DescribedFunction = {
8
11
  id: string;
@@ -17,40 +20,74 @@ export type DescribedFunction = {
17
20
  };
18
21
  export type DescribedRoute = {
19
22
  path: string;
23
+ file?: string;
24
+ /** From the route's `staticData.description`; display-only. */
25
+ description?: string;
20
26
  methods: Record<string, Access>;
21
27
  problems: string[];
22
28
  };
29
+ /** A route that renders: what the editor's page picker and system map show. */
30
+ export type DescribedPage = {
31
+ id: string;
32
+ path: string;
33
+ file?: string;
34
+ };
23
35
  export type DescribedWorkflow = {
24
36
  id: string;
25
37
  file: string;
26
38
  description?: string;
27
- schedule?: WorkflowConfig["schedule"];
28
- trigger?: WorkflowConfig["trigger"];
39
+ schedule?: AutomationConfig["schedule"];
40
+ /** As declared, without a provider trigger's `subscribe` and `unsubscribe`. */
41
+ trigger?: ZiteTrigger;
42
+ /** A provider trigger's: whether it can be taken down, and a hash of both functions' code, so publish registers it again when they change. */
43
+ registration?: {
44
+ unsubscribe: boolean;
45
+ hash: string;
46
+ };
29
47
  problems: string[];
30
48
  };
31
49
  export type Description = {
32
50
  functions: DescribedFunction[];
33
51
  routes: DescribedRoute[];
52
+ pages: DescribedPage[];
34
53
  workflows: DescribedWorkflow[];
54
+ /** The hooks the app's `zite.auth.ts` defines. */
55
+ authHooks: AuthHookName[];
35
56
  };
36
57
  export declare function describeFunction(id: string, request: Request): Promise<DescribedFunction>;
37
58
  type RouteLike = {
59
+ id: string;
38
60
  fullPath: string;
39
61
  parentRoute?: RouteLike;
40
62
  options?: {
63
+ path?: string;
64
+ component?: unknown;
65
+ staticData?: {
66
+ description?: unknown;
67
+ };
41
68
  server?: {
42
69
  middleware?: unknown[];
43
70
  handlers?: unknown;
44
71
  };
45
72
  };
46
73
  };
47
- export declare function describeRoutes(routesById: Record<string, RouteLike>): DescribedRoute[];
48
- export declare function describeWorkflows(workflows: LoadedWorkflow[]): DescribedWorkflow[];
74
+ export declare function describePages(routesById: Record<string, RouteLike>, files?: Record<string, string>): DescribedPage[];
75
+ export declare function describeRoutes(routesById: Record<string, RouteLike>, files?: Record<string, string>): DescribedRoute[];
76
+ export declare function describeWorkflows(workflows: LoadedWorkflow[], hashes?: Record<string, string>, unfinished?: Array<{
77
+ id: string;
78
+ file: string;
79
+ }>): DescribedWorkflow[];
49
80
  export declare function describeApp(opts: {
50
81
  fnIds: string[];
51
82
  descriptions?: Record<string, string>;
83
+ routeFiles?: Record<string, string>;
84
+ registrationHashes?: Record<string, string>;
52
85
  getRouter: () => unknown;
53
86
  request: Request;
54
87
  workflows?: LoadedWorkflow[];
88
+ unfinishedWorkflows?: Array<{
89
+ id: string;
90
+ file: string;
91
+ }>;
55
92
  }): Promise<Description>;
56
93
  export {};
@@ -5,6 +5,8 @@ import { createSsrRpc } from "@tanstack/react-start/ssr-rpc";
5
5
  import { runWithStartContext } from "@tanstack/start-storage-context";
6
6
  import { z } from "zod";
7
7
  import { ziteMiddlewareKind } from "./index.js";
8
+ import { loadAuthHooks } from "./authHooks.js";
9
+ import { canonicalNames, registrationHash } from "./registrationHash.js";
8
10
  const accessOf = (chain, problems) => {
9
11
  const kinds = chain.map(ziteMiddlewareKind).filter((k) => !!k);
10
12
  const roles = kinds.flatMap((k) => (k.kind === "role" ? [k.role] : []));
@@ -16,7 +18,8 @@ const accessOf = (chain, problems) => {
16
18
  if (base.length > 1)
17
19
  problems.push(`access-conflict: ${base.join(" + ")}`);
18
20
  const kind = base.includes("webhook") ? "webhook" : base.includes("signedIn") ? "signedIn" : "anyone";
19
- return { kind, roles };
21
+ const paused = kinds.some((k) => k.kind === "webhook" && k.paused === true);
22
+ return paused ? { kind, roles, paused } : { kind, roles };
20
23
  };
21
24
  const jsonSchemaOf = (validator) => {
22
25
  if (validator && typeof validator === "object" && "_zod" in validator) {
@@ -42,20 +45,19 @@ const SERVER_ONLY = "server-only: nothing in the browser calls it, and a server
42
45
  "Move the shared logic into a *.server.ts helper and call that.";
43
46
  export async function describeFunction(id, request) {
44
47
  const problems = [];
45
- const seen = [];
48
+ let own;
46
49
  probe = { reached: false };
47
- // Before running a chain, TanStack asks this set about every middleware in it.
48
- // Recording the questions gives the exact chain it would have run.
49
- const executedRequestMiddlewares = {
50
- has: (middleware) => {
51
- seen.push(middleware);
52
- return false;
50
+ // TanStack appends the function's own chain to the global middleware with
51
+ // `concat`. Recording what it appends gives the exact chain it would have run.
52
+ const functionMiddleware = Object.assign([describeProbe], {
53
+ concat: (chain) => {
54
+ own = chain;
55
+ return [describeProbe, ...chain];
53
56
  },
54
- };
57
+ });
55
58
  const startContext = {
56
59
  request,
57
- startOptions: { functionMiddleware: [describeProbe] },
58
- executedRequestMiddlewares,
60
+ startOptions: { functionMiddleware },
59
61
  contextAfterGlobalMiddlewares: {},
60
62
  handlerType: "serverFn",
61
63
  getRouter: () => {
@@ -77,14 +79,15 @@ export async function describeFunction(id, request) {
77
79
  }
78
80
  const state = probe;
79
81
  probe = null;
80
- // Fails closed: if TanStack stops asking, or stops running globals first, every
82
+ // Fails closed: if TanStack stops appending, or the probe never runs, every
81
83
  // function reports a problem and the build stops.
82
- if (!state.reached || seen[0] !== describeProbe)
84
+ if (!state.reached || own === undefined)
83
85
  problems.push("probe-not-first: chain could not be read");
84
- const chain = seen.filter((m) => m !== describeProbe);
86
+ const chain = flattenMiddlewares((own ?? [])).filter((m) => m !== describeProbe);
85
87
  if (!chain.some((m) => ziteMiddlewareKind(m)?.kind === "factory")) {
86
88
  problems.push("raw-server-fn: define it with signedInFn or publicFn from zitejs/start");
87
89
  }
90
+ // TanStack keeps the validator under `inputValidator` up to 1.168 and `validator` from 1.169 (Start 1.0).
88
91
  const handlerStep = chain.at(-1);
89
92
  return {
90
93
  id,
@@ -92,11 +95,24 @@ export async function describeFunction(id, request) {
92
95
  file: state.meta?.filename,
93
96
  method: state.method,
94
97
  access: accessOf(chain, problems),
95
- input: jsonSchemaOf(handlerStep?.options?.inputValidator),
98
+ input: jsonSchemaOf(handlerStep?.options?.validator ?? handlerStep?.options?.inputValidator),
96
99
  problems,
97
100
  };
98
101
  }
99
- export function describeRoutes(routesById) {
102
+ const ROOT_ROUTE_ID = "__root__";
103
+ // Pathless layouts have no path of their own, and a file with only server handlers is an API route.
104
+ export function describePages(routesById, files = {}) {
105
+ return Object.values(routesById).flatMap((route) => {
106
+ const options = route.options ?? {};
107
+ if (route.id === ROOT_ROUTE_ID || options.path === undefined)
108
+ return [];
109
+ if (options.server?.handlers && !options.component)
110
+ return [];
111
+ const file = files[route.id];
112
+ return [{ id: route.id, path: route.fullPath, ...(file && { file }) }];
113
+ });
114
+ }
115
+ export function describeRoutes(routesById, files = {}) {
100
116
  const out = [];
101
117
  for (const route of Object.values(routesById)) {
102
118
  const server = route.options?.server;
@@ -118,13 +134,23 @@ export function describeRoutes(routesById) {
118
134
  methods[method] = accessOf(chain, methodProblems);
119
135
  problems.push(...methodProblems.map((p) => `${method}: ${p}`));
120
136
  }
121
- out.push({ path: route.fullPath, methods, problems });
137
+ const file = files[route.id];
138
+ const description = route.options?.staticData?.description;
139
+ out.push({
140
+ path: route.fullPath,
141
+ ...(file && { file }),
142
+ ...(typeof description === "string" && description && { description }),
143
+ methods,
144
+ problems,
145
+ });
122
146
  }
123
147
  return out;
124
148
  }
125
- // A workflow's id is its export name: what the host invokes it by and the editor shows.
126
- export function describeWorkflows(workflows) {
127
- return workflows.map(({ id, file, workflow }) => {
149
+ const HANDLER_MISSING = "workflow-handler-missing: give createAutomation its function with .handler(async (args) => { ... }), not in its config";
150
+ // A workflow's id is its export name: what the host invokes it by and the editor shows. `hashes` are the registration
151
+ // hashes zite() read from the app's source; one it couldn't read is hashed from the built functions, names numbered.
152
+ export function describeWorkflows(workflows, hashes = {}, unfinished = []) {
153
+ const described = workflows.map(({ id, file, workflow }) => {
128
154
  const problems = [];
129
155
  if (id === "default")
130
156
  problems.push("workflow-default-export: export it by name, which becomes its id");
@@ -132,8 +158,30 @@ export function describeWorkflows(workflows) {
132
158
  if (elsewhere)
133
159
  problems.push(`duplicate-workflow: ${id} is also exported from ${elsewhere.file}`);
134
160
  const { description, schedule, trigger } = workflow.config;
135
- return { id, file, description, ...(schedule ? { schedule } : { trigger }), problems };
161
+ if (schedule)
162
+ return { id, file, description, schedule, problems };
163
+ if (!trigger || trigger.every !== undefined || trigger.events !== undefined) {
164
+ return { id, file, description, trigger, problems };
165
+ }
166
+ const { subscribe, unsubscribe, ...declared } = trigger;
167
+ // The types refuse them, but a build doesn't typecheck.
168
+ if ("table" in declared || "form" in declared) {
169
+ problems.push("trigger-unsupported: a Start automation can't take a database or form trigger yet");
170
+ return { id, file, description, trigger: declared, problems };
171
+ }
172
+ if (typeof subscribe !== "function") {
173
+ problems.push("workflow-trigger-unregistered: a provider trigger needs `subscribe` to register it with the provider");
174
+ return { id, file, description, trigger: declared, problems };
175
+ }
176
+ const registration = {
177
+ unsubscribe: typeof unsubscribe === "function",
178
+ hash: Object.hasOwn(hashes, id)
179
+ ? hashes[id]
180
+ : registrationHash(canonicalNames(String(subscribe)), typeof unsubscribe === "function" ? canonicalNames(String(unsubscribe)) : undefined),
181
+ };
182
+ return { id, file, description, trigger: declared, registration, problems };
136
183
  });
184
+ return [...described, ...unfinished.map(({ id, file }) => ({ id, file, problems: [HANDLER_MISSING] }))];
137
185
  }
138
186
  export async function describeApp(opts) {
139
187
  const functions = [];
@@ -142,6 +190,12 @@ export async function describeApp(opts) {
142
190
  const description = opts.descriptions?.[id];
143
191
  functions.push(description ? { ...described, description } : described);
144
192
  }
145
- const router = (await opts.getRouter());
146
- return { functions, routes: describeRoutes(router.routesById), workflows: describeWorkflows(opts.workflows ?? []) };
193
+ const { routesById } = (await opts.getRouter());
194
+ return {
195
+ functions,
196
+ routes: describeRoutes(routesById, opts.routeFiles),
197
+ pages: describePages(routesById, opts.routeFiles),
198
+ workflows: describeWorkflows(opts.workflows ?? [], opts.registrationHashes, opts.unfinishedWorkflows),
199
+ authHooks: Object.keys(await loadAuthHooks()),
200
+ };
147
201
  }
@@ -1,16 +1,22 @@
1
- import type { SourceDir } from "../sourceRoots.js";
1
+ import { type SourceDir } from "../sourceRoots.js";
2
2
  export declare const START_SERVER_ENTRY = ".zite/server.ts";
3
3
  export declare const START_INSTANCE_ENTRY = ".zite/start.ts";
4
- /** The server entry every Start app builds with. Platform-owned: regenerated, never edited. */
5
- export declare const renderStartServerEntry: () => string;
4
+ export type StartTarget = "cloudflare" | "node";
5
+ /**
6
+ * The server entry every Start app builds with. Platform-owned: regenerated,
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.
9
+ */
10
+ export declare const renderStartServerEntry: (target?: StartTarget) => string;
6
11
  /** The start instance: the platform's middleware, then the app's own `src/start.ts` when it has one. */
7
12
  export declare const renderStartInstance: (hasAppStart: boolean) => string;
8
13
  export declare const hasAppStart: (appDir: string) => boolean;
9
14
  /** Writes `file` under `appDir` when its content differs. Returns whether it wrote. */
10
15
  export declare const writeIfChanged: (appDir: string, file: string, content: string) => boolean;
11
16
  export declare const isStartAppDir: (appPath: string) => boolean;
17
+ export declare const workspaceHasStartApps: () => boolean;
12
18
  export declare function regenerateStartEntries(app: SourceDir): void;
13
- /** App modules that mention createWorkflow: what the workflow registry imports. Describe decides what each one really exports. */
19
+ /** App modules that mention createAutomation: what the workflow registry imports. Describe decides what each one really exports. */
14
20
  export declare function workflowFiles(appDir: string): string[];
15
21
  /** The registry zite() builds in place of zitejs's empty one. */
16
22
  export declare const renderWorkflowModules: (appDir: string, files: string[]) => string;