@peasant-labs/fairtrade 0.0.60 → 0.0.61
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,23 @@
|
|
|
1
|
+
//#region src/ui/closed-value.js
|
|
2
|
+
function e(e, r) {
|
|
3
|
+
t(e), n(r);
|
|
4
|
+
let i = String(e);
|
|
5
|
+
return Object.freeze({
|
|
6
|
+
wire: e,
|
|
7
|
+
label: r,
|
|
8
|
+
String: () => i,
|
|
9
|
+
toString: () => i,
|
|
10
|
+
toJSON: () => e
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
function t(e) {
|
|
14
|
+
if (!(typeof e == "string" && e.length > 0) && !(typeof e == "number" && Number.isFinite(e))) throw TypeError(`closed(wire, label) failed in src/ui/closed-value.js: wire must be a non-empty string or a finite number, received ${r(e)}. A closed value's wire is the exact value persisted and compared, so it must be a primitive with a stable value (for example 'project' or 25). Pass the primitive at the member definition.`);
|
|
15
|
+
}
|
|
16
|
+
function n(e) {
|
|
17
|
+
if (!(typeof e == "string" && e.length > 0)) throw TypeError(`closed(wire, label) failed in src/ui/closed-value.js: label must be a non-empty string, received ${r(e)}. The label is the human-readable text shown for the member, so every member needs its own (for example '25' for the numeric wire 25). Pass the label at the member definition.`);
|
|
18
|
+
}
|
|
19
|
+
function r(e) {
|
|
20
|
+
return typeof e == "string" ? JSON.stringify(e) : typeof e == "number" ? String(e) : e === null ? "null" : Array.isArray(e) ? "an array" : `a ${typeof e}`;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { e as closed };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A closed value: a frozen object that carries its wire value, the label a
|
|
3
|
+
* surface shows for it, and the conversion hooks.
|
|
4
|
+
*
|
|
5
|
+
* - `wire` is the exact value persisted, compared, and sent on the wire.
|
|
6
|
+
* - `label` is the human-readable text shown for the member.
|
|
7
|
+
* - `String()` is the Go-style explicit text conversion; it returns `String(wire)`.
|
|
8
|
+
* - `toString()` is the text conversion used by `String(value)` and template literals.
|
|
9
|
+
* - `toJSON()` is the persistence conversion used by `JSON.stringify`; it returns `wire`.
|
|
10
|
+
*
|
|
11
|
+
* @template {string | number} W - the exact value persisted, compared, and sent on the wire.
|
|
12
|
+
* @template {string} L - the human-readable label shown for the member.
|
|
13
|
+
* @typedef {{
|
|
14
|
+
* readonly wire: W,
|
|
15
|
+
* readonly label: L,
|
|
16
|
+
* String: () => string,
|
|
17
|
+
* toString: () => string,
|
|
18
|
+
* toJSON: () => W,
|
|
19
|
+
* }} ClosedValue
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Create one frozen closed-set member.
|
|
23
|
+
*
|
|
24
|
+
* @template {string | number} W
|
|
25
|
+
* @template {string} L
|
|
26
|
+
* @param {W} wire - the exact value persisted, compared, and sent on the wire.
|
|
27
|
+
* @param {L} label - the human-readable text shown for the member.
|
|
28
|
+
* @returns {ClosedValue<W, L>} a new frozen member for this `(wire, label)` pair.
|
|
29
|
+
*/
|
|
30
|
+
export function closed<W extends string | number, L extends string>(wire: W, label: L): ClosedValue<W, L>;
|
|
31
|
+
/**
|
|
32
|
+
* A closed value: a frozen object that carries its wire value, the label a
|
|
33
|
+
* surface shows for it, and the conversion hooks.
|
|
34
|
+
*
|
|
35
|
+
* - `wire` is the exact value persisted, compared, and sent on the wire.
|
|
36
|
+
* - `label` is the human-readable text shown for the member.
|
|
37
|
+
* - `String()` is the Go-style explicit text conversion; it returns `String(wire)`.
|
|
38
|
+
* - `toString()` is the text conversion used by `String(value)` and template literals.
|
|
39
|
+
* - `toJSON()` is the persistence conversion used by `JSON.stringify`; it returns `wire`.
|
|
40
|
+
*/
|
|
41
|
+
export type ClosedValue<W extends string | number, L extends string> = {
|
|
42
|
+
readonly wire: W;
|
|
43
|
+
readonly label: L;
|
|
44
|
+
String: () => string;
|
|
45
|
+
toString: () => string;
|
|
46
|
+
toJSON: () => W;
|
|
47
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peasant-labs/fairtrade",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.61",
|
|
5
5
|
"description": "Fairtrade design-system library: canonical tokens, base styles, component CSS, and React UI exports.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -47,6 +47,12 @@
|
|
|
47
47
|
"require": "./dist/lib/icons.js",
|
|
48
48
|
"default": "./dist/lib/icons.js"
|
|
49
49
|
},
|
|
50
|
+
"./closed-value": {
|
|
51
|
+
"types": "./dist/lib/types/closed-value.d.ts",
|
|
52
|
+
"import": "./dist/lib/closed-value.js",
|
|
53
|
+
"require": "./dist/lib/closed-value.js",
|
|
54
|
+
"default": "./dist/lib/closed-value.js"
|
|
55
|
+
},
|
|
50
56
|
"./share": {
|
|
51
57
|
"types": "./dist/lib/types/share/index.d.ts",
|
|
52
58
|
"import": "./dist/lib/share.js",
|
|
@@ -91,6 +97,7 @@
|
|
|
91
97
|
"icons:check": "node scripts/gen-app-icons.mjs --check",
|
|
92
98
|
"build:app": "node scripts/gen-app-icons.mjs --check && node scripts/gen-llm-artifacts.mjs && node scripts/contrast.mjs && vite build",
|
|
93
99
|
"test:contract": "tsc -p tsconfig.contract.json",
|
|
100
|
+
"test:closed-value": "node --test src/ui/closed-value.test.js",
|
|
94
101
|
"test:share-types": "tsc -p tsconfig.share-types.json",
|
|
95
102
|
"test:runtime-floor": "node scripts/runtime-floor.test.mjs",
|
|
96
103
|
"test:code-map-state": "node scripts/code-map-state.test.mjs",
|
|
@@ -192,7 +199,7 @@
|
|
|
192
199
|
"test:accessibility-semantics:mutations": "node scripts/parts-mutations.mjs scripts/accessibility-semantics.test.mjs scripts/testdata/accessibility-semantics.manifest.yaml",
|
|
193
200
|
"test:parts": "pnpm test:transcript-integrity && pnpm test:transcript-integrity-viewer && pnpm test:transcript-ledger-chrome && pnpm test:transcript-ledger-turns && pnpm test:transcript-reading-layout && pnpm test:accessibility-semantics && pnpm test:code-map-disclosure && pnpm test:page-headings && pnpm test:code-map-line-counts && pnpm test:transcript-viewer-chrome && pnpm test:app-sections && pnpm test:local-offline-banner && pnpm test:app-sidebar && pnpm test:settings-nav && pnpm test:transcript-session-records && pnpm test:transcript-system-groups && pnpm test:transcript-viewer-format && pnpm test:prompt-digest-split && pnpm test:village-parts && pnpm test:publish-states && pnpm test:setting-row && pnpm test:repo-picker && pnpm test:commons-demo-pages && pnpm test:collectives-views && pnpm test:number-format && pnpm test:command-block",
|
|
194
201
|
"test:parts:mutations": "pnpm test:transcript-integrity:mutations && pnpm test:transcript-integrity-viewer:mutations && pnpm test:transcript-ledger-chrome:mutations && pnpm test:transcript-ledger-turns:mutations && pnpm test:transcript-reading-layout:mutations && pnpm test:accessibility-semantics:mutations && pnpm test:code-map-disclosure:mutations && pnpm test:page-headings:mutations && pnpm test:code-map-line-counts:mutations && pnpm test:transcript-viewer-chrome:mutations && pnpm test:app-sections:mutations && pnpm test:local-offline-banner:mutations && pnpm test:app-sidebar:mutations && pnpm test:settings-nav:mutations && pnpm test:transcript-session-records:mutations && pnpm test:transcript-system-groups:mutations && pnpm test:transcript-viewer-format:mutations && pnpm test:prompt-digest-split:mutations && pnpm test:village-parts:mutations && pnpm test:publish-states:mutations && pnpm test:setting-row:mutations && pnpm test:repo-picker:mutations && pnpm test:commons-demo-pages:mutations && pnpm test:collectives-views:mutations && pnpm test:number-format:mutations && pnpm test:command-block:mutations",
|
|
195
|
-
"test:gates": "pnpm test:design-decisions && pnpm audit:design-decisions && pnpm test:port-record && pnpm test:demo-truth && pnpm test:datatable && pnpm test:structured-shiki && pnpm test:transcript-provenance && pnpm test:pi-transcript && pnpm test:pi-transcript:mutations && node scripts/gates.test.mjs && node scripts/turns-to-flow-edges.test.mjs && pnpm test:transcript-helpers && pnpm test:helper-groups && pnpm test:transcript-outcome-chip && pnpm test:transcript-viewer-outcome && pnpm test:parts && pnpm test:release-notes && pnpm test:share-card",
|
|
202
|
+
"test:gates": "pnpm test:design-decisions && pnpm audit:design-decisions && pnpm test:port-record && pnpm test:demo-truth && pnpm test:datatable && pnpm test:structured-shiki && pnpm test:transcript-provenance && pnpm test:pi-transcript && pnpm test:pi-transcript:mutations && node scripts/gates.test.mjs && node scripts/turns-to-flow-edges.test.mjs && pnpm test:transcript-helpers && pnpm test:helper-groups && pnpm test:transcript-outcome-chip && pnpm test:transcript-viewer-outcome && pnpm test:parts && pnpm test:release-notes && pnpm test:share-card && pnpm test:closed-value",
|
|
196
203
|
"test:analytics": "node src/ui/analytics/metrics.test.mjs",
|
|
197
204
|
"test:mobile-layout": "node scripts/mobile-layout.test.mjs",
|
|
198
205
|
"test:transcript-composite-width": "node scripts/transcript-composite-width.test.mjs",
|