@githolon/dsl 0.31.0 → 0.31.1
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/package.json +1 -1
- package/src/aggregate.ts +11 -0
- package/src/codegen_dart.ts +64 -13
- package/src/codegen_dart_client.ts +12 -0
- package/src/compile_package_main.ts +91 -13
- package/src/directive.ts +10 -0
- package/src/framework/framework_aggregates.ts +138 -0
- package/src/query.ts +10 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@githolon/dsl",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Nomos 2 domain-authoring DSL: aggregates + directives in TS, executed and encoded to the Rust kernel's wire shapes.",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
package/src/aggregate.ts
CHANGED
|
@@ -155,6 +155,17 @@ export interface AggregateHandle<
|
|
|
155
155
|
readonly hasMany: HasManyFields<F>;
|
|
156
156
|
/** Brand so a plain string is never accepted where a handle is required. */
|
|
157
157
|
readonly __isAggregateHandle: true;
|
|
158
|
+
/**
|
|
159
|
+
* FRAMEWORK-SHARED brand (Dart-codegen hygiene). Set (by `framework/framework_aggregates.ts`)
|
|
160
|
+
* ONLY on the framework-owned aggregate singletons declared in `dsl/src/framework/` — most
|
|
161
|
+
* importantly `RelationTuple`, auto-added to EVERY relation-using domain. A branded aggregate's
|
|
162
|
+
* Dart surface (read-model class, typed-id class, by-id accessors) is emitted ONCE per package into
|
|
163
|
+
* a shared `nomos_framework.dart` file, NOT re-emitted in each domain's generated `.dart` — so a
|
|
164
|
+
* package barrel re-exporting several domains never gets a duplicate framework symbol (no hand-
|
|
165
|
+
* maintained `hide` clause). NOT hashed / NOT law: a pure frontend-codegen marker (like
|
|
166
|
+
* `readModelAggregates`). Identified by OBJECT IDENTITY (the branded singleton), so a tenant
|
|
167
|
+
* aggregate that merely SHARES a name is never misclassified. OMITTED on tenant aggregates. */
|
|
168
|
+
readonly framework?: true;
|
|
158
169
|
/** Presence-only flag (hashed); OMITTED ENTIRELY when no invariant is declared. */
|
|
159
170
|
readonly hasInvariant?: true;
|
|
160
171
|
/** The executable body — ships in the engine bundle, NOT the manifest. */
|
package/src/codegen_dart.ts
CHANGED
|
@@ -1168,8 +1168,8 @@ function emitEvidenceRefClass(): string {
|
|
|
1168
1168
|
|
|
1169
1169
|
/** True when ANY aggregate field in the module is `t.evidence()` — gates emitting the
|
|
1170
1170
|
* shared [emitEvidenceRefClass] once. */
|
|
1171
|
-
function moduleUsesEvidence(
|
|
1172
|
-
return
|
|
1171
|
+
function moduleUsesEvidence(aggregates: readonly AggregateHandle[]): boolean {
|
|
1172
|
+
return aggregates.some((a) =>
|
|
1173
1173
|
Object.values(a.fields as Record<string, Field>).some((f) => f.kind === "evidence"),
|
|
1174
1174
|
);
|
|
1175
1175
|
}
|
|
@@ -2300,14 +2300,21 @@ function emitMintedCreates(
|
|
|
2300
2300
|
directives: AnyDirective[],
|
|
2301
2301
|
domainName: string,
|
|
2302
2302
|
enumDartTypes: Map<string, string>,
|
|
2303
|
+
/** Aggregate ids whose typed-id CLASS is emitted in the shared `nomos_framework.dart` (imported
|
|
2304
|
+
* here), so it must NOT be re-declared. Minting FACTORIES still emit and reference the imported
|
|
2305
|
+
* class. Empty = emit every id class locally (the single-domain / shared-file path). */
|
|
2306
|
+
skipIdClassFor: ReadonlySet<string> = new Set(),
|
|
2303
2307
|
): string {
|
|
2304
2308
|
const blocks: string[] = [];
|
|
2305
2309
|
|
|
2306
2310
|
// (1) A typed id class per aggregate. Dedup by the typed-id class NAME: two wire
|
|
2307
2311
|
// types never collide on a name (the name is a pure function of the type), and a
|
|
2308
2312
|
// domain that re-exports a framework aggregate must not emit its id class twice.
|
|
2313
|
+
// Framework-shared aggregates are emitted ONCE in the package's `nomos_framework.dart`,
|
|
2314
|
+
// so their id class is SKIPPED here (referenced via import).
|
|
2309
2315
|
const emittedIdClasses = new Set<string>();
|
|
2310
2316
|
for (const agg of aggregates) {
|
|
2317
|
+
if (skipIdClassFor.has(agg.id)) continue;
|
|
2311
2318
|
const cls = typedIdClassForAggregateType(agg.id);
|
|
2312
2319
|
if (emittedIdClasses.has(cls)) continue;
|
|
2313
2320
|
emittedIdClasses.add(cls);
|
|
@@ -2565,12 +2572,49 @@ export interface DomainModule {
|
|
|
2565
2572
|
dartRefImports?: DartRefImport[];
|
|
2566
2573
|
}
|
|
2567
2574
|
|
|
2575
|
+
/** Options controlling FRAMEWORK-SHARED aggregate deduplication (Dart-codegen hygiene). */
|
|
2576
|
+
export interface GenerateDartDomainOptions {
|
|
2577
|
+
/**
|
|
2578
|
+
* Aggregate ids whose Dart surface (projection class, read model, typed-id class, by-id accessors)
|
|
2579
|
+
* is emitted ONCE per package in the shared `nomos_framework.dart` and MUST NOT be re-emitted here —
|
|
2580
|
+
* this domain REFERENCES them via {@link frameworkImportUri}. Empty/absent ⇒ emit everything locally
|
|
2581
|
+
* (the legacy single-file behaviour; byte-identical to before this option existed).
|
|
2582
|
+
*/
|
|
2583
|
+
readonly skipAggregateIds?: ReadonlySet<string>;
|
|
2584
|
+
/**
|
|
2585
|
+
* Framework-shared DIRECTIVE ids whose generated payload class (+ minted-create factory) is emitted
|
|
2586
|
+
* ONCE per package in the shared file and MUST NOT be re-emitted here. The domain still OFFERS them
|
|
2587
|
+
* (the client offer methods stay per-domain); only the payload TYPE moves to the shared file.
|
|
2588
|
+
*/
|
|
2589
|
+
readonly skipDirectiveIds?: ReadonlySet<string>;
|
|
2590
|
+
/**
|
|
2591
|
+
* Framework-shared QUERY ids whose top-level `watch<Q>`/`read<Q>` accessors are emitted ONCE per
|
|
2592
|
+
* package in the shared file and MUST NOT be re-emitted here. The client's per-domain query methods
|
|
2593
|
+
* stay (they reference the shared read models via the framework import).
|
|
2594
|
+
*/
|
|
2595
|
+
readonly skipQueryIds?: ReadonlySet<string>;
|
|
2596
|
+
/**
|
|
2597
|
+
* Relative import of the shared framework file (e.g. `nomos_framework.dart`). Added as an ordinary
|
|
2598
|
+
* `import` so skipped framework symbols resolve. Omit when nothing is skipped.
|
|
2599
|
+
*/
|
|
2600
|
+
readonly frameworkImportUri?: string;
|
|
2601
|
+
}
|
|
2602
|
+
|
|
2568
2603
|
/** Generate the full Dart source for one domain module. */
|
|
2569
|
-
export function generateDartDomain(mod: DomainModule): string {
|
|
2604
|
+
export function generateDartDomain(mod: DomainModule, opts: GenerateDartDomainOptions = {}): string {
|
|
2570
2605
|
const domainKey = mod.domain ?? mod.name;
|
|
2606
|
+
const skipAggregateIds = opts.skipAggregateIds ?? new Set<string>();
|
|
2607
|
+
const skipDirectiveIds = opts.skipDirectiveIds ?? new Set<string>();
|
|
2608
|
+
const skipQueryIds = opts.skipQueryIds ?? new Set<string>();
|
|
2609
|
+
// The symbols whose Dart surface this file EMITS (framework-shared ones live in the shared file).
|
|
2610
|
+
const localAggregates = mod.aggregates.filter((a) => !skipAggregateIds.has(a.id));
|
|
2611
|
+
const localDirectives = mod.directives.filter((d) => !skipDirectiveIds.has(d.id));
|
|
2612
|
+
const localQueries = (mod.queries ?? []).filter((q) => !skipQueryIds.has(q.id));
|
|
2613
|
+
// Enums are collected from the LOCALLY-emitted symbols only — a framework directive/aggregate's
|
|
2614
|
+
// enums ride the shared `nomos_framework.dart`, so a domain that skips them emits no dangling enum.
|
|
2571
2615
|
const { dartTypes, decls } = collectEnums(
|
|
2572
|
-
|
|
2573
|
-
|
|
2616
|
+
localAggregates,
|
|
2617
|
+
localDirectives,
|
|
2574
2618
|
domainKey,
|
|
2575
2619
|
);
|
|
2576
2620
|
const refIdClassForAggregate = refIdClassResolver(mod);
|
|
@@ -2583,7 +2627,7 @@ export function generateDartDomain(mod: DomainModule): string {
|
|
|
2583
2627
|
);
|
|
2584
2628
|
const enumBlock = decls.join("\n\n");
|
|
2585
2629
|
const permissionVocabularyBlock = emitPermissionVocabulary(mod.permissionVocabulary);
|
|
2586
|
-
const aggBlock =
|
|
2630
|
+
const aggBlock = localAggregates
|
|
2587
2631
|
.map((a) =>
|
|
2588
2632
|
emitAggregate(
|
|
2589
2633
|
a,
|
|
@@ -2593,7 +2637,7 @@ export function generateDartDomain(mod: DomainModule): string {
|
|
|
2593
2637
|
),
|
|
2594
2638
|
)
|
|
2595
2639
|
.join("\n\n");
|
|
2596
|
-
const dirBlock =
|
|
2640
|
+
const dirBlock = localDirectives
|
|
2597
2641
|
.map((d) => emitDirective(d, domainKey, dartTypes))
|
|
2598
2642
|
.join("\n\n");
|
|
2599
2643
|
|
|
@@ -2602,7 +2646,9 @@ export function generateDartDomain(mod: DomainModule): string {
|
|
|
2602
2646
|
// ref fields name their target's typed id), plus a top-level `create…` factory that
|
|
2603
2647
|
// mints THROUGH the kernel (no raw id) for every `.creates` directive carrying a
|
|
2604
2648
|
// `mintSeed` + an own-id field.
|
|
2605
|
-
|
|
2649
|
+
// Minted-create factories for framework directives (if any) live in the shared file — pass only the
|
|
2650
|
+
// LOCAL directives here; framework typed-id classes are likewise skipped (referenced via import).
|
|
2651
|
+
const mintedBlock = emitMintedCreates(mod.aggregates, localDirectives, domainKey, dartTypes, skipAggregateIds);
|
|
2606
2652
|
|
|
2607
2653
|
// PROVIDER SDK (the symmetric twin of the peer payload classes): for each declared
|
|
2608
2654
|
// `impureCapability` capability, a typed Obligation/Result/Failure + handler typedef + dispatcher.
|
|
@@ -2635,7 +2681,7 @@ export function generateDartDomain(mod: DomainModule): string {
|
|
|
2635
2681
|
list.push(c);
|
|
2636
2682
|
combinedsByType.set(c.of, list);
|
|
2637
2683
|
}
|
|
2638
|
-
const readModelBlock =
|
|
2684
|
+
const readModelBlock = localAggregates
|
|
2639
2685
|
.filter((a) => readModelTypes.has(a.id))
|
|
2640
2686
|
.map((a) =>
|
|
2641
2687
|
emitReadModel(
|
|
@@ -2657,7 +2703,7 @@ export function generateDartDomain(mod: DomainModule): string {
|
|
|
2657
2703
|
// §5 claim that "codegen already emits count reads" was wrong; this is the actual
|
|
2658
2704
|
// first emission. The predicate is baked into the maintained counter and is
|
|
2659
2705
|
// INVISIBLE to the generated accessor (worldview law).
|
|
2660
|
-
const queryReads =
|
|
2706
|
+
const queryReads = localQueries
|
|
2661
2707
|
.map((q) =>
|
|
2662
2708
|
emitQueryReads(
|
|
2663
2709
|
q,
|
|
@@ -2731,7 +2777,9 @@ export function generateDartDomain(mod: DomainModule): string {
|
|
|
2731
2777
|
)
|
|
2732
2778
|
.join("\n\n");
|
|
2733
2779
|
const orderedReadBlock = (mod.orderedReads ?? []).map(emitOrderedReads).join("\n\n");
|
|
2734
|
-
|
|
2780
|
+
// By-id accessors for framework-shared aggregates live in `nomos_framework.dart` (emitted once);
|
|
2781
|
+
// this domain references them via the framework import.
|
|
2782
|
+
const byIdReads = localAggregates.map(emitAggregateByIdReads).join("\n\n");
|
|
2735
2783
|
const readBlock = [queryReads, countReads, sumReads, minReads, maxReads, existsReads, orderedReadBlock, byIdReads]
|
|
2736
2784
|
.filter((s) => s !== "")
|
|
2737
2785
|
.join("\n\n");
|
|
@@ -2739,7 +2787,7 @@ export function generateDartDomain(mod: DomainModule): string {
|
|
|
2739
2787
|
// `_mapEq` is only referenced by aggregate `==`/`hashCode` for MAP fields. Emit it
|
|
2740
2788
|
// ONLY when some aggregate has a map field, else a map-less domain trips an
|
|
2741
2789
|
// unused-element lint.
|
|
2742
|
-
const hasMapField =
|
|
2790
|
+
const hasMapField = localAggregates.some((a) =>
|
|
2743
2791
|
Object.values(a.fields as Record<string, Field>).some((f) => f.kind === "map"),
|
|
2744
2792
|
);
|
|
2745
2793
|
const helperBlock = hasMapField
|
|
@@ -2771,6 +2819,9 @@ export function generateDartDomain(mod: DomainModule): string {
|
|
|
2771
2819
|
// out of nomos_client into the co-located tenant package). The framework barrel
|
|
2772
2820
|
// re-exports wire/dispatch/subscriptions/provider, so one import covers them all.
|
|
2773
2821
|
`import 'package:nomos_client/nomos_client.dart';`,
|
|
2822
|
+
// FRAMEWORK-SHARED aggregates (RelationTuple, …) are emitted ONCE per package in the shared
|
|
2823
|
+
// file; import it so this domain's read accessors / ref-id fields resolve those symbols.
|
|
2824
|
+
...(opts.frameworkImportUri !== undefined ? [`import '${opts.frameworkImportUri}';`] : []),
|
|
2774
2825
|
...(mod.dartImports ?? []).map(dartImportLine),
|
|
2775
2826
|
``,
|
|
2776
2827
|
`// ---- enums ----`,
|
|
@@ -2783,7 +2834,7 @@ export function generateDartDomain(mod: DomainModule): string {
|
|
|
2783
2834
|
``,
|
|
2784
2835
|
]
|
|
2785
2836
|
: []),
|
|
2786
|
-
...(moduleUsesEvidence(
|
|
2837
|
+
...(moduleUsesEvidence(localAggregates)
|
|
2787
2838
|
? [
|
|
2788
2839
|
`// ---- evidence (content-addressed EvidenceRef; evidence.md §9.2) ----`,
|
|
2789
2840
|
emitEvidenceRefClass(),
|
|
@@ -99,6 +99,14 @@ export interface DartBridgeClientOptions {
|
|
|
99
99
|
readonly interface?: unknown;
|
|
100
100
|
/** Where the bridge/runtime support types are imported from. */
|
|
101
101
|
readonly supportImport?: "vendored" | "package";
|
|
102
|
+
/**
|
|
103
|
+
* Relative import of the shared `nomos_framework.dart` (framework-shared aggregate types, emitted
|
|
104
|
+
* ONCE per package). When present the client IMPORTS it (its by-id accessors reference framework
|
|
105
|
+
* read models) and RE-EXPORTS it, so a package barrel re-exporting several domain clients surfaces
|
|
106
|
+
* the framework types EXACTLY ONCE (Dart de-dups re-exports of the SAME library) — no `hide` needed.
|
|
107
|
+
* Omit for a package with no framework-shared aggregates.
|
|
108
|
+
*/
|
|
109
|
+
readonly frameworkImportUri?: string;
|
|
102
110
|
}
|
|
103
111
|
|
|
104
112
|
/** Generate the `<name>.client.dart` async bridge client for one domain module. */
|
|
@@ -245,9 +253,13 @@ export function generateDartBridgeClient(mod: DomainModule, opts: DartBridgeClie
|
|
|
245
253
|
...(opts.interface !== undefined ? [`import 'dart:convert';`, ``] : []),
|
|
246
254
|
`import '${supportImport}';`,
|
|
247
255
|
`import '${mod.name}.dart';`,
|
|
256
|
+
// Framework-shared aggregate types (RelationTupleReadModel, …) live in the ONE shared file — import
|
|
257
|
+
// them (the by-id accessors reference them) and re-export them (once per package, Dart de-dups).
|
|
258
|
+
...(opts.frameworkImportUri !== undefined ? [`import '${opts.frameworkImportUri}';`] : []),
|
|
248
259
|
`// Re-export the sibling types (read models + payloads + the bridge runtime) so ONE import of this`,
|
|
249
260
|
`// client file gives an app the whole typed surface.`,
|
|
250
261
|
`export '${mod.name}.dart';`,
|
|
262
|
+
...(opts.frameworkImportUri !== undefined ? [`export '${opts.frameworkImportUri}';`] : []),
|
|
251
263
|
`export '${supportImport}' show NomosBridge, BridgeTransport, NomosBridgeError, MissingOfferAuthority, kWebviewBridgeVersion;`,
|
|
252
264
|
``,
|
|
253
265
|
`/// sha256 of the deployed \`.package.usda\` — the installed law this client offers under.`,
|
|
@@ -61,6 +61,11 @@ import {
|
|
|
61
61
|
type PermissionVocabulary,
|
|
62
62
|
} from "./codegen_dart.js";
|
|
63
63
|
import { generateDartBridgeClient } from "./codegen_dart_client.js";
|
|
64
|
+
import {
|
|
65
|
+
isFrameworkAggregate,
|
|
66
|
+
isFrameworkDirective,
|
|
67
|
+
isFrameworkQuery,
|
|
68
|
+
} from "./framework/framework_aggregates.js";
|
|
64
69
|
import { finishCount, type AnyCount } from "./count.js";
|
|
65
70
|
import type { QueryDecl } from "./query.js";
|
|
66
71
|
import type { SpatialDecl } from "./spatial.js";
|
|
@@ -387,35 +392,108 @@ function emitDart(
|
|
|
387
392
|
removeVendoredDartSupport(dartOut);
|
|
388
393
|
}
|
|
389
394
|
|
|
390
|
-
// 2.
|
|
391
|
-
//
|
|
392
|
-
|
|
395
|
+
// 2. FRAMEWORK-SHARED symbol dedup (Dart-codegen hygiene). Framework-owned symbols fold into MANY
|
|
396
|
+
// domains, so their generated Dart would be DEFINED once per domain — a package barrel re-exporting
|
|
397
|
+
// ≥2 domains then COLLIDES (the historical `hide RelationTuple, EnrollDelegationPayload,
|
|
398
|
+
// readSignerDelegationByUser, …` band-aid). THREE kinds are deduped, each identified by the
|
|
399
|
+
// framework BRAND (object identity, so a tenant symbol that merely shares a name is never
|
|
400
|
+
// misclassified) and emitted EXACTLY ONCE into `nomos_framework.dart`:
|
|
401
|
+
// • AGGREGATES — read-model class, typed-id class, by-id accessors (`RelationTuple` auto-added
|
|
402
|
+
// to every relation-using domain, `SignerDelegation`/`KeyScope`/… re-exported verbatim);
|
|
403
|
+
// • DIRECTIVES — the generated payload class (relate/signer/enroll family). The domain still
|
|
404
|
+
// OFFERS them (client offer methods stay per-domain); only the payload TYPE moves to the shared file;
|
|
405
|
+
// • QUERIES — the top-level `watch<Q>`/`read<Q>` accessors.
|
|
406
|
+
// Per-domain files SKIP each and IMPORT the shared file; clients RE-EXPORT it (Dart de-dups the
|
|
407
|
+
// same-library re-export). So a barrel over all domains needs NO `hide` clause.
|
|
408
|
+
type ModDirective = DomainModule["directives"][number];
|
|
409
|
+
type ModQuery = NonNullable<DomainModule["queries"]>[number];
|
|
410
|
+
const frameworkAggById = new Map<string, AggregateHandle>();
|
|
411
|
+
const frameworkDirById = new Map<string, ModDirective>();
|
|
412
|
+
const frameworkQueryById = new Map<string, ModQuery>();
|
|
393
413
|
for (const mod of modules) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
414
|
+
for (const a of mod.aggregates) if (isFrameworkAggregate(a)) frameworkAggById.set(a.id, a);
|
|
415
|
+
for (const d of mod.directives) if (isFrameworkDirective(d)) frameworkDirById.set(d.id, d);
|
|
416
|
+
for (const q of mod.queries ?? []) if (isFrameworkQuery(q)) frameworkQueryById.set(q.id, q);
|
|
417
|
+
}
|
|
418
|
+
const frameworkAggs = [...frameworkAggById.values()];
|
|
419
|
+
const frameworkDirs = [...frameworkDirById.values()];
|
|
420
|
+
const frameworkQueries = [...frameworkQueryById.values()];
|
|
421
|
+
const frameworkAggIds: ReadonlySet<string> = new Set(frameworkAggById.keys());
|
|
422
|
+
const frameworkDirIds: ReadonlySet<string> = new Set(frameworkDirById.keys());
|
|
423
|
+
const frameworkQueryIds: ReadonlySet<string> = new Set(frameworkQueryById.keys());
|
|
424
|
+
const hasFrameworkSymbols =
|
|
425
|
+
frameworkAggs.length > 0 || frameworkDirs.length > 0 || frameworkQueries.length > 0;
|
|
426
|
+
const FRAMEWORK_FILE = "nomos_framework";
|
|
427
|
+
const frameworkImportUri = hasFrameworkSymbols ? `${FRAMEWORK_FILE}.dart` : undefined;
|
|
428
|
+
|
|
429
|
+
const written: string[] = [];
|
|
430
|
+
|
|
431
|
+
const writeGenerated = (fileBase: string, src: string): string => {
|
|
402
432
|
if (!src.includes(DART_PACKAGE_IMPORT)) {
|
|
403
433
|
fail(
|
|
404
|
-
`generated Dart for
|
|
434
|
+
`generated Dart for '${fileBase}' does not carry the expected support import (${DART_PACKAGE_IMPORT}) — codegen_dart header drifted; fix the rewrite in compile_package_main.ts`,
|
|
405
435
|
);
|
|
406
436
|
}
|
|
407
|
-
const p = path.join(dartOut, `${
|
|
437
|
+
const p = path.join(dartOut, `${fileBase}.dart`);
|
|
408
438
|
writeFileSync(
|
|
409
439
|
p,
|
|
410
440
|
supportImport === "vendored" ? src.replace(DART_PACKAGE_IMPORT, DART_RELATIVE_IMPORT) : src,
|
|
411
441
|
"utf8",
|
|
412
442
|
);
|
|
413
443
|
written.push(p);
|
|
444
|
+
return p;
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
// 2a. the shared framework file — the framework aggregates + directives + queries, ONCE. Its own
|
|
448
|
+
// surface is emitted in full (no skip). Imported by every domain that folds any framework symbol.
|
|
449
|
+
if (hasFrameworkSymbols) {
|
|
450
|
+
const frameworkMod: DomainModule = {
|
|
451
|
+
name: FRAMEWORK_FILE,
|
|
452
|
+
domain: FRAMEWORK_FILE,
|
|
453
|
+
aggregates: frameworkAggs,
|
|
454
|
+
directives: frameworkDirs,
|
|
455
|
+
readModelAggregates: frameworkAggs.map((a) => a.id),
|
|
456
|
+
...(frameworkQueries.length > 0 ? { queries: frameworkQueries } : {}),
|
|
457
|
+
};
|
|
458
|
+
writeGenerated(FRAMEWORK_FILE, generateDartDomain(frameworkMod));
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// 2b. one generated file per composed domain — the TYPES (`<name>.dart`) + the async bridge
|
|
462
|
+
// CLIENT (`<name>.client.dart`, the Flutter sibling of `<name>.client.ts`).
|
|
463
|
+
for (const mod of modules) {
|
|
464
|
+
// Default the read-model allowlist to EVERY aggregate when the domain didn't pin one, so
|
|
465
|
+
// `<name>.dart` carries a read model per aggregate — the bridge client imports them. A domain
|
|
466
|
+
// that pins `readModelAggregates` keeps its choice (byte-identical to before this default).
|
|
467
|
+
const modForDart: DomainModule =
|
|
468
|
+
mod.readModelAggregates === undefined
|
|
469
|
+
? { ...mod, readModelAggregates: mod.aggregates.map((a) => a.id) }
|
|
470
|
+
: mod;
|
|
471
|
+
// Skip framework symbols this domain folds (they live in the shared file); reference them via the
|
|
472
|
+
// framework import. Only pass the import when this domain actually folds a framework symbol.
|
|
473
|
+
const domainFwAggIds = new Set(
|
|
474
|
+
modForDart.aggregates.filter((a) => frameworkAggIds.has(a.id)).map((a) => a.id),
|
|
475
|
+
);
|
|
476
|
+
const domainFwDirIds = new Set(
|
|
477
|
+
modForDart.directives.filter((d) => frameworkDirIds.has(d.id)).map((d) => d.id),
|
|
478
|
+
);
|
|
479
|
+
const domainFwQueryIds = new Set(
|
|
480
|
+
(modForDart.queries ?? []).filter((q) => frameworkQueryIds.has(q.id)).map((q) => q.id),
|
|
481
|
+
);
|
|
482
|
+
const foldsFramework = domainFwAggIds.size > 0 || domainFwDirIds.size > 0 || domainFwQueryIds.size > 0;
|
|
483
|
+
const domainFrameworkImport = foldsFramework ? frameworkImportUri : undefined;
|
|
484
|
+
const src = generateDartDomain(modForDart, {
|
|
485
|
+
skipAggregateIds: domainFwAggIds,
|
|
486
|
+
skipDirectiveIds: domainFwDirIds,
|
|
487
|
+
skipQueryIds: domainFwQueryIds,
|
|
488
|
+
...(domainFrameworkImport !== undefined ? { frameworkImportUri: domainFrameworkImport } : {}),
|
|
489
|
+
});
|
|
490
|
+
writeGenerated(mod.name, src);
|
|
414
491
|
|
|
415
492
|
const clientSrc = generateDartBridgeClient(modForDart, {
|
|
416
493
|
domainHash,
|
|
417
494
|
interface: packageInterface[modForDart.domain ?? modForDart.name],
|
|
418
495
|
supportImport,
|
|
496
|
+
...(domainFrameworkImport !== undefined ? { frameworkImportUri: domainFrameworkImport } : {}),
|
|
419
497
|
});
|
|
420
498
|
const cp = path.join(dartOut, `${mod.name}.client.dart`);
|
|
421
499
|
writeFileSync(cp, clientSrc, "utf8");
|
package/src/directive.ts
CHANGED
|
@@ -71,6 +71,16 @@ export interface Directive<P = unknown> {
|
|
|
71
71
|
readonly aggregateId: string;
|
|
72
72
|
readonly payloadSchema: z.ZodType<P>;
|
|
73
73
|
readonly plan: (payload: P, ctx: Ports) => PlannedOp[];
|
|
74
|
+
/**
|
|
75
|
+
* FRAMEWORK-SHARED brand (Dart-codegen hygiene). Set (by `framework/framework_aggregates.ts`) ONLY on
|
|
76
|
+
* the framework-owned directive singletons declared in `dsl/src/framework/` (the relate/signer/enroll
|
|
77
|
+
* family — `relateSubject`, `enrollDelegation`, `advanceSignerEpoch`, …) which fold into MANY domains.
|
|
78
|
+
* A branded directive's generated Dart PAYLOAD TYPE (`EnrollDelegationPayload`, …) + any minted-create
|
|
79
|
+
* factory is emitted ONCE per package into the shared `nomos_framework.dart`, NOT re-emitted in each
|
|
80
|
+
* domain's `.dart` — so a package barrel re-exporting several domains never gets a duplicate payload
|
|
81
|
+
* class (no hand-maintained `hide` clause). NOT hashed / NOT law: a pure frontend-codegen marker.
|
|
82
|
+
* Identified by OBJECT IDENTITY, so a tenant directive that merely shares a name is never misclassified. */
|
|
83
|
+
readonly framework?: true;
|
|
74
84
|
/**
|
|
75
85
|
* Human-readable description of what this directive does — the SINGLE source of
|
|
76
86
|
* the hover-doc text codegen emits onto each generated payload class + ctor (so
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// NOMOS — Nomos Sovereign: participants act · verify · remember LOCALLY; hosted
|
|
2
|
+
// remotes are replaceable custody/transport, not truth. ⇒ ONE Nomos GitHolon wasm.
|
|
3
|
+
// If a file isn't this / hosting this / authoring for this / proving this — it's gone.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* THE FRAMEWORK-SYMBOL REGISTRY (Dart-codegen hygiene).
|
|
7
|
+
*
|
|
8
|
+
* Some DSL symbols are FRAMEWORK-owned + framework-SHARED: they are declared once in
|
|
9
|
+
* `dsl/src/framework/` and folded into MANY tenant domains. Three kinds collide in generated Dart:
|
|
10
|
+
*
|
|
11
|
+
* • AGGREGATES — `RelationTuple` (auto-added to EVERY relation-using domain), plus `SignerDelegation`,
|
|
12
|
+
* `KeyScope`, `WrappedKey`, `HomeOwner`, `WorkspaceSelf`, … re-exported verbatim so their events fold.
|
|
13
|
+
* Each emits a read-model class + typed-id class + by-id accessors → `RelationTupleReadModel`,
|
|
14
|
+
* `SignerDelegationId`, `watchSignerDelegationById`, … DEFINED per domain.
|
|
15
|
+
* • DIRECTIVES — the relate/signer/enroll family (`relateSubject`, `enrollDelegation`,
|
|
16
|
+
* `advanceSignerEpoch`, …) fold into many domains; each emits a payload class → `EnrollDelegationPayload`
|
|
17
|
+
* DEFINED per domain.
|
|
18
|
+
* • QUERIES — `signerDelegationByUser`, `relationTuplesByObject`, … emit top-level `watch<Q>`/`read<Q>`
|
|
19
|
+
* accessors → `readSignerDelegationByUser`, `watchSignerDelegationByUser` DEFINED per domain.
|
|
20
|
+
*
|
|
21
|
+
* A package barrel re-exporting ≥2 domains COLLIDES on every such symbol — the historical band-aid was a
|
|
22
|
+
* hand-maintained `hide RelationTuple, EnrollDelegationPayload, readSignerDelegationByUser, …` clause on
|
|
23
|
+
* the tenant barrel. The fix: BRAND the framework SINGLETONS here (once, at module load) so the codegen
|
|
24
|
+
* emits their Dart surface EXACTLY ONCE per package (into the shared `nomos_framework.dart`) and SKIPS
|
|
25
|
+
* re-emitting them in each domain. Identification is by OBJECT IDENTITY (the brand rides the branded
|
|
26
|
+
* singleton), so a tenant symbol that merely SHARES a name is NEVER misclassified.
|
|
27
|
+
*
|
|
28
|
+
* FRONTEND CODEGEN ONLY — the brand is never hashed and never enters the USD IR / read manifest / law
|
|
29
|
+
* (identical guarantee to `readModelAggregates`). Deterministic: the registry is derived from the actual
|
|
30
|
+
* framework exports, not a hand-kept string list.
|
|
31
|
+
*/
|
|
32
|
+
import type { AggregateHandle } from "../aggregate.js";
|
|
33
|
+
import type { Directive } from "../directive.js";
|
|
34
|
+
import type { QueryDecl } from "../query.js";
|
|
35
|
+
import * as disclosure from "./disclosure.js";
|
|
36
|
+
import * as domainLifecycle from "./domain_lifecycle.js";
|
|
37
|
+
import * as encryptionIdentity from "./encryption_identity.js";
|
|
38
|
+
import * as encryptionScope from "./encryption_scope.js";
|
|
39
|
+
import * as genesis from "./genesis.js";
|
|
40
|
+
import * as home from "./home.js";
|
|
41
|
+
import * as identity from "./identity.js";
|
|
42
|
+
import * as relations from "./relations.js";
|
|
43
|
+
import * as repair from "./repair.js";
|
|
44
|
+
import * as signingIdentity from "./signing_identity.js";
|
|
45
|
+
import * as workspaces from "./workspaces.js";
|
|
46
|
+
|
|
47
|
+
// Every framework module that DECLARES aggregate / directive / query singletons. Namespace imports so
|
|
48
|
+
// the registry is derived from the real exports (no hand-kept id list to drift).
|
|
49
|
+
const FRAMEWORK_NAMESPACES: ReadonlyArray<Record<string, unknown>> = [
|
|
50
|
+
disclosure,
|
|
51
|
+
domainLifecycle,
|
|
52
|
+
encryptionIdentity,
|
|
53
|
+
encryptionScope,
|
|
54
|
+
genesis,
|
|
55
|
+
home,
|
|
56
|
+
identity,
|
|
57
|
+
relations,
|
|
58
|
+
repair,
|
|
59
|
+
signingIdentity,
|
|
60
|
+
workspaces,
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
function isAggregateHandle(v: unknown): v is AggregateHandle {
|
|
64
|
+
return (
|
|
65
|
+
typeof v === "object" &&
|
|
66
|
+
v !== null &&
|
|
67
|
+
(v as { __isAggregateHandle?: unknown }).__isAggregateHandle === true
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// A finished Directive duck-type ({id, plan, aggregateId}) — the SAME shape `directivesOf` discovers.
|
|
72
|
+
function isDirective(v: unknown): v is Directive {
|
|
73
|
+
return (
|
|
74
|
+
typeof v === "object" &&
|
|
75
|
+
v !== null &&
|
|
76
|
+
typeof (v as { id?: unknown }).id === "string" &&
|
|
77
|
+
typeof (v as { plan?: unknown }).plan === "function" &&
|
|
78
|
+
typeof (v as { aggregateId?: unknown }).aggregateId === "string"
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// A finished QueryDecl duck-type ({id, key:[], returns:""}). Distinct from the un-keyed builder
|
|
83
|
+
// (`KeylessQuery.key` is a FUNCTION); here `key` is an array and `returns` a string.
|
|
84
|
+
function isQueryDecl(v: unknown): v is QueryDecl {
|
|
85
|
+
return (
|
|
86
|
+
typeof v === "object" &&
|
|
87
|
+
v !== null &&
|
|
88
|
+
typeof (v as { id?: unknown }).id === "string" &&
|
|
89
|
+
Array.isArray((v as { key?: unknown }).key) &&
|
|
90
|
+
typeof (v as { returns?: unknown }).returns === "string"
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const aggregateIds = new Set<string>();
|
|
95
|
+
const directiveIds = new Set<string>();
|
|
96
|
+
const queryIds = new Set<string>();
|
|
97
|
+
|
|
98
|
+
// Brand every framework singleton at module load. Mutating the readonly `framework` slot on the
|
|
99
|
+
// singleton is intentional: the branded object IS the one that flows through composition
|
|
100
|
+
// (`composeDomainModule` keeps the discovered aggregate/directive/query object references; a tenant
|
|
101
|
+
// re-exports the framework singleton verbatim), so the brand rides object identity everywhere.
|
|
102
|
+
for (const ns of FRAMEWORK_NAMESPACES) {
|
|
103
|
+
for (const v of Object.values(ns)) {
|
|
104
|
+
if (isAggregateHandle(v)) {
|
|
105
|
+
(v as { framework?: true }).framework = true;
|
|
106
|
+
aggregateIds.add(v.id);
|
|
107
|
+
} else if (isDirective(v)) {
|
|
108
|
+
(v as { framework?: true }).framework = true;
|
|
109
|
+
directiveIds.add(v.id);
|
|
110
|
+
} else if (isQueryDecl(v)) {
|
|
111
|
+
(v as { framework?: true }).framework = true;
|
|
112
|
+
queryIds.add(v.id);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export const FRAMEWORK_AGGREGATE_IDS: ReadonlySet<string> = aggregateIds;
|
|
118
|
+
export const FRAMEWORK_DIRECTIVE_IDS: ReadonlySet<string> = directiveIds;
|
|
119
|
+
export const FRAMEWORK_QUERY_IDS: ReadonlySet<string> = queryIds;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* TRUE iff this aggregate is a framework-shared singleton whose Dart surface is emitted ONCE per
|
|
123
|
+
* package (in `nomos_framework.dart`). By the BRAND (object identity) — a tenant aggregate that
|
|
124
|
+
* happens to share an id is NOT a framework aggregate.
|
|
125
|
+
*/
|
|
126
|
+
export function isFrameworkAggregate(agg: Pick<AggregateHandle, "framework">): boolean {
|
|
127
|
+
return agg.framework === true;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** TRUE iff this directive is a framework-shared singleton (its payload class lives in the shared file). */
|
|
131
|
+
export function isFrameworkDirective(d: Pick<Directive, "framework">): boolean {
|
|
132
|
+
return d.framework === true;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** TRUE iff this query is a framework-shared singleton (its accessors live in the shared file). */
|
|
136
|
+
export function isFrameworkQuery(q: Pick<QueryDecl, "framework">): boolean {
|
|
137
|
+
return q.framework === true;
|
|
138
|
+
}
|
package/src/query.ts
CHANGED
|
@@ -67,6 +67,16 @@ export interface QueryDecl {
|
|
|
67
67
|
readonly key: string[];
|
|
68
68
|
/** The aggregate TYPE id the query returns, e.g. `SampleThingAggregate`. */
|
|
69
69
|
readonly returns: string;
|
|
70
|
+
/**
|
|
71
|
+
* FRAMEWORK-SHARED brand (Dart-codegen hygiene). Set (by `framework/framework_aggregates.ts`) ONLY on
|
|
72
|
+
* the framework-owned query singletons declared in `dsl/src/framework/` (`signerDelegationByUser`,
|
|
73
|
+
* `relationTuplesByObject`, …) which fold into MANY domains. A branded query's generated top-level
|
|
74
|
+
* `watch<Q>`/`read<Q>` accessors are emitted ONCE per package into the shared `nomos_framework.dart`,
|
|
75
|
+
* NOT re-emitted in each domain's `.dart` — so a package barrel re-exporting several domains never gets
|
|
76
|
+
* duplicate accessors (no hand-maintained `hide` clause). NOT hashed / NOT law: a pure frontend-codegen
|
|
77
|
+
* marker (never enters the read manifest / USD IR). Identified by OBJECT IDENTITY, so a tenant query
|
|
78
|
+
* that merely shares a name is never misclassified. */
|
|
79
|
+
readonly framework?: true;
|
|
70
80
|
}
|
|
71
81
|
|
|
72
82
|
/**
|