@rivetkit/effect 2.3.29 → 3.0.0-preview.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/package.json +3 -3
- package/src/Actor.test-d.ts +0 -641
- package/src/Actor.test.ts +0 -209
- package/src/Client.test.ts +0 -206
- package/src/Registry.test-d.ts +0 -126
- package/src/Registry.test.ts +0 -400
- package/src/RivetError.test.ts +0 -199
- package/src/State.test.ts +0 -340
- package/src/internal/logging.test.ts +0 -274
package/src/Actor.test.ts
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { assert, describe, it } from "@effect/vitest";
|
|
2
|
-
import { Actor, State } from "@rivetkit/effect";
|
|
3
|
-
import { Context, Effect, Layer } from "effect";
|
|
4
|
-
import type * as Rivetkit from "rivetkit";
|
|
5
|
-
|
|
6
|
-
class Prefix extends Context.Service<Prefix, { readonly value: string }>()(
|
|
7
|
-
"Actor.test/Prefix",
|
|
8
|
-
) {}
|
|
9
|
-
const PrefixLive = Layer.succeed(Prefix, Prefix.of({ value: "svc" }));
|
|
10
|
-
|
|
11
|
-
describe("Actor.toWakeHandler", () => {
|
|
12
|
-
it("defaults actions to an empty array", () => {
|
|
13
|
-
const actor = Actor.make("NoActions");
|
|
14
|
-
|
|
15
|
-
assert.deepStrictEqual(actor.actions, []);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it.effect("wraps a plain action handler object", () =>
|
|
19
|
-
Effect.gen(function* () {
|
|
20
|
-
const wake = { Ping: () => Effect.succeed("pong") };
|
|
21
|
-
const wakeHandler = Actor.toWakeHandler(wake);
|
|
22
|
-
const actionHandlers = yield* wakeHandler({} as Actor.WakeOptions);
|
|
23
|
-
|
|
24
|
-
assert.strictEqual(actionHandlers, wake);
|
|
25
|
-
}),
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
it.effect("runs an Effect that resolves to action handlers", () =>
|
|
29
|
-
Effect.gen(function* () {
|
|
30
|
-
const wake = Effect.gen(function* () {
|
|
31
|
-
const prefix = yield* Prefix;
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
Ping: () => Effect.succeed(`${prefix.value}:pong`),
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
const wakeHandler = Actor.toWakeHandler(wake);
|
|
38
|
-
const actionHandlers = yield* wakeHandler({} as Actor.WakeOptions);
|
|
39
|
-
|
|
40
|
-
assert.strictEqual(yield* actionHandlers.Ping(), "svc:pong");
|
|
41
|
-
}).pipe(Effect.provide(PrefixLive)),
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
it.effect("calls a wake function with wake options", () =>
|
|
45
|
-
Effect.gen(function* () {
|
|
46
|
-
const rawRivetkitContext = {
|
|
47
|
-
key: ["room", "1"],
|
|
48
|
-
} as Rivetkit.WakeContextOf<Rivetkit.AnyActorDefinition>;
|
|
49
|
-
const wakeOptions: Actor.WakeOptions = {
|
|
50
|
-
rawRivetkitContext,
|
|
51
|
-
};
|
|
52
|
-
const wake = (wakeOptions: Actor.WakeOptions) => ({
|
|
53
|
-
GetKey: () =>
|
|
54
|
-
Effect.succeed(
|
|
55
|
-
wakeOptions.rawRivetkitContext.key.join("/"),
|
|
56
|
-
),
|
|
57
|
-
});
|
|
58
|
-
const wakeHandler = Actor.toWakeHandler(wake);
|
|
59
|
-
const actionHandlers = yield* wakeHandler(wakeOptions);
|
|
60
|
-
|
|
61
|
-
assert.strictEqual(
|
|
62
|
-
wakeOptions.rawRivetkitContext,
|
|
63
|
-
rawRivetkitContext,
|
|
64
|
-
);
|
|
65
|
-
assert.strictEqual(yield* actionHandlers.GetKey(), "room/1");
|
|
66
|
-
}),
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
it.effect("passes actor state through wake options", () =>
|
|
70
|
-
Effect.gen(function* () {
|
|
71
|
-
const cell = { value: { count: 1 } };
|
|
72
|
-
const state = yield* State.make(
|
|
73
|
-
() => Effect.sync(() => cell.value),
|
|
74
|
-
(value: { readonly count: number }) =>
|
|
75
|
-
Effect.sync(() => {
|
|
76
|
-
cell.value = value;
|
|
77
|
-
}),
|
|
78
|
-
);
|
|
79
|
-
type StatefulWakeOptions = Actor.WakeOptions & {
|
|
80
|
-
readonly state: State.State<
|
|
81
|
-
{ readonly count: number },
|
|
82
|
-
never,
|
|
83
|
-
never
|
|
84
|
-
>;
|
|
85
|
-
};
|
|
86
|
-
const wakeOptions: StatefulWakeOptions = {
|
|
87
|
-
rawRivetkitContext:
|
|
88
|
-
{} as Rivetkit.WakeContextOf<Rivetkit.AnyActorDefinition>,
|
|
89
|
-
state,
|
|
90
|
-
};
|
|
91
|
-
const wake = (wakeOptions: StatefulWakeOptions) => ({
|
|
92
|
-
GetCount: () => State.get(wakeOptions.state),
|
|
93
|
-
SetCount: (count: number) =>
|
|
94
|
-
State.set(wakeOptions.state, { count }),
|
|
95
|
-
});
|
|
96
|
-
const wakeHandler = Actor.toWakeHandler(wake);
|
|
97
|
-
const actionHandlers = yield* wakeHandler(wakeOptions);
|
|
98
|
-
|
|
99
|
-
assert.deepStrictEqual(yield* actionHandlers.GetCount(), {
|
|
100
|
-
count: 1,
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
yield* actionHandlers.SetCount(7);
|
|
104
|
-
assert.deepStrictEqual(cell.value, { count: 7 });
|
|
105
|
-
}),
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
it.effect("flattens a wake function returning an Effect", () =>
|
|
109
|
-
Effect.gen(function* () {
|
|
110
|
-
const wakeOptions: Actor.WakeOptions = {
|
|
111
|
-
rawRivetkitContext: {
|
|
112
|
-
key: ["room", "2"],
|
|
113
|
-
} as Rivetkit.WakeContextOf<Rivetkit.AnyActorDefinition>,
|
|
114
|
-
};
|
|
115
|
-
const wake = (options: Actor.WakeOptions) =>
|
|
116
|
-
Effect.gen(function* () {
|
|
117
|
-
const prefix = yield* Prefix;
|
|
118
|
-
|
|
119
|
-
return {
|
|
120
|
-
GetKey: () =>
|
|
121
|
-
Effect.succeed(
|
|
122
|
-
`${prefix.value}:${options.rawRivetkitContext.key.join("/")}`,
|
|
123
|
-
),
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
const wakeHandler = Actor.toWakeHandler(wake);
|
|
127
|
-
const actionHandlers = yield* wakeHandler(wakeOptions);
|
|
128
|
-
|
|
129
|
-
assert.strictEqual(yield* actionHandlers.GetKey(), "svc:room/2");
|
|
130
|
-
}).pipe(Effect.provide(PrefixLive)),
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
it.effect("runs an Effect that resolves to a wake function", () =>
|
|
134
|
-
Effect.gen(function* () {
|
|
135
|
-
const wakeOptions: Actor.WakeOptions = {
|
|
136
|
-
rawRivetkitContext: {
|
|
137
|
-
actorId: "actor-1",
|
|
138
|
-
} as Rivetkit.WakeContextOf<Rivetkit.AnyActorDefinition>,
|
|
139
|
-
};
|
|
140
|
-
const wake = Effect.gen(function* () {
|
|
141
|
-
const prefix = yield* Prefix;
|
|
142
|
-
|
|
143
|
-
return (options: Actor.WakeOptions) =>
|
|
144
|
-
Effect.succeed({
|
|
145
|
-
GetActorId: () =>
|
|
146
|
-
Effect.succeed(
|
|
147
|
-
`${prefix.value}:${options.rawRivetkitContext.actorId}`,
|
|
148
|
-
),
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
const wakeHandler = Actor.toWakeHandler(wake);
|
|
152
|
-
const actionHandlers = yield* wakeHandler(wakeOptions);
|
|
153
|
-
|
|
154
|
-
assert.strictEqual(
|
|
155
|
-
yield* actionHandlers.GetActorId(),
|
|
156
|
-
"svc:actor-1",
|
|
157
|
-
);
|
|
158
|
-
}).pipe(Effect.provide(PrefixLive)),
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
it.effect("accepts an Effect.fn wake function", () =>
|
|
162
|
-
Effect.gen(function* () {
|
|
163
|
-
const wakeOptions: Actor.WakeOptions = {
|
|
164
|
-
rawRivetkitContext: {
|
|
165
|
-
key: ["effect", "fn"],
|
|
166
|
-
} as Rivetkit.WakeContextOf<Rivetkit.AnyActorDefinition>,
|
|
167
|
-
};
|
|
168
|
-
const wake = Effect.fn("wake")(function* (
|
|
169
|
-
options: Actor.WakeOptions,
|
|
170
|
-
) {
|
|
171
|
-
const prefix = yield* Prefix;
|
|
172
|
-
|
|
173
|
-
return {
|
|
174
|
-
GetKey: () =>
|
|
175
|
-
Effect.succeed(
|
|
176
|
-
`${prefix.value}:${options.rawRivetkitContext.key.join("/")}`,
|
|
177
|
-
),
|
|
178
|
-
};
|
|
179
|
-
});
|
|
180
|
-
const wakeHandler = Actor.toWakeHandler(wake);
|
|
181
|
-
const actionHandlers = yield* wakeHandler(wakeOptions);
|
|
182
|
-
|
|
183
|
-
assert.strictEqual(yield* actionHandlers.GetKey(), "svc:effect/fn");
|
|
184
|
-
}).pipe(Effect.provide(PrefixLive)),
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
it.effect(
|
|
188
|
-
"defers wake functions until the returned handler is invoked",
|
|
189
|
-
() =>
|
|
190
|
-
Effect.gen(function* () {
|
|
191
|
-
let calls = 0;
|
|
192
|
-
const wake = () => {
|
|
193
|
-
calls++;
|
|
194
|
-
return { Count: () => Effect.succeed(calls) };
|
|
195
|
-
};
|
|
196
|
-
const wakeHandler = Actor.toWakeHandler(wake);
|
|
197
|
-
|
|
198
|
-
assert.strictEqual(calls, 0);
|
|
199
|
-
|
|
200
|
-
const first = yield* wakeHandler({} as Actor.WakeOptions);
|
|
201
|
-
assert.strictEqual(calls, 1);
|
|
202
|
-
assert.strictEqual(yield* first.Count(), 1);
|
|
203
|
-
|
|
204
|
-
const second = yield* wakeHandler({} as Actor.WakeOptions);
|
|
205
|
-
assert.strictEqual(calls, 2);
|
|
206
|
-
assert.strictEqual(yield* second.Count(), 2);
|
|
207
|
-
}),
|
|
208
|
-
);
|
|
209
|
-
});
|
package/src/Client.test.ts
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { assert, describe, it } from "@effect/vitest";
|
|
2
|
-
import { Client, RivetError, RivetLogger } from "@rivetkit/effect";
|
|
3
|
-
import { Effect, Layer, Schema } from "effect";
|
|
4
|
-
import * as RivetkitErrors from "rivetkit/errors";
|
|
5
|
-
import * as RivetkitLog from "rivetkit/log";
|
|
6
|
-
import * as ActionErrorEnvelope from "./internal/ActionErrorEnvelope";
|
|
7
|
-
|
|
8
|
-
function makeTestLogger(
|
|
9
|
-
entries?: Array<{
|
|
10
|
-
readonly level: string;
|
|
11
|
-
readonly fields: Record<string, unknown>;
|
|
12
|
-
readonly msg: string | undefined;
|
|
13
|
-
}>,
|
|
14
|
-
): RivetkitLog.Logger {
|
|
15
|
-
const logger: Record<string, unknown> = {
|
|
16
|
-
level: "debug",
|
|
17
|
-
child: () => logger,
|
|
18
|
-
};
|
|
19
|
-
for (const level of ["trace", "debug", "info", "warn", "error", "fatal"]) {
|
|
20
|
-
logger[level] = (
|
|
21
|
-
fields: Record<string, unknown>,
|
|
22
|
-
msg?: string,
|
|
23
|
-
): void => {
|
|
24
|
-
entries?.push({ level, fields, msg });
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return logger as unknown as RivetkitLog.Logger;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
describe("Client", () => {
|
|
32
|
-
it.effect("configures the underlying RivetKit client logger", () =>
|
|
33
|
-
Effect.scoped(
|
|
34
|
-
Effect.gen(function* () {
|
|
35
|
-
const baseLogger = makeTestLogger();
|
|
36
|
-
|
|
37
|
-
yield* Effect.addFinalizer(() =>
|
|
38
|
-
Effect.sync(() =>
|
|
39
|
-
RivetkitLog.configureDefaultLogger("silent"),
|
|
40
|
-
),
|
|
41
|
-
);
|
|
42
|
-
yield* Client.make({
|
|
43
|
-
endpoint: "http://127.0.0.1:6420",
|
|
44
|
-
}).pipe(Effect.provide(RivetLogger.layerFromPino(baseLogger)));
|
|
45
|
-
|
|
46
|
-
assert.strictEqual(RivetkitLog.getBaseLogger(), baseLogger);
|
|
47
|
-
}),
|
|
48
|
-
),
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
it.effect("installs the RivetKit Effect logger for client programs", () =>
|
|
52
|
-
Effect.scoped(
|
|
53
|
-
Effect.gen(function* () {
|
|
54
|
-
const entries: Array<{
|
|
55
|
-
readonly level: string;
|
|
56
|
-
readonly fields: Record<string, unknown>;
|
|
57
|
-
readonly msg: string | undefined;
|
|
58
|
-
}> = [];
|
|
59
|
-
const baseLogger = makeTestLogger(entries);
|
|
60
|
-
|
|
61
|
-
yield* Effect.addFinalizer(() =>
|
|
62
|
-
Effect.sync(() =>
|
|
63
|
-
RivetkitLog.configureDefaultLogger("silent"),
|
|
64
|
-
),
|
|
65
|
-
);
|
|
66
|
-
yield* Effect.gen(function* () {
|
|
67
|
-
yield* Client.Client;
|
|
68
|
-
yield* Effect.logInfo("client effect log", {
|
|
69
|
-
clientId: "test-client",
|
|
70
|
-
});
|
|
71
|
-
}).pipe(
|
|
72
|
-
Effect.provide(
|
|
73
|
-
Client.layer({
|
|
74
|
-
endpoint: "http://127.0.0.1:6420",
|
|
75
|
-
}).pipe(
|
|
76
|
-
Layer.provideMerge(
|
|
77
|
-
RivetLogger.layerFromPino(baseLogger),
|
|
78
|
-
),
|
|
79
|
-
),
|
|
80
|
-
),
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const entry = entries[0];
|
|
84
|
-
assert.ok(entry !== undefined);
|
|
85
|
-
assert.strictEqual(entry.level, "info");
|
|
86
|
-
assert.strictEqual(entry.msg, "client effect log");
|
|
87
|
-
assert.strictEqual(entry.fields.clientId, "test-client");
|
|
88
|
-
assert.strictEqual(typeof entry.fields.fiberId, "string");
|
|
89
|
-
assert.ok(
|
|
90
|
-
entries.some(
|
|
91
|
-
(entry) =>
|
|
92
|
-
entry.level === "debug" &&
|
|
93
|
-
(entry.fields as { msg?: unknown }).msg ===
|
|
94
|
-
"disposing client",
|
|
95
|
-
),
|
|
96
|
-
);
|
|
97
|
-
}),
|
|
98
|
-
),
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe("makeRivetkitActionFailureClassifier", () => {
|
|
103
|
-
const ExpectedError = Schema.Struct({
|
|
104
|
-
_tag: Schema.tag("CounterOverflow"),
|
|
105
|
-
message: Schema.String,
|
|
106
|
-
limit: Schema.Number,
|
|
107
|
-
});
|
|
108
|
-
const classifyRivetkitActionFailure =
|
|
109
|
-
Client.makeRivetkitActionFailureClassifier(ExpectedError);
|
|
110
|
-
|
|
111
|
-
it.effect("preserves non-Rivet failures as UnknownError", () =>
|
|
112
|
-
Effect.gen(function* () {
|
|
113
|
-
const cause = new Error("plain failure");
|
|
114
|
-
const error = yield* classifyRivetkitActionFailure(cause);
|
|
115
|
-
|
|
116
|
-
assert.instanceOf(error, RivetError.RivetError);
|
|
117
|
-
assert.instanceOf(error.reason, RivetError.UnknownError);
|
|
118
|
-
assert.strictEqual(error.reason.message, "plain failure");
|
|
119
|
-
assert.strictEqual(error.reason.cause, cause);
|
|
120
|
-
}),
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
it.effect("preserves structured non-action Rivet errors", () =>
|
|
124
|
-
Effect.gen(function* () {
|
|
125
|
-
const cause = new RivetkitErrors.RivetError(
|
|
126
|
-
"actor",
|
|
127
|
-
"not_found",
|
|
128
|
-
"actor not found",
|
|
129
|
-
);
|
|
130
|
-
const error = yield* classifyRivetkitActionFailure(cause);
|
|
131
|
-
|
|
132
|
-
assert.instanceOf(error, RivetError.RivetError);
|
|
133
|
-
assert.instanceOf(error.reason, RivetError.ActorNotFound);
|
|
134
|
-
assert.strictEqual(error.reason.cause.group, "actor");
|
|
135
|
-
assert.strictEqual(error.reason.cause.code, "not_found");
|
|
136
|
-
assert.strictEqual(error.reason.cause.message, "actor not found");
|
|
137
|
-
}),
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
it.effect(
|
|
141
|
-
"decodes action-error metadata into the declared error type",
|
|
142
|
-
() =>
|
|
143
|
-
Effect.gen(function* () {
|
|
144
|
-
const cause = new RivetkitErrors.RivetError(
|
|
145
|
-
"user",
|
|
146
|
-
"CounterOverflow",
|
|
147
|
-
"counter overflow",
|
|
148
|
-
{
|
|
149
|
-
public: true,
|
|
150
|
-
metadata: {
|
|
151
|
-
_tag: ActionErrorEnvelope.tag,
|
|
152
|
-
version: ActionErrorEnvelope.schemaVersion,
|
|
153
|
-
error: {
|
|
154
|
-
_tag: "CounterOverflow",
|
|
155
|
-
message: "counter overflow",
|
|
156
|
-
limit: 10,
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
|
-
);
|
|
161
|
-
const error = yield* classifyRivetkitActionFailure(cause);
|
|
162
|
-
|
|
163
|
-
assert.deepStrictEqual(error, {
|
|
164
|
-
_tag: "CounterOverflow",
|
|
165
|
-
message: "counter overflow",
|
|
166
|
-
limit: 10,
|
|
167
|
-
});
|
|
168
|
-
}),
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
it.effect(
|
|
172
|
-
"wraps invalid typed action-error payloads in ActionErrorDecodeFailed",
|
|
173
|
-
() =>
|
|
174
|
-
Effect.gen(function* () {
|
|
175
|
-
const cause = new RivetkitErrors.RivetError(
|
|
176
|
-
"user",
|
|
177
|
-
"CounterOverflow",
|
|
178
|
-
"counter overflow",
|
|
179
|
-
{
|
|
180
|
-
metadata: {
|
|
181
|
-
_tag: ActionErrorEnvelope.tag,
|
|
182
|
-
version: ActionErrorEnvelope.schemaVersion,
|
|
183
|
-
error: {
|
|
184
|
-
_tag: "CounterOverflow",
|
|
185
|
-
message: "counter overflow",
|
|
186
|
-
limit: "10",
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
const error = yield* classifyRivetkitActionFailure(cause);
|
|
193
|
-
|
|
194
|
-
assert.instanceOf(error, RivetError.RivetError);
|
|
195
|
-
assert.instanceOf(
|
|
196
|
-
error.reason,
|
|
197
|
-
RivetError.ActionErrorDecodeFailed,
|
|
198
|
-
);
|
|
199
|
-
assert.strictEqual(error.reason.rivetError.group, "user");
|
|
200
|
-
assert.strictEqual(
|
|
201
|
-
error.reason.rivetError.code,
|
|
202
|
-
"CounterOverflow",
|
|
203
|
-
);
|
|
204
|
-
}),
|
|
205
|
-
);
|
|
206
|
-
});
|
package/src/Registry.test-d.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { Action, Actor, Registry } from "@rivetkit/effect";
|
|
2
|
-
import { type Context, Effect, Layer, type Scope } from "effect";
|
|
3
|
-
import type {
|
|
4
|
-
HttpServerError,
|
|
5
|
-
HttpServerRequest,
|
|
6
|
-
HttpServerResponse,
|
|
7
|
-
} from "effect/http";
|
|
8
|
-
import { describe, expectTypeOf, test } from "vitest";
|
|
9
|
-
|
|
10
|
-
const TestActor = Actor.make("TestActor", {
|
|
11
|
-
actions: [Action.make("Test")],
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const TestActorLive = TestActor.toLayer({
|
|
15
|
-
Test: () => Effect.void,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
const RegistryLive = TestActorLive.pipe(
|
|
19
|
-
Layer.provideMerge(Registry.layer({ endpoint: "http://127.0.0.1:6420" })),
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
describe("Registry.layer", () => {
|
|
23
|
-
test("accepts connection options", () => {
|
|
24
|
-
expectTypeOf(Registry.layer).toBeCallableWith({
|
|
25
|
-
endpoint: "http://127.0.0.1:6420",
|
|
26
|
-
token: "dev-token",
|
|
27
|
-
namespace: "default",
|
|
28
|
-
noWelcome: true,
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test("does not accept serverless options", () => {
|
|
33
|
-
Registry.layer({
|
|
34
|
-
// @ts-expect-error: serverless routing belongs to toWebHandler and toHttpEffect options.
|
|
35
|
-
serverless: {
|
|
36
|
-
basePath: "/",
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe("Registry.serve", () => {
|
|
43
|
-
test("accepts an actor registration layer", () => {
|
|
44
|
-
expectTypeOf(Registry.serve).toBeCallableWith(TestActorLive);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test("returns a server layer that requires Registry", () => {
|
|
48
|
-
expectTypeOf(Registry.serve(TestActorLive)).toEqualTypeOf<
|
|
49
|
-
Layer.Layer<never, never, Registry.Registry>
|
|
50
|
-
>();
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe("Registry.toWebHandler", () => {
|
|
55
|
-
test("accepts a registry layer", () => {
|
|
56
|
-
expectTypeOf(Registry.toWebHandler).toBeCallableWith(RegistryLive);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test("rejects actor registration layers that do not provide Registry", () => {
|
|
60
|
-
// @ts-expect-error: actor registration layers require Registry but do not provide it.
|
|
61
|
-
// @effect-diagnostics effect/missingLayerContext:off effect/floatingEffect:off
|
|
62
|
-
Registry.toWebHandler(TestActorLive);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test("accepts serverless routing options", () => {
|
|
66
|
-
expectTypeOf(Registry.toWebHandler).toBeCallableWith(RegistryLive, {
|
|
67
|
-
basePath: "/",
|
|
68
|
-
maxStartPayloadBytes: 1024,
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test("rejects registry options", () => {
|
|
73
|
-
Registry.toWebHandler(RegistryLive, {
|
|
74
|
-
// @ts-expect-error: noWelcome belongs to Registry.layer options.
|
|
75
|
-
noWelcome: true,
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test("returns a Fetch-compatible handler", () => {
|
|
80
|
-
const handler = Registry.toWebHandler(RegistryLive);
|
|
81
|
-
|
|
82
|
-
expectTypeOf(handler.handler).toEqualTypeOf<
|
|
83
|
-
(
|
|
84
|
-
request: Request,
|
|
85
|
-
context?: Context.Context<never> | undefined,
|
|
86
|
-
) => Promise<Response>
|
|
87
|
-
>();
|
|
88
|
-
expectTypeOf(handler.dispose).toEqualTypeOf<() => Promise<void>>();
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe("Registry.toHttpEffect", () => {
|
|
93
|
-
test("accepts serverless routing options", () => {
|
|
94
|
-
expectTypeOf(Registry.toHttpEffect).toBeCallableWith(RegistryLive, {
|
|
95
|
-
basePath: "/",
|
|
96
|
-
maxStartPayloadBytes: 1024,
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test("rejects registry options", () => {
|
|
101
|
-
Registry.toHttpEffect(RegistryLive, {
|
|
102
|
-
// @ts-expect-error: noWelcome belongs to Registry.layer options.
|
|
103
|
-
noWelcome: true,
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test("rejects actor registration layers that do not provide Registry", () => {
|
|
108
|
-
// @ts-expect-error: actor registration layers require Registry but do not provide it.
|
|
109
|
-
// @effect-diagnostics effect/missingLayerContext:off effect/floatingEffect:off
|
|
110
|
-
Registry.toHttpEffect(TestActorLive);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test("returns a scoped Effect HTTP handler", () => {
|
|
114
|
-
expectTypeOf(Registry.toHttpEffect(RegistryLive)).toEqualTypeOf<
|
|
115
|
-
Effect.Effect<
|
|
116
|
-
Effect.Effect<
|
|
117
|
-
HttpServerResponse.HttpServerResponse,
|
|
118
|
-
HttpServerError.HttpServerError,
|
|
119
|
-
HttpServerRequest.HttpServerRequest
|
|
120
|
-
>,
|
|
121
|
-
never,
|
|
122
|
-
Scope.Scope
|
|
123
|
-
>
|
|
124
|
-
>();
|
|
125
|
-
});
|
|
126
|
-
});
|