@effected/jsonl 0.15.1 → 0.15.3

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/Journal.js CHANGED
@@ -42,12 +42,11 @@ var Journal = class {
42
42
  */
43
43
  static Service() {
44
44
  return (id, options) => {
45
- const make = (config) => Effect.map(makeEngine(id, options.events, config), (engine) => engine.journal);
46
45
  const config = Effect.isEffect(options.config) ? options.config : Effect.succeed(options.config);
47
46
  class JournalService extends Context.Service()(id) {
48
47
  static events = options.events;
49
- static make = make;
50
- static layer = Layer.effect(JournalService, Effect.flatMap(config, make));
48
+ static make = (config) => Effect.map(makeEngine(id, options.events, config), (engine) => engine.journal);
49
+ static layer = Layer.effect(JournalService, Effect.flatMap(config, (resolved) => JournalService.make(resolved)));
51
50
  }
52
51
  return JournalService;
53
52
  };
package/JsonlError.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { causeMessage } from "./internal/causeMessage.js";
1
2
  import { LineSlice } from "./LineSlice.js";
2
3
  import { Option, Schema } from "effect";
3
4
 
@@ -169,7 +170,7 @@ var UnserializableData = class extends Schema.TaggedError()("UnserializableData"
169
170
  cause: Schema.Defect()
170
171
  }) {
171
172
  get message() {
172
- const detail = this.cause instanceof Error ? this.cause.message : "value is not JSON-serializable";
173
+ const detail = causeMessage(this.cause) ?? "value is not JSON-serializable";
173
174
  return `cannot serialize payload for event ${JSON.stringify(this.event)}: ${detail}`;
174
175
  }
175
176
  };
@@ -0,0 +1,39 @@
1
+ import { Predicate } from "effect";
2
+
3
+ // src/internal/causeMessage.ts
4
+ /** How many nodes of a cause chain the walk reads before stopping, so a cyclic chain cannot spin. */
5
+ const CAUSE_DEPTH = 8;
6
+ /** The message a single node carries: a thrown string, or a non-empty string `message` property. */
7
+ const messageAt = (node) => {
8
+ const text = Predicate.isString(node) ? node : Predicate.hasProperty(node, "message") && Predicate.isString(node.message) ? node.message : void 0;
9
+ return text === void 0 || text.trim() === "" ? void 0 : text;
10
+ };
11
+ /**
12
+ * Every distinct non-empty message a preserved cause chain carries, nearest
13
+ * first and joined with `: `, or `undefined` when nothing along it has one.
14
+ *
15
+ * A `Schema.Defect()` field holds whatever was thrown, so the read is guarded
16
+ * rather than assumed: `Predicate.hasProperty` + `Predicate.isString` accepts
17
+ * an `Error`, a cross-realm `Error` that fails `instanceof`, a plain
18
+ * `{ message }` object and a thrown string alike. An empty or whitespace-only
19
+ * message counts as none. The walk follows `cause` links because a wrapper's
20
+ * text is often the generic summary and the driver's text underneath is the
21
+ * actionable detail, yet a wrapper that composes its own context must not
22
+ * lose it either; so nothing is dropped, and a deeper text the nearer one
23
+ * already contains is not repeated. The walk is bounded, so a cycle terminates.
24
+ */
25
+ const causeMessage = (cause) => {
26
+ let message;
27
+ let node = cause;
28
+ for (let depth = 0; depth < CAUSE_DEPTH && node !== void 0 && node !== null; depth++) {
29
+ const text = messageAt(node);
30
+ if (text !== void 0) {
31
+ if (message === void 0 || text.includes(message)) message = text;
32
+ else if (!message.includes(text)) message = `${message}: ${text}`;
33
+ }
34
+ node = Predicate.hasProperty(node, "cause") ? node.cause : void 0;
35
+ }
36
+ return message;
37
+ };
38
+
39
+ export { causeMessage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/jsonl",
3
- "version": "0.15.1",
3
+ "version": "0.15.3",
4
4
  "private": false,
5
5
  "description": "Append-only, schema-validated JSONL journals as a definable Effect service.",
6
6
  "keywords": [
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.59.1"
8
+ "packageVersion": "7.59.4"
9
9
  }
10
10
  ]
11
11
  }