@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,9 +2,13 @@ import { compileContracts } from "../compiler/contract.compiler.js";
|
|
|
2
2
|
import { resolveFrameworkConfig } from "../config/config.resolver.js";
|
|
3
3
|
import { validateFrameworkConfig } from "../config/config.validator.js";
|
|
4
4
|
import { AVENTARA_PROTOCOL_VERSION } from "../contracts/contract-protocol.js";
|
|
5
|
+
import { copyEnvelopeAtDoor, refuseCallerData, } from "../runtime/caller-data.door.js";
|
|
5
6
|
import { createDiagnosticsReporter, createTransactionDiagnosticsChannel, recordDiagnosticsSink, } from "../runtime/diagnostics-reporter.js";
|
|
6
|
-
import {
|
|
7
|
+
import { createMisuseReporter, } from "../runtime/misuse-reporter.js";
|
|
8
|
+
import { internalFailure, operationFailure, } from "../runtime/operation-response.js";
|
|
7
9
|
import { createOperationRuntime } from "../runtime/operation-runtime.js";
|
|
10
|
+
import { recordOwnedExecution } from "../runtime/owned-execution.registry.js";
|
|
11
|
+
import { validateOperationEnvelope, validateTransactionEnvelope, } from "../runtime/request-envelope.validator.js";
|
|
8
12
|
import { requestIdOf } from "../runtime/request-id.js";
|
|
9
13
|
import { createTransactionPlanAssembler } from "../transactions/transaction-plan-assembler.js";
|
|
10
14
|
import { createTransactionRuntime } from "../transactions/transaction-runtime.js";
|
|
@@ -41,25 +45,26 @@ export async function createFramework(config) {
|
|
|
41
45
|
contracts: compilation.contracts,
|
|
42
46
|
config: resolvedConfig,
|
|
43
47
|
});
|
|
44
|
-
const
|
|
48
|
+
const misuse = createMisuseReporter(resolvedConfig.misuse);
|
|
49
|
+
const executeOperation = (request) => executeTotally(execute, request, resolvedConfig.diagnostics, "caller");
|
|
45
50
|
const protocol = {
|
|
46
51
|
version: AVENTARA_PROTOCOL_VERSION,
|
|
47
52
|
hash: compilation.contracts.client.protocol.hash,
|
|
48
53
|
};
|
|
49
|
-
const assembler = createTransactionPlanAssembler(compilation.contracts, protocol);
|
|
54
|
+
const assembler = createTransactionPlanAssembler(compilation.contracts, protocol, misuse);
|
|
50
55
|
const framework = {
|
|
51
56
|
entrypoint: resolvedConfig.entrypoint,
|
|
52
57
|
contracts: compilation.contracts,
|
|
53
58
|
application: createOperationFacade(model, (resource, identity, args, requestId) => ({
|
|
54
59
|
...identity,
|
|
55
|
-
|
|
60
|
+
origin: "application",
|
|
56
61
|
requestId,
|
|
57
62
|
resource,
|
|
58
63
|
arguments: args,
|
|
59
64
|
}), executeOperation),
|
|
60
65
|
client: createOperationFacade(model, (resource, identity, args, requestId) => ({
|
|
61
66
|
...identity,
|
|
62
|
-
|
|
67
|
+
origin: "client",
|
|
63
68
|
protocol,
|
|
64
69
|
requestId,
|
|
65
70
|
resource,
|
|
@@ -67,28 +72,66 @@ export async function createFramework(config) {
|
|
|
67
72
|
}), executeOperation),
|
|
68
73
|
appTx: createOperationTree(model, (resource, identity) => (args) => assembler.defer("application", resource, identity, args === undefined ? {} : args)),
|
|
69
74
|
clientTx: createOperationTree(model, (resource, identity) => (args) => assembler.defer("client", resource, identity, args === undefined ? {} : args)),
|
|
70
|
-
execute:
|
|
71
|
-
executeTransaction: (request) =>
|
|
75
|
+
execute: (request) => executeRequestTotally(execute, request, resolvedConfig.diagnostics, misuse),
|
|
76
|
+
executeTransaction: (request) => executeTransactionRequestTotally(executeTransaction, request, resolvedConfig.diagnostics, misuse),
|
|
72
77
|
transaction: ((operations, options) => runTransactionTotally(executeTransaction, assembler, operations, requestIdOf(options), resolvedConfig.diagnostics)),
|
|
73
78
|
};
|
|
74
79
|
recordDiagnosticsSink(framework, resolvedConfig.diagnostics);
|
|
80
|
+
recordOwnedExecution(framework, {
|
|
81
|
+
execute: (request) => executeTotally(execute, request, resolvedConfig.diagnostics, "owned"),
|
|
82
|
+
executeTransaction: (request) => executeTransactionTotally(executeTransaction, request, resolvedConfig.diagnostics, undefined, { source: "owned" }),
|
|
83
|
+
});
|
|
75
84
|
return framework;
|
|
76
85
|
}
|
|
77
|
-
async function executeTotally(execute, request, diagnostics) {
|
|
86
|
+
async function executeTotally(execute, request, diagnostics, source) {
|
|
78
87
|
const report = createDiagnosticsReporter(diagnostics, request);
|
|
79
88
|
try {
|
|
80
|
-
return await execute(request, report);
|
|
89
|
+
return await execute(request, report, source);
|
|
81
90
|
}
|
|
82
91
|
catch (error) {
|
|
83
92
|
report(error, "A3000");
|
|
84
93
|
return internalFailure();
|
|
85
94
|
}
|
|
86
95
|
}
|
|
87
|
-
|
|
96
|
+
function executeRequestTotally(execute, request, diagnostics, misuse) {
|
|
97
|
+
const envelope = copyEnvelopeAtDoor(request, ["protocol", "transport"]);
|
|
98
|
+
if (!envelope.ok) {
|
|
99
|
+
return Promise.resolve(operationFailure("A2004", {
|
|
100
|
+
message: "Operation arguments failed framework validation.",
|
|
101
|
+
issues: [refuseCallerData(envelope.error, [], {}, misuse)],
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
const malformed = validateOperationEnvelope(envelope.value);
|
|
105
|
+
if (malformed.length > 0) {
|
|
106
|
+
return Promise.resolve(operationFailure("A2004", {
|
|
107
|
+
message: "Operation arguments failed framework validation.",
|
|
108
|
+
issues: malformed,
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
return executeTotally(execute, envelope.value, diagnostics, "caller");
|
|
112
|
+
}
|
|
113
|
+
function executeTransactionRequestTotally(execute, request, diagnostics, misuse) {
|
|
114
|
+
const envelope = copyEnvelopeAtDoor(request, ["protocol", "transport"]);
|
|
115
|
+
if (!envelope.ok) {
|
|
116
|
+
return Promise.resolve(operationFailure("A2004", {
|
|
117
|
+
message: "Transaction plan failed framework validation.",
|
|
118
|
+
issues: [refuseCallerData(envelope.error, [], {}, misuse)],
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
const malformed = validateTransactionEnvelope(envelope.value);
|
|
122
|
+
if (malformed.length > 0) {
|
|
123
|
+
return Promise.resolve(operationFailure("A2004", {
|
|
124
|
+
message: "Transaction plan failed framework validation.",
|
|
125
|
+
issues: malformed,
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
return executeTransactionTotally(execute, envelope.value, diagnostics, undefined, { source: "caller" });
|
|
129
|
+
}
|
|
130
|
+
async function executeTransactionTotally(execute, request, diagnostics, origins, planArguments) {
|
|
88
131
|
const channel = createTransactionDiagnosticsChannel(diagnostics, request);
|
|
89
132
|
const report = channel.transaction();
|
|
90
133
|
try {
|
|
91
|
-
return await execute(request, channel, origins);
|
|
134
|
+
return await execute(request, channel, origins, planArguments);
|
|
92
135
|
}
|
|
93
136
|
catch (error) {
|
|
94
137
|
report(error, "A3000");
|
|
@@ -102,7 +145,7 @@ async function runTransactionTotally(execute, assembler, operations, requestId,
|
|
|
102
145
|
}
|
|
103
146
|
catch (error) {
|
|
104
147
|
createTransactionDiagnosticsChannel(diagnostics, {
|
|
105
|
-
|
|
148
|
+
origin: "application",
|
|
106
149
|
requestId,
|
|
107
150
|
plan: operations,
|
|
108
151
|
}).transaction()(error, "A3000");
|
|
@@ -111,5 +154,5 @@ async function runTransactionTotally(execute, assembler, operations, requestId,
|
|
|
111
154
|
if (!assembled.ok) {
|
|
112
155
|
return assembled.response;
|
|
113
156
|
}
|
|
114
|
-
return executeTransactionTotally(execute, {
|
|
157
|
+
return executeTransactionTotally(execute, { origin: "application", requestId, plan: assembled.plan }, diagnostics, assembled.origins, { source: "owned", refused: assembled.refused });
|
|
115
158
|
}
|
|
@@ -9,13 +9,9 @@ import type { FrameworkOperationRequest } from "../runtime/operation-request.js"
|
|
|
9
9
|
import type { OperationResponse } from "../runtime/operation-response.js";
|
|
10
10
|
import type { ApplicationContractView, ClientContractView } from "./contract-view.js";
|
|
11
11
|
/**
|
|
12
|
-
* A model whose Resource names are not literal — the abstract `AdapterModel`
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* `execute`. It is also what keeps a typed `Framework<M, Cfg>` assignable to
|
|
16
|
-
* `Framework` cheaply: deriving every argument and result over a `string`-keyed
|
|
17
|
-
* Contract, for all sixteen operations, measured at ≈250,000 instantiations for
|
|
18
|
-
* nothing a caller could use.
|
|
12
|
+
* A model whose Resource names are not literal — the abstract `AdapterModel` behind
|
|
13
|
+
* the default `Framework` — has no Contract to type a call against, so a surface over
|
|
14
|
+
* it is typed as the opaque object it is, and such a caller uses `execute`.
|
|
19
15
|
*/
|
|
20
16
|
type OpaqueSurface = {
|
|
21
17
|
readonly [resource: string]: unknown;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,83 +1,51 @@
|
|
|
1
1
|
export type { Adapter } from "./adapters/adapter.interface.js";
|
|
2
2
|
export type { AdapterDiscoveryDiagnostic, AdapterDiscoveryDiagnosticCode, } from "./adapters/adapter-discovery-diagnostic.js";
|
|
3
|
-
export type { AdapterField, AdapterLifecycleTrait, AdapterRelationField, AdapterScalarField, } from "./adapters/adapter-field.js";
|
|
4
|
-
export type { AdapterIdentifier, AdapterScalarFieldKey, } from "./adapters/adapter-identifier.js";
|
|
5
3
|
export type { AdapterModel } from "./adapters/adapter-model.js";
|
|
6
|
-
export type {
|
|
7
|
-
export type { AdapterOperationExecutor } from "./adapters/adapter-operation-executor.interface.js";
|
|
8
|
-
export type { AdapterFieldKey, AdapterFieldMap, AdapterResource, } from "./adapters/adapter-resource.js";
|
|
9
|
-
export type { ContractCompilationResult, FrameworkContracts, } from "./compiler/contract.compiler.js";
|
|
10
|
-
export { compileContracts } from "./compiler/contract.compiler.js";
|
|
4
|
+
export type { FrameworkContracts } from "./compiler/contract.compiler.js";
|
|
11
5
|
export type { ContractCompilerDiagnostic, ContractCompilerDiagnosticCode, } from "./compiler/contract-compiler-diagnostic.js";
|
|
12
|
-
export type { ResolvedFrameworkConfig, ResolvedFrameworkScopeConfig, } from "./config/config.resolver.js";
|
|
13
|
-
export { resolveFrameworkConfig } from "./config/config.resolver.js";
|
|
14
|
-
export { validateFrameworkConfig } from "./config/config.validator.js";
|
|
15
6
|
export type { ConfigDiagnostic, ConfigDiagnosticCode, } from "./config/config-diagnostic.js";
|
|
16
7
|
export type { ConfigLayer, RequestOrigin } from "./config/config-layer.js";
|
|
17
8
|
export type { AddedScalarFieldConfig, FrameworkFieldsShape, KnownScalarFieldConfig, } from "./config/define-fields.js";
|
|
18
9
|
export { defineFields } from "./config/define-fields.js";
|
|
19
|
-
export type { ConfigFieldKey, EffectiveFieldKey,
|
|
10
|
+
export type { ConfigFieldKey, EffectiveFieldKey, } from "./config/effective-fields.js";
|
|
20
11
|
export type { FrameworkFieldBehaviorConfig, FrameworkReadBehavior, FrameworkResourceBehaviorsConfig, } from "./config/framework-behaviors-config.js";
|
|
21
12
|
export type { AnyFieldsBlock, AnyFrameworkConfig, AnyScopeConfig, FrameworkBehaviorsConfig, FrameworkCapabilitySetRestriction, FrameworkConfig, FrameworkFieldLifecycleTrait, FrameworkFieldRestrictions, FrameworkFieldsConfig, FrameworkLimitsConfig, FrameworkProjectionScopeRestriction, FrameworkRelationCapabilityRestrictions, FrameworkRelationFieldRestrictions, FrameworkRelationMutationRestriction, FrameworkRelationReducerRestriction, FrameworkResourceFieldRestrictions, FrameworkResourceFieldsConfig, FrameworkResourceKey, FrameworkResourceOperationRestrictions, FrameworkResourceRestrictions, FrameworkRestrictionsConfig, FrameworkScalarCapabilityRestrictions, FrameworkScalarFieldConfig, FrameworkScalarFieldRestrictions, FrameworkScalarTypeRef, FrameworkScopeConfig, } from "./config/framework-config.js";
|
|
22
|
-
export type { PipelineConfig
|
|
13
|
+
export type { PipelineConfig } from "./config/pipeline-config.js";
|
|
23
14
|
export type { PaginationCapability, ProjectionScope, RelationFilterCapability, RelationMutationDirective, RelationReducer, ScalarFilterOperator, ScalarMutationDirective, WriteScope, } from "./contracts/capability.js";
|
|
24
|
-
export { PROJECTION_SCOPES, WRITE_SCOPES, } from "./contracts/capability.js";
|
|
25
|
-
export type { ClientContractStructureVerdict } from "./contracts/client-contract-structure.validator.js";
|
|
26
|
-
export { validateClientContractStructure } from "./contracts/client-contract-structure.validator.js";
|
|
27
15
|
export type { ApplicationContract, ClientContract, Contract, CoreContract, } from "./contracts/contract.js";
|
|
28
|
-
export { CanonicalJsonError, canonicalizeContract, canonicalizeJson, } from "./contracts/contract-canonicalizer.js";
|
|
29
|
-
export type { ClientContractHashInput } from "./contracts/contract-hash.js";
|
|
30
|
-
export { computeClientContractHash, verifyClientContractHash, } from "./contracts/contract-hash.js";
|
|
31
16
|
export type { ContractLimits } from "./contracts/contract-limits.js";
|
|
32
|
-
export { DEFAULT_CONTRACT_LIMITS } from "./contracts/contract-limits.js";
|
|
33
17
|
export type { ClientContractProtocol, ContractHash, ContractProtocol, } from "./contracts/contract-protocol.js";
|
|
34
|
-
export { AVENTARA_PROTOCOL_VERSION } from "./contracts/contract-protocol.js";
|
|
35
18
|
export type { EnumDefinition } from "./contracts/enum-definition.js";
|
|
36
19
|
export type { Field, ProjectionScopes, RelationField, RelationFieldCapabilities, RelationMutationCapability, RelationProjectionCapability, RelationReducerCapability, ScalarField, ScalarFieldCapabilities, ScalarFormat, ScopedRelationMutations, ScopedRelationReducers, WriteScopes, } from "./contracts/field.js";
|
|
37
|
-
export { advertisedDirectives, advertisedDirectivesAt, advertisedReducers, advertisedReducersAt, holdsAt, holdsInAnyScope, } from "./contracts/field.js";
|
|
38
20
|
export type { Identifier, ScalarFieldKey } from "./contracts/identifier.js";
|
|
39
21
|
export type { LifecycleTrait } from "./contracts/lifecycle-trait.js";
|
|
40
|
-
export { LIFECYCLE_TRAITS } from "./contracts/lifecycle-trait.js";
|
|
41
22
|
export type { Resource, ResourceFieldMap } from "./contracts/resource.js";
|
|
42
23
|
export type { OperationAvailability, OperationVariantScopes, ResourceOperations, } from "./contracts/resource-operations.js";
|
|
43
|
-
export { isOperationVariantAvailable, projectionScopeOf, writeScopeOf, } from "./contracts/resource-operations.js";
|
|
44
24
|
export type { BuiltInScalar, ScalarDefinition, ScalarRegistry, } from "./contracts/scalar.js";
|
|
45
|
-
export { BUILT_IN_SCALARS } from "./contracts/scalar.js";
|
|
46
25
|
export type { ApplicationScalarForms, ScalarValueType, WireScalarForms, } from "./contracts/scalar-value-type.js";
|
|
47
26
|
export type { TransactionCapability } from "./contracts/transaction-capability.js";
|
|
48
|
-
export { TRANSACTION_CAPABILITIES } from "./contracts/transaction-capability.js";
|
|
49
|
-
export type { ApplicationContractView } from "./framework/contract-view.js";
|
|
50
27
|
export { createFramework } from "./framework/framework.factory.js";
|
|
51
28
|
export type { Framework } from "./framework/framework.js";
|
|
52
29
|
export type { FrameworkConstructionDiagnostic, FrameworkConstructionStage, } from "./framework/framework-construction.error.js";
|
|
53
30
|
export { FrameworkConstructionError } from "./framework/framework-construction.error.js";
|
|
54
|
-
export type { CreateDataInput, CursorInput, FieldKey, IncludeInput, NullsOrder, OperationArgumentMap, OperationArgumentsFor, OrderByEntry, OrderByInput, ProjectionEntry,
|
|
31
|
+
export type { CreateDataInput, CursorInput, FieldKey, IncludeInput, NullsOrder, OperationArgumentMap, OperationArgumentsFor, OrderByEntry, OrderByInput, ProjectionEntry, RelationProjectionInput, ResourceKey, ScalarOrderInput, SelectInput, SortDirection, UniqueWhereInput, UpdateDataInput, WhereInput, } from "./operations/operation-arguments.js";
|
|
55
32
|
export type { DeferredOperationCall, OperationCall, OperationGrammar, OperationSlot, } from "./operations/operation-call.js";
|
|
56
33
|
export type { OperationFamily, OperationIdentity, OperationVariant, } from "./operations/operation-identity.js";
|
|
57
34
|
export type { OperationResultFor } from "./operations/operation-result.js";
|
|
58
|
-
export type { OperationValidationResult, SemanticOperationArguments, } from "./operations/operation-validator.js";
|
|
59
|
-
export { validateOperationArguments } from "./operations/operation-validator.js";
|
|
60
35
|
export type { ValidationCode, ValidationIssue, } from "./operations/validation-code.js";
|
|
61
|
-
export { VALIDATION_CODE_MESSAGES, VALIDATION_CODES, } from "./operations/validation-code.js";
|
|
62
36
|
export { Decimal } from "./runtime/decimal.js";
|
|
63
37
|
export type { FrameworkDiagnostic, FrameworkDiagnosticsSink, OperationDiagnostic, TransactionDiagnostic, } from "./runtime/diagnostics-reporter.js";
|
|
64
38
|
export type { ExecutionOptions } from "./runtime/execution-options.js";
|
|
65
39
|
export type { ComputedReadBehavior, ComputeOnCreate, ComputeOnRead, ComputeOnUpdate, } from "./runtime/field-behavior.js";
|
|
66
40
|
export { FrameworkError } from "./runtime/framework-error.js";
|
|
67
41
|
export type { JsonValue } from "./runtime/json-value.js";
|
|
68
|
-
export type {
|
|
69
|
-
export type { Cause, OperationCode, OperationErrorCode, OperationFailureResponse,
|
|
70
|
-
export { OPERATION_CODES, operationFailure, operationNoMatch, operationSuccess, } from "./runtime/operation-response.js";
|
|
42
|
+
export type { FrameworkMisuseEvent, FrameworkMisuseSink, } from "./runtime/misuse-reporter.js";
|
|
43
|
+
export type { Cause, OperationCode, OperationErrorCode, OperationFailureResponse, OperationNoMatchResponse, OperationResponse, OperationSuccessCode, OperationSuccessDataCode, OperationSuccessResponse, } from "./runtime/operation-response.js";
|
|
71
44
|
export type { AfterHook, BeforeHook, Filter, Guard, Interceptor, Pipe, PipelineContext, PipelineTransportContext, } from "./runtime/pipeline.js";
|
|
72
|
-
export type {
|
|
73
|
-
export type { OperationFingerprintNode } from "./transactions/operation-fingerprint.js";
|
|
74
|
-
export { computeOperationFingerprint, isOperationFingerprint, } from "./transactions/operation-fingerprint.js";
|
|
45
|
+
export type { Operation, OperationReferenceSurface, ReferenceableField, ReferenceBuilder, SingleRowResult, TransactionResults, TransactionRunner, } from "./transactions/deferred-operation.js";
|
|
75
46
|
export type { TransactionIntegrityViolation } from "./transactions/transaction-integrity-error.js";
|
|
76
47
|
export { TransactionIntegrityError } from "./transactions/transaction-integrity-error.js";
|
|
77
|
-
export type {
|
|
78
|
-
export { isTransactionReferenceCandidate, isTransactionReferenceObject, } from "./transactions/transaction-reference.js";
|
|
79
|
-
export type { ApplicationTransactionRequest, ClientTransactionRequest, FrameworkTransactionRequest, } from "./transactions/transaction-request.js";
|
|
48
|
+
export type { TransactionReference } from "./transactions/transaction-reference.js";
|
|
80
49
|
export type { TransactionCommittedResponse, TransactionResponse, } from "./transactions/transaction-response.js";
|
|
81
|
-
export { transactionCommitted, transactionInfrastructureFailure, transactionOperationFailure, } from "./transactions/transaction-response.js";
|
|
82
50
|
export type { TransactionSlotPathViolation } from "./transactions/transaction-slot-path-error.js";
|
|
83
51
|
export { TransactionSlotPathError } from "./transactions/transaction-slot-path-error.js";
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,7 @@
|
|
|
1
|
-
export { compileContracts } from "./compiler/contract.compiler.js";
|
|
2
|
-
export { resolveFrameworkConfig } from "./config/config.resolver.js";
|
|
3
|
-
export { validateFrameworkConfig } from "./config/config.validator.js";
|
|
4
1
|
export { defineFields } from "./config/define-fields.js";
|
|
5
|
-
export { PROJECTION_SCOPES, WRITE_SCOPES, } from "./contracts/capability.js";
|
|
6
|
-
export { validateClientContractStructure } from "./contracts/client-contract-structure.validator.js";
|
|
7
|
-
export { CanonicalJsonError, canonicalizeContract, canonicalizeJson, } from "./contracts/contract-canonicalizer.js";
|
|
8
|
-
export { computeClientContractHash, verifyClientContractHash, } from "./contracts/contract-hash.js";
|
|
9
|
-
export { DEFAULT_CONTRACT_LIMITS } from "./contracts/contract-limits.js";
|
|
10
|
-
export { AVENTARA_PROTOCOL_VERSION } from "./contracts/contract-protocol.js";
|
|
11
|
-
export { advertisedDirectives, advertisedDirectivesAt, advertisedReducers, advertisedReducersAt, holdsAt, holdsInAnyScope, } from "./contracts/field.js";
|
|
12
|
-
export { LIFECYCLE_TRAITS } from "./contracts/lifecycle-trait.js";
|
|
13
|
-
export { isOperationVariantAvailable, projectionScopeOf, writeScopeOf, } from "./contracts/resource-operations.js";
|
|
14
|
-
export { BUILT_IN_SCALARS } from "./contracts/scalar.js";
|
|
15
|
-
export { TRANSACTION_CAPABILITIES } from "./contracts/transaction-capability.js";
|
|
16
2
|
export { createFramework } from "./framework/framework.factory.js";
|
|
17
3
|
export { FrameworkConstructionError } from "./framework/framework-construction.error.js";
|
|
18
|
-
export { validateOperationArguments } from "./operations/operation-validator.js";
|
|
19
|
-
export { VALIDATION_CODE_MESSAGES, VALIDATION_CODES, } from "./operations/validation-code.js";
|
|
20
4
|
export { Decimal } from "./runtime/decimal.js";
|
|
21
5
|
export { FrameworkError } from "./runtime/framework-error.js";
|
|
22
|
-
export { OPERATION_CODES, operationFailure, operationNoMatch, operationSuccess, } from "./runtime/operation-response.js";
|
|
23
|
-
export { computeOperationFingerprint, isOperationFingerprint, } from "./transactions/operation-fingerprint.js";
|
|
24
6
|
export { TransactionIntegrityError } from "./transactions/transaction-integrity-error.js";
|
|
25
|
-
export { isTransactionReferenceCandidate, isTransactionReferenceObject, } from "./transactions/transaction-reference.js";
|
|
26
|
-
export { transactionCommitted, transactionInfrastructureFailure, transactionOperationFailure, } from "./transactions/transaction-response.js";
|
|
27
7
|
export { TransactionSlotPathError } from "./transactions/transaction-slot-path-error.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@aventara/core/internal` is not public API.
|
|
3
|
+
*
|
|
4
|
+
* It holds what Aventara's own packages (the adapters, the client generator,
|
|
5
|
+
* the testing kit) need from core and an application does not. It carries no
|
|
6
|
+
* stability promise: any export here may change or disappear in any release,
|
|
7
|
+
* including a patch release. Applications import from `@aventara/core`.
|
|
8
|
+
*/
|
|
9
|
+
export type { AdapterField, AdapterLifecycleTrait, AdapterRelationField, AdapterScalarField, } from "./adapters/adapter-field.js";
|
|
10
|
+
export type { AdapterIdentifier, AdapterScalarFieldKey, } from "./adapters/adapter-identifier.js";
|
|
11
|
+
export type { AdapterOperation } from "./adapters/adapter-operation.js";
|
|
12
|
+
export type { AdapterOperationExecutor } from "./adapters/adapter-operation-executor.interface.js";
|
|
13
|
+
export type { AdapterFieldKey, AdapterFieldMap, AdapterResource, } from "./adapters/adapter-resource.js";
|
|
14
|
+
export { compileContracts } from "./compiler/contract.compiler.js";
|
|
15
|
+
export { resolveFrameworkConfig } from "./config/config.resolver.js";
|
|
16
|
+
export { PROJECTION_SCOPES, WRITE_SCOPES } from "./contracts/capability.js";
|
|
17
|
+
export { validateClientContractStructure } from "./contracts/client-contract-structure.validator.js";
|
|
18
|
+
export { CanonicalJsonError, canonicalizeContract, canonicalizeJson, } from "./contracts/contract-canonicalizer.js";
|
|
19
|
+
export type { ClientContractHashInput } from "./contracts/contract-hash.js";
|
|
20
|
+
export { computeClientContractHash, verifyClientContractHash, } from "./contracts/contract-hash.js";
|
|
21
|
+
export { DEFAULT_CONTRACT_LIMITS } from "./contracts/contract-limits.js";
|
|
22
|
+
export { AVENTARA_PROTOCOL_VERSION } from "./contracts/contract-protocol.js";
|
|
23
|
+
export { advertisedDirectives, advertisedReducers } from "./contracts/field.js";
|
|
24
|
+
export { LIFECYCLE_TRAITS } from "./contracts/lifecycle-trait.js";
|
|
25
|
+
export { isOperationVariantAvailable, projectionScopeOf, writeScopeOf, } from "./contracts/resource-operations.js";
|
|
26
|
+
export { BUILT_IN_SCALARS } from "./contracts/scalar.js";
|
|
27
|
+
export { TRANSACTION_CAPABILITIES } from "./contracts/transaction-capability.js";
|
|
28
|
+
export type { ApplicationContractView } from "./framework/contract-view.js";
|
|
29
|
+
export type { SemanticOperationArguments } from "./operations/operation-validator.js";
|
|
30
|
+
export { VALIDATION_CODES } from "./operations/validation-code.js";
|
|
31
|
+
export type { ApplicationOperationRequest, ClientOperationRequest, ClientProtocolIdentity, FrameworkOperationRequest, } from "./runtime/operation-request.js";
|
|
32
|
+
export { OPERATION_CODES } from "./runtime/operation-response.js";
|
|
33
|
+
export type { BuiltinNonRow, OperationFingerprint, } from "./transactions/deferred-operation.js";
|
|
34
|
+
export { computeOperationFingerprint } from "./transactions/operation-fingerprint.js";
|
|
35
|
+
export type { ApplicationTransactionRequest, ClientTransactionRequest, FrameworkTransactionRequest, } from "./transactions/transaction-request.js";
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { compileContracts } from "./compiler/contract.compiler.js";
|
|
2
|
+
export { resolveFrameworkConfig } from "./config/config.resolver.js";
|
|
3
|
+
export { PROJECTION_SCOPES, WRITE_SCOPES } from "./contracts/capability.js";
|
|
4
|
+
export { validateClientContractStructure } from "./contracts/client-contract-structure.validator.js";
|
|
5
|
+
export { CanonicalJsonError, canonicalizeContract, canonicalizeJson, } from "./contracts/contract-canonicalizer.js";
|
|
6
|
+
export { computeClientContractHash, verifyClientContractHash, } from "./contracts/contract-hash.js";
|
|
7
|
+
export { DEFAULT_CONTRACT_LIMITS } from "./contracts/contract-limits.js";
|
|
8
|
+
export { AVENTARA_PROTOCOL_VERSION } from "./contracts/contract-protocol.js";
|
|
9
|
+
export { advertisedDirectives, advertisedReducers } from "./contracts/field.js";
|
|
10
|
+
export { LIFECYCLE_TRAITS } from "./contracts/lifecycle-trait.js";
|
|
11
|
+
export { isOperationVariantAvailable, projectionScopeOf, writeScopeOf, } from "./contracts/resource-operations.js";
|
|
12
|
+
export { BUILT_IN_SCALARS } from "./contracts/scalar.js";
|
|
13
|
+
export { TRANSACTION_CAPABILITIES } from "./contracts/transaction-capability.js";
|
|
14
|
+
export { VALIDATION_CODES } from "./operations/validation-code.js";
|
|
15
|
+
export { OPERATION_CODES } from "./runtime/operation-response.js";
|
|
16
|
+
export { computeOperationFingerprint } from "./transactions/operation-fingerprint.js";
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { JsonSchemaPrimitive, JsonShape, JsonShapeValue } from "../contracts/json-shape.js";
|
|
2
|
+
/** The forms a Json Shape takes. */
|
|
3
|
+
export type AvZKind = "string" | "number" | "int" | "boolean" | "null" | "literal" | "enum" | "object" | "array" | "tuple" | "record" | "union" | "discriminatedUnion" | "optional" | "nullable";
|
|
4
|
+
/**
|
|
5
|
+
* A Json Shape built with {@link AvZ}: opaque, its `kind` the only member. Its
|
|
6
|
+
* TypeScript type is `AvZ.infer<typeof shape>`.
|
|
7
|
+
*/
|
|
8
|
+
export interface AvZShape<Value = unknown, Kind extends AvZKind = AvZKind> extends JsonShape<Value> {
|
|
9
|
+
readonly kind: Kind;
|
|
10
|
+
}
|
|
11
|
+
/** The fields of an object shape, by key. */
|
|
12
|
+
export type AvZFields = {
|
|
13
|
+
readonly [key: string]: AvZShape;
|
|
14
|
+
};
|
|
15
|
+
declare const avzOptionalKey: unique symbol;
|
|
16
|
+
/** Marks a shape whose object key may be left out. Type-level only. */
|
|
17
|
+
interface AvZOptionalKey {
|
|
18
|
+
readonly [avzOptionalKey]: true;
|
|
19
|
+
}
|
|
20
|
+
type FieldKeysOptional<Fields extends AvZFields> = {
|
|
21
|
+
[Key in keyof Fields]: Fields[Key] extends AvZOptionalKey ? Key : never;
|
|
22
|
+
}[keyof Fields];
|
|
23
|
+
type Flatten<T> = {
|
|
24
|
+
[Key in keyof T]: T[Key];
|
|
25
|
+
} & {};
|
|
26
|
+
/** The value an object shape describes. */
|
|
27
|
+
type AvZObjectValue<Fields extends AvZFields> = ObjectValueOf<Fields, FieldKeysOptional<Fields>>;
|
|
28
|
+
type ObjectValueOf<Fields extends AvZFields, Optional extends keyof Fields> = Flatten<{
|
|
29
|
+
-readonly [Key in Exclude<keyof Fields, Optional>]: JsonShapeValue<Fields[Key]>;
|
|
30
|
+
} & {
|
|
31
|
+
-readonly [Key in Optional]?: JsonShapeValue<Fields[Key]>;
|
|
32
|
+
}>;
|
|
33
|
+
/** An object shape: closed, so a key it does not declare is refused. */
|
|
34
|
+
export interface AvZObject<Fields extends AvZFields = AvZFields> extends AvZShape<AvZObjectValue<Fields>, "object"> {
|
|
35
|
+
readonly fields: Fields;
|
|
36
|
+
}
|
|
37
|
+
/** A shape whose object key may be left out. */
|
|
38
|
+
export interface AvZOptional<Inner extends AvZShape = AvZShape> extends AvZShape<JsonShapeValue<Inner> | undefined, "optional">, AvZOptionalKey {
|
|
39
|
+
}
|
|
40
|
+
/** A shape that also admits `null`. */
|
|
41
|
+
export type AvZNullable<Inner extends AvZShape = AvZShape> = AvZShape<JsonShapeValue<Inner> | null, "nullable"> & (Inner extends AvZOptionalKey ? AvZOptionalKey : unknown);
|
|
42
|
+
/** A value a literal shape may hold. */
|
|
43
|
+
export type AvZLiteralValue = JsonSchemaPrimitive;
|
|
44
|
+
/** What keys a record shape: any string, an enum's values or one literal. */
|
|
45
|
+
type AvZRecordKey = AvZShape<string, "string"> | AvZShape<string, "enum"> | AvZShape<string, "literal">;
|
|
46
|
+
/** An option of a discriminated union: an object whose discriminator is a literal or an enum. */
|
|
47
|
+
type AvZDiscriminable<Discriminator extends string> = AvZObject<{
|
|
48
|
+
readonly [Key in Discriminator]: AvZShape<AvZLiteralValue, "literal"> | AvZShape<string, "enum">;
|
|
49
|
+
} & AvZFields>;
|
|
50
|
+
type TupleValue<Items extends readonly AvZShape[]> = {
|
|
51
|
+
-readonly [Index in keyof Items]: JsonShapeValue<Items[Index]>;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Builds Json Shapes: the type of a Json field, declared in the configuration as
|
|
55
|
+
* `fields: { Post: { meta: { json: AvZ.object({ … }) } } }`. Types only — no
|
|
56
|
+
* rules, refinements, transforms or defaults. Objects are closed: a key the shape
|
|
57
|
+
* does not declare is refused.
|
|
58
|
+
*/
|
|
59
|
+
export declare class AvZ {
|
|
60
|
+
private constructor();
|
|
61
|
+
/** Any string. */
|
|
62
|
+
static readonly string: () => AvZShape<string, "string">;
|
|
63
|
+
/** Any finite number. */
|
|
64
|
+
static readonly number: () => AvZShape<number, "number">;
|
|
65
|
+
/** An integer (a safe one). */
|
|
66
|
+
static readonly int: () => AvZShape<number, "int">;
|
|
67
|
+
/** `true` or `false`. */
|
|
68
|
+
static readonly boolean: () => AvZShape<boolean, "boolean">;
|
|
69
|
+
/** `null`. */
|
|
70
|
+
static readonly null: () => AvZShape<null, "null">;
|
|
71
|
+
/** Exactly `value`: a string, a finite number, a boolean or `null`. */
|
|
72
|
+
static readonly literal: <const Value extends AvZLiteralValue>(value: Value) => AvZShape<Value, "literal">;
|
|
73
|
+
/** One of `values`. */
|
|
74
|
+
static readonly enum: <const Values extends readonly [string, ...string[]]>(values: Values) => AvZShape<Values[number], "enum">;
|
|
75
|
+
/** An object with exactly these keys; `AvZ.optional` marks one that may be left out. */
|
|
76
|
+
static readonly object: <const Fields extends AvZFields>(fields: Fields) => AvZObject<Fields>;
|
|
77
|
+
/** A list of `item`s. */
|
|
78
|
+
static readonly array: <Item extends AvZShape>(item: Item) => AvZShape<JsonShapeValue<Item>[], "array">;
|
|
79
|
+
/** A list of exactly these items, in order. */
|
|
80
|
+
static readonly tuple: <const Items extends readonly [AvZShape, ...AvZShape[]]>(items: Items) => AvZShape<TupleValue<Items>, "tuple">;
|
|
81
|
+
/** An object of `value`s, keyed by any string, an enum's values or a literal. */
|
|
82
|
+
static readonly record: <Key extends AvZRecordKey, Value extends AvZShape>(key: Key, value: Value) => AvZShape<Record<JsonShapeValue<Key>, JsonShapeValue<Value>>, "record">;
|
|
83
|
+
/** Any one of `options`. */
|
|
84
|
+
static readonly union: <const Options extends readonly [AvZShape, AvZShape, ...AvZShape[]]>(options: Options) => AvZShape<JsonShapeValue<Options[number]>, "union">;
|
|
85
|
+
/** One of `options`, told apart by the literal or enum at `discriminator`. */
|
|
86
|
+
static readonly discriminatedUnion: <Discriminator extends string, const Options extends readonly [AvZDiscriminable<Discriminator>, ...AvZDiscriminable<Discriminator>[]]>(discriminator: Discriminator, options: Options) => AvZShape<JsonShapeValue<Options[number]>, "discriminatedUnion">;
|
|
87
|
+
/** An object key that may be left out. */
|
|
88
|
+
static readonly optional: <Inner extends AvZShape>(inner: Inner) => AvZOptional<Inner>;
|
|
89
|
+
/** `inner`, or `null`. */
|
|
90
|
+
static readonly nullable: <Inner extends AvZShape>(inner: Inner) => AvZNullable<Inner>;
|
|
91
|
+
}
|
|
92
|
+
export declare namespace AvZ {
|
|
93
|
+
/** The TypeScript type a shape describes. */
|
|
94
|
+
type infer<Shape extends JsonShape> = JsonShapeValue<Shape>;
|
|
95
|
+
}
|
|
96
|
+
export {};
|
package/dist/json/avz.js
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import * as zodMini from "zod/mini";
|
|
2
|
+
import { registerJsonShape } from "./json-shape.registry.js";
|
|
3
|
+
import { translateZodIssues } from "./zod-issue.translator.js";
|
|
4
|
+
const z = zodMini;
|
|
5
|
+
const SHAPE_PROTOTYPE = Object.freeze(Object.create(null));
|
|
6
|
+
const compiled = new WeakMap();
|
|
7
|
+
function compiledOf(builder, value) {
|
|
8
|
+
const found = typeof value === "object" && value !== null
|
|
9
|
+
? compiled.get(value)
|
|
10
|
+
: undefined;
|
|
11
|
+
if (found === undefined) {
|
|
12
|
+
throw new TypeError(`AvZ.${builder}: every part of a shape must be built with AvZ (a Zod schema or any other value is not accepted).`);
|
|
13
|
+
}
|
|
14
|
+
return found;
|
|
15
|
+
}
|
|
16
|
+
function requiredPart(builder, value) {
|
|
17
|
+
const part = compiledOf(builder, value);
|
|
18
|
+
if (part.optionalKey) {
|
|
19
|
+
throw new TypeError(`AvZ.${builder}: AvZ.optional marks an object key that may be left out; use it only for a field of AvZ.object.`);
|
|
20
|
+
}
|
|
21
|
+
return part;
|
|
22
|
+
}
|
|
23
|
+
function build(node, zod, schema, optionalKey = false) {
|
|
24
|
+
const shape = Object.freeze(Object.assign(Object.create(SHAPE_PROTOTYPE), { kind: node.kind }));
|
|
25
|
+
const frozenSchema = deepFreeze(schema);
|
|
26
|
+
compiled.set(shape, { node, zod, schema: frozenSchema, optionalKey });
|
|
27
|
+
registerJsonShape(shape, {
|
|
28
|
+
schema: frozenSchema,
|
|
29
|
+
validate: (value) => {
|
|
30
|
+
const result = zod.safeParse(value);
|
|
31
|
+
return result.success
|
|
32
|
+
? []
|
|
33
|
+
: translateZodIssues(node, value, result.error.issues);
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
return shape;
|
|
37
|
+
}
|
|
38
|
+
function deepFreeze(value) {
|
|
39
|
+
if (typeof value === "object" && value !== null) {
|
|
40
|
+
for (const child of Object.values(value)) {
|
|
41
|
+
deepFreeze(child);
|
|
42
|
+
}
|
|
43
|
+
Object.freeze(value);
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
function isLiteralValue(value) {
|
|
48
|
+
return (value === null ||
|
|
49
|
+
typeof value === "string" ||
|
|
50
|
+
typeof value === "boolean" ||
|
|
51
|
+
(typeof value === "number" && Number.isFinite(value)));
|
|
52
|
+
}
|
|
53
|
+
const string = () => build({ kind: "string" }, z.string(), { type: "string" });
|
|
54
|
+
const number = () => build({ kind: "number" }, z.number(), { type: "number" });
|
|
55
|
+
const int = () => build({ kind: "int" }, z.int(), { type: "integer" });
|
|
56
|
+
const boolean = () => build({ kind: "boolean" }, z.boolean(), { type: "boolean" });
|
|
57
|
+
const nullShape = () => build({ kind: "null" }, z.null(), { type: "null" });
|
|
58
|
+
const literal = (value) => {
|
|
59
|
+
if (!isLiteralValue(value)) {
|
|
60
|
+
throw new TypeError("AvZ.literal: the value must be a string, a finite number, a boolean or null.");
|
|
61
|
+
}
|
|
62
|
+
return build({ kind: "literal", value }, z.literal(value), { const: value });
|
|
63
|
+
};
|
|
64
|
+
const enumShape = (values) => {
|
|
65
|
+
if (!Array.isArray(values) ||
|
|
66
|
+
values.length === 0 ||
|
|
67
|
+
values.some((value) => typeof value !== "string") ||
|
|
68
|
+
new Set(values).size !== values.length) {
|
|
69
|
+
throw new TypeError("AvZ.enum: the values must be a non-empty list of distinct strings.");
|
|
70
|
+
}
|
|
71
|
+
const copy = [...values];
|
|
72
|
+
return build({ kind: "enum", values: copy }, z.enum(copy), {
|
|
73
|
+
type: "string",
|
|
74
|
+
enum: copy,
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
const object = (fields) => {
|
|
78
|
+
if (typeof fields !== "object" || fields === null || Array.isArray(fields)) {
|
|
79
|
+
throw new TypeError("AvZ.object: the fields must be an object of shapes.");
|
|
80
|
+
}
|
|
81
|
+
const nodes = {};
|
|
82
|
+
const zods = {};
|
|
83
|
+
const properties = {};
|
|
84
|
+
const required = [];
|
|
85
|
+
for (const key of Object.keys(fields)) {
|
|
86
|
+
const part = compiledOf("object", fields[key]);
|
|
87
|
+
nodes[key] = part.node;
|
|
88
|
+
zods[key] = part.zod;
|
|
89
|
+
properties[key] = part.schema;
|
|
90
|
+
if (!part.optionalKey) {
|
|
91
|
+
required.push(key);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return build({ kind: "object", fields: nodes }, z.strictObject(zods), {
|
|
95
|
+
type: "object",
|
|
96
|
+
properties,
|
|
97
|
+
...(required.length > 0 ? { required } : {}),
|
|
98
|
+
additionalProperties: false,
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
const array = (item) => {
|
|
102
|
+
const part = requiredPart("array", item);
|
|
103
|
+
return build({ kind: "array", item: part.node }, z.array(part.zod), {
|
|
104
|
+
type: "array",
|
|
105
|
+
items: part.schema,
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
const tuple = (items) => {
|
|
109
|
+
if (!Array.isArray(items) || items.length === 0) {
|
|
110
|
+
throw new TypeError("AvZ.tuple: the items must be a non-empty list of shapes.");
|
|
111
|
+
}
|
|
112
|
+
const parts = items.map((item) => requiredPart("tuple", item));
|
|
113
|
+
return build({ kind: "tuple", items: parts.map((part) => part.node) }, z.tuple(parts.map((part) => part.zod)), {
|
|
114
|
+
type: "array",
|
|
115
|
+
prefixItems: parts.map((part) => part.schema),
|
|
116
|
+
items: false,
|
|
117
|
+
minItems: parts.length,
|
|
118
|
+
maxItems: parts.length,
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
const record = (key, value) => {
|
|
122
|
+
const keyPart = requiredPart("record", key);
|
|
123
|
+
const valuePart = requiredPart("record", value);
|
|
124
|
+
const keyNode = keyPart.node;
|
|
125
|
+
const keys = keyNode.kind === "enum"
|
|
126
|
+
? keyNode.values
|
|
127
|
+
: keyNode.kind === "literal" && typeof keyNode.value === "string"
|
|
128
|
+
? [keyNode.value]
|
|
129
|
+
: keyNode.kind === "string"
|
|
130
|
+
? undefined
|
|
131
|
+
: null;
|
|
132
|
+
if (keys === null) {
|
|
133
|
+
throw new TypeError("AvZ.record: the key must be AvZ.string(), AvZ.enum([...]) or a string AvZ.literal(...).");
|
|
134
|
+
}
|
|
135
|
+
const schema = keys === undefined
|
|
136
|
+
? { type: "object", additionalProperties: valuePart.schema }
|
|
137
|
+
: {
|
|
138
|
+
type: "object",
|
|
139
|
+
properties: Object.fromEntries(keys.map((entry) => [entry, valuePart.schema])),
|
|
140
|
+
required: [...keys],
|
|
141
|
+
additionalProperties: false,
|
|
142
|
+
};
|
|
143
|
+
return build({ kind: "record", value: valuePart.node }, z.record(keyPart.zod, valuePart.zod), schema);
|
|
144
|
+
};
|
|
145
|
+
const union = (options) => {
|
|
146
|
+
if (!Array.isArray(options) || options.length < 2) {
|
|
147
|
+
throw new TypeError("AvZ.union: the options must be a list of at least two shapes.");
|
|
148
|
+
}
|
|
149
|
+
const parts = options.map((option) => requiredPart("union", option));
|
|
150
|
+
return build({ kind: "union", options: parts.map((part) => part.node) }, z.union(parts.map((part) => part.zod)), {
|
|
151
|
+
anyOf: parts.map((part) => part.schema),
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
const discriminatedUnion = (discriminator, options) => {
|
|
155
|
+
if (typeof discriminator !== "string" ||
|
|
156
|
+
!Array.isArray(options) ||
|
|
157
|
+
options.length === 0) {
|
|
158
|
+
throw new TypeError("AvZ.discriminatedUnion: give the discriminator key and a non-empty list of object shapes.");
|
|
159
|
+
}
|
|
160
|
+
const parts = options.map((option) => requiredPart("discriminatedUnion", option));
|
|
161
|
+
const tags = new Map();
|
|
162
|
+
parts.forEach((part, index) => {
|
|
163
|
+
const tag = part.node.kind === "object" ? part.node.fields[discriminator] : undefined;
|
|
164
|
+
const values = tag?.kind === "literal"
|
|
165
|
+
? [tag.value]
|
|
166
|
+
: tag?.kind === "enum"
|
|
167
|
+
? tag.values
|
|
168
|
+
: undefined;
|
|
169
|
+
if (values === undefined) {
|
|
170
|
+
throw new TypeError(`AvZ.discriminatedUnion: option ${index} must be an AvZ.object whose "${discriminator}" is an AvZ.literal or an AvZ.enum.`);
|
|
171
|
+
}
|
|
172
|
+
for (const value of values) {
|
|
173
|
+
if (tags.has(value)) {
|
|
174
|
+
throw new TypeError(`AvZ.discriminatedUnion: options ${tags.get(value)} and ${index} both match "${discriminator}" ${JSON.stringify(value)}.`);
|
|
175
|
+
}
|
|
176
|
+
tags.set(value, index);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
return build({
|
|
180
|
+
kind: "discriminatedUnion",
|
|
181
|
+
discriminator,
|
|
182
|
+
options: parts.map((part) => part.node),
|
|
183
|
+
}, z.discriminatedUnion(discriminator, parts.map((part) => part.zod)), {
|
|
184
|
+
oneOf: parts.map((part) => part.schema),
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
const optional = (inner) => {
|
|
188
|
+
const part = compiledOf("optional", inner);
|
|
189
|
+
return build({ kind: "optional", inner: part.node }, z.optional(part.zod), part.schema, true);
|
|
190
|
+
};
|
|
191
|
+
const nullable = (inner) => {
|
|
192
|
+
const part = compiledOf("nullable", inner);
|
|
193
|
+
return build({ kind: "nullable", inner: part.node }, z.nullable(part.zod), { anyOf: [part.schema, { type: "null" }] }, part.optionalKey);
|
|
194
|
+
};
|
|
195
|
+
export class AvZ {
|
|
196
|
+
constructor() { }
|
|
197
|
+
static string = string;
|
|
198
|
+
static number = number;
|
|
199
|
+
static int = int;
|
|
200
|
+
static boolean = boolean;
|
|
201
|
+
static null = nullShape;
|
|
202
|
+
static literal = literal;
|
|
203
|
+
static enum = enumShape;
|
|
204
|
+
static object = object;
|
|
205
|
+
static array = array;
|
|
206
|
+
static tuple = tuple;
|
|
207
|
+
static record = record;
|
|
208
|
+
static union = union;
|
|
209
|
+
static discriminatedUnion = discriminatedUnion;
|
|
210
|
+
static optional = optional;
|
|
211
|
+
static nullable = nullable;
|
|
212
|
+
}
|