@vite-hub/queue 0.6.1 → 0.8.0
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.
- package/README.md +17 -12
- package/dist/{client-CwoCdKct.js → client-mT8TUaag.js} +46 -15
- package/dist/{cloudflare-client-xWteD-su.js → cloudflare-client-DBgvWY0z.js} +14 -42
- package/dist/{cloudflare-resource-name-Bv8Z7nDU.js → cloudflare-resource-name-Coz5CPmn.js} +1 -1
- package/dist/{config-Bzp1xmdh.js → config-ByKUipob.js} +4 -2
- package/dist/{definition-CIiFfst2.js → definition-Dorliu47.js} +9 -2
- package/dist/{duration-C5w_-Rf4.js → duration-BZKArIBP.js} +20 -5
- package/dist/{error-diagnostics-kKXseq8d.js → error-diagnostics-CsiNo_oI.js} +3 -3
- package/dist/{error-diagnostics-Dv6nKZQW.js → error-diagnostics-Yj8XCiya.js} +30 -6
- package/dist/{handler-response-CchTXVjm.js → handler-response-DKhsmxDV.js} +6 -2
- package/dist/index.d.ts +13 -8
- package/dist/index.js +4 -4
- package/dist/internal/runtime/cloudflare-client.d.ts +1 -1
- package/dist/internal/runtime/cloudflare-client.js +1 -1
- package/dist/internal/runtime/cloudflare-vite.d.ts +1 -1
- package/dist/internal/runtime/cloudflare-vite.js +9 -8
- package/dist/internal/runtime/local-client.d.ts +3 -3
- package/dist/internal/runtime/local-client.js +4 -4
- package/dist/internal/runtime/postgres-client.d.ts +8 -6
- package/dist/internal/runtime/postgres-client.js +178 -40
- package/dist/internal/runtime/state.d.ts +5 -3
- package/dist/internal/runtime/state.js +1 -1
- package/dist/internal/runtime/vercel-client.d.ts +1 -1
- package/dist/internal/runtime/vercel-client.js +28 -57
- package/dist/internal/runtime/worker-client.d.ts +2 -2
- package/dist/internal/runtime/worker-client.js +1 -1
- package/dist/{local-RX10a_Sq.js → local-5pcvR1RC.js} +148 -97
- package/dist/{local-B72WRWkS.d.ts → local-DUh8sGn-.d.ts} +1 -1
- package/dist/{operations-CoEXxfUW.js → operations-BSouq47k.js} +11 -6
- package/dist/{operation-definition-CqZkx1Rm.d.ts → operations-DSslh_vK.d.ts} +169 -1
- package/dist/operations.d.ts +13 -4
- package/dist/operations.js +98 -37
- package/dist/retries-BSAZru9n.js +27 -0
- package/dist/run-handler-COXFYL5z.js +61 -0
- package/dist/runtime/hosted.d.ts +1 -1
- package/dist/runtime/hosted.js +32 -20
- package/dist/{scan-module-BaqBao0J.js → scan-module-3HfnrGbT.js} +16 -1
- package/dist/source-files-DrAH1-c8.js +147 -0
- package/dist/{state-DqxeV11k.js → state-C-t99I4Q.js} +9 -3
- package/dist/{types-BevEYrUV.d.ts → types-BPs6OsRv.d.ts} +1 -1
- package/dist/{types-BzPGPV9z.d.ts → types-rZHAtkK0.d.ts} +74 -12
- package/dist/{vercel-region-DEsR1YJQ.js → vercel-region-Bp3hwRBr.js} +1 -1
- package/dist/vite.d.ts +2 -155
- package/dist/vite.js +522 -138
- package/package.json +4 -3
package/dist/vite.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { t as invariant } from "./invariant-CmdvZ3vp.js";
|
|
2
|
-
import { t as internalErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
+
import { t as internalErrorDiagnostics } from "./error-diagnostics-CsiNo_oI.js";
|
|
3
3
|
import { n as isRecord, r as isRecordOrFunction, t as cloneRecord } from "./object-DRSmpe04.js";
|
|
4
|
-
import { a as
|
|
5
|
-
import { t as queueErrorDiagnostics } from "./error-diagnostics-
|
|
6
|
-
import { n as
|
|
4
|
+
import { a as getHostingProvider, i as queueWorkersVariable, n as normalizeQueueOptions, o as resolveHost, r as postgresQueueUrlVariable, s as resolveHostPreset, t as defaultLocalQueueBase } from "./config-ByKUipob.js";
|
|
5
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-Yj8XCiya.js";
|
|
6
|
+
import { n as listSourceTreeFiles } from "./source-files-DrAH1-c8.js";
|
|
7
|
+
import { n as isQueueMaxBatchSize } from "./definition-Dorliu47.js";
|
|
7
8
|
import { t as getCloudflareQueueBindingName } from "./cloudflare-BMc35cBD.js";
|
|
8
9
|
import { t as getVercelQueueTopicName } from "./vercel-sUJOxFBB.js";
|
|
9
|
-
import { t as getCloudflareQueueName } from "./cloudflare-resource-name-
|
|
10
|
+
import { t as getCloudflareQueueName } from "./cloudflare-resource-name-Coz5CPmn.js";
|
|
10
11
|
import { n as summarizeDefinitions } from "./inspect-CwdWUhPj.js";
|
|
11
12
|
import { createRequire } from "node:module";
|
|
12
|
-
import { existsSync, readFileSync,
|
|
13
|
+
import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
13
14
|
import { tmpdir } from "node:os";
|
|
14
15
|
import { basename, dirname, isAbsolute, parse, resolve } from "node:path";
|
|
15
16
|
import { fileURLToPath } from "node:url";
|
|
16
|
-
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
17
|
+
import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
17
18
|
import { basename as basename$1, dirname as dirname$1, isAbsolute as isAbsolute$1, relative, resolve as resolve$1 } from "pathe";
|
|
19
|
+
import { isDeepStrictEqual } from "node:util";
|
|
18
20
|
// ../internal/src/build/vite.ts
|
|
19
21
|
const projectRootDirectoryMarkers = [
|
|
20
22
|
["server", "agents"],
|
|
@@ -123,18 +125,26 @@ function isMissingProjectMarker(error) {
|
|
|
123
125
|
const code = error.code;
|
|
124
126
|
return code === "ENOENT" || code === "ENOTDIR";
|
|
125
127
|
}
|
|
128
|
+
/** The owner of the generated code that a Vite or Nuxt config writes, from the CLI discovery and Node test markers. */
|
|
129
|
+
function viteHubGeneratedOwner(config) {
|
|
130
|
+
if (Reflect.get(config, "vitehubNodeTest") === true) return "node-test";
|
|
131
|
+
return Reflect.get(config, "vitehubCliDiscovery") === true ? "cli" : "app";
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The generated-code folder of an owner, relative to the project root: `.vitehub` for the app, `.vitehub/cli` and
|
|
135
|
+
* `.vitehub/node-test` for the others. State that the processes share, such as the Email outbox or the Env secret,
|
|
136
|
+
* stays in `.vitehub`, and so do the declaration files that TypeScript reads, because their contents follow only the
|
|
137
|
+
* Definitions.
|
|
138
|
+
*/
|
|
139
|
+
function viteHubGeneratedCodeDir(owner = "app") {
|
|
140
|
+
return owner === "app" ? ".vitehub" : `.vitehub/${owner}`;
|
|
141
|
+
}
|
|
126
142
|
// ../internal/src/durability.ts
|
|
127
143
|
/** The `durability` module next to the Vite plugin module at `importMetaUrl`, in source and in `dist`. */
|
|
128
144
|
function durabilityModuleFile(importMetaUrl) {
|
|
129
145
|
return fileURLToPath(new URL(importMetaUrl.endsWith(".ts") ? "./durability.ts" : "./durability.js", importMetaUrl));
|
|
130
146
|
}
|
|
131
147
|
// ../internal/src/build/paths.ts
|
|
132
|
-
function generatedDirSegments(productName) {
|
|
133
|
-
return [".vitehub", productName];
|
|
134
|
-
}
|
|
135
|
-
function ensureGeneratedDir(rootDir, productName) {
|
|
136
|
-
return resolve$1(rootDir, ...generatedDirSegments(productName));
|
|
137
|
-
}
|
|
138
148
|
function computePackageDir(importMetaUrl) {
|
|
139
149
|
const currentFileDir = dirname$1(fileURLToPath(importMetaUrl));
|
|
140
150
|
return resolve$1(currentFileDir, basename$1(currentFileDir) === "internal" ? "../.." : "..");
|
|
@@ -251,19 +261,312 @@ function mergeOwnedArrays(existing, value, arrays) {
|
|
|
251
261
|
const next = { ...value };
|
|
252
262
|
for (const [field, ownership] of Object.entries(arrays ?? {})) {
|
|
253
263
|
const incoming = Array.isArray(value[field]) ? value[field] : [];
|
|
254
|
-
const
|
|
264
|
+
const unowned = preserveUnownedKeyedArrayEntries(existing[field], ownership, incoming);
|
|
265
|
+
const merged = ownership.key !== void 0 && ownership.preserveOrder && Array.isArray(existing[field]) ? mergeOrderedEntries(existing[field], unowned, incoming, ownership.key) : [...unowned, ...incoming];
|
|
255
266
|
if (merged.length) next[field] = merged;
|
|
256
267
|
else delete next[field];
|
|
257
268
|
}
|
|
258
269
|
return next;
|
|
259
270
|
}
|
|
271
|
+
function mergeOrderedEntries(current, unowned, incoming, key) {
|
|
272
|
+
const preserved = new Set(unowned);
|
|
273
|
+
const replacements = new Map(incoming.flatMap((entry) => {
|
|
274
|
+
const identity = getKeyedArrayEntryValue(entry, key);
|
|
275
|
+
return identity === void 0 ? [] : [[identity, entry]];
|
|
276
|
+
}));
|
|
277
|
+
return [...current.flatMap((entry) => {
|
|
278
|
+
if (preserved.has(entry)) return [entry];
|
|
279
|
+
const identity = getKeyedArrayEntryValue(entry, key);
|
|
280
|
+
if (identity === void 0) return [];
|
|
281
|
+
const replacement = replacements.get(identity);
|
|
282
|
+
if (replacement === void 0) return [];
|
|
283
|
+
replacements.delete(identity);
|
|
284
|
+
return [replacement];
|
|
285
|
+
}), ...incoming.filter((entry) => {
|
|
286
|
+
const identity = getKeyedArrayEntryValue(entry, key);
|
|
287
|
+
return identity === void 0 || replacements.has(identity);
|
|
288
|
+
})];
|
|
289
|
+
}
|
|
260
290
|
function mergeProviderOutputConfig(existing, value, ownership = {}) {
|
|
261
291
|
assertProviderJsonRecord(existing);
|
|
262
292
|
assertProviderJsonRecord(value);
|
|
263
|
-
|
|
293
|
+
const next = {
|
|
264
294
|
...deleteOwnedFields(existing, ownership),
|
|
265
295
|
...mergeOwnedArrays(existing, value, ownership.arrays)
|
|
266
296
|
};
|
|
297
|
+
for (const [field, childOwnership] of Object.entries(ownership.objects ?? {})) {
|
|
298
|
+
const current = existing[field];
|
|
299
|
+
const incoming = value[field];
|
|
300
|
+
const merged = mergeProviderOutputConfig(isProviderJsonRecord(current) ? current : {}, isProviderJsonRecord(incoming) ? incoming : {}, childOwnership);
|
|
301
|
+
if (Object.keys(merged).length) next[field] = merged;
|
|
302
|
+
else delete next[field];
|
|
303
|
+
}
|
|
304
|
+
return next;
|
|
305
|
+
}
|
|
306
|
+
// ../internal/src/build/wrangler-bindings.ts
|
|
307
|
+
/**
|
|
308
|
+
* Named-entry arrays that ViteHub writes, other than `d1_databases`, which the Database package collapses with its
|
|
309
|
+
* own rules and error.
|
|
310
|
+
*/
|
|
311
|
+
const wranglerEntrySpecs = [
|
|
312
|
+
{
|
|
313
|
+
path: ["kv_namespaces"],
|
|
314
|
+
identity: "binding",
|
|
315
|
+
resource: ["id", "preview_id"],
|
|
316
|
+
ids: ["id", "preview_id"],
|
|
317
|
+
preservePlaceholderIds: ["preview_id"]
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
path: ["r2_buckets"],
|
|
321
|
+
identity: "binding",
|
|
322
|
+
resource: [
|
|
323
|
+
"bucket_name",
|
|
324
|
+
"jurisdiction",
|
|
325
|
+
"preview_bucket_name"
|
|
326
|
+
]
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
path: ["ratelimits"],
|
|
330
|
+
identity: "name",
|
|
331
|
+
resource: ["namespace_id", "simple"]
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
path: ["hyperdrive"],
|
|
335
|
+
identity: "binding",
|
|
336
|
+
resource: ["id"],
|
|
337
|
+
ids: ["id"],
|
|
338
|
+
preservePlaceholderIds: true
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
path: ["containers"],
|
|
342
|
+
identity: ["class_name", "name"],
|
|
343
|
+
resource: [
|
|
344
|
+
"scheduling_policy",
|
|
345
|
+
"image",
|
|
346
|
+
"images",
|
|
347
|
+
"image_build_context",
|
|
348
|
+
"image_vars",
|
|
349
|
+
"class_name",
|
|
350
|
+
"name",
|
|
351
|
+
"instance_type",
|
|
352
|
+
"max_instances"
|
|
353
|
+
],
|
|
354
|
+
defaults: { scheduling_policy: "default" },
|
|
355
|
+
exclusive: [["image", "images"]]
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
path: ["durable_objects", "bindings"],
|
|
359
|
+
identity: "name",
|
|
360
|
+
resource: [
|
|
361
|
+
"class_name",
|
|
362
|
+
"script_name",
|
|
363
|
+
"environment"
|
|
364
|
+
]
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
path: ["migrations"],
|
|
368
|
+
identity: "tag",
|
|
369
|
+
resource: [
|
|
370
|
+
"new_classes",
|
|
371
|
+
"new_sqlite_classes",
|
|
372
|
+
"renamed_classes",
|
|
373
|
+
"deleted_classes",
|
|
374
|
+
"transferred_classes"
|
|
375
|
+
]
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
path: ["queues", "producers"],
|
|
379
|
+
identity: "binding",
|
|
380
|
+
resource: ["queue"]
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
path: ["queues", "consumers"],
|
|
384
|
+
identity: "queue",
|
|
385
|
+
resource: ["max_retries"]
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
path: ["workflows"],
|
|
389
|
+
identity: "binding",
|
|
390
|
+
resource: [
|
|
391
|
+
"name",
|
|
392
|
+
"class_name",
|
|
393
|
+
"script_name",
|
|
394
|
+
"jurisdiction"
|
|
395
|
+
],
|
|
396
|
+
exclusive: [["script_name", "jurisdiction"]]
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
path: ["services"],
|
|
400
|
+
identity: "binding",
|
|
401
|
+
resource: [
|
|
402
|
+
"service",
|
|
403
|
+
"entrypoint",
|
|
404
|
+
"environment"
|
|
405
|
+
]
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
path: ["send_email"],
|
|
409
|
+
identity: "name",
|
|
410
|
+
resource: [
|
|
411
|
+
"destination_address",
|
|
412
|
+
"allowed_destination_addresses",
|
|
413
|
+
"allowed_sender_addresses"
|
|
414
|
+
],
|
|
415
|
+
exclusive: [["destination_address", "allowed_destination_addresses"]]
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
path: ["analytics_engine_datasets"],
|
|
419
|
+
identity: "binding",
|
|
420
|
+
resource: ["dataset"]
|
|
421
|
+
}
|
|
422
|
+
];
|
|
423
|
+
const placeholderId = /^(?:0+|0{8}-0{4}-[0-8]000-[089ab]000-0{12})$/;
|
|
424
|
+
/**
|
|
425
|
+
* Whether `value` is an all-zero id, such as `00000000000000000000000000000000` or
|
|
426
|
+
* `00000000-0000-4000-8000-000000000000`. Templates such as a Deploy to Cloudflare repository put one where Cloudflare
|
|
427
|
+
* writes the real id. It never names a resource.
|
|
428
|
+
*/
|
|
429
|
+
function isPlaceholderCloudflareId(value) {
|
|
430
|
+
return typeof value === "string" && placeholderId.test(value);
|
|
431
|
+
}
|
|
432
|
+
function defaultConflict({ field, generated, name, path, project, scope }) {
|
|
433
|
+
return internalErrorDiagnostics.INTERNAL_B0051({
|
|
434
|
+
field,
|
|
435
|
+
generated: JSON.stringify(generated),
|
|
436
|
+
name,
|
|
437
|
+
path,
|
|
438
|
+
project: JSON.stringify(project),
|
|
439
|
+
scope
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
function collapseEntries(entries, spec, scope, conflict) {
|
|
443
|
+
const collapsed = [];
|
|
444
|
+
const byName = /* @__PURE__ */ new Map();
|
|
445
|
+
const identities = typeof spec.identity === "string" ? [spec.identity] : spec.identity;
|
|
446
|
+
const aliases = /* @__PURE__ */ new Map();
|
|
447
|
+
function canonical(key) {
|
|
448
|
+
const parent = aliases.get(key);
|
|
449
|
+
if (parent === void 0) return key;
|
|
450
|
+
const root = canonical(parent);
|
|
451
|
+
aliases.set(key, root);
|
|
452
|
+
return root;
|
|
453
|
+
}
|
|
454
|
+
if (identities.length > 1) for (const entry of entries) {
|
|
455
|
+
if (!isRecord(entry)) continue;
|
|
456
|
+
const keys = identities.filter((field) => typeof entry[field] === "string").map((field) => `${field}:${entry[field]}`);
|
|
457
|
+
for (const key of keys.slice(1)) {
|
|
458
|
+
const root = canonical(keys[0]);
|
|
459
|
+
const alias = canonical(key);
|
|
460
|
+
if (root !== alias) aliases.set(alias, root);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
for (const entry of entries) {
|
|
464
|
+
const identity = isRecord(entry) ? identities.find((field) => typeof entry[field] === "string") : void 0;
|
|
465
|
+
if (!isRecord(entry) || identity === void 0) {
|
|
466
|
+
collapsed.push(entry);
|
|
467
|
+
continue;
|
|
468
|
+
}
|
|
469
|
+
const name = entry[identity];
|
|
470
|
+
const key = canonical(`${identity}:${name}`);
|
|
471
|
+
const first = byName.get(key);
|
|
472
|
+
if (!first) {
|
|
473
|
+
const copy = { ...entry };
|
|
474
|
+
byName.set(key, copy);
|
|
475
|
+
collapsed.push(copy);
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
for (const field of spec.resource) {
|
|
479
|
+
const generated = first[field] === void 0 ? spec.defaults?.[field] : first[field];
|
|
480
|
+
const project = entry[field] === void 0 ? spec.defaults?.[field] : entry[field];
|
|
481
|
+
if (generated === void 0 || project === void 0 || isDeepStrictEqual(generated, project)) continue;
|
|
482
|
+
const isId = spec.ids?.includes(field) === true;
|
|
483
|
+
if (isId && isPlaceholderCloudflareId(project)) continue;
|
|
484
|
+
if (isId && isPlaceholderCloudflareId(generated)) {
|
|
485
|
+
first[field] = project;
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
throw conflict({
|
|
489
|
+
field,
|
|
490
|
+
generated,
|
|
491
|
+
name,
|
|
492
|
+
path: spec.path.join("."),
|
|
493
|
+
project,
|
|
494
|
+
scope
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
for (const group of spec.exclusive ?? []) {
|
|
498
|
+
const generatedField = group.find((field) => first[field] !== void 0);
|
|
499
|
+
const projectField = group.find((field) => entry[field] !== void 0);
|
|
500
|
+
if (generatedField && projectField && generatedField !== projectField) throw conflict({
|
|
501
|
+
field: group.join(" / "),
|
|
502
|
+
generated: { [generatedField]: first[generatedField] },
|
|
503
|
+
name,
|
|
504
|
+
path: spec.path.join("."),
|
|
505
|
+
project: { [projectField]: entry[projectField] },
|
|
506
|
+
scope
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
const kept = new Set((spec.groups ?? []).filter((group) => group.some((field) => first[field] !== void 0)).flat());
|
|
510
|
+
for (const [key, value] of Object.entries(entry)) if (!kept.has(key) && first[key] === void 0) first[key] = value;
|
|
511
|
+
}
|
|
512
|
+
const preservedIds = spec.preservePlaceholderIds === true ? spec.ids : spec.preservePlaceholderIds || [];
|
|
513
|
+
for (const entry of byName.values()) for (const field of spec.ids ?? []) if (!preservedIds?.includes(field) && isPlaceholderCloudflareId(entry[field])) delete entry[field];
|
|
514
|
+
return collapsed;
|
|
515
|
+
}
|
|
516
|
+
function unique(values) {
|
|
517
|
+
return Array.isArray(values) ? [...new Set(values)] : values;
|
|
518
|
+
}
|
|
519
|
+
function collapseTarget(target, specs, scope, conflict) {
|
|
520
|
+
const result = { ...target };
|
|
521
|
+
for (const spec of specs) {
|
|
522
|
+
const parents = spec.path.slice(0, -1);
|
|
523
|
+
const key = spec.path.at(-1);
|
|
524
|
+
let parent = result;
|
|
525
|
+
let found = true;
|
|
526
|
+
for (const segment of parents) {
|
|
527
|
+
const next = parent[segment];
|
|
528
|
+
if (!isRecord(next)) {
|
|
529
|
+
found = false;
|
|
530
|
+
break;
|
|
531
|
+
}
|
|
532
|
+
parent = parent[segment] = { ...next };
|
|
533
|
+
}
|
|
534
|
+
if (found && Array.isArray(parent[key])) parent[key] = collapseEntries(parent[key], spec, scope, conflict);
|
|
535
|
+
}
|
|
536
|
+
if (Array.isArray(result.compatibility_flags)) result.compatibility_flags = unique(result.compatibility_flags);
|
|
537
|
+
if (isRecord(result.secrets) && Array.isArray(result.secrets.required)) result.secrets = {
|
|
538
|
+
...result.secrets,
|
|
539
|
+
required: unique(result.secrets.required)
|
|
540
|
+
};
|
|
541
|
+
return result;
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* The Wrangler config with one entry per name in each array of `specs`, and without repeated compatibility flags or
|
|
545
|
+
* required secrets, at the top level and in each `env`.
|
|
546
|
+
*/
|
|
547
|
+
function collapseWranglerConfig(wrangler, options = {}) {
|
|
548
|
+
const specs = options.specs ?? wranglerEntrySpecs;
|
|
549
|
+
const conflict = options.conflict ?? defaultConflict;
|
|
550
|
+
const result = collapseTarget(wrangler, specs, "", conflict);
|
|
551
|
+
if (isRecord(wrangler.env)) result.env = Object.fromEntries(Object.entries(wrangler.env).map(([name, config]) => [name, isRecord(config) ? collapseTarget(config, specs, ` in env.${name}`, conflict) : config]));
|
|
552
|
+
return result;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Collapses the `wrangler.json` in `serverDir` that Nitro's Cloudflare preset wrote. Run it in a `compiled` hook. It
|
|
556
|
+
* does nothing when the file is missing, and writes only when something changed.
|
|
557
|
+
*/
|
|
558
|
+
async function collapseWranglerConfigFile(serverDir, options = {}) {
|
|
559
|
+
const file = resolve(serverDir, "wrangler.json");
|
|
560
|
+
const text = await readFile(file, "utf8").catch((error) => {
|
|
561
|
+
if (error.code === "ENOENT") return void 0;
|
|
562
|
+
throw error;
|
|
563
|
+
});
|
|
564
|
+
if (text === void 0) return;
|
|
565
|
+
const wrangler = JSON.parse(text);
|
|
566
|
+
if (!isRecord(wrangler)) return;
|
|
567
|
+
options.validate?.(wrangler);
|
|
568
|
+
const collapsed = collapseWranglerConfig(wrangler, options);
|
|
569
|
+
if (!isDeepStrictEqual(collapsed, wrangler)) await writeFile(file, `${JSON.stringify(collapsed, null, 2)}\n`);
|
|
267
570
|
}
|
|
268
571
|
// ../internal/src/build/bundle-options.ts
|
|
269
572
|
/** Select the runtime constants from one resolved Vite configuration. */
|
|
@@ -280,16 +583,16 @@ function resolveViteHubBundleDefines(config) {
|
|
|
280
583
|
return defines;
|
|
281
584
|
}
|
|
282
585
|
// ../internal/src/build/cloudflare-provider-output.ts
|
|
283
|
-
function isDeepStrictEqual(left, right) {
|
|
586
|
+
function isDeepStrictEqual$1(left, right) {
|
|
284
587
|
if (Object.is(left, right)) return true;
|
|
285
588
|
if (!left || !right || typeof left !== "object" || typeof right !== "object") return false;
|
|
286
589
|
if (Array.isArray(left) !== Array.isArray(right)) return false;
|
|
287
|
-
if (Array.isArray(left)) return left.length === right.length && left.every((value, index) => isDeepStrictEqual(value, right[index]));
|
|
590
|
+
if (Array.isArray(left)) return left.length === right.length && left.every((value, index) => isDeepStrictEqual$1(value, right[index]));
|
|
288
591
|
const leftRecord = left;
|
|
289
592
|
const rightRecord = right;
|
|
290
593
|
const leftKeys = Object.keys(leftRecord);
|
|
291
594
|
const rightKeys = Object.keys(rightRecord);
|
|
292
|
-
return leftKeys.length === rightKeys.length && leftKeys.every((key) => Object.hasOwn(rightRecord, key) && isDeepStrictEqual(leftRecord[key], rightRecord[key]));
|
|
595
|
+
return leftKeys.length === rightKeys.length && leftKeys.every((key) => Object.hasOwn(rightRecord, key) && isDeepStrictEqual$1(leftRecord[key], rightRecord[key]));
|
|
293
596
|
}
|
|
294
597
|
const providerOutputCatalogRegistry$1 = globalThis;
|
|
295
598
|
const providerOutputCatalogByNitroValue = providerOutputCatalogRegistry$1.__vitehubProviderOutputCatalogsByNitroValue ??= /* @__PURE__ */ new WeakMap();
|
|
@@ -302,10 +605,6 @@ function cloneProviderValue(value) {
|
|
|
302
605
|
if (value && typeof value === "object") return cloneProviderRecord(value);
|
|
303
606
|
return value;
|
|
304
607
|
}
|
|
305
|
-
/**
|
|
306
|
-
* The incoming entries that the app config does not have yet. An entry that the app already has must agree on
|
|
307
|
-
* `conflictKeys`, and on each of `setKeys` that the incoming entry sets, because the app's entry is the one that stays.
|
|
308
|
-
*/
|
|
309
608
|
function compatibleEntries(existing, incoming, identityKey, conflictKeys, owner, setKeys = []) {
|
|
310
609
|
const current = Array.isArray(existing) ? existing.map(cloneProviderRecord) : [];
|
|
311
610
|
return (incoming ?? []).filter((entry) => {
|
|
@@ -315,15 +614,33 @@ function compatibleEntries(existing, incoming, identityKey, conflictKeys, owner,
|
|
|
315
614
|
current.push(entry);
|
|
316
615
|
return true;
|
|
317
616
|
}
|
|
318
|
-
if (conflictKeys.some((key) => !isDeepStrictEqual(match[key], entry[key]))) throw internalErrorDiagnostics.INTERNAL_B0001({ message: `[vitehub] Cloudflare ${identityKey} ${JSON.stringify(identity)} from ${owner} is already assigned to an incompatible resource.` });
|
|
319
|
-
const differentKey = setKeys.find((key) => entry[key] !== void 0 && !isDeepStrictEqual(match[key], entry[key]));
|
|
617
|
+
if (conflictKeys.some((key) => !isDeepStrictEqual$1(match[key], entry[key]))) throw internalErrorDiagnostics.INTERNAL_B0001({ message: `[vitehub] Cloudflare ${identityKey} ${JSON.stringify(identity)} from ${owner} is already assigned to an incompatible resource.` });
|
|
618
|
+
const differentKey = setKeys.find((key) => entry[key] !== void 0 && !isDeepStrictEqual$1(match[key], entry[key]));
|
|
320
619
|
if (differentKey) throw internalErrorDiagnostics.INTERNAL_B0001({ message: `[vitehub] The Cloudflare ${identityKey} ${JSON.stringify(identity)} in the app's Wrangler config has ${differentKey} ${JSON.stringify(match[differentKey]) ?? "unset"}, but ${owner} sets ${JSON.stringify(entry[differentKey])}. Remove the entry from the Wrangler config, because ViteHub writes it, or give it the same value.` });
|
|
321
620
|
return false;
|
|
322
621
|
});
|
|
323
622
|
}
|
|
623
|
+
async function finalizeCloudflareQueueConsumers(serverDir, consumers) {
|
|
624
|
+
const expected = new Map(consumers.filter((consumer) => consumer.max_retries !== void 0).map((consumer) => [consumer.queue, consumer]));
|
|
625
|
+
await collapseWranglerConfigFile(serverDir, {
|
|
626
|
+
specs: wranglerEntrySpecs.filter((spec) => spec.path[0] === "queues" && spec.path[1] === "consumers"),
|
|
627
|
+
validate(wrangler) {
|
|
628
|
+
const environments = cloneRecord(wrangler.env);
|
|
629
|
+
for (const config of [wrangler, ...Object.values(environments).map(cloneRecord)]) {
|
|
630
|
+
const queues = cloneRecord(config.queues);
|
|
631
|
+
if (!Array.isArray(queues.consumers)) continue;
|
|
632
|
+
for (const entry of queues.consumers) {
|
|
633
|
+
const consumer = cloneRecord(entry);
|
|
634
|
+
const definition = typeof consumer.queue === "string" ? expected.get(consumer.queue) : void 0;
|
|
635
|
+
if (definition) compatibleEntries([consumer], [definition], "queue", [], "queue", ["max_retries"]);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
}
|
|
324
641
|
function removeEntries(existing, entries) {
|
|
325
642
|
if (!Array.isArray(existing) || !entries?.length) return Array.isArray(existing) ? existing : [];
|
|
326
|
-
return existing.filter((entry) => !entries.some((previous) => isDeepStrictEqual(entry, previous)));
|
|
643
|
+
return existing.filter((entry) => !entries.some((previous) => isDeepStrictEqual$1(entry, previous)));
|
|
327
644
|
}
|
|
328
645
|
function removeContribution(wrangler, contribution) {
|
|
329
646
|
const queues = cloneProviderRecord(wrangler.queues);
|
|
@@ -374,7 +691,7 @@ function mergeContribution(wrangler, owner, contribution) {
|
|
|
374
691
|
const queues = cloneProviderRecord(wrangler.queues);
|
|
375
692
|
const secrets = cloneProviderRecord(wrangler.secrets);
|
|
376
693
|
const environments = cloneProviderRecord(wrangler.env);
|
|
377
|
-
const consumers = compatibleEntries(queues.consumers, contribution.queues?.consumers, "queue", [], owner, ["max_batch_size"]);
|
|
694
|
+
const consumers = compatibleEntries(queues.consumers, contribution.queues?.consumers, "queue", [], owner, ["max_batch_size", "max_retries"]);
|
|
378
695
|
const producers = compatibleEntries(queues.producers, contribution.queues?.producers, "binding", ["queue"], owner);
|
|
379
696
|
const r2Buckets = compatibleEntries(wrangler.r2_buckets, contribution.r2Buckets, "binding", ["bucket_name", "jurisdiction"], owner);
|
|
380
697
|
const rateLimits = compatibleEntries(wrangler.ratelimits, contribution.rateLimits, "name", ["namespace_id", "simple"], owner);
|
|
@@ -537,17 +854,17 @@ var ProviderOutputCatalog = class {
|
|
|
537
854
|
}
|
|
538
855
|
this.#restoreDeploymentContribution(entry);
|
|
539
856
|
}
|
|
540
|
-
resetDeploymentContributions(generation) {
|
|
857
|
+
resetDeploymentContributions(generation, failure) {
|
|
541
858
|
if (!generation) {
|
|
542
859
|
for (const reference of this.#deploymentGenerations) {
|
|
543
860
|
const current = reference.deref();
|
|
544
861
|
if (current) current.valid = false;
|
|
545
862
|
}
|
|
546
863
|
this.#deploymentGenerations.clear();
|
|
547
|
-
for (const entries of this.#deploymentContributions.values()) for (const entry of entries) this.#queueDeploymentDiscard(entry);
|
|
864
|
+
for (const entries of this.#deploymentContributions.values()) for (const entry of entries) this.#queueDeploymentDiscard(entry, failure);
|
|
548
865
|
for (const taken of this.#takenDeploymentContributions.values()) {
|
|
549
|
-
if (!taken.entryDiscarded) this.#queueDeploymentDiscard(taken.entry);
|
|
550
|
-
for (const fallback of taken.fallbacks) this.#queueDeploymentDiscard(fallback);
|
|
866
|
+
if (!taken.entryDiscarded) this.#queueDeploymentDiscard(taken.entry, failure);
|
|
867
|
+
for (const fallback of taken.fallbacks) this.#queueDeploymentDiscard(fallback, failure);
|
|
551
868
|
}
|
|
552
869
|
this.#deploymentContributions.clear();
|
|
553
870
|
this.#takenDeploymentContributions.clear();
|
|
@@ -556,7 +873,7 @@ var ProviderOutputCatalog = class {
|
|
|
556
873
|
generation.valid = false;
|
|
557
874
|
this.#deleteDeploymentGeneration(generation);
|
|
558
875
|
for (const [owner, entries] of this.#deploymentContributions) {
|
|
559
|
-
for (const entry of entries) if (entry.generation === generation) this.#queueDeploymentDiscard(entry);
|
|
876
|
+
for (const entry of entries) if (entry.generation === generation) this.#queueDeploymentDiscard(entry, failure);
|
|
560
877
|
const remaining = entries.filter((entry) => entry.generation !== generation);
|
|
561
878
|
if (remaining.length) this.#deploymentContributions.set(owner, remaining);
|
|
562
879
|
else this.#deploymentContributions.delete(owner);
|
|
@@ -564,10 +881,10 @@ var ProviderOutputCatalog = class {
|
|
|
564
881
|
for (const [contribution, taken] of this.#takenDeploymentContributions) {
|
|
565
882
|
const invalidatedFallbacks = taken.fallbacks.filter((entry) => entry.generation === generation);
|
|
566
883
|
taken.fallbacks = taken.fallbacks.filter((entry) => entry.generation !== generation);
|
|
567
|
-
for (const fallback of invalidatedFallbacks) this.#queueDeploymentDiscard(fallback);
|
|
884
|
+
for (const fallback of invalidatedFallbacks) this.#queueDeploymentDiscard(fallback, failure);
|
|
568
885
|
if (taken.entry.generation !== generation) continue;
|
|
569
886
|
this.#takenDeploymentContributions.delete(contribution);
|
|
570
|
-
if (!taken.entryDiscarded) this.#queueDeploymentDiscard(taken.entry);
|
|
887
|
+
if (!taken.entryDiscarded) this.#queueDeploymentDiscard(taken.entry, failure);
|
|
571
888
|
for (const fallback of taken.fallbacks) if (taken.committed) this.#queueDeploymentDiscard(fallback);
|
|
572
889
|
else this.#restoreDeploymentContribution(fallback);
|
|
573
890
|
}
|
|
@@ -610,7 +927,7 @@ var ProviderOutputCatalog = class {
|
|
|
610
927
|
const failure = (await Promise.allSettled(discarded)).find((result) => result.status === "rejected");
|
|
611
928
|
if (failure) throw failure.reason;
|
|
612
929
|
}
|
|
613
|
-
async completeDeploymentContributions(contributions) {
|
|
930
|
+
async completeDeploymentContributions(contributions, buildFailure) {
|
|
614
931
|
const discarded = this.#pendingDeploymentDiscards.splice(0);
|
|
615
932
|
const completedGenerations = /* @__PURE__ */ new Set();
|
|
616
933
|
for (const contribution of contributions) {
|
|
@@ -620,7 +937,7 @@ var ProviderOutputCatalog = class {
|
|
|
620
937
|
const entries = taken.entryDiscarded ? taken.fallbacks : [...taken.fallbacks, taken.entry];
|
|
621
938
|
for (const entry of entries) {
|
|
622
939
|
if (entry.generation) completedGenerations.add(entry.generation);
|
|
623
|
-
if (entry.contribution.discard) discarded.push(entry.contribution.discard());
|
|
940
|
+
if (entry.contribution.discard) discarded.push(entry.contribution.discard(entry === taken.entry ? buildFailure : void 0));
|
|
624
941
|
}
|
|
625
942
|
}
|
|
626
943
|
for (const generation of completedGenerations) this.#retireDeploymentGeneration(generation);
|
|
@@ -664,9 +981,9 @@ var ProviderOutputCatalog = class {
|
|
|
664
981
|
if (reference) this.#deploymentGenerations.delete(reference);
|
|
665
982
|
this.#deploymentGenerationRefs.delete(generation);
|
|
666
983
|
}
|
|
667
|
-
#queueDeploymentDiscard(entry) {
|
|
984
|
+
#queueDeploymentDiscard(entry, failure) {
|
|
668
985
|
if (!entry.contribution.discard) return;
|
|
669
|
-
const discard = Promise.resolve().then(entry.contribution.discard);
|
|
986
|
+
const discard = Promise.resolve().then(async () => await entry.contribution.discard?.(failure));
|
|
670
987
|
discard.catch(() => {});
|
|
671
988
|
this.#pendingDeploymentDiscards.push(discard);
|
|
672
989
|
}
|
|
@@ -690,7 +1007,12 @@ function contributeCloudflareProviderOutput(catalog, contribution) {
|
|
|
690
1007
|
const { owner, ...value } = contribution;
|
|
691
1008
|
catalog.replaceCloudflareContribution(owner, value);
|
|
692
1009
|
}
|
|
693
|
-
|
|
1010
|
+
// ../internal/src/nitro-kit.ts
|
|
1011
|
+
/**
|
|
1012
|
+
* The route meta of a ViteHub handler that Auth access routes leave alone, such as the Console RPC. The handler takes
|
|
1013
|
+
* only its own signed requests and signed Site access tokens, so app access rules do not apply to it.
|
|
1014
|
+
*/
|
|
1015
|
+
const ownAccessHandlerMeta = Object.freeze({ vitehubAuthAccess: "handler" });
|
|
694
1016
|
Object.freeze({ vitehubOwnAccess: true });
|
|
695
1017
|
function cloneArray(value) {
|
|
696
1018
|
return Array.isArray(value) ? [...value] : [];
|
|
@@ -863,8 +1185,8 @@ async function collectQueueContributions(plugins, context) {
|
|
|
863
1185
|
const owners = ["queue"];
|
|
864
1186
|
/**
|
|
865
1187
|
* The variables that Queue reads on the deployed host. The `postgres` provider reads `QUEUE_POSTGRES_URL`, which is
|
|
866
|
-
* required unless the build found a Postgres Default Database to borrow
|
|
867
|
-
* `QUEUE_REGION`. Cloudflare Queues and the `local` provider read none.
|
|
1188
|
+
* required unless the build found a Postgres Default Database to borrow, and the optional `QUEUE_WORKERS`. The `vercel`
|
|
1189
|
+
* provider reads the optional `QUEUE_REGION`. Cloudflare Queues and the `local` provider read none.
|
|
868
1190
|
*/
|
|
869
1191
|
function queueDeploymentEnv(queue) {
|
|
870
1192
|
if (!queue) return [];
|
|
@@ -874,6 +1196,12 @@ function queueDeploymentEnv(queue) {
|
|
|
874
1196
|
secret: true,
|
|
875
1197
|
hasDefault: Boolean(queue.database),
|
|
876
1198
|
owners
|
|
1199
|
+
}, {
|
|
1200
|
+
names: [queueWorkersVariable],
|
|
1201
|
+
required: false,
|
|
1202
|
+
secret: false,
|
|
1203
|
+
hasDefault: true,
|
|
1204
|
+
owners
|
|
877
1205
|
}];
|
|
878
1206
|
if (queue.driver === "vercel") return [{
|
|
879
1207
|
names: ["QUEUE_REGION"],
|
|
@@ -888,15 +1216,6 @@ function queueDeploymentEnv(queue) {
|
|
|
888
1216
|
const sourceFilePattern = /\.(?:c|m)?[jt]sx?$/i;
|
|
889
1217
|
const declarationFilePattern = /\.d\.(?:c|m)?[jt]sx?$/i;
|
|
890
1218
|
const testFilePattern = /\.(?:test|spec)\.(?:c|m)?[jt]sx?$/i;
|
|
891
|
-
const ignoredDirs = /* @__PURE__ */ new Set([
|
|
892
|
-
"node_modules",
|
|
893
|
-
"dist",
|
|
894
|
-
".output",
|
|
895
|
-
".nuxt",
|
|
896
|
-
".vercel",
|
|
897
|
-
".git",
|
|
898
|
-
".vitehub"
|
|
899
|
-
]);
|
|
900
1219
|
function resolveDefinitionScanRoots(rootDir, scanDirs = []) {
|
|
901
1220
|
return [...new Set([rootDir, ...scanDirs].filter(Boolean))];
|
|
902
1221
|
}
|
|
@@ -919,32 +1238,8 @@ function createSuffixDefinitionSource(source, roots, pattern, normalizeName, opt
|
|
|
919
1238
|
source
|
|
920
1239
|
};
|
|
921
1240
|
}
|
|
922
|
-
function readDirEntries(root) {
|
|
923
|
-
try {
|
|
924
|
-
return readdirSync(root, { withFileTypes: true });
|
|
925
|
-
} catch (error) {
|
|
926
|
-
if (error.code === "ENOENT") return [];
|
|
927
|
-
throw error;
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
function isGitRepositoryDirectory(directory) {
|
|
931
|
-
return existsSync(resolve$1(directory, ".git"));
|
|
932
|
-
}
|
|
933
1241
|
function listMatchingFiles(root, predicate, options = {}) {
|
|
934
|
-
|
|
935
|
-
for (const entry of readDirEntries(root)) {
|
|
936
|
-
const absolute = resolve$1(root, entry.name);
|
|
937
|
-
if (entry.isDirectory() && !entry.isSymbolicLink()) {
|
|
938
|
-
if (isGitRepositoryDirectory(absolute)) continue;
|
|
939
|
-
if (entry.name.startsWith(".")) continue;
|
|
940
|
-
if (ignoredDirs.has(entry.name)) continue;
|
|
941
|
-
files.push(...listMatchingFiles(absolute, predicate, options));
|
|
942
|
-
continue;
|
|
943
|
-
}
|
|
944
|
-
if (entry.name.startsWith(".") && !options.includeHidden) continue;
|
|
945
|
-
if (entry.isFile() && predicate(entry.name)) files.push(absolute);
|
|
946
|
-
}
|
|
947
|
-
return files.sort();
|
|
1242
|
+
return listSourceTreeFiles(root, predicate, options);
|
|
948
1243
|
}
|
|
949
1244
|
/** A module that a Definitions folder can hold: JavaScript or TypeScript, and not a declaration, test, or spec file. */
|
|
950
1245
|
function isDefinitionSourceFile(name) {
|
|
@@ -1034,6 +1329,12 @@ function createRuntimeRegistryContents(registryFile, definitions) {
|
|
|
1034
1329
|
""
|
|
1035
1330
|
].join("\n");
|
|
1036
1331
|
}
|
|
1332
|
+
/** `writeFileIfChangedSync` for async callers. */
|
|
1333
|
+
async function writeFileIfChanged(file, contents) {
|
|
1334
|
+
if (await readFile(file, "utf8").catch(() => void 0) === contents) return;
|
|
1335
|
+
await mkdir(resolve$1(file, ".."), { recursive: true });
|
|
1336
|
+
await writeFile(file, contents, "utf8");
|
|
1337
|
+
}
|
|
1037
1338
|
// src/discovery.ts
|
|
1038
1339
|
const queueSuffixPattern = /\.queue\.(?:c|m)?[jt]s$/i;
|
|
1039
1340
|
/** Discovery source of Queue Definitions that Vite plugins contribute through `vitehub.queues`. */
|
|
@@ -1083,17 +1384,24 @@ function createQueueTypes(file, definitions, importBase = "@vite-hub/queue") {
|
|
|
1083
1384
|
}
|
|
1084
1385
|
async function writeQueueTypes(root, definitions, importBase = "@vite-hub/queue") {
|
|
1085
1386
|
const file = resolve$1(root, ".vitehub/queue.d.ts");
|
|
1086
|
-
await
|
|
1087
|
-
await writeFile(file, createQueueTypes(file, definitions, importBase), "utf8");
|
|
1387
|
+
await writeFileIfChanged(file, createQueueTypes(file, definitions, importBase));
|
|
1088
1388
|
}
|
|
1089
1389
|
// src/internal/vite-build.ts
|
|
1090
1390
|
const queuePackageName = "@vite-hub/queue";
|
|
1091
1391
|
const productName = "queue";
|
|
1092
1392
|
const generatedRegistryFileName = "registry.mjs";
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
const
|
|
1096
|
-
|
|
1393
|
+
/** The generated Queue files of an owner, relative to the project root. */
|
|
1394
|
+
function queueGeneratedPaths(owner = "app") {
|
|
1395
|
+
const dir = viteHubGeneratedCodeDir(owner);
|
|
1396
|
+
return {
|
|
1397
|
+
middleware: `${dir}/nitro/queue/middleware.ts`,
|
|
1398
|
+
plugin: `${dir}/nitro/queue/plugin.ts`,
|
|
1399
|
+
registryDir: `${dir}/${productName}`,
|
|
1400
|
+
testSetup: `${dir}/${productName}/test-setup.mjs`,
|
|
1401
|
+
vercelConsumerDir: `${dir}/nitro/queue/vercel`
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
const vercelQueueFunctionEnv = "VITEHUB_VERCEL_QUEUE_FUNCTION";
|
|
1097
1405
|
const vercelQueueConsumerRoutePrefix = "/api/vitehub/queues/vercel";
|
|
1098
1406
|
const packageDir = computePackageDir(import.meta.url);
|
|
1099
1407
|
const packageRequire = createRequire(resolve(packageDir, "package.json"));
|
|
@@ -1140,39 +1448,69 @@ function createCloudflareQueueDefinitionNames(definitions, namePrefix = "") {
|
|
|
1140
1448
|
}
|
|
1141
1449
|
return Object.fromEntries([...names].map(([physicalName, definition]) => [physicalName, definition.name]));
|
|
1142
1450
|
}
|
|
1451
|
+
function readLiteral(properties, key, valid, exported, invalid) {
|
|
1452
|
+
const property = properties.findLast((candidate) => candidate.key === key);
|
|
1453
|
+
if (!property) return void 0;
|
|
1454
|
+
if (!exported || property.node.type !== "Property" || property.node.kind !== "init" || property.node.method || property.value?.type !== "Literal" || !valid(property.value.value)) return invalid();
|
|
1455
|
+
return property.value.value;
|
|
1456
|
+
}
|
|
1457
|
+
function isQueueRetriesLimit(value) {
|
|
1458
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0 && value <= 100;
|
|
1459
|
+
}
|
|
1143
1460
|
/**
|
|
1144
|
-
* Reads `maxBatchSize`
|
|
1145
|
-
* so the build fails when it cannot prove
|
|
1146
|
-
* number literal, or the option on a `defineQueue()` call that is not the default export.
|
|
1461
|
+
* Reads `maxBatchSize` and `retries.limit` from a default-exported Queue Definition. The Cloudflare consumer is
|
|
1462
|
+
* configured at build time, so the build fails when it cannot prove a value: a spread or computed key in those options,
|
|
1463
|
+
* a value that is not a number literal, or the option on a `defineQueue()` call that is not the default export.
|
|
1147
1464
|
*/
|
|
1148
|
-
function
|
|
1465
|
+
function readQueueConsumerOptions(file, { argumentExpression, defaultExportExpression, findCalls, objectProperties, scanModule }) {
|
|
1149
1466
|
const module = scanModule(readFileSync(file, "utf8"), file);
|
|
1150
|
-
const
|
|
1467
|
+
const invalidBatchSize = () => {
|
|
1151
1468
|
throw queueErrorDiagnostics.QUEUE_MAX_BATCH_SIZE_INVALID({ where: file });
|
|
1152
1469
|
};
|
|
1470
|
+
const invalidRetries = () => {
|
|
1471
|
+
throw queueErrorDiagnostics.QUEUE_RETRIES_LIMIT_INVALID({ where: file });
|
|
1472
|
+
};
|
|
1153
1473
|
const exported = defaultExportExpression(module);
|
|
1154
|
-
|
|
1155
|
-
for (const
|
|
1156
|
-
|
|
1157
|
-
if (
|
|
1474
|
+
const names = /* @__PURE__ */ new Set(["defineQueue"]);
|
|
1475
|
+
for (const statement of module.program.body) {
|
|
1476
|
+
if (statement.type !== "ImportDeclaration") continue;
|
|
1477
|
+
for (const specifier of statement.specifiers) if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name === "defineQueue") names.add(specifier.local.name);
|
|
1478
|
+
}
|
|
1479
|
+
const consumer = {};
|
|
1480
|
+
const definitions = findCalls(module, names).map((call) => ({
|
|
1481
|
+
options: argumentExpression(call.arguments[0]),
|
|
1482
|
+
exported: call === exported
|
|
1483
|
+
}));
|
|
1484
|
+
if (exported?.type === "ObjectExpression") definitions.push({
|
|
1485
|
+
options: exported,
|
|
1486
|
+
exported: true
|
|
1487
|
+
});
|
|
1488
|
+
for (const definition of definitions) {
|
|
1489
|
+
const { options } = definition;
|
|
1490
|
+
if (options?.type !== "ObjectExpression") return invalidBatchSize();
|
|
1158
1491
|
const properties = objectProperties(options);
|
|
1159
|
-
if (properties.some((property) => property.key === void 0 || property.computed)) return
|
|
1160
|
-
const
|
|
1161
|
-
if (
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1492
|
+
if (properties.some((property) => property.key === void 0 || property.computed)) return invalidBatchSize();
|
|
1493
|
+
const maxBatchSize = readLiteral(properties, "maxBatchSize", isQueueMaxBatchSize, definition.exported, invalidBatchSize);
|
|
1494
|
+
if (maxBatchSize !== void 0) consumer.max_batch_size = maxBatchSize;
|
|
1495
|
+
const retries = properties.findLast((candidate) => candidate.key === "retries");
|
|
1496
|
+
if (!retries) continue;
|
|
1497
|
+
if (retries.node.type !== "Property" || retries.node.kind !== "init" || retries.node.method || retries.value?.type !== "ObjectExpression") return invalidRetries();
|
|
1498
|
+
const retryProperties = objectProperties(retries.value);
|
|
1499
|
+
if (retryProperties.some((property) => property.key === void 0 || property.computed)) return invalidRetries();
|
|
1500
|
+
const limit = readLiteral(retryProperties, "limit", isQueueRetriesLimit, definition.exported, invalidRetries);
|
|
1501
|
+
if (limit !== void 0) consumer.max_retries = limit;
|
|
1502
|
+
}
|
|
1503
|
+
if (!definitions.some((definition) => definition.exported)) return invalidRetries();
|
|
1504
|
+
return consumer;
|
|
1166
1505
|
}
|
|
1167
1506
|
async function createCloudflareQueueBindings(definitions, namePrefix = "") {
|
|
1168
1507
|
if (!definitions.length) return;
|
|
1169
1508
|
createCloudflareQueueDefinitionNames(definitions, namePrefix);
|
|
1170
|
-
const scanner = await import("./scan-module-
|
|
1509
|
+
const scanner = await import("./scan-module-3HfnrGbT.js");
|
|
1171
1510
|
return {
|
|
1172
1511
|
consumers: definitions.map((definition) => {
|
|
1173
|
-
const maxBatchSize = readQueueMaxBatchSize(definition.handler, scanner);
|
|
1174
1512
|
return {
|
|
1175
|
-
...
|
|
1513
|
+
...readQueueConsumerOptions(definition.handler, scanner),
|
|
1176
1514
|
queue: getCloudflareQueueName(definition.name, namePrefix)
|
|
1177
1515
|
};
|
|
1178
1516
|
}),
|
|
@@ -1198,7 +1536,7 @@ function renderNitroPlugin(pluginFile, registryFile, queueConfig, cloudflareQueu
|
|
|
1198
1536
|
...cloudflare ? [`import { createQueueCloudflareWorker } from ${JSON.stringify(createImportPath(pluginFile, resolveRuntimeModule("internal/runtime/cloudflare-vite")))}`] : [],
|
|
1199
1537
|
...cloudflareRuntime ? [`import { createCloudflareQueueRuntimeClient } from ${JSON.stringify(createImportPath(pluginFile, resolveRuntimeModule("internal/runtime/cloudflare-client")))}`] : [],
|
|
1200
1538
|
...localRuntime ? [`import { closeLocalQueues, createLocalQueueRuntimeClient, startLocalQueue } from ${JSON.stringify(createImportPath(pluginFile, resolveRuntimeModule("internal/runtime/local-client")))}`] : [],
|
|
1201
|
-
...postgresRuntime ? [`import { closePostgresQueues, createPostgresQueueRuntimeClient, startPostgresQueue } from ${JSON.stringify(createImportPath(pluginFile, resolveRuntimeModule("internal/runtime/postgres-client")))}`] : [],
|
|
1539
|
+
...postgresRuntime ? [`import { closePostgresQueues, createPostgresQueueRuntimeClient, readQueueWorkers, startPostgresQueue } from ${JSON.stringify(createImportPath(pluginFile, resolveRuntimeModule("internal/runtime/postgres-client")))}`] : [],
|
|
1202
1540
|
...vercelRuntime ? [`import { createVercelQueueRuntimeClient } from ${JSON.stringify(createImportPath(pluginFile, resolveRuntimeModule("internal/runtime/vercel-client")))}`] : [],
|
|
1203
1541
|
`import { setQueueRuntimeConfig, setQueueRuntimeEventDefaults, setQueueRuntimeRegistry } from ${JSON.stringify(createImportPath(pluginFile, resolveRuntimeModule("internal/runtime/state")))}`,
|
|
1204
1542
|
`import queueRegistry from ${JSON.stringify(createImportPath(pluginFile, registryFile))}`,
|
|
@@ -1206,6 +1544,7 @@ function renderNitroPlugin(pluginFile, registryFile, queueConfig, cloudflareQueu
|
|
|
1206
1544
|
...cloudflareGlobals ? ["const { env: vitehubEnv, waitUntil: vitehubWaitUntil } = vitehubCloudflareWorkers as unknown as { env: Record<string, unknown>, waitUntil(promise: Promise<unknown>): void }", ""] : [],
|
|
1207
1545
|
...vercelRuntime ? ["globalThis.__vitehubVercelQueue = __vitehubVercelQueue", ""] : [],
|
|
1208
1546
|
`const queueConfig = ${JSON.stringify(queueConfig, null, 2)}`,
|
|
1547
|
+
...postgresRuntime ? ["const queueWorkers = readQueueWorkers()"] : [],
|
|
1209
1548
|
...cloudflare ? [`const queueDefinitions = ${JSON.stringify(queueDefinitions, null, 2)}`, "const queueWorker = createQueueCloudflareWorker({ definitions: queueDefinitions, queue: queueConfig, registry: queueRegistry })"] : [],
|
|
1210
1549
|
"",
|
|
1211
1550
|
`export default definePlugin((${cloudflare || localRuntime || postgresRuntime ? "nitro" : ""}) => {`,
|
|
@@ -1214,7 +1553,7 @@ function renderNitroPlugin(pluginFile, registryFile, queueConfig, cloudflareQueu
|
|
|
1214
1553
|
...cloudflareGlobals ? [" setQueueRuntimeEventDefaults({ env: vitehubEnv, waitUntil: vitehubWaitUntil })"] : [],
|
|
1215
1554
|
...cloudflare ? [" nitro.hooks.hook('cloudflare:queue', ({ batch, context, env }) => queueWorker.queue(batch, env, context))"] : [],
|
|
1216
1555
|
...localRuntime ? [" startLocalQueue(queueConfig)", " nitro.hooks.hook('close', closeLocalQueues)"] : [],
|
|
1217
|
-
...postgresRuntime ? [postgresDatabase ? ` startPostgresQueue(queueConfig, () => import(${JSON.stringify(databaseImport)}).then(module => module.databases))` : " startPostgresQueue(queueConfig)", " nitro.hooks.hook('close', closePostgresQueues)"] : [],
|
|
1556
|
+
...postgresRuntime ? [postgresDatabase ? ` startPostgresQueue(queueConfig, () => import(${JSON.stringify(databaseImport)}).then(module => module.databases), queueWorkers)` : " startPostgresQueue(queueConfig, undefined, queueWorkers)", " nitro.hooks.hook('close', closePostgresQueues)"] : [],
|
|
1218
1557
|
"})",
|
|
1219
1558
|
""
|
|
1220
1559
|
].join("\n");
|
|
@@ -1240,38 +1579,40 @@ function renderNitroMiddleware(middlewareFile, queueConfig, hasDefinitions, deve
|
|
|
1240
1579
|
].join("\n");
|
|
1241
1580
|
}
|
|
1242
1581
|
/** Writes the generated Queue integration and returns the Queue config that its Nitro plugin uses. */
|
|
1243
|
-
async function writeQueueNitroIntegration(rootDir, queue, hosting, cloudflareQueues = true, definitions = discoverQueueDefinitions({ rootDir }), development = false, importBase = queuePackageName, database = {}) {
|
|
1582
|
+
async function writeQueueNitroIntegration(rootDir, queue, hosting, cloudflareQueues = true, definitions = discoverQueueDefinitions({ rootDir }), development = false, importBase = queuePackageName, database = {}, owner = "app") {
|
|
1583
|
+
const paths = queueGeneratedPaths(owner);
|
|
1244
1584
|
await writeQueueTypes(rootDir, definitions, importBase);
|
|
1245
|
-
const generatedDir =
|
|
1585
|
+
const generatedDir = resolve(rootDir, paths.registryDir);
|
|
1246
1586
|
const registryFile = resolve(generatedDir, generatedRegistryFileName);
|
|
1247
|
-
const pluginFile = resolve(rootDir,
|
|
1248
|
-
const middlewareFile = resolve(rootDir,
|
|
1587
|
+
const pluginFile = resolve(rootDir, paths.plugin);
|
|
1588
|
+
const middlewareFile = resolve(rootDir, paths.middleware);
|
|
1249
1589
|
const queueConfig = resolveOutputQueueConfig(typeof queue === "undefined" ? {} : queue, hosting, database.postgres === true);
|
|
1250
1590
|
const queueDefinitions = cloudflareQueues && queueConfig !== false && queueConfig.driver === "cloudflare" ? createCloudflareQueueDefinitionNames(definitions, queueConfig.namePrefix) : {};
|
|
1251
1591
|
const runtimeConfig = resolveRuntimeQueueConfig(queueConfig, development, rootDir);
|
|
1252
1592
|
await Promise.all([mkdir(dirname(pluginFile), { recursive: true }), mkdir(generatedDir, { recursive: true })]);
|
|
1253
|
-
const vercelConsumerDir = resolve(rootDir,
|
|
1254
|
-
const vercelConsumers = queueConfig !== false && queueConfig.driver === "vercel" ? createVercelQueueConsumerRoutes(definitions) : [];
|
|
1255
|
-
|
|
1593
|
+
const vercelConsumerDir = resolve(rootDir, paths.vercelConsumerDir);
|
|
1594
|
+
const vercelConsumers = queueConfig !== false && queueConfig.driver === "vercel" ? createVercelQueueConsumerRoutes(definitions, owner) : [];
|
|
1595
|
+
const vercelConsumerFiles = new Set(vercelConsumers.map((consumer) => resolve(rootDir, consumer.handler)));
|
|
1596
|
+
const staleVercelConsumerFiles = (await readdir(vercelConsumerDir).catch(() => [])).map((name) => resolve(vercelConsumerDir, name)).filter((file) => !vercelConsumerFiles.has(file));
|
|
1597
|
+
await Promise.all(staleVercelConsumerFiles.map((file) => rm(file, {
|
|
1256
1598
|
force: true,
|
|
1257
1599
|
recursive: true
|
|
1258
|
-
});
|
|
1259
|
-
if (vercelConsumers.length) await mkdir(vercelConsumerDir, { recursive: true });
|
|
1600
|
+
})));
|
|
1260
1601
|
await Promise.all([
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1602
|
+
writeFileIfChanged(registryFile, createRuntimeRegistryContents(registryFile, definitions)),
|
|
1603
|
+
writeFileIfChanged(pluginFile, renderNitroPlugin(pluginFile, registryFile, runtimeConfig, cloudflareQueues, queueDefinitions, development, database.import ?? "@vite-hub/database/runtime/registry")),
|
|
1604
|
+
writeFileIfChanged(middlewareFile, renderNitroMiddleware(middlewareFile, runtimeConfig, definitions.length > 0, development)),
|
|
1264
1605
|
...vercelConsumers.map(async (consumer) => {
|
|
1265
1606
|
const file = resolve(rootDir, consumer.handler);
|
|
1266
|
-
await
|
|
1607
|
+
await writeFileIfChanged(file, renderVercelQueueConsumerHandler(file, consumer));
|
|
1267
1608
|
}),
|
|
1268
|
-
...process.env.VITEST ? [
|
|
1269
|
-
`import { setQueueRuntimeConfig, setQueueRuntimeRegistry } from ${JSON.stringify(createImportPath(resolve(rootDir,
|
|
1609
|
+
...process.env.VITEST ? [writeFileIfChanged(resolve(rootDir, paths.testSetup), [
|
|
1610
|
+
`import { setQueueRuntimeConfig, setQueueRuntimeRegistry } from ${JSON.stringify(createImportPath(resolve(rootDir, paths.testSetup), resolveRuntimeModule("internal/runtime/state")))}`,
|
|
1270
1611
|
`import registry from "./${generatedRegistryFileName}"`,
|
|
1271
1612
|
`setQueueRuntimeConfig(${JSON.stringify(queueConfig)})`,
|
|
1272
1613
|
"setQueueRuntimeRegistry(registry)",
|
|
1273
1614
|
""
|
|
1274
|
-
].join("\n")
|
|
1615
|
+
].join("\n"))] : []
|
|
1275
1616
|
]);
|
|
1276
1617
|
return queueConfig;
|
|
1277
1618
|
}
|
|
@@ -1288,7 +1629,8 @@ function sanitizeVercelConsumerName(functionPath) {
|
|
|
1288
1629
|
* Maps each Queue Definition to a Nitro route with a Vercel queue trigger.
|
|
1289
1630
|
* The consumer name keeps the function path of earlier ViteHub releases, so a redeploy keeps the Vercel consumer group.
|
|
1290
1631
|
*/
|
|
1291
|
-
function createVercelQueueConsumerRoutes(definitions) {
|
|
1632
|
+
function createVercelQueueConsumerRoutes(definitions, owner = "app") {
|
|
1633
|
+
const { vercelConsumerDir } = queueGeneratedPaths(owner);
|
|
1292
1634
|
const routes = /* @__PURE__ */ new Map();
|
|
1293
1635
|
return definitions.map((definition) => {
|
|
1294
1636
|
const segments = definition.name.replace(/[^a-z0-9/_-]+/gi, "_").split("/");
|
|
@@ -1303,22 +1645,24 @@ function createVercelQueueConsumerRoutes(definitions) {
|
|
|
1303
1645
|
const consumer = sanitizeVercelConsumerName(`${route.slice(1)}.func`);
|
|
1304
1646
|
return {
|
|
1305
1647
|
consumer,
|
|
1306
|
-
handler: `${
|
|
1648
|
+
handler: `${vercelConsumerDir}/${consumer}.mjs`,
|
|
1307
1649
|
name: definition.name,
|
|
1308
1650
|
route,
|
|
1309
1651
|
topic: getVercelQueueTopicName(definition.name)
|
|
1310
1652
|
};
|
|
1311
1653
|
});
|
|
1312
1654
|
}
|
|
1313
|
-
function renderVercelQueueConsumerHandler(file, name) {
|
|
1655
|
+
function renderVercelQueueConsumerHandler(file, { consumer, name }) {
|
|
1314
1656
|
return [
|
|
1315
1657
|
`import { handleHostedVercelQueueCallback } from ${JSON.stringify(createImportPath(file, resolveRuntimeModule("runtime/hosted")))}`,
|
|
1316
1658
|
`import { loadQueueDefinition, missingQueueDefinitionError } from ${JSON.stringify(createImportPath(file, resolveRuntimeModule("internal/runtime/state")))}`,
|
|
1317
1659
|
"",
|
|
1318
1660
|
`const name = ${JSON.stringify(name)}`,
|
|
1661
|
+
`const isConsumerFunction = process.env.${vercelQueueFunctionEnv} === ${JSON.stringify(consumer)}`,
|
|
1319
1662
|
"",
|
|
1320
1663
|
"export default {",
|
|
1321
1664
|
" async fetch(request) {",
|
|
1665
|
+
" if (!isConsumerFunction) return new Response(null, { status: 404 })",
|
|
1322
1666
|
" const definition = await loadQueueDefinition(name)",
|
|
1323
1667
|
" if (!definition) throw missingQueueDefinitionError(name)",
|
|
1324
1668
|
" return await handleHostedVercelQueueCallback(request, name, definition)",
|
|
@@ -1513,6 +1857,13 @@ function readProviderErrorCodes(body) {
|
|
|
1513
1857
|
function isShellSafeProvisionValue(value) {
|
|
1514
1858
|
return /^[A-Za-z0-9][\w.-]*$/.test(value);
|
|
1515
1859
|
}
|
|
1860
|
+
/**
|
|
1861
|
+
* The warning of a Cloudflare Provision Step that skips without credentials. `vitehub provision` and `vitehub deploy`
|
|
1862
|
+
* read a `wrangler login` of the Wrangler installed in the project, so the warning names it.
|
|
1863
|
+
*/
|
|
1864
|
+
function cloudflareProvisionSkipWarning(skipping) {
|
|
1865
|
+
return `${skipping}, missing CLOUDFLARE_ACCOUNT_ID/CLOUDFLARE_API_TOKEN. Install Wrangler in the project and run \`npx wrangler login\`, or set both variables. With more than one Cloudflare account, also set CLOUDFLARE_ACCOUNT_ID.`;
|
|
1866
|
+
}
|
|
1516
1867
|
function resolveCloudflareProvisionConfig(env) {
|
|
1517
1868
|
const credentials = readHostCredentialsFromEnv("cloudflare", env);
|
|
1518
1869
|
if (!credentials?.accountId) return;
|
|
@@ -1646,7 +1997,7 @@ function createQueueProvisionStep(resolveDefinitions, resolveNamePrefix = () =>
|
|
|
1646
1997
|
async plan(context) {
|
|
1647
1998
|
const config = resolveCloudflareProvisionConfig(context.env);
|
|
1648
1999
|
if (!config) {
|
|
1649
|
-
context.logger.warn("queue: skipping Cloudflare queues
|
|
2000
|
+
context.logger.warn(cloudflareProvisionSkipWarning("queue: skipping Cloudflare queues"));
|
|
1650
2001
|
context.markPlanUnchecked?.();
|
|
1651
2002
|
return [];
|
|
1652
2003
|
}
|
|
@@ -1730,23 +2081,30 @@ function supportsCloudflareQueues(nitro) {
|
|
|
1730
2081
|
function isGeneratedNitroRegistration(value, generatedPath) {
|
|
1731
2082
|
return typeof value === "string" && (value === generatedPath || value.replaceAll("\\", "/").endsWith(`/${generatedPath}`));
|
|
1732
2083
|
}
|
|
1733
|
-
function isGeneratedVercelConsumer(value) {
|
|
1734
|
-
return typeof value === "string" && value.replaceAll("\\", "/").includes(
|
|
2084
|
+
function isGeneratedVercelConsumer(value, vercelConsumerDir) {
|
|
2085
|
+
return typeof value === "string" && value.replaceAll("\\", "/").includes(`${vercelConsumerDir}/`);
|
|
1735
2086
|
}
|
|
1736
2087
|
function hostsVercelQueueConsumers(nitro) {
|
|
1737
2088
|
const hosting = getHostingProvider(resolveHost({ nitro }));
|
|
1738
2089
|
return hosting === "vercel" || hosting === void 0 && Boolean(process.env.VERCEL);
|
|
1739
2090
|
}
|
|
1740
|
-
function addVercelQueueConsumers(kit, definitions, root) {
|
|
2091
|
+
function addVercelQueueConsumers(kit, definitions, root, owner) {
|
|
1741
2092
|
const vercel = cloneRecord(kit.config.vercel);
|
|
1742
2093
|
const functionRules = cloneRecord(vercel.functionRules);
|
|
1743
|
-
for (const consumer of createVercelQueueConsumerRoutes(definitions)) {
|
|
2094
|
+
for (const consumer of createVercelQueueConsumerRoutes(definitions, owner)) {
|
|
2095
|
+
const rule = cloneRecord(functionRules[consumer.route]);
|
|
1744
2096
|
kit.addHandler({
|
|
1745
2097
|
handler: root ? resolve$1(root, consumer.handler) : consumer.handler,
|
|
2098
|
+
lazy: false,
|
|
2099
|
+
meta: { ...ownAccessHandlerMeta },
|
|
1746
2100
|
route: consumer.route
|
|
1747
2101
|
});
|
|
1748
2102
|
functionRules[consumer.route] = {
|
|
1749
|
-
...
|
|
2103
|
+
...rule,
|
|
2104
|
+
environment: {
|
|
2105
|
+
...cloneRecord(rule.environment),
|
|
2106
|
+
[vercelQueueFunctionEnv]: consumer.consumer
|
|
2107
|
+
},
|
|
1750
2108
|
experimentalTriggers: [{
|
|
1751
2109
|
consumer: consumer.consumer,
|
|
1752
2110
|
topic: consumer.topic,
|
|
@@ -1759,17 +2117,31 @@ function addVercelQueueConsumers(kit, definitions, root) {
|
|
|
1759
2117
|
functionRules
|
|
1760
2118
|
};
|
|
1761
2119
|
}
|
|
2120
|
+
const queueWranglerModules = /* @__PURE__ */ new WeakSet();
|
|
2121
|
+
function queueWranglerModule(consumers) {
|
|
2122
|
+
const module = (nitro) => {
|
|
2123
|
+
nitro.hooks.hook("compiled", async () => {
|
|
2124
|
+
if (nitro.options.cloudflare?.deployConfig === false) return;
|
|
2125
|
+
await finalizeCloudflareQueueConsumers(nitro.options.output.serverDir, consumers);
|
|
2126
|
+
});
|
|
2127
|
+
};
|
|
2128
|
+
queueWranglerModules.add(module);
|
|
2129
|
+
return module;
|
|
2130
|
+
}
|
|
1762
2131
|
async function mergeNitroConfig(config, value, queue, root, definitions) {
|
|
1763
2132
|
const providerOutput = useProviderOutputCatalog(config);
|
|
1764
2133
|
const nitro = cloneRecord(value);
|
|
2134
|
+
if (Array.isArray(nitro.modules)) nitro.modules = nitro.modules.filter((module) => !queueWranglerModules.has(module));
|
|
1765
2135
|
const nitroHosting = getHostingProvider(resolveHost({ nitro }));
|
|
1766
2136
|
const normalizedQueue = normalizeQueueForHosting(queue, nitroHosting);
|
|
1767
2137
|
const runtimeEnabled = queue !== false && !(queue !== false && nitroHosting && queue && normalizedQueue === void 0);
|
|
1768
2138
|
const nitroOwnsPaths = hasNitroConfigContext(config);
|
|
1769
|
-
const
|
|
1770
|
-
const
|
|
1771
|
-
|
|
1772
|
-
|
|
2139
|
+
const owner = viteHubGeneratedOwner(config);
|
|
2140
|
+
const paths = queueGeneratedPaths(owner);
|
|
2141
|
+
const plugin = nitroOwnsPaths ? resolve$1(root, paths.plugin) : paths.plugin;
|
|
2142
|
+
const middleware = nitroOwnsPaths ? resolve$1(root, paths.middleware) : paths.middleware;
|
|
2143
|
+
nitro.plugins = Array.isArray(nitro.plugins) ? nitro.plugins.filter((entry) => !isGeneratedNitroRegistration(entry, paths.plugin)) : [];
|
|
2144
|
+
nitro.handlers = Array.isArray(nitro.handlers) ? nitro.handlers.filter((handler) => !isGeneratedNitroRegistration(handler?.handler, paths.middleware) && !isGeneratedVercelConsumer(handler?.handler, paths.vercelConsumerDir)) : [];
|
|
1773
2145
|
const kit = createNitroServerKit(nitro);
|
|
1774
2146
|
if (!runtimeEnabled) {
|
|
1775
2147
|
contributeCloudflareProviderOutput(providerOutput, { owner: "queue" });
|
|
@@ -1783,7 +2155,7 @@ async function mergeNitroConfig(config, value, queue, root, definitions) {
|
|
|
1783
2155
|
}, "start");
|
|
1784
2156
|
const queueHosting = resolveQueueHosting(queue, resolveQueueHost(config, nitro));
|
|
1785
2157
|
const resolvedVercelQueue = queueHosting === "vercel" ? normalizeQueueOptions(queue, { hosting: queueHosting }) : void 0;
|
|
1786
|
-
if (resolvedVercelQueue && resolvedVercelQueue.driver === "vercel" && hostsVercelQueueConsumers(nitro)) addVercelQueueConsumers(kit, definitions, nitroOwnsPaths ? root : void 0);
|
|
2158
|
+
if (resolvedVercelQueue && resolvedVercelQueue.driver === "vercel" && hostsVercelQueueConsumers(nitro)) addVercelQueueConsumers(kit, definitions, nitroOwnsPaths ? root : void 0, owner);
|
|
1787
2159
|
if (queueHosting !== "cloudflare") {
|
|
1788
2160
|
contributeCloudflareProviderOutput(providerOutput, { owner: "queue" });
|
|
1789
2161
|
return composeNitroCloudflareProviderOutput(providerOutput, kit.config, value);
|
|
@@ -1829,7 +2201,14 @@ async function mergeNitroConfig(config, value, queue, root, definitions) {
|
|
|
1829
2201
|
producers: generatedProducers
|
|
1830
2202
|
}
|
|
1831
2203
|
});
|
|
1832
|
-
|
|
2204
|
+
if (cloudflareQueues && generated.consumers.some((consumer) => consumer.max_retries !== void 0)) {
|
|
2205
|
+
const modules = Array.isArray(nitro.modules) ? nitro.modules : [];
|
|
2206
|
+
nitro.modules = [queueWranglerModule(generated.consumers), ...modules];
|
|
2207
|
+
}
|
|
2208
|
+
return composeNitroCloudflareProviderOutput(providerOutput, {
|
|
2209
|
+
...baseNitro,
|
|
2210
|
+
modules: nitro.modules
|
|
2211
|
+
}, value);
|
|
1833
2212
|
}
|
|
1834
2213
|
function hubQueue(options, internalOptions = {}) {
|
|
1835
2214
|
let resolved;
|
|
@@ -1860,7 +2239,7 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
1860
2239
|
});
|
|
1861
2240
|
}
|
|
1862
2241
|
function discoverViteQueueDefinitions(viteRoot, outputRoot, found) {
|
|
1863
|
-
return resolve$1(viteRoot) === outputRoot ? discoverQueueDefinitions({
|
|
2242
|
+
return resolve$1(viteRoot) === outputRoot && !serverDirs ? discoverQueueDefinitions({
|
|
1864
2243
|
contributions: found,
|
|
1865
2244
|
rootDir: viteRoot
|
|
1866
2245
|
}) : discoverQueueDefinitions({
|
|
@@ -1881,6 +2260,7 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
1881
2260
|
import: internalOptions.databaseImport,
|
|
1882
2261
|
postgres: postgresDatabase
|
|
1883
2262
|
});
|
|
2263
|
+
let generatedOwner = "app";
|
|
1884
2264
|
const nodeWrites = /* @__PURE__ */ new Map();
|
|
1885
2265
|
function recordNodeWrite(rootDir, queue, host, definitions) {
|
|
1886
2266
|
if (host !== "node") return;
|
|
@@ -1889,6 +2269,7 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
1889
2269
|
definitions,
|
|
1890
2270
|
development: localDevelopment,
|
|
1891
2271
|
nitroQueue,
|
|
2272
|
+
owner: generatedOwner,
|
|
1892
2273
|
postgres: postgresDatabase,
|
|
1893
2274
|
queue
|
|
1894
2275
|
});
|
|
@@ -1957,6 +2338,7 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
1957
2338
|
["__vitehubNitroConfigContext"]: true,
|
|
1958
2339
|
nitro
|
|
1959
2340
|
};
|
|
2341
|
+
if (viteConfig) generatedOwner = viteHubGeneratedOwner(viteConfig);
|
|
1960
2342
|
const resolvedConfig = resolvedConfigs.get(root);
|
|
1961
2343
|
const state = resolvedConfig ? buildStates.get(resolvedConfig) : void 0;
|
|
1962
2344
|
const projectQueue = viteConfig ? getResolvedFeatureOptions(viteConfig, "queue") ?? options : state ? state.queue : queueOptions.has(root) ? queueOptions.get(root) : options;
|
|
@@ -1989,13 +2371,14 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
1989
2371
|
};
|
|
1990
2372
|
nuxtStates.set(root, nuxtState);
|
|
1991
2373
|
if (state) Object.assign(state, nuxtState);
|
|
1992
|
-
writtenQueue = await writeQueueNitroIntegration(projectRoot, nitroQueue, hosting, cloudflareQueues, definitions, localDevelopment, internalOptions.importBase, database());
|
|
2374
|
+
writtenQueue = await writeQueueNitroIntegration(projectRoot, nitroQueue, hosting, cloudflareQueues, definitions, localDevelopment, internalOptions.importBase, database(), generatedOwner);
|
|
1993
2375
|
recordNodeWrite(projectRoot, projectQueue, host, definitions);
|
|
1994
2376
|
return configuredNitro;
|
|
1995
2377
|
} }
|
|
1996
2378
|
},
|
|
1997
2379
|
async config(config, env) {
|
|
1998
2380
|
preview = env?.isPreview === true;
|
|
2381
|
+
generatedOwner = viteHubGeneratedOwner(config);
|
|
1999
2382
|
queue = getResolvedFeatureOptions(config, "queue") ?? options;
|
|
2000
2383
|
queueOptions.set(resolve$1(config.root || process.cwd()), queue);
|
|
2001
2384
|
serverDirs = config["__vitehubServerDirs"] ?? serverDirs;
|
|
@@ -2005,10 +2388,11 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
2005
2388
|
contributions = await collectPluginQueueContributions(config.plugins, root, configuredRoot);
|
|
2006
2389
|
const nitro = config.nitro;
|
|
2007
2390
|
config.nitro = await mergeNitroConfig(config, nitro, queue, outputRoot, discoverViteQueueDefinitions(root, outputRoot, contributions));
|
|
2008
|
-
if (process.env.VITEST) return { test: { setupFiles: [resolve$1(outputRoot,
|
|
2391
|
+
if (process.env.VITEST) return { test: { setupFiles: [resolve$1(outputRoot, queueGeneratedPaths(generatedOwner).testSetup)] } };
|
|
2009
2392
|
},
|
|
2010
2393
|
async configResolved(config) {
|
|
2011
2394
|
resolved = config;
|
|
2395
|
+
generatedOwner = viteHubGeneratedOwner(config);
|
|
2012
2396
|
const configuredRoot = frameworkProjectRoot(config);
|
|
2013
2397
|
const nuxtState = nuxtStates.get(config.root) ?? (configuredRoot ? nuxtStates.get(configuredRoot) : void 0);
|
|
2014
2398
|
nuxtConfiguredDefinitions = nuxtState?.nuxtConfiguredDefinitions;
|
|
@@ -2035,7 +2419,7 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
2035
2419
|
nitroQueue = resolvedQueue?.driver && nitroHosting && resolvedQueue.driver !== nitroHosting ? false : queue;
|
|
2036
2420
|
validatesNitroDefinitions = hasNitroConfigContext(config) && nitroQueue !== false;
|
|
2037
2421
|
localDevelopment = config.command === "serve" && !preview;
|
|
2038
|
-
writtenQueue = await writeQueueNitroIntegration(outputRoot, nitroQueue, hosting, cloudflareQueues, configuredDefinitions, localDevelopment, internalOptions.importBase, database());
|
|
2422
|
+
writtenQueue = await writeQueueNitroIntegration(outputRoot, nitroQueue, hosting, cloudflareQueues, configuredDefinitions, localDevelopment, internalOptions.importBase, database(), generatedOwner);
|
|
2039
2423
|
recordNodeWrite(outputRoot, queue, host, configuredDefinitions);
|
|
2040
2424
|
buildStates.set(config, {
|
|
2041
2425
|
configuredDefinitions,
|
|
@@ -2059,7 +2443,7 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
2059
2443
|
resolved = context.server.config;
|
|
2060
2444
|
const outputRoot = nuxtProjectRoot || frameworkProjectRoot(resolved) || resolve$1(resolved.root);
|
|
2061
2445
|
const definitions = resolveNuxtDefinitions?.() ?? discoverViteQueueDefinitions(resolved.root, outputRoot, contributions);
|
|
2062
|
-
writtenQueue = await writeQueueNitroIntegration(outputRoot, nitroQueue, hosting, cloudflareQueues, definitions, localDevelopment, internalOptions.importBase, database());
|
|
2446
|
+
writtenQueue = await writeQueueNitroIntegration(outputRoot, nitroQueue, hosting, cloudflareQueues, definitions, localDevelopment, internalOptions.importBase, database(), generatedOwner);
|
|
2063
2447
|
},
|
|
2064
2448
|
async buildStart() {
|
|
2065
2449
|
const databaseConfig = databasePlugin?.api?.getConfig?.();
|
|
@@ -2069,7 +2453,7 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
2069
2453
|
if (write.postgres === postgresDatabase) continue;
|
|
2070
2454
|
write.postgres = postgresDatabase;
|
|
2071
2455
|
hosting = resolveQueueHosting(write.queue, "node", postgresDatabase);
|
|
2072
|
-
writtenQueue = await writeQueueNitroIntegration(rootDir, write.nitroQueue, hosting, write.cloudflareQueues, write.definitions, write.development, internalOptions.importBase, database());
|
|
2456
|
+
writtenQueue = await writeQueueNitroIntegration(rootDir, write.nitroQueue, hosting, write.cloudflareQueues, write.definitions, write.development, internalOptions.importBase, database(), write.owner);
|
|
2073
2457
|
}
|
|
2074
2458
|
},
|
|
2075
2459
|
buildEnd(error) {
|