@aventara/core 0.1.0-pilot.3 → 1.0.0-rc.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/CHANGELOG.md +338 -0
- package/README.md +100 -3
- package/dist/adapters/adapter-discovery-diagnostic.d.ts +2 -0
- package/dist/adapters/adapter-field.d.ts +3 -26
- package/dist/adapters/adapter-identifier.d.ts +1 -11
- package/dist/adapters/adapter-model.d.ts +12 -0
- package/dist/adapters/adapter-operation-executor.interface.d.ts +5 -1
- package/dist/adapters/adapter-resource.d.ts +7 -28
- package/dist/adapters/adapter.interface.d.ts +25 -26
- package/dist/compiler/contract-compiler-diagnostic.d.ts +8 -0
- package/dist/compiler/contract.compiler.d.ts +11 -22
- package/dist/compiler/contract.compiler.js +67 -0
- package/dist/config/any-framework-config.d.ts +5 -26
- package/dist/config/config-diagnostic.d.ts +2 -0
- package/dist/config/config-layer.d.ts +6 -19
- package/dist/config/config.resolver.d.ts +9 -14
- package/dist/config/config.resolver.js +1 -0
- package/dist/config/config.validator.d.ts +6 -3
- package/dist/config/config.validator.js +6 -0
- package/dist/config/define-fields.d.ts +15 -48
- package/dist/config/effective-fields.d.ts +6 -29
- package/dist/config/entrypoint.normalizer.d.ts +6 -18
- package/dist/config/framework-behaviors-config.d.ts +11 -10
- package/dist/config/framework-config.d.ts +19 -16
- package/dist/config/framework-fields-config.d.ts +20 -7
- package/dist/config/framework-restrictions-config.d.ts +41 -61
- package/dist/config/pipeline-config.d.ts +7 -17
- package/dist/contracts/capability.d.ts +13 -49
- package/dist/contracts/client-contract-structure.validator.d.ts +28 -54
- package/dist/contracts/client-contract-structure.validator.js +99 -2
- package/dist/contracts/contract-canonicalizer.d.ts +4 -6
- package/dist/contracts/contract-canonicalizer.js +32 -0
- package/dist/contracts/contract-hash.d.ts +3 -2
- package/dist/contracts/contract-limits.d.ts +7 -1
- package/dist/contracts/contract-protocol.d.ts +7 -8
- package/dist/contracts/contract.d.ts +20 -4
- package/dist/contracts/enum-definition.d.ts +2 -0
- package/dist/contracts/field.d.ts +40 -167
- package/dist/contracts/identifier.d.ts +1 -16
- package/dist/contracts/json-shape.d.ts +65 -0
- package/dist/contracts/json-shape.js +1 -0
- package/dist/contracts/lifecycle-trait.d.ts +4 -3
- package/dist/contracts/reference-write-limit.d.ts +7 -0
- package/dist/contracts/reference-write-limit.js +1 -0
- package/dist/contracts/resource-operations.d.ts +2 -62
- package/dist/contracts/resource.d.ts +2 -0
- package/dist/contracts/scalar-value-type.d.ts +28 -48
- package/dist/contracts/scalar.d.ts +4 -3
- package/dist/contracts/transaction-capability.d.ts +2 -0
- package/dist/contracts/wire-scalar-format.d.ts +6 -21
- package/dist/framework/contract-view.d.ts +152 -130
- package/dist/framework/framework-construction.error.d.ts +6 -1
- package/dist/framework/framework.d.ts +33 -46
- package/dist/framework/framework.factory.d.ts +3 -17
- package/dist/framework/framework.factory.js +56 -13
- package/dist/framework/operation-facade.d.ts +3 -7
- package/dist/index.d.ts +8 -40
- package/dist/index.js +0 -20
- package/dist/internal.d.ts +35 -0
- package/dist/internal.js +16 -0
- package/dist/json/avz.d.ts +96 -0
- package/dist/json/avz.js +212 -0
- package/dist/json/index.d.ts +6 -0
- package/dist/json/index.js +1 -0
- package/dist/json/json-shape.registry.d.ts +22 -0
- package/dist/json/json-shape.registry.js +16 -0
- package/dist/json/zod-issue.translator.d.ts +51 -0
- package/dist/json/zod-issue.translator.js +142 -0
- package/dist/operations/operation-arguments.d.ts +198 -303
- package/dist/operations/operation-call.d.ts +13 -15
- package/dist/operations/operation-identity.d.ts +6 -2
- package/dist/operations/operation-identity.js +3 -0
- package/dist/operations/operation-result.d.ts +15 -61
- package/dist/operations/operation-validator-core.d.ts +6 -5
- package/dist/operations/operation-validator-core.js +28 -10
- package/dist/operations/operation-validator.d.ts +22 -9
- package/dist/operations/operation-validator.js +26 -10
- package/dist/operations/projection-scope.resolver.d.ts +1 -11
- package/dist/operations/structural-limits.walker.d.ts +19 -0
- package/dist/operations/structural-limits.walker.js +344 -0
- package/dist/operations/validation-code.d.ts +5 -17
- package/dist/operations/write-scope.resolver.d.ts +3 -28
- package/dist/protocol/absent-route.responder.d.ts +25 -39
- package/dist/protocol/absent-route.responder.js +32 -6
- package/dist/protocol/av-protocol.d.ts +2 -8
- package/dist/protocol/contract-document.responder.d.ts +5 -18
- package/dist/protocol/http-request.decoder.d.ts +18 -59
- package/dist/protocol/http-request.decoder.js +11 -3
- package/dist/protocol/http-request.reader.d.ts +5 -5
- package/dist/protocol/http-response.encoder.d.ts +14 -20
- package/dist/protocol/http-status.table.d.ts +0 -8
- package/dist/protocol/index.d.ts +2 -7
- package/dist/protocol/operation-response.guard.d.ts +0 -15
- package/dist/protocol/protocol-failure.d.ts +8 -27
- package/dist/protocol/protocol-headers.d.ts +15 -42
- package/dist/protocol/protocol-surface.d.ts +0 -22
- package/dist/protocol/protocol.binder.d.ts +19 -27
- package/dist/protocol/protocol.binder.js +3 -1
- package/dist/protocol/protocol.handler.d.ts +19 -23
- package/dist/protocol/protocol.handler.js +14 -4
- package/dist/protocol/unmounted-route.error.d.ts +19 -0
- package/dist/protocol/unmounted-route.error.js +10 -0
- package/dist/runtime/caller-data.copier.d.ts +59 -0
- package/dist/runtime/caller-data.copier.js +470 -0
- package/dist/runtime/caller-data.door.d.ts +56 -0
- package/dist/runtime/caller-data.door.js +65 -0
- package/dist/runtime/computed-read-runtime.js +3 -10
- package/dist/runtime/computed-value.error.d.ts +13 -0
- package/dist/runtime/computed-value.error.js +9 -0
- package/dist/runtime/create-requirement.d.ts +43 -7
- package/dist/runtime/create-requirement.js +89 -9
- package/dist/runtime/decimal.d.ts +5 -3
- package/dist/runtime/diagnostics-reporter.d.ts +33 -37
- package/dist/runtime/diagnostics-reporter.js +11 -4
- package/dist/runtime/error-boundary.d.ts +14 -10
- package/dist/runtime/error-boundary.js +65 -35
- package/dist/runtime/execution-options.d.ts +3 -7
- package/dist/runtime/field-behavior.d.ts +14 -21
- package/dist/runtime/framework-error.d.ts +14 -2
- package/dist/runtime/json-value.d.ts +7 -15
- package/dist/runtime/misuse-reporter.d.ts +32 -0
- package/dist/runtime/misuse-reporter.js +19 -0
- package/dist/runtime/mutation-planner.d.ts +6 -12
- package/dist/runtime/mutation-planner.js +13 -11
- package/dist/runtime/operation-request.d.ts +11 -11
- package/dist/runtime/operation-response.d.ts +18 -23
- package/dist/runtime/operation-runtime.d.ts +25 -33
- package/dist/runtime/operation-runtime.js +37 -18
- package/dist/runtime/outcome-mapper.js +12 -2
- package/dist/runtime/output-validator.d.ts +10 -0
- package/dist/runtime/output-validator.js +11 -0
- package/dist/runtime/owned-execution.registry.d.ts +13 -0
- package/dist/runtime/owned-execution.registry.js +7 -0
- package/dist/runtime/pipeline.d.ts +33 -36
- package/dist/runtime/referential-action.d.ts +8 -26
- package/dist/runtime/request-envelope.validator.d.ts +5 -0
- package/dist/runtime/request-envelope.validator.js +118 -0
- package/dist/runtime/request-id.d.ts +3 -10
- package/dist/runtime/scalar-runtime.d.ts +42 -14
- package/dist/runtime/scalar-runtime.js +162 -79
- package/dist/transactions/deferred-operation.d.ts +10 -21
- package/dist/transactions/operation-arguments-encoder.d.ts +1 -0
- package/dist/transactions/operation-fingerprint.d.ts +3 -1
- package/dist/transactions/transaction-envelope.d.ts +2 -4
- package/dist/transactions/transaction-integrity-error.d.ts +4 -15
- package/dist/transactions/transaction-plan-assembler.d.ts +6 -1
- package/dist/transactions/transaction-plan-assembler.js +74 -75
- package/dist/transactions/transaction-plan-validator.d.ts +33 -24
- package/dist/transactions/transaction-plan-validator.js +204 -153
- package/dist/transactions/transaction-reference-collector.d.ts +30 -0
- package/dist/transactions/transaction-reference-collector.js +204 -0
- package/dist/transactions/transaction-reference-resolver.d.ts +9 -12
- package/dist/transactions/transaction-reference-resolver.js +10 -5
- package/dist/transactions/transaction-reference-validator.js +24 -17
- package/dist/transactions/transaction-reference.d.ts +31 -64
- package/dist/transactions/transaction-request.d.ts +6 -8
- package/dist/transactions/transaction-response.d.ts +10 -7
- package/dist/transactions/transaction-response.js +24 -1
- package/dist/transactions/transaction-runtime.d.ts +7 -5
- package/dist/transactions/transaction-runtime.js +4 -3
- package/dist/transactions/transaction-slot-path-error.d.ts +5 -15
- package/dist/transactions/transaction-slot-writer.d.ts +3 -13
- package/package.json +17 -3
- package/dist/operations/operation-boolean-nodes.d.ts +0 -11
- package/dist/operations/operation-boolean-nodes.js +0 -283
- package/dist/operations/operation-nesting.d.ts +0 -8
- package/dist/operations/operation-nesting.js +0 -307
|
@@ -2,12 +2,16 @@ import type { AdapterModel } from "../adapters/adapter-model.js";
|
|
|
2
2
|
import type { AnyFrameworkConfig } from "../config/any-framework-config.js";
|
|
3
3
|
import type { RequestOrigin } from "../config/config-layer.js";
|
|
4
4
|
import type { ContractLimits } from "../contracts/contract-limits.js";
|
|
5
|
-
|
|
6
|
-
type IsLayeredRecord<T> = [T] extends [readonly unknown[]] ? false : [T] extends [object] ? true : false;
|
|
5
|
+
import type { JsonShape, ShapedJsonSchema } from "../contracts/json-shape.js";
|
|
7
6
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
|
|
7
|
+
* Whether `resolveRecord` descends into a value: an object that is no array and
|
|
8
|
+
* no Json Shape.
|
|
9
|
+
*/
|
|
10
|
+
type IsLayeredRecord<T> = [T] extends [readonly unknown[]] ? false : [T] extends [JsonShape] ? false : [T] extends [object] ? true : false;
|
|
11
|
+
/**
|
|
12
|
+
* A root record with a scoped record layered over it: a key the scoped side
|
|
13
|
+
* states wins; when both sides are records they merge, recursively; otherwise
|
|
14
|
+
* the scoped value replaces the root one.
|
|
11
15
|
*/
|
|
12
16
|
type LayeredRecord<Root, Scoped> = {
|
|
13
17
|
readonly [K in keyof Root | keyof Scoped]: K extends keyof Scoped ? K extends keyof Root ? [IsLayeredRecord<Root[K]>, IsLayeredRecord<Scoped[K]>] extends [
|
|
@@ -24,19 +28,8 @@ type LayeredRecord<Root, Scoped> = {
|
|
|
24
28
|
type LiteralRecord<T> = unknown extends T ? never : [NonNullable<T>] extends [never] ? never : [NonNullable<T>] extends [object] ? string extends keyof NonNullable<T> ? never : NonNullable<T> : never;
|
|
25
29
|
type LayeredBlocks<Root, Scoped> = [Root] extends [never] ? Scoped : [Scoped] extends [never] ? Root : LayeredRecord<Root, Scoped>;
|
|
26
30
|
/**
|
|
27
|
-
* One configuration block as a derived Contract is compiled from it
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* **Read by indexed access, deliberately not through `effective-fields.ts`'s
|
|
31
|
-
* `FieldsBlockOf`.** That reader (`Cfg extends { fields?: infer Block } ? Block
|
|
32
|
-
* extends AnyFieldsBlock ? … `) is right for a key set, but here it makes
|
|
33
|
-
* TypeScript's variance probe treat `Cfg` as irrelevant to this view, so
|
|
34
|
-
* `Framework<M, A>` and `Framework<M, B>` compare identical whatever their `fields`
|
|
35
|
-
* say — the collapse `framework.factory.test-d.ts`'s non-collapse rows exist to
|
|
36
|
-
* catch, and measured: substituting `FieldsBlockOf` here fails both of them. An
|
|
37
|
-
* indexed access is related only when its object types are, so the probe sees
|
|
38
|
-
* `Cfg`. The rows, not this comment, are the guard: the measurement is
|
|
39
|
-
* TypeScript's, and it can move.
|
|
31
|
+
* One configuration block as a derived Contract is compiled from it: the root
|
|
32
|
+
* `Key`, with layer `Layer`'s `Key` layered over it.
|
|
40
33
|
*/
|
|
41
34
|
type LayerBlock<Cfg, Layer extends RequestOrigin, Key extends "fields" | "restrictions"> = LayeredBlocks<LiteralRecord<(Cfg & {
|
|
42
35
|
readonly [K in Key]?: unknown;
|
|
@@ -45,20 +38,19 @@ type LayerBlock<Cfg, Layer extends RequestOrigin, Key extends "fields" | "restri
|
|
|
45
38
|
})[Layer] & {
|
|
46
39
|
readonly [K in Key]?: unknown;
|
|
47
40
|
})[Key]>>;
|
|
41
|
+
/** Root's own `Key` block, before any layer is layered over it. */
|
|
42
|
+
type RootBlock<Cfg, Key extends "fields" | "restrictions"> = LiteralRecord<(Cfg & {
|
|
43
|
+
readonly [K in Key]?: unknown;
|
|
44
|
+
})[Key]>;
|
|
48
45
|
/** One key's entry in a layered block, or `never` when the block has none. */
|
|
49
46
|
type EntryOf<Block, Key> = [Block] extends [never] ? never : Key extends keyof Block ? LiteralRecord<NonNullable<Block[Key]>> : never;
|
|
50
47
|
type ConfiguredCapabilities<FieldConfig> = [FieldConfig] extends [never] ? Record<never, never> : FieldConfig extends {
|
|
51
48
|
readonly capabilities: infer Capabilities;
|
|
52
49
|
} ? NonNullable<Capabilities> : Record<never, never>;
|
|
53
50
|
/**
|
|
54
|
-
*
|
|
55
|
-
* `true` when neither states
|
|
56
|
-
*
|
|
57
|
-
* The override is the first, homomorphic part — mapped over the field's own
|
|
58
|
-
* members, so a member the model leaves optional stays optional rather than
|
|
59
|
-
* becoming a required `T | undefined` that no Contract admits. The other two parts
|
|
60
|
-
* only ADD keys the first does not have, so intersecting them can never narrow a
|
|
61
|
-
* member (the `true & false` failure is an intersection over a SHARED key).
|
|
51
|
+
* A field's capabilities with the configured ones applied: a configured member
|
|
52
|
+
* replaces the field's own, and `select` defaults to `true` when neither states
|
|
53
|
+
* it.
|
|
62
54
|
*/
|
|
63
55
|
type LayeredCapabilities<Own, Configured> = {
|
|
64
56
|
readonly [P in keyof Own]: P extends keyof Configured ? Configured[P] : Own[P];
|
|
@@ -68,28 +60,29 @@ type LayeredCapabilities<Own, Configured> = {
|
|
|
68
60
|
readonly select: true;
|
|
69
61
|
});
|
|
70
62
|
/**
|
|
71
|
-
*
|
|
72
|
-
* capabilities
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* **A field the layer does not configure, and whose capabilities state `select`,
|
|
76
|
-
* is the model's own field type** — rule 3 changes nothing about it, so the view
|
|
77
|
-
* re-states nothing. That is every field of a typical model but the handful a
|
|
78
|
-
* configuration names, and it is what keeps the view's cost proportional to the
|
|
79
|
-
* configuration rather than to the schema: every reader of a field (each
|
|
80
|
-
* capability question, the `Contract` check a surface asks once) reads the model's
|
|
81
|
-
* literal directly instead of a mapped copy of it.
|
|
63
|
+
* A discovered field as the view sees it: every structural fact from the model,
|
|
64
|
+
* its capabilities with the configuration applied. A relation is the model's
|
|
65
|
+
* own.
|
|
82
66
|
*/
|
|
83
67
|
type LayeredModelField<Field, FieldConfig> = Field extends {
|
|
84
68
|
readonly kind: "scalar";
|
|
85
69
|
} ? [FieldConfig] extends [never] ? Field extends {
|
|
86
70
|
readonly capabilities: infer Capabilities;
|
|
87
71
|
} ? "select" extends keyof Capabilities ? Field : ConfiguredModelField<Field, FieldConfig> : ConfiguredModelField<Field, FieldConfig> : ConfiguredModelField<Field, FieldConfig> : Field;
|
|
88
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* A discovered scalar with its configured capabilities applied, member by member,
|
|
74
|
+
* and its configured Json Shape, whose type its value takes.
|
|
75
|
+
*/
|
|
89
76
|
type ConfiguredModelField<Field, FieldConfig> = {
|
|
90
77
|
readonly [P in keyof Field]: P extends "capabilities" ? LayeredCapabilities<Field[P], ConfiguredCapabilities<FieldConfig>> : Field[P];
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
78
|
+
} & ConfiguredJsonShape<FieldConfig>;
|
|
79
|
+
/** A configured Json Shape as a view field's `json` member; nothing otherwise. */
|
|
80
|
+
type ConfiguredJsonShape<FieldConfig> = [FieldConfig] extends [never] ? unknown : FieldConfig extends {
|
|
81
|
+
readonly json: JsonShape<infer Value>;
|
|
82
|
+
} ? {
|
|
83
|
+
readonly json: ShapedJsonSchema<Value>;
|
|
84
|
+
} : unknown;
|
|
85
|
+
/** A scalar the configuration adds, exactly as the configuration states it. */
|
|
93
86
|
type AddedField<FieldConfig> = {
|
|
94
87
|
readonly kind: "scalar";
|
|
95
88
|
readonly type: FieldConfig extends {
|
|
@@ -110,118 +103,147 @@ type AddedFieldKey<ModelFields, ResourceConfig> = [ResourceConfig] extends [
|
|
|
110
103
|
never
|
|
111
104
|
] ? never : Exclude<Extract<keyof ResourceConfig, string>, keyof ModelFields>;
|
|
112
105
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* the thing stays in the view and the validation layer answers it.
|
|
106
|
+
* Whether a restriction entry hides what it names: only a literal `hidden: true`
|
|
107
|
+
* does; `false` restores it.
|
|
116
108
|
*/
|
|
117
109
|
type IsHidden<Restriction> = [Restriction] extends [never] ? false : Restriction extends {
|
|
118
110
|
readonly hidden: true;
|
|
119
111
|
} ? true : false;
|
|
120
112
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* **A key set, computed once per block, rather than a per-key test in an `as`
|
|
125
|
-
* clause.** A remapped mapped type (`[K in … as …]`) re-evaluates its `as` for
|
|
126
|
-
* every key whenever any of its keys or members is asked for; a mapped type over
|
|
127
|
-
* `Exclude<keys, HiddenKey<…>>` reads this set once. Measured on the artifact's
|
|
128
|
-
* shape: ≈2,300 instantiations per client-origin call, and the remapped form was
|
|
129
|
-
* the costliest single term of a client-layer surface.
|
|
113
|
+
* The keys a restrictions block hides, or `never` for a view that reads no
|
|
114
|
+
* restrictions.
|
|
130
115
|
*/
|
|
131
116
|
type HiddenKey<Restrictions> = [Restrictions] extends [never] ? never : {
|
|
132
117
|
[K in keyof Restrictions]-?: IsHidden<EntryOf<Restrictions, K>> extends true ? K : never;
|
|
133
118
|
}[keyof Restrictions];
|
|
119
|
+
/** A restriction entry's `capabilities` block, or `never` when it states none. */
|
|
120
|
+
type CapabilityRestrictionsOf<Entry> = [Entry] extends [never] ? never : EntryOf<Entry, "capabilities">;
|
|
121
|
+
/** A restriction member that is a literal `false`: a denial. */
|
|
122
|
+
type IsDenial<Value> = [Value] extends [false] ? true : false;
|
|
123
|
+
/** A restriction member that is a literal `true`: a restoration. */
|
|
124
|
+
type IsRestoration<Value> = [Value] extends [true] ? true : false;
|
|
125
|
+
/** The tokens a capability member advertises, its qualifier aside. */
|
|
126
|
+
type MemberTokens<Member, TokenKey extends string> = Member extends {
|
|
127
|
+
readonly scopes: unknown;
|
|
128
|
+
} ? TokenKey extends keyof Member ? Member[TokenKey] : never : Member;
|
|
129
|
+
/** The positions a scope-qualified member holds in; `never` for an unqualified one. */
|
|
130
|
+
type MemberScopes<Member> = Member extends {
|
|
131
|
+
readonly scopes: infer Scopes;
|
|
132
|
+
} ? Scopes : never;
|
|
133
|
+
/** A relation's `create`, `update` or `reducers` member narrowed by a restriction. */
|
|
134
|
+
type NarrowedScopedTokens<Member, Restriction, TokenKey extends "directives" | "reducers"> = Restriction extends readonly unknown[] ? [MemberScopes<Member>] extends [never] ? Restriction : {
|
|
135
|
+
readonly [K in TokenKey | "scopes"]: K extends "scopes" ? MemberScopes<Member> : Restriction;
|
|
136
|
+
} : Restriction extends object ? (Restriction extends {
|
|
137
|
+
readonly scopes: infer Scopes;
|
|
138
|
+
} ? Scopes : MemberScopes<Member>) extends infer Scopes ? [Scopes] extends [never] ? Restriction extends {
|
|
139
|
+
readonly [K in TokenKey]: infer Tokens;
|
|
140
|
+
} ? Tokens : MemberTokens<Member, TokenKey> : Scopes extends readonly [] ? false : {
|
|
141
|
+
readonly [K in TokenKey | "scopes"]: K extends "scopes" ? Scopes : Restriction extends {
|
|
142
|
+
readonly [T in TokenKey]: infer Tokens;
|
|
143
|
+
} ? Tokens : MemberTokens<Member, TokenKey>;
|
|
144
|
+
} : never : Member;
|
|
145
|
+
/** One capability member narrowed by a list (or, on a relation, an object) restriction. */
|
|
146
|
+
type NarrowedMember<Kind, Key, Member, Restriction> = Kind extends "relation" ? Key extends "select" | "include" ? Restriction extends readonly [] ? false : Restriction : Key extends "create" | "update" ? NarrowedScopedTokens<Member, Restriction, "directives"> : Key extends "reducers" ? NarrowedScopedTokens<Member, Restriction, "reducers"> : Restriction : Restriction;
|
|
147
|
+
/** One capability member of a field under its layer's restrictions. */
|
|
148
|
+
type RestrictedMember<Kind, Key, Member, Root, Layered> = IsRestoration<Layered> extends true ? Root extends readonly unknown[] | {
|
|
149
|
+
readonly scopes?: unknown;
|
|
150
|
+
} ? NarrowedMember<Kind, Key, Member, Root> : Member : [Layered] extends [boolean] ? Member : NarrowedMember<Kind, Key, Member, Layered>;
|
|
151
|
+
/** The members a capabilities restriction denies, or narrows to nothing. */
|
|
152
|
+
type DeniedMember<Kind, Own, Root, Layered> = {
|
|
153
|
+
[P in keyof Own]-?: P extends keyof Layered ? IsDenial<Layered[P]> extends true ? P : [
|
|
154
|
+
RestrictedMember<Kind, P, Own[P], P extends keyof Root ? Root[P] : undefined, Layered[P]>
|
|
155
|
+
] extends [false] ? P : never : never;
|
|
156
|
+
}[keyof Own];
|
|
157
|
+
/** A field's capabilities under its layer's restrictions. */
|
|
158
|
+
type RestrictedCapabilities<Kind, Own, Root, Layered> = {
|
|
159
|
+
readonly [P in keyof Own as P extends DeniedMember<Kind, Own, Root, Layered> ? never : P]: P extends keyof Layered ? RestrictedMember<Kind, P, Own[P], P extends keyof Root ? Root[P] : undefined, Layered[P]> : Own[P];
|
|
160
|
+
};
|
|
161
|
+
/** A view field with its layer's capability restrictions applied. */
|
|
162
|
+
type RestrictedField<Field, RootEntry, Entry> = [
|
|
163
|
+
CapabilityRestrictionsOf<Entry>
|
|
164
|
+
] extends [never] ? Field : {
|
|
165
|
+
readonly [P in keyof Field]: P extends "capabilities" ? RestrictedCapabilities<Field extends {
|
|
166
|
+
readonly kind: infer Kind;
|
|
167
|
+
} ? Kind : never, Field[P], CapabilityRestrictionsOf<RootEntry>, CapabilityRestrictionsOf<Entry>> : Field[P];
|
|
168
|
+
};
|
|
134
169
|
/**
|
|
135
|
-
* A Resource's fields in the view: the model's
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
* (`Awaited<Promise<Framework<…>>>` is one); a separate branch per case measured
|
|
142
|
-
* at +9,000 instantiations there, and naming the field rule below as an alias at
|
|
143
|
-
* +2,300.
|
|
144
|
-
*/
|
|
145
|
-
type LayeredFields<ModelFields, ResourceConfig, FieldRestrictions> = {
|
|
146
|
-
readonly [F in Exclude<keyof ModelFields | AddedFieldKey<ModelFields, ResourceConfig>, HiddenKey<FieldRestrictions>>]: F extends keyof ModelFields ? LayeredModelField<ModelFields[F], EntryOf<ResourceConfig, F>> : AddedField<EntryOf<ResourceConfig, F>>;
|
|
170
|
+
* A Resource's fields in the view: the model's and the ones the configuration
|
|
171
|
+
* adds, less the ones this view's restrictions hide, each with its capability
|
|
172
|
+
* restrictions applied.
|
|
173
|
+
*/
|
|
174
|
+
type LayeredFields<ModelFields, ResourceConfig, FieldRestrictions, RootFieldRestrictions> = {
|
|
175
|
+
readonly [F in Exclude<keyof ModelFields | AddedFieldKey<ModelFields, ResourceConfig>, HiddenKey<FieldRestrictions>>]: RestrictedField<F extends keyof ModelFields ? LayeredModelField<ModelFields[F], EntryOf<ResourceConfig, F>> : AddedField<EntryOf<ResourceConfig, F>>, EntryOf<RootFieldRestrictions, F>, EntryOf<FieldRestrictions, F>>;
|
|
147
176
|
};
|
|
177
|
+
/** The variants of one family an operations restriction turns off: literal `false` only. */
|
|
178
|
+
type DisabledVariant<FamilyRestriction> = [FamilyRestriction] extends [never] ? never : {
|
|
179
|
+
[V in keyof FamilyRestriction]-?: IsDenial<FamilyRestriction[V]> extends true ? V : never;
|
|
180
|
+
}[keyof FamilyRestriction];
|
|
181
|
+
/** The variants of the unique style, which need an identifier the layer keeps. */
|
|
182
|
+
type UniqueVariant = "unique";
|
|
148
183
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
184
|
+
* The variants of one family the layer advertises: the model's, less those turned
|
|
185
|
+
* off, less the unique one when no identifier survives.
|
|
186
|
+
*/
|
|
187
|
+
type AvailableVariant<Family, FamilyRestriction, UniqueLost> = Exclude<keyof Family, DisabledVariant<FamilyRestriction> | (UniqueLost extends true ? UniqueVariant : never)>;
|
|
188
|
+
/** The families with at least one variant the layer advertises. */
|
|
189
|
+
type AvailableFamily<Operations, OperationRestrictions, UniqueLost> = {
|
|
190
|
+
[F in keyof Operations]-?: [
|
|
191
|
+
AvailableVariant<NonNullable<Operations[F]>, EntryOf<OperationRestrictions, F>, UniqueLost>
|
|
192
|
+
] extends [never] ? never : F;
|
|
193
|
+
}[keyof Operations];
|
|
194
|
+
/** A Resource's operations under its layer's restrictions. */
|
|
195
|
+
type RestrictedOperations<Operations, OperationRestrictions, UniqueLost> = [
|
|
196
|
+
OperationRestrictions
|
|
197
|
+
] extends [never] ? UniqueLost extends true ? LayerOperations<Operations, never, UniqueLost> : Operations : LayerOperations<Operations, OperationRestrictions, UniqueLost>;
|
|
198
|
+
type LayerOperations<Operations, OperationRestrictions, UniqueLost> = {
|
|
199
|
+
readonly [F in AvailableFamily<Operations, OperationRestrictions, UniqueLost>]: {
|
|
200
|
+
readonly [V in AvailableVariant<NonNullable<Operations[F]>, EntryOf<OperationRestrictions, F>, UniqueLost>]: NonNullable<Operations[F]>[V];
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
/** A Resource's identifiers less those naming a hidden field. */
|
|
204
|
+
type KeptIdentifiers<Identifiers, Hidden> = [Hidden] extends [never] ? Identifiers : Identifiers extends readonly (infer Identifier)[] ? readonly (Identifier extends readonly (infer Field)[] ? [Extract<Field, Hidden>] extends [never] ? Identifier : never : never)[] : Identifiers;
|
|
205
|
+
/** Whether hiding fields left a Resource with no identifier at all. */
|
|
206
|
+
type IdentifiersLost<Identifiers, Hidden> = [Hidden] extends [never] ? false : [
|
|
207
|
+
KeptIdentifiers<Identifiers, Hidden> extends readonly (infer Kept)[] ? Kept : never
|
|
208
|
+
] extends [never] ? true : false;
|
|
209
|
+
/**
|
|
210
|
+
* One Resource in the view: the model's own, with its fields layered and its
|
|
211
|
+
* layer's restrictions applied to its fields, operations and identifiers.
|
|
212
|
+
*/
|
|
213
|
+
type LayeredResource<in out Resource, in out ResourceConfig, in out ResourceRestrictions, in out RootResourceRestrictions> = {
|
|
214
|
+
readonly [P in keyof Resource]: P extends "fields" ? LayeredFields<Resource[P], ResourceConfig, EntryOf<ResourceRestrictions, "fields">, EntryOf<RootResourceRestrictions, "fields">> : P extends "operations" ? RestrictedOperations<Resource[P], EntryOf<ResourceRestrictions, "operations">, IdentifiersLost<Resource extends {
|
|
215
|
+
readonly identifiers: infer Ids;
|
|
216
|
+
} ? Ids : never, HiddenKey<EntryOf<ResourceRestrictions, "fields">>>> : P extends "identifiers" ? KeptIdentifiers<Resource[P], HiddenKey<EntryOf<ResourceRestrictions, "fields">>> : Resource[P];
|
|
170
217
|
};
|
|
171
218
|
/**
|
|
172
|
-
*
|
|
173
|
-
*
|
|
219
|
+
* The Resources in the view. `Restrictions` is the layer's layered
|
|
220
|
+
* `restrictions` block and `RootRestrictions` root's own, whose narrowings a
|
|
221
|
+
* restoration inherits; both `never` for a configuration that restricts nothing.
|
|
174
222
|
*/
|
|
175
|
-
type LayeredResources<Resources, Block, Restrictions> = {
|
|
176
|
-
readonly [R in Exclude<keyof Resources, HiddenKey<Restrictions>>]: LayeredResource<Resources[R], EntryOf<Block, R>, EntryOf<Restrictions, R>>;
|
|
223
|
+
type LayeredResources<Resources, Block, Restrictions, RootRestrictions> = {
|
|
224
|
+
readonly [R in Exclude<keyof Resources, HiddenKey<Restrictions>>]: LayeredResource<Resources[R], EntryOf<Block, R>, EntryOf<Restrictions, R>, EntryOf<RootRestrictions, R>>;
|
|
177
225
|
};
|
|
178
226
|
/**
|
|
179
|
-
* One derived Contract's
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
* keys an instantiated type on the arguments of the alias it is reached through,
|
|
185
|
-
* so a view instantiated through an alias over `Cfg` is a distinct type for every
|
|
186
|
-
* configuration, and two `Framework`s whose configurations differ only in what
|
|
187
|
-
* the view never reads — a pipeline, a diagnostics sink, the other layer — carry
|
|
188
|
-
* four distinct surfaces that only a structural walk of every operation of every
|
|
189
|
-
* Resource can prove equal. Measured on `transaction-plan-validator.spec.ts`,
|
|
190
|
-
* where two such Frameworks share one array literal: ≈95,000 instantiations for
|
|
191
|
-
* that one line, ≈4,000 keyed on blocks. The two named views below reach this
|
|
192
|
-
* type through a conditional for that reason (see {@link ApplicationContractView}).
|
|
193
|
-
*/
|
|
194
|
-
type DerivedContractView<M extends AdapterModel, FieldsBlock, Restrictions> = {
|
|
227
|
+
* One derived Contract's type: the model, with a layer's `fields` block applied
|
|
228
|
+
* and its layered `restrictions` block (`Restrictions`, over root's own,
|
|
229
|
+
* `RootRestrictions`) applied.
|
|
230
|
+
*/
|
|
231
|
+
type DerivedContractView<M extends AdapterModel, FieldsBlock, Restrictions, RootRestrictions> = {
|
|
195
232
|
readonly scalars: M["scalars"];
|
|
196
233
|
readonly enums: M["enums"];
|
|
197
|
-
readonly resources: LayeredResources<M["resources"], FieldsBlock, Restrictions>;
|
|
234
|
+
readonly resources: LayeredResources<M["resources"], FieldsBlock, Restrictions, RootRestrictions>;
|
|
198
235
|
readonly limits: ContractLimits;
|
|
199
236
|
readonly transactions: M["transactions"];
|
|
200
237
|
};
|
|
201
238
|
/**
|
|
202
239
|
* The Application Contract's type, derived from the adapter model and the
|
|
203
|
-
* configuration
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
* the branch's own type, while a plain alias over `Cfg` would key the instantiated
|
|
213
|
-
* view on the whole configuration (see `DerivedContractView`).
|
|
214
|
-
*/
|
|
215
|
-
export type ApplicationContractView<M extends AdapterModel, Cfg = AnyFrameworkConfig> = [Cfg] extends [unknown] ? DerivedContractView<M, LayerBlock<Cfg, "application", "fields">, never> : never;
|
|
216
|
-
/**
|
|
217
|
-
* The Client Contract's type, by the same four rules over `client.fields`, plus
|
|
218
|
-
* rule 5: what the client layer hides is absent. Typed under ClientContract rules
|
|
219
|
-
* for the in-process client-origin surfaces (`framework.client`,
|
|
220
|
-
* `framework.clientTx`).
|
|
221
|
-
*
|
|
222
|
-
* Not exported from the package; a generated client reads the deployed
|
|
223
|
-
* ClientContract literal itself. Resolved through a conditional for the reason
|
|
224
|
-
* {@link ApplicationContractView} gives.
|
|
225
|
-
*/
|
|
226
|
-
export type ClientContractView<M extends AdapterModel, Cfg = AnyFrameworkConfig> = [Cfg] extends [unknown] ? DerivedContractView<M, LayerBlock<Cfg, "client", "fields">, LayerBlock<Cfg, "client", "restrictions">> : never;
|
|
240
|
+
* configuration.
|
|
241
|
+
*/
|
|
242
|
+
export type ApplicationContractView<M extends AdapterModel, Cfg = AnyFrameworkConfig> = [Cfg] extends [unknown] ? DerivedContractView<M, LayerBlock<Cfg, "application", "fields">, LayerBlock<Cfg, "application", "restrictions">, RootBlock<Cfg, "restrictions">> : never;
|
|
243
|
+
/**
|
|
244
|
+
* The Client Contract's type, derived from the adapter model and the
|
|
245
|
+
* configuration: what the client layer hides is absent. It types
|
|
246
|
+
* `framework.client` and `framework.clientTx`.
|
|
247
|
+
*/
|
|
248
|
+
export type ClientContractView<M extends AdapterModel, Cfg = AnyFrameworkConfig> = [Cfg] extends [unknown] ? DerivedContractView<M, LayerBlock<Cfg, "client", "fields">, LayerBlock<Cfg, "client", "restrictions">, RootBlock<Cfg, "restrictions">> : never;
|
|
227
249
|
export {};
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type { AdapterDiscoveryDiagnostic } from "../adapters/adapter-discovery-diagnostic.js";
|
|
2
2
|
import type { ContractCompilerDiagnostic } from "../compiler/contract-compiler-diagnostic.js";
|
|
3
3
|
import type { ConfigDiagnostic } from "../config/config-diagnostic.js";
|
|
4
|
+
/** The construction step that failed. */
|
|
4
5
|
export type FrameworkConstructionStage = "configuration" | "discovery" | "contract-compilation";
|
|
6
|
+
/** One problem reported by {@link FrameworkConstructionError}. */
|
|
5
7
|
export type FrameworkConstructionDiagnostic = ConfigDiagnostic | AdapterDiscoveryDiagnostic | ContractCompilerDiagnostic;
|
|
6
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Thrown by {@link createFramework} when construction fails: `stage` says
|
|
10
|
+
* where, and `diagnostics` lists every problem found there.
|
|
11
|
+
*/
|
|
7
12
|
export declare class FrameworkConstructionError extends Error {
|
|
8
13
|
readonly stage: FrameworkConstructionStage;
|
|
9
14
|
readonly diagnostics: readonly FrameworkConstructionDiagnostic[];
|
|
@@ -7,36 +7,33 @@ import type { TransactionRunner } from "../transactions/deferred-operation.js";
|
|
|
7
7
|
import type { FrameworkTransactionRequest } from "../transactions/transaction-request.js";
|
|
8
8
|
import type { TransactionResponse } from "../transactions/transaction-response.js";
|
|
9
9
|
import type { ApplicationOperations, ApplicationTransactionBuilders, ClientOperations, ClientTransactionBuilders } from "./operation-facade.js";
|
|
10
|
+
/**
|
|
11
|
+
* One Aventara instance, as returned by {@link createFramework}: its compiled
|
|
12
|
+
* Contracts, typed in-process operations, transaction builders and the
|
|
13
|
+
* untyped `execute` entry a transport calls.
|
|
14
|
+
*/
|
|
10
15
|
export type Framework<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkConfig> = {
|
|
11
16
|
readonly entrypoint: string;
|
|
12
17
|
readonly contracts: FrameworkContracts;
|
|
13
18
|
/**
|
|
14
|
-
*
|
|
15
|
-
* `framework.application.<resource>.<family>.<variant>(args)`.
|
|
19
|
+
* Typed in-process operations under the Application Contract:
|
|
20
|
+
* `framework.application.<resource>.<family>.<variant>(args, options?)`.
|
|
16
21
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* — the same totality guard and validation layer — which still refuses what a
|
|
22
|
-
* restriction removed, since restrictions stay invisible to the types.
|
|
23
|
-
*
|
|
24
|
-
* A call's optional second argument is its `ExecutionOptions`: a supplied
|
|
25
|
-
* `requestId` is the request's, in every pipeline context and diagnostic; omitted
|
|
26
|
-
* or empty, a fresh id is minted per call.
|
|
22
|
+
* Typed from the Application Contract as configured: what the application's
|
|
23
|
+
* restrictions hide, deny or turn off is absent from the types, and a call is
|
|
24
|
+
* validated like any other request. The optional second argument is
|
|
25
|
+
* {@link ExecutionOptions}.
|
|
27
26
|
*/
|
|
28
27
|
readonly application: ApplicationOperations<M, Cfg>;
|
|
29
28
|
/**
|
|
30
|
-
* The same
|
|
31
|
-
* `framework.client.<resource>.<family>.<variant>(args)`.
|
|
29
|
+
* The same operations under ClientContract rules:
|
|
30
|
+
* `framework.client.<resource>.<family>.<variant>(args, options?)`.
|
|
32
31
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* request body carries, so a transport can
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* validation layer, which answers whatever a free-flow body says. Takes the
|
|
39
|
-
* same `ExecutionOptions` second argument as {@link application}.
|
|
32
|
+
* What the client layer hides, denies or turns off is absent from the types,
|
|
33
|
+
* as from a generated client, and arguments are read in the wire
|
|
34
|
+
* forms a decoded request body carries, so a transport can pass `req.body` as
|
|
35
|
+
* it is. Each call runs the client pipelines and the same validation as a
|
|
36
|
+
* remote request.
|
|
40
37
|
*/
|
|
41
38
|
readonly client: ClientOperations<M, Cfg>;
|
|
42
39
|
/**
|
|
@@ -49,41 +46,31 @@ export type Framework<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkC
|
|
|
49
46
|
*/
|
|
50
47
|
readonly appTx: ApplicationTransactionBuilders<M, Cfg>;
|
|
51
48
|
/**
|
|
52
|
-
* The same builders under ClientContract rules
|
|
53
|
-
*
|
|
54
|
-
*
|
|
49
|
+
* The same builders under ClientContract rules, taking wire-form arguments.
|
|
50
|
+
* Client and application handles may share one {@link transaction}; each step
|
|
51
|
+
* runs under its own handle's rules.
|
|
55
52
|
*/
|
|
56
53
|
readonly clientTx: ClientTransactionBuilders<M, Cfg>;
|
|
57
54
|
execute(request: FrameworkOperationRequest): Promise<OperationResponse>;
|
|
58
55
|
/**
|
|
59
|
-
* Validates a whole transaction plan, then runs its operations
|
|
60
|
-
*
|
|
61
|
-
* operation's final data in plan order, the failing operation's own code
|
|
62
|
-
* `cause.operation` after rollback, or `A3002` when the transaction
|
|
63
|
-
* fails.
|
|
56
|
+
* Validates a whole transaction plan, then runs its operations one after
|
|
57
|
+
* another inside one Adapter transaction. Answers `A1009` with each
|
|
58
|
+
* operation's final data in plan order, the failing operation's own code
|
|
59
|
+
* with `cause.operation` after rollback, or `A3002` when the transaction
|
|
60
|
+
* itself fails. Never rejects.
|
|
64
61
|
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* Adapter must reject with the exact value its transaction callback threw, by
|
|
68
|
-
* identity.
|
|
62
|
+
* Guards, pipes, hooks and interceptors run while the transaction is open, so
|
|
63
|
+
* they should not perform network I/O or other slow work.
|
|
69
64
|
*/
|
|
70
65
|
executeTransaction(request: FrameworkTransactionRequest): Promise<TransactionResponse>;
|
|
71
66
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* step, and runs the resulting passive plan through the same validation layer and
|
|
76
|
-
* transaction runtime as {@link executeTransaction} — each step under its own
|
|
77
|
-
* handle's origin, its own layer's Contract and pipelines, inside one Adapter
|
|
78
|
-
* transaction. The committed response is typed per position.
|
|
67
|
+
* Runs handles from `appTx`/`clientTx` as one transaction:
|
|
68
|
+
* `framework.transaction([h1, h2, …], options?)`. Resolves the committed
|
|
69
|
+
* response, typed per position, or the failure response. Never rejects.
|
|
79
70
|
*
|
|
80
71
|
* Refused before anything runs: an entry that is not one of this Framework's
|
|
81
|
-
* handles, or the same handle twice (`A2004`/`V1001`); a `$ref` to a handle
|
|
82
|
-
* the list (`A2007`/`V1010`).
|
|
83
|
-
*
|
|
84
|
-
* The optional second argument is the run's `ExecutionOptions`: its `requestId` is
|
|
85
|
-
* every step's, under either origin; omitted or empty, one id is minted for the
|
|
86
|
-
* run. Handles take no options — a handle is not a request.
|
|
72
|
+
* handles, or the same handle twice (`A2004`/`V1001`); a `$ref` to a handle
|
|
73
|
+
* not in the list (`A2007`/`V1010`).
|
|
87
74
|
*/
|
|
88
75
|
readonly transaction: TransactionRunner;
|
|
89
76
|
};
|
|
@@ -3,23 +3,9 @@ import type { AnyFrameworkConfig } from "../config/any-framework-config.js";
|
|
|
3
3
|
import type { FrameworkConfig } from "../config/framework-config.js";
|
|
4
4
|
import type { Framework } from "./framework.js";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Creates a Framework: validates the configuration, reads the adapter's
|
|
7
|
+
* model and compiles the Contracts.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
* the obvious `FrameworkConfig<M, Cfg>`. `Cfg` has to appear somewhere the
|
|
11
|
-
* compiler actually infers from; inside `FrameworkConfig`'s body it only ever
|
|
12
|
-
* reaches non-inference positions, so it would fall back to its
|
|
13
|
-
* `AnyFrameworkConfig` default with no error reported anywhere, and every
|
|
14
|
-
* narrowing keyed on the authored configuration would quietly widen. The
|
|
15
|
-
* intersection puts `Cfg` directly against the argument type.
|
|
16
|
-
*
|
|
17
|
-
* `Cfg` is a `const` type parameter for the same reason: it stands for the
|
|
18
|
-
* configuration *as authored*. Without `const`, inferring `Cfg` from an
|
|
19
|
-
* inline configuration literal widens its scalar references away from their
|
|
20
|
-
* literal types, and the widened `Cfg` then loses to the intersection's own
|
|
21
|
-
* `FrameworkConfig` half — a call site that compiles today stops compiling.
|
|
22
|
-
* A configuration passed as an already-annotated variable is unaffected
|
|
23
|
-
* either way.
|
|
9
|
+
* @throws {@link FrameworkConstructionError} when any of those steps fails.
|
|
24
10
|
*/
|
|
25
11
|
export declare function createFramework<M extends AdapterModel, const Cfg = AnyFrameworkConfig>(config: Cfg & FrameworkConfig<M, Cfg>): Promise<Framework<M, Cfg>>;
|