effect-cf 0.46.0 → 0.47.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/CHANGELOG.md +16 -0
- package/README.md +2 -0
- package/dist/AiGateway.d.mts +7 -8
- package/dist/AnalyticsEngine.d.mts +5 -6
- package/dist/Artifacts.d.mts +24 -25
- package/dist/Cache.d.mts +11 -12
- package/dist/DurableObjectRpcWebSocket.mjs +20 -7
- package/dist/Email.d.mts +7 -8
- package/dist/Images.d.mts +53 -54
- package/dist/Kv.d.mts +0 -1
- package/dist/QueueBinding.d.mts +11 -12
- package/dist/R2.d.mts +14 -15
- package/dist/RpcWebSocketClient.d.mts +30 -0
- package/dist/RpcWebSocketClient.mjs +19 -0
- package/dist/Vectorize.d.mts +17 -18
- package/dist/WebTransport.d.mts +0 -1
- package/dist/WebTransport.mjs +31 -0
- package/dist/WorkersAi.d.mts +0 -1
- package/dist/WorkflowBinding.d.mts +14 -15
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +2 -1
- package/package.json +6 -1
- package/src/AiGateway.ts +2 -3
- package/src/AnalyticsEngine.ts +2 -6
- package/src/Artifacts.ts +8 -16
- package/src/Cache.ts +7 -13
- package/src/DurableObjectRpcWebSocket.ts +25 -2
- package/src/Email.ts +5 -11
- package/src/Images.ts +31 -60
- package/src/Kv.ts +2 -6
- package/src/QueueBinding.ts +8 -17
- package/src/R2.ts +29 -49
- package/src/RpcWebSocketClient.ts +45 -0
- package/src/Vectorize.ts +11 -29
- package/src/WebTransport.ts +2 -4
- package/src/WorkersAi.ts +2 -17
- package/src/WorkflowBinding.ts +14 -26
- package/src/index.ts +1 -0
package/src/R2.ts
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
R2Bucket as CloudflareR2Bucket,
|
|
3
|
-
R2Conditional as CloudflareR2Conditional,
|
|
4
|
-
R2GetOptions as CloudflareR2GetOptions,
|
|
5
|
-
R2ListOptions as CloudflareR2ListOptions,
|
|
6
|
-
R2MultipartOptions as CloudflareR2MultipartOptions,
|
|
7
|
-
R2MultipartUpload as CloudflareR2MultipartUpload,
|
|
8
|
-
R2Object as CloudflareR2Object,
|
|
9
|
-
R2ObjectBody as CloudflareR2ObjectBody,
|
|
10
|
-
R2Objects as CloudflareR2Objects,
|
|
11
|
-
R2PutOptions as CloudflareR2PutOptions,
|
|
12
|
-
R2UploadPartOptions as CloudflareR2UploadPartOptions,
|
|
13
|
-
R2UploadedPart as CloudflareR2UploadedPart,
|
|
14
|
-
} from "@cloudflare/workers-types";
|
|
15
1
|
import * as Context from "effect/Context";
|
|
16
2
|
import * as Data from "effect/Data";
|
|
17
3
|
import * as Effect from "effect/Effect";
|
|
@@ -60,19 +46,19 @@ export interface R2Definition {
|
|
|
60
46
|
readonly binding: string;
|
|
61
47
|
}
|
|
62
48
|
|
|
63
|
-
export type R2GetOptions =
|
|
64
|
-
export type
|
|
65
|
-
export type
|
|
66
|
-
export type
|
|
67
|
-
export type R2UploadPartOptions =
|
|
49
|
+
export type R2GetOptions = globalThis.R2GetOptions;
|
|
50
|
+
export type R2ListOptions = globalThis.R2ListOptions;
|
|
51
|
+
export type R2MultipartOptions = globalThis.R2MultipartOptions;
|
|
52
|
+
export type R2PutOptions = globalThis.R2PutOptions;
|
|
53
|
+
export type R2UploadPartOptions = globalThis.R2UploadPartOptions;
|
|
68
54
|
export type R2PutValue = ReadableStream | ArrayBuffer | ArrayBufferView | string | null | Blob;
|
|
69
55
|
export type R2UploadPartValue = ReadableStream | ArrayBuffer | ArrayBufferView | string | Blob;
|
|
70
56
|
|
|
71
57
|
export interface R2ObjectBodyClient extends Omit<
|
|
72
|
-
|
|
58
|
+
R2ObjectBody,
|
|
73
59
|
"arrayBuffer" | "blob" | "bytes" | "json" | "text"
|
|
74
60
|
> {
|
|
75
|
-
readonly raw:
|
|
61
|
+
readonly raw: R2ObjectBody;
|
|
76
62
|
readonly arrayBuffer: Effect.Effect<ArrayBuffer, R2OperationError>;
|
|
77
63
|
readonly bytes: Effect.Effect<Uint8Array, R2OperationError>;
|
|
78
64
|
readonly text: Effect.Effect<string, R2OperationError>;
|
|
@@ -81,29 +67,27 @@ export interface R2ObjectBodyClient extends Omit<
|
|
|
81
67
|
}
|
|
82
68
|
|
|
83
69
|
export interface R2MultipartUploadClient {
|
|
84
|
-
readonly raw:
|
|
70
|
+
readonly raw: R2MultipartUpload;
|
|
85
71
|
readonly key: string;
|
|
86
72
|
readonly uploadId: string;
|
|
87
73
|
readonly uploadPart: (
|
|
88
74
|
partNumber: number,
|
|
89
75
|
value: R2UploadPartValue,
|
|
90
76
|
options?: R2UploadPartOptions,
|
|
91
|
-
) => Effect.Effect<
|
|
77
|
+
) => Effect.Effect<R2UploadedPart, R2OperationError>;
|
|
92
78
|
readonly abort: Effect.Effect<void, R2OperationError>;
|
|
93
79
|
readonly complete: (
|
|
94
|
-
uploadedParts: ReadonlyArray<
|
|
95
|
-
) => Effect.Effect<
|
|
80
|
+
uploadedParts: ReadonlyArray<R2UploadedPart>,
|
|
81
|
+
) => Effect.Effect<R2Object, R2OperationError>;
|
|
96
82
|
}
|
|
97
83
|
|
|
98
84
|
export interface R2Client {
|
|
99
|
-
readonly head: (
|
|
100
|
-
key: string,
|
|
101
|
-
) => Effect.Effect<Option.Option<CloudflareR2Object>, R2OperationError>;
|
|
85
|
+
readonly head: (key: string) => Effect.Effect<Option.Option<R2Object>, R2OperationError>;
|
|
102
86
|
readonly get: {
|
|
103
87
|
(
|
|
104
88
|
key: string,
|
|
105
|
-
options: R2GetOptions & { readonly onlyIf:
|
|
106
|
-
): Effect.Effect<Option.Option<R2ObjectBodyClient |
|
|
89
|
+
options: R2GetOptions & { readonly onlyIf: R2Conditional | Headers },
|
|
90
|
+
): Effect.Effect<Option.Option<R2ObjectBodyClient | R2Object>, R2OperationError>;
|
|
107
91
|
(
|
|
108
92
|
key: string,
|
|
109
93
|
options?: R2GetOptions,
|
|
@@ -113,13 +97,13 @@ export interface R2Client {
|
|
|
113
97
|
(
|
|
114
98
|
key: string,
|
|
115
99
|
value: R2PutValue,
|
|
116
|
-
options: R2PutOptions & { readonly onlyIf:
|
|
117
|
-
): Effect.Effect<Option.Option<
|
|
100
|
+
options: R2PutOptions & { readonly onlyIf: R2Conditional | Headers },
|
|
101
|
+
): Effect.Effect<Option.Option<R2Object>, R2OperationError>;
|
|
118
102
|
(
|
|
119
103
|
key: string,
|
|
120
104
|
value: R2PutValue,
|
|
121
105
|
options?: R2PutOptions,
|
|
122
|
-
): Effect.Effect<
|
|
106
|
+
): Effect.Effect<R2Object, R2OperationError>;
|
|
123
107
|
};
|
|
124
108
|
readonly createMultipartUpload: (
|
|
125
109
|
key: string,
|
|
@@ -130,8 +114,8 @@ export interface R2Client {
|
|
|
130
114
|
uploadId: string,
|
|
131
115
|
) => Effect.Effect<R2MultipartUploadClient, R2OperationError>;
|
|
132
116
|
readonly delete: (keys: string | ReadonlyArray<string>) => Effect.Effect<void, R2OperationError>;
|
|
133
|
-
readonly list: (options?: R2ListOptions) => Effect.Effect<
|
|
134
|
-
readonly rawUnsafe: Effect.Effect<
|
|
117
|
+
readonly list: (options?: R2ListOptions) => Effect.Effect<R2Objects, R2OperationError>;
|
|
118
|
+
readonly rawUnsafe: Effect.Effect<R2Bucket>;
|
|
135
119
|
readonly definition: R2Definition;
|
|
136
120
|
}
|
|
137
121
|
|
|
@@ -189,9 +173,7 @@ const spanOptions = (binding: string, operation: R2Operation) => ({
|
|
|
189
173
|
attributes: { binding, operation },
|
|
190
174
|
});
|
|
191
175
|
|
|
192
|
-
const isR2ObjectBody = (
|
|
193
|
-
value: CloudflareR2ObjectBody | CloudflareR2Object,
|
|
194
|
-
): value is CloudflareR2ObjectBody =>
|
|
176
|
+
const isR2ObjectBody = (value: R2ObjectBody | R2Object): value is R2ObjectBody =>
|
|
195
177
|
"body" in value &&
|
|
196
178
|
Predicate.isFunction(value.arrayBuffer) &&
|
|
197
179
|
Predicate.isFunction(value.bytes) &&
|
|
@@ -199,7 +181,7 @@ const isR2ObjectBody = (
|
|
|
199
181
|
Predicate.isFunction(value.json) &&
|
|
200
182
|
Predicate.isFunction(value.blob);
|
|
201
183
|
|
|
202
|
-
const wrapObjectBody = (binding: string, object:
|
|
184
|
+
const wrapObjectBody = (binding: string, object: R2ObjectBody): R2ObjectBodyClient => ({
|
|
203
185
|
key: object.key,
|
|
204
186
|
version: object.version,
|
|
205
187
|
size: object.size,
|
|
@@ -238,8 +220,8 @@ const wrapObjectBody = (binding: string, object: CloudflareR2ObjectBody): R2Obje
|
|
|
238
220
|
|
|
239
221
|
const wrapGetResult = (
|
|
240
222
|
binding: string,
|
|
241
|
-
object:
|
|
242
|
-
): R2ObjectBodyClient |
|
|
223
|
+
object: R2ObjectBody | R2Object | null,
|
|
224
|
+
): R2ObjectBodyClient | R2Object | null => {
|
|
243
225
|
if (object === null || !isR2ObjectBody(object)) {
|
|
244
226
|
return object;
|
|
245
227
|
}
|
|
@@ -250,7 +232,7 @@ const wrapGetResult = (
|
|
|
250
232
|
type R2BindingValue = Schema.Schema.Type<typeof Schema.Unknown>;
|
|
251
233
|
|
|
252
234
|
const R2BucketSchema = Schema.declare(
|
|
253
|
-
(value: R2BindingValue): value is
|
|
235
|
+
(value: R2BindingValue): value is R2Bucket =>
|
|
254
236
|
Predicate.hasProperty(value, "head") &&
|
|
255
237
|
Predicate.isFunction(value.head) &&
|
|
256
238
|
Predicate.hasProperty(value, "get") &&
|
|
@@ -268,13 +250,11 @@ const R2BucketSchema = Schema.declare(
|
|
|
268
250
|
);
|
|
269
251
|
const decodeR2Bucket = Schema.decodeUnknownOption(R2BucketSchema);
|
|
270
252
|
|
|
271
|
-
export const isR2Bucket = (value: R2BindingValue): value is
|
|
253
|
+
export const isR2Bucket = (value: R2BindingValue): value is R2Bucket =>
|
|
272
254
|
Option.isSome(decodeR2Bucket(value));
|
|
273
255
|
|
|
274
|
-
export const makeClient = (
|
|
275
|
-
|
|
276
|
-
): ((bucket: CloudflareR2Bucket) => R2Client) => {
|
|
277
|
-
const wrapUpload = (upload: CloudflareR2MultipartUpload): R2MultipartUploadClient => ({
|
|
256
|
+
export const makeClient = (definition: R2Definition): ((bucket: R2Bucket) => R2Client) => {
|
|
257
|
+
const wrapUpload = (upload: R2MultipartUpload): R2MultipartUploadClient => ({
|
|
278
258
|
raw: upload,
|
|
279
259
|
key: upload.key,
|
|
280
260
|
uploadId: upload.uploadId,
|
|
@@ -295,7 +275,7 @@ export const makeClient = (
|
|
|
295
275
|
complete: Effect.fn(
|
|
296
276
|
"R2.completeMultipartUpload",
|
|
297
277
|
spanOptions(definition.binding, "completeMultipartUpload"),
|
|
298
|
-
)((uploadedParts: ReadonlyArray<
|
|
278
|
+
)((uploadedParts: ReadonlyArray<R2UploadedPart>) =>
|
|
299
279
|
tryR2Promise(definition.binding, "completeMultipartUpload", () =>
|
|
300
280
|
upload.complete([...uploadedParts]),
|
|
301
281
|
),
|
|
@@ -332,7 +312,7 @@ export const makeClient = (
|
|
|
332
312
|
tryR2Promise(definition.binding, "put", () => bucket.put(key, value, options)).pipe(
|
|
333
313
|
Effect.map((object) => {
|
|
334
314
|
if (object === null) {
|
|
335
|
-
return Option.none<
|
|
315
|
+
return Option.none<R2Object>();
|
|
336
316
|
}
|
|
337
317
|
|
|
338
318
|
if (options !== undefined && "onlyIf" in options) {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type * as Context from "effect/Context";
|
|
2
|
+
import * as Layer from "effect/Layer";
|
|
3
|
+
import type * as Rpc from "effect/unstable/rpc/Rpc";
|
|
4
|
+
import * as RpcClient from "effect/unstable/rpc/RpcClient";
|
|
5
|
+
import type { RpcClientError } from "effect/unstable/rpc/RpcClientError";
|
|
6
|
+
import type * as RpcGroup from "effect/unstable/rpc/RpcGroup";
|
|
7
|
+
import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization";
|
|
8
|
+
import * as Socket from "effect/unstable/socket/Socket";
|
|
9
|
+
|
|
10
|
+
export interface LayerOptions {
|
|
11
|
+
readonly socket?: Parameters<typeof Socket.layerWebSocket>[1];
|
|
12
|
+
readonly protocol?: Parameters<typeof RpcClient.layerProtocolSocket>[0];
|
|
13
|
+
readonly client?: Omit<NonNullable<Parameters<typeof RpcClient.make>[1]>, "flatten">;
|
|
14
|
+
/** Must match the server's serialization. Defaults to Effect RPC JSON. */
|
|
15
|
+
readonly serialization?: RpcSerialization.RpcSerialization["Service"] | undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Provides a typed RPC client and its WebSocket transport for the layer's lifetime.
|
|
20
|
+
* Callers yield the service without supplying a Scope. Provide this layer once
|
|
21
|
+
* around the application or session to share the connection across calls.
|
|
22
|
+
*
|
|
23
|
+
* Provide Socket.layerWebSocketConstructorGlobal in browsers, or a platform's
|
|
24
|
+
* WebSocketConstructor layer elsewhere. Streaming RPCs returned as queues still
|
|
25
|
+
* require a consumer scope; ordinary Stream operations manage their own scopes.
|
|
26
|
+
*/
|
|
27
|
+
export const layer = <I, Rpcs extends Rpc.Any>(
|
|
28
|
+
service: Context.Key<I, RpcClient.RpcClient<Rpcs, RpcClientError>>,
|
|
29
|
+
group: RpcGroup.RpcGroup<Rpcs>,
|
|
30
|
+
url: Parameters<typeof Socket.layerWebSocket>[0],
|
|
31
|
+
options: LayerOptions = {},
|
|
32
|
+
): Layer.Layer<I, never, Socket.WebSocketConstructor | Rpc.MiddlewareClient<Rpcs>> =>
|
|
33
|
+
Layer.effect(service, RpcClient.make(group, options.client)).pipe(
|
|
34
|
+
Layer.provide(
|
|
35
|
+
RpcClient.layerProtocolSocket(options.protocol).pipe(
|
|
36
|
+
Layer.provide(Socket.layerWebSocket(url, options.socket)),
|
|
37
|
+
Layer.provide(
|
|
38
|
+
Layer.succeed(
|
|
39
|
+
RpcSerialization.RpcSerialization,
|
|
40
|
+
options.serialization ?? RpcSerialization.json,
|
|
41
|
+
),
|
|
42
|
+
),
|
|
43
|
+
),
|
|
44
|
+
),
|
|
45
|
+
);
|
package/src/Vectorize.ts
CHANGED
|
@@ -5,22 +5,6 @@ import * as Option from "effect/Option";
|
|
|
5
5
|
import * as Predicate from "effect/Predicate";
|
|
6
6
|
import * as Schema from "effect/Schema";
|
|
7
7
|
import type { Layer } from "effect";
|
|
8
|
-
import type {
|
|
9
|
-
Vectorize as CloudflareVectorize,
|
|
10
|
-
VectorizeAsyncMutation as CloudflareVectorizeAsyncMutation,
|
|
11
|
-
VectorizeIndex as CloudflareVectorizeIndex,
|
|
12
|
-
VectorizeIndexDetails as CloudflareVectorizeIndexDetails,
|
|
13
|
-
VectorizeIndexInfo as CloudflareVectorizeIndexInfo,
|
|
14
|
-
VectorizeMatch as CloudflareVectorizeMatch,
|
|
15
|
-
VectorizeMatches as CloudflareVectorizeMatches,
|
|
16
|
-
VectorizeQueryOptions as CloudflareVectorizeQueryOptions,
|
|
17
|
-
VectorizeVector as CloudflareVectorizeVector,
|
|
18
|
-
VectorizeVectorMetadata as CloudflareVectorizeVectorMetadata,
|
|
19
|
-
VectorizeVectorMetadataFilter as CloudflareVectorizeVectorMetadataFilter,
|
|
20
|
-
VectorizeVectorMetadataValue as CloudflareVectorizeVectorMetadataValue,
|
|
21
|
-
VectorizeVectorMutation as CloudflareVectorizeVectorMutation,
|
|
22
|
-
} from "@cloudflare/workers-types";
|
|
23
|
-
|
|
24
8
|
import * as Binding from "./Binding";
|
|
25
9
|
import type { WorkerEnvironment } from "./Environment";
|
|
26
10
|
import * as ErrorMessage from "./internal/ErrorMessage";
|
|
@@ -53,19 +37,17 @@ export interface VectorizeDefinition {
|
|
|
53
37
|
readonly binding: string;
|
|
54
38
|
}
|
|
55
39
|
|
|
56
|
-
export type VectorizeBinding =
|
|
57
|
-
export type
|
|
58
|
-
export type
|
|
59
|
-
export type
|
|
60
|
-
export type
|
|
61
|
-
export type VectorizeQueryOptions =
|
|
62
|
-
export type
|
|
63
|
-
export type
|
|
64
|
-
export type
|
|
65
|
-
export type
|
|
66
|
-
export type VectorizeMutation =
|
|
67
|
-
| CloudflareVectorizeAsyncMutation
|
|
68
|
-
| CloudflareVectorizeVectorMutation;
|
|
40
|
+
export type VectorizeBinding = Vectorize | VectorizeIndex;
|
|
41
|
+
export type VectorizeIndexDetails = globalThis.VectorizeIndexDetails;
|
|
42
|
+
export type VectorizeIndexInfo = globalThis.VectorizeIndexInfo;
|
|
43
|
+
export type VectorizeMatch = globalThis.VectorizeMatch;
|
|
44
|
+
export type VectorizeMatches = globalThis.VectorizeMatches;
|
|
45
|
+
export type VectorizeQueryOptions = globalThis.VectorizeQueryOptions;
|
|
46
|
+
export type VectorizeVector = globalThis.VectorizeVector;
|
|
47
|
+
export type VectorizeVectorMetadata = globalThis.VectorizeVectorMetadata;
|
|
48
|
+
export type VectorizeVectorMetadataFilter = globalThis.VectorizeVectorMetadataFilter;
|
|
49
|
+
export type VectorizeVectorMetadataValue = globalThis.VectorizeVectorMetadataValue;
|
|
50
|
+
export type VectorizeMutation = VectorizeAsyncMutation | VectorizeVectorMutation;
|
|
69
51
|
export type VectorizeValues = Float32Array | Float64Array | ReadonlyArray<number>;
|
|
70
52
|
|
|
71
53
|
interface VectorizeRuntimeBinding {
|
package/src/WebTransport.ts
CHANGED
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
* {@link inboundTransport} decodes the HTTP/3-relevant request metadata that
|
|
30
30
|
* the edge does provide.
|
|
31
31
|
*/
|
|
32
|
-
import type { Request as CloudflareRequest } from "@cloudflare/workers-types";
|
|
33
32
|
import * as Data from "effect/Data";
|
|
34
33
|
import * as Effect from "effect/Effect";
|
|
35
34
|
import * as Option from "effect/Option";
|
|
@@ -61,9 +60,8 @@ const decodeInboundTransport = S.decodeUnknownResult(InboundTransport);
|
|
|
61
60
|
* dev` or when a Worker invokes another Worker directly) or does not match
|
|
62
61
|
* the expected shape.
|
|
63
62
|
*/
|
|
64
|
-
export const inboundTransport = (
|
|
65
|
-
request
|
|
66
|
-
): Option.Option<InboundTransport> => Result.getSuccess(decodeInboundTransport(request.cf));
|
|
63
|
+
export const inboundTransport = (request: Pick<Request, "cf">): Option.Option<InboundTransport> =>
|
|
64
|
+
Result.getSuccess(decodeInboundTransport(request.cf));
|
|
67
65
|
|
|
68
66
|
export const isHttp3 = (transport: InboundTransport): boolean =>
|
|
69
67
|
transport.clientQuicRtt !== undefined || transport.httpProtocol === "HTTP/3";
|
package/src/WorkersAi.ts
CHANGED
|
@@ -5,18 +5,6 @@ import * as Option from "effect/Option";
|
|
|
5
5
|
import * as Predicate from "effect/Predicate";
|
|
6
6
|
import * as S from "effect/Schema";
|
|
7
7
|
import type { Layer } from "effect";
|
|
8
|
-
import type {
|
|
9
|
-
Ai as CloudflareAi,
|
|
10
|
-
AiAsyncBatchResponse,
|
|
11
|
-
AiGateway as CloudflareAiGateway,
|
|
12
|
-
AiModelListType,
|
|
13
|
-
AiModels,
|
|
14
|
-
AiModelsSearchObject,
|
|
15
|
-
AiModelsSearchParams,
|
|
16
|
-
AiOptions,
|
|
17
|
-
AiTextEmbeddingsInput,
|
|
18
|
-
Ai_Cf_Qwen_Qwen3_Embedding_0_6B_Input,
|
|
19
|
-
} from "@cloudflare/workers-types";
|
|
20
8
|
|
|
21
9
|
import * as Binding from "./Binding";
|
|
22
10
|
import type { WorkerEnvironment } from "./Environment";
|
|
@@ -40,8 +28,7 @@ export interface WorkersAiDefinition {
|
|
|
40
28
|
readonly binding: string;
|
|
41
29
|
}
|
|
42
30
|
|
|
43
|
-
export type WorkersAiBinding<ModelList extends AiModelListType = AiModels> =
|
|
44
|
-
CloudflareAi<ModelList>;
|
|
31
|
+
export type WorkersAiBinding<ModelList extends AiModelListType = AiModels> = Ai<ModelList>;
|
|
45
32
|
export type WorkersAiOptions = AiOptions;
|
|
46
33
|
export type WorkersAiModelsSearchParams = AiModelsSearchParams;
|
|
47
34
|
export type WorkersAiModelsSearchObject = AiModelsSearchObject;
|
|
@@ -113,9 +100,7 @@ export interface WorkersAiClient<ModelList extends AiModelListType = AiModels> {
|
|
|
113
100
|
readonly models: (
|
|
114
101
|
params?: WorkersAiModelsSearchParams,
|
|
115
102
|
) => Effect.Effect<ReadonlyArray<WorkersAiModelsSearchObject>, WorkersAiOperationError>;
|
|
116
|
-
readonly gateway: (
|
|
117
|
-
gatewayId: string,
|
|
118
|
-
) => Effect.Effect<CloudflareAiGateway, WorkersAiOperationError>;
|
|
103
|
+
readonly gateway: (gatewayId: string) => Effect.Effect<AiGateway, WorkersAiOperationError>;
|
|
119
104
|
readonly rawUnsafe: Effect.Effect<WorkersAiBinding<ModelList>>;
|
|
120
105
|
readonly definition: WorkersAiDefinition;
|
|
121
106
|
}
|
package/src/WorkflowBinding.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
InstanceStatus as CloudflareInstanceStatus,
|
|
3
|
-
Workflow as CloudflareWorkflow,
|
|
4
|
-
WorkflowInstance as CloudflareWorkflowInstance,
|
|
5
|
-
WorkflowInstanceCreateOptions as CloudflareWorkflowInstanceCreateOptions,
|
|
6
|
-
WorkflowInstanceLocationHint as CloudflareWorkflowInstanceLocationHint,
|
|
7
|
-
WorkflowInstanceRestartOptions as CloudflareWorkflowInstanceRestartOptions,
|
|
8
|
-
WorkflowInstanceTerminateOptions as CloudflareWorkflowInstanceTerminateOptions,
|
|
9
|
-
} from "@cloudflare/workers-types";
|
|
10
1
|
import * as Data from "effect/Data";
|
|
11
2
|
import * as Effect from "effect/Effect";
|
|
12
3
|
import * as Option from "effect/Option";
|
|
@@ -21,7 +12,7 @@ import * as ErrorMessage from "./internal/ErrorMessage";
|
|
|
21
12
|
const expectedWorkflow = "Workflow binding with create(), createBatch(), and get()";
|
|
22
13
|
|
|
23
14
|
export type WorkflowInstanceCreateOptions<Payload> = Omit<
|
|
24
|
-
|
|
15
|
+
globalThis.WorkflowInstanceCreateOptions<Payload>,
|
|
25
16
|
"params"
|
|
26
17
|
>;
|
|
27
18
|
|
|
@@ -29,11 +20,11 @@ export type WorkflowInstanceCreateBatchOptions<Payload, EncodedPayload = unknown
|
|
|
29
20
|
{ readonly payload: Payload } & WorkflowInstanceCreateOptions<EncodedPayload>
|
|
30
21
|
>;
|
|
31
22
|
|
|
32
|
-
export type
|
|
33
|
-
export type
|
|
34
|
-
export type
|
|
23
|
+
export type WorkflowInstanceLocationHint = globalThis.WorkflowInstanceLocationHint;
|
|
24
|
+
export type WorkflowInstanceRestartOptions = globalThis.WorkflowInstanceRestartOptions;
|
|
25
|
+
export type WorkflowInstanceTerminateOptions = globalThis.WorkflowInstanceTerminateOptions;
|
|
35
26
|
|
|
36
|
-
export type WorkflowInstanceStatusName =
|
|
27
|
+
export type WorkflowInstanceStatusName = InstanceStatus["status"];
|
|
37
28
|
|
|
38
29
|
export interface WorkflowInstanceStatus<Result> {
|
|
39
30
|
readonly status: WorkflowInstanceStatusName;
|
|
@@ -45,7 +36,7 @@ export interface WorkflowInstanceStatus<Result> {
|
|
|
45
36
|
}
|
|
46
37
|
|
|
47
38
|
export interface WorkflowInstance<Result> {
|
|
48
|
-
readonly raw:
|
|
39
|
+
readonly raw: globalThis.WorkflowInstance;
|
|
49
40
|
readonly id: string;
|
|
50
41
|
readonly pause: Effect.Effect<void, WorkflowOperationError>;
|
|
51
42
|
readonly resume: Effect.Effect<void, WorkflowOperationError>;
|
|
@@ -97,7 +88,7 @@ export interface WorkflowBindingClient<
|
|
|
97
88
|
readonly get: (
|
|
98
89
|
instanceId: string,
|
|
99
90
|
) => Effect.Effect<WorkflowInstance<S.Schema.Type<Result>>, WorkflowOperationError>;
|
|
100
|
-
readonly rawUnsafe: Effect.Effect<
|
|
91
|
+
readonly rawUnsafe: Effect.Effect<Workflow<S.Codec.Encoded<Payload>>>;
|
|
101
92
|
}
|
|
102
93
|
|
|
103
94
|
export class WorkflowOperationError extends Data.TaggedError("WorkflowOperationError")<{
|
|
@@ -136,7 +127,7 @@ const tryWorkflowPromise = <A>(
|
|
|
136
127
|
type WorkflowBindingValue = S.Schema.Type<typeof S.Unknown>;
|
|
137
128
|
|
|
138
129
|
const WorkflowBindingSchema = S.declare(
|
|
139
|
-
(value: WorkflowBindingValue): value is
|
|
130
|
+
(value: WorkflowBindingValue): value is Workflow<WorkflowBindingValue> =>
|
|
140
131
|
Predicate.hasProperty(value, "create") &&
|
|
141
132
|
Predicate.isFunction(value.create) &&
|
|
142
133
|
Predicate.hasProperty(value, "createBatch") &&
|
|
@@ -146,18 +137,15 @@ const WorkflowBindingSchema = S.declare(
|
|
|
146
137
|
);
|
|
147
138
|
const decodeWorkflowBinding = S.decodeUnknownOption(WorkflowBindingSchema);
|
|
148
139
|
|
|
149
|
-
export const isWorkflow = <Payload>(
|
|
150
|
-
value
|
|
151
|
-
): value is CloudflareWorkflow<Payload> => Option.isSome(decodeWorkflowBinding(value));
|
|
140
|
+
export const isWorkflow = <Payload>(value: WorkflowBindingValue): value is Workflow<Payload> =>
|
|
141
|
+
Option.isSome(decodeWorkflowBinding(value));
|
|
152
142
|
|
|
153
143
|
export const makeClient = <
|
|
154
144
|
Payload extends RpcDefinition.ServiceFreeSchema,
|
|
155
145
|
Result extends RpcDefinition.ServiceFreeSchema,
|
|
156
146
|
>(
|
|
157
147
|
definition: WorkflowBindingDefinition<Payload, Result>,
|
|
158
|
-
): ((
|
|
159
|
-
workflow: CloudflareWorkflow<S.Codec.Encoded<Payload>>,
|
|
160
|
-
) => WorkflowBindingClient<Payload, Result>) => {
|
|
148
|
+
): ((workflow: Workflow<S.Codec.Encoded<Payload>>) => WorkflowBindingClient<Payload, Result>) => {
|
|
161
149
|
type PayloadValue = S.Schema.Type<Payload>;
|
|
162
150
|
type EncodedPayload = S.Codec.Encoded<Payload>;
|
|
163
151
|
type ResultValue = S.Schema.Type<Result>;
|
|
@@ -165,7 +153,7 @@ export const makeClient = <
|
|
|
165
153
|
const encodePayload = S.encodeEffect(definition.payload);
|
|
166
154
|
const decodeResult = S.decodeUnknownEffect(definition.result);
|
|
167
155
|
|
|
168
|
-
const wrapInstance = (raw:
|
|
156
|
+
const wrapInstance = (raw: globalThis.WorkflowInstance): WorkflowInstance<ResultValue> => {
|
|
169
157
|
const operation = <A>(name: string, evaluate: () => Promise<A>) =>
|
|
170
158
|
tryWorkflowPromise(definition.binding, name, evaluate);
|
|
171
159
|
|
|
@@ -229,7 +217,7 @@ export const makeClient = <
|
|
|
229
217
|
createBatch: Effect.fn("WorkflowBinding.createBatch", {
|
|
230
218
|
attributes: { binding: definition.binding, operation: "createBatch" },
|
|
231
219
|
})(function* (batch: WorkflowInstanceCreateBatchOptions<PayloadValue, EncodedPayload>) {
|
|
232
|
-
const encodedBatch: Array<
|
|
220
|
+
const encodedBatch: Array<globalThis.WorkflowInstanceCreateOptions<EncodedPayload>> = [];
|
|
233
221
|
|
|
234
222
|
for (const item of batch) {
|
|
235
223
|
const { payload, ...options } = item;
|
|
@@ -265,7 +253,7 @@ export const layer = <
|
|
|
265
253
|
Binding.layer(
|
|
266
254
|
tag,
|
|
267
255
|
definition.binding,
|
|
268
|
-
(value): value is
|
|
256
|
+
(value): value is Workflow<S.Codec.Encoded<Payload>> =>
|
|
269
257
|
isWorkflow<S.Codec.Encoded<Payload>>(value),
|
|
270
258
|
makeClient(definition),
|
|
271
259
|
{ expected: expectedWorkflow },
|
package/src/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ export * as Rpc from "./Rpc";
|
|
|
30
30
|
export * as RpcDefinition from "./RpcDefinition";
|
|
31
31
|
export * as RpcTracing from "./RpcTracing";
|
|
32
32
|
export * as RpcTargets from "./RpcTargets";
|
|
33
|
+
export * as RpcWebSocketClient from "./RpcWebSocketClient";
|
|
33
34
|
export * as ServiceBinding from "./ServiceBinding";
|
|
34
35
|
export * as Vectorize from "./Vectorize";
|
|
35
36
|
export * as WebTransport from "./WebTransport";
|