@pbuilder/sdk 0.12.0 → 0.13.0

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.
@@ -4,12 +4,12 @@
4
4
  export function forceEntry(force) {
5
5
  return force !== undefined ? { force } : {};
6
6
  }
7
- // REQ-TOE-01: shallow top-level composite (array/plain-object) -> JSON string; everything
8
- // else passes through verbatim. Assembly uses Object.defineProperty (never spread/`result[k]=`)
7
+ // REQ-TOE-01: top-level composite (array/plain-object) values are copied as native JSON;
8
+ // everything else passes through verbatim. Assembly uses Object.defineProperty (never spread/`result[k]=`)
9
9
  // per REQ-TOE-05 — enumerable:true is load-bearing, defineProperty defaults it to false and an
10
10
  // unenumerable key silently drops from JSON.stringify at the wire boundary.
11
11
  // REQ-TOE-01.5: a null-prototype object (Object.create(null)) is a plain, dict-like data
12
- // container and encodes like any other plain object — only a prototype OUTSIDE
12
+ // container and is copied like any other plain object — only a prototype OUTSIDE
13
13
  // {Object.prototype, null} (Date/Map/class instances) is non-plain (REQ-TOE-04, S-002).
14
14
  function isPlainObject(v) {
15
15
  if (typeof v !== "object" || v === null || Array.isArray(v))
@@ -44,7 +44,9 @@ function rejectOption(optionKey, detail) {
44
44
  // ascent (add-recurse-delete, scoped per top-level call via the default parameter) — never a
45
45
  // global "ever-visited" set. Only a value that is its own ancestor (a true cycle) rejects; an
46
46
  // acyclic SHARED reference (`const s = {x:1}; {a:s,b:s}`) is revisited from a clean ancestor
47
- // path each time and encodes normally, matching native JSON.stringify.
47
+ // path each time and is copied normally, matching native JSON.stringify.
48
+ // Returns a structural copy of a valid value: composites are rebuilt (plain-object keys via
49
+ // Object.defineProperty, REQ-TOE-05), scalars are returned as they are.
48
50
  function assertEncodable(value, optionKey, ancestors = new Set(), path = optionKey) {
49
51
  if (value === undefined)
50
52
  rejectOption(optionKey, `undefined at ${path}`);
@@ -54,40 +56,42 @@ function assertEncodable(value, optionKey, ancestors = new Set(), path = optionK
54
56
  rejectOption(optionKey, `symbol at ${path}`);
55
57
  if (typeof value === "bigint")
56
58
  rejectOption(optionKey, `BigInt at ${path}`);
57
- if (value === null || typeof value !== "object")
58
- return; // string/number/boolean/null: fine
59
+ if (value === null || typeof value !== "object") {
60
+ // A nested -0 inside the old JSON-string form became 0; keep that, or the round-trip
61
+ // guard rejects it (-0 === 0, so this also catches -0). A top-level -0 was never encoded, so it is left alone.
62
+ return value === 0 && path !== optionKey ? 0 : value;
63
+ }
59
64
  if (Array.isArray(value) || isPlainObject(value)) {
60
65
  if (ancestors.has(value))
61
66
  rejectOption(optionKey, `a circular reference at ${path}`);
62
67
  ancestors.add(value);
63
68
  try {
64
69
  if (Array.isArray(value)) {
65
- value.forEach((item, i) => assertEncodable(item, optionKey, ancestors, `${path}[${i}]`));
66
- }
67
- else {
68
- for (const [k, v] of Object.entries(value)) {
69
- assertEncodable(v, optionKey, ancestors, `${path}.${k}`);
70
- }
70
+ return value.map((item, i) => assertEncodable(item, optionKey, ancestors, `${path}[${i}]`));
71
71
  }
72
+ return copyEntries(value, ([k, v]) => assertEncodable(v, optionKey, ancestors, `${path}.${k}`));
72
73
  }
73
74
  finally {
74
75
  ancestors.delete(value);
75
76
  }
76
- return;
77
77
  }
78
- rejectOption(optionKey, `${kindOf(value)} at ${path}`);
78
+ return rejectOption(optionKey, `${kindOf(value)} at ${path}`);
79
79
  }
80
- export function encodeOptions(options) {
81
- if (!isPlainObject(options))
82
- return options;
80
+ function copyEntries(source, copy) {
83
81
  const result = {};
84
- for (const [key, value] of Object.entries(options)) {
85
- assertEncodable(value, key);
86
- const encoded = Array.isArray(value) || isPlainObject(value) ? JSON.stringify(value) : value;
87
- Object.defineProperty(result, key, { value: encoded, enumerable: true, writable: true, configurable: true });
82
+ for (const entry of Object.entries(source)) {
83
+ Object.defineProperty(result, entry[0], { value: copy(entry), enumerable: true, writable: true, configurable: true });
88
84
  }
89
85
  return result;
90
86
  }
87
+ // ADR-0082: composites reach the wire as native JSON. The copy snapshots the author's value
88
+ // at scheduling time and keeps nested non-finite numbers, so the flush-time round-trip
89
+ // guard sees them (REQ-TOE-03.3).
90
+ export function encodeOptions(options) {
91
+ if (!isPlainObject(options))
92
+ return options;
93
+ return copyEntries(options, ([key, value]) => assertEncodable(value, key));
94
+ }
91
95
  export class DirectiveFactory {
92
96
  create(a) {
93
97
  return {
@@ -2,7 +2,7 @@
2
2
  "manifestVersion": 1,
3
3
  "algorithm": "sha256",
4
4
  "entry": "dist/bin/pbuilder-runner.js",
5
- "packageVersion": "0.12.0",
5
+ "packageVersion": "0.13.0",
6
6
  "files": [
7
7
  {
8
8
  "path": "dist/bin/pbuilder-runner.js",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  {
20
20
  "path": "dist/core/directive-factory.js",
21
- "sha256": "06f13f234f77bfd749139d937b7d2381a0d72b364d9f68912a0bccbc7ee43cf3"
21
+ "sha256": "9aad2b51eec7679dbf031e2b9e71276d86ac4ce3ad6f0411e88d4d8a966cb3ae"
22
22
  },
23
23
  {
24
24
  "path": "dist/core/emit-rejection.js",
@@ -98,7 +98,7 @@
98
98
  },
99
99
  {
100
100
  "path": "package.json",
101
- "sha256": "dd84ad976cc9ec3ae2fba6d4adc7c2d5a7ce3eceeac47212a62727e7a2e96a9c"
101
+ "sha256": "9751fadd8a84cde86463e3a32f80d93bc791f233ca96783715193b9fc5514657"
102
102
  }
103
103
  ]
104
104
  }
@@ -102,12 +102,8 @@ export function classifyTransport(params) {
102
102
  // `>` (not `>=`) — exactly-at-budget still fits (REQ-CCL-02.3).
103
103
  //
104
104
  // REQ-CCL-02.4: `options` is run through the SAME shared `encodeOptions` (fit-39's one
105
- // other sanctioned call site) real `create()` emission applies — never the caller's raw,
106
- // pre-encode shape. A composite option value's JSON-string form carries its own
107
- // quote/backslash-escaping inflation once re-embedded and serialized again here, closing
108
- // the pre-encode/post-encode misclassification gap: measuring the raw shape would
109
- // under-count and could wrongly classify by-value a directive that is actually over
110
- // budget once the real encode step runs.
105
+ // other sanctioned call site) real `create()` emission applies, so the measure and the
106
+ // emitted directive can never disagree on the options' wire form.
111
107
  const prospectiveDirective = {
112
108
  op: "create",
113
109
  create: { pathTemplate: destPath, template: content, options: encodeOptions(options), ...forceEntry(force) },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pbuilder/sdk",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "The public TypeScript/Bun authoring layer for Project Builder schematics. Authors file mutations (create, replaceContent, remove, rename, move, copy, copyIn), lowers them to IR, and talks to the Project Builder engine over framed stdio (see docs/engine-sdk-wire-spec.md).",
5
5
  "license": "MIT",
6
6
  "type": "module",