@rivetkit/effect 0.0.0-sqlite-query-metrics-v2.f5d3605 → 0.0.0-sqlite-query-metrics-v3.1dff84f
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/RivetError.d.ts +19 -3
- package/dist/RivetError.d.ts.map +1 -1
- package/dist/RivetError.js +34 -0
- package/dist/RivetError.js.map +1 -1
- package/dist/internal/ActionDispatcher.d.ts +1 -2
- package/dist/internal/ActionDispatcher.d.ts.map +1 -1
- package/dist/internal/ActionDispatcher.js +7 -1
- package/dist/internal/ActionDispatcher.js.map +1 -1
- package/package.json +4 -4
- package/src/RivetError.ts +40 -0
- package/src/internal/ActionDispatcher.ts +7 -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/State.test.ts
DELETED
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
import { assert, describe, it } from "@effect/vitest";
|
|
2
|
-
import { State } from "@rivetkit/effect";
|
|
3
|
-
import { Effect, Exit, PubSub, Stream } from "effect";
|
|
4
|
-
|
|
5
|
-
// Helper: build a State backed by a plain mutable cell, with
|
|
6
|
-
// Effect-typed read/write closures. Mirrors how Registry wires
|
|
7
|
-
// `decodeUnknownEffect` / `encodeUnknownEffect` over `c.state`.
|
|
8
|
-
const makeCellState = <A>(initial: A) => {
|
|
9
|
-
const cell = { value: initial };
|
|
10
|
-
return State.make<A, never, never>(
|
|
11
|
-
() => Effect.sync(() => cell.value),
|
|
12
|
-
(v) =>
|
|
13
|
-
Effect.sync(() => {
|
|
14
|
-
cell.value = v;
|
|
15
|
-
}),
|
|
16
|
-
).pipe(Effect.map((s) => ({ s, cell })));
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
describe("State", () => {
|
|
20
|
-
it.effect("get reflects the backing store", () =>
|
|
21
|
-
Effect.gen(function* () {
|
|
22
|
-
const { s, cell } = yield* makeCellState(42);
|
|
23
|
-
assert.strictEqual(yield* State.get(s), 42);
|
|
24
|
-
|
|
25
|
-
cell.value = 100;
|
|
26
|
-
assert.strictEqual(yield* State.get(s), 100);
|
|
27
|
-
}),
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
it.effect("set writes through to the backing store", () =>
|
|
31
|
-
Effect.gen(function* () {
|
|
32
|
-
const { s, cell } = yield* makeCellState(0);
|
|
33
|
-
yield* State.set(s, 7);
|
|
34
|
-
assert.strictEqual(cell.value, 7);
|
|
35
|
-
assert.strictEqual(yield* State.get(s), 7);
|
|
36
|
-
}),
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
it.effect(
|
|
40
|
-
"getAndSet returns the previous value and commits the new value",
|
|
41
|
-
() =>
|
|
42
|
-
Effect.gen(function* () {
|
|
43
|
-
const { s, cell } = yield* makeCellState(10);
|
|
44
|
-
const previous = yield* State.getAndSet(s, 15);
|
|
45
|
-
assert.strictEqual(previous, 10);
|
|
46
|
-
assert.strictEqual(cell.value, 15);
|
|
47
|
-
}),
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
it.effect("setAndGet returns the committed value", () =>
|
|
51
|
-
Effect.gen(function* () {
|
|
52
|
-
const { s, cell } = yield* makeCellState(10);
|
|
53
|
-
const next = yield* State.setAndGet(s, 15);
|
|
54
|
-
assert.strictEqual(next, 15);
|
|
55
|
-
assert.strictEqual(cell.value, 15);
|
|
56
|
-
}),
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
it.effect("update applies f over read/write", () =>
|
|
60
|
-
Effect.gen(function* () {
|
|
61
|
-
const { s, cell } = yield* makeCellState(10);
|
|
62
|
-
yield* State.update(s, (n) => n + 5);
|
|
63
|
-
assert.strictEqual(cell.value, 15);
|
|
64
|
-
}),
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
it.effect("updateEffect applies an Effectful f over read/write", () =>
|
|
68
|
-
Effect.gen(function* () {
|
|
69
|
-
const { s, cell } = yield* makeCellState(10);
|
|
70
|
-
yield* State.updateEffect(s, (n) => Effect.succeed(n + 5));
|
|
71
|
-
assert.strictEqual(cell.value, 15);
|
|
72
|
-
}),
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
it.effect(
|
|
76
|
-
"getAndUpdate returns the previous value and commits the new value",
|
|
77
|
-
() =>
|
|
78
|
-
Effect.gen(function* () {
|
|
79
|
-
const { s, cell } = yield* makeCellState(10);
|
|
80
|
-
const previous = yield* State.getAndUpdate(s, (n) => n + 5);
|
|
81
|
-
assert.strictEqual(previous, 10);
|
|
82
|
-
assert.strictEqual(cell.value, 15);
|
|
83
|
-
}),
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
it.effect(
|
|
87
|
-
"getAndUpdateEffect returns the previous value and commits the new value",
|
|
88
|
-
() =>
|
|
89
|
-
Effect.gen(function* () {
|
|
90
|
-
const { s, cell } = yield* makeCellState(10);
|
|
91
|
-
const previous = yield* State.getAndUpdateEffect(s, (n) =>
|
|
92
|
-
Effect.succeed(n + 5),
|
|
93
|
-
);
|
|
94
|
-
assert.strictEqual(previous, 10);
|
|
95
|
-
assert.strictEqual(cell.value, 15);
|
|
96
|
-
}),
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
it.effect("updateAndGet returns the new value and commits it", () =>
|
|
100
|
-
Effect.gen(function* () {
|
|
101
|
-
const { s, cell } = yield* makeCellState(10);
|
|
102
|
-
const next = yield* State.updateAndGet(s, (n) => n + 5);
|
|
103
|
-
assert.strictEqual(next, 15);
|
|
104
|
-
assert.strictEqual(cell.value, 15);
|
|
105
|
-
}),
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
it.effect("updateAndGetEffect returns the new value and commits it", () =>
|
|
109
|
-
Effect.gen(function* () {
|
|
110
|
-
const { s, cell } = yield* makeCellState(10);
|
|
111
|
-
const next = yield* State.updateAndGetEffect(s, (n) =>
|
|
112
|
-
Effect.succeed(n + 5),
|
|
113
|
-
);
|
|
114
|
-
assert.strictEqual(next, 15);
|
|
115
|
-
assert.strictEqual(cell.value, 15);
|
|
116
|
-
}),
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
it.effect("modify returns B and commits the new value", () =>
|
|
120
|
-
Effect.gen(function* () {
|
|
121
|
-
const { s, cell } = yield* makeCellState("a");
|
|
122
|
-
const b = yield* State.modify(
|
|
123
|
-
s,
|
|
124
|
-
(str) => [str.length, `${str}b`] as const,
|
|
125
|
-
);
|
|
126
|
-
assert.strictEqual(b, 1);
|
|
127
|
-
assert.strictEqual(cell.value, "ab");
|
|
128
|
-
}),
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
it.effect("modifyEffect returns B and commits the new value", () =>
|
|
132
|
-
Effect.gen(function* () {
|
|
133
|
-
const { s, cell } = yield* makeCellState("a");
|
|
134
|
-
const b = yield* State.modifyEffect(s, (str) =>
|
|
135
|
-
Effect.succeed([str.length, `${str}b`] as const),
|
|
136
|
-
);
|
|
137
|
-
assert.strictEqual(b, 1);
|
|
138
|
-
assert.strictEqual(cell.value, "ab");
|
|
139
|
-
}),
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
it.effect(
|
|
143
|
-
"update is atomic across concurrent fibers (no lost updates)",
|
|
144
|
-
() =>
|
|
145
|
-
Effect.gen(function* () {
|
|
146
|
-
const { s, cell } = yield* makeCellState(0);
|
|
147
|
-
yield* Effect.all(
|
|
148
|
-
Array.from({ length: 100 }, () =>
|
|
149
|
-
State.update(s, (n) => n + 1),
|
|
150
|
-
),
|
|
151
|
-
{ concurrency: "unbounded" },
|
|
152
|
-
);
|
|
153
|
-
assert.strictEqual(cell.value, 100);
|
|
154
|
-
}),
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
it.effect("changes replays the most recent published value", () =>
|
|
158
|
-
Effect.gen(function* () {
|
|
159
|
-
const { s } = yield* makeCellState(0);
|
|
160
|
-
const initial = yield* State.changes(s).pipe(
|
|
161
|
-
Stream.take(1),
|
|
162
|
-
Stream.runCollect,
|
|
163
|
-
);
|
|
164
|
-
assert.deepStrictEqual(initial, [0]);
|
|
165
|
-
|
|
166
|
-
yield* s[State.RuntimeTypeId].publishEffect(Effect.succeed(7));
|
|
167
|
-
const later = yield* State.changes(s).pipe(
|
|
168
|
-
Stream.take(1),
|
|
169
|
-
Stream.runCollect,
|
|
170
|
-
);
|
|
171
|
-
assert.deepStrictEqual(later, [7]);
|
|
172
|
-
}),
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
it.effect("publish pushes values to live subscribers", () =>
|
|
176
|
-
Effect.gen(function* () {
|
|
177
|
-
const { s } = yield* makeCellState(0);
|
|
178
|
-
yield* Effect.scoped(
|
|
179
|
-
Effect.gen(function* () {
|
|
180
|
-
const sub = yield* PubSub.subscribe(
|
|
181
|
-
s[State.RuntimeTypeId].pubsub,
|
|
182
|
-
);
|
|
183
|
-
assert.strictEqual(yield* PubSub.take(sub), 0);
|
|
184
|
-
|
|
185
|
-
yield* s[State.RuntimeTypeId].publishEffect(
|
|
186
|
-
Effect.succeed(1),
|
|
187
|
-
);
|
|
188
|
-
yield* s[State.RuntimeTypeId].publishEffect(
|
|
189
|
-
Effect.succeed(2),
|
|
190
|
-
);
|
|
191
|
-
assert.strictEqual(yield* PubSub.take(sub), 1);
|
|
192
|
-
assert.strictEqual(yield* PubSub.take(sub), 2);
|
|
193
|
-
}),
|
|
194
|
-
);
|
|
195
|
-
}),
|
|
196
|
-
);
|
|
197
|
-
|
|
198
|
-
it.effect("shuts down the backing pubsub when its scope closes", () =>
|
|
199
|
-
Effect.gen(function* () {
|
|
200
|
-
const pubsub = yield* Effect.scoped(
|
|
201
|
-
Effect.gen(function* () {
|
|
202
|
-
const { s } = yield* makeCellState(0);
|
|
203
|
-
return s[State.RuntimeTypeId].pubsub;
|
|
204
|
-
}),
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
assert.isTrue(yield* PubSub.isShutdown(pubsub));
|
|
208
|
-
}),
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
it.effect("set does NOT auto-publish — the runtime does", () =>
|
|
212
|
-
Effect.gen(function* () {
|
|
213
|
-
const { s } = yield* makeCellState(0);
|
|
214
|
-
yield* State.set(s, 99);
|
|
215
|
-
// replay should still hold the initial 0, not 99
|
|
216
|
-
const latest = yield* State.changes(s).pipe(
|
|
217
|
-
Stream.take(1),
|
|
218
|
-
Stream.runCollect,
|
|
219
|
-
);
|
|
220
|
-
assert.deepStrictEqual(latest, [0]);
|
|
221
|
-
}),
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
it.effect("isState discriminates", () =>
|
|
225
|
-
Effect.gen(function* () {
|
|
226
|
-
const { s } = yield* makeCellState(0);
|
|
227
|
-
assert.isTrue(State.isState(s));
|
|
228
|
-
assert.isFalse(State.isState({}));
|
|
229
|
-
assert.isFalse(State.isState(null));
|
|
230
|
-
assert.isFalse(State.isState(42));
|
|
231
|
-
}),
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
it.effect("supports .pipe()", () =>
|
|
235
|
-
Effect.gen(function* () {
|
|
236
|
-
const { s } = yield* makeCellState(0);
|
|
237
|
-
yield* s.pipe(State.set(5));
|
|
238
|
-
assert.strictEqual(yield* State.get(s), 5);
|
|
239
|
-
|
|
240
|
-
yield* s.pipe(State.update((n) => n * 2));
|
|
241
|
-
assert.strictEqual(yield* State.get(s), 10);
|
|
242
|
-
|
|
243
|
-
yield* s.pipe(State.updateEffect((n) => Effect.succeed(n + 1)));
|
|
244
|
-
assert.strictEqual(yield* State.get(s), 11);
|
|
245
|
-
}),
|
|
246
|
-
);
|
|
247
|
-
|
|
248
|
-
it.effect("supports instance methods", () =>
|
|
249
|
-
Effect.gen(function* () {
|
|
250
|
-
const { s, cell } = yield* makeCellState(0);
|
|
251
|
-
assert.strictEqual(yield* s.get, 0);
|
|
252
|
-
|
|
253
|
-
yield* s.set(5);
|
|
254
|
-
assert.strictEqual(cell.value, 5);
|
|
255
|
-
|
|
256
|
-
const beforeSet = yield* s.getAndSet(6);
|
|
257
|
-
assert.strictEqual(beforeSet, 5);
|
|
258
|
-
assert.strictEqual(cell.value, 6);
|
|
259
|
-
|
|
260
|
-
const afterSet = yield* s.setAndGet(7);
|
|
261
|
-
assert.strictEqual(afterSet, 7);
|
|
262
|
-
assert.strictEqual(cell.value, 7);
|
|
263
|
-
|
|
264
|
-
yield* s.update((n) => n * 2);
|
|
265
|
-
assert.strictEqual(yield* s.get, 14);
|
|
266
|
-
|
|
267
|
-
yield* s.updateEffect((n) => Effect.succeed(n + 1));
|
|
268
|
-
assert.strictEqual(yield* s.get, 15);
|
|
269
|
-
|
|
270
|
-
const previousUpdate = yield* s.getAndUpdate((n) => n + 1);
|
|
271
|
-
assert.strictEqual(previousUpdate, 15);
|
|
272
|
-
assert.strictEqual(yield* s.get, 16);
|
|
273
|
-
|
|
274
|
-
const previousEffectUpdate = yield* s.getAndUpdateEffect((n) =>
|
|
275
|
-
Effect.succeed(n + 1),
|
|
276
|
-
);
|
|
277
|
-
assert.strictEqual(previousEffectUpdate, 16);
|
|
278
|
-
assert.strictEqual(yield* s.get, 17);
|
|
279
|
-
|
|
280
|
-
const next = yield* s.updateAndGet((n) => n + 1);
|
|
281
|
-
assert.strictEqual(next, 18);
|
|
282
|
-
|
|
283
|
-
const effectNext = yield* s.updateAndGetEffect((n) =>
|
|
284
|
-
Effect.succeed(n + 1),
|
|
285
|
-
);
|
|
286
|
-
assert.strictEqual(effectNext, 19);
|
|
287
|
-
|
|
288
|
-
const previous = yield* s.modify((n) => [n, n + 1] as const);
|
|
289
|
-
assert.strictEqual(previous, 19);
|
|
290
|
-
assert.strictEqual(yield* s.get, 20);
|
|
291
|
-
|
|
292
|
-
const effectPrevious = yield* s.modifyEffect((n) =>
|
|
293
|
-
Effect.succeed([n, n + 1] as const),
|
|
294
|
-
);
|
|
295
|
-
assert.strictEqual(effectPrevious, 20);
|
|
296
|
-
assert.strictEqual(yield* s.get, 21);
|
|
297
|
-
}),
|
|
298
|
-
);
|
|
299
|
-
|
|
300
|
-
it.effect("read failure propagates through get", () =>
|
|
301
|
-
Effect.gen(function* () {
|
|
302
|
-
const reads = { count: 0 };
|
|
303
|
-
// Construction reads once to seed the pubsub; subsequent reads
|
|
304
|
-
// fail. Mirrors a schema mismatch on persisted state.
|
|
305
|
-
const s = yield* State.make<number, "boom", never>(
|
|
306
|
-
() =>
|
|
307
|
-
Effect.suspend(() => {
|
|
308
|
-
reads.count++;
|
|
309
|
-
if (reads.count === 1) return Effect.succeed(0);
|
|
310
|
-
return Effect.fail("boom" as const);
|
|
311
|
-
}),
|
|
312
|
-
() => Effect.void,
|
|
313
|
-
);
|
|
314
|
-
const exit = yield* Effect.exit(State.get(s));
|
|
315
|
-
assert.isTrue(Exit.isFailure(exit));
|
|
316
|
-
}),
|
|
317
|
-
);
|
|
318
|
-
|
|
319
|
-
it.effect("write failure propagates through set", () =>
|
|
320
|
-
Effect.gen(function* () {
|
|
321
|
-
const s = yield* State.make<number, "boom", never>(
|
|
322
|
-
() => Effect.succeed(0),
|
|
323
|
-
() => Effect.fail("boom" as const),
|
|
324
|
-
);
|
|
325
|
-
const exit = yield* Effect.exit(State.set(s, 1));
|
|
326
|
-
assert.isTrue(Exit.isFailure(exit));
|
|
327
|
-
}),
|
|
328
|
-
);
|
|
329
|
-
|
|
330
|
-
it.effect("Effectful update failure does not write", () =>
|
|
331
|
-
Effect.gen(function* () {
|
|
332
|
-
const { s, cell } = yield* makeCellState(0);
|
|
333
|
-
const exit = yield* Effect.exit(
|
|
334
|
-
State.updateEffect(s, () => Effect.fail("boom" as const)),
|
|
335
|
-
);
|
|
336
|
-
assert.isTrue(Exit.isFailure(exit));
|
|
337
|
-
assert.strictEqual(cell.value, 0);
|
|
338
|
-
}),
|
|
339
|
-
);
|
|
340
|
-
});
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
import { assert, describe, it } from "@effect/vitest";
|
|
2
|
-
import { ConfigProvider, Effect, Logger, References } from "effect";
|
|
3
|
-
import * as RivetkitLog from "rivetkit/log";
|
|
4
|
-
import * as Logging from "./logging.ts";
|
|
5
|
-
|
|
6
|
-
type LogEntry = {
|
|
7
|
-
readonly level: string;
|
|
8
|
-
readonly fields: Record<string, unknown>;
|
|
9
|
-
readonly msg: string | undefined;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
function makeTestLogger(entries: Array<LogEntry>): RivetkitLog.Logger {
|
|
13
|
-
const logger: Record<string, unknown> = {};
|
|
14
|
-
for (const level of ["trace", "debug", "info", "warn", "error", "fatal"]) {
|
|
15
|
-
logger[level] = (
|
|
16
|
-
fields: Record<string, unknown>,
|
|
17
|
-
msg?: string,
|
|
18
|
-
): void => {
|
|
19
|
-
entries.push({ level, fields, msg });
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return logger as unknown as RivetkitLog.Logger;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
describe("internal/logging", () => {
|
|
27
|
-
it("serializes actor keys like the RivetKit actor runtime logger", () => {
|
|
28
|
-
assert.strictEqual(Logging.serializeActorKey([]), "/");
|
|
29
|
-
assert.strictEqual(Logging.serializeActorKey(["room", "1"]), "room/1");
|
|
30
|
-
assert.strictEqual(Logging.serializeActorKey(["room/1"]), "room\\/1");
|
|
31
|
-
assert.strictEqual(Logging.serializeActorKey([""]), "\\0");
|
|
32
|
-
assert.strictEqual(Logging.serializeActorKey(["a\\b"]), "a\\\\b");
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("builds actor log annotations with serialized keys", () => {
|
|
36
|
-
assert.deepStrictEqual(
|
|
37
|
-
Logging.makeActorLogAnnotations({
|
|
38
|
-
name: "ChatRoom",
|
|
39
|
-
key: ["room/1"],
|
|
40
|
-
actorId: "actor-1",
|
|
41
|
-
}),
|
|
42
|
-
{
|
|
43
|
-
actor: "ChatRoom",
|
|
44
|
-
key: "room\\/1",
|
|
45
|
-
actorId: "actor-1",
|
|
46
|
-
},
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it.effect("writes Effect logs through the RivetKit base logger", () =>
|
|
51
|
-
Effect.gen(function* () {
|
|
52
|
-
const entries: Array<LogEntry> = [];
|
|
53
|
-
const baseLogger = makeTestLogger(entries);
|
|
54
|
-
|
|
55
|
-
yield* Effect.logInfo("room awake", { roomId: "abc" }).pipe(
|
|
56
|
-
Effect.annotateLogs({
|
|
57
|
-
actor: "ChatRoom",
|
|
58
|
-
key: "room-1",
|
|
59
|
-
actorId: "actor-1",
|
|
60
|
-
}),
|
|
61
|
-
Effect.provide(Logger.layer([Logging.makeLogger(baseLogger)])),
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
const entry = entries[0];
|
|
65
|
-
assert.ok(entry !== undefined);
|
|
66
|
-
assert.strictEqual(entry.level, "info");
|
|
67
|
-
assert.strictEqual(entry.msg, "room awake");
|
|
68
|
-
assert.deepStrictEqual(entry.fields, {
|
|
69
|
-
roomId: "abc",
|
|
70
|
-
actor: "ChatRoom",
|
|
71
|
-
key: "room-1",
|
|
72
|
-
actorId: "actor-1",
|
|
73
|
-
fiberId: entry.fields.fiberId,
|
|
74
|
-
});
|
|
75
|
-
assert.strictEqual(typeof entry.fields.fiberId, "string");
|
|
76
|
-
}),
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
it.effect("preserves Error log messages as structured error fields", () =>
|
|
80
|
-
Effect.gen(function* () {
|
|
81
|
-
const entries: Array<LogEntry> = [];
|
|
82
|
-
const baseLogger = makeTestLogger(entries);
|
|
83
|
-
const error = new Error("room failed to wake");
|
|
84
|
-
|
|
85
|
-
yield* Effect.logError(error).pipe(
|
|
86
|
-
Effect.provide(Logger.layer([Logging.makeLogger(baseLogger)])),
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
const entry = entries[0];
|
|
90
|
-
assert.ok(entry !== undefined);
|
|
91
|
-
assert.strictEqual(entry.level, "error");
|
|
92
|
-
assert.strictEqual(entry.fields.error, error);
|
|
93
|
-
assert.strictEqual(entry.msg, error.message);
|
|
94
|
-
}),
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
it.effect("preserves Error log messages with additional fields", () =>
|
|
98
|
-
Effect.gen(function* () {
|
|
99
|
-
const entries: Array<LogEntry> = [];
|
|
100
|
-
const baseLogger = makeTestLogger(entries);
|
|
101
|
-
const error = new Error("action dispatch failed");
|
|
102
|
-
|
|
103
|
-
yield* Effect.logError(error, {
|
|
104
|
-
actorId: "actor-1",
|
|
105
|
-
action: "SendMessage",
|
|
106
|
-
}).pipe(
|
|
107
|
-
Effect.provide(Logger.layer([Logging.makeLogger(baseLogger)])),
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
const entry = entries[0];
|
|
111
|
-
assert.ok(entry !== undefined);
|
|
112
|
-
assert.strictEqual(entry.level, "error");
|
|
113
|
-
assert.strictEqual(entry.fields.error, error);
|
|
114
|
-
assert.strictEqual(entry.fields.actorId, "actor-1");
|
|
115
|
-
assert.strictEqual(entry.fields.action, "SendMessage");
|
|
116
|
-
assert.strictEqual(entry.msg, error.message);
|
|
117
|
-
}),
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
it.effect("accepts RIVET_LOG_LEVEL values", () =>
|
|
121
|
-
Effect.gen(function* () {
|
|
122
|
-
const baseLogger = yield* Logging.makeDefaultBaseLogger;
|
|
123
|
-
|
|
124
|
-
assert.strictEqual(baseLogger.level, "silent");
|
|
125
|
-
}).pipe(
|
|
126
|
-
Effect.provideService(
|
|
127
|
-
ConfigProvider.ConfigProvider,
|
|
128
|
-
ConfigProvider.fromEnv({
|
|
129
|
-
env: {
|
|
130
|
-
RIVET_LOG_LEVEL: "silent",
|
|
131
|
-
},
|
|
132
|
-
}),
|
|
133
|
-
),
|
|
134
|
-
),
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
it.effect("accepts uppercase RIVET_LOG_LEVEL values", () =>
|
|
138
|
-
Effect.gen(function* () {
|
|
139
|
-
const baseLogger = yield* Logging.makeDefaultBaseLogger;
|
|
140
|
-
|
|
141
|
-
assert.strictEqual(baseLogger.level, "debug");
|
|
142
|
-
}).pipe(
|
|
143
|
-
Effect.provideService(
|
|
144
|
-
ConfigProvider.ConfigProvider,
|
|
145
|
-
ConfigProvider.fromEnv({
|
|
146
|
-
env: {
|
|
147
|
-
RIVET_LOG_LEVEL: "DEBUG",
|
|
148
|
-
},
|
|
149
|
-
}),
|
|
150
|
-
),
|
|
151
|
-
),
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
it.effect("ignores Effect-only RIVET_LOG_LEVEL values", () =>
|
|
155
|
-
Effect.gen(function* () {
|
|
156
|
-
const baseLogger = yield* Logging.makeDefaultBaseLogger;
|
|
157
|
-
|
|
158
|
-
assert.strictEqual(baseLogger.level, "info");
|
|
159
|
-
}).pipe(
|
|
160
|
-
Effect.provideService(References.MinimumLogLevel, "Info"),
|
|
161
|
-
Effect.provideService(
|
|
162
|
-
ConfigProvider.ConfigProvider,
|
|
163
|
-
ConfigProvider.fromEnv({
|
|
164
|
-
env: {
|
|
165
|
-
RIVET_LOG_LEVEL: "None",
|
|
166
|
-
},
|
|
167
|
-
}),
|
|
168
|
-
),
|
|
169
|
-
),
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
it.effect("falls back to References.MinimumLogLevel without env", () =>
|
|
173
|
-
Effect.gen(function* () {
|
|
174
|
-
const baseLogger = yield* Logging.makeDefaultBaseLogger;
|
|
175
|
-
|
|
176
|
-
assert.strictEqual(baseLogger.level, "debug");
|
|
177
|
-
}).pipe(
|
|
178
|
-
Effect.provideService(References.MinimumLogLevel, "Debug"),
|
|
179
|
-
Effect.provideService(
|
|
180
|
-
ConfigProvider.ConfigProvider,
|
|
181
|
-
ConfigProvider.fromEnv({
|
|
182
|
-
env: {},
|
|
183
|
-
}),
|
|
184
|
-
),
|
|
185
|
-
),
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
it.effect("RIVET_LOG_LEVEL overrides References.MinimumLogLevel", () =>
|
|
189
|
-
Effect.gen(function* () {
|
|
190
|
-
const baseLogger = yield* Logging.makeDefaultBaseLogger;
|
|
191
|
-
|
|
192
|
-
assert.strictEqual(baseLogger.level, "silent");
|
|
193
|
-
}).pipe(
|
|
194
|
-
Effect.provideService(References.MinimumLogLevel, "Debug"),
|
|
195
|
-
Effect.provideService(
|
|
196
|
-
ConfigProvider.ConfigProvider,
|
|
197
|
-
ConfigProvider.fromEnv({
|
|
198
|
-
env: {
|
|
199
|
-
RIVET_LOG_LEVEL: "silent",
|
|
200
|
-
},
|
|
201
|
-
}),
|
|
202
|
-
),
|
|
203
|
-
),
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
it.effect(
|
|
207
|
-
"uses References.CurrentLogLevel for plain Effect.log calls",
|
|
208
|
-
() =>
|
|
209
|
-
Effect.gen(function* () {
|
|
210
|
-
const entries: Array<LogEntry> = [];
|
|
211
|
-
const baseLogger = makeTestLogger(entries);
|
|
212
|
-
|
|
213
|
-
yield* Effect.log("plain log").pipe(
|
|
214
|
-
Effect.provideService(References.CurrentLogLevel, "Debug"),
|
|
215
|
-
Effect.provideService(References.MinimumLogLevel, "Debug"),
|
|
216
|
-
Effect.provide(
|
|
217
|
-
Logger.layer([Logging.makeLogger(baseLogger)]),
|
|
218
|
-
),
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
const entry = entries[0];
|
|
222
|
-
assert.ok(entry !== undefined);
|
|
223
|
-
assert.strictEqual(entry.level, "debug");
|
|
224
|
-
assert.strictEqual(entry.msg, "plain log");
|
|
225
|
-
assert.deepStrictEqual(entry.fields, {
|
|
226
|
-
fiberId: entry.fields.fiberId,
|
|
227
|
-
});
|
|
228
|
-
assert.strictEqual(typeof entry.fields.fiberId, "string");
|
|
229
|
-
}),
|
|
230
|
-
);
|
|
231
|
-
|
|
232
|
-
it.effect(
|
|
233
|
-
"does not call a Pino method for the None current log level",
|
|
234
|
-
() =>
|
|
235
|
-
Effect.gen(function* () {
|
|
236
|
-
const entries: Array<LogEntry> = [];
|
|
237
|
-
const baseLogger = makeTestLogger(entries);
|
|
238
|
-
|
|
239
|
-
yield* Effect.log("hidden log").pipe(
|
|
240
|
-
Effect.provideService(References.CurrentLogLevel, "None"),
|
|
241
|
-
Effect.provideService(References.MinimumLogLevel, "All"),
|
|
242
|
-
Effect.provide(
|
|
243
|
-
Logger.layer([Logging.makeLogger(baseLogger)]),
|
|
244
|
-
),
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
assert.deepStrictEqual(entries, []);
|
|
248
|
-
}),
|
|
249
|
-
);
|
|
250
|
-
|
|
251
|
-
it.effect(
|
|
252
|
-
"emits References.CurrentLogSpans as structured span durations",
|
|
253
|
-
() =>
|
|
254
|
-
Effect.gen(function* () {
|
|
255
|
-
const entries: Array<LogEntry> = [];
|
|
256
|
-
const baseLogger = makeTestLogger(entries);
|
|
257
|
-
|
|
258
|
-
yield* Effect.logInfo("checkout complete").pipe(
|
|
259
|
-
Effect.withLogSpan("checkout"),
|
|
260
|
-
Effect.provide(
|
|
261
|
-
Logger.layer([Logging.makeLogger(baseLogger)]),
|
|
262
|
-
),
|
|
263
|
-
);
|
|
264
|
-
|
|
265
|
-
assert.strictEqual(entries.length, 1);
|
|
266
|
-
assert.strictEqual(entries[0]?.level, "info");
|
|
267
|
-
assert.strictEqual(entries[0]?.msg, "checkout complete");
|
|
268
|
-
const spans = entries[0]?.fields.spans as
|
|
269
|
-
| Record<string, unknown>
|
|
270
|
-
| undefined;
|
|
271
|
-
assert.strictEqual(typeof spans?.checkout, "number");
|
|
272
|
-
}),
|
|
273
|
-
);
|
|
274
|
-
});
|