Skip to content

Commit dd3fcb0

Browse files
committed
v1.2.0: invert source of truth — TypeScript field files, JSON is generated
The hand-edited data/supplier-questionnaire.json was awkward to author and forfeited type safety on enums and Baustein IDs. Inverted: the TypeScript field files in src/fields/ are now the source of truth, and the JSON is a generated artefact for non-TS consumers. Source layout: src/fields/profile.ts 17 fields src/fields/security-practices.ts 24 fields src/fields/saas-technical.ts 5 fields src/fields/on-prem-technical.ts 4 fields src/fields/pro-services.ts 3 fields src/fields/managed-services.ts 3 fields src/fields/index.ts combines into allFields Authoring workflow: 1. Edit src/fields/<section>.ts (TypeScript with full autocomplete) 2. Run `bun run build:json` to regenerate the JSON artefact 3. Run `bun run check:json-in-sync` (CI does this too) Backwards compatible. The published JSON still validates against the same Zod schema, the npm-package exports are unchanged, and consumers that import the JSON directly continue to work.
1 parent 1183192 commit dd3fcb0

13 files changed

Lines changed: 1367 additions & 140 deletions

.github/workflows/validate.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ jobs:
1717
- run: bun install --no-save
1818
- name: Typecheck
1919
run: bun run typecheck
20-
- name: Schema validates bundled JSON
20+
- name: TS source validates against schema
2121
run: bun run validate
22+
- name: JSON artefact matches TS source
23+
run: bun run check:json-in-sync

README.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
Maintained by [Kardashev Catalyst UG](https://nisd2.eu) — operator of [nisd2.eu](https://nisd2.eu) — and the same questionnaire that powers the supplier portal at nisd2.eu.
88

9-
The Zod schema is the source of truth. The bundled JSON snapshot is a derived, schema-validated artefact.
9+
Source of truth lives in [`src/fields/<section>.ts`](./src/fields/) — typed, with full TypeScript autocomplete on enums, citations, and Baustein IDs. The bundled JSON at [`data/supplier-questionnaire.json`](./data/supplier-questionnaire.json) is generated from these files for non-TS consumers.
1010

1111
---
1212

@@ -25,12 +25,42 @@ A single shared, openly maintained, legally-anchored questionnaire is more valua
2525

2626
## Why a schema, not just a JSON file
2727

28-
A JSON-only release is a dead artefact: nobody can validate it without re-deriving the rules, and forks drift silently. A Zod schema is alive:
28+
A JSON-only release is a dead artefact: nobody can validate it without re-deriving the rules, and forks drift silently. The TypeScript field files + Zod schema are alive:
2929

30-
- **TypeScript consumers** import the schema directly and get full type safety.
31-
- **Non-TS consumers** generate JSON Schema via [`zod-to-json-schema`](https://github.com/StefanTerdell/zod-to-json-schema) and use it from Python, Go, Rust, Excel, anywhere.
30+
- **TypeScript consumers** import the data directly and get full type safety, autocomplete on enums, and inline IDE hints.
31+
- **Non-TS consumers** read the bundled `data/supplier-questionnaire.json` directly, or generate JSON Schema via [`zod-to-json-schema`](https://github.com/StefanTerdell/zod-to-json-schema) and use it from Python, Go, Rust, Excel, anywhere.
3232
- **Drizzle / Prisma / Kysely consumers** use `examples/drizzle-storage-reference.ts` for a suggested response-storage layer keyed to our field IDs.
33-
- **Forks stay honest** — every change must validate against the schema or CI fails.
33+
- **Forks stay honest** — the JSON is regenerated from TS via `bun run build:json`; CI fails if it drifts.
34+
35+
### Source layout
36+
37+
```
38+
src/
39+
schema.ts Zod schema (the type definitions)
40+
fields/
41+
profile.ts 17 fields
42+
security-practices.ts 24 fields
43+
saas-technical.ts 5 fields
44+
on-prem-technical.ts 4 fields
45+
pro-services.ts 3 fields
46+
managed-services.ts 3 fields
47+
index.ts combines them into allFields
48+
data.ts wraps allFields in version + lastUpdated, validates
49+
data/
50+
supplier-questionnaire.json GENERATED — do not edit by hand
51+
scripts/
52+
build-json.ts regenerates the JSON from src/fields/*.ts
53+
generate-bsi-mapping.py regenerates the BSI inverse mapping
54+
```
55+
56+
### Editing fields
57+
58+
1. Edit the relevant `src/fields/<section>.ts` file (TypeScript, autocomplete works).
59+
2. Run `bun run build:json` to regenerate `data/supplier-questionnaire.json`.
60+
3. Run `bun run generate:bsi-mapping` if you changed `bsiBausteine` arrays.
61+
4. Run `bun run validate` and `bun run typecheck` to confirm everything is consistent.
62+
63+
CI runs `bun run check:json-in-sync` and fails if the bundled JSON doesn't match what the TS would generate.
3464

3565
---
3666

@@ -45,7 +75,7 @@ bun add @nisd2/nis2-supplier-questionnaire
4575
Or pin to a specific commit / tag without npm:
4676

4777
```bash
48-
npm install github:NISD2/nis2-supplier-questionnaire#v1.1.0
78+
npm install github:NISD2/nis2-supplier-questionnaire#v1.2.0
4979
```
5080

5181
---

0 commit comments

Comments
 (0)