alchemy 2.0.0-beta.48 → 2.0.0-beta.49
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/bin/exec.js +28 -5
- package/bin/exec.js.map +1 -1
- package/lib/AdoptPolicy.js +1 -1
- package/lib/AdoptPolicy.js.map +1 -1
- package/lib/Binding.d.ts +5 -1
- package/lib/Binding.d.ts.map +1 -1
- package/lib/Binding.js.map +1 -1
- package/lib/Cloudflare/AiGateway/AiGateway.d.ts +1 -1
- package/lib/Cloudflare/ApiToken/Common.d.ts +10 -1
- package/lib/Cloudflare/ApiToken/Common.d.ts.map +1 -1
- package/lib/Cloudflare/ApiToken/Common.js.map +1 -1
- package/lib/Cloudflare/Dns/DnsBinding.d.ts +52 -0
- package/lib/Cloudflare/Dns/DnsBinding.d.ts.map +1 -0
- package/lib/Cloudflare/Dns/DnsBinding.js +59 -0
- package/lib/Cloudflare/Dns/DnsBinding.js.map +1 -0
- package/lib/Cloudflare/Dns/DnsRead.d.ts +80 -0
- package/lib/Cloudflare/Dns/DnsRead.d.ts.map +1 -0
- package/lib/Cloudflare/Dns/DnsRead.js +70 -0
- package/lib/Cloudflare/Dns/DnsRead.js.map +1 -0
- package/lib/Cloudflare/Dns/DnsReadWrite.d.ts +79 -0
- package/lib/Cloudflare/Dns/DnsReadWrite.d.ts.map +1 -0
- package/lib/Cloudflare/Dns/DnsReadWrite.js +72 -0
- package/lib/Cloudflare/Dns/DnsReadWrite.js.map +1 -0
- package/lib/Cloudflare/Dns/DnsWrite.d.ts +113 -0
- package/lib/Cloudflare/Dns/DnsWrite.d.ts.map +1 -0
- package/lib/Cloudflare/Dns/DnsWrite.js +100 -0
- package/lib/Cloudflare/Dns/DnsWrite.js.map +1 -0
- package/lib/Cloudflare/Dns/index.d.ts +5 -0
- package/lib/Cloudflare/Dns/index.d.ts.map +1 -0
- package/lib/Cloudflare/Dns/index.js +5 -0
- package/lib/Cloudflare/Dns/index.js.map +1 -0
- package/lib/Cloudflare/Hyperdrive/Hyperdrive.d.ts +1 -1
- package/lib/Cloudflare/KV/KVNamespace.d.ts +1 -1
- package/lib/Cloudflare/Providers.d.ts.map +1 -1
- package/lib/Cloudflare/Providers.js +5 -1
- package/lib/Cloudflare/Providers.js.map +1 -1
- package/lib/Cloudflare/Queue/Queue.d.ts +1 -1
- package/lib/Cloudflare/R2/R2Bucket.d.ts +1 -1
- package/lib/Cloudflare/SecretsStore/Secret.d.ts +1 -1
- package/lib/Cloudflare/StateStore/Api.d.ts +1 -1
- package/lib/Cloudflare/Vectorize/VectorizeIndex.d.ts +1 -1
- package/lib/Cloudflare/Workers/WorkerBinding.d.ts +2 -2
- 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/Output.d.ts +13 -1
- package/lib/Output.d.ts.map +1 -1
- package/lib/Output.js +43 -11
- package/lib/Output.js.map +1 -1
- package/lib/Plan.d.ts.map +1 -1
- package/lib/Plan.js +8 -0
- package/lib/Plan.js.map +1 -1
- package/lib/Platform.d.ts.map +1 -1
- package/lib/Platform.js +5 -2
- package/lib/Platform.js.map +1 -1
- package/lib/Resource.d.ts +1 -1
- package/lib/Resource.d.ts.map +1 -1
- package/lib/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/AdoptPolicy.ts +1 -1
- package/src/Binding.ts +5 -1
- package/src/Cloudflare/ApiToken/Common.ts +13 -3
- package/src/Cloudflare/Dns/DnsBinding.ts +123 -0
- package/src/Cloudflare/Dns/DnsRead.ts +129 -0
- package/src/Cloudflare/Dns/DnsReadWrite.ts +99 -0
- package/src/Cloudflare/Dns/DnsWrite.ts +209 -0
- package/src/Cloudflare/Dns/index.ts +4 -0
- package/src/Cloudflare/Providers.ts +7 -0
- package/src/Cloudflare/index.ts +1 -0
- package/src/Output.ts +67 -11
- package/src/Plan.ts +9 -0
- package/src/Platform.ts +11 -3
- package/src/Resource.ts +1 -1
package/src/Cloudflare/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./Browser/index.ts";
|
|
|
6
6
|
export * from "./CloudflareEnvironment.ts";
|
|
7
7
|
export * from "./Container/index.ts";
|
|
8
8
|
export * from "./D1/index.ts";
|
|
9
|
+
export * from "./Dns/index.ts";
|
|
9
10
|
export * from "./EdgeSession.ts";
|
|
10
11
|
export * from "./Fetcher.ts";
|
|
11
12
|
export * from "./Email/index.ts";
|
package/src/Output.ts
CHANGED
|
@@ -81,6 +81,7 @@ export type Expr<A = any, Req = any> =
|
|
|
81
81
|
| AllExpr<Expr<A, Req>[]>
|
|
82
82
|
| ApplyExpr<any, A, Req>
|
|
83
83
|
| EffectExpr<any, A, Req>
|
|
84
|
+
| FlatMapExpr<any, A, Req>
|
|
84
85
|
| LiteralExpr<A>
|
|
85
86
|
| NamedExpr<A, Req>
|
|
86
87
|
| PropExpr<A, keyof A, Req>
|
|
@@ -238,6 +239,45 @@ export const mapEffect =
|
|
|
238
239
|
<Req>(output: Output<A, Req>): ToOutput<B, Req | Req2> =>
|
|
239
240
|
new EffectExpr(output as Expr<A, Req>, fn) as any;
|
|
240
241
|
|
|
242
|
+
export const flatMap: {
|
|
243
|
+
<A, B, Req2>(
|
|
244
|
+
fn: (value: A) => Output<B, Req2>,
|
|
245
|
+
): <Req>(output: Output<A, Req>) => ToOutput<B, Req | Req2>;
|
|
246
|
+
<A, B, Req, Req2>(
|
|
247
|
+
output: Output<A, Req>,
|
|
248
|
+
fn: (value: A) => Output<B, Req2>,
|
|
249
|
+
): ToOutput<B, Req | Req2>;
|
|
250
|
+
} = (<A, B, Req, Req2>(
|
|
251
|
+
...args:
|
|
252
|
+
| [fn: (value: A) => Output<B, Req2>]
|
|
253
|
+
| [output: Output<A, Req>, fn: (value: A) => Output<B, Req2>]
|
|
254
|
+
) =>
|
|
255
|
+
args.length === 1
|
|
256
|
+
? <Req>(output: Output<A, Req>): ToOutput<B, Req | Req2> =>
|
|
257
|
+
new FlatMapExpr(output as Expr<A, Req>, args[0]) as any
|
|
258
|
+
: new FlatMapExpr(args[0] as any, args[1])) as any;
|
|
259
|
+
|
|
260
|
+
export const isFlatMapExpr = <In = any, Out = any, Req = any, Req2 = any>(
|
|
261
|
+
node: any,
|
|
262
|
+
): node is FlatMapExpr<In, Out, Req, Req2> => node?.kind === "FlatMapExpr";
|
|
263
|
+
|
|
264
|
+
export class FlatMapExpr<A, B, Req = never, Req2 = never> extends BaseExpr<
|
|
265
|
+
B,
|
|
266
|
+
Req | Req2
|
|
267
|
+
> {
|
|
268
|
+
readonly kind = "FlatMapExpr";
|
|
269
|
+
constructor(
|
|
270
|
+
public readonly expr: Expr<A, Req>,
|
|
271
|
+
public readonly f: (value: A) => Output<B, Req2>,
|
|
272
|
+
) {
|
|
273
|
+
super();
|
|
274
|
+
return proxy(this);
|
|
275
|
+
}
|
|
276
|
+
[inspect](): string {
|
|
277
|
+
return `${this.expr[inspect]()}.flatMap(${this.f.toString()})`;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
241
281
|
export const isEffectExpr = <In = any, Out = any, Req = any, Req2 = any>(
|
|
242
282
|
node: any,
|
|
243
283
|
): node is EffectExpr<In, Out, Req, Req2> => node?.kind === "EffectExpr";
|
|
@@ -461,20 +501,26 @@ function proxy(self: any): any {
|
|
|
461
501
|
? target[inspect]
|
|
462
502
|
: isResourceExpr(self) && self.stables && prop in self.stables
|
|
463
503
|
? self.stables[prop as keyof typeof self.stables]
|
|
464
|
-
: prop
|
|
465
|
-
? self[prop]
|
|
466
|
-
|
|
467
|
-
?
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
: self[prop as keyof typeof self]
|
|
471
|
-
: new PropExpr(proxy, prop as never),
|
|
504
|
+
: prop in self
|
|
505
|
+
? typeof self[prop as keyof typeof self] === "function" &&
|
|
506
|
+
!("kind" in self)
|
|
507
|
+
? new PropExpr(proxy, prop as never)
|
|
508
|
+
: self[prop as keyof typeof self]
|
|
509
|
+
: new PropExpr(proxy, prop as never),
|
|
472
510
|
apply: (_, thisArg, args) => {
|
|
473
511
|
if (isPropExpr(self)) {
|
|
474
|
-
|
|
512
|
+
// Method-style combinators on an Output proxy. `map`/`apply` and
|
|
513
|
+
// `mapEffect`/`effect` are aliases that mirror the standalone
|
|
514
|
+
// `Output.map` / `Output.mapEffect` / `Output.flatMap` functions.
|
|
515
|
+
if (self.identifier === "map" || self.identifier === "apply") {
|
|
475
516
|
return new ApplyExpr(self.expr, args[0]);
|
|
476
|
-
} else if (
|
|
517
|
+
} else if (
|
|
518
|
+
self.identifier === "mapEffect" ||
|
|
519
|
+
self.identifier === "effect"
|
|
520
|
+
) {
|
|
477
521
|
return new EffectExpr(self.expr, args[0]);
|
|
522
|
+
} else if (self.identifier === "flatMap") {
|
|
523
|
+
return new FlatMapExpr(self.expr, args[0]);
|
|
478
524
|
}
|
|
479
525
|
}
|
|
480
526
|
return undefined;
|
|
@@ -540,6 +586,11 @@ export const evaluate: <A, Req = never>(
|
|
|
540
586
|
} else if (isEffectExpr(expr)) {
|
|
541
587
|
// TODO(sam): the same effect shoudl be memoized so that it's not run multiple times
|
|
542
588
|
return yield* expr.f(yield* evaluate(expr.expr, upstream));
|
|
589
|
+
} else if (isFlatMapExpr(expr)) {
|
|
590
|
+
// Resolve the source, hand it to `f` to produce a new Output, then
|
|
591
|
+
// recursively evaluate that Output (flattening one level).
|
|
592
|
+
const value = yield* evaluate(expr.expr, upstream);
|
|
593
|
+
return yield* evaluate(expr.f(value), upstream);
|
|
543
594
|
} else if (isAllExpr(expr)) {
|
|
544
595
|
return yield* Effect.all(
|
|
545
596
|
expr.outs.map((out) => evaluate(out, upstream)),
|
|
@@ -648,7 +699,12 @@ export const upstream = <E extends Output<any, any>>(expr: E): any => {
|
|
|
648
699
|
return upstream(expr.expr);
|
|
649
700
|
} else if (isAllExpr(expr)) {
|
|
650
701
|
return Object.assign({}, ...expr.outs.map((out) => upstream(out)));
|
|
651
|
-
} else if (
|
|
702
|
+
} else if (
|
|
703
|
+
isEffectExpr(expr) ||
|
|
704
|
+
isApplyExpr(expr) ||
|
|
705
|
+
isFlatMapExpr(expr) ||
|
|
706
|
+
isNamedExpr(expr)
|
|
707
|
+
) {
|
|
652
708
|
return upstream(expr.expr);
|
|
653
709
|
} else if (Array.isArray(expr)) {
|
|
654
710
|
return expr.map(upstream).reduce(toObject, {});
|
package/src/Plan.ts
CHANGED
|
@@ -424,6 +424,15 @@ export const make = <A>(
|
|
|
424
424
|
} else if (Output.isEffectExpr(expr)) {
|
|
425
425
|
const upstream = yield* resolveOutput(expr.expr);
|
|
426
426
|
return Output.hasOutputs(upstream) ? expr : yield* expr.f(upstream);
|
|
427
|
+
} else if (Output.isFlatMapExpr(expr)) {
|
|
428
|
+
const upstream = yield* resolveOutput(expr.expr);
|
|
429
|
+
// Source still unresolved -> keep the flatMap intact for a later pass.
|
|
430
|
+
// Otherwise run `f` to produce the next Output and resolve into it.
|
|
431
|
+
return Output.hasOutputs(upstream)
|
|
432
|
+
? expr
|
|
433
|
+
: yield* resolveOutput(
|
|
434
|
+
Output.asOutput(expr.f(upstream)) as Output.Expr<any>,
|
|
435
|
+
);
|
|
427
436
|
} else if (Output.isAllExpr(expr)) {
|
|
428
437
|
return yield* Effect.all(expr.outs.map(resolveOutput), {
|
|
429
438
|
concurrency: "unbounded",
|
package/src/Platform.ts
CHANGED
|
@@ -5,6 +5,7 @@ import * as Effect from "effect/Effect";
|
|
|
5
5
|
import { pipe } from "effect/Function";
|
|
6
6
|
import * as Layer from "effect/Layer";
|
|
7
7
|
import * as Option from "effect/Option";
|
|
8
|
+
import * as Redacted from "effect/Redacted";
|
|
8
9
|
import type { Scope } from "effect/Scope";
|
|
9
10
|
import type { HttpClient } from "effect/unstable/http/HttpClient";
|
|
10
11
|
import { SingleShotGen } from "effect/Utils";
|
|
@@ -370,14 +371,21 @@ export const Platform = <
|
|
|
370
371
|
const node = yield* configProvider.get(path);
|
|
371
372
|
if (phase === "plan" && node) {
|
|
372
373
|
// bind it to the RuntimeContext if running in plan phase
|
|
373
|
-
const output = Output.literal(
|
|
374
|
+
const output = Output.literal(
|
|
375
|
+
Redacted.make(node.value),
|
|
376
|
+
);
|
|
374
377
|
yield* ctx?.set(key, output) ?? Effect.void;
|
|
375
378
|
return node;
|
|
376
379
|
} else if (phase === "runtime" && ctx) {
|
|
377
380
|
// retrieve from the RuntimeContext if running in runtime phase
|
|
378
|
-
const value =
|
|
381
|
+
const value =
|
|
382
|
+
yield* ctx.get<Redacted.Redacted<string>>(key);
|
|
379
383
|
if (value) {
|
|
380
|
-
return ConfigProvider.makeValue(
|
|
384
|
+
return ConfigProvider.makeValue(
|
|
385
|
+
Redacted.isRedacted(value)
|
|
386
|
+
? Redacted.value(value)
|
|
387
|
+
: value,
|
|
388
|
+
);
|
|
381
389
|
}
|
|
382
390
|
}
|
|
383
391
|
// fallback to the config provider otherwise
|
package/src/Resource.ts
CHANGED
|
@@ -126,7 +126,7 @@ export type Resource<
|
|
|
126
126
|
Providers = undefined,
|
|
127
127
|
> = Pipeable &
|
|
128
128
|
ResourceLike<Type, Props, Attributes, Binding, Providers> & {
|
|
129
|
-
bind(sid: string
|
|
129
|
+
bind(sid: Input<string>, binding: Input<Binding>): Effect.Effect<void>;
|
|
130
130
|
bind(
|
|
131
131
|
template: TemplateStringsArray,
|
|
132
132
|
...args: any[]
|