@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
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The phantom key a Json Shape's TypeScript type travels under. Type-level only:
|
|
3
|
+
* no value ever holds it.
|
|
4
|
+
*/
|
|
5
|
+
declare const jsonShapeValue: unique symbol;
|
|
6
|
+
/**
|
|
7
|
+
* A Json Shape, as the type system sees it: the TypeScript type `Value` of a
|
|
8
|
+
* value that conforms to it. `AvZ` builds every one; a value from anywhere else —
|
|
9
|
+
* a Zod schema included — is not one.
|
|
10
|
+
*/
|
|
11
|
+
export interface JsonShape<Value = unknown> {
|
|
12
|
+
readonly [jsonShapeValue]: Value;
|
|
13
|
+
}
|
|
14
|
+
/** The TypeScript type a {@link JsonShape} describes. */
|
|
15
|
+
export type JsonShapeValue<Shape extends JsonShape> = Shape[typeof jsonShapeValue];
|
|
16
|
+
/** A JSON primitive: what a `const` names. */
|
|
17
|
+
export type JsonSchemaPrimitive = string | number | boolean | null;
|
|
18
|
+
/**
|
|
19
|
+
* A Json Shape in a Contract: passive JSON Schema (draft 2020-12), restricted to
|
|
20
|
+
* the forms Aventara emits.
|
|
21
|
+
*/
|
|
22
|
+
export type JsonSchema = {
|
|
23
|
+
readonly type: "string" | "number" | "integer" | "boolean" | "null";
|
|
24
|
+
} | {
|
|
25
|
+
readonly const: JsonSchemaPrimitive;
|
|
26
|
+
} | {
|
|
27
|
+
readonly type: "string";
|
|
28
|
+
readonly enum: readonly [string, ...string[]];
|
|
29
|
+
} | {
|
|
30
|
+
readonly type: "object";
|
|
31
|
+
readonly properties: {
|
|
32
|
+
readonly [key: string]: JsonSchema;
|
|
33
|
+
};
|
|
34
|
+
readonly required?: readonly string[];
|
|
35
|
+
readonly additionalProperties: false;
|
|
36
|
+
} | {
|
|
37
|
+
readonly type: "object";
|
|
38
|
+
readonly additionalProperties: JsonSchema;
|
|
39
|
+
} | {
|
|
40
|
+
readonly type: "array";
|
|
41
|
+
readonly items: JsonSchema;
|
|
42
|
+
} | {
|
|
43
|
+
readonly type: "array";
|
|
44
|
+
readonly prefixItems: readonly [JsonSchema, ...JsonSchema[]];
|
|
45
|
+
readonly items: false;
|
|
46
|
+
readonly minItems: number;
|
|
47
|
+
readonly maxItems: number;
|
|
48
|
+
} | {
|
|
49
|
+
readonly anyOf: readonly [JsonSchema, JsonSchema, ...JsonSchema[]];
|
|
50
|
+
} | {
|
|
51
|
+
readonly oneOf: readonly [JsonSchema, ...JsonSchema[]];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* The type-level carrier of a shaped Json field's TypeScript type, on the field's
|
|
55
|
+
* `json` member in a typed Contract view. Never present at runtime.
|
|
56
|
+
*/
|
|
57
|
+
export type JsonFieldType<Value> = {
|
|
58
|
+
readonly "~jsonType": Value;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* A shaped Json field's `json` member in a typed Contract view: the schema, and
|
|
62
|
+
* the type it describes.
|
|
63
|
+
*/
|
|
64
|
+
export type ShapedJsonSchema<Value> = JsonSchema & JsonFieldType<Value>;
|
|
65
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* framework
|
|
2
|
+
* Where a field's value comes from, without saying whether it is writable:
|
|
3
|
+
* `DEFAULTED` and `GENERATED_ON_*` by the data source, `COMPUTED_ON_*` by a
|
|
4
|
+
* framework behavior; `VIRTUAL` marks a field that is not stored.
|
|
5
5
|
*/
|
|
6
6
|
export declare const LIFECYCLE_TRAITS: readonly ["DEFAULTED", "GENERATED_ON_CREATE", "GENERATED_ON_UPDATE", "COMPUTED_ON_CREATE", "COMPUTED_ON_UPDATE", "COMPUTED_ON_READ", "VIRTUAL"];
|
|
7
|
+
/** One of {@link LIFECYCLE_TRAITS}. */
|
|
7
8
|
export type LifecycleTrait = (typeof LIFECYCLE_TRAITS)[number];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The limits a data source may put on how one record writes its references. */
|
|
2
|
+
export declare const REFERENCE_WRITE_LIMITS: readonly ["uniform"];
|
|
3
|
+
/**
|
|
4
|
+
* `"uniform"`: one record writes the relations that hold a reference either all
|
|
5
|
+
* as relations or all through their reference fields, never some each way.
|
|
6
|
+
*/
|
|
7
|
+
export type ReferenceWriteLimit = (typeof REFERENCE_WRITE_LIMITS)[number];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const REFERENCE_WRITE_LIMITS = ["uniform"];
|
|
@@ -3,19 +3,6 @@ import type { ProjectionScope, WriteScope } from "./capability.js";
|
|
|
3
3
|
* The argument scopes one advertised operation variant qualifies its arguments
|
|
4
4
|
* with: which projection position its projection arguments sit in, and which write
|
|
5
5
|
* position its data argument sits in.
|
|
6
|
-
*
|
|
7
|
-
* The variant-to-scope map is an ADAPTER fact, not a protocol constant — a
|
|
8
|
-
* variant's projection position depends on which ORM call the adapter routes it to
|
|
9
|
-
* — so the advertised variant carries the answer rather than core tabulating it.
|
|
10
|
-
*
|
|
11
|
-
* At least one scope must be stated. A descriptor stating neither says exactly
|
|
12
|
-
* what `true` says, and one semantic fact with two encodings is one fact with two
|
|
13
|
-
* hashes.
|
|
14
|
-
*
|
|
15
|
-
* Named for the variant it qualifies, and deliberately not `OperationScopes`:
|
|
16
|
-
* `OperationScope` is a public (now deprecated) alias of `RequestOrigin`, meaning
|
|
17
|
-
* `"application" | "client"`, and two public names one character apart with
|
|
18
|
-
* nothing in common is a vocabulary collision, not a near-miss.
|
|
19
6
|
*/
|
|
20
7
|
export type OperationVariantScopes = {
|
|
21
8
|
readonly projection: ProjectionScope;
|
|
@@ -60,63 +47,16 @@ export type ResourceOperations = {
|
|
|
60
47
|
};
|
|
61
48
|
};
|
|
62
49
|
/**
|
|
63
|
-
* Whether one `ResourceOperations`
|
|
64
|
-
*
|
|
65
|
-
* Availability is **presence**: the leaf is `true`, or it is the descriptor that
|
|
66
|
-
* qualifies the variant's arguments. A descriptor states how the variant's
|
|
67
|
-
* arguments are scoped — it never retracts the variant — so `leaf === true` is
|
|
68
|
-
* the wrong question wherever availability is read, and the leaf's widening to
|
|
69
|
-
* `true | OperationVariantScopes` made every hand-rolled copy of that question
|
|
70
|
-
* silently wrong. The question has one home so the next widening of
|
|
71
|
-
* `OperationAvailability` reaches every reader at once.
|
|
72
|
-
*
|
|
73
|
-
* The parameter is `unknown` because the readers are the request validator and
|
|
74
|
-
* the Contract compiler, which hold the leaf as a Contract value keyed by an
|
|
75
|
-
* untrusted or mid-compilation string. Descriptor *shape* is not judged here: a
|
|
76
|
-
* present leaf is an available variant, and validating what the descriptor says
|
|
77
|
-
* belongs to whoever owns the descriptor's own invariants.
|
|
50
|
+
* Whether one `ResourceOperations` entry marks its variant available: it is
|
|
51
|
+
* `true` or an argument-position descriptor.
|
|
78
52
|
*/
|
|
79
53
|
export declare function isOperationVariantAvailable(availability: unknown): availability is OperationAvailability;
|
|
80
54
|
/**
|
|
81
55
|
* The projection position one advertised variant's projection arguments sit in.
|
|
82
|
-
*
|
|
83
|
-
* `"record"` — the unrestricted position — is the answer for `true`, for an absent
|
|
84
|
-
* leaf and for a descriptor that qualifies only its write argument, because the
|
|
85
|
-
* unqualified arm means *nothing is narrowed here*. A Contract written before the
|
|
86
|
-
* axis existed therefore keeps validating exactly as it did, which is what makes
|
|
87
|
-
* the widening in {@link OperationAvailability} non-breaking for a producer that
|
|
88
|
-
* has not measured it.
|
|
89
|
-
*
|
|
90
|
-
* The map from variant to scope is **not** here and must never be:
|
|
91
|
-
* `update.first`'s projection position is the single-record one only because an
|
|
92
|
-
* adapter chose to route that variant to a single-record provider call, and an
|
|
93
|
-
* adapter that routes it to a bulk one moves the answer. Core reads what the
|
|
94
|
-
* advertised variant carries rather than tabulating one scope per variant name.
|
|
95
|
-
*
|
|
96
|
-
* `unknown` for the same reason {@link isOperationVariantAvailable} takes it: the
|
|
97
|
-
* caller holds the leaf keyed by an untrusted request string.
|
|
98
56
|
*/
|
|
99
57
|
export declare function projectionScopeOf(availability: unknown): ProjectionScope;
|
|
100
58
|
/**
|
|
101
59
|
* The write position one advertised variant's data argument sits in, and the write
|
|
102
60
|
* mirror of {@link projectionScopeOf}.
|
|
103
|
-
*
|
|
104
|
-
* `"nested"` — the unrestricted position — is the answer for `true`, for an absent
|
|
105
|
-
* leaf and for a descriptor that qualifies only its projection argument, for the
|
|
106
|
-
* same reason `"record"` is on the projection axis: the unqualified arm means
|
|
107
|
-
* *nothing is narrowed here*, so a Contract written before the axis existed keeps
|
|
108
|
-
* the write surface it had.
|
|
109
|
-
*
|
|
110
|
-
* The two axes are read by two functions, not one that returns a pair, because
|
|
111
|
-
* they are measured and consulted separately — `WRITE_SCOPES` is a separate array
|
|
112
|
-
* from `PROJECTION_SCOPES` for that reason — and a caller that needs only one
|
|
113
|
-
* position should not be handed the other to discard.
|
|
114
|
-
*
|
|
115
|
-
* The mirror exists so that *"what does this descriptor mean?"* has one answer per
|
|
116
|
-
* axis rather than one answer and one convention. The canonicalizer's collapse of
|
|
117
|
-
* a redundant descriptor is keyed on these two functions' answer for `true`: a
|
|
118
|
-
* descriptor says nothing beyond `true` exactly when every reader answers for it
|
|
119
|
-
* what it answers for `true`, and that test is only as honest as the readers being
|
|
120
|
-
* the single statement of each axis's unqualified scope.
|
|
121
61
|
*/
|
|
122
62
|
export declare function writeScopeOf(availability: unknown): WriteScope;
|
|
@@ -2,7 +2,9 @@ import type { Contract } from "./contract.js";
|
|
|
2
2
|
import type { Field } from "./field.js";
|
|
3
3
|
import type { Identifier } from "./identifier.js";
|
|
4
4
|
import type { ResourceOperations } from "./resource-operations.js";
|
|
5
|
+
/** A Resource's fields, by name. */
|
|
5
6
|
export type ResourceFieldMap<C extends Contract> = Readonly<Record<string, Field<C>>>;
|
|
7
|
+
/** One Resource: its fields, identifiers and available operations. */
|
|
6
8
|
export type Resource<C extends Contract, TFields extends ResourceFieldMap<C> = ResourceFieldMap<C>> = {
|
|
7
9
|
readonly fields: TFields;
|
|
8
10
|
readonly identifiers: readonly Identifier<TFields>[];
|
|
@@ -2,33 +2,19 @@ import type { Decimal } from "../runtime/decimal.js";
|
|
|
2
2
|
import type { JsonValue } from "../runtime/json-value.js";
|
|
3
3
|
import type { Contract } from "./contract.js";
|
|
4
4
|
import type { ScalarField } from "./field.js";
|
|
5
|
+
import type { JsonFieldType } from "./json-shape.js";
|
|
5
6
|
import type { BuiltInScalar } from "./scalar.js";
|
|
6
7
|
/**
|
|
7
|
-
* A scalar-form map: the TypeScript type each built-in scalar takes on one side
|
|
8
|
-
* a boundary. Every built-in must be
|
|
9
|
-
* compile where it is passed rather than typing that scalar as `unknown`.
|
|
10
|
-
*
|
|
11
|
-
* It is a parameter rather than a fixed table because one derivation serves more
|
|
12
|
-
* than one side: the application forms below for an in-process caller, and the
|
|
13
|
-
* wire forms for a transport or a generated client.
|
|
14
|
-
*
|
|
15
|
-
* This constraint is not exported: a map is checked for completeness where it is
|
|
16
|
-
* passed, so a consumer never has to name it.
|
|
8
|
+
* A scalar-form map: the TypeScript type each built-in scalar takes on one side
|
|
9
|
+
* of a boundary. Every built-in must be listed.
|
|
17
10
|
*/
|
|
18
11
|
export type ScalarForms = {
|
|
19
12
|
readonly [Scalar in BuiltInScalar]: unknown;
|
|
20
13
|
};
|
|
21
14
|
/**
|
|
22
|
-
* The
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* which maps to the application branch of `normalizeScalarAtom`, and the adapter
|
|
26
|
-
* is held to it (`runtime/scalar-runtime.ts`, `runtime/output-validator.ts`). So
|
|
27
|
-
* a client-scope caller receives these forms too, in process; the wire encoding
|
|
28
|
-
* happens on a transport's way out.
|
|
29
|
-
*
|
|
30
|
-
* `decimal` is core's own {@link Decimal} — never a provider's decimal class —
|
|
31
|
-
* which is what `normalizeScalarAtom`'s `instanceof Decimal` check enforces.
|
|
15
|
+
* The TypeScript form each built-in scalar takes in process: in results of
|
|
16
|
+
* either origin, and in `framework.application` arguments. `decimal` is
|
|
17
|
+
* Aventara's own {@link Decimal}.
|
|
32
18
|
*/
|
|
33
19
|
export type ApplicationScalarForms = {
|
|
34
20
|
readonly string: string;
|
|
@@ -40,17 +26,15 @@ export type ApplicationScalarForms = {
|
|
|
40
26
|
readonly datetime: Date;
|
|
41
27
|
readonly bytes: Uint8Array;
|
|
42
28
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* the `| null` comes from the Contract's `nullable` like every other scalar's. A
|
|
46
|
-
* `null` INSIDE the value is JSON's.
|
|
29
|
+
* Any JSON value. A field-level `null` is the field's absence and is allowed
|
|
30
|
+
* only where the field is nullable; a `null` inside the value is JSON's own.
|
|
47
31
|
*/
|
|
48
32
|
readonly json: Exclude<JsonValue, null>;
|
|
49
33
|
};
|
|
50
34
|
/**
|
|
51
|
-
* The encoded forms the
|
|
52
|
-
*
|
|
53
|
-
*
|
|
35
|
+
* The encoded forms of the built-in scalars: base-10 bigint strings, decimal strings,
|
|
36
|
+
* canonical ISO-8601 UTC datetimes and RFC 4648 base64 bytes. For a transport or a
|
|
37
|
+
* generated client to pass as `Forms`.
|
|
54
38
|
*/
|
|
55
39
|
export type WireScalarForms = {
|
|
56
40
|
readonly string: string;
|
|
@@ -61,42 +45,38 @@ export type WireScalarForms = {
|
|
|
61
45
|
readonly decimal: string;
|
|
62
46
|
readonly datetime: string;
|
|
63
47
|
readonly bytes: string;
|
|
64
|
-
/**
|
|
65
|
-
* The same form as the application's: `normalizeJsonValue` has no client
|
|
66
|
-
* branch, and a JSON value needs no encoding to cross a JSON wire.
|
|
67
|
-
*/
|
|
48
|
+
/** The same as in process: a JSON value needs no encoding to cross a JSON wire. */
|
|
68
49
|
readonly json: Exclude<JsonValue, null>;
|
|
69
50
|
};
|
|
70
|
-
/**
|
|
71
|
-
* One value of a scalar field, before `list` and `nullable` apply.
|
|
72
|
-
*
|
|
73
|
-
* Exported to the argument surface only, never from the package: a filter's
|
|
74
|
-
* `in`, a list's `has` and a mutation directive's operand each take one entry of
|
|
75
|
-
* a list field, which is exactly this, and a second spelling of it would be a
|
|
76
|
-
* second derivation of one rule.
|
|
77
|
-
*/
|
|
51
|
+
/** One value of a scalar field, before `list` and `nullable` apply. */
|
|
78
52
|
export type ScalarAtom<C extends Contract, Type, Forms extends ScalarForms> = Type extends {
|
|
79
53
|
readonly enum: infer Enum extends keyof C["enums"];
|
|
80
54
|
} ? C["enums"][Enum]["values"][number] : Type extends {
|
|
81
55
|
readonly scalar: infer Scalar;
|
|
82
56
|
} ? Scalar extends keyof Forms ? Forms[Scalar] : unknown : never;
|
|
57
|
+
/**
|
|
58
|
+
* One value of a scalar field, before `list` and `nullable` apply: its Json
|
|
59
|
+
* Shape's type where the field is shaped, otherwise {@link ScalarAtom}.
|
|
60
|
+
*/
|
|
61
|
+
export type FieldAtom<C extends Contract, Field extends {
|
|
62
|
+
readonly type: unknown;
|
|
63
|
+
readonly json?: unknown;
|
|
64
|
+
}, Forms extends ScalarForms> = Field extends {
|
|
65
|
+
readonly json: JsonFieldType<infer Value>;
|
|
66
|
+
} ? Value : ScalarAtom<C, Field["type"], Forms>;
|
|
83
67
|
/**
|
|
84
68
|
* `list: true` makes the value a read-only array of atoms. A `list` the Contract
|
|
85
69
|
* left as a plain `boolean` admits either, so neither form is promised.
|
|
86
70
|
*/
|
|
87
71
|
type ListValue<List, Atom> = [List] extends [false] ? Atom : [List] extends [true] ? readonly Atom[] : Atom | readonly Atom[];
|
|
88
72
|
/**
|
|
89
|
-
* The value type of one scalar field, under one scalar-form map
|
|
73
|
+
* The value type of one scalar field, under one scalar-form map:
|
|
90
74
|
*
|
|
91
|
-
* - enum-backed → the
|
|
92
|
-
*
|
|
75
|
+
* - enum-backed → the union of its values (literal only while the model is
|
|
76
|
+
* `as const`; otherwise `string`);
|
|
93
77
|
* - built-in scalar → `Forms[scalar]`;
|
|
94
|
-
* - `list: true` → `readonly T[]`, whose entries are never `null
|
|
95
|
-
* (`normalizeScalarFieldValue` refuses a null entry);
|
|
78
|
+
* - `list: true` → `readonly T[]`, whose entries are never `null`;
|
|
96
79
|
* - `nullable: true` → `| null`, on the whole value, list or not.
|
|
97
|
-
*
|
|
98
|
-
* Nullability is read as "can it be `true`", so a Contract that widened the flag
|
|
99
|
-
* to `boolean` is typed nullable rather than promised non-null.
|
|
100
80
|
*/
|
|
101
|
-
export type ScalarValueType<C extends Contract, Field extends ScalarField<C>, Forms extends ScalarForms = ApplicationScalarForms> = ListValue<Field["list"],
|
|
81
|
+
export type ScalarValueType<C extends Contract, Field extends ScalarField<C>, Forms extends ScalarForms = ApplicationScalarForms> = ListValue<Field["list"], FieldAtom<C, Field, Forms>> | (true extends Field["nullable"] ? null : never);
|
|
102
82
|
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** The built-in scalar types of the Aventara protocol. */
|
|
2
2
|
export declare const BUILT_IN_SCALARS: readonly ["string", "boolean", "int", "float", "bigint", "decimal", "datetime", "bytes", "json"];
|
|
3
|
+
/** One of {@link BUILT_IN_SCALARS}. */
|
|
3
4
|
export type BuiltInScalar = (typeof BUILT_IN_SCALARS)[number];
|
|
4
|
-
/**
|
|
5
|
+
/** One entry of a scalar registry. */
|
|
5
6
|
export type ScalarDefinition = {
|
|
6
7
|
readonly builtin: true;
|
|
7
8
|
};
|
|
8
|
-
/**
|
|
9
|
+
/** The scalar types an adapter model or Contract supports, by name. */
|
|
9
10
|
export type ScalarRegistry = Readonly<Record<string, ScalarDefinition>>;
|
|
@@ -2,9 +2,9 @@ import type { BuiltInScalar } from "./scalar.js";
|
|
|
2
2
|
import type { ApplicationScalarForms, WireScalarForms } from "./scalar-value-type.js";
|
|
3
3
|
/**
|
|
4
4
|
* The built-in scalars whose wire form is not their runtime form — the ones a JSON
|
|
5
|
-
* wire carries as a string with a grammar of its own. Derived from the two form
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* wire carries as a string with a grammar of its own. Derived from the two form maps
|
|
6
|
+
* rather than listed, so a built-in scalar added with a string wire form fails to
|
|
7
|
+
* compile below until its grammar is written.
|
|
8
8
|
*/
|
|
9
9
|
type WireEncodedScalar = {
|
|
10
10
|
readonly [S in BuiltInScalar]: WireScalarForms[S] extends ApplicationScalarForms[S] ? never : S;
|
|
@@ -13,18 +13,6 @@ type WireEncodedScalar = {
|
|
|
13
13
|
* `AvProtocol.scalarFormats` — the wire grammars of protocol version 1, as passive
|
|
14
14
|
* data: one anchored pattern SOURCE string per wire-encoded scalar, in
|
|
15
15
|
* `BUILT_IN_SCALARS` order.
|
|
16
|
-
*
|
|
17
|
-
* The one source: execution decodes client-scope arguments with these
|
|
18
|
-
* (`runtime/scalar-runtime.ts`, `runtime/decimal.ts`), `@aventara/core/protocol`
|
|
19
|
-
* re-exports this object, and the client generator emits each source by value into
|
|
20
|
-
* the generated runtime as a regular-expression literal. Strings, not `RegExp`s,
|
|
21
|
-
* so it survives JSON and can be emitted; frozen, so no consumer can rewrite a
|
|
22
|
-
* grammar in place.
|
|
23
|
-
*
|
|
24
|
-
* A grammar is the SHAPE only. Two scalars carry one more rule each, applied where
|
|
25
|
-
* they decode: a `datetime` must also round-trip `toISOString()` exactly, and a
|
|
26
|
-
* `bytes` string's padded group must leave its unused bits zero ({@link
|
|
27
|
-
* decodeBase64}).
|
|
28
16
|
*/
|
|
29
17
|
export declare const scalarFormats: Readonly<{
|
|
30
18
|
readonly bigint: "^-?(?:0|[1-9]\\d*)$";
|
|
@@ -32,18 +20,15 @@ export declare const scalarFormats: Readonly<{
|
|
|
32
20
|
readonly datetime: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$";
|
|
33
21
|
readonly bytes: "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$";
|
|
34
22
|
}>;
|
|
35
|
-
/** {@link scalarFormats}, compiled
|
|
23
|
+
/** {@link scalarFormats}, compiled to regular expressions. */
|
|
36
24
|
export declare const WIRE_SCALAR_PATTERNS: {
|
|
37
25
|
readonly [S in WireEncodedScalar]: RegExp;
|
|
38
26
|
};
|
|
39
27
|
/** RFC 4648 base64, standard alphabet, padded: the canonical spelling of `bytes`. */
|
|
40
28
|
export declare function encodeBase64(bytes: Uint8Array): string;
|
|
41
29
|
/**
|
|
42
|
-
* The bytes of a
|
|
43
|
-
* string
|
|
44
|
-
* bits a padded final group does not carry must be zero, or two wire strings would
|
|
45
|
-
* name one byte sequence (`"AB=="` and `"AA=="` both `[0]`). The generated
|
|
46
|
-
* client's decoder applies the same rule.
|
|
30
|
+
* The bytes of a canonical RFC 4648 base64 string; `undefined` for any other
|
|
31
|
+
* string, including one whose unused padding bits are not zero.
|
|
47
32
|
*/
|
|
48
33
|
export declare function decodeBase64(wire: string): Uint8Array | undefined;
|
|
49
34
|
export {};
|