@nwire/messages 0.8.0 → 0.9.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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Validated<T> brand — semantics test. The brand exists to let trust
3
+ * boundaries (HTTP parseAndValidate, queue worker consume) signal
4
+ * "already-parsed" so downstream code (forge runtime.dispatch) can
5
+ * skip its own redundant zod parse.
6
+ *
7
+ * The brand must survive identity but NOT structural copies — a
8
+ * spread, JSON.stringify, or transport boundary should drop the
9
+ * claim so untrusted data never inherits a stale "validated" tag.
10
+ */
11
+ export {};
12
+ //# sourceMappingURL=validated.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validated.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/validated.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Validated<T> brand — semantics test. The brand exists to let trust
3
+ * boundaries (HTTP parseAndValidate, queue worker consume) signal
4
+ * "already-parsed" so downstream code (forge runtime.dispatch) can
5
+ * skip its own redundant zod parse.
6
+ *
7
+ * The brand must survive identity but NOT structural copies — a
8
+ * spread, JSON.stringify, or transport boundary should drop the
9
+ * claim so untrusted data never inherits a stale "validated" tag.
10
+ */
11
+ import { describe, it, expect } from "vitest";
12
+ import { markValidated, isValidated } from "../validated.js";
13
+ describe("Validated<T> brand", () => {
14
+ it("marks objects and detects the mark", () => {
15
+ const obj = markValidated({ name: "alex" });
16
+ expect(isValidated(obj)).toBe(true);
17
+ });
18
+ it("isValidated returns false for unbranded objects", () => {
19
+ expect(isValidated({ name: "alex" })).toBe(false);
20
+ expect(isValidated([])).toBe(false);
21
+ });
22
+ it("isValidated returns false for null and primitives", () => {
23
+ expect(isValidated(null)).toBe(false);
24
+ expect(isValidated(undefined)).toBe(false);
25
+ expect(isValidated(42)).toBe(false);
26
+ expect(isValidated("hello")).toBe(false);
27
+ expect(isValidated(true)).toBe(false);
28
+ });
29
+ it("brand survives identity through dispatch passing", () => {
30
+ // Simulates HTTP -> runtime.dispatch where the SAME object reference
31
+ // flows down. The runtime's `isValidated(input)` returns true.
32
+ const input = markValidated({ id: "a" });
33
+ function pretendDispatch(x) {
34
+ return isValidated(x);
35
+ }
36
+ expect(pretendDispatch(input)).toBe(true);
37
+ });
38
+ it("brand is dropped by structural copy — spread loses the claim", () => {
39
+ const input = markValidated({ id: "a" });
40
+ const copy = { ...input };
41
+ expect(isValidated(input)).toBe(true);
42
+ expect(isValidated(copy)).toBe(false);
43
+ });
44
+ it("brand is dropped by JSON roundtrip — wire transport invalidates the claim", () => {
45
+ const input = markValidated({ id: "a" });
46
+ const wire = JSON.parse(JSON.stringify(input));
47
+ expect(isValidated(input)).toBe(true);
48
+ expect(isValidated(wire)).toBe(false);
49
+ });
50
+ it("brand is non-enumerable — JSON.stringify ignores it", () => {
51
+ const input = markValidated({ id: "a" });
52
+ expect(JSON.stringify(input)).toBe('{"id":"a"}');
53
+ });
54
+ it("markValidated on a primitive is a no-op (returns the primitive)", () => {
55
+ // Primitives can't carry brands; markValidated returns them unchanged
56
+ // and the runtime falls back to parse — which is the right behavior
57
+ // because a primitive can't have been validated against an object schema.
58
+ expect(markValidated(42)).toBe(42);
59
+ expect(markValidated(null)).toBe(null);
60
+ expect(isValidated(markValidated(42))).toBe(false);
61
+ });
62
+ });
63
+ //# sourceMappingURL=validated.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validated.test.js","sourceRoot":"","sources":["../../src/__tests__/validated.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE1D,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC5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CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACrD,IAAI,CAAC,CAAC;YAAE,SAAS;QACjB,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;QACnB,mEAAmE;QACnE,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;YAAE,SAAS;QACvC,OAAO;YACL,IAAI;YACJ,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC;YACnB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC;SACtB,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nwire/messages",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "Nwire — typed command and event contracts. defineCommand, defineEvent with public/internal visibility. Zod-validated; shareable across the backend, frontends, BFFs.",
5
5
  "keywords": [
6
6
  "commands",