@silverprotocol/core 0.6.3 → 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,CAM/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,20 +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 along.
22
- return Object.assign({}, v, r.data);
49
+ return copyJson(v);
23
50
  }
24
51
  export function ingestAgEvents(vs) {
25
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,kFAAkF;IAClF,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;AACtC,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"}
1
+ {"version":3,"file":"ingest.js","sourceRoot":"","sources":["../src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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.3",
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,19 +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 along.
21
- return Object.assign({}, v, r.data);
46
+ return copyJson(v) as unknown as AgEvent;
22
47
  }
23
48
 
24
49
  export function ingestAgEvents(vs: JsonValue[]): AgEvent[] {