@gjermundgaraba/effect-actions 0.41.0 → 0.42.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/dist/Action.d.mts +1 -1
- package/dist/Action.mjs +1 -1
- package/dist/ActionCli.d.mts +3 -3
- package/dist/ActionCli.mjs +2 -2
- package/dist/ActionEntity.d.mts +4 -4
- package/dist/ActionEntity.mjs +4 -4
- package/dist/ActionHttp.d.mts +3 -3
- package/dist/ActionHttp.mjs +3 -3
- package/dist/ActionMcp.d.mts +3 -3
- package/dist/ActionMcp.mjs +21 -15
- package/dist/ActionRpc.d.mts +4 -4
- package/dist/ActionRpc.mjs +3 -3
- package/dist/ActionToolkit.d.mts +2 -2
- package/dist/ActionToolkit.mjs +19 -17
- package/dist/Authentication.d.mts +3 -3
- package/dist/Authentication.mjs +3 -3
- package/dist/Event.d.mts +1 -1
- package/dist/Event.mjs +1 -1
- package/dist/Stored.d.mts +2 -2
- package/dist/Stored.mjs +3 -3
- package/dist/Testing.d.mts +1 -1
- package/dist/Testing.mjs +1 -1
- package/dist/Webhook.d.mts +3 -3
- package/dist/Webhook.mjs +5 -5
- package/dist/authentication/provider.d.mts +6 -6
- package/dist/authentication/provider.mjs +1 -1
- package/dist/authentication/refusal.mjs +2 -2
- package/dist/cli/commands.d.mts +2 -2
- package/dist/cli/commands.mjs +2 -2
- package/dist/contract/authorizer.d.mts +2 -3
- package/dist/contract/authorizer.mjs +1 -1
- package/dist/contract/call.d.mts +1 -1
- package/dist/contract/call.mjs +1 -1
- package/dist/contract/caller.d.mts +1 -1
- package/dist/contract/codes.mjs +1 -1
- package/dist/contract/declared.d.mts +1 -1
- package/dist/contract/declared.mjs +1 -1
- package/dist/contract/feed.d.mts +1 -1
- package/dist/contract/feed.mjs +1 -1
- package/dist/contract/hub.d.mts +1 -1
- package/dist/contract/hub.mjs +1 -1
- package/dist/contract/idempotency.d.mts +1 -1
- package/dist/contract/idempotency.mjs +1 -1
- package/dist/contract/implementation.d.mts +1 -1
- package/dist/contract/implementation.mjs +22 -3
- package/dist/contract/lift.mjs +17 -14
- package/dist/contract/log.d.mts +1 -1
- package/dist/contract/log.mjs +1 -1
- package/dist/contract/media.d.mts +1 -1
- package/dist/contract/occurrence.d.mts +1 -1
- package/dist/contract/pages.d.mts +1 -1
- package/dist/contract/pages.mjs +1 -1
- package/dist/contract/progress.d.mts +1 -1
- package/dist/contract/push.d.mts +1 -1
- package/dist/contract/push.mjs +1 -1
- package/dist/contract/receiving.d.mts +1 -1
- package/dist/contract/receiving.mjs +1 -1
- package/dist/contract/stream.d.mts +5 -5
- package/dist/contract/stream.mjs +4 -4
- package/dist/contract/subscribe.d.mts +1 -1
- package/dist/contract/subscribe.mjs +1 -1
- package/dist/contract/transient.mjs +2 -2
- package/dist/contract/wake.d.mts +1 -1
- package/dist/contract/watch.d.mts +1 -1
- package/dist/contract/watch.mjs +1 -1
- package/dist/contract/webhooks.d.mts +1 -1
- package/dist/contract/webhooks.mjs +1 -1
- package/dist/entity/forwarded.d.mts +1 -1
- package/dist/entity/wakes.mjs +3 -3
- package/dist/http/client.d.mts +3 -3
- package/dist/http/client.mjs +3 -3
- package/dist/http/events.d.mts +2 -2
- package/dist/http/events.mjs +3 -3
- package/dist/http/schema-errors.mjs +1 -1
- package/dist/http/streamed.d.mts +3 -3
- package/dist/http/streamed.mjs +3 -3
- package/dist/http/unavailable.mjs +1 -1
- package/dist/http/watch.mjs +2 -2
- package/dist/mcp/bridge.mjs +3 -3
- package/dist/mcp/client.d.mts +2 -2
- package/dist/mcp/client.mjs +6 -6
- package/dist/mcp/events.mjs +2 -2
- package/dist/mcp/progress.mjs +1 -1
- package/dist/mcp/protocol.mjs +21 -12
- package/dist/mcp/reply.d.mts +2 -2
- package/dist/mcp/reply.mjs +1 -1
- package/dist/mcp/request.mjs +1 -1
- package/dist/mcp/watch.mjs +1 -1
- package/dist/rpc/erased.d.mts +2 -2
- package/dist/rpc/erased.mjs +4 -4
- package/dist/rpc/watch.mjs +3 -3
- package/dist/testing/memory.d.mts +1 -1
- package/dist/webhook/attempt.mjs +1 -1
- package/dist/webhook/receiver.mjs +3 -3
- package/dist/webhook/signing.mjs +2 -2
- package/dist/webhook/stored.mjs +2 -2
- package/dist/webhook/subscriptions.mjs +2 -2
- package/docs/Action.md +1 -1
- package/docs/setup.md +1 -1
- package/package.json +7 -7
package/dist/contract/call.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import "effect";
|
|
1
2
|
import { Any } from "../Action.mjs";
|
|
2
3
|
import "./codec.mjs";
|
|
3
4
|
import "./errors.mjs";
|
|
4
5
|
import "./implementation.mjs";
|
|
5
6
|
import { ProgressArgs } from "./progress.mjs";
|
|
6
|
-
import { Effect, Schema, Stream } from "effect";
|
|
7
7
|
/**
|
|
8
8
|
* A call of `A` answering `R`, taking `{ onProgress }` after its input where `A` declares
|
|
9
9
|
* `progress`. It may leave its input out when `{}` is a valid encoded input, such as for an
|
package/dist/contract/call.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { InvalidInput } from "./errors.mjs";
|
|
2
1
|
import { Effect, Predicate, Schema, Stream } from "effect";
|
|
2
|
+
import { InvalidInput } from "./errors.mjs";
|
|
3
3
|
// src/contract/call.ts
|
|
4
4
|
const isCallOptions = (options) => Predicate.hasProperty(options, "onProgress") && Predicate.isFunction(options.onProgress);
|
|
5
5
|
const onProgressOf = (args) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import "effect";
|
|
1
2
|
import { Any } from "../Action.mjs";
|
|
2
3
|
import { Codec } from "./codec.mjs";
|
|
3
|
-
import { Context, Effect } from "effect";
|
|
4
4
|
/**
|
|
5
5
|
* The caller of a public action, `caller: Action.Anyone`: anyone, signed in or not, and no
|
|
6
6
|
* authorizer runs for it. Registered globally, so two copies of the package agree on it, as they
|
package/dist/contract/codes.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Option, Schema, SchemaTransformation, Struct } from "effect";
|
|
1
2
|
import { Forbidden, Refusal } from "./errors.mjs";
|
|
2
3
|
import { CallbackCategory, CallbackFailed, NotServed, NotSubscribed, SubscriptionError, Unsupported } from "../Event.mjs";
|
|
3
|
-
import { Option, Schema, SchemaTransformation, Struct } from "effect";
|
|
4
4
|
// src/contract/codes.ts
|
|
5
5
|
const eventCodes = {
|
|
6
6
|
notFound: -32023,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Types } from "effect";
|
|
1
2
|
import { Errors } from "../Action.mjs";
|
|
2
3
|
import "./caller.mjs";
|
|
3
|
-
import { Types } from "effect";
|
|
4
4
|
type ListOf<G> = G extends Errors ? G : readonly [G];
|
|
5
5
|
/**
|
|
6
6
|
* The errors options `O` declare, as at run time: those `error` always gives, or, where it may
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { Predicate, Schema, SchemaAST } from "effect";
|
|
1
2
|
import { literalValues, members } from "./ast.mjs";
|
|
2
3
|
import { Anyone, assertAuthentication } from "./caller.mjs";
|
|
3
4
|
import { builtIns } from "./errors.mjs";
|
|
4
5
|
import { httpApiStatusOf } from "./status.mjs";
|
|
5
|
-
import { Predicate, Schema, SchemaAST } from "effect";
|
|
6
6
|
// src/contract/declared.ts
|
|
7
7
|
const errorList = (error) => {
|
|
8
8
|
if (error === void 0) return [];
|
package/dist/contract/feed.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Stream } from "effect";
|
|
1
2
|
import { Anyone } from "./caller.mjs";
|
|
2
3
|
import { Any } from "../Event.mjs";
|
|
3
4
|
import { ErasedAuthorize, ErasedValue, Memoized, Protected } from "./implementation.mjs";
|
|
4
5
|
import { Fed, Page } from "./pages.mjs";
|
|
5
6
|
import { WebhookHolder } from "./webhooks.mjs";
|
|
6
|
-
import { Context, Duration, Effect, Layer, Stream } from "effect";
|
|
7
7
|
/**
|
|
8
8
|
* An implemented event type, behind its authorizer, as a surface serves it: a poll, whose
|
|
9
9
|
* subscription `subscriber` names, such as its principal, and a stream, which lasts as long as it
|
package/dist/contract/feed.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Array, DateTime, Duration, Effect, Exit, Layer, Option, Predicate, Stream } from "effect";
|
|
1
2
|
import { jsonRoundTrip } from "./call.mjs";
|
|
2
3
|
import { Anyone } from "./caller.mjs";
|
|
3
4
|
import { canonical, canonicalInput } from "./canonical.mjs";
|
|
@@ -11,7 +12,6 @@ import { AnyOccurrence, Gap } from "./occurrence.mjs";
|
|
|
11
12
|
import { fedOf, pagedFrom } from "./pages.mjs";
|
|
12
13
|
import { reported } from "./reported.mjs";
|
|
13
14
|
import { Wake } from "./wake.mjs";
|
|
14
|
-
import { Array, DateTime, Duration, Effect, Exit, Layer, Option, Predicate, Stream } from "effect";
|
|
15
15
|
// src/contract/feed.ts
|
|
16
16
|
const defaultNextPoll = Duration.seconds(5);
|
|
17
17
|
const shortestNextPoll = Duration.seconds(1);
|
package/dist/contract/hub.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Context, Effect, Layer } from "effect";
|
|
1
2
|
import { Any, Emitted } from "../Event.mjs";
|
|
2
3
|
import "./log.mjs";
|
|
3
|
-
import { Context, Effect, Layer, Scope, Stream } from "effect";
|
|
4
4
|
/** What `notify` and `publish` take: the key whose subscribers they reach. */
|
|
5
5
|
export interface KeyOptions {
|
|
6
6
|
/**
|
package/dist/contract/hub.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { makeLog, makeLogStore, memoryStorage } from "./log.mjs";
|
|
2
1
|
import { Context, Effect, Layer, Queue, Stream } from "effect";
|
|
2
|
+
import { makeLog, makeLogStore, memoryStorage } from "./log.mjs";
|
|
3
3
|
// src/contract/hub.ts
|
|
4
4
|
const memoryRevisions = () => {
|
|
5
5
|
const counts = /* @__PURE__ */ new Map();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
1
2
|
import "../Action.mjs";
|
|
2
3
|
import "./implementation.mjs";
|
|
3
|
-
import { Context, Effect, Layer, Schema } from "effect";
|
|
4
4
|
export declare const Kept: Schema.Struct<{
|
|
5
5
|
readonly input: Schema.String;
|
|
6
6
|
readonly outcome: Schema.String;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Cause, Clock, Context, Deferred, Effect, Exit, Layer, Option, Predicate, Schema } from "effect";
|
|
1
2
|
import { CallerKeyed, principalOf } from "./caller.mjs";
|
|
2
3
|
import { canonicalInput } from "./canonical.mjs";
|
|
3
4
|
import { projectedErrors } from "./declared.mjs";
|
|
@@ -5,7 +6,6 @@ import { sha256Hex } from "./digest.mjs";
|
|
|
5
6
|
import { InvalidInput } from "./errors.mjs";
|
|
6
7
|
import { answered } from "./implementation.mjs";
|
|
7
8
|
import { declaredStatus, isTransientStatus } from "./status.mjs";
|
|
8
|
-
import { Cause, Clock, Context, Deferred, Effect, Exit, Layer, Option, Predicate, Schema } from "effect";
|
|
9
9
|
// src/contract/idempotency.ts
|
|
10
10
|
const Kept = Schema.Struct({
|
|
11
11
|
input: Schema.String,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Stream } from "effect";
|
|
1
2
|
import { Any } from "../Action.mjs";
|
|
2
3
|
import { Anyone, Keyed } from "./caller.mjs";
|
|
3
4
|
import { Refusal } from "./errors.mjs";
|
|
4
5
|
import { Any as Any$1 } from "../Event.mjs";
|
|
5
6
|
import { AnyEventImplementation, EventOf } from "./feed.mjs";
|
|
6
7
|
import { Reporting } from "./progress.mjs";
|
|
7
|
-
import { Context, Effect, Layer, Scope, Stream } from "effect";
|
|
8
8
|
export type ErasedValue = Any["input"]["Type"];
|
|
9
9
|
export type WrittenHandler<R> = {
|
|
10
10
|
bivarianceHack(input: ErasedValue, reporting?: Reporting): Effect.Effect<ErasedValue, ErasedValue, R> | Stream.Stream<ErasedValue, ErasedValue, R>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { Array, Cause, Context, Effect, Exit, Layer, Option, Predicate, References, Schema, Stream } from "effect";
|
|
1
2
|
import { Anyone, CallerKeyed } from "./caller.mjs";
|
|
2
3
|
import { projectedErrors } from "./declared.mjs";
|
|
3
4
|
import { Unauthenticated } from "./errors.mjs";
|
|
4
5
|
import { reportedTo, streamReportedTo } from "./progress.mjs";
|
|
5
6
|
import { elementOf } from "./stream.mjs";
|
|
6
|
-
import { Array, Cause, Context, Effect, Exit, Layer, Option, Predicate, References, Schema, Stream } from "effect";
|
|
7
7
|
// src/contract/implementation.ts
|
|
8
8
|
const uniqueKey = () => Math.random().toString(36).slice(2);
|
|
9
9
|
const notAStream = /* @__PURE__ */ new Error("A handler answered otherwise than its action's success declares");
|
|
@@ -23,6 +23,25 @@ const asDefects = (reason, rejected) => {
|
|
|
23
23
|
const trace = Context.makeUnsafe(reason.annotations);
|
|
24
24
|
return [Cause.makeDieReason(reason.error).annotate(trace), Cause.makeDieReason(Cause.squash(rejected)).annotate(trace)];
|
|
25
25
|
};
|
|
26
|
+
const failsOnly = (cause) => cause.reasons.every(Cause.isFailReason);
|
|
27
|
+
const noteAnswer = (cause) => {
|
|
28
|
+
const error = Option.getOrUndefined(Cause.findErrorOption(cause));
|
|
29
|
+
return Effect.annotateCurrentSpan("error.type", Predicate.hasProperty(error, "_tag") && Predicate.isString(error._tag) ? error._tag : "_OTHER");
|
|
30
|
+
};
|
|
31
|
+
var Answered = class {
|
|
32
|
+
cause;
|
|
33
|
+
constructor(cause) {
|
|
34
|
+
this.cause = cause;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const answeredIn = (cause) => failsOnly(cause) ? Effect.as(noteAnswer(cause), new Answered(cause)) : Effect.failCause(cause);
|
|
38
|
+
const unanswered = (value) => value instanceof Answered ? Effect.failCause(value.cause) : Effect.succeed(value);
|
|
39
|
+
const withAnsweringSpan = (name, options) => (stream) => Stream.suspend(() => {
|
|
40
|
+
let answer;
|
|
41
|
+
return stream.pipe(Stream.catchCause((cause) => failsOnly(cause) ? Stream.fromEffectDrain(Effect.andThen(noteAnswer(cause), Effect.sync(() => {
|
|
42
|
+
answer = cause;
|
|
43
|
+
}))) : Stream.failCause(cause)), Stream.withSpan(name, options), Stream.concat(Stream.suspend(() => answer === void 0 ? Stream.empty : Stream.failCause(answer))));
|
|
44
|
+
});
|
|
26
45
|
const dispatch = (action, handle, before, keyed) => {
|
|
27
46
|
const actionAttributes = {
|
|
28
47
|
"action.name": action.name,
|
|
@@ -47,12 +66,12 @@ const dispatch = (action, handle, before, keyed) => {
|
|
|
47
66
|
return (input, sink) => Effect.succeed(Stream.unwrap(Effect.map(admitted, () => streamReportedTo(action.progress, sink, (reporting) => streamed(handle(input, reporting))))).pipe(Stream.catchCause((cause) => Stream.fromEffect(declaredOrDefect(cause))), Stream.updateService(References.CurrentLogAnnotations, (annotations) => ({
|
|
48
67
|
...annotations,
|
|
49
68
|
...actionAttributes
|
|
50
|
-
})),
|
|
69
|
+
})), withAnsweringSpan(action.name, {
|
|
51
70
|
...span,
|
|
52
71
|
...trace
|
|
53
72
|
})));
|
|
54
73
|
}
|
|
55
|
-
return (input, sink) => Effect.scoped(admitted.pipe(Effect.andThen(Effect.suspend(() => reportedTo(action.progress, sink, (reporting) => answered(handle(input, reporting))))), Effect.provideService(CallerKeyed, keyed), Effect.catchCause(declaredOrDefect))).pipe(Effect.annotateLogs(actionAttributes), Effect.withSpan(action.name, span, trace));
|
|
74
|
+
return (input, sink) => Effect.scoped(admitted.pipe(Effect.andThen(Effect.suspend(() => reportedTo(action.progress, sink, (reporting) => answered(handle(input, reporting))))), Effect.provideService(CallerKeyed, keyed), Effect.catchCause(declaredOrDefect))).pipe(Effect.annotateLogs(actionAttributes), Effect.catchCause(answeredIn), Effect.withSpan(action.name, span, trace), Effect.flatMap(unanswered));
|
|
56
75
|
};
|
|
57
76
|
/**
|
|
58
77
|
* Actions bound to their handlers and their authorizer: everything one `Action.implement` call
|
package/dist/contract/lift.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Predicate, Schema, SchemaAST } from "effect";
|
|
1
2
|
import { unsuspended } from "./ast.mjs";
|
|
2
3
|
import { Media, kindOf } from "./media.mjs";
|
|
3
|
-
import { Predicate, Schema, SchemaAST } from "effect";
|
|
4
4
|
// src/contract/lift.ts
|
|
5
5
|
const isMedia = Schema.is(Media);
|
|
6
6
|
const isMediaArray = Schema.is(Schema.Array(Media));
|
|
@@ -37,12 +37,12 @@ const liftOf = (success) => {
|
|
|
37
37
|
const ast = unsuspended(success.ast);
|
|
38
38
|
const whole = wholeSuccessMediaOf(ast);
|
|
39
39
|
if (whole !== void 0) return {
|
|
40
|
+
_tag: "Fields",
|
|
40
41
|
fields: [{
|
|
41
42
|
name: void 0,
|
|
42
43
|
...whole
|
|
43
44
|
}],
|
|
44
|
-
rest: void 0
|
|
45
|
-
otherwise: void 0
|
|
45
|
+
rest: void 0
|
|
46
46
|
};
|
|
47
47
|
if (SchemaAST.isUnion(ast) && ast.encoding === void 0) {
|
|
48
48
|
const members = ast.types.map((member) => [member, wholeSuccessMediaOf(member)]);
|
|
@@ -51,16 +51,20 @@ const liftOf = (success) => {
|
|
|
51
51
|
...lifted
|
|
52
52
|
}]);
|
|
53
53
|
const others = members.flatMap(([member, lifted]) => lifted === void 0 ? [Schema.make(member)] : []);
|
|
54
|
-
|
|
54
|
+
const [only, ...more] = others;
|
|
55
|
+
if (media.length > 0) return only === void 0 ? {
|
|
56
|
+
_tag: "Fields",
|
|
55
57
|
fields: media,
|
|
56
|
-
rest: void 0
|
|
57
|
-
|
|
58
|
+
rest: void 0
|
|
59
|
+
} : {
|
|
60
|
+
_tag: "Either",
|
|
61
|
+
fields: media,
|
|
62
|
+
otherwise: more.length === 0 ? only : Schema.Union(others)
|
|
58
63
|
};
|
|
59
64
|
}
|
|
60
65
|
if (!SchemaAST.isObjects(ast) || ast.encoding !== void 0) return {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
otherwise: void 0
|
|
66
|
+
_tag: "Plain",
|
|
67
|
+
success
|
|
64
68
|
};
|
|
65
69
|
const fields = ast.propertySignatures.flatMap(({ name, type }) => {
|
|
66
70
|
const field = mediaFieldOf(type);
|
|
@@ -70,20 +74,19 @@ const liftOf = (success) => {
|
|
|
70
74
|
}];
|
|
71
75
|
});
|
|
72
76
|
if (fields.length === 0) return {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
otherwise: void 0
|
|
77
|
+
_tag: "Plain",
|
|
78
|
+
success
|
|
76
79
|
};
|
|
77
80
|
const names = new Set(fields.map(({ name }) => name));
|
|
78
81
|
const rest = ast.propertySignatures.filter(({ name }) => !names.has(name));
|
|
79
82
|
const { identifier: _identifierOfWholeSuccess, ...annotationsOfRest } = ast.annotations ?? {};
|
|
80
83
|
return {
|
|
84
|
+
_tag: "Fields",
|
|
81
85
|
fields,
|
|
82
|
-
otherwise: void 0,
|
|
83
86
|
rest: rest.length === 0 && ast.indexSignatures.length === 0 ? void 0 : Schema.make(new SchemaAST.Objects(rest, ast.indexSignatures, annotationsOfRest))
|
|
84
87
|
};
|
|
85
88
|
};
|
|
86
|
-
const liftedFrom = (
|
|
89
|
+
const liftedFrom = (fields, success) => fields.flatMap(({ name, kind, many }) => {
|
|
87
90
|
const field = name !== void 0 && Predicate.hasProperty(success, name) ? success[name] : void 0;
|
|
88
91
|
const value = name === void 0 ? success : field;
|
|
89
92
|
const listed = isMediaArray(value) ? value : [];
|
package/dist/contract/log.d.mts
CHANGED
package/dist/contract/log.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Cause, Clock, Duration, Effect, Option, Queue, Semaphore, Stream } from "effect";
|
|
1
2
|
import { uniqueKey } from "./implementation.mjs";
|
|
2
3
|
import { reported } from "./reported.mjs";
|
|
3
|
-
import { Cause, Clock, Duration, Effect, Option, Queue, Semaphore, Stream } from "effect";
|
|
4
4
|
// src/contract/log.ts
|
|
5
5
|
const defaultBounds = {
|
|
6
6
|
maxAge: Duration.minutes(10),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema
|
|
1
|
+
import { Schema } from "effect";
|
|
2
2
|
/**
|
|
3
3
|
* An image, a media field of a success: `{ data: Uint8Array, mimeType: string }`, `mimeType` such
|
|
4
4
|
* as `image/png`. A top-level field of a struct success, one, optional, or a required array, the
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Checked, OccurrenceSchema } from "./occurrence.mjs";
|
|
2
|
+
import { Duration, Schema } from "effect";
|
|
2
3
|
import { Any, Occurrence, Received } from "../Event.mjs";
|
|
3
|
-
import { Duration, Effect, Schema, Stream } from "effect";
|
|
4
4
|
/** One poll's answer, as a surface sends it and a client reads it. */
|
|
5
5
|
export interface Page {
|
|
6
6
|
readonly events: ReadonlyArray<Occurrence<Any>>;
|
package/dist/contract/pages.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Checked, Gap, OccurrenceOf } from "./occurrence.mjs";
|
|
2
1
|
import { Duration, Effect, Option, Schema, Stream } from "effect";
|
|
2
|
+
import { Checked, Gap, OccurrenceOf } from "./occurrence.mjs";
|
|
3
3
|
// src/contract/pages.ts
|
|
4
4
|
const pageFields = (occurrence) => ({
|
|
5
5
|
events: Schema.Array(occurrence),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
1
2
|
import { Codec } from "./codec.mjs";
|
|
2
3
|
import { ErasedValue } from "./implementation.mjs";
|
|
3
|
-
import { Data, Effect, Scope, Stream } from "effect";
|
|
4
4
|
export interface Reporting {
|
|
5
5
|
readonly progress: (value: ErasedValue) => Effect.Effect<void>;
|
|
6
6
|
}
|
package/dist/contract/push.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { OccurrenceSchema } from "./occurrence.mjs";
|
|
2
2
|
import { Codec } from "./codec.mjs";
|
|
3
|
+
import { Schema } from "effect";
|
|
3
4
|
import "./errors.mjs";
|
|
4
5
|
import { Any } from "../Event.mjs";
|
|
5
6
|
import "./pages.mjs";
|
|
6
|
-
import { Cause, Effect, Queue, Schema, Stream } from "effect";
|
|
7
7
|
export declare const PushedOf: <E extends Any>(event: E) => Schema.Union<readonly [OccurrenceSchema<E>, Schema.TaggedStruct<"Gap", {
|
|
8
8
|
readonly cursor: Schema.NullOr<Schema.String>;
|
|
9
9
|
}>, Schema.TaggedStruct<"Checked", {
|
package/dist/contract/push.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { Cause, Duration, Effect, Latch, Match, Queue, Schema, Stream } from "effect";
|
|
1
2
|
import { Refusal } from "./errors.mjs";
|
|
2
3
|
import { defaultNextPoll } from "./feed.mjs";
|
|
3
4
|
import { Checked, Gap, OccurrenceOf } from "./occurrence.mjs";
|
|
4
5
|
import { reported } from "./reported.mjs";
|
|
5
|
-
import { Cause, Duration, Effect, Latch, Match, Queue, Schema, Stream } from "effect";
|
|
6
6
|
// src/contract/push.ts
|
|
7
7
|
const Failed = Schema.TaggedStruct("Failed", {});
|
|
8
8
|
const PushedOf = (event) => Schema.Union([
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { Context, Effect, Schema, Scope } from "effect";
|
|
1
2
|
import { SigningSecret } from "./callback.mjs";
|
|
2
3
|
import "./errors.mjs";
|
|
3
4
|
import "../Event.mjs";
|
|
4
5
|
import "./pages.mjs";
|
|
5
|
-
import { Context, Effect, Schema, Scope } from "effect";
|
|
6
6
|
/** A POST a receiver verified, its JSON body: an occurrence, or an envelope. */
|
|
7
7
|
export interface Delivered {
|
|
8
8
|
readonly [key: string]: Schema.Json;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Context, Effect, Option, Schema, Struct } from "effect";
|
|
1
2
|
import { reasonOf, refusalOf } from "./codes.mjs";
|
|
2
3
|
import { Forbidden } from "./errors.mjs";
|
|
3
4
|
import { Gap, untaggedOccurrenceOf } from "./occurrence.mjs";
|
|
4
|
-
import { Context, Effect, Option, Schema, Struct } from "effect";
|
|
5
5
|
// src/contract/receiving.ts
|
|
6
6
|
const watchParameter = "watch";
|
|
7
7
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { Effect, Schema, Stream as Stream$1 } from "effect";
|
|
1
2
|
import { Codec, CodecOf, Fields } from "./codec.mjs";
|
|
2
|
-
import { Data, Effect, Schema, Stream } from "effect";
|
|
3
3
|
declare const TypeId = "~effect-actions/Stream";
|
|
4
4
|
/** The success of an action answering a stream: a schema of `Stream`s, holding its element's. */
|
|
5
|
-
export interface StreamOf<Element extends Codec> extends Schema.declare<Stream.Stream<Element["Type"]>> {
|
|
5
|
+
export interface StreamOf<Element extends Codec> extends Schema.declare<Stream$1.Stream<Element["Type"]>> {
|
|
6
6
|
readonly Rebuild: StreamOf<Element>;
|
|
7
7
|
readonly [TypeId]: typeof TypeId;
|
|
8
8
|
/** The schema of each element. */
|
|
@@ -21,9 +21,9 @@ export interface StreamOf<Element extends Codec> extends Schema.declare<Stream.S
|
|
|
21
21
|
* - An element breaking its schema is the call's defect, as an answer breaking `success` is.
|
|
22
22
|
* - With `progress`, values and elements are each in their order, not against each other: a value may reach `onProgress` after an element yielded after it.
|
|
23
23
|
*/
|
|
24
|
-
declare const Stream
|
|
24
|
+
export declare const Stream: <const E extends Codec | Fields>(element: E) => StreamOf<CodecOf<E>>;
|
|
25
25
|
/** What a handler or a call of an action with success `S` answers: a stream, or one value. */
|
|
26
|
-
export type Answer<S extends Codec, E, R> = [S] extends [never] ? Effect.Effect<never, E, R> : [S] extends [StreamOf<infer Element>] ? Stream.Stream<Element["Type"], E, R> : Effect.Effect<S["Type"], E, R>;
|
|
26
|
+
export type Answer<S extends Codec, E, R> = [S] extends [never] ? Effect.Effect<never, E, R> : [S] extends [StreamOf<infer Element>] ? Stream$1.Stream<Element["Type"], E, R> : Effect.Effect<S["Type"], E, R>;
|
|
27
27
|
/**
|
|
28
28
|
* The success a tool answers for an action with success `S`: an array of the elements of one
|
|
29
29
|
* answering a stream, collected whole, or `S`.
|
|
@@ -31,4 +31,4 @@ export type Answer<S extends Codec, E, R> = [S] extends [never] ? Effect.Effect<
|
|
|
31
31
|
export type ToolSuccess<S extends Codec> = [S] extends [StreamOf<infer Element>] ? Schema.$Array<Element> : S;
|
|
32
32
|
/** What a call of an action with success `S` gives one at a time: an element, or its answer. */
|
|
33
33
|
export type Each<S extends Codec> = [S] extends [StreamOf<infer Element>] ? Element["Type"] : S["Type"];
|
|
34
|
-
export {
|
|
34
|
+
export {};
|
package/dist/contract/stream.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { Data, Predicate, Schema, Stream as Stream$1 } from "effect";
|
|
1
2
|
import { codecOf } from "./codec.mjs";
|
|
2
|
-
import { Data, Predicate, Schema, Stream } from "effect";
|
|
3
3
|
// src/contract/stream.ts
|
|
4
4
|
const TypeId = "~effect-actions/Stream";
|
|
5
|
-
const streams = Schema.declare(Stream.isStream);
|
|
5
|
+
const streams = Schema.declare(Stream$1.isStream);
|
|
6
6
|
/**
|
|
7
7
|
* A success that is a stream of `element`, a schema or struct fields: the handler returns a
|
|
8
8
|
* `Stream` of them, which may fail with the action's errors, and every client's call returns
|
|
@@ -16,7 +16,7 @@ const streams = Schema.declare(Stream.isStream);
|
|
|
16
16
|
* - An element breaking its schema is the call's defect, as an answer breaking `success` is.
|
|
17
17
|
* - With `progress`, values and elements are each in their order, not against each other: a value may reach `onProgress` after an element yielded after it.
|
|
18
18
|
*/
|
|
19
|
-
const Stream
|
|
19
|
+
const Stream = (element) => Schema.make(streams.ast, {
|
|
20
20
|
[TypeId]: TypeId,
|
|
21
21
|
element: codecOf(element)
|
|
22
22
|
});
|
|
@@ -38,4 +38,4 @@ const toolSuccessOf = (success) => {
|
|
|
38
38
|
const element = elementOf(success);
|
|
39
39
|
return element === void 0 ? success : Schema.Array(element);
|
|
40
40
|
};
|
|
41
|
-
export { Answering, Stream
|
|
41
|
+
export { Answering, Stream, answeringOf, elementOf, toolSuccessOf };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Codec } from "./codec.mjs";
|
|
2
|
-
import { Any } from "../Event.mjs";
|
|
3
2
|
import { Schema } from "effect";
|
|
3
|
+
import { Any } from "../Event.mjs";
|
|
4
4
|
export declare const WebhookSubscriptionOf: <E extends Any>(event: E) => Schema.Struct<{
|
|
5
5
|
readonly input: Codec;
|
|
6
6
|
readonly cursor: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.String>, never>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Schema, Struct } from "effect";
|
|
1
2
|
import { CallbackUrl, WebhookSecret } from "./callback.mjs";
|
|
2
3
|
import { CallbackCategory, SubscriptionError, Unsupported } from "../Event.mjs";
|
|
3
4
|
import { SubscriptionOf } from "./push.mjs";
|
|
4
|
-
import { Schema, Struct } from "effect";
|
|
5
5
|
// src/contract/subscribe.ts
|
|
6
6
|
const deliveryUnsupported = (event, mode) => SubscriptionError.of(event, new Unsupported({
|
|
7
7
|
feature: "deliveryMode",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { readOn } from "./push.mjs";
|
|
2
|
-
import { isTransientStatus } from "./status.mjs";
|
|
3
1
|
import { Cause, Duration, Effect, Function, Match, Predicate, Stream } from "effect";
|
|
4
2
|
import { HttpClientError } from "effect/http";
|
|
3
|
+
import { readOn } from "./push.mjs";
|
|
4
|
+
import { isTransientStatus } from "./status.mjs";
|
|
5
5
|
// src/contract/transient.ts
|
|
6
6
|
const answeredStatus = ({ reason }) => Match.value(reason).pipe(Match.tag("StatusCodeError", "DecodeError", ({ response }) => response.status), Match.orElse(Function.constUndefined));
|
|
7
7
|
const isTransientReason = (reason) => Match.value(reason).pipe(Match.tag("TransportError", () => true), Match.tag("DecodeError", ({ response }) => response.status < 300 || isTransientStatus(response.status)), Match.tag("StatusCodeError", ({ response }) => isTransientStatus(response.status)), Match.orElse(() => false));
|
package/dist/contract/wake.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Unavailable } from "./errors.mjs";
|
|
2
1
|
import { Context, Effect } from "effect";
|
|
2
|
+
import { Unavailable } from "./errors.mjs";
|
|
3
3
|
declare const Wake_base: Context.ServiceClass<Wake, "effect-actions/Wake", {
|
|
4
4
|
readonly wakeAt: (at: number) => Effect.Effect<void, Unavailable>;
|
|
5
5
|
readonly until: (at: number) => Effect.Effect<void>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import "effect";
|
|
1
2
|
import { Any, WatchOptions, WebhookDelivery } from "../Event.mjs";
|
|
2
3
|
import "./pages.mjs";
|
|
3
4
|
import { Receiving } from "./receiving.mjs";
|
|
4
5
|
import "./subscribe.mjs";
|
|
5
|
-
import { Effect, Schema, Stream } from "effect";
|
|
6
6
|
/**
|
|
7
7
|
* The arguments of `watch(event, ...)` after the event: its input, which may be left out when
|
|
8
8
|
* `{}` is a valid encoded input, as for an action's call, and the watch's options `O`, whose
|
package/dist/contract/watch.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Cause, Clock, Duration, Effect, Predicate, Queue, Schedule, Schema, Stream } from "effect";
|
|
1
2
|
import { CallbackUrl } from "./callback.mjs";
|
|
2
3
|
import { isUnavailable } from "./errors.mjs";
|
|
3
4
|
import { SubscriptionError } from "../Event.mjs";
|
|
@@ -6,7 +7,6 @@ import { paged } from "./pages.mjs";
|
|
|
6
7
|
import { watchParameter } from "./receiving.mjs";
|
|
7
8
|
import { makeRecent } from "./recent.mjs";
|
|
8
9
|
import { deliveryUnsupported } from "./subscribe.mjs";
|
|
9
|
-
import { Cause, Clock, Duration, Effect, Predicate, Queue, Schedule, Schema, Stream } from "effect";
|
|
10
10
|
// src/contract/watch.ts
|
|
11
11
|
const reconnectDelay = Duration.seconds(1);
|
|
12
12
|
const maxReconnectDelay = Duration.seconds(30);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { Context, Effect } from "effect";
|
|
1
2
|
import { Anyone, Keyed } from "./caller.mjs";
|
|
2
3
|
import { Any } from "../Event.mjs";
|
|
3
4
|
import { Feed } from "./feed.mjs";
|
|
4
5
|
import { AnyWebhookCancellation, AnyWebhookSubscription, Subscribed } from "./subscribe.mjs";
|
|
5
|
-
import { Context, Effect, Option } from "effect";
|
|
6
6
|
/** An event type a surface may offer by webhook: a protected one, its caller an identity. */
|
|
7
7
|
export type Protected = Any & {
|
|
8
8
|
readonly caller: Exclude<Any["caller"], typeof Anyone>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Context, Effect, Option } from "effect";
|
|
1
2
|
import { Anyone } from "./caller.mjs";
|
|
2
3
|
import { acquireFeeds } from "./feed.mjs";
|
|
3
4
|
import { deliveryUnsupported } from "./subscribe.mjs";
|
|
4
|
-
import { Context, Effect, Option } from "effect";
|
|
5
5
|
// src/contract/webhooks.ts
|
|
6
6
|
/**
|
|
7
7
|
* Where a surface's webhook subscriptions are held and delivered from: `Webhook.layer` provides
|
package/dist/entity/wakes.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { reported } from "../contract/reported.mjs";
|
|
2
|
-
import { Wake } from "../contract/wake.mjs";
|
|
3
1
|
import { Clock, DateTime, Deferred, Duration, Effect, Schema, Semaphore } from "effect";
|
|
4
2
|
import { ClusterSchema, DeliverAt } from "effect/cluster";
|
|
5
3
|
import { Rpc } from "effect/rpc";
|
|
4
|
+
import { reported } from "../contract/reported.mjs";
|
|
5
|
+
import { Wake } from "../contract/wake.mjs";
|
|
6
6
|
// src/entity/wakes.ts
|
|
7
7
|
const wakeTag = "effect-actions/wake";
|
|
8
8
|
var WakeAt = class extends Schema.Class("effect-actions/ActionEntity/WakeAt")({ at: Schema.Int }) {
|
|
@@ -19,7 +19,7 @@ const makeWake = (send) => Effect.gen(function* () {
|
|
|
19
19
|
const clock = yield* Clock.Clock;
|
|
20
20
|
const lock = yield* Semaphore.make(1);
|
|
21
21
|
const pending = /* @__PURE__ */ new Set();
|
|
22
|
-
let latest = -
|
|
22
|
+
let latest = -1e400;
|
|
23
23
|
let fired = Deferred.makeUnsafe();
|
|
24
24
|
const stored = (at, covers) => lock.withPermit(Effect.suspend(() => [...pending].some(covers) ? Effect.void : Effect.uninterruptible(Effect.tap(send(new WakeAt({ at })), () => Effect.sync(() => pending.add(at))))));
|
|
25
25
|
const slept = (at) => clock.sleep(Duration.millis(Math.max(at - clock.currentTimeMillisUnsafe(), 0)));
|
package/dist/http/client.d.mts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Schema, Stream } from "effect";
|
|
2
|
+
import { HttpClient, HttpClientError } from "effect/http";
|
|
3
|
+
import { HttpApi, HttpApiClient } from "effect/http-api";
|
|
1
4
|
import { Any, VerifierError } from "../authentication/provider.mjs";
|
|
2
5
|
import { Any as Any$1, Errors } from "../Action.mjs";
|
|
3
6
|
import { Call } from "../contract/call.mjs";
|
|
@@ -9,9 +12,6 @@ import "../contract/receiving.mjs";
|
|
|
9
12
|
import { Answer, StreamOf } from "../contract/stream.mjs";
|
|
10
13
|
import { WatchArgs, WatchRequirement } from "../contract/watch.mjs";
|
|
11
14
|
import { sentOf } from "./events.mjs";
|
|
12
|
-
import { Effect, Schema, Stream } from "effect";
|
|
13
|
-
import { HttpClient, HttpClientError } from "effect/http";
|
|
14
|
-
import { HttpApi, HttpApiClient } from "effect/http-api";
|
|
15
15
|
/**
|
|
16
16
|
* The native `HttpApiClient.make` options except `transformResponse`, which may change a call's
|
|
17
17
|
* success, failure or services the method types cannot follow: `baseUrl`, and `transformClient`,
|
package/dist/http/client.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { Effect, Stream } from "effect";
|
|
2
|
+
import { HttpClient, HttpClientRequest } from "effect/http";
|
|
3
|
+
import { HttpApiClient } from "effect/http-api";
|
|
1
4
|
import { checked, checkedStream, sendingValue, sentInput } from "../contract/call.mjs";
|
|
2
5
|
import { Answering, answeringOf } from "../contract/stream.mjs";
|
|
3
6
|
import { watching } from "../contract/watch.mjs";
|
|
4
7
|
import { readElements, readWithProgress } from "./streamed.mjs";
|
|
5
8
|
import { transportOf } from "./watch.mjs";
|
|
6
|
-
import { Effect, Stream } from "effect";
|
|
7
|
-
import { HttpClient, HttpClientRequest } from "effect/http";
|
|
8
|
-
import { HttpApiClient } from "effect/http-api";
|
|
9
9
|
// src/http/client.ts
|
|
10
10
|
const methodOf = (native, name, what) => {
|
|
11
11
|
const method = native[name];
|
package/dist/http/events.d.mts
CHANGED
|
@@ -2,13 +2,13 @@ import { OccurrenceSchema } from "../contract/occurrence.mjs";
|
|
|
2
2
|
import { Forbidden, Unauthenticated } from "../contract/errors.mjs";
|
|
3
3
|
import "../contract/codec.mjs";
|
|
4
4
|
import "../contract/pages.mjs";
|
|
5
|
+
import { Schema } from "effect";
|
|
6
|
+
import { HttpApiSchema } from "effect/http-api";
|
|
5
7
|
import "../authentication/provider.mjs";
|
|
6
8
|
import "../Action.mjs";
|
|
7
9
|
import { Any } from "../Event.mjs";
|
|
8
10
|
import "../contract/feed.mjs";
|
|
9
11
|
import "../contract/push.mjs";
|
|
10
|
-
import { Effect, Schema, Stream } from "effect";
|
|
11
|
-
import { HttpApiEndpoint, HttpApiSchema } from "effect/http-api";
|
|
12
12
|
export declare const sentOf: <E extends Any>(event: E) => HttpApiSchema.StreamSse<HttpApiSchema.SseEventFromData<Schema.Union<readonly [OccurrenceSchema<E>, Schema.TaggedStruct<"Gap", {
|
|
13
13
|
readonly cursor: Schema.NullOr<Schema.String>;
|
|
14
14
|
}>, Schema.TaggedStruct<"Checked", {
|
package/dist/http/events.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Effect, Function, Schema, Stream } from "effect";
|
|
2
|
+
import { HttpServerRequest } from "effect/http";
|
|
3
|
+
import { HttpApiEndpoint, HttpApiSchema, OpenApi } from "effect/http-api";
|
|
1
4
|
import { principalOf } from "../contract/caller.mjs";
|
|
2
5
|
import { assertDistinctTags } from "../contract/declared.mjs";
|
|
3
6
|
import { Refusal } from "../contract/errors.mjs";
|
|
@@ -7,9 +10,6 @@ import { PushedOf, SubscriptionOf, queuedPush } from "../contract/push.mjs";
|
|
|
7
10
|
import { declared } from "../contract/status.mjs";
|
|
8
11
|
import { Subscribed, WebhookCancellationOf, WebhookSubscriptionOf } from "../contract/subscribe.mjs";
|
|
9
12
|
import { acceptsEventStream } from "./streamed.mjs";
|
|
10
|
-
import { Effect, Function, Schema, Stream } from "effect";
|
|
11
|
-
import { HttpServerRequest } from "effect/http";
|
|
12
|
-
import { HttpApiEndpoint, HttpApiSchema, OpenApi } from "effect/http-api";
|
|
13
13
|
// src/http/events.ts
|
|
14
14
|
const sentOf = (event) => HttpApiSchema.StreamSse({
|
|
15
15
|
data: PushedOf(event),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { InvalidInput } from "../contract/errors.mjs";
|
|
2
1
|
import { Effect } from "effect";
|
|
3
2
|
import { HttpApiMiddleware } from "effect/http-api";
|
|
3
|
+
import { InvalidInput } from "../contract/errors.mjs";
|
|
4
4
|
// src/http/schema-errors.ts
|
|
5
5
|
const responseEncodingKinds = /* @__PURE__ */ new Set(["Body", "ResponseHeaders"]);
|
|
6
6
|
var SchemaErrors = class extends HttpApiMiddleware.Service()("effect-actions/http/SchemaErrors", { error: [InvalidInput] }) {};
|