@somewhere-tech/cli 0.31.17 → 0.31.19

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 (79) hide show
  1. package/dist/commands/browser.js +1 -1
  2. package/dist/commands/browser.js.map +1 -1
  3. package/dist/commands/check.js +1 -2
  4. package/dist/commands/check.js.map +1 -1
  5. package/dist/commands/dev.js +18 -383
  6. package/dist/commands/dev.js.map +1 -1
  7. package/dist/commands/status.js +0 -36
  8. package/dist/commands/status.js.map +1 -1
  9. package/dist/commands/typecheck.js +1 -1
  10. package/dist/commands/typecheck.js.map +1 -1
  11. package/dist/commands/verify.js +1 -1
  12. package/dist/commands/verify.js.map +1 -1
  13. package/dist/index.js +0 -2
  14. package/dist/index.js.map +1 -1
  15. package/dist/{local → lib}/browser-run.js +1 -1
  16. package/dist/lib/browser-run.js.map +1 -0
  17. package/dist/lib/chrome.js.map +1 -0
  18. package/dist/lib/envfile-write.js +2 -2
  19. package/dist/lib/envfile-write.js.map +1 -1
  20. package/dist/lib/frontend-dev.js +122 -0
  21. package/dist/lib/frontend-dev.js.map +1 -0
  22. package/dist/lib/init-agent-guide.js +15 -19
  23. package/dist/lib/init-agent-guide.js.map +1 -1
  24. package/dist/lib/init-green-template.js +1 -1
  25. package/dist/lib/platform-tools.js +4 -1
  26. package/dist/lib/platform-tools.js.map +1 -1
  27. package/dist/lib/project-urls.js +13 -0
  28. package/dist/lib/project-urls.js.map +1 -1
  29. package/npm-shrinkwrap.json +2 -17
  30. package/package.json +4 -6
  31. package/runtime/VENDOR.json +0 -2
  32. package/dist/commands/exec.js +0 -145
  33. package/dist/commands/exec.js.map +0 -1
  34. package/dist/local/browser-run.js.map +0 -1
  35. package/dist/local/chrome.js.map +0 -1
  36. package/dist/local/compiler-core.js +0 -51
  37. package/dist/local/compiler-core.js.map +0 -1
  38. package/dist/local/compiler.js +0 -683
  39. package/dist/local/compiler.js.map +0 -1
  40. package/dist/local/dev-server.js +0 -517
  41. package/dist/local/dev-server.js.map +0 -1
  42. package/dist/local/envfile.js +0 -40
  43. package/dist/local/envfile.js.map +0 -1
  44. package/dist/local/loader.js +0 -299
  45. package/dist/local/loader.js.map +0 -1
  46. package/dist/local/loopback.js +0 -129
  47. package/dist/local/loopback.js.map +0 -1
  48. package/dist/local/request-timing.js +0 -101
  49. package/dist/local/request-timing.js.map +0 -1
  50. package/dist/local/router.js +0 -114
  51. package/dist/local/router.js.map +0 -1
  52. package/dist/local/runtime.js +0 -345
  53. package/dist/local/runtime.js.map +0 -1
  54. package/dist/local/server.js +0 -309
  55. package/dist/local/server.js.map +0 -1
  56. package/dist/local/telemetry-filter.js +0 -120
  57. package/dist/local/telemetry-filter.js.map +0 -1
  58. package/node_modules/esbuild-wasm/LICENSE.md +0 -21
  59. package/node_modules/esbuild-wasm/README.md +0 -3
  60. package/node_modules/esbuild-wasm/bin/esbuild +0 -91
  61. package/node_modules/esbuild-wasm/esbuild.wasm +0 -0
  62. package/node_modules/esbuild-wasm/esm/browser.d.ts +0 -705
  63. package/node_modules/esbuild-wasm/esm/browser.js +0 -2393
  64. package/node_modules/esbuild-wasm/esm/browser.min.js +0 -20
  65. package/node_modules/esbuild-wasm/lib/browser.d.ts +0 -705
  66. package/node_modules/esbuild-wasm/lib/browser.js +0 -2438
  67. package/node_modules/esbuild-wasm/lib/browser.min.js +0 -22
  68. package/node_modules/esbuild-wasm/lib/main.d.ts +0 -705
  69. package/node_modules/esbuild-wasm/lib/main.js +0 -2051
  70. package/node_modules/esbuild-wasm/package.json +0 -19
  71. package/node_modules/esbuild-wasm/wasm_exec.js +0 -561
  72. package/node_modules/esbuild-wasm/wasm_exec_node.js +0 -39
  73. package/runtime/compiler/VENDOR.json +0 -64
  74. package/runtime/compiler/compile-core.cjs +0 -2007
  75. package/runtime/compiler/graph-contract.cjs +0 -124
  76. package/runtime/compiler/typed-functions.cjs +0 -575
  77. package/runtime/platform-context.mjs +0 -8193
  78. package/runtime/sw-init.mjs +0 -283
  79. /package/dist/{local → lib}/chrome.js +0 -0
