@johannc-dev/zyrk 0.0.0-stage → 0.2.1
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 +79 -2
- package/dist/build.d.ts +48 -0
- package/dist/build.js +338 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +295 -0
- package/dist/client.d.ts +212 -0
- package/dist/client.js +909 -0
- package/dist/contracts.d.ts +312 -0
- package/dist/contracts.js +154 -0
- package/dist/errors.d.ts +99 -0
- package/dist/errors.js +63 -0
- package/dist/export.d.ts +96 -0
- package/dist/export.js +422 -0
- package/dist/globals.d.ts +59 -0
- package/dist/hourfile.d.ts +59 -0
- package/dist/hourfile.js +345 -0
- package/dist/limits.d.ts +91 -0
- package/dist/limits.js +54 -0
- package/dist/local-data.d.ts +115 -0
- package/dist/local-data.js +373 -0
- package/dist/local-replay.d.ts +40 -0
- package/dist/local-replay.js +343 -0
- package/dist/local-storage.d.ts +76 -0
- package/dist/local-storage.js +499 -0
- package/dist/local.d.ts +235 -0
- package/dist/local.js +1147 -0
- package/dist/sandbox-bootstrap.js +681 -0
- package/dist/sdk.d.ts +1152 -0
- package/dist/sdk.js +210 -0
- package/dist/stream.d.ts +84 -0
- package/dist/stream.js +167 -0
- package/dist/webhook.d.ts +43 -0
- package/dist/webhook.js +54 -0
- package/package.json +56 -4
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schemas of what the service sends and accepts over HTTP and the event
|
|
3
|
+
* stream. The guest types live in `@johannc-dev/zyrk` (no Effect there).
|
|
4
|
+
*/
|
|
5
|
+
import { Effect, Result, Schema, type SchemaAST } from "effect";
|
|
6
|
+
import { DecodeError, Failure } from "./errors.js";
|
|
7
|
+
export { Failure } from "./errors.js";
|
|
8
|
+
export { MAX_BUNDLE_BYTES } from "./limits.js";
|
|
9
|
+
export declare const Json: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
10
|
+
export type Json = typeof Json.Type;
|
|
11
|
+
export declare const Name: Schema.String;
|
|
12
|
+
export declare const Address: Schema.String;
|
|
13
|
+
export declare const Trigger: Schema.Union<readonly [Schema.Struct<{
|
|
14
|
+
readonly kind: Schema.Literal<"trade">;
|
|
15
|
+
readonly mint: Schema.optionalKey<Schema.String>;
|
|
16
|
+
readonly wallet: Schema.optionalKey<Schema.String>;
|
|
17
|
+
}>, Schema.Struct<{
|
|
18
|
+
readonly kind: Schema.Literal<"volume">;
|
|
19
|
+
readonly thresholdRaw: Schema.String;
|
|
20
|
+
readonly mint: Schema.optionalKey<Schema.String>;
|
|
21
|
+
readonly quote: Schema.optionalKey<Schema.String>;
|
|
22
|
+
readonly windowMs: Schema.optionalKey<Schema.Number>;
|
|
23
|
+
}>, Schema.Struct<{
|
|
24
|
+
readonly kind: Schema.Literal<"priceVariation">;
|
|
25
|
+
readonly mint: Schema.optionalKey<Schema.String>;
|
|
26
|
+
readonly mode: Schema.Literals<readonly ["rise", "fall", "both"]>;
|
|
27
|
+
readonly factor: Schema.Number;
|
|
28
|
+
readonly durationMs: Schema.Number;
|
|
29
|
+
}>, Schema.Struct<{
|
|
30
|
+
readonly kind: Schema.Literal<"interval">;
|
|
31
|
+
readonly everyMs: Schema.Number;
|
|
32
|
+
}>, Schema.Struct<{
|
|
33
|
+
readonly kind: Schema.Literal<"poolEvent">;
|
|
34
|
+
readonly mint: Schema.optionalKey<Schema.String>;
|
|
35
|
+
readonly events: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
36
|
+
}>]>;
|
|
37
|
+
export type Trigger = typeof Trigger.Type;
|
|
38
|
+
export declare const Subscription: Schema.Struct<{
|
|
39
|
+
readonly function: Schema.String;
|
|
40
|
+
readonly trigger: Schema.Union<readonly [Schema.Struct<{
|
|
41
|
+
readonly kind: Schema.Literal<"trade">;
|
|
42
|
+
readonly mint: Schema.optionalKey<Schema.String>;
|
|
43
|
+
readonly wallet: Schema.optionalKey<Schema.String>;
|
|
44
|
+
}>, Schema.Struct<{
|
|
45
|
+
readonly kind: Schema.Literal<"volume">;
|
|
46
|
+
readonly thresholdRaw: Schema.String;
|
|
47
|
+
readonly mint: Schema.optionalKey<Schema.String>;
|
|
48
|
+
readonly quote: Schema.optionalKey<Schema.String>;
|
|
49
|
+
readonly windowMs: Schema.optionalKey<Schema.Number>;
|
|
50
|
+
}>, Schema.Struct<{
|
|
51
|
+
readonly kind: Schema.Literal<"priceVariation">;
|
|
52
|
+
readonly mint: Schema.optionalKey<Schema.String>;
|
|
53
|
+
readonly mode: Schema.Literals<readonly ["rise", "fall", "both"]>;
|
|
54
|
+
readonly factor: Schema.Number;
|
|
55
|
+
readonly durationMs: Schema.Number;
|
|
56
|
+
}>, Schema.Struct<{
|
|
57
|
+
readonly kind: Schema.Literal<"interval">;
|
|
58
|
+
readonly everyMs: Schema.Number;
|
|
59
|
+
}>, Schema.Struct<{
|
|
60
|
+
readonly kind: Schema.Literal<"poolEvent">;
|
|
61
|
+
readonly mint: Schema.optionalKey<Schema.String>;
|
|
62
|
+
readonly events: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
63
|
+
}>]>;
|
|
64
|
+
readonly recovery: Schema.Literals<readonly ["latest", "replay"]>;
|
|
65
|
+
readonly maxReplayEvents: Schema.withDecodingDefaultKey<Schema.Number, never>;
|
|
66
|
+
}>;
|
|
67
|
+
export type Subscription = typeof Subscription.Type;
|
|
68
|
+
/**
|
|
69
|
+
* Measured usage of an execution. Every field is optional so that a field
|
|
70
|
+
* added or renamed by the service does not break older clients.
|
|
71
|
+
*/
|
|
72
|
+
export declare const Usage: Schema.Struct<{
|
|
73
|
+
readonly cpuMs: Schema.optionalKey<Schema.Number>;
|
|
74
|
+
readonly wallMs: Schema.optionalKey<Schema.Number>;
|
|
75
|
+
readonly readBytes: Schema.optionalKey<Schema.Number>;
|
|
76
|
+
readonly readCalls: Schema.optionalKey<Schema.Number>;
|
|
77
|
+
/** CPU time spent serving history reads (not in `cpuMs`). */
|
|
78
|
+
readonly readMs: Schema.optionalKey<Schema.Number>;
|
|
79
|
+
readonly hostOps: Schema.optionalKey<Schema.Number>;
|
|
80
|
+
readonly outputBytes: Schema.optionalKey<Schema.Number>;
|
|
81
|
+
readonly peakHeapBytes: Schema.optionalKey<Schema.Number>;
|
|
82
|
+
/** User storage (`ctx.storage`), counted by the service. */
|
|
83
|
+
readonly storageReadBytes: Schema.optionalKey<Schema.Number>;
|
|
84
|
+
readonly storageWriteBytes: Schema.optionalKey<Schema.Number>;
|
|
85
|
+
readonly storageCalls: Schema.optionalKey<Schema.Number>;
|
|
86
|
+
readonly storageMs: Schema.optionalKey<Schema.Number>;
|
|
87
|
+
}>;
|
|
88
|
+
export type Usage = typeof Usage.Type;
|
|
89
|
+
/** Every status an execution record can have. */
|
|
90
|
+
export declare const JobStatus: Schema.Literals<readonly ["queued", "running", "succeeded", "failed", "cancelled", "expired", "acknowledged", "continued"]>;
|
|
91
|
+
export type JobStatus = typeof JobStatus.Type;
|
|
92
|
+
/** `GET /v1/functions/executions/{id}`. */
|
|
93
|
+
export declare const Job: Schema.Union<readonly [Schema.Struct<{
|
|
94
|
+
readonly status: Schema.Literals<readonly ["continued"]>;
|
|
95
|
+
readonly nextExecutionId: Schema.String;
|
|
96
|
+
readonly id: Schema.String;
|
|
97
|
+
readonly program: Schema.String;
|
|
98
|
+
readonly version: Schema.String;
|
|
99
|
+
readonly workflow: Schema.String;
|
|
100
|
+
readonly function: Schema.String;
|
|
101
|
+
readonly createdAt: Schema.Number;
|
|
102
|
+
readonly attempt: Schema.Number;
|
|
103
|
+
readonly depth: Schema.optionalKey<Schema.Number>;
|
|
104
|
+
readonly onComplete: Schema.optionalKey<Schema.String>;
|
|
105
|
+
readonly parent: Schema.optionalKey<Schema.String>;
|
|
106
|
+
readonly subscription: Schema.optionalKey<Schema.String>;
|
|
107
|
+
readonly usage: Schema.optionalKey<Schema.Struct<{
|
|
108
|
+
readonly cpuMs: Schema.optionalKey<Schema.Number>;
|
|
109
|
+
readonly wallMs: Schema.optionalKey<Schema.Number>;
|
|
110
|
+
readonly readBytes: Schema.optionalKey<Schema.Number>;
|
|
111
|
+
readonly readCalls: Schema.optionalKey<Schema.Number>;
|
|
112
|
+
/** CPU time spent serving history reads (not in `cpuMs`). */
|
|
113
|
+
readonly readMs: Schema.optionalKey<Schema.Number>;
|
|
114
|
+
readonly hostOps: Schema.optionalKey<Schema.Number>;
|
|
115
|
+
readonly outputBytes: Schema.optionalKey<Schema.Number>;
|
|
116
|
+
readonly peakHeapBytes: Schema.optionalKey<Schema.Number>;
|
|
117
|
+
/** User storage (`ctx.storage`), counted by the service. */
|
|
118
|
+
readonly storageReadBytes: Schema.optionalKey<Schema.Number>;
|
|
119
|
+
readonly storageWriteBytes: Schema.optionalKey<Schema.Number>;
|
|
120
|
+
readonly storageCalls: Schema.optionalKey<Schema.Number>;
|
|
121
|
+
readonly storageMs: Schema.optionalKey<Schema.Number>;
|
|
122
|
+
}>>;
|
|
123
|
+
readonly logs: Schema.optionalKey<Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
124
|
+
}>, Schema.Struct<{
|
|
125
|
+
readonly status: Schema.Literals<readonly ["queued", "running"]>;
|
|
126
|
+
readonly id: Schema.String;
|
|
127
|
+
readonly program: Schema.String;
|
|
128
|
+
readonly version: Schema.String;
|
|
129
|
+
readonly workflow: Schema.String;
|
|
130
|
+
readonly function: Schema.String;
|
|
131
|
+
readonly createdAt: Schema.Number;
|
|
132
|
+
readonly attempt: Schema.Number;
|
|
133
|
+
readonly depth: Schema.optionalKey<Schema.Number>;
|
|
134
|
+
readonly onComplete: Schema.optionalKey<Schema.String>;
|
|
135
|
+
readonly parent: Schema.optionalKey<Schema.String>;
|
|
136
|
+
readonly subscription: Schema.optionalKey<Schema.String>;
|
|
137
|
+
readonly usage: Schema.optionalKey<Schema.Struct<{
|
|
138
|
+
readonly cpuMs: Schema.optionalKey<Schema.Number>;
|
|
139
|
+
readonly wallMs: Schema.optionalKey<Schema.Number>;
|
|
140
|
+
readonly readBytes: Schema.optionalKey<Schema.Number>;
|
|
141
|
+
readonly readCalls: Schema.optionalKey<Schema.Number>;
|
|
142
|
+
/** CPU time spent serving history reads (not in `cpuMs`). */
|
|
143
|
+
readonly readMs: Schema.optionalKey<Schema.Number>;
|
|
144
|
+
readonly hostOps: Schema.optionalKey<Schema.Number>;
|
|
145
|
+
readonly outputBytes: Schema.optionalKey<Schema.Number>;
|
|
146
|
+
readonly peakHeapBytes: Schema.optionalKey<Schema.Number>;
|
|
147
|
+
/** User storage (`ctx.storage`), counted by the service. */
|
|
148
|
+
readonly storageReadBytes: Schema.optionalKey<Schema.Number>;
|
|
149
|
+
readonly storageWriteBytes: Schema.optionalKey<Schema.Number>;
|
|
150
|
+
readonly storageCalls: Schema.optionalKey<Schema.Number>;
|
|
151
|
+
readonly storageMs: Schema.optionalKey<Schema.Number>;
|
|
152
|
+
}>>;
|
|
153
|
+
readonly logs: Schema.optionalKey<Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
154
|
+
}>, Schema.Struct<{
|
|
155
|
+
readonly status: Schema.Literals<readonly ["succeeded"]>;
|
|
156
|
+
readonly result: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
157
|
+
readonly id: Schema.String;
|
|
158
|
+
readonly program: Schema.String;
|
|
159
|
+
readonly version: Schema.String;
|
|
160
|
+
readonly workflow: Schema.String;
|
|
161
|
+
readonly function: Schema.String;
|
|
162
|
+
readonly createdAt: Schema.Number;
|
|
163
|
+
readonly attempt: Schema.Number;
|
|
164
|
+
readonly depth: Schema.optionalKey<Schema.Number>;
|
|
165
|
+
readonly onComplete: Schema.optionalKey<Schema.String>;
|
|
166
|
+
readonly parent: Schema.optionalKey<Schema.String>;
|
|
167
|
+
readonly subscription: Schema.optionalKey<Schema.String>;
|
|
168
|
+
readonly usage: Schema.optionalKey<Schema.Struct<{
|
|
169
|
+
readonly cpuMs: Schema.optionalKey<Schema.Number>;
|
|
170
|
+
readonly wallMs: Schema.optionalKey<Schema.Number>;
|
|
171
|
+
readonly readBytes: Schema.optionalKey<Schema.Number>;
|
|
172
|
+
readonly readCalls: Schema.optionalKey<Schema.Number>;
|
|
173
|
+
/** CPU time spent serving history reads (not in `cpuMs`). */
|
|
174
|
+
readonly readMs: Schema.optionalKey<Schema.Number>;
|
|
175
|
+
readonly hostOps: Schema.optionalKey<Schema.Number>;
|
|
176
|
+
readonly outputBytes: Schema.optionalKey<Schema.Number>;
|
|
177
|
+
readonly peakHeapBytes: Schema.optionalKey<Schema.Number>;
|
|
178
|
+
/** User storage (`ctx.storage`), counted by the service. */
|
|
179
|
+
readonly storageReadBytes: Schema.optionalKey<Schema.Number>;
|
|
180
|
+
readonly storageWriteBytes: Schema.optionalKey<Schema.Number>;
|
|
181
|
+
readonly storageCalls: Schema.optionalKey<Schema.Number>;
|
|
182
|
+
readonly storageMs: Schema.optionalKey<Schema.Number>;
|
|
183
|
+
}>>;
|
|
184
|
+
readonly logs: Schema.optionalKey<Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
185
|
+
}>, Schema.Struct<{
|
|
186
|
+
readonly status: Schema.Literals<readonly ["failed"]>;
|
|
187
|
+
readonly error: Schema.Struct<{
|
|
188
|
+
readonly kind: Schema.Literals<readonly ["program", "limit", "infrastructure", "permission"]>;
|
|
189
|
+
readonly code: Schema.String;
|
|
190
|
+
readonly message: Schema.String;
|
|
191
|
+
}>;
|
|
192
|
+
readonly id: Schema.String;
|
|
193
|
+
readonly program: Schema.String;
|
|
194
|
+
readonly version: Schema.String;
|
|
195
|
+
readonly workflow: Schema.String;
|
|
196
|
+
readonly function: Schema.String;
|
|
197
|
+
readonly createdAt: Schema.Number;
|
|
198
|
+
readonly attempt: Schema.Number;
|
|
199
|
+
readonly depth: Schema.optionalKey<Schema.Number>;
|
|
200
|
+
readonly onComplete: Schema.optionalKey<Schema.String>;
|
|
201
|
+
readonly parent: Schema.optionalKey<Schema.String>;
|
|
202
|
+
readonly subscription: Schema.optionalKey<Schema.String>;
|
|
203
|
+
readonly usage: Schema.optionalKey<Schema.Struct<{
|
|
204
|
+
readonly cpuMs: Schema.optionalKey<Schema.Number>;
|
|
205
|
+
readonly wallMs: Schema.optionalKey<Schema.Number>;
|
|
206
|
+
readonly readBytes: Schema.optionalKey<Schema.Number>;
|
|
207
|
+
readonly readCalls: Schema.optionalKey<Schema.Number>;
|
|
208
|
+
/** CPU time spent serving history reads (not in `cpuMs`). */
|
|
209
|
+
readonly readMs: Schema.optionalKey<Schema.Number>;
|
|
210
|
+
readonly hostOps: Schema.optionalKey<Schema.Number>;
|
|
211
|
+
readonly outputBytes: Schema.optionalKey<Schema.Number>;
|
|
212
|
+
readonly peakHeapBytes: Schema.optionalKey<Schema.Number>;
|
|
213
|
+
/** User storage (`ctx.storage`), counted by the service. */
|
|
214
|
+
readonly storageReadBytes: Schema.optionalKey<Schema.Number>;
|
|
215
|
+
readonly storageWriteBytes: Schema.optionalKey<Schema.Number>;
|
|
216
|
+
readonly storageCalls: Schema.optionalKey<Schema.Number>;
|
|
217
|
+
readonly storageMs: Schema.optionalKey<Schema.Number>;
|
|
218
|
+
}>>;
|
|
219
|
+
readonly logs: Schema.optionalKey<Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
220
|
+
}>, Schema.Struct<{
|
|
221
|
+
readonly status: Schema.Literals<readonly ["cancelled", "expired", "acknowledged"]>;
|
|
222
|
+
readonly id: Schema.String;
|
|
223
|
+
readonly program: Schema.String;
|
|
224
|
+
readonly version: Schema.String;
|
|
225
|
+
readonly workflow: Schema.String;
|
|
226
|
+
readonly function: Schema.String;
|
|
227
|
+
readonly createdAt: Schema.Number;
|
|
228
|
+
readonly attempt: Schema.Number;
|
|
229
|
+
readonly depth: Schema.optionalKey<Schema.Number>;
|
|
230
|
+
readonly onComplete: Schema.optionalKey<Schema.String>;
|
|
231
|
+
readonly parent: Schema.optionalKey<Schema.String>;
|
|
232
|
+
readonly subscription: Schema.optionalKey<Schema.String>;
|
|
233
|
+
readonly usage: Schema.optionalKey<Schema.Struct<{
|
|
234
|
+
readonly cpuMs: Schema.optionalKey<Schema.Number>;
|
|
235
|
+
readonly wallMs: Schema.optionalKey<Schema.Number>;
|
|
236
|
+
readonly readBytes: Schema.optionalKey<Schema.Number>;
|
|
237
|
+
readonly readCalls: Schema.optionalKey<Schema.Number>;
|
|
238
|
+
/** CPU time spent serving history reads (not in `cpuMs`). */
|
|
239
|
+
readonly readMs: Schema.optionalKey<Schema.Number>;
|
|
240
|
+
readonly hostOps: Schema.optionalKey<Schema.Number>;
|
|
241
|
+
readonly outputBytes: Schema.optionalKey<Schema.Number>;
|
|
242
|
+
readonly peakHeapBytes: Schema.optionalKey<Schema.Number>;
|
|
243
|
+
/** User storage (`ctx.storage`), counted by the service. */
|
|
244
|
+
readonly storageReadBytes: Schema.optionalKey<Schema.Number>;
|
|
245
|
+
readonly storageWriteBytes: Schema.optionalKey<Schema.Number>;
|
|
246
|
+
readonly storageCalls: Schema.optionalKey<Schema.Number>;
|
|
247
|
+
readonly storageMs: Schema.optionalKey<Schema.Number>;
|
|
248
|
+
}>>;
|
|
249
|
+
readonly logs: Schema.optionalKey<Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
250
|
+
}>]>;
|
|
251
|
+
export type Job = typeof Job.Type;
|
|
252
|
+
/** Same shape as the guest's `JobResult` (`ctx.jobs.wait/result`). */
|
|
253
|
+
export type JobResult = {
|
|
254
|
+
readonly id: string;
|
|
255
|
+
readonly status: "queued" | "running";
|
|
256
|
+
} | {
|
|
257
|
+
readonly id: string;
|
|
258
|
+
readonly status: "succeeded";
|
|
259
|
+
readonly result: Json;
|
|
260
|
+
} | {
|
|
261
|
+
readonly id: string;
|
|
262
|
+
readonly status: "failed";
|
|
263
|
+
readonly error: Failure;
|
|
264
|
+
} | {
|
|
265
|
+
readonly id: string;
|
|
266
|
+
readonly status: "cancelled" | "expired" | "acknowledged";
|
|
267
|
+
};
|
|
268
|
+
/** `POST /v1/functions/programs/{name}/invoke` (202). */
|
|
269
|
+
export declare const Started: Schema.Struct<{
|
|
270
|
+
readonly id: Schema.String;
|
|
271
|
+
}>;
|
|
272
|
+
/** `GET /v1/functions/programs`. */
|
|
273
|
+
export declare const ProgramSummary: Schema.Struct<{
|
|
274
|
+
readonly name: Schema.String;
|
|
275
|
+
readonly version: Schema.String;
|
|
276
|
+
readonly stateVersion: Schema.Number;
|
|
277
|
+
readonly paused: Schema.Boolean;
|
|
278
|
+
}>;
|
|
279
|
+
export type ProgramSummary = typeof ProgramSummary.Type;
|
|
280
|
+
/** A schema that decodes without Effect services, so decoding is synchronous. */
|
|
281
|
+
export type Decodable = Schema.Top & {
|
|
282
|
+
readonly DecodingServices: never;
|
|
283
|
+
};
|
|
284
|
+
export declare const NonNegativeInt: Schema.Number;
|
|
285
|
+
/** Decodes `unknown` with `options`, mapping the schema error through `onError`. */
|
|
286
|
+
export declare const decodeWith: <S extends Decodable, E>(schema: S, options: SchemaAST.ParseOptions | undefined, onError: (message: string) => E) => (input: unknown) => Result.Result<S["Type"], E>;
|
|
287
|
+
/** A stream event kind: every job status transition, plus guest `ctx.emit`. */
|
|
288
|
+
export declare const ExecutionEventKind: Schema.Literals<readonly ["queued", "running", "succeeded", "failed", "cancelled", "expired", "acknowledged", "continued", "emitted"]>;
|
|
289
|
+
export type ExecutionEventKind = typeof ExecutionEventKind.Type;
|
|
290
|
+
export declare const ExecutionEvent: Schema.Struct<{
|
|
291
|
+
readonly seq: Schema.Number;
|
|
292
|
+
readonly executionId: Schema.String;
|
|
293
|
+
readonly workflow: Schema.String;
|
|
294
|
+
readonly program: Schema.String;
|
|
295
|
+
readonly function: Schema.String;
|
|
296
|
+
readonly version: Schema.String;
|
|
297
|
+
readonly attempt: Schema.Number;
|
|
298
|
+
readonly createdAt: Schema.Number;
|
|
299
|
+
readonly kind: Schema.Literals<readonly ["queued", "running", "succeeded", "failed", "cancelled", "expired", "acknowledged", "continued", "emitted"]>;
|
|
300
|
+
readonly data: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
301
|
+
}>;
|
|
302
|
+
export type ExecutionEvent = typeof ExecutionEvent.Type;
|
|
303
|
+
/** Events between `resumeAfter` and `headSeq` were dropped by the server. */
|
|
304
|
+
export declare const Gap: Schema.Struct<{
|
|
305
|
+
readonly resumeAfter: Schema.Number;
|
|
306
|
+
readonly headSeq: Schema.Number;
|
|
307
|
+
}>;
|
|
308
|
+
export type Gap = typeof Gap.Type;
|
|
309
|
+
/** Decodes service data; unknown keys are stripped. */
|
|
310
|
+
export declare const decode: <S extends Decodable>(schema: S, what: string) => (input: unknown) => Effect.Effect<S["Type"], DecodeError>;
|
|
311
|
+
/** The guest-facing view of an execution record (continuations not followed). */
|
|
312
|
+
export declare const toJobResult: (job: Job) => JobResult;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Effect, Result, Schema } from "effect";
|
|
2
|
+
import { DecodeError, Failure } from "./errors.js";
|
|
3
|
+
export { Failure } from "./errors.js";
|
|
4
|
+
export { MAX_BUNDLE_BYTES } from "./limits.js";
|
|
5
|
+
export const Json = Schema.Json;
|
|
6
|
+
export const Name = Schema.String.check(Schema.isPattern(/^[A-Za-z][A-Za-z0-9_-]{0,63}$/)).annotate({ identifier: "Name" });
|
|
7
|
+
export const Address = Schema.String.check(Schema.isPattern(/^[1-9A-HJ-NP-Za-km-z]{32,44}$/)).annotate({ identifier: "Address" });
|
|
8
|
+
const IntBetween = (min, max) => Schema.Number.check(Schema.isInt(), Schema.isBetween({ minimum: min, maximum: max }));
|
|
9
|
+
const PriceFactor = Schema.Number.check(Schema.isBetween({ minimum: 1.01, maximum: 11 }), Schema.makeFilter((n) => Math.abs(n * 10_000 - Math.round(n * 10_000)) < 1e-6, { description: "at most four decimals" }));
|
|
10
|
+
export const Trigger = Schema.Union([
|
|
11
|
+
Schema.Struct({
|
|
12
|
+
kind: Schema.Literal("trade"),
|
|
13
|
+
mint: Schema.optionalKey(Address),
|
|
14
|
+
wallet: Schema.optionalKey(Address),
|
|
15
|
+
}),
|
|
16
|
+
Schema.Struct({
|
|
17
|
+
kind: Schema.Literal("volume"),
|
|
18
|
+
thresholdRaw: Schema.String.check(Schema.isPattern(/^[1-9][0-9]{0,19}$/)),
|
|
19
|
+
mint: Schema.optionalKey(Address),
|
|
20
|
+
quote: Schema.optionalKey(Address),
|
|
21
|
+
windowMs: Schema.optionalKey(IntBetween(1000, 3600000)),
|
|
22
|
+
}),
|
|
23
|
+
Schema.Struct({
|
|
24
|
+
kind: Schema.Literal("priceVariation"),
|
|
25
|
+
mint: Schema.optionalKey(Address),
|
|
26
|
+
mode: Schema.Literals(["rise", "fall", "both"]),
|
|
27
|
+
factor: PriceFactor,
|
|
28
|
+
durationMs: IntBetween(15000, 3600000),
|
|
29
|
+
}),
|
|
30
|
+
Schema.Struct({
|
|
31
|
+
kind: Schema.Literal("interval"),
|
|
32
|
+
everyMs: IntBetween(1000, 86400000),
|
|
33
|
+
}),
|
|
34
|
+
Schema.Struct({
|
|
35
|
+
kind: Schema.Literal("poolEvent"),
|
|
36
|
+
mint: Schema.optionalKey(Address),
|
|
37
|
+
events: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
38
|
+
}),
|
|
39
|
+
]);
|
|
40
|
+
export const Subscription = Schema.Struct({
|
|
41
|
+
function: Name,
|
|
42
|
+
trigger: Trigger,
|
|
43
|
+
recovery: Schema.Literals(["latest", "replay"]),
|
|
44
|
+
maxReplayEvents: IntBetween(1, 10000).pipe(Schema.withDecodingDefaultKey(Effect.succeed(1000))),
|
|
45
|
+
});
|
|
46
|
+
export const Usage = Schema.Struct({
|
|
47
|
+
cpuMs: Schema.optionalKey(Schema.Number),
|
|
48
|
+
wallMs: Schema.optionalKey(Schema.Number),
|
|
49
|
+
readBytes: Schema.optionalKey(Schema.Number),
|
|
50
|
+
readCalls: Schema.optionalKey(Schema.Number),
|
|
51
|
+
readMs: Schema.optionalKey(Schema.Number),
|
|
52
|
+
hostOps: Schema.optionalKey(Schema.Number),
|
|
53
|
+
outputBytes: Schema.optionalKey(Schema.Number),
|
|
54
|
+
peakHeapBytes: Schema.optionalKey(Schema.Number),
|
|
55
|
+
storageReadBytes: Schema.optionalKey(Schema.Number),
|
|
56
|
+
storageWriteBytes: Schema.optionalKey(Schema.Number),
|
|
57
|
+
storageCalls: Schema.optionalKey(Schema.Number),
|
|
58
|
+
storageMs: Schema.optionalKey(Schema.Number),
|
|
59
|
+
});
|
|
60
|
+
export const JobStatus = Schema.Literals([
|
|
61
|
+
"queued",
|
|
62
|
+
"running",
|
|
63
|
+
"succeeded",
|
|
64
|
+
"failed",
|
|
65
|
+
"cancelled",
|
|
66
|
+
"expired",
|
|
67
|
+
"acknowledged",
|
|
68
|
+
"continued",
|
|
69
|
+
]);
|
|
70
|
+
const common = {
|
|
71
|
+
id: Schema.String,
|
|
72
|
+
program: Schema.String,
|
|
73
|
+
version: Schema.String,
|
|
74
|
+
workflow: Schema.String,
|
|
75
|
+
function: Schema.String,
|
|
76
|
+
createdAt: Schema.Number,
|
|
77
|
+
attempt: Schema.Number,
|
|
78
|
+
depth: Schema.optionalKey(Schema.Number),
|
|
79
|
+
onComplete: Schema.optionalKey(Schema.String),
|
|
80
|
+
parent: Schema.optionalKey(Schema.String),
|
|
81
|
+
subscription: Schema.optionalKey(Schema.String),
|
|
82
|
+
usage: Schema.optionalKey(Usage),
|
|
83
|
+
logs: Schema.optionalKey(Schema.Array(Json)),
|
|
84
|
+
};
|
|
85
|
+
export const Job = Schema.Union([
|
|
86
|
+
Schema.Struct({
|
|
87
|
+
...common,
|
|
88
|
+
status: JobStatus.pick(["continued"]),
|
|
89
|
+
nextExecutionId: Schema.String,
|
|
90
|
+
}),
|
|
91
|
+
Schema.Struct({ ...common, status: JobStatus.pick(["queued", "running"]) }),
|
|
92
|
+
Schema.Struct({
|
|
93
|
+
...common,
|
|
94
|
+
status: JobStatus.pick(["succeeded"]),
|
|
95
|
+
result: Json,
|
|
96
|
+
}),
|
|
97
|
+
Schema.Struct({
|
|
98
|
+
...common,
|
|
99
|
+
status: JobStatus.pick(["failed"]),
|
|
100
|
+
error: Failure,
|
|
101
|
+
}),
|
|
102
|
+
Schema.Struct({
|
|
103
|
+
...common,
|
|
104
|
+
status: JobStatus.pick(["cancelled", "expired", "acknowledged"]),
|
|
105
|
+
}),
|
|
106
|
+
]);
|
|
107
|
+
export const Started = Schema.Struct({ id: Schema.String });
|
|
108
|
+
export const ProgramSummary = Schema.Struct({
|
|
109
|
+
name: Schema.String,
|
|
110
|
+
version: Schema.String,
|
|
111
|
+
stateVersion: Schema.Number,
|
|
112
|
+
paused: Schema.Boolean,
|
|
113
|
+
});
|
|
114
|
+
export const NonNegativeInt = Schema.Number.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0));
|
|
115
|
+
export const decodeWith = (schema, options, onError) => {
|
|
116
|
+
const parse = Schema.decodeUnknownResult(schema);
|
|
117
|
+
return (input) => Result.mapError(parse(input, options), (error) => onError(error.message));
|
|
118
|
+
};
|
|
119
|
+
export const ExecutionEventKind = Schema.Literals([
|
|
120
|
+
...JobStatus.literals,
|
|
121
|
+
"emitted",
|
|
122
|
+
]);
|
|
123
|
+
export const ExecutionEvent = Schema.Struct({
|
|
124
|
+
seq: NonNegativeInt,
|
|
125
|
+
executionId: Schema.String,
|
|
126
|
+
workflow: Schema.String,
|
|
127
|
+
program: Schema.String,
|
|
128
|
+
function: Schema.String,
|
|
129
|
+
version: Schema.String,
|
|
130
|
+
attempt: Schema.Number,
|
|
131
|
+
createdAt: Schema.Number,
|
|
132
|
+
kind: ExecutionEventKind,
|
|
133
|
+
data: Json,
|
|
134
|
+
});
|
|
135
|
+
export const Gap = Schema.Struct({
|
|
136
|
+
resumeAfter: Schema.Number,
|
|
137
|
+
headSeq: Schema.Number,
|
|
138
|
+
});
|
|
139
|
+
export const decode = (schema, what) => {
|
|
140
|
+
const parse = decodeWith(schema, { errors: "all" }, (message) => new DecodeError({ what, message }));
|
|
141
|
+
return (input) => Effect.suspend(() => Effect.fromResult(parse(input)));
|
|
142
|
+
};
|
|
143
|
+
export const toJobResult = (job) => {
|
|
144
|
+
switch (job.status) {
|
|
145
|
+
case "succeeded":
|
|
146
|
+
return { id: job.id, status: job.status, result: job.result };
|
|
147
|
+
case "failed":
|
|
148
|
+
return { id: job.id, status: job.status, error: job.error };
|
|
149
|
+
case "continued":
|
|
150
|
+
return { id: job.id, status: "running" };
|
|
151
|
+
default:
|
|
152
|
+
return { id: job.id, status: job.status };
|
|
153
|
+
}
|
|
154
|
+
};
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
/** Why an execution failed, as reported by the service. */
|
|
3
|
+
export declare const FailureKind: Schema.Literals<readonly ["program", "limit", "infrastructure", "permission"]>;
|
|
4
|
+
export type FailureKind = typeof FailureKind.Type;
|
|
5
|
+
export declare const Failure: Schema.Struct<{
|
|
6
|
+
readonly kind: Schema.Literals<readonly ["program", "limit", "infrastructure", "permission"]>;
|
|
7
|
+
readonly code: Schema.String;
|
|
8
|
+
readonly message: Schema.String;
|
|
9
|
+
}>;
|
|
10
|
+
export type Failure = typeof Failure.Type;
|
|
11
|
+
/** The message of a thrown value: `Error#message`, else its string form. */
|
|
12
|
+
export declare const messageOf: (cause: unknown) => string;
|
|
13
|
+
declare const ConfigError_base: Schema.Class<ConfigError, Schema.TaggedStruct<"ConfigError", {
|
|
14
|
+
readonly message: Schema.String;
|
|
15
|
+
}>, import("effect/Cause").YieldableError>;
|
|
16
|
+
/** The CLI or client is missing configuration (URL, API key, arguments). */
|
|
17
|
+
export declare class ConfigError extends ConfigError_base {
|
|
18
|
+
}
|
|
19
|
+
declare const NetworkError_base: Schema.Class<NetworkError, Schema.TaggedStruct<"NetworkError", {
|
|
20
|
+
readonly url: Schema.String;
|
|
21
|
+
readonly message: Schema.String;
|
|
22
|
+
readonly cause: Schema.Unknown;
|
|
23
|
+
readonly reason: Schema.optional<Schema.String>;
|
|
24
|
+
}>, import("effect/Cause").YieldableError>;
|
|
25
|
+
/**
|
|
26
|
+
* The service could not be reached (DNS, TLS, connection reset, abort), or
|
|
27
|
+
* it ended a live stream. `reason` is set by the stream:
|
|
28
|
+
* - `functions_disabled`: Functions access was removed from the account;
|
|
29
|
+
* - `channel_closed`: the server closed the stream (subscribe again with
|
|
30
|
+
* `afterSeq`);
|
|
31
|
+
* - the server's reason of a refused join (e.g. `functions_unavailable`).
|
|
32
|
+
*/
|
|
33
|
+
export declare class NetworkError extends NetworkError_base {
|
|
34
|
+
}
|
|
35
|
+
declare const ApiError_base: Schema.Class<ApiError, Schema.TaggedStruct<"ApiError", {
|
|
36
|
+
readonly status: Schema.Number;
|
|
37
|
+
/** Stable machine code, e.g. `program_not_found`, `sdk_version_unsupported`. */
|
|
38
|
+
readonly code: Schema.String;
|
|
39
|
+
readonly message: Schema.String;
|
|
40
|
+
readonly failure: Schema.optional<Schema.Struct<{
|
|
41
|
+
readonly kind: Schema.Literals<readonly ["program", "limit", "infrastructure", "permission"]>;
|
|
42
|
+
readonly code: Schema.String;
|
|
43
|
+
readonly message: Schema.String;
|
|
44
|
+
}>>;
|
|
45
|
+
readonly body: Schema.Unknown;
|
|
46
|
+
}>, import("effect/Cause").YieldableError>;
|
|
47
|
+
/** The service answered with a non-2xx status. */
|
|
48
|
+
export declare class ApiError extends ApiError_base {
|
|
49
|
+
}
|
|
50
|
+
declare const DecodeError_base: Schema.Class<DecodeError, Schema.TaggedStruct<"DecodeError", {
|
|
51
|
+
readonly what: Schema.String;
|
|
52
|
+
readonly message: Schema.String;
|
|
53
|
+
}>, import("effect/Cause").YieldableError>;
|
|
54
|
+
/** A response or event did not match the expected contract. */
|
|
55
|
+
export declare class DecodeError extends DecodeError_base {
|
|
56
|
+
}
|
|
57
|
+
declare const ExecutionFailed_base: Schema.Class<ExecutionFailed, Schema.TaggedStruct<"ExecutionFailed", {
|
|
58
|
+
readonly executionId: Schema.String;
|
|
59
|
+
readonly failure: Schema.Struct<{
|
|
60
|
+
readonly kind: Schema.Literals<readonly ["program", "limit", "infrastructure", "permission"]>;
|
|
61
|
+
readonly code: Schema.String;
|
|
62
|
+
readonly message: Schema.String;
|
|
63
|
+
}>;
|
|
64
|
+
}>, import("effect/Cause").YieldableError>;
|
|
65
|
+
/** The execution finished with a failure raised by the program or the runtime. */
|
|
66
|
+
export declare class ExecutionFailed extends ExecutionFailed_base {
|
|
67
|
+
get message(): string;
|
|
68
|
+
}
|
|
69
|
+
declare const ExecutionEnded_base: Schema.Class<ExecutionEnded, Schema.TaggedStruct<"ExecutionEnded", {
|
|
70
|
+
readonly executionId: Schema.String;
|
|
71
|
+
readonly status: Schema.Literals<readonly ["cancelled", "expired", "acknowledged"]>;
|
|
72
|
+
}>, import("effect/Cause").YieldableError>;
|
|
73
|
+
/** The execution ended without a result (cancelled, expired, acknowledged). */
|
|
74
|
+
export declare class ExecutionEnded extends ExecutionEnded_base {
|
|
75
|
+
get message(): string;
|
|
76
|
+
}
|
|
77
|
+
declare const WaitTimeout_base: Schema.Class<WaitTimeout, Schema.TaggedStruct<"WaitTimeout", {
|
|
78
|
+
readonly executionId: Schema.String;
|
|
79
|
+
readonly timeoutMs: Schema.Number;
|
|
80
|
+
}>, import("effect/Cause").YieldableError>;
|
|
81
|
+
/** `wait` gave up after `timeoutMs`; the execution keeps running. */
|
|
82
|
+
export declare class WaitTimeout extends WaitTimeout_base {
|
|
83
|
+
get message(): string;
|
|
84
|
+
}
|
|
85
|
+
declare const BuildError_base: Schema.Class<BuildError, Schema.TaggedStruct<"BuildError", {
|
|
86
|
+
readonly stage: Schema.Literals<readonly ["v1_api", "forbidden_import", "forbidden_global", "typecheck", "bundle", "size", "write"]>;
|
|
87
|
+
readonly message: Schema.String;
|
|
88
|
+
}>, import("effect/Cause").YieldableError>;
|
|
89
|
+
/**
|
|
90
|
+
* Building the program failed. `stage` is stable:
|
|
91
|
+
* - `v1_api`: the program uses the removed 0.1 API (`ctx.data.query/pages`);
|
|
92
|
+
* - `forbidden_import`: a Node module (`fs`, `net`, `node:*`…);
|
|
93
|
+
* - `forbidden_global`: `fetch` or another network API in the program's code;
|
|
94
|
+
* - `typecheck`, `bundle`, `size` (over 1 MiB), `write`.
|
|
95
|
+
*/
|
|
96
|
+
export declare class BuildError extends BuildError_base {
|
|
97
|
+
}
|
|
98
|
+
export type ClientError = ConfigError | NetworkError | ApiError | DecodeError | ExecutionFailed | ExecutionEnded | WaitTimeout;
|
|
99
|
+
export {};
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
export const FailureKind = Schema.Literals([
|
|
3
|
+
"program",
|
|
4
|
+
"limit",
|
|
5
|
+
"infrastructure",
|
|
6
|
+
"permission",
|
|
7
|
+
]);
|
|
8
|
+
export const Failure = Schema.Struct({
|
|
9
|
+
kind: FailureKind,
|
|
10
|
+
code: Schema.String.check(Schema.isMaxLength(128)),
|
|
11
|
+
message: Schema.String.check(Schema.isMaxLength(2048)),
|
|
12
|
+
});
|
|
13
|
+
export const messageOf = (cause) => cause instanceof Error ? cause.message : String(cause);
|
|
14
|
+
export class ConfigError extends Schema.TaggedError()("ConfigError", { message: Schema.String }) {
|
|
15
|
+
}
|
|
16
|
+
export class NetworkError extends Schema.TaggedError()("NetworkError", {
|
|
17
|
+
url: Schema.String,
|
|
18
|
+
message: Schema.String,
|
|
19
|
+
cause: Schema.Unknown,
|
|
20
|
+
reason: Schema.optional(Schema.String),
|
|
21
|
+
}) {
|
|
22
|
+
}
|
|
23
|
+
export class ApiError extends Schema.TaggedError()("ApiError", {
|
|
24
|
+
status: Schema.Number,
|
|
25
|
+
code: Schema.String,
|
|
26
|
+
message: Schema.String,
|
|
27
|
+
failure: Schema.optional(Failure),
|
|
28
|
+
body: Schema.Unknown,
|
|
29
|
+
}) {
|
|
30
|
+
}
|
|
31
|
+
export class DecodeError extends Schema.TaggedError()("DecodeError", { what: Schema.String, message: Schema.String }) {
|
|
32
|
+
}
|
|
33
|
+
export class ExecutionFailed extends Schema.TaggedError()("ExecutionFailed", { executionId: Schema.String, failure: Failure }) {
|
|
34
|
+
get message() {
|
|
35
|
+
return `Execution ${this.executionId} failed (${this.failure.kind}/${this.failure.code}): ${this.failure.message}`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export class ExecutionEnded extends Schema.TaggedError()("ExecutionEnded", {
|
|
39
|
+
executionId: Schema.String,
|
|
40
|
+
status: Schema.Literals(["cancelled", "expired", "acknowledged"]),
|
|
41
|
+
}) {
|
|
42
|
+
get message() {
|
|
43
|
+
return `Execution ${this.executionId} ended without result: ${this.status}`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export class WaitTimeout extends Schema.TaggedError()("WaitTimeout", { executionId: Schema.String, timeoutMs: Schema.Number }) {
|
|
47
|
+
get message() {
|
|
48
|
+
return `Execution ${this.executionId} not finished after ${this.timeoutMs} ms`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export class BuildError extends Schema.TaggedError()("BuildError", {
|
|
52
|
+
stage: Schema.Literals([
|
|
53
|
+
"v1_api",
|
|
54
|
+
"forbidden_import",
|
|
55
|
+
"forbidden_global",
|
|
56
|
+
"typecheck",
|
|
57
|
+
"bundle",
|
|
58
|
+
"size",
|
|
59
|
+
"write",
|
|
60
|
+
]),
|
|
61
|
+
message: Schema.String,
|
|
62
|
+
}) {
|
|
63
|
+
}
|