@fougere/schema 0.1.0-alpha.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.
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/entity.d.ts +117 -0
- package/dist/entity.d.ts.map +1 -0
- package/dist/entity.js +285 -0
- package/dist/entity.js.map +1 -0
- package/dist/field/boundary.d.ts +75 -0
- package/dist/field/boundary.d.ts.map +1 -0
- package/dist/field/boundary.js +76 -0
- package/dist/field/boundary.js.map +1 -0
- package/dist/field/field.d.ts +64 -0
- package/dist/field/field.d.ts.map +1 -0
- package/dist/field/field.js +28 -0
- package/dist/field/field.js.map +1 -0
- package/dist/field/index.d.ts +7 -0
- package/dist/field/index.d.ts.map +1 -0
- package/dist/field/index.js +9 -0
- package/dist/field/index.js.map +1 -0
- package/dist/field/lifecycle.d.ts +40 -0
- package/dist/field/lifecycle.d.ts.map +1 -0
- package/dist/field/lifecycle.js +27 -0
- package/dist/field/lifecycle.js.map +1 -0
- package/dist/field/meta.d.ts +9 -0
- package/dist/field/meta.d.ts.map +1 -0
- package/dist/field/meta.js +7 -0
- package/dist/field/meta.js.map +1 -0
- package/dist/field/role.d.ts +54 -0
- package/dist/field/role.d.ts.map +1 -0
- package/dist/field/role.js +55 -0
- package/dist/field/role.js.map +1 -0
- package/dist/field/shape.d.ts +77 -0
- package/dist/field/shape.d.ts.map +1 -0
- package/dist/field/shape.js +49 -0
- package/dist/field/shape.js.map +1 -0
- package/dist/hints.d.ts +33 -0
- package/dist/hints.d.ts.map +1 -0
- package/dist/hints.js +2 -0
- package/dist/hints.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/projections/card.d.ts +117 -0
- package/dist/projections/card.d.ts.map +1 -0
- package/dist/projections/card.js +8 -0
- package/dist/projections/card.js.map +1 -0
- package/dist/projections/describe.d.ts +25 -0
- package/dist/projections/describe.d.ts.map +1 -0
- package/dist/projections/describe.js +129 -0
- package/dist/projections/describe.js.map +1 -0
- package/dist/projections/encode.d.ts +11 -0
- package/dist/projections/encode.d.ts.map +1 -0
- package/dist/projections/encode.js +26 -0
- package/dist/projections/encode.js.map +1 -0
- package/dist/projections/io.d.ts +30 -0
- package/dist/projections/io.d.ts.map +1 -0
- package/dist/projections/io.js +52 -0
- package/dist/projections/io.js.map +1 -0
- package/dist/projections/lifecycle.d.ts +43 -0
- package/dist/projections/lifecycle.d.ts.map +1 -0
- package/dist/projections/lifecycle.js +115 -0
- package/dist/projections/lifecycle.js.map +1 -0
- package/dist/projections/reconstruct.d.ts +36 -0
- package/dist/projections/reconstruct.d.ts.map +1 -0
- package/dist/projections/reconstruct.js +149 -0
- package/dist/projections/reconstruct.js.map +1 -0
- package/dist/projections/source.d.ts +41 -0
- package/dist/projections/source.d.ts.map +1 -0
- package/dist/projections/source.js +37 -0
- package/dist/projections/source.js.map +1 -0
- package/dist/projections/standard.d.ts +41 -0
- package/dist/projections/standard.d.ts.map +1 -0
- package/dist/projections/standard.js +10 -0
- package/dist/projections/standard.js.map +1 -0
- package/dist/projections/typescript.d.ts +53 -0
- package/dist/projections/typescript.d.ts.map +1 -0
- package/dist/projections/typescript.js +166 -0
- package/dist/projections/typescript.js.map +1 -0
- package/dist/projections/validation.d.ts +49 -0
- package/dist/projections/validation.d.ts.map +1 -0
- package/dist/projections/validation.js +140 -0
- package/dist/projections/validation.js.map +1 -0
- package/dist/unique.d.ts +65 -0
- package/dist/unique.d.ts.map +1 -0
- package/dist/unique.js +80 -0
- package/dist/unique.js.map +1 -0
- package/dist/vocabulary/auto.d.ts +8 -0
- package/dist/vocabulary/auto.d.ts.map +1 -0
- package/dist/vocabulary/auto.js +13 -0
- package/dist/vocabulary/auto.js.map +1 -0
- package/dist/vocabulary/bool.d.ts +6 -0
- package/dist/vocabulary/bool.d.ts.map +1 -0
- package/dist/vocabulary/bool.js +9 -0
- package/dist/vocabulary/bool.js.map +1 -0
- package/dist/vocabulary/date.d.ts +3 -0
- package/dist/vocabulary/date.d.ts.map +1 -0
- package/dist/vocabulary/date.js +5 -0
- package/dist/vocabulary/date.js.map +1 -0
- package/dist/vocabulary/email.d.ts +5 -0
- package/dist/vocabulary/email.d.ts.map +1 -0
- package/dist/vocabulary/email.js +6 -0
- package/dist/vocabulary/email.js.map +1 -0
- package/dist/vocabulary/immutable.d.ts +9 -0
- package/dist/vocabulary/immutable.d.ts.map +1 -0
- package/dist/vocabulary/immutable.js +11 -0
- package/dist/vocabulary/immutable.js.map +1 -0
- package/dist/vocabulary/indexed.d.ts +19 -0
- package/dist/vocabulary/indexed.d.ts.map +1 -0
- package/dist/vocabulary/indexed.js +21 -0
- package/dist/vocabulary/indexed.js.map +1 -0
- package/dist/vocabulary/json.d.ts +18 -0
- package/dist/vocabulary/json.d.ts.map +1 -0
- package/dist/vocabulary/json.js +16 -0
- package/dist/vocabulary/json.js.map +1 -0
- package/dist/vocabulary/list.d.ts +21 -0
- package/dist/vocabulary/list.d.ts.map +1 -0
- package/dist/vocabulary/list.js +21 -0
- package/dist/vocabulary/list.js.map +1 -0
- package/dist/vocabulary/many.d.ts +8 -0
- package/dist/vocabulary/many.d.ts.map +1 -0
- package/dist/vocabulary/many.js +12 -0
- package/dist/vocabulary/many.js.map +1 -0
- package/dist/vocabulary/nullable.d.ts +9 -0
- package/dist/vocabulary/nullable.d.ts.map +1 -0
- package/dist/vocabulary/nullable.js +13 -0
- package/dist/vocabulary/nullable.js.map +1 -0
- package/dist/vocabulary/number.d.ts +10 -0
- package/dist/vocabulary/number.d.ts.map +1 -0
- package/dist/vocabulary/number.js +9 -0
- package/dist/vocabulary/number.js.map +1 -0
- package/dist/vocabulary/oneOf.d.ts +16 -0
- package/dist/vocabulary/oneOf.d.ts.map +1 -0
- package/dist/vocabulary/oneOf.js +13 -0
- package/dist/vocabulary/oneOf.js.map +1 -0
- package/dist/vocabulary/optional.d.ts +10 -0
- package/dist/vocabulary/optional.d.ts.map +1 -0
- package/dist/vocabulary/optional.js +15 -0
- package/dist/vocabulary/optional.js.map +1 -0
- package/dist/vocabulary/primary.d.ts +22 -0
- package/dist/vocabulary/primary.d.ts.map +1 -0
- package/dist/vocabulary/primary.js +31 -0
- package/dist/vocabulary/primary.js.map +1 -0
- package/dist/vocabulary/readOnly.d.ts +10 -0
- package/dist/vocabulary/readOnly.d.ts.map +1 -0
- package/dist/vocabulary/readOnly.js +12 -0
- package/dist/vocabulary/readOnly.js.map +1 -0
- package/dist/vocabulary/ref.d.ts +12 -0
- package/dist/vocabulary/ref.d.ts.map +1 -0
- package/dist/vocabulary/ref.js +20 -0
- package/dist/vocabulary/ref.js.map +1 -0
- package/dist/vocabulary/text.d.ts +12 -0
- package/dist/vocabulary/text.d.ts.map +1 -0
- package/dist/vocabulary/text.js +9 -0
- package/dist/vocabulary/text.js.map +1 -0
- package/dist/vocabulary/unique.d.ts +23 -0
- package/dist/vocabulary/unique.d.ts.map +1 -0
- package/dist/vocabulary/unique.js +25 -0
- package/dist/vocabulary/unique.js.map +1 -0
- package/dist/vocabulary/updated.d.ts +8 -0
- package/dist/vocabulary/updated.d.ts.map +1 -0
- package/dist/vocabulary/updated.js +12 -0
- package/dist/vocabulary/updated.js.map +1 -0
- package/dist/vocabulary/url.d.ts +5 -0
- package/dist/vocabulary/url.d.ts.map +1 -0
- package/dist/vocabulary/url.js +6 -0
- package/dist/vocabulary/url.js.map +1 -0
- package/dist/vocabulary/writeOnly.d.ts +9 -0
- package/dist/vocabulary/writeOnly.d.ts.map +1 -0
- package/dist/vocabulary/writeOnly.js +11 -0
- package/dist/vocabulary/writeOnly.js.map +1 -0
- package/package.json +40 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// ─── The primitive — a Field on four orthogonal axes + meta ──
|
|
2
|
+
export { isField, cloneField, nullableShape, anatomy,
|
|
3
|
+
// The constraint a `role.unique` member list denotes — `[]` means the field carrying it.
|
|
4
|
+
uniqueMembers, isNullable, registerGenerator, resolveCustomGenerator, resolveBoundary, declaredBoundary, boundaryOf, registerDecoder, registerEncoder, registerBoundaryAlias, } from './field/index.js';
|
|
5
|
+
// ─── The carrier and its derivation algebra ──────────────────
|
|
6
|
+
export { entity, compose, createSchemaConstructor, ANONYMOUS_SCHEMA_NAME, } from './entity.js';
|
|
7
|
+
// ─── The vocabulary — field constructors and transforms ──────
|
|
8
|
+
export { primary } from './vocabulary/primary.js';
|
|
9
|
+
export { text } from './vocabulary/text.js';
|
|
10
|
+
export { email } from './vocabulary/email.js';
|
|
11
|
+
export { url } from './vocabulary/url.js';
|
|
12
|
+
export { list } from './vocabulary/list.js';
|
|
13
|
+
export { number } from './vocabulary/number.js';
|
|
14
|
+
export { bool } from './vocabulary/bool.js';
|
|
15
|
+
export { date } from './vocabulary/date.js';
|
|
16
|
+
export { auto } from './vocabulary/auto.js';
|
|
17
|
+
export { updated } from './vocabulary/updated.js';
|
|
18
|
+
export { oneOf } from './vocabulary/oneOf.js';
|
|
19
|
+
export { ref } from './vocabulary/ref.js';
|
|
20
|
+
export { many } from './vocabulary/many.js';
|
|
21
|
+
export { optional } from './vocabulary/optional.js';
|
|
22
|
+
export { nullable } from './vocabulary/nullable.js';
|
|
23
|
+
export { immutable } from './vocabulary/immutable.js';
|
|
24
|
+
export { unique } from './vocabulary/unique.js';
|
|
25
|
+
export { indexed } from './vocabulary/indexed.js';
|
|
26
|
+
export { readOnly } from './vocabulary/readOnly.js';
|
|
27
|
+
export { writeOnly } from './vocabulary/writeOnly.js';
|
|
28
|
+
export { json } from './vocabulary/json.js';
|
|
29
|
+
// ─── Projections — consumers of the axes ─────────────────────
|
|
30
|
+
// lifecycle: the axis → the values the system writes. The dual of validation — the
|
|
31
|
+
// judge never fills a hole, this is what fills it, and a storage adapter calls it
|
|
32
|
+
// instead of re-deriving the rule.
|
|
33
|
+
export { applyCreate, applyUpdate } from './projections/lifecycle.js';
|
|
34
|
+
// validation: shape → ingress predicate (+ boundary decode)
|
|
35
|
+
export { validateFields, checkValue } from './projections/validation.js';
|
|
36
|
+
// encode: boundary → egress wire form (the dual of validation)
|
|
37
|
+
export { encodeFields } from './projections/encode.js';
|
|
38
|
+
// io: the dual client-surface projections — ingress (may supply) / egress (may read)
|
|
39
|
+
export { inputFields, outputFields } from './projections/io.js';
|
|
40
|
+
// descriptor (the card): the portable, serialisable identity of a schema
|
|
41
|
+
export { describe, describeSet, sourceNameOf } from './projections/describe.js';
|
|
42
|
+
export { reconstruct, reconstructSet } from './projections/reconstruct.js';
|
|
43
|
+
export { shapeTypeOf, entitySourceOf, facadeTypeSourceOf } from './projections/typescript.js';
|
|
44
|
+
// source: the one reader that takes a live class OR a card — what an adapter stands on
|
|
45
|
+
export { schemaOf, fieldsOf, uniqueOf } from './projections/source.js';
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,OAAO,EAmBL,OAAO,EACP,UAAU,EACV,aAAa,EACb,OAAO;AACP,yFAAyF;AACzF,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,eAAe,EACf,qBAAqB,GAMtB,MAAM,kBAAkB,CAAC;AAE1B,gEAAgE;AAChE,OAAO,EACL,MAAM,EACN,OAAO,EACP,uBAAuB,EACvB,qBAAqB,GAItB,MAAM,aAAa,CAAC;AAIrB,gEAAgE;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAoB,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAoB,MAAM,sBAAsB,CAAC;A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,MAAM,2BAA2B,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,kBAAkB,EAA6C,MAAM,6BAA6B,CAAC;AAUzI,uFAAuF;AACvF,OAAO,EAAqB,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { BoundaryRef, Lifecycle } from '../field/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The portable schema descriptor — Fougère's "carte d'identité" of an entity.
|
|
4
|
+
*
|
|
5
|
+
* It is a JSON Schema document (the `shape` axis, a near-identity projection now
|
|
6
|
+
* that {@link FieldDescriptor} already speaks JSON Schema) carrying the three axes JSON
|
|
7
|
+
* Schema cannot express under a single `x-fougere` extension key per field: `role`
|
|
8
|
+
* (identity/relations), `lifecycle` (write rules), `boundary` (wire↔domain).
|
|
9
|
+
* The normal forms (named tokens, pure JSON) ARE the wire form — lifecycle and
|
|
10
|
+
* boundary travel verbatim, no descriptor twin to maintain.
|
|
11
|
+
*
|
|
12
|
+
* It is the structural counterpart of Standard Schema (`~standard`): where
|
|
13
|
+
* `~standard` is the live, opaque "I can validate" interface, the descriptor is the
|
|
14
|
+
* transparent, serialisable description that crosses the wire. `describe()` produces
|
|
15
|
+
* it; a single `reconstruct()` reads it back into a working schema (validate + from).
|
|
16
|
+
*
|
|
17
|
+
* Honest losses vs the live field map — a reference becomes a name, a live function
|
|
18
|
+
* does not travel:
|
|
19
|
+
* - `role.relation.to` (a `() => Entity` thunk) → {@link RelationDescriptor.to}, a name.
|
|
20
|
+
* - a custom generator or boundary decoder/encoder travels by NAME, re-resolved
|
|
21
|
+
* against the consumer's registry ("unknown generator/alias" is loud and local).
|
|
22
|
+
*/
|
|
23
|
+
/** JSON Schema's `type` values, plus `null` for the nullable union form. */
|
|
24
|
+
export type JsonSchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
|
|
25
|
+
/**
|
|
26
|
+
* One field as a JSON Schema property. The shape keywords sit at the top level
|
|
27
|
+
* (so an external JSON Schema tool reads them directly); the Fougère-only axes
|
|
28
|
+
* live under `x-fougere`. A nullable field folds into the union `type: ['T','null']`.
|
|
29
|
+
*/
|
|
30
|
+
export interface FieldDescriptor {
|
|
31
|
+
type?: JsonSchemaType | JsonSchemaType[];
|
|
32
|
+
/** JSON Schema format predicate (`date-time` for a date value, email, uuid, uri…). */
|
|
33
|
+
format?: 'date-time' | 'date' | 'time' | 'email' | 'uuid' | 'uri';
|
|
34
|
+
enum?: readonly (string | null)[];
|
|
35
|
+
minLength?: number;
|
|
36
|
+
maxLength?: number;
|
|
37
|
+
pattern?: string;
|
|
38
|
+
minimum?: number;
|
|
39
|
+
maximum?: number;
|
|
40
|
+
/** A value list's element shape (`list(text())`). A bare `many` relation has none. */
|
|
41
|
+
items?: FieldDescriptor;
|
|
42
|
+
minItems?: number;
|
|
43
|
+
maxItems?: number;
|
|
44
|
+
/** An embedded value object (`json(Entity)`): the nested shape-only properties. */
|
|
45
|
+
properties?: Record<string, FieldDescriptor>;
|
|
46
|
+
/** The embedded object's required keys (JSON Schema nesting, travels verbatim). */
|
|
47
|
+
required?: readonly string[];
|
|
48
|
+
/** JSON Schema standard keyword — mirrors the field's `description`. */
|
|
49
|
+
description?: string;
|
|
50
|
+
'x-fougere'?: FieldExtension;
|
|
51
|
+
}
|
|
52
|
+
/** The three axes JSON Schema can't express, namespaced under a field's `x-fougere`. */
|
|
53
|
+
export interface FieldExtension {
|
|
54
|
+
role?: RoleDescriptor;
|
|
55
|
+
/** The normal form travels verbatim — named tokens, pure JSON. */
|
|
56
|
+
lifecycle?: Lifecycle;
|
|
57
|
+
boundary?: BoundaryRef;
|
|
58
|
+
}
|
|
59
|
+
export interface RoleDescriptor {
|
|
60
|
+
primary?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* The unique constraints this field is a member of — one member list each, member
|
|
63
|
+
* names spelled out. `[["slug"]]` is unique on its own; `[["listId","docId"]]` on both
|
|
64
|
+
* members says the pair is unique together, which is the fact a foreign consumer could
|
|
65
|
+
* not read before: the card carried one boolean per field and the pair vanished.
|
|
66
|
+
*
|
|
67
|
+
* Self-reference is resolved on the way out (a lone `unique()` holds `[]` in memory,
|
|
68
|
+
* because a field does not know its own key) — a card always names its members, so a
|
|
69
|
+
* reader never has to know which field a group hangs on.
|
|
70
|
+
*/
|
|
71
|
+
unique?: string[][];
|
|
72
|
+
index?: boolean;
|
|
73
|
+
relation?: RelationDescriptor;
|
|
74
|
+
}
|
|
75
|
+
/** A relation as portable data: the target is a NAME, not a live entity thunk. */
|
|
76
|
+
export interface RelationDescriptor {
|
|
77
|
+
to: string;
|
|
78
|
+
kind: 'one' | 'many';
|
|
79
|
+
onDelete?: 'cascade' | 'restrict' | 'set null';
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A whole entity as a JSON Schema object document. `version`/`vendor` mirror Standard
|
|
83
|
+
* Schema's own (versioned + vendored), under `x-` extension keywords so the document
|
|
84
|
+
* stays a valid JSON Schema for external tooling.
|
|
85
|
+
*/
|
|
86
|
+
export interface SchemaDescriptor {
|
|
87
|
+
/** The entity name. */
|
|
88
|
+
title?: string;
|
|
89
|
+
type: 'object';
|
|
90
|
+
properties: Record<string, FieldDescriptor>;
|
|
91
|
+
/**
|
|
92
|
+
* Create-time semantics: the names a caller MUST supply — no `lifecycle.create`
|
|
93
|
+
* rule answers absence (nor a `many` relation, absent → `[]`). Presence only:
|
|
94
|
+
* a nullable-but-required field IS listed (supply `null`, don't omit the key).
|
|
95
|
+
* Narrower than JSON Schema's context-free `required`: it answers "what must a
|
|
96
|
+
* creation payload carry?", not "what is always present when read?".
|
|
97
|
+
*/
|
|
98
|
+
required?: string[];
|
|
99
|
+
'x-fougere-version': 1;
|
|
100
|
+
'x-fougere-vendor': 'fougere';
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* A self-contained set of entity cards — a JSON Schema bundle. Every entity lives
|
|
104
|
+
* under `$defs`, keyed by name; a relation's `to` is that name — the `$ref` into
|
|
105
|
+
* `$defs`. The document is portable AND circular-safe: a relation is a pointer, never
|
|
106
|
+
* an inlined sub-schema, so `Post → Author → Post` is two references, not infinite
|
|
107
|
+
* nesting. `reconstructSet` resolves those `$ref`s so a synced relation hands back the
|
|
108
|
+
* real reconstructed target (it feeds adapters), not just a name.
|
|
109
|
+
*/
|
|
110
|
+
export interface SchemaBundle {
|
|
111
|
+
$defs: Record<string, SchemaDescriptor>;
|
|
112
|
+
'x-fougere-version': 1;
|
|
113
|
+
'x-fougere-vendor': 'fougere';
|
|
114
|
+
}
|
|
115
|
+
/** Drop keys whose value is `undefined`, so the descriptor stays clean JSON. */
|
|
116
|
+
export declare function clean<T extends Record<string, unknown>>(obj: T): T;
|
|
117
|
+
//# sourceMappingURL=card.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card.d.ts","sourceRoot":"","sources":["../../src/projections/card.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,4EAA4E;AAC5E,MAAM,MAAM,cAAc,GACtB,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,SAAS,GACT,QAAQ,GACR,OAAO,GACP,MAAM,CAAC;AAEX;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,cAAc,GAAG,cAAc,EAAE,CAAC;IACzC,sFAAsF;IACtF,MAAM,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;IAClE,IAAI,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;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Ae,CAAC,CAAC;IAC5C;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,mBAAmB,EAAE,CAAC,CAAC;IACvB,kBAAkB,EAAE,SAAS,CAAC;CAC/B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACxC,mBAAmB,EAAE,CAAC,CAAC;IACvB,kBAAkB,EAAE,SAAS,CAAC;CAC/B;AAED,gFAAgF;AAChF,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAGlE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card.js","sourceRoot":"","sources":["../../src/projections/card.ts"],"names":[],"mappings":"AAkIA,gFAAgF;AAChF,MAAM,UAAU,KAAK,CAAoC,GAAM;IAC7D,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS;YAAE,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;IAChF,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SchemaLike } from '../field/index.js';
|
|
2
|
+
import { type SchemaBundle, type SchemaDescriptor } from './card.js';
|
|
3
|
+
/**
|
|
4
|
+
* Produce the portable card for a schema — THE single canonical serialiser
|
|
5
|
+
* (the hand-rolled copies in adapters call this). `name` titles the entity; it
|
|
6
|
+
* falls back to the schema's source/class name when omitted.
|
|
7
|
+
*/
|
|
8
|
+
export declare function describe(schema: SchemaLike, name?: string): SchemaDescriptor;
|
|
9
|
+
/**
|
|
10
|
+
* The name of the schema a view came from — `Post` for `Post`, and `Post` for
|
|
11
|
+
* `Post.pick('title')` too, since a derivation carries its `source`.
|
|
12
|
+
*
|
|
13
|
+
* Exported because two projections need the SAME answer: the card titles an entity with it,
|
|
14
|
+
* and GraphQL names a field's enum type with it — an enum named after the view would give
|
|
15
|
+
* `Post.status` and `CreatePostInput.status` two incompatible types for one set of values.
|
|
16
|
+
*/
|
|
17
|
+
export declare function sourceNameOf(schema: SchemaLike): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Describe a whole set of entities as one self-contained bundle (the `$defs`
|
|
20
|
+
* document). Accepts a name→schema record or an array (names taken from the
|
|
21
|
+
* schemas). Keys are lowercased to match the relation `to` names `describe` emits,
|
|
22
|
+
* so `$ref`-by-name resolves cleanly in {@link reconstructSet}.
|
|
23
|
+
*/
|
|
24
|
+
export declare function describeSet(schemas: Record<string, SchemaLike> | SchemaLike[]): SchemaBundle;
|
|
25
|
+
//# sourceMappingURL=describe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"describe.d.ts","sourceRoot":"","sources":["../../src/projections/describe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpE,OAAO,EAML,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACtB,MAAM,WAAW,CAAC;AAkEnB;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAiB5E;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAGnE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,UAAU,EAAE,GAAG,YAAY,CAU5F"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { uniqueMembers } from '../field/index.js';
|
|
2
|
+
import { clean, } from './card.js';
|
|
3
|
+
// ─── describe — schema → card (the single canonical serialiser) ────
|
|
4
|
+
/**
|
|
5
|
+
* A caller must supply this field: no create rule answers absence, and it is not
|
|
6
|
+
* a `many` relation (absent → `[]`). Presence only — nullability is the OTHER
|
|
7
|
+
* axis: a `nullable()` field stays required (the caller may supply `null`, not
|
|
8
|
+
* omit the key), exactly what `validateFields` enforces.
|
|
9
|
+
*/
|
|
10
|
+
function isRequired(field) {
|
|
11
|
+
if (field.lifecycle?.create !== undefined)
|
|
12
|
+
return false;
|
|
13
|
+
if (field.role?.relation?.kind === 'many')
|
|
14
|
+
return false;
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
function describeRole(role, key) {
|
|
18
|
+
const out = {};
|
|
19
|
+
if (role.primary)
|
|
20
|
+
out.primary = true;
|
|
21
|
+
// Members are spelled out on the wire: in memory a lone `unique()` holds the empty
|
|
22
|
+
// self-reference (a field cannot name its own key), and a consumer has no way to know
|
|
23
|
+
// which field a group hangs on. `key` is that missing half, so it is resolved here.
|
|
24
|
+
if (role.unique?.length)
|
|
25
|
+
out.unique = role.unique.map((group) => uniqueMembers(group, key));
|
|
26
|
+
if (role.index)
|
|
27
|
+
out.index = true;
|
|
28
|
+
if (role.relation) {
|
|
29
|
+
out.relation = clean({
|
|
30
|
+
to: role.relation.to().name?.toLowerCase() ?? '', // thunk → name
|
|
31
|
+
kind: role.relation.kind,
|
|
32
|
+
onDelete: role.relation.onDelete,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return Object.keys(out).length ? out : undefined;
|
|
36
|
+
}
|
|
37
|
+
function describeExtension(field, key) {
|
|
38
|
+
const ext = {};
|
|
39
|
+
if (field.role)
|
|
40
|
+
ext.role = describeRole(field.role, key);
|
|
41
|
+
// The normal forms are named tokens, pure JSON — they travel verbatim
|
|
42
|
+
// (a custom generator travels by NAME, re-resolved against the consumer's registry).
|
|
43
|
+
if (field.lifecycle)
|
|
44
|
+
ext.lifecycle = field.lifecycle;
|
|
45
|
+
// Carry only an explicit override; the derived default (date → isoDate) is
|
|
46
|
+
// re-derived from `shape.format` on reconstruction (convention over config).
|
|
47
|
+
if (field.boundary !== undefined)
|
|
48
|
+
ext.boundary = field.boundary;
|
|
49
|
+
clean(ext);
|
|
50
|
+
return Object.keys(ext).length ? ext : undefined;
|
|
51
|
+
}
|
|
52
|
+
function describeField(field, key) {
|
|
53
|
+
const out = {};
|
|
54
|
+
// Shape is already JSON Schema's vocabulary — nullability included, as the
|
|
55
|
+
// `[T,'null']` type union — so its keywords copy verbatim (an embedded object's
|
|
56
|
+
// `properties`/`required` too, themselves shape-only).
|
|
57
|
+
if (field.shape) {
|
|
58
|
+
for (const [key, value] of Object.entries(field.shape)) {
|
|
59
|
+
if (value === undefined)
|
|
60
|
+
continue;
|
|
61
|
+
out[key] = value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (field.role?.relation?.kind === 'many') {
|
|
65
|
+
out.type = 'array';
|
|
66
|
+
}
|
|
67
|
+
if (field.meta?.description)
|
|
68
|
+
out.description = field.meta.description;
|
|
69
|
+
const ext = describeExtension(field, key);
|
|
70
|
+
if (ext)
|
|
71
|
+
out['x-fougere'] = ext;
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Produce the portable card for a schema — THE single canonical serialiser
|
|
76
|
+
* (the hand-rolled copies in adapters call this). `name` titles the entity; it
|
|
77
|
+
* falls back to the schema's source/class name when omitted.
|
|
78
|
+
*/
|
|
79
|
+
export function describe(schema, name) {
|
|
80
|
+
const properties = {};
|
|
81
|
+
const required = [];
|
|
82
|
+
for (const [key, field] of Object.entries(schema.getFields())) {
|
|
83
|
+
properties[key] = describeField(field, key);
|
|
84
|
+
if (isRequired(field))
|
|
85
|
+
required.push(key);
|
|
86
|
+
}
|
|
87
|
+
const descriptor = {
|
|
88
|
+
type: 'object',
|
|
89
|
+
properties,
|
|
90
|
+
'x-fougere-version': 1,
|
|
91
|
+
'x-fougere-vendor': 'fougere',
|
|
92
|
+
};
|
|
93
|
+
const title = name ?? sourceNameOf(schema);
|
|
94
|
+
if (title)
|
|
95
|
+
descriptor.title = title;
|
|
96
|
+
if (required.length)
|
|
97
|
+
descriptor.required = required;
|
|
98
|
+
return descriptor;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The name of the schema a view came from — `Post` for `Post`, and `Post` for
|
|
102
|
+
* `Post.pick('title')` too, since a derivation carries its `source`.
|
|
103
|
+
*
|
|
104
|
+
* Exported because two projections need the SAME answer: the card titles an entity with it,
|
|
105
|
+
* and GraphQL names a field's enum type with it — an enum named after the view would give
|
|
106
|
+
* `Post.status` and `CreatePostInput.status` two incompatible types for one set of values.
|
|
107
|
+
*/
|
|
108
|
+
export function sourceNameOf(schema) {
|
|
109
|
+
const s = schema;
|
|
110
|
+
return s.source?.name ?? s.name;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Describe a whole set of entities as one self-contained bundle (the `$defs`
|
|
114
|
+
* document). Accepts a name→schema record or an array (names taken from the
|
|
115
|
+
* schemas). Keys are lowercased to match the relation `to` names `describe` emits,
|
|
116
|
+
* so `$ref`-by-name resolves cleanly in {@link reconstructSet}.
|
|
117
|
+
*/
|
|
118
|
+
export function describeSet(schemas) {
|
|
119
|
+
const entries = Array.isArray(schemas)
|
|
120
|
+
? schemas.map((s) => [sourceNameOf(s) ?? '', s])
|
|
121
|
+
: Object.entries(schemas);
|
|
122
|
+
const $defs = {};
|
|
123
|
+
for (const [name, schema] of entries) {
|
|
124
|
+
const key = name.toLowerCase();
|
|
125
|
+
$defs[key] = describe(schema, key);
|
|
126
|
+
}
|
|
127
|
+
return { $defs, 'x-fougere-version': 1, 'x-fougere-vendor': 'fougere' };
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=describe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"describe.js","sourceRoot":"","sources":["../../src/projections/describe.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,aAAa,EAAE,MAAM,mBAAmB,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G,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QACpC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAU,CAAC;QACzD,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5B,MAAM,KAAK,GAAqC,EAAE,CAAC;IACnD,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAC/B,KAAK,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,mBAAmB,EAAE,CAAC,EAAE,kBAAkB,EAAE,SAAS,EAAE,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Fields } from '../field/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Egress: encode a domain record into its wire form, field by field — the dual of
|
|
4
|
+
* `validateFields` (which decodes on ingress). A write-only field (boundary
|
|
5
|
+
* `out: 'closed'`, e.g. a password) is OMITTED — it never crosses outbound.
|
|
6
|
+
* Keys absent from `fields` (e.g. presenter computed fields) pass through
|
|
7
|
+
* untouched; null/undefined are left as-is.
|
|
8
|
+
* Shallow by design: a relation's nested rows are not deep-encoded here.
|
|
9
|
+
*/
|
|
10
|
+
export declare function encodeFields(fields: Fields, record: Record<string, unknown>): Record<string, unknown>;
|
|
11
|
+
//# sourceMappingURL=encode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/projections/encode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGhD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAUrG"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { boundaryOf, resolveBoundary } from '../field/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Egress: encode a domain record into its wire form, field by field — the dual of
|
|
4
|
+
* `validateFields` (which decodes on ingress). A write-only field (boundary
|
|
5
|
+
* `out: 'closed'`, e.g. a password) is OMITTED — it never crosses outbound.
|
|
6
|
+
* Keys absent from `fields` (e.g. presenter computed fields) pass through
|
|
7
|
+
* untouched; null/undefined are left as-is.
|
|
8
|
+
* Shallow by design: a relation's nested rows are not deep-encoded here.
|
|
9
|
+
*/
|
|
10
|
+
export function encodeFields(fields, record) {
|
|
11
|
+
const out = { ...record };
|
|
12
|
+
for (const [key, field] of Object.entries(fields)) {
|
|
13
|
+
if (!(key in record))
|
|
14
|
+
continue;
|
|
15
|
+
if (boundaryOf(field).out === 'closed') {
|
|
16
|
+
delete out[key];
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const value = record[key];
|
|
20
|
+
if (value === null || value === undefined)
|
|
21
|
+
continue;
|
|
22
|
+
out[key] = resolveBoundary(field).encode(value);
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=encode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../src/projections/encode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEhE;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,MAA+B;IAC1E,MAAM,GAAG,GAA4B,EAAE,GAAG,MAAM,EAAE,CAAC;IACnD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,IAAI,CAAC,CAAC,GAAG,IAAI,MAAM,CAAC;YAAE,SAAS;QAC/B,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;YAAC,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;YAAC,SAAS;QAAC,CAAC;QACtE,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QACpD,GAAG,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Fields } from '../field/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The two dual projections of a field set onto a client surface — membership
|
|
4
|
+
* only, derived from the axes.
|
|
5
|
+
*
|
|
6
|
+
* The create/patch MODE never changes membership, it only changes omissibility, which
|
|
7
|
+
* the view (`partial()`) carries.
|
|
8
|
+
*
|
|
9
|
+
* ⚠️ The audience lives in this comment, not in the data — no axis says "client", so
|
|
10
|
+
* these two functions are the only place the word exists. Surfaces are SUPPOSED to read
|
|
11
|
+
* them instead of restating the rules, and several don't: the GraphQL public
|
|
12
|
+
* `registerInput`, the runtime judge and the CLI each answer "what may a client supply"
|
|
13
|
+
* with a different set. The judge is the most permissive — a client-forged primary key
|
|
14
|
+
* reaches the ORM. Reconciling them needs the audience to become data.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Ingress: what a CLIENT may supply. Excluded —
|
|
18
|
+
* - `role.primary` → identity is system-owned
|
|
19
|
+
* - `lifecycle.create === 'now'` → managed timestamps are stamped, not supplied
|
|
20
|
+
* - `role.relation.kind 'many'` → the collection lives on the other side
|
|
21
|
+
* - `boundary.in === 'closed'` → read-only, never accepted from a client
|
|
22
|
+
*/
|
|
23
|
+
export declare function inputFields(fields: Fields): Fields;
|
|
24
|
+
/**
|
|
25
|
+
* Egress: what a CLIENT may read. Excluded —
|
|
26
|
+
* - `boundary.out === 'closed'` → write-only (password), never emitted
|
|
27
|
+
* (`encodeFields` also omits them at runtime; types and payloads agree.)
|
|
28
|
+
*/
|
|
29
|
+
export declare function outputFields(fields: Fields): Fields;
|
|
30
|
+
//# sourceMappingURL=io.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../../src/projections/io.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGhD;;;;;;;;;;;;;GAaG;AAEH;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAUlD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAOnD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { boundaryOf } from '../field/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The two dual projections of a field set onto a client surface — membership
|
|
4
|
+
* only, derived from the axes.
|
|
5
|
+
*
|
|
6
|
+
* The create/patch MODE never changes membership, it only changes omissibility, which
|
|
7
|
+
* the view (`partial()`) carries.
|
|
8
|
+
*
|
|
9
|
+
* ⚠️ The audience lives in this comment, not in the data — no axis says "client", so
|
|
10
|
+
* these two functions are the only place the word exists. Surfaces are SUPPOSED to read
|
|
11
|
+
* them instead of restating the rules, and several don't: the GraphQL public
|
|
12
|
+
* `registerInput`, the runtime judge and the CLI each answer "what may a client supply"
|
|
13
|
+
* with a different set. The judge is the most permissive — a client-forged primary key
|
|
14
|
+
* reaches the ORM. Reconciling them needs the audience to become data.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Ingress: what a CLIENT may supply. Excluded —
|
|
18
|
+
* - `role.primary` → identity is system-owned
|
|
19
|
+
* - `lifecycle.create === 'now'` → managed timestamps are stamped, not supplied
|
|
20
|
+
* - `role.relation.kind 'many'` → the collection lives on the other side
|
|
21
|
+
* - `boundary.in === 'closed'` → read-only, never accepted from a client
|
|
22
|
+
*/
|
|
23
|
+
export function inputFields(fields) {
|
|
24
|
+
const result = {};
|
|
25
|
+
for (const [name, field] of Object.entries(fields)) {
|
|
26
|
+
if (field.role?.primary)
|
|
27
|
+
continue;
|
|
28
|
+
if (field.lifecycle?.create === 'now')
|
|
29
|
+
continue;
|
|
30
|
+
if (field.role?.relation?.kind === 'many')
|
|
31
|
+
continue;
|
|
32
|
+
if (boundaryOf(field).in === 'closed')
|
|
33
|
+
continue;
|
|
34
|
+
result[name] = field;
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Egress: what a CLIENT may read. Excluded —
|
|
40
|
+
* - `boundary.out === 'closed'` → write-only (password), never emitted
|
|
41
|
+
* (`encodeFields` also omits them at runtime; types and payloads agree.)
|
|
42
|
+
*/
|
|
43
|
+
export function outputFields(fields) {
|
|
44
|
+
const result = {};
|
|
45
|
+
for (const [name, field] of Object.entries(fields)) {
|
|
46
|
+
if (boundaryOf(field).out === 'closed')
|
|
47
|
+
continue;
|
|
48
|
+
result[name] = field;
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=io.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"io.js","sourceRoot":"","sources":["../../src/projections/io.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C;;;;;;;;;;;;;GAaG;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,MAAM,MAAM,GAAW,EAAE,CAAC;IAC1B,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,IAAI,KAAK,CAAC,IAAI,EAAE,OAAO;YAAE,SAAS;QAClC,IAAI,KAAK,CAAC,SAAS,EAAE,MAAM,KAAK,KAAK;YAAE,SAAS;QAChD,IAAI,KAAK,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,KAAK,MAAM;YAAE,SAAS;QACpD,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,QAAQ;YAAE,SAAS;QAChD,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IACvB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,MAAM,MAAM,GAAW,EAAE,CAAC;IAC1B,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,QAAQ;YAAE,SAAS;QACjD,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IACvB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The lifecycle axis, realized — once, for every storage.
|
|
3
|
+
*
|
|
4
|
+
* `validation.ts` states the split: the judge answers "is this value legal?" and never
|
|
5
|
+
* fills a hole; filling it — stamp `'now'`, apply `{ value }`, call `{ generate }` — is
|
|
6
|
+
* the storage's role at the point of persistence. The split is right. What was missing
|
|
7
|
+
* is that the framework shipped the RULE and never its realization, so each storage
|
|
8
|
+
* rewrote it and they drifted:
|
|
9
|
+
*
|
|
10
|
+
* - `schema-sql` realized `{ generate }` and `'now'` in its ORM, and `{ value }` in its
|
|
11
|
+
* DDL — as a column `DEFAULT` the database fills. A mechanism only SQL has.
|
|
12
|
+
* - The Nuxt module's fallback ORM realized none of the three: its signature is
|
|
13
|
+
* `(_entity, _name)`, both ignored, so it forces the name `id` and a random uuid.
|
|
14
|
+
* - A third-party adapter (MongoDB, written outside the repo on 2026-08-08) found the
|
|
15
|
+
* gap the only way available: a test that expected `'draft'` and got `undefined`.
|
|
16
|
+
*
|
|
17
|
+
* Measured, one entity, `oneOf('draft','published',{ default:'draft' })`: SQLite answered
|
|
18
|
+
* `'draft'`, MongoDB answered `undefined`. Same declaration, same port, two answers.
|
|
19
|
+
*
|
|
20
|
+
* So the rule and its realization live together now, and a storage adapter calls this
|
|
21
|
+
* instead of re-deriving it. `update: 'forbidden'` is NOT here: refusing a value is a
|
|
22
|
+
* judgment, and the façade already does it (`validation.ts`, patch mode).
|
|
23
|
+
*/
|
|
24
|
+
import { type Fields } from '../field/index.js';
|
|
25
|
+
type Row = Record<string, unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* Fill what the entity says the system writes at creation.
|
|
28
|
+
*
|
|
29
|
+
* A value the caller supplied is never touched, including `null` — presence is the
|
|
30
|
+
* test, not truthiness, so `archivedAt: null` stays null rather than being re-filled.
|
|
31
|
+
*
|
|
32
|
+
* `'now'` produces a `Date`, the value the field declares. The storage converts it if
|
|
33
|
+
* its driver needs something else (`schema-sql/src/values.ts` does exactly that) —
|
|
34
|
+
* which is the same direction every other value travels.
|
|
35
|
+
*/
|
|
36
|
+
export declare function applyCreate(fields: Fields, input: Row): Row;
|
|
37
|
+
/**
|
|
38
|
+
* Fill what the entity says the system writes at every update — `updated()`, and
|
|
39
|
+
* nothing else. A supplied value wins, same rule as create.
|
|
40
|
+
*/
|
|
41
|
+
export declare function applyUpdate(fields: Fields, patch: Row): Row;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/projections/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAyC,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGvF,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AA8BnC;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG,CAqB3D;AAgBD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG,CAS3D"}
|