@@ -1,114 +0,0 @@
1
- /**
2
- * File-based routing for the local function runtime — a faithful port of the
3
- * deploy pipeline's route compiler + matcher (worker/src/utils/function-bundle.ts:
4
- * compileRoutePattern / routeSpecificityKey / matchRoute), so a URL resolves to
5
- * the same function locally as it does deployed.
6
- *
7
- * api/hello.ts → /api/hello (static)
8
- * api/sites/[id].ts → /api/sites/:id (param)
9
- * api/files/[...path].ts → /api/files/*path (catch-all)
10
- * [...path].ts (root) → /*path (root catch-all)
11
- *
12
- * Static beats param beats rest. `_lib/` and plain root files are bundled for
13
- * imports but never routed.
14
- */
15
- export function compileRoutePattern(file) {
16
- const noExt = file.replace(/\.(ts|tsx|mts|js|mjs|jsx)$/, '');
17
- const parts = noExt.split('/');
18
- const pattern = [];
19
- const display = [];
20
- parts.forEach((seg, i) => {
21
- const rest = seg.match(/^\[\.\.\.([a-zA-Z_][a-zA-Z0-9_]*)\]$/);
22
- if (rest) {
23
- if (i !== parts.length - 1) {
24
- throw new Error(`catch-all [...${rest[1]}] must be the last path segment: ${file}`);
25
- }
26
- pattern.push({ type: 'rest', value: rest[1] });
27
- display.push(`*${rest[1]}`);
28
- return;
29
- }
30
- const param = seg.match(/^\[([a-zA-Z_][a-zA-Z0-9_]*)\]$/);
31
- if (param) {
32
- pattern.push({ type: 'param', value: param[1] });
33
- display.push(`:${param[1]}`);
34
- return;
35
- }
36
- if (/[\[\]]/.test(seg)) {
37
- throw new Error(`malformed parametric segment "${seg}" in ${file}. Use [name] or [...name].`);
38
- }
39
- pattern.push({ type: 'static', value: seg });
40
- display.push(seg);
41
- });
42
- return { pattern, displayPath: '/' + display.join('/') };
43
- }
44
- function routeSpecificityKey(pattern) {
45
- return pattern.map((s) => (s.type === 'static' ? '2' : s.type === 'param' ? '1' : '0')).join('');
46
- }
47
- function hasRestSegment(pattern) {
48
- return pattern.some((s) => s.type === 'rest');
49
- }
50
- export function isRoutable(file) {
51
- const isRootParametric = !file.includes('/') && /\[/.test(file);
52
- return file.startsWith('api/') || isRootParametric;
53
- }
54
- /**
55
- * Compile + sort routes most-specific first, mirroring buildFunctionBundle:
56
- * non-rest beats rest; within a group, segment-wise static > param wins.
57
- * Throws on two files compiling to the same route (same deploy-time error).
58
- */
59
- export function compileRoutes(files) {
60
- const routes = [];
61
- for (const { file, absPath } of files) {
62
- if (!isRoutable(file))
63
- continue;
64
- const { pattern, displayPath } = compileRoutePattern(file);
65
- routes.push({ file, absPath, pattern, displayPath });
66
- }
67
- const seen = new Map();
68
- for (const r of routes) {
69
- const prior = seen.get(r.displayPath);
70
- if (prior) {
71
- throw new Error(`Two functions compile to the same route "${r.displayPath}": ${prior} and ${r.file}`);
72
- }
73
- seen.set(r.displayPath, r.file);
74
- }
75
- routes.sort((a, b) => {
76
- const aRest = hasRestSegment(a.pattern);
77
- const bRest = hasRestSegment(b.pattern);
78
- if (aRest !== bRest)
79
- return aRest ? 1 : -1;
80
- const ka = routeSpecificityKey(a.pattern);
81
- const kb = routeSpecificityKey(b.pattern);
82
- return kb.localeCompare(ka);
83
- });
84
- return routes;
85
- }
86
- /** Walk routes in order and return the first match — port of the shim's matchRoute. */
87
- export function matchRoute(routes, pathname) {
88
- const urlSegs = pathname.split('/').filter(Boolean);
89
- outer: for (const route of routes) {
90
- const params = {};
91
- const pat = route.pattern;
92
- for (let i = 0; i < pat.length; i++) {
93
- const p = pat[i];
94
- if (p.type === 'rest') {
95
- params[p.value] = urlSegs.slice(i).map(decodeURIComponent).join('/');
96
- return { route, params };
97
- }
98
- if (i >= urlSegs.length)
99
- continue outer;
100
- if (p.type === 'static') {
101
- if (urlSegs[i] !== p.value)
102
- continue outer;
103
- }
104
- else {
105
- params[p.value] = decodeURIComponent(urlSegs[i]);
106
- }
107
- }
108
- if (pat.length === urlSegs.length) {
109
- return { route, params };
110
- }
111
- }
112
- return null;
113
- }
114
- //# sourceMappingURL=router.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"router.js","sourceRoot":"","sources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3B,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -1,345 +0,0 @@
1
- /**
2
- * The local function runtime behind `somewhere dev --local` and
3
- * `somewhere exec`: run a project's functions in local Node while every
4
- * sw.* binding talks to the real platform over the same REST surface the
5
- * deployed runtime uses.
6
- *
7
- * Contract fidelity comes from running the VENDORED deployed runtime
8
- * (runtime/platform-context.mjs + runtime/sw-init.mjs — extracted verbatim
9
- * from the deploy pipeline) rather than a reimplementation. The deployed
10
- * shim's REST fallback path (no D1 binding) is exactly the local path: we
11
- * build the same `env` bindings object it expects, minus PROJECT_DB.
12
- *
13
- * Local-only deviations, all deliberate:
14
- * - sw.env is a fail-loud proxy: keys that exist on the platform but have
15
- * no local value THROW on access (the env API never returns values).
16
- * - Handler errors return the real message + stack in the response body
17
- * (deployed keeps them in logs only) — it's your own terminal.
18
- * - Uncaught errors print to the terminal instead of POSTing to /v1/logs.
19
- */
20
- import { readdirSync } from 'node:fs';
21
- import { dirname, join, relative } from 'node:path';
22
- import { fileURLToPath, pathToFileURL } from 'node:url';
23
- import { IGNORE } from '../lib/files.js';
24
- import { fallbackProjectServingUrl } from '../lib/project-urls.js';
25
- import { compileRoutes, matchRoute } from './router.js';
26
- import { entryUrl } from './loader.js';
27
- import { loadLocalEnv } from './envfile.js';
28
- import { installTelemetryFilter } from './telemetry-filter.js';
29
- import { LocalRequestTiming } from './request-timing.js';
30
- function packageRoot() {
31
- // dist/local/runtime.js → package root is two levels up.
32
- return join(dirname(fileURLToPath(import.meta.url)), '..', '..');
33
- }
34
- let contextModule = null;
35
- /** Import the vendored runtime once: sw-init (globalThis.sw.endpoint) + context factory. */
36
- export async function loadVendoredRuntime() {
37
- if (contextModule)
38
- return contextModule;
39
- // The vendored runtime instruments itself for the platform's telemetry sink,
40
- // which does not exist on this machine — so its output would land in the
41
- // developer's terminal instead. Filter it here, at the one place the runtime
42
- // enters the process (tsk_eef0a0ef).
43
- installTelemetryFilter();
44
- const root = packageRoot();
45
- await import(pathToFileURL(join(root, 'runtime', 'sw-init.mjs')).href);
46
- contextModule = (await import(pathToFileURL(join(root, 'runtime', 'platform-context.mjs')).href));
47
- return contextModule;
48
- }
49
- /**
50
- * One row of GET /db/scopes. `intent` is what the platform PROVED about the
51
- * table — user-owned, shared, server-only, or membership-joined — and it is
52
- * what the structured query API (`sw.db.from` and friends) asks for before it
53
- * will compose any SQL. Reading only `owner_column` and dropping the intent is
54
- * why a `shared()` table came back locally as "this table has no declared
55
- * intent" while working perfectly on the same deployed project
56
- * (tsk_a21bc829).
57
- */
58
- /**
59
- * Env values the platform provides for a project, resolved for a local run.
60
- *
61
- * Anything named here is NOT the developer's to supply, so it must never be
62
- * reported as a value they forgot. Keep this to keys the platform genuinely
63
- * writes on their behalf — a key the developer owns belongs in their .env, and
64
- * silently inventing a value for one would be worse than the warning.
65
- */
66
- export function platformProvidedEnv(ctx) {
67
- const appUrl = ctx.localOrigin ?? fallbackProjectServingUrl({ subdomain: ctx.subdomain ?? null });
68
- return appUrl ? { APP_URL: appUrl } : {};
69
- }
70
- /** Walk the project dir and return every function-routable source file. */
71
- export function collectFunctionFiles(cwd) {
72
- const out = [];
73
- const walk = (dir) => {
74
- for (const entry of readdirSync(dir, { withFileTypes: true })) {
75
- if (IGNORE.has(entry.name) || entry.name.startsWith('.'))
76
- continue;
77
- const full = join(dir, entry.name);
78
- if (entry.isDirectory()) {
79
- walk(full);
80
- continue;
81
- }
82
- if (!entry.isFile())
83
- continue;
84
- const rel = relative(cwd, full).split('\\').join('/');
85
- if (!/\.(ts|tsx|mts|js|mjs|jsx)$/i.test(rel))
86
- continue;
87
- // Same key remapping as deploy: functions/ prefix is stripped; api/,
88
- // _lib/ and root parametric files at the root are functions as-is.
89
- const key = rel.startsWith('functions/') ? rel.slice('functions/'.length) : rel;
90
- out.push({ file: key, absPath: full });
91
- }
92
- };
93
- walk(cwd);
94
- return out;
95
- }
96
- /**
97
- * Fetch everything the runtime needs from the platform (project info, env
98
- * key list, table scopes), merge local env values, and compile routes.
99
- */
100
- export async function prepareLocalProject(client, token, projectId, cwd, opts = {}) {
101
- const [project, envResult, scopesResult] = await Promise.all([
102
- client.call('GET', `/projects/${encodeURIComponent(projectId)}`),
103
- client.call('GET', '/env', undefined, {
104
- project_id: projectId,
105
- }),
106
- client
107
- .call('GET', '/db/scopes', undefined, { project_id: projectId })
108
- .catch(() => ({ scopes: [] })),
109
- ]);
110
- const remoteKeys = (envResult.keys ?? envResult.vars ?? []).map((k) => k.key);
111
- const localFileEnv = loadLocalEnv(cwd);
112
- const values = {};
113
- for (const key of remoteKeys) {
114
- const local = localFileEnv[key] ?? process.env[key];
115
- if (local !== undefined)
116
- values[key] = local;
117
- }
118
- // Local-only keys are honored too — useful before the first `somewhere env set`.
119
- for (const [key, value] of Object.entries(localFileEnv)) {
120
- if (!(key in values))
121
- values[key] = value;
122
- }
123
- // Keys the PLATFORM sets, not the developer. APP_URL is written by deploy
124
- // and holds wherever the app is being served; the developer never authored
125
- // it, so reporting it back as one of THEIR missing values sent a first-time
126
- // user off to write a .env entry for a variable that is not theirs, and
127
- // devalued every real warning beside it (tsk_6a2a09bc5d).
128
- //
129
- // Locally the answer is knowable: the app is being served right here. Fill it
130
- // with the local origin when there is one, and otherwise with the project's
131
- // public URL — which is what the platform fills it with, and what run_code
132
- // already does for the same key.
133
- for (const [key, value] of Object.entries(platformProvidedEnv({ localOrigin: opts.localOrigin, subdomain: project.subdomain }))) {
134
- if (remoteKeys.includes(key) && !(key in values))
135
- values[key] = value;
136
- }
137
- const missingEnvKeys = remoteKeys.filter((k) => !(k in values));
138
- // The scope bake, mirroring what deploy bakes into a function bundle. Two
139
- // maps, and the runtime treats a disagreement between them as a bad bundle:
140
- // PROJECT_SCOPES carries an owner column ONLY for a user-owned table, and
141
- // every entry in it must have a matching `scoped` intent.
142
- const scopes = {};
143
- const intents = {};
144
- for (const s of scopesResult.scopes ?? []) {
145
- const table = s.table.toLowerCase();
146
- const intent = s.intent ?? (s.owner_column ? 'scoped' : undefined);
147
- if (!intent)
148
- continue;
149
- intents[table] = intent;
150
- if (intent === 'scoped' && s.owner_column)
151
- scopes[table] = s.owner_column;
152
- }
153
- // Mirror of the deploy pipeline's bindings (buildFunctionBundle), minus
154
- // PROJECT_DB — its absence selects the runtime's REST db path, which is
155
- // exactly what local dev wants.
156
- const bindings = {
157
- PROJECT_ID: project.id,
158
- SUBDOMAIN: project.subdomain,
159
- TIER: 'free', // tier isn't readable over the project API; only informational in the runtime
160
- PROJECT_API_KEY: token,
161
- USER_ENV: JSON.stringify(values),
162
- PROJECT_SCOPES: JSON.stringify(scopes),
163
- PROJECT_ENV: 'dev',
164
- };
165
- // Baked only when there is something to say, exactly like the deploy bundle:
166
- // an absent binding is the runtime's own "nothing declared" default, and
167
- // baking an empty map instead would be a different statement.
168
- if (Object.keys(intents).length > 0) {
169
- bindings.PROJECT_TABLE_INTENTS = JSON.stringify(intents);
170
- }
171
- // Who owns a row on a signed-out request. Baked only for 'visitor', matching
172
- // deploy — an absent binding reads as 'authenticated'.
173
- if (scopesResult.owner_identity_mode === 'visitor') {
174
- bindings.PROJECT_OWNER_IDENTITY_MODE = 'visitor';
175
- }
176
- const files = collectFunctionFiles(cwd);
177
- const routes = compileRoutes(files);
178
- return {
179
- projectId: project.id,
180
- subdomain: project.subdomain,
181
- cwd,
182
- bindings,
183
- missingEnvKeys,
184
- localEnvKeys: Object.keys(values),
185
- routes,
186
- localDevDbAllowed: typeof project.local_dev_db_allowed === 'boolean'
187
- ? project.local_dev_db_allowed
188
- : null,
189
- localDevDbPlans: Array.isArray(project.local_dev_db_required_plans)
190
- ? project.local_dev_db_required_plans.filter((p) => typeof p === 'string')
191
- : [],
192
- };
193
- }
194
- /** Re-scan the directory and recompile routes (after add/remove of files). */
195
- export function refreshRoutes(state) {
196
- state.routes = compileRoutes(collectFunctionFiles(state.cwd));
197
- }
198
- // ─── sw.env fail-loud proxy ─────────────────────────────────────────────────
199
- function makeEnvProxy(values, missingKeys) {
200
- const missing = new Set(missingKeys);
201
- return new Proxy({ ...values }, {
202
- get(target, prop, receiver) {
203
- if (typeof prop !== 'string')
204
- return Reflect.get(target, prop, receiver);
205
- if (prop in target)
206
- return target[prop];
207
- if (missing.has(prop)) {
208
- throw new Error(`sw.env.${prop} is set on the platform, but env values can't be fetched over the API. ` +
209
- `Add ${prop}=... to a .env file in your project root (never deployed) or export it ` +
210
- `in your shell, then restart \`somewhere dev\`.`);
211
- }
212
- return undefined;
213
- },
214
- has(target, prop) {
215
- return Reflect.has(target, prop) || (typeof prop === 'string' && missing.has(prop));
216
- },
217
- ownKeys(target) {
218
- return [...new Set([...Reflect.ownKeys(target), ...missing])];
219
- },
220
- getOwnPropertyDescriptor(target, prop) {
221
- const own = Reflect.getOwnPropertyDescriptor(target, prop);
222
- if (own)
223
- return own;
224
- if (typeof prop === 'string' && missing.has(prop)) {
225
- return { enumerable: true, configurable: true, value: undefined };
226
- }
227
- return undefined;
228
- },
229
- });
230
- }
231
- // ─── Dispatch (port of the generated index.mjs fetch handler) ───────────────
232
- function jsonError(status, code, message) {
233
- return new Response(JSON.stringify({ ok: false, error: code, message }), {
234
- status,
235
- headers: { 'Content-Type': 'application/json' },
236
- });
237
- }
238
- /** Port of the shim's attachPendingRefresh — auth auto-refresh headers + cookies. */
239
- function attachPendingRefresh(response, ctx) {
240
- const pending = ctx.__sw_pendingRefresh;
241
- const cookies = ctx.__sw_pendingCookies ?? [];
242
- const hasRefresh = !!(pending && pending.access && pending.refresh);
243
- if (!hasRefresh && cookies.length === 0)
244
- return response;
245
- const headers = new Headers(response.headers);
246
- if (hasRefresh && pending) {
247
- headers.set('X-New-Access-Token', pending.access);
248
- headers.set('X-New-Refresh-Token', pending.refresh);
249
- }
250
- for (const c of cookies)
251
- headers.append('Set-Cookie', c);
252
- return new Response(response.body, {
253
- status: response.status,
254
- statusText: response.statusText,
255
- headers,
256
- });
257
- }
258
- /**
259
- * Route one Request through the local runtime: match → import (current
260
- * generation) → buildPlatformContext → handler → response envelope.
261
- */
262
- export async function dispatchRequest(request, state) {
263
- const url = new URL(request.url);
264
- const match = matchRoute(state.routes, url.pathname);
265
- if (!match) {
266
- return {
267
- response: jsonError(404, 'FUNCTION_NOT_FOUND', 'No function registered at ' + url.pathname),
268
- route: null,
269
- };
270
- }
271
- let mod;
272
- try {
273
- mod = (await import(entryUrl(match.route.absPath)));
274
- }
275
- catch (err) {
276
- return {
277
- response: jsonError(500, 'FUNCTION_LOAD_FAILED', `${match.route.file} failed to load: ${err instanceof Error ? err.message : String(err)}`),
278
- route: match.route.displayPath,
279
- error: err,
280
- };
281
- }
282
- const method = request.method.toUpperCase();
283
- const handler = (mod[method] ?? mod.default);
284
- if (typeof handler !== 'function') {
285
- return {
286
- response: jsonError(405, 'METHOD_NOT_ALLOWED', method + ' not supported on ' + match.route.displayPath),
287
- route: match.route.displayPath,
288
- };
289
- }
290
- try {
291
- Object.defineProperty(request, 'params', {
292
- value: match.params,
293
- enumerable: true,
294
- configurable: true,
295
- writable: true,
296
- });
297
- }
298
- catch {
299
- // frozen Request — sw.params still carries them
300
- }
301
- const { buildPlatformContext } = await loadVendoredRuntime();
302
- const requestTiming = new LocalRequestTiming();
303
- let ctx;
304
- try {
305
- ctx = buildPlatformContext(state.bindings, request, requestTiming.fetch);
306
- ctx.params = match.params;
307
- // Swap the plain env object for the fail-loud proxy (see module docs).
308
- ctx.env = makeEnvProxy(JSON.parse(state.bindings.USER_ENV || '{}'), state.missingEnvKeys);
309
- }
310
- catch (err) {
311
- return {
312
- response: jsonError(500, 'CONTEXT_BUILD_FAILED', `Function context could not be built: ${err instanceof Error ? err.message : String(err)}`),
313
- route: match.route.displayPath,
314
- error: err,
315
- };
316
- }
317
- try {
318
- const result = await handler(request, ctx);
319
- let response;
320
- if (result instanceof Response) {
321
- response = result;
322
- }
323
- else {
324
- response = new Response(JSON.stringify(result), {
325
- headers: { 'Content-Type': 'application/json' },
326
- });
327
- }
328
- return {
329
- response: attachPendingRefresh(response, ctx),
330
- route: match.route.displayPath,
331
- databaseTiming: await requestTiming.finish(),
332
- };
333
- }
334
- catch (err) {
335
- // Deployed runtime hides the message and points at dashboard Logs; local
336
- // dev puts the real error in the response — it's the developer's terminal.
337
- return {
338
- response: jsonError(500, 'FUNCTION_ERROR', `Function handler threw: ${err instanceof Error ? err.message : String(err)}`),
339
- route: match.route.displayPath,
340
- error: err,
341
- databaseTiming: await requestTiming.finish(),
342
- };
343
- }
344
- }
345
- //# sourceMappingURL=runtime.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/local/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAExD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAmB,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAgC,MAAM,qBAAqB,CAAC;AAqBvF,SAAS,WAAW;IAClB,yDAAyD;IACzD,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACnE,CAAC;AAED,IAAI,aAAa,GAAiC,IAAI,CAAC;AAEvD,4FAA4F;AAC5F,MAAM,CAAC,KAAK,UAA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