@ocap/util 1.30.3 → 1.30.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.
@@ -1,4 +1,18 @@
1
1
  //#region src/get-list-field.d.ts
2
2
  declare const getListField: (obj: $TSFixMe, key: string) => any;
3
+ /**
4
+ * Write a repeated field to its canonical (no-suffix) form and remove the
5
+ * jspb `xxxList` twin. Keeps pipe code insulated from protobuf vs CBOR
6
+ * provenance while ensuring only one source of truth remains on `obj`.
7
+ *
8
+ * ⚠️ Must use `delete` (not `= undefined`) — see CLAUDE.md Critical Lesson #1.
9
+ */
10
+ declare const setListField: (obj: $TSFixMe, key: string, value: unknown) => void;
11
+ /**
12
+ * Remove both `xxx` and `xxxList` twins so the field is absent from any
13
+ * subsequent spread / pick / serialization. Mirrors `setListField` for
14
+ * the "clear" case. Uses `delete` for the same reason as `setListField`.
15
+ */
16
+ declare const deleteListField: (obj: $TSFixMe, key: string) => void;
3
17
  //#endregion
4
- export { getListField };
18
+ export { deleteListField, getListField, setListField };
@@ -1,6 +1,26 @@
1
1
  //#region src/get-list-field.ts
2
2
  const getByPath = (obj, path) => path.split(".").reduce((o, k) => o?.[k], obj);
3
3
  const getListField = (obj, key) => getByPath(obj, `${key}List`) || getByPath(obj, key) || [];
4
+ /**
5
+ * Write a repeated field to its canonical (no-suffix) form and remove the
6
+ * jspb `xxxList` twin. Keeps pipe code insulated from protobuf vs CBOR
7
+ * provenance while ensuring only one source of truth remains on `obj`.
8
+ *
9
+ * ⚠️ Must use `delete` (not `= undefined`) — see CLAUDE.md Critical Lesson #1.
10
+ */
11
+ const setListField = (obj, key, value) => {
12
+ delete obj[`${key}List`];
13
+ obj[key] = value;
14
+ };
15
+ /**
16
+ * Remove both `xxx` and `xxxList` twins so the field is absent from any
17
+ * subsequent spread / pick / serialization. Mirrors `setListField` for
18
+ * the "clear" case. Uses `delete` for the same reason as `setListField`.
19
+ */
20
+ const deleteListField = (obj, key) => {
21
+ delete obj[`${key}List`];
22
+ delete obj[key];
23
+ };
4
24
 
5
25
  //#endregion
6
- export { getListField };
26
+ export { deleteListField, getListField, setListField };
@@ -2,6 +2,28 @@
2
2
  //#region src/get-list-field.ts
3
3
  const getByPath = (obj, path) => path.split(".").reduce((o, k) => o?.[k], obj);
4
4
  const getListField = (obj, key) => getByPath(obj, `${key}List`) || getByPath(obj, key) || [];
5
+ /**
6
+ * Write a repeated field to its canonical (no-suffix) form and remove the
7
+ * jspb `xxxList` twin. Keeps pipe code insulated from protobuf vs CBOR
8
+ * provenance while ensuring only one source of truth remains on `obj`.
9
+ *
10
+ * ⚠️ Must use `delete` (not `= undefined`) — see CLAUDE.md Critical Lesson #1.
11
+ */
12
+ const setListField = (obj, key, value) => {
13
+ delete obj[`${key}List`];
14
+ obj[key] = value;
15
+ };
16
+ /**
17
+ * Remove both `xxx` and `xxxList` twins so the field is absent from any
18
+ * subsequent spread / pick / serialization. Mirrors `setListField` for
19
+ * the "clear" case. Uses `delete` for the same reason as `setListField`.
20
+ */
21
+ const deleteListField = (obj, key) => {
22
+ delete obj[`${key}List`];
23
+ delete obj[key];
24
+ };
5
25
 
6
26
  //#endregion
7
- exports.getListField = getListField;
27
+ exports.deleteListField = deleteListField;
28
+ exports.getListField = getListField;
29
+ exports.setListField = setListField;
@@ -1,4 +1,18 @@
1
1
  //#region src/get-list-field.d.ts
2
2
  declare const getListField: (obj: $TSFixMe, key: string) => any;
3
+ /**
4
+ * Write a repeated field to its canonical (no-suffix) form and remove the
5
+ * jspb `xxxList` twin. Keeps pipe code insulated from protobuf vs CBOR
6
+ * provenance while ensuring only one source of truth remains on `obj`.
7
+ *
8
+ * ⚠️ Must use `delete` (not `= undefined`) — see CLAUDE.md Critical Lesson #1.
9
+ */
10
+ declare const setListField: (obj: $TSFixMe, key: string, value: unknown) => void;
11
+ /**
12
+ * Remove both `xxx` and `xxxList` twins so the field is absent from any
13
+ * subsequent spread / pick / serialization. Mirrors `setListField` for
14
+ * the "clear" case. Uses `delete` for the same reason as `setListField`.
15
+ */
16
+ declare const deleteListField: (obj: $TSFixMe, key: string) => void;
3
17
  //#endregion
4
- export { getListField };
18
+ export { deleteListField, getListField, setListField };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ocap/util",
3
- "version": "1.30.3",
3
+ "version": "1.30.5",
4
4
  "type": "module",
5
5
  "description": "utils shared across multiple forge js libs, works in both node.js and browser",
6
6
  "keywords": [
@@ -12,7 +12,7 @@
12
12
  "access": "public"
13
13
  },
14
14
  "dependencies": {
15
- "@ocap/types": "1.30.3",
15
+ "@ocap/types": "1.30.5",
16
16
  "@types/bn.js": "^5.2.0",
17
17
  "base64-url": "^2.3.3",
18
18
  "bn.js": "5.2.3",