alchemy 0.51.3 → 0.53.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/lib/cloudflare/assets.d.ts +1 -1
- package/lib/cloudflare/assets.d.ts.map +1 -1
- package/lib/cloudflare/bindings.d.ts +12 -11
- package/lib/cloudflare/bindings.d.ts.map +1 -1
- package/lib/cloudflare/bindings.js.map +1 -1
- package/lib/cloudflare/bound.d.ts +11 -18
- package/lib/cloudflare/bound.d.ts.map +1 -1
- package/lib/cloudflare/bucket.d.ts +4 -5
- package/lib/cloudflare/bucket.d.ts.map +1 -1
- package/lib/cloudflare/bucket.js +1 -16
- package/lib/cloudflare/bucket.js.map +1 -1
- package/lib/cloudflare/compatibility-date.gen.d.ts +1 -1
- package/lib/cloudflare/compatibility-date.gen.js +1 -1
- package/lib/cloudflare/d1-database.d.ts +85 -26
- package/lib/cloudflare/d1-database.d.ts.map +1 -1
- package/lib/cloudflare/d1-database.js +66 -47
- package/lib/cloudflare/d1-database.js.map +1 -1
- package/lib/cloudflare/d1-local-migrations.d.ts +10 -0
- package/lib/cloudflare/d1-local-migrations.d.ts.map +1 -0
- package/lib/cloudflare/d1-local-migrations.js +39 -0
- package/lib/cloudflare/d1-local-migrations.js.map +1 -0
- package/lib/cloudflare/dispatch-namespace.d.ts +4 -6
- package/lib/cloudflare/dispatch-namespace.d.ts.map +1 -1
- package/lib/cloudflare/dispatch-namespace.js +1 -11
- package/lib/cloudflare/dispatch-namespace.js.map +1 -1
- package/lib/cloudflare/event-source.d.ts +3 -3
- package/lib/cloudflare/event-source.d.ts.map +1 -1
- package/lib/cloudflare/hyperdrive.d.ts +3 -4
- package/lib/cloudflare/hyperdrive.d.ts.map +1 -1
- package/lib/cloudflare/hyperdrive.js +1 -9
- package/lib/cloudflare/hyperdrive.js.map +1 -1
- package/lib/cloudflare/index.d.ts +1 -0
- package/lib/cloudflare/index.d.ts.map +1 -1
- package/lib/cloudflare/index.js +1 -0
- package/lib/cloudflare/index.js.map +1 -1
- package/lib/cloudflare/kv-namespace.d.ts +4 -5
- package/lib/cloudflare/kv-namespace.d.ts.map +1 -1
- package/lib/cloudflare/kv-namespace.js +1 -14
- package/lib/cloudflare/kv-namespace.js.map +1 -1
- package/lib/cloudflare/pipeline.d.ts +4 -5
- package/lib/cloudflare/pipeline.d.ts.map +1 -1
- package/lib/cloudflare/pipeline.js +1 -12
- package/lib/cloudflare/pipeline.js.map +1 -1
- package/lib/cloudflare/queue-consumer.d.ts +3 -3
- package/lib/cloudflare/queue-consumer.d.ts.map +1 -1
- package/lib/cloudflare/queue.d.ts +3 -4
- package/lib/cloudflare/queue.d.ts.map +1 -1
- package/lib/cloudflare/queue.js +1 -11
- package/lib/cloudflare/queue.js.map +1 -1
- package/lib/cloudflare/vectorize-index.d.ts +4 -5
- package/lib/cloudflare/vectorize-index.d.ts.map +1 -1
- package/lib/cloudflare/vectorize-index.js +1 -15
- package/lib/cloudflare/vectorize-index.js.map +1 -1
- package/lib/cloudflare/vectorize-metadata-index.d.ts +2 -2
- package/lib/cloudflare/vectorize-metadata-index.d.ts.map +1 -1
- package/lib/cloudflare/worker-ref.d.ts +41 -0
- package/lib/cloudflare/worker-ref.d.ts.map +1 -0
- package/lib/cloudflare/worker-ref.js +27 -0
- package/lib/cloudflare/worker-ref.js.map +1 -0
- package/lib/cloudflare/worker.d.ts +6 -68
- package/lib/cloudflare/worker.d.ts.map +1 -1
- package/lib/cloudflare/worker.js +5 -198
- package/lib/cloudflare/worker.js.map +1 -1
- package/lib/cloudflare/wrangler.json.js +2 -2
- package/lib/cloudflare/wrangler.json.js.map +1 -1
- package/lib/esbuild/bundle.d.ts +2 -2
- package/lib/state/instrumented-state-store.d.ts +2 -0
- package/lib/state/instrumented-state-store.d.ts.map +1 -1
- package/lib/state/instrumented-state-store.js +2 -0
- package/lib/state/instrumented-state-store.js.map +1 -1
- package/package.json +1 -1
- package/src/cloudflare/bindings.ts +18 -17
- package/src/cloudflare/bound.ts +35 -18
- package/src/cloudflare/bucket.ts +5 -27
- package/src/cloudflare/compatibility-date.gen.ts +1 -1
- package/src/cloudflare/d1-database.ts +107 -100
- package/src/cloudflare/d1-local-migrations.ts +52 -0
- package/src/cloudflare/dispatch-namespace.ts +6 -25
- package/src/cloudflare/event-source.ts +3 -3
- package/src/cloudflare/hyperdrive.ts +4 -19
- package/src/cloudflare/index.ts +1 -0
- package/src/cloudflare/kv-namespace.ts +5 -28
- package/src/cloudflare/pipeline.ts +8 -27
- package/src/cloudflare/queue-consumer.ts +3 -3
- package/src/cloudflare/queue.ts +4 -22
- package/src/cloudflare/vectorize-index.ts +5 -27
- package/src/cloudflare/vectorize-metadata-index.ts +2 -2
- package/src/cloudflare/worker-ref.ts +51 -0
- package/src/cloudflare/worker.ts +16 -332
- package/src/cloudflare/wrangler.json.ts +2 -2
- package/src/state/instrumented-state-store.ts +2 -0
package/src/cloudflare/worker.ts
CHANGED
|
@@ -6,13 +6,8 @@ import { isDeepStrictEqual } from "node:util";
|
|
|
6
6
|
import path from "pathe";
|
|
7
7
|
import type { Context } from "../context.ts";
|
|
8
8
|
import type { BundleProps } from "../esbuild/bundle.ts";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { isRuntime } from "../runtime/global.ts";
|
|
12
|
-
import { bootstrapPlugin } from "../runtime/plugin.ts";
|
|
13
|
-
import { Scope } from "../scope.ts";
|
|
14
|
-
import { Secret, isSecret, secret } from "../secret.ts";
|
|
15
|
-
import { serializeScope } from "../serde.ts";
|
|
9
|
+
import { Resource, ResourceKind } from "../resource.ts";
|
|
10
|
+
import { isSecret } from "../secret.ts";
|
|
16
11
|
import type { type } from "../type.ts";
|
|
17
12
|
import { DeferredPromise } from "../util/deferred-promise.ts";
|
|
18
13
|
import { logger } from "../util/logger.ts";
|
|
@@ -25,16 +20,12 @@ import {
|
|
|
25
20
|
createCloudflareApi,
|
|
26
21
|
} from "./api.ts";
|
|
27
22
|
import type { Assets } from "./assets.ts";
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
type WorkerBindingDurableObjectNamespace,
|
|
33
|
-
type WorkerBindingService,
|
|
34
|
-
type WorkerBindingSpec,
|
|
23
|
+
import type {
|
|
24
|
+
Bindings,
|
|
25
|
+
WorkerBindingDurableObjectNamespace,
|
|
26
|
+
WorkerBindingSpec,
|
|
35
27
|
} from "./bindings.ts";
|
|
36
28
|
import type { Bound } from "./bound.ts";
|
|
37
|
-
import { isBucket } from "./bucket.ts";
|
|
38
29
|
import {
|
|
39
30
|
type WorkerBundle,
|
|
40
31
|
type WorkerBundleChunk,
|
|
@@ -49,36 +40,27 @@ import {
|
|
|
49
40
|
} from "./compatibility-presets.ts";
|
|
50
41
|
import { type Container, ContainerApplication } from "./container.ts";
|
|
51
42
|
import { CustomDomain } from "./custom-domain.ts";
|
|
52
|
-
import {
|
|
53
|
-
import type { DispatchNamespaceResource } from "./dispatch-namespace.ts";
|
|
43
|
+
import type { DispatchNamespace } from "./dispatch-namespace.ts";
|
|
54
44
|
import {
|
|
55
45
|
DurableObjectNamespace,
|
|
56
46
|
isDurableObjectNamespace,
|
|
57
47
|
} from "./durable-object-namespace.ts";
|
|
58
|
-
import {
|
|
59
|
-
type EventSource,
|
|
60
|
-
type QueueEventSource,
|
|
61
|
-
isQueueEventSource,
|
|
62
|
-
} from "./event-source.ts";
|
|
63
|
-
import { isKVNamespace } from "./kv-namespace.ts";
|
|
48
|
+
import { type EventSource, isQueueEventSource } from "./event-source.ts";
|
|
64
49
|
import type { MiniflareWorkerOptions } from "./miniflare/miniflare-worker-options.ts";
|
|
65
50
|
import { miniflareServer } from "./miniflare/miniflare.ts";
|
|
66
|
-
import { isPipeline } from "./pipeline.ts";
|
|
67
51
|
import {
|
|
68
52
|
QueueConsumer,
|
|
69
53
|
deleteQueueConsumer,
|
|
70
54
|
listQueueConsumersForWorker,
|
|
71
55
|
} from "./queue-consumer.ts";
|
|
72
|
-
import {
|
|
56
|
+
import { isQueue } from "./queue.ts";
|
|
73
57
|
import { Route } from "./route.ts";
|
|
74
|
-
import { isVectorizeIndex } from "./vectorize-index.ts";
|
|
75
58
|
import { uploadAssets } from "./worker-assets.ts";
|
|
76
59
|
import {
|
|
77
60
|
type WorkerScriptMetadata,
|
|
78
61
|
bumpMigrationTagVersion,
|
|
79
62
|
prepareWorkerMetadata,
|
|
80
63
|
} from "./worker-metadata.ts";
|
|
81
|
-
import { WorkerStub, isWorkerStub } from "./worker-stub.ts";
|
|
82
64
|
import { WorkerSubdomain, disableWorkerSubdomain } from "./worker-subdomain.ts";
|
|
83
65
|
import { createTail } from "./worker-tail.ts";
|
|
84
66
|
import { Workflow, isWorkflow, upsertWorkflow } from "./workflow.ts";
|
|
@@ -330,7 +312,7 @@ export interface BaseWorkerProps<
|
|
|
330
312
|
*
|
|
331
313
|
* This allows workers to be routed to via dispatch namespace routing rules
|
|
332
314
|
*/
|
|
333
|
-
namespace?: string |
|
|
315
|
+
namespace?: string | DispatchNamespace;
|
|
334
316
|
|
|
335
317
|
/**
|
|
336
318
|
* Version label for this worker deployment
|
|
@@ -455,45 +437,6 @@ export type WorkerProps<
|
|
|
455
437
|
RPC extends Rpc.WorkerEntrypointBranded = Rpc.WorkerEntrypointBranded,
|
|
456
438
|
> = InlineWorkerProps<B, RPC> | EntrypointWorkerProps<B, RPC>;
|
|
457
439
|
|
|
458
|
-
export type FetchWorkerProps<
|
|
459
|
-
B extends Bindings = Bindings,
|
|
460
|
-
E extends EventSource[] = EventSource[],
|
|
461
|
-
> = Omit<WorkerProps<B>, "entrypoint" | "eventSources"> & {
|
|
462
|
-
/**
|
|
463
|
-
* A function that will be used to fetch the worker script.
|
|
464
|
-
*
|
|
465
|
-
* This is only used when using the fetch property.
|
|
466
|
-
*/
|
|
467
|
-
fetch?(
|
|
468
|
-
request: Request,
|
|
469
|
-
env: Bindings.Runtime<B>,
|
|
470
|
-
ctx: ExecutionContext,
|
|
471
|
-
): Promise<Response>;
|
|
472
|
-
/**
|
|
473
|
-
* Event sources that this worker will consume.
|
|
474
|
-
*
|
|
475
|
-
* Can include queues, streams, or other event sources.
|
|
476
|
-
*/
|
|
477
|
-
eventSources?: E;
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* A function that will be used to queue the worker script.
|
|
481
|
-
*
|
|
482
|
-
* This is only used when using the queue property.
|
|
483
|
-
*/
|
|
484
|
-
queue?(
|
|
485
|
-
batch: QueueBatch<E>,
|
|
486
|
-
env: Bindings.Runtime<B>,
|
|
487
|
-
ctx: ExecutionContext,
|
|
488
|
-
): Promise<void>;
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
type QueueBatch<E extends EventSource[]> = E[number] extends QueueEventSource
|
|
492
|
-
? any
|
|
493
|
-
: E[number] extends QueueResource<infer Body>
|
|
494
|
-
? MessageBatch<Body>
|
|
495
|
-
: MessageBatch<unknown>;
|
|
496
|
-
|
|
497
440
|
export function isWorker(resource: Resource): resource is Worker<any> {
|
|
498
441
|
return resource[ResourceKind] === "cloudflare::Worker";
|
|
499
442
|
}
|
|
@@ -505,8 +448,7 @@ export type Worker<
|
|
|
505
448
|
B extends Bindings | undefined = Bindings | undefined,
|
|
506
449
|
RPC extends Rpc.WorkerEntrypointBranded = Rpc.WorkerEntrypointBranded,
|
|
507
450
|
> = Resource<"cloudflare::Worker"> &
|
|
508
|
-
Omit<WorkerProps<B>, "url" | "script" | "routes" | "domains"> &
|
|
509
|
-
globalThis.Service & {
|
|
451
|
+
Omit<WorkerProps<B>, "url" | "script" | "routes" | "domains"> & {
|
|
510
452
|
/** @internal phantom property */
|
|
511
453
|
__rpc__?: RPC;
|
|
512
454
|
|
|
@@ -586,7 +528,7 @@ export type Worker<
|
|
|
586
528
|
/**
|
|
587
529
|
* The dispatch namespace this worker is deployed to
|
|
588
530
|
*/
|
|
589
|
-
namespace?: string |
|
|
531
|
+
namespace?: string | DispatchNamespace;
|
|
590
532
|
|
|
591
533
|
/**
|
|
592
534
|
* Version label for this worker deployment
|
|
@@ -601,56 +543,6 @@ export type Worker<
|
|
|
601
543
|
};
|
|
602
544
|
};
|
|
603
545
|
|
|
604
|
-
/**
|
|
605
|
-
* Represents a reference to a Cloudflare Worker service.
|
|
606
|
-
*
|
|
607
|
-
* @template RPC - The type of the worker's RPC entrypoint, defaults to Rpc.WorkerEntrypointBranded.
|
|
608
|
-
*
|
|
609
|
-
* This interface extends all properties of WorkerBindingService except for "name".
|
|
610
|
-
* It also includes an optional __rpc__ property for type branding.
|
|
611
|
-
*/
|
|
612
|
-
export type WorkerRef<
|
|
613
|
-
RPC extends Rpc.WorkerEntrypointBranded = Rpc.WorkerEntrypointBranded,
|
|
614
|
-
> = Omit<WorkerBindingService, "name"> & {
|
|
615
|
-
/**
|
|
616
|
-
* Optional type branding for the worker's RPC entrypoint.
|
|
617
|
-
*/
|
|
618
|
-
__rpc__?: RPC;
|
|
619
|
-
};
|
|
620
|
-
|
|
621
|
-
/**
|
|
622
|
-
* Creates a reference to a Cloudflare Worker service.
|
|
623
|
-
*
|
|
624
|
-
* @example
|
|
625
|
-
* // Create a reference to a Cloudflare Worker service:
|
|
626
|
-
* const ref = WorkerRef({
|
|
627
|
-
* service: "my-worker",
|
|
628
|
-
* environment: "production",
|
|
629
|
-
* namespace: "main"
|
|
630
|
-
* });
|
|
631
|
-
*
|
|
632
|
-
* // Optionally, you can specify only the service:
|
|
633
|
-
* const ref2 = WorkerRef({ service: "my-worker" });
|
|
634
|
-
*
|
|
635
|
-
* // You can also specify the RPC type for stronger typing:
|
|
636
|
-
* interface MyWorkerRPC extends Rpc.WorkerEntrypointBranded {
|
|
637
|
-
* myMethod(arg: string): Promise<number>;
|
|
638
|
-
* }
|
|
639
|
-
* const typedRef = WorkerRef<MyWorkerRPC>({ service: "my-worker" });
|
|
640
|
-
*/
|
|
641
|
-
export function WorkerRef<
|
|
642
|
-
RPC extends Rpc.WorkerEntrypointBranded = Rpc.WorkerEntrypointBranded,
|
|
643
|
-
>(options?: {
|
|
644
|
-
service: string;
|
|
645
|
-
environment?: string;
|
|
646
|
-
namespace?: string;
|
|
647
|
-
}): WorkerRef<RPC> {
|
|
648
|
-
return {
|
|
649
|
-
...options,
|
|
650
|
-
type: "service",
|
|
651
|
-
} as WorkerRef<RPC>;
|
|
652
|
-
}
|
|
653
|
-
|
|
654
546
|
/**
|
|
655
547
|
* A Cloudflare Worker is a serverless function that can be deployed to the Cloudflare network.
|
|
656
548
|
*
|
|
@@ -807,220 +699,12 @@ export function Worker<
|
|
|
807
699
|
const B extends Bindings,
|
|
808
700
|
RPC extends Rpc.WorkerEntrypointBranded,
|
|
809
701
|
>(id: string, props: WorkerProps<B, RPC>): Promise<Worker<B, RPC>>;
|
|
810
|
-
|
|
811
|
-
id: string,
|
|
812
|
-
meta: ImportMeta,
|
|
813
|
-
props: FetchWorkerProps<B, E>,
|
|
814
|
-
): Promise<Worker<B>> & globalThis.Service;
|
|
702
|
+
|
|
815
703
|
export function Worker<const B extends Bindings>(
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
| [id: string, meta: ImportMeta, props: FetchWorkerProps<B>]
|
|
704
|
+
id: string,
|
|
705
|
+
props: WorkerProps<B>,
|
|
819
706
|
): Promise<Worker<B>> {
|
|
820
|
-
|
|
821
|
-
args.length === 2 ? [args[0], undefined, args[1]] : args;
|
|
822
|
-
|
|
823
|
-
if (("fetch" in props && props.fetch) || ("queue" in props && props.queue)) {
|
|
824
|
-
const scope = Scope.current;
|
|
825
|
-
|
|
826
|
-
const workerName = props.name ?? id;
|
|
827
|
-
|
|
828
|
-
// we need to make sure the worker exists
|
|
829
|
-
const stub = WorkerStub(`${id}/stub`, {
|
|
830
|
-
name: workerName,
|
|
831
|
-
accountId: props.accountId,
|
|
832
|
-
apiKey: props.apiKey,
|
|
833
|
-
apiToken: props.apiToken,
|
|
834
|
-
baseUrl: props.baseUrl,
|
|
835
|
-
email: props.email,
|
|
836
|
-
});
|
|
837
|
-
|
|
838
|
-
async function collectResources(
|
|
839
|
-
scope: Scope | undefined,
|
|
840
|
-
): Promise<Resource[]> {
|
|
841
|
-
if (!scope) {
|
|
842
|
-
return [];
|
|
843
|
-
}
|
|
844
|
-
return (
|
|
845
|
-
await Promise.all(
|
|
846
|
-
Array.from(scope.resources.values()).map(async (resource) => [
|
|
847
|
-
(await resource) as Resource,
|
|
848
|
-
...(await collectResources(await resource[InnerResourceScope])),
|
|
849
|
-
]),
|
|
850
|
-
)
|
|
851
|
-
).flat();
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
const deferred = scope.defer(async () => {
|
|
855
|
-
const autoBindings: Record<string, Binding> = {};
|
|
856
|
-
for (const resource of await collectResources(Scope.root)) {
|
|
857
|
-
if (
|
|
858
|
-
isQueue(resource) ||
|
|
859
|
-
isWorkerStub(resource) ||
|
|
860
|
-
isWorker(resource) ||
|
|
861
|
-
isD1Database(resource) ||
|
|
862
|
-
isBucket(resource) ||
|
|
863
|
-
isPipeline(resource) ||
|
|
864
|
-
isVectorizeIndex(resource) ||
|
|
865
|
-
isKVNamespace(resource)
|
|
866
|
-
) {
|
|
867
|
-
// TODO(sam): make this generic/pluggable
|
|
868
|
-
autoBindings[getBindKey(resource)] = resource;
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
// TODO(sam): prune to only needed secrets
|
|
873
|
-
for (const secret of Secret.all()) {
|
|
874
|
-
autoBindings[secret.name] = secret;
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
const bindings = {
|
|
878
|
-
...props.bindings,
|
|
879
|
-
__ALCHEMY_WORKER_NAME__: workerName,
|
|
880
|
-
__ALCHEMY_SERIALIZED_SCOPE__: Json(await serializeScope(scope)),
|
|
881
|
-
ALCHEMY_STAGE: scope.stage,
|
|
882
|
-
ALCHEMY_PASSWORD: secret(scope.password),
|
|
883
|
-
// TODO(sam): prune un-needed bindings
|
|
884
|
-
...autoBindings,
|
|
885
|
-
};
|
|
886
|
-
|
|
887
|
-
return _Worker(id, {
|
|
888
|
-
...(props as any),
|
|
889
|
-
url: true,
|
|
890
|
-
compatibilityFlags: Array.from(
|
|
891
|
-
new Set([
|
|
892
|
-
"nodejs_compat",
|
|
893
|
-
...unionCompatibilityFlags(
|
|
894
|
-
props.compatibility,
|
|
895
|
-
props.compatibilityFlags,
|
|
896
|
-
),
|
|
897
|
-
]),
|
|
898
|
-
),
|
|
899
|
-
entrypoint: meta!.filename,
|
|
900
|
-
name: workerName,
|
|
901
|
-
// adopt because the stub guarnatees that the worker exists
|
|
902
|
-
adopt: true,
|
|
903
|
-
bindings,
|
|
904
|
-
bundle: {
|
|
905
|
-
...props.bundle,
|
|
906
|
-
plugins: [bootstrapPlugin],
|
|
907
|
-
external: [
|
|
908
|
-
// for alchemy
|
|
909
|
-
"libsodium*",
|
|
910
|
-
"@swc/*",
|
|
911
|
-
"esbuild",
|
|
912
|
-
// TODO(sam): this is for fetch, why is it a package?
|
|
913
|
-
"undici",
|
|
914
|
-
"miniflare",
|
|
915
|
-
"@iarna/toml",
|
|
916
|
-
"cli-*",
|
|
917
|
-
"react*",
|
|
918
|
-
],
|
|
919
|
-
banner: {
|
|
920
|
-
js: "var __ALCHEMY_RUNTIME__ = true;",
|
|
921
|
-
},
|
|
922
|
-
inject: [
|
|
923
|
-
...(props.bundle?.inject ?? []),
|
|
924
|
-
path.resolve(import.meta.dirname, "..", "runtime", "shims.js"),
|
|
925
|
-
],
|
|
926
|
-
},
|
|
927
|
-
});
|
|
928
|
-
}) as Promise<Worker<B>>;
|
|
929
|
-
|
|
930
|
-
// defer construction of this worker until the app is about to finaloze
|
|
931
|
-
// this ensures that the Worker's dependencies are instantiated before we bundle
|
|
932
|
-
// it is then safe to bundle and import the Worker to detect which resources need to be auto-bound
|
|
933
|
-
const promise = Promise.all([deferred, stub]).then(
|
|
934
|
-
([worker]) => worker,
|
|
935
|
-
) as Promise<Worker<B>> & {
|
|
936
|
-
fetch?: (...args: any[]) => Promise<Response>;
|
|
937
|
-
queue?: (
|
|
938
|
-
batch: QueueBatch<any>,
|
|
939
|
-
env: Bindings.Runtime<B>,
|
|
940
|
-
ctx: ExecutionContext,
|
|
941
|
-
) => Promise<void>;
|
|
942
|
-
};
|
|
943
|
-
|
|
944
|
-
if (isRuntime) {
|
|
945
|
-
if (props.fetch) {
|
|
946
|
-
promise.fetch = async (
|
|
947
|
-
request: Request,
|
|
948
|
-
env: Bindings.Runtime<B>,
|
|
949
|
-
ctx: ExecutionContext,
|
|
950
|
-
) => {
|
|
951
|
-
try {
|
|
952
|
-
return await props.fetch!(request, env as any, ctx);
|
|
953
|
-
} catch (err: any) {
|
|
954
|
-
return new Response(err.message + err.stack, {
|
|
955
|
-
status: 500,
|
|
956
|
-
});
|
|
957
|
-
}
|
|
958
|
-
};
|
|
959
|
-
}
|
|
960
|
-
if (props.queue) {
|
|
961
|
-
promise.queue = async (
|
|
962
|
-
batch: QueueBatch<any>,
|
|
963
|
-
env: Bindings.Runtime<B>,
|
|
964
|
-
ctx: ExecutionContext,
|
|
965
|
-
) => {
|
|
966
|
-
return await props.queue!(batch, env, ctx);
|
|
967
|
-
};
|
|
968
|
-
}
|
|
969
|
-
} else {
|
|
970
|
-
promise.fetch = async (
|
|
971
|
-
request: string | URL | Request,
|
|
972
|
-
init?: RequestInit,
|
|
973
|
-
) => {
|
|
974
|
-
const worker = await promise;
|
|
975
|
-
if (!worker.url) {
|
|
976
|
-
throw new Error("Worker URL is not available in runtime");
|
|
977
|
-
}
|
|
978
|
-
if (request instanceof Request) {
|
|
979
|
-
const origin = new URL(worker.url);
|
|
980
|
-
const incoming = request.url.startsWith("/")
|
|
981
|
-
? new URL(`${worker.url}${request.url}`)
|
|
982
|
-
: new URL(request.url);
|
|
983
|
-
logger.log(incoming);
|
|
984
|
-
const proxyURL = new URL(
|
|
985
|
-
`${incoming.pathname}${incoming.search}${incoming.hash}`,
|
|
986
|
-
origin,
|
|
987
|
-
);
|
|
988
|
-
|
|
989
|
-
const headers = new Headers(request.headers);
|
|
990
|
-
headers.set("host", origin.host);
|
|
991
|
-
|
|
992
|
-
try {
|
|
993
|
-
return await fetch(
|
|
994
|
-
new Request(proxyURL, {
|
|
995
|
-
method: request.method,
|
|
996
|
-
body: request.body,
|
|
997
|
-
headers,
|
|
998
|
-
// TODO(sam): do we need this? GPT added it ...
|
|
999
|
-
// redirect: "manual",
|
|
1000
|
-
}),
|
|
1001
|
-
);
|
|
1002
|
-
} catch (err: any) {
|
|
1003
|
-
return new Response(err.message ?? "proxy error", { status: 500 });
|
|
1004
|
-
}
|
|
1005
|
-
} else {
|
|
1006
|
-
if (typeof request === "string" && request.startsWith("/")) {
|
|
1007
|
-
request = new URL(`${worker.url}${request}`);
|
|
1008
|
-
}
|
|
1009
|
-
return await fetch(request, init);
|
|
1010
|
-
}
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
|
-
return promise;
|
|
1014
|
-
}
|
|
1015
|
-
return _Worker(id, props as WorkerProps<B>).then(async (worker) => {
|
|
1016
|
-
const binding = await tryGetBinding(worker);
|
|
1017
|
-
if (binding) {
|
|
1018
|
-
worker.fetch = (request: Request) => binding.fetch(request);
|
|
1019
|
-
worker.connect = (address: SocketAddress, options: SocketOptions) =>
|
|
1020
|
-
binding.connect(address, options);
|
|
1021
|
-
}
|
|
1022
|
-
return worker;
|
|
1023
|
-
});
|
|
707
|
+
return _Worker(id, props as WorkerProps<B>);
|
|
1024
708
|
}
|
|
1025
709
|
|
|
1026
710
|
export const _Worker = Resource(
|
|
@@ -557,7 +557,7 @@ function processBindings(
|
|
|
557
557
|
for (const eventSource of eventSources ?? []) {
|
|
558
558
|
if (isQueueEventSource(eventSource)) {
|
|
559
559
|
queues.consumers.push({
|
|
560
|
-
queue: eventSource.queue.
|
|
560
|
+
queue: eventSource.queue.name,
|
|
561
561
|
max_batch_size: eventSource.settings?.batchSize,
|
|
562
562
|
max_concurrency: eventSource.settings?.maxConcurrency,
|
|
563
563
|
max_retries: eventSource.settings?.maxRetries,
|
|
@@ -566,7 +566,7 @@ function processBindings(
|
|
|
566
566
|
});
|
|
567
567
|
} else if (isQueue(eventSource)) {
|
|
568
568
|
queues.consumers.push({
|
|
569
|
-
queue: eventSource.
|
|
569
|
+
queue: eventSource.name,
|
|
570
570
|
});
|
|
571
571
|
}
|
|
572
572
|
}
|
|
@@ -6,6 +6,8 @@ import type { Telemetry } from "../util/telemetry/types.ts";
|
|
|
6
6
|
export class InstrumentedStateStore<T extends StateStore>
|
|
7
7
|
implements StateStore
|
|
8
8
|
{
|
|
9
|
+
/** @internal */
|
|
10
|
+
__phantom?: T;
|
|
9
11
|
private readonly stateStore: StateStore;
|
|
10
12
|
private readonly telemetryClient: ITelemetryClient;
|
|
11
13
|
private readonly stateStoreClass: string;
|