@silverprotocol/core 0.6.4 → 0.6.5

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/ingest.d.ts CHANGED
@@ -6,10 +6,18 @@
6
6
  * DISTINCT from producer conformance (`AgEvent.parse`), which rejects anything
7
7
  * outside the schema.
8
8
  *
9
- * Field-passthrough scope: unknown TOP-LEVEL fields are preserved verbatim.
10
- * Nested structured sub-objects are returned in validated form; the opaque
11
- * channels (`_meta`, `providerMetadata`, provider payload fields) are typed as
12
- * opaque bags and therefore pass through in full by construction.
9
+ * Field-passthrough scope: unknown fields are preserved verbatim at EVERY
10
+ * depth (SPEC.md:27 does not limit "untouched" to the top level). After a
11
+ * successful `AgEvent.safeParse`, the returned event is an own-property deep
12
+ * copy of the RAW input, not zod's validated output, which strips unknown
13
+ * nested keys. The copy equals the validated value only because no schema in
14
+ * agjson.ts rewrites values (no transform/default/coerce/catch/pipe/
15
+ * preprocess); ingest.test.ts guards that.
16
+ *
17
+ * One exception, at every depth: a key named `__proto__` is dropped, never
18
+ * copied. A consumer must not let wire data select the prototype of any object
19
+ * it materialises (JSON.parse keeps such a key as an own property, and
20
+ * assigning it would run Object.prototype's setter).
13
21
  */
14
22
  import { AgEvent, type JsonValue } from "./agjson.js";
15
23
  export declare function ingestAgEvent(v: JsonValue): AgEvent | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"ingest.d.ts","sourceRoot":"","sources":["../src/ingest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAEtD,wBAAgB,aAAa,CAAC,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,SAAS,CAmB/D;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,OAAO,EAAE,CAOzD"}
1
+ {"version":3,"file":"ingest.d.ts","sourceRoot":"","sources":["../src/ingest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAoBtD,wBAAgB,aAAa,CAAC,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,SAAS,CAK/D;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,OAAO,EAAE,CAOzD"}
package/dist/ingest.js CHANGED
@@ -6,34 +6,47 @@
6
6
  * DISTINCT from producer conformance (`AgEvent.parse`), which rejects anything
7
7
  * outside the schema.
8
8
  *
9
- * Field-passthrough scope: unknown TOP-LEVEL fields are preserved verbatim.
10
- * Nested structured sub-objects are returned in validated form; the opaque
11
- * channels (`_meta`, `providerMetadata`, provider payload fields) are typed as
12
- * opaque bags and therefore pass through in full by construction.
9
+ * Field-passthrough scope: unknown fields are preserved verbatim at EVERY
10
+ * depth (SPEC.md:27 does not limit "untouched" to the top level). After a
11
+ * successful `AgEvent.safeParse`, the returned event is an own-property deep
12
+ * copy of the RAW input, not zod's validated output, which strips unknown
13
+ * nested keys. The copy equals the validated value only because no schema in
14
+ * agjson.ts rewrites values (no transform/default/coerce/catch/pipe/
15
+ * preprocess); ingest.test.ts guards that.
16
+ *
17
+ * One exception, at every depth: a key named `__proto__` is dropped, never
18
+ * copied. A consumer must not let wire data select the prototype of any object
19
+ * it materialises (JSON.parse keeps such a key as an own property, and
20
+ * assigning it would run Object.prototype's setter).
13
21
  */
14
22
  import { AgEvent } from "./agjson.js";
23
+ /** Own-property deep copy of a JSON value, dropping `__proto__` at every depth. */
24
+ function copyJson(v) {
25
+ if (Array.isArray(v))
26
+ return v.map(copyJson);
27
+ if (v === null || typeof v !== "object")
28
+ return v;
29
+ const out = {};
30
+ for (const k of Object.keys(v)) {
31
+ if (k === "__proto__")
32
+ continue;
33
+ // DEFINED, never assigned (belt and braces with the skip above).
34
+ Object.defineProperty(out, k, {
35
+ value: copyJson(v[k]),
36
+ enumerable: true,
37
+ writable: true,
38
+ configurable: true,
39
+ });
40
+ }
41
+ return out;
42
+ }
15
43
  export function ingestAgEvent(v) {
16
44
  if (v === null || typeof v !== "object" || Array.isArray(v))
17
45
  return undefined;
18
46
  const r = AgEvent.safeParse(v);
19
47
  if (!r.success)
20
48
  return undefined;
21
- // Preserve unknown top-level fields: validated keys win, unknown keys ride
22
- // along, in the same key order a plain merge would give. Keys are DEFINED,
23
- // never assigned: assigning a wire key named `__proto__` runs
24
- // Object.prototype's setter, which would let wire data choose the returned
25
- // event's prototype, and then fields it never carried (and the schema never
26
- // validated) would be inherited (SPEC.md:759, :27). That one key is skipped
27
- // outright, matching zod, which keeps it at no nested depth either.
28
- const out = {};
29
- for (const src of [v, r.data]) {
30
- for (const k of Object.keys(src)) {
31
- if (k === "__proto__")
32
- continue;
33
- Object.defineProperty(out, k, { value: src[k], enumerable: true, writable: true, configurable: true });
34
- }
35
- }
36
- return out;
49
+ return copyJson(v);
37
50
  }
38
51
  export function ingestAgEvents(vs) {
39
52
  const out = [];
@@ -1 +1 @@
1
- {"version":3,"file":"ingest.js","sourceRoot":"","sources":["../src/ingest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,OAAO,EAAkB,MAAM,aAAa,CAAC;AAEtD,MAAM,UAAU,aAAa,CAAC,CAAY;IACxC,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IAC9E,MAAM,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC/B,IAAI,CAAC,CAAC,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IACjC,2EAA2E;IAC3E,2EAA2E;IAC3E,8DAA8D;IAC9D,2EAA2E;IAC3E,4EAA4E;IAC5E,4EAA4E;IAC5E,oEAAoE;IACpE,MAAM,GAAG,GAA6B,E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AC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/B,IAAI,CAAC,KAAK,WAAW;YAAE,SAAS;QAChC,iEAAiE;QACjE,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC,EAAE;YAC5B,KAAK,EAAE,QAAQ,CAAE,CAAgC,CAAC,CAAC,CAAE,CAAC;YACtD,UAAU,EAAE,IAAI;YAChB,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,CAAY;IACxC,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IAC9E,MAAM,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC/B,IAAI,CAAC,CAAC,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IACjC,OAAO,QAAQ,CAAC,CAAC,CAAuB,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,EAAe;IAC5C,MAAM,GAAG,GAAc,EAAE,CAAC;IAC1B,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QACnB,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,CAAC,KAAK,SAAS;YAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@silverprotocol/core",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "description": "AgJSON core — the typed schema (AgInput / AgEvent / AgMessage), the Normalizer interface, and the normative reduce().",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/ingest.ts CHANGED
@@ -6,32 +6,44 @@
6
6
  * DISTINCT from producer conformance (`AgEvent.parse`), which rejects anything
7
7
  * outside the schema.
8
8
  *
9
- * Field-passthrough scope: unknown TOP-LEVEL fields are preserved verbatim.
10
- * Nested structured sub-objects are returned in validated form; the opaque
11
- * channels (`_meta`, `providerMetadata`, provider payload fields) are typed as
12
- * opaque bags and therefore pass through in full by construction.
9
+ * Field-passthrough scope: unknown fields are preserved verbatim at EVERY
10
+ * depth (SPEC.md:27 does not limit "untouched" to the top level). After a
11
+ * successful `AgEvent.safeParse`, the returned event is an own-property deep
12
+ * copy of the RAW input, not zod's validated output, which strips unknown
13
+ * nested keys. The copy equals the validated value only because no schema in
14
+ * agjson.ts rewrites values (no transform/default/coerce/catch/pipe/
15
+ * preprocess); ingest.test.ts guards that.
16
+ *
17
+ * One exception, at every depth: a key named `__proto__` is dropped, never
18
+ * copied. A consumer must not let wire data select the prototype of any object
19
+ * it materialises (JSON.parse keeps such a key as an own property, and
20
+ * assigning it would run Object.prototype's setter).
13
21
  */
14
22
  import { AgEvent, type JsonValue } from "./agjson.js";
15
23
 
24
+ /** Own-property deep copy of a JSON value, dropping `__proto__` at every depth. */
25
+ function copyJson(v: JsonValue): JsonValue {
26
+ if (Array.isArray(v)) return v.map(copyJson);
27
+ if (v === null || typeof v !== "object") return v;
28
+ const out: { [k: string]: JsonValue } = {};
29
+ for (const k of Object.keys(v)) {
30
+ if (k === "__proto__") continue;
31
+ // DEFINED, never assigned (belt and braces with the skip above).
32
+ Object.defineProperty(out, k, {
33
+ value: copyJson((v as { [k: string]: JsonValue })[k]!),
34
+ enumerable: true,
35
+ writable: true,
36
+ configurable: true,
37
+ });
38
+ }
39
+ return out;
40
+ }
41
+
16
42
  export function ingestAgEvent(v: JsonValue): AgEvent | undefined {
17
43
  if (v === null || typeof v !== "object" || Array.isArray(v)) return undefined;
18
44
  const r = AgEvent.safeParse(v);
19
45
  if (!r.success) return undefined;
20
- // Preserve unknown top-level fields: validated keys win, unknown keys ride
21
- // along, in the same key order a plain merge would give. Keys are DEFINED,
22
- // never assigned: assigning a wire key named `__proto__` runs
23
- // Object.prototype's setter, which would let wire data choose the returned
24
- // event's prototype, and then fields it never carried (and the schema never
25
- // validated) would be inherited (SPEC.md:759, :27). That one key is skipped
26
- // outright, matching zod, which keeps it at no nested depth either.
27
- const out: { [k: string]: unknown } = {};
28
- for (const src of [v, r.data] as ReadonlyArray<{ [k: string]: unknown }>) {
29
- for (const k of Object.keys(src)) {
30
- if (k === "__proto__") continue;
31
- Object.defineProperty(out, k, { value: src[k], enumerable: true, writable: true, configurable: true });
32
- }
33
- }
34
- return out as AgEvent;
46
+ return copyJson(v) as unknown as AgEvent;
35
47
  }
36
48
 
37
49
  export function ingestAgEvents(vs: JsonValue[]): AgEvent[] {