@aventara/core 1.0.0-rc.0 → 1.0.0-rc.10
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 +2068 -1
- package/ERRORS.md +142 -0
- package/README.md +485 -60
- package/dist/adapters/adapter-discovery-diagnostic.d.ts +4 -4
- package/dist/adapters/adapter-discovery-diagnostic.guidance.d.ts +6 -0
- package/dist/adapters/adapter-discovery-diagnostic.guidance.js +7 -0
- package/dist/adapters/adapter-field.d.ts +33 -11
- package/dist/adapters/adapter-identifier.d.ts +15 -6
- package/dist/adapters/adapter-identifier.js +6 -1
- package/dist/adapters/adapter-model.d.ts +18 -9
- package/dist/adapters/adapter-operation-executor.interface.d.ts +4 -4
- package/dist/adapters/adapter-operation.d.ts +21 -6
- package/dist/adapters/adapter-resource.d.ts +23 -9
- package/dist/adapters/adapter-sql-statement.d.ts +19 -0
- package/dist/adapters/adapter-transaction-executor.interface.d.ts +19 -0
- package/dist/adapters/adapter.interface.d.ts +59 -29
- package/dist/avz/avz-check.factory.d.ts +83 -0
- package/dist/avz/avz-check.factory.js +116 -0
- package/dist/avz/avz-check.registry.d.ts +35 -0
- package/dist/avz/avz-check.registry.js +9 -0
- package/dist/avz/avz.d.ts +203 -0
- package/dist/{json → avz}/avz.js +150 -8
- package/dist/{json → avz}/index.d.ts +2 -1
- package/dist/{json → avz}/json-shape.registry.d.ts +9 -8
- package/dist/{json → avz}/zod-issue.translator.d.ts +8 -2
- package/dist/{json → avz}/zod-issue.translator.js +7 -0
- package/dist/compiler/contract-compiler-diagnostic.d.ts +31 -5
- package/dist/compiler/contract-compiler-diagnostic.guidance.d.ts +6 -0
- package/dist/compiler/contract-compiler-diagnostic.guidance.js +97 -0
- package/dist/compiler/contract.compiler.d.ts +23 -17
- package/dist/compiler/contract.compiler.js +753 -443
- package/dist/compiler/create-requirements.projector.d.ts +49 -0
- package/dist/compiler/create-requirements.projector.js +423 -0
- package/dist/compiler/field-validator.compiler.d.ts +47 -0
- package/dist/compiler/field-validator.compiler.js +238 -0
- package/dist/compiler/managed-elsewhere.projector.d.ts +52 -0
- package/dist/compiler/managed-elsewhere.projector.js +179 -0
- package/dist/compiler/managed-elsewhere.validator.d.ts +9 -0
- package/dist/compiler/managed-elsewhere.validator.js +74 -0
- package/dist/config/any-framework-config.d.ts +19 -12
- package/dist/config/computed-fields.d.ts +62 -0
- package/dist/config/computed-fields.js +73 -0
- package/dist/config/config-diagnostic.d.ts +11 -4
- package/dist/config/config-diagnostic.guidance.d.ts +6 -0
- package/dist/config/config-diagnostic.guidance.js +32 -0
- package/dist/config/config-layer.d.ts +15 -6
- package/dist/config/config.resolver.d.ts +98 -31
- package/dist/config/config.resolver.js +173 -44
- package/dist/config/config.validator.d.ts +7 -7
- package/dist/config/config.validator.js +792 -69
- package/dist/config/define-resource.d.ts +53 -0
- package/dist/config/define-resource.js +14 -0
- package/dist/config/effective-fields.d.ts +19 -23
- package/dist/config/entrypoint.normalizer.d.ts +4 -3
- package/dist/config/exact-framework-config.d.ts +325 -0
- package/dist/config/field-compute.resolver.d.ts +21 -0
- package/dist/config/field-compute.resolver.js +123 -0
- package/dist/config/field-pipeline-config.d.ts +47 -0
- package/dist/config/forced-operation.validator.d.ts +10 -0
- package/dist/config/forced-operation.validator.js +66 -0
- package/dist/config/framework-config.d.ts +148 -39
- package/dist/config/framework-exemptions-config.d.ts +91 -0
- package/dist/config/framework-exemptions-config.js +1 -0
- package/dist/config/framework-field-definition.d.ts +78 -0
- package/dist/config/framework-field-definition.js +28 -0
- package/dist/config/framework-resources-config.d.ts +127 -0
- package/dist/config/framework-resources-config.js +1 -0
- package/dist/config/pipeline-config.d.ts +56 -20
- package/dist/config/pipeline-tree.resolver.d.ts +79 -0
- package/dist/config/pipeline-tree.resolver.js +220 -0
- package/dist/config/stage-type.eraser.d.ts +65 -0
- package/dist/config/stage-type.eraser.js +1 -0
- package/dist/contracts/access-route.rules.d.ts +10 -0
- package/dist/contracts/access-route.rules.js +45 -0
- package/dist/contracts/capability.d.ts +37 -12
- package/dist/contracts/capability.js +20 -0
- package/dist/contracts/client-contract-structure.validator.d.ts +621 -114
- package/dist/contracts/client-contract-structure.validator.js +189 -10
- package/dist/contracts/contract-access.d.ts +29 -0
- package/dist/contracts/contract-access.js +1 -0
- package/dist/contracts/contract-canonicalizer.d.ts +27 -3
- package/dist/contracts/contract-canonicalizer.js +168 -29
- package/dist/contracts/contract-hash.d.ts +11 -7
- package/dist/contracts/contract-hash.js +4 -3
- package/dist/contracts/contract-limits.d.ts +4 -1
- package/dist/contracts/contract-limits.js +1 -0
- package/dist/contracts/contract-lookup.d.ts +5 -5
- package/dist/contracts/contract-protocol.d.ts +4 -4
- package/dist/contracts/contract.d.ts +51 -17
- package/dist/contracts/create-requirements.d.ts +35 -0
- package/dist/contracts/create-requirements.js +1 -0
- package/dist/contracts/enum-definition.d.ts +1 -1
- package/dist/contracts/field-check.d.ts +101 -0
- package/dist/contracts/field-check.js +1 -0
- package/dist/contracts/field.d.ts +109 -42
- package/dist/contracts/identifier.d.ts +4 -4
- package/dist/contracts/json-schema.projector.d.ts +11 -0
- package/dist/contracts/json-schema.projector.js +78 -0
- package/dist/contracts/json-shape.d.ts +12 -1
- package/dist/contracts/lifecycle-trait.d.ts +2 -2
- package/dist/contracts/resource-operations.d.ts +28 -28
- package/dist/contracts/resource.d.ts +15 -9
- package/dist/contracts/scalar-value-type.d.ts +17 -15
- package/dist/contracts/scalar.d.ts +3 -3
- package/dist/contracts/transaction-capability.d.ts +1 -1
- package/dist/contracts/wire-scalar-format.d.ts +4 -4
- package/dist/framework/access-facade.d.ts +116 -0
- package/dist/framework/access-facade.js +120 -0
- package/dist/framework/contract-view.d.ts +315 -145
- package/dist/framework/framework-construction.error.d.ts +21 -11
- package/dist/framework/framework-construction.error.js +20 -4
- package/dist/framework/framework.d.ts +71 -26
- package/dist/framework/framework.factory.d.ts +8 -6
- package/dist/framework/framework.factory.js +150 -38
- package/dist/framework/operation-facade.d.ts +192 -54
- package/dist/framework/operation-facade.js +10 -1
- package/dist/index.d.ts +67 -50
- package/dist/index.js +7 -6
- package/dist/internal.d.ts +20 -10
- package/dist/internal.js +9 -1
- package/dist/operations/database-refusal.d.ts +51 -0
- package/dist/operations/database-refusal.js +45 -0
- package/dist/operations/operation-arguments.d.ts +381 -228
- package/dist/operations/operation-call.d.ts +31 -28
- package/dist/operations/operation-identity.d.ts +10 -10
- package/dist/operations/operation-result.d.ts +25 -23
- package/dist/operations/operation-validator-core.d.ts +6 -6
- package/dist/operations/operation-validator-core.js +172 -38
- package/dist/operations/operation-validator.d.ts +10 -10
- package/dist/operations/projection-scope.resolver.d.ts +6 -6
- package/dist/operations/structural-limits.walker.d.ts +7 -7
- package/dist/operations/structural-limits.walker.js +145 -0
- package/dist/operations/validation-code.d.ts +11 -6
- package/dist/operations/validation-code.guidance.d.ts +6 -0
- package/dist/operations/validation-code.guidance.js +90 -0
- package/dist/operations/validation-code.js +4 -0
- package/dist/operations/write-scope.resolver.d.ts +10 -6
- package/dist/operations/write-scope.resolver.js +2 -0
- package/dist/policy/access-provider.interface.d.ts +91 -0
- package/dist/policy/access-provider.interface.js +1 -0
- package/dist/policy/access-provider.registry.d.ts +17 -0
- package/dist/policy/access-provider.registry.js +15 -0
- package/dist/policy/access-question.d.ts +20 -0
- package/dist/policy/access-question.js +1 -0
- package/dist/policy/access-question.registry.d.ts +5 -0
- package/dist/policy/access-question.registry.js +19 -0
- package/dist/policy/access-question.runtime.d.ts +36 -0
- package/dist/policy/access-question.runtime.js +297 -0
- package/dist/policy/access-verb.table.d.ts +56 -0
- package/dist/policy/access-verb.table.js +21 -0
- package/dist/policy/access-verbs.d.ts +46 -0
- package/dist/policy/access-verbs.js +1 -0
- package/dist/policy/policy-admission.d.ts +20 -0
- package/dist/policy/policy-admission.js +409 -0
- package/dist/policy/policy-after-update.runtime.d.ts +79 -0
- package/dist/policy/policy-after-update.runtime.js +208 -0
- package/dist/policy/policy-condition.d.ts +15 -0
- package/dist/policy/policy-condition.js +36 -0
- package/dist/policy/policy-engine.d.ts +205 -0
- package/dist/policy/policy-engine.js +1 -0
- package/dist/policy/policy-named-rows.d.ts +18 -0
- package/dist/policy/policy-named-rows.js +51 -0
- package/dist/policy/policy-nested-write.runtime.d.ts +44 -0
- package/dist/policy/policy-nested-write.runtime.js +545 -0
- package/dist/policy/policy-read.runtime.d.ts +81 -0
- package/dist/policy/policy-read.runtime.js +503 -0
- package/dist/policy/policy-reference-write.runtime.d.ts +51 -0
- package/dist/policy/policy-reference-write.runtime.js +345 -0
- package/dist/policy/policy-request.d.ts +41 -0
- package/dist/policy/policy-request.js +63 -0
- package/dist/policy/policy-session.d.ts +106 -0
- package/dist/policy/policy-session.js +295 -0
- package/dist/policy/policy-startup.validator.d.ts +10 -0
- package/dist/policy/policy-startup.validator.js +112 -0
- package/dist/policy/policy-write.runtime.d.ts +39 -0
- package/dist/policy/policy-write.runtime.js +532 -0
- package/dist/prebuilt/core-version.generated.d.ts +2 -0
- package/dist/prebuilt/core-version.generated.js +1 -0
- package/dist/prebuilt/prebuilt-changes.d.ts +29 -0
- package/dist/prebuilt/prebuilt-changes.js +65 -0
- package/dist/prebuilt/prebuilt-contracts.d.ts +40 -0
- package/dist/prebuilt/prebuilt-contracts.emitter.d.ts +16 -0
- package/dist/prebuilt/prebuilt-contracts.emitter.js +50 -0
- package/dist/prebuilt/prebuilt-contracts.js +1 -0
- package/dist/prebuilt/prebuilt-contracts.loader.d.ts +19 -0
- package/dist/prebuilt/prebuilt-contracts.loader.js +77 -0
- package/dist/prebuilt/prebuilt-inputs.fingerprint.d.ts +16 -0
- package/dist/prebuilt/prebuilt-inputs.fingerprint.js +229 -0
- package/dist/protocol/absent-route.responder.d.ts +17 -34
- package/dist/protocol/absent-route.responder.js +53 -20
- package/dist/protocol/contract-document.responder.d.ts +5 -4
- package/dist/protocol/contract-document.responder.js +2 -2
- package/dist/protocol/http-request.decoder.d.ts +33 -13
- package/dist/protocol/http-request.decoder.js +34 -11
- package/dist/protocol/http-request.reader.d.ts +9 -6
- package/dist/protocol/http-request.reader.js +1 -0
- package/dist/protocol/http-response.encoder.d.ts +4 -4
- package/dist/protocol/http-response.encoder.js +94 -55
- package/dist/protocol/http-status.table.d.ts +2 -2
- package/dist/protocol/operation-response.guard.d.ts +2 -2
- package/dist/protocol/protocol-headers.d.ts +3 -3
- package/dist/protocol/protocol-surface.d.ts +10 -5
- package/dist/protocol/protocol-surface.js +7 -0
- package/dist/protocol/protocol.binder.d.ts +66 -28
- package/dist/protocol/protocol.binder.js +16 -10
- package/dist/protocol/protocol.handler.d.ts +34 -14
- package/dist/protocol/protocol.handler.js +122 -18
- package/dist/protocol/unmounted-route.error.d.ts +4 -4
- package/dist/protocol/unmounted-route.error.js +2 -2
- package/dist/runtime/caller-data.copier.d.ts +22 -7
- package/dist/runtime/caller-data.copier.js +30 -17
- package/dist/runtime/caller-data.door.d.ts +18 -11
- package/dist/runtime/caller-data.door.js +6 -4
- package/dist/runtime/computed-read-runtime.d.ts +12 -6
- package/dist/runtime/computed-read-runtime.js +271 -71
- package/dist/runtime/computed-value.error.d.ts +7 -6
- package/dist/runtime/computed-value.error.js +5 -4
- package/dist/runtime/context-executor.runtime.d.ts +60 -0
- package/dist/runtime/context-executor.runtime.js +277 -0
- package/dist/runtime/core-class.brand.d.ts +10 -0
- package/dist/runtime/core-class.brand.js +21 -0
- package/dist/runtime/create-requirement.d.ts +34 -79
- package/dist/runtime/create-requirement.js +205 -74
- package/dist/runtime/decimal.d.ts +16 -2
- package/dist/runtime/decimal.js +22 -1
- package/dist/runtime/diagnostics-reporter.d.ts +91 -30
- package/dist/runtime/diagnostics-reporter.js +37 -1
- package/dist/runtime/error-boundary.d.ts +73 -9
- package/dist/runtime/error-boundary.js +57 -19
- package/dist/runtime/error-guidance.d.ts +12 -0
- package/dist/runtime/error-guidance.js +1 -0
- package/dist/runtime/error.catalog.d.ts +49 -0
- package/dist/runtime/error.catalog.js +49 -0
- package/dist/runtime/execution-options.d.ts +18 -2
- package/dist/runtime/field-check.evaluator.d.ts +27 -0
- package/dist/runtime/field-check.evaluator.js +521 -0
- package/dist/runtime/field-compute.d.ts +65 -0
- package/dist/runtime/field-compute.js +1 -0
- package/dist/runtime/field-stage.plan.d.ts +15 -0
- package/dist/runtime/field-stage.plan.js +27 -0
- package/dist/runtime/field-stage.runtime.d.ts +37 -0
- package/dist/runtime/field-stage.runtime.js +147 -0
- package/dist/runtime/field-validator.runtime.d.ts +29 -0
- package/dist/runtime/field-validator.runtime.js +126 -0
- package/dist/runtime/framework-error-class.table.d.ts +33 -0
- package/dist/runtime/framework-error-class.table.js +25 -0
- package/dist/runtime/framework-error.d.ts +68 -8
- package/dist/runtime/framework-error.factory.d.ts +4 -0
- package/dist/runtime/framework-error.factory.js +15 -0
- package/dist/runtime/framework-error.js +32 -2
- package/dist/runtime/framework-warning.emitter.d.ts +6 -0
- package/dist/runtime/framework-warning.emitter.js +8 -0
- package/dist/runtime/interceptor-next.error.d.ts +5 -0
- package/dist/runtime/interceptor-next.error.js +6 -0
- package/dist/runtime/json-value.d.ts +11 -6
- package/dist/runtime/level-lifecycle.runtime.d.ts +26 -0
- package/dist/runtime/level-lifecycle.runtime.js +40 -0
- package/dist/runtime/misuse-reporter.d.ts +12 -12
- package/dist/runtime/mutation-planner.d.ts +20 -16
- package/dist/runtime/mutation-planner.js +48 -35
- package/dist/runtime/nested-write.walker.d.ts +32 -0
- package/dist/runtime/nested-write.walker.js +73 -0
- package/dist/runtime/operation-code.guidance.d.ts +6 -0
- package/dist/runtime/operation-code.guidance.js +167 -0
- package/dist/runtime/operation-request.d.ts +45 -11
- package/dist/runtime/operation-response.d.ts +17 -17
- package/dist/runtime/operation-runtime.d.ts +133 -27
- package/dist/runtime/operation-runtime.js +576 -84
- package/dist/runtime/outcome-mapper.d.ts +17 -5
- package/dist/runtime/outcome-mapper.js +23 -6
- package/dist/runtime/output-validator.d.ts +11 -11
- package/dist/runtime/output-validator.js +3 -3
- package/dist/runtime/owned-execution.registry.d.ts +16 -6
- package/dist/runtime/pipe-output.validator.d.ts +43 -18
- package/dist/runtime/pipe-output.validator.js +15 -13
- package/dist/runtime/pipeline.d.ts +221 -34
- package/dist/runtime/readonly-value.d.ts +47 -0
- package/dist/runtime/readonly-value.js +189 -0
- package/dist/runtime/referential-action.d.ts +1 -1
- package/dist/runtime/request-envelope.validator.d.ts +3 -3
- package/dist/runtime/request-envelope.validator.js +12 -7
- package/dist/runtime/request-id.d.ts +1 -1
- package/dist/runtime/request-state.d.ts +14 -0
- package/dist/runtime/request-state.js +1 -0
- package/dist/runtime/request-state.resolver.d.ts +12 -0
- package/dist/runtime/request-state.resolver.js +20 -0
- package/dist/runtime/scalar-runtime.d.ts +33 -25
- package/dist/runtime/scalar-runtime.js +105 -38
- package/dist/runtime/unsent-value.normalizer.d.ts +15 -0
- package/dist/runtime/unsent-value.normalizer.js +128 -0
- package/dist/transactions/deferred-operation.d.ts +35 -20
- package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
- package/dist/transactions/operation-arguments-encoder.js +8 -3
- package/dist/transactions/operation-fingerprint.js +2 -2
- package/dist/transactions/sql-statement.d.ts +85 -0
- package/dist/transactions/sql-statement.js +47 -0
- package/dist/transactions/sql-statement.validator.d.ts +44 -0
- package/dist/transactions/sql-statement.validator.js +167 -0
- package/dist/transactions/transaction-envelope.d.ts +9 -8
- package/dist/transactions/transaction-integrity-error.d.ts +6 -6
- package/dist/transactions/transaction-integrity-error.js +7 -2
- package/dist/transactions/transaction-plan-assembler.d.ts +30 -13
- package/dist/transactions/transaction-plan-assembler.js +184 -32
- package/dist/transactions/transaction-plan-validator.d.ts +50 -25
- package/dist/transactions/transaction-plan-validator.js +96 -38
- package/dist/transactions/transaction-reference-collector.d.ts +5 -5
- package/dist/transactions/transaction-reference-resolver.d.ts +21 -3
- package/dist/transactions/transaction-reference-resolver.js +26 -14
- package/dist/transactions/transaction-reference-validator.d.ts +74 -4
- package/dist/transactions/transaction-reference-validator.js +129 -71
- package/dist/transactions/transaction-reference.d.ts +14 -14
- package/dist/transactions/transaction-reference.js +5 -0
- package/dist/transactions/transaction-request.d.ts +22 -9
- package/dist/transactions/transaction-response.d.ts +6 -6
- package/dist/transactions/transaction-runtime.d.ts +12 -8
- package/dist/transactions/transaction-runtime.js +218 -50
- package/dist/transactions/transaction-settlement.runtime.d.ts +52 -0
- package/dist/transactions/transaction-settlement.runtime.js +120 -0
- package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
- package/dist/transactions/transaction-slot-path-error.js +4 -2
- package/dist/transactions/transaction-slot-writer.js +2 -2
- package/dist/transactions/transaction-stage.runtime.d.ts +83 -0
- package/dist/transactions/transaction-stage.runtime.js +126 -0
- package/package.json +11 -9
- package/src/runtime/field-check.evaluator.ts +720 -0
- package/dist/config/define-fields.d.ts +0 -42
- package/dist/config/define-fields.js +0 -3
- package/dist/config/framework-behaviors-config.d.ts +0 -30
- package/dist/config/framework-fields-config.d.ts +0 -42
- package/dist/config/framework-restrictions-config.d.ts +0 -142
- package/dist/json/avz.d.ts +0 -96
- package/dist/runtime/field-behavior.d.ts +0 -48
- /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
- /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
- /package/dist/{json → avz}/index.js +0 -0
- /package/dist/{json → avz}/json-shape.registry.js +0 -0
- /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
- /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** The request limits a Contract enforces. */
|
|
2
|
-
export type
|
|
2
|
+
export type AvContractLimits = {
|
|
3
3
|
/** The largest request body accepted, in bytes. */
|
|
4
4
|
readonly maxRequestBytes: number;
|
|
5
5
|
/** How deeply arguments may nest. */
|
|
@@ -10,6 +10,8 @@ export type ContractLimits = {
|
|
|
10
10
|
readonly maxTransactionOperations: number;
|
|
11
11
|
/** The most boolean and filter nodes one request may hold. */
|
|
12
12
|
readonly maxBooleanNodes: number;
|
|
13
|
+
/** How deeply a `json` field's value may nest: its arrays and objects, counted from the value. */
|
|
14
|
+
readonly maxJsonDepth: number;
|
|
13
15
|
};
|
|
14
16
|
/** The limits in force when the configuration sets none. */
|
|
15
17
|
export declare const DEFAULT_CONTRACT_LIMITS: {
|
|
@@ -18,4 +20,5 @@ export declare const DEFAULT_CONTRACT_LIMITS: {
|
|
|
18
20
|
readonly maxListLimit: 250;
|
|
19
21
|
readonly maxTransactionOperations: 20;
|
|
20
22
|
readonly maxBooleanNodes: 50;
|
|
23
|
+
readonly maxJsonDepth: 64;
|
|
21
24
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { AvContract } from "./contract.js";
|
|
2
|
+
import type { AvField } from "./field.js";
|
|
3
|
+
import type { AvResource } from "./resource.js";
|
|
4
4
|
/**
|
|
5
5
|
* Own-property lookups over Contract registries.
|
|
6
6
|
*
|
|
@@ -12,5 +12,5 @@ import type { Resource } from "./resource.js";
|
|
|
12
12
|
* must go through here so an unknown key is unknown, whatever its name.
|
|
13
13
|
*/
|
|
14
14
|
export declare function lookupOwn<T>(registry: Readonly<Record<string, T>> | undefined, key: string): T | undefined;
|
|
15
|
-
export declare function lookupResource<C extends
|
|
16
|
-
export declare function lookupField<C extends
|
|
15
|
+
export declare function lookupResource<C extends AvContract>(contract: C, resourceName: string): AvResource<C> | undefined;
|
|
16
|
+
export declare function lookupField<C extends AvContract>(resource: AvResource<C> | undefined, fieldName: string): AvField<C> | undefined;
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export declare const AVENTARA_PROTOCOL_VERSION: 1;
|
|
7
7
|
/** A Contract hash: `sha256:` followed by the hex digest. */
|
|
8
|
-
export type
|
|
8
|
+
export type AvContractHash = `sha256:${string}`;
|
|
9
9
|
/** The protocol a Contract is written for. */
|
|
10
|
-
export type
|
|
10
|
+
export type AvContractProtocol = {
|
|
11
11
|
/** The protocol version; see {@link AVENTARA_PROTOCOL_VERSION}. */
|
|
12
12
|
readonly version: typeof AVENTARA_PROTOCOL_VERSION;
|
|
13
13
|
};
|
|
14
14
|
/** A ClientContract's `protocol`: the protocol version and the Contract hash. */
|
|
15
|
-
export type
|
|
16
|
-
readonly hash:
|
|
15
|
+
export type AvContractClientProtocol = AvContractProtocol & {
|
|
16
|
+
readonly hash: AvContractHash;
|
|
17
17
|
};
|
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { AvContractClientAccess } from "./contract-access.js";
|
|
2
|
+
import type { AvContractLimits } from "./contract-limits.js";
|
|
3
|
+
import type { AvContractClientProtocol } from "./contract-protocol.js";
|
|
4
|
+
import type { AvEnumDefinition } from "./enum-definition.js";
|
|
5
|
+
import type { AvCoreField } from "./field.js";
|
|
4
6
|
import type { ReferenceWriteLimit } from "./reference-write-limit.js";
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
7
|
+
import type { AvResource } from "./resource.js";
|
|
8
|
+
import type { AvScalarRegistry } from "./scalar.js";
|
|
9
|
+
import type { AvTransactionCapability } from "./transaction-capability.js";
|
|
8
10
|
/** What every Contract describes: scalars, enums, Resources, limits and transactions. */
|
|
9
|
-
export interface
|
|
11
|
+
export interface AvContract {
|
|
10
12
|
/** The scalar types available. */
|
|
11
|
-
readonly scalars:
|
|
13
|
+
readonly scalars: AvScalarRegistry;
|
|
12
14
|
/** The enums, by name. */
|
|
13
|
-
readonly enums: Readonly<Record<string,
|
|
15
|
+
readonly enums: Readonly<Record<string, AvEnumDefinition>>;
|
|
14
16
|
/** The Resources, by name. */
|
|
15
|
-
readonly resources: Readonly<Record<string,
|
|
17
|
+
readonly resources: Readonly<Record<string, AvResource<this>>>;
|
|
16
18
|
/** The request limits in force. */
|
|
17
|
-
readonly limits:
|
|
19
|
+
readonly limits: AvContractLimits;
|
|
18
20
|
/** Whether interactive transactions are available. */
|
|
19
|
-
readonly transactions:
|
|
21
|
+
readonly transactions: AvTransactionCapability;
|
|
20
22
|
/**
|
|
21
23
|
* `"uniform"` when one record must write the relations that hold a reference
|
|
22
24
|
* either all as relations or all through their reference fields; a record
|
|
@@ -24,17 +26,49 @@ export interface Contract {
|
|
|
24
26
|
*/
|
|
25
27
|
readonly referenceWrites?: ReferenceWriteLimit;
|
|
26
28
|
}
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
+
/**
|
|
30
|
+
* The Contract compiled from the root configuration. Its relation fields also
|
|
31
|
+
* state the target's fields their reference names (`references`), and its
|
|
32
|
+
* Resources the database schema the store keeps them in (`schema`) and whether
|
|
33
|
+
* another service owns them (`managedElsewhere`), which no other Contract
|
|
34
|
+
* carries.
|
|
35
|
+
*/
|
|
36
|
+
export interface AvContractCore extends AvContract {
|
|
37
|
+
/** The Resources, by name. */
|
|
38
|
+
readonly resources: Readonly<Record<string, AvCoreResource>>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A Resource as the Core Contract states it: its fields are
|
|
42
|
+
* {@link AvCoreField}s, so its relation fields carry `references`.
|
|
43
|
+
*/
|
|
44
|
+
export interface AvCoreResource extends AvResource<AvContractCore> {
|
|
45
|
+
readonly fields: Readonly<Record<string, AvCoreField<AvContractCore>>>;
|
|
46
|
+
/** The database schema the store keeps this Resource in, when the adapter states one. */
|
|
47
|
+
readonly schema?: string;
|
|
48
|
+
/** Present when another service owns this Resource: it is read, never written. */
|
|
49
|
+
readonly managedElsewhere?: true;
|
|
29
50
|
}
|
|
30
51
|
/** The Contract in-process calls run under (`framework.application`). */
|
|
31
|
-
export interface
|
|
52
|
+
export interface AvContractApplication extends AvContract {
|
|
32
53
|
}
|
|
33
54
|
/**
|
|
34
55
|
* The Contract remote clients run under, published at `GET /_contract` and
|
|
35
56
|
* identified by its hash.
|
|
36
57
|
*/
|
|
37
|
-
export interface
|
|
58
|
+
export interface AvContractClient extends AvContract {
|
|
59
|
+
/** The protocol version and this Contract's hash. */
|
|
60
|
+
readonly protocol: AvContractClientProtocol;
|
|
61
|
+
/**
|
|
62
|
+
* Present exactly when the framework's `access` option is configured: the
|
|
63
|
+
* `POST /_access/can` route, and `$access`'s other verbs when it has `verbs`.
|
|
64
|
+
*/
|
|
65
|
+
readonly access?: AvContractClientAccess;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The Contract an AI agent's calls run under (the `agent` layer), identified by
|
|
69
|
+
* its hash. MCP tools are built from it.
|
|
70
|
+
*/
|
|
71
|
+
export interface AvContractAgent extends AvContract {
|
|
38
72
|
/** The protocol version and this Contract's hash. */
|
|
39
|
-
readonly protocol:
|
|
73
|
+
readonly protocol: AvContractClientProtocol;
|
|
40
74
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A required to-one relation and the scalar fields that hold its reference,
|
|
3
|
+
* relation first: `["author", "authorId"]`. A create writes the relation, or
|
|
4
|
+
* every one of the fields together (`["author", "tenantId", "authorId"]` for a
|
|
5
|
+
* composite reference), never both.
|
|
6
|
+
*/
|
|
7
|
+
export type AvCreateRequirementGroup = readonly [string, string, ...string[]];
|
|
8
|
+
/**
|
|
9
|
+
* What a create of one Resource cannot do without, as the Contract's layer
|
|
10
|
+
* exposes it. Only fields the layer lets a caller write at create appear: a
|
|
11
|
+
* group whose reference fields the layer hides is its relation alone, in
|
|
12
|
+
* `required`; one whose relation it hides is its reference fields, in
|
|
13
|
+
* `required`; a field a compute stage fills at create (`COMPUTED_ON_CREATE`) is
|
|
14
|
+
* not required.
|
|
15
|
+
*/
|
|
16
|
+
export type AvCreateRequirements = {
|
|
17
|
+
/**
|
|
18
|
+
* The fields every create must write: scalars with no default, generated or
|
|
19
|
+
* computed value, and relations whose reference fields the layer hides.
|
|
20
|
+
*/
|
|
21
|
+
readonly required?: readonly [string, ...string[]];
|
|
22
|
+
/** The required relations a create writes either way: see {@link AvCreateRequirementGroup}. */
|
|
23
|
+
readonly oneOf?: readonly [
|
|
24
|
+
AvCreateRequirementGroup,
|
|
25
|
+
...AvCreateRequirementGroup[]
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* By parent Resource, then by its relation: the fields above that a create
|
|
29
|
+
* nested through that relation gets from its parent, so it is not required
|
|
30
|
+
* there. `{ "User": { "posts": ["author", "authorId"] } }`: a post created in
|
|
31
|
+
* `User.posts` needs neither `author` nor `authorId`; a group any of whose
|
|
32
|
+
* fields is listed is satisfied whole.
|
|
33
|
+
*/
|
|
34
|
+
readonly parentSupplies?: Readonly<Record<string, Readonly<Record<string, readonly [string, ...string[]]>>>>;
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/** The named string formats: what `AvZ.email()`, `AvZ.uuid()` and the rest check. */
|
|
2
|
+
export type AvFieldCheckFormat = "email" | "url" | "emoji" | "uuid" | "guid" | "nanoid" | "cuid" | "cuid2" | "ulid" | "xid" | "ksuid" | "datetime" | "date" | "time" | "duration" | "ipv4" | "ipv6" | "cidrv4" | "cidrv6" | "base64" | "base64url" | "json_string" | "e164" | "credit_card" | "iban" | "jwt";
|
|
3
|
+
/**
|
|
4
|
+
* A bound on a value (`AvZ.lt`, `AvZ.gte`, `AvZ.positive`, …). `value` is a number
|
|
5
|
+
* for an `int` or `float` field and a Json number; for a `bigint`, `decimal` or
|
|
6
|
+
* `datetime` field it is the bound's wire string.
|
|
7
|
+
*/
|
|
8
|
+
export type AvFieldRangeCheck = {
|
|
9
|
+
readonly check: "less_than" | "greater_than";
|
|
10
|
+
readonly value: number | string;
|
|
11
|
+
readonly inclusive: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** `AvZ.multipleOf`: `value` is written as {@link AvFieldRangeCheck}'s is. */
|
|
14
|
+
export type AvFieldMultipleCheck = {
|
|
15
|
+
readonly check: "multiple_of";
|
|
16
|
+
readonly value: number | string;
|
|
17
|
+
};
|
|
18
|
+
/** A length bound: a string's, or with `list: true` a list's. */
|
|
19
|
+
export type AvFieldLengthCheck = {
|
|
20
|
+
readonly check: "max_length";
|
|
21
|
+
readonly maximum: number;
|
|
22
|
+
readonly list?: true;
|
|
23
|
+
} | {
|
|
24
|
+
readonly check: "min_length";
|
|
25
|
+
readonly minimum: number;
|
|
26
|
+
readonly list?: true;
|
|
27
|
+
} | {
|
|
28
|
+
readonly check: "length_equals";
|
|
29
|
+
readonly length: number;
|
|
30
|
+
};
|
|
31
|
+
/** A pattern or a named format a string must match. */
|
|
32
|
+
export type AvFieldFormatCheck = {
|
|
33
|
+
readonly check: "string_format";
|
|
34
|
+
readonly format: "regex";
|
|
35
|
+
/** A JavaScript regular expression: its `source` and its `flags`. */
|
|
36
|
+
readonly pattern: {
|
|
37
|
+
readonly source: string;
|
|
38
|
+
readonly flags: string;
|
|
39
|
+
};
|
|
40
|
+
} | {
|
|
41
|
+
readonly check: "string_format";
|
|
42
|
+
readonly format: "includes";
|
|
43
|
+
readonly includes: string;
|
|
44
|
+
} | {
|
|
45
|
+
readonly check: "string_format";
|
|
46
|
+
readonly format: "starts_with";
|
|
47
|
+
readonly prefix: string;
|
|
48
|
+
} | {
|
|
49
|
+
readonly check: "string_format";
|
|
50
|
+
readonly format: "ends_with";
|
|
51
|
+
readonly suffix: string;
|
|
52
|
+
} | {
|
|
53
|
+
readonly check: "string_format";
|
|
54
|
+
readonly format: "lowercase" | "uppercase" | AvFieldCheckFormat;
|
|
55
|
+
};
|
|
56
|
+
/** A `bytes` value's byte length. */
|
|
57
|
+
export type AvFieldSizeCheck = {
|
|
58
|
+
readonly check: "max_size";
|
|
59
|
+
readonly maximum: number;
|
|
60
|
+
} | {
|
|
61
|
+
readonly check: "min_size";
|
|
62
|
+
readonly minimum: number;
|
|
63
|
+
} | {
|
|
64
|
+
readonly check: "size_equals";
|
|
65
|
+
readonly size: number;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* One field validator as the Contract stores it: its check's name (`check`) and
|
|
69
|
+
* the check's parameters.
|
|
70
|
+
*/
|
|
71
|
+
export type AvFieldCheck = AvFieldRangeCheck | AvFieldMultipleCheck | AvFieldLengthCheck | AvFieldFormatCheck | AvFieldSizeCheck;
|
|
72
|
+
/** The checks a Json Shape's string node may carry: its length, a pattern or a format. */
|
|
73
|
+
export type AvJsonStringCheck = {
|
|
74
|
+
readonly check: "max_length";
|
|
75
|
+
readonly maximum: number;
|
|
76
|
+
} | {
|
|
77
|
+
readonly check: "min_length";
|
|
78
|
+
readonly minimum: number;
|
|
79
|
+
} | {
|
|
80
|
+
readonly check: "length_equals";
|
|
81
|
+
readonly length: number;
|
|
82
|
+
} | AvFieldFormatCheck;
|
|
83
|
+
/** The checks a Json Shape's number or integer node may carry: bounds are numbers. */
|
|
84
|
+
export type AvJsonNumberCheck = {
|
|
85
|
+
readonly check: "less_than" | "greater_than";
|
|
86
|
+
readonly value: number;
|
|
87
|
+
readonly inclusive: boolean;
|
|
88
|
+
} | {
|
|
89
|
+
readonly check: "multiple_of";
|
|
90
|
+
readonly value: number;
|
|
91
|
+
};
|
|
92
|
+
/** The checks a Json Shape's array node may carry: its length. */
|
|
93
|
+
export type AvJsonListCheck = {
|
|
94
|
+
readonly check: "max_length";
|
|
95
|
+
readonly maximum: number;
|
|
96
|
+
readonly list: true;
|
|
97
|
+
} | {
|
|
98
|
+
readonly check: "min_length";
|
|
99
|
+
readonly minimum: number;
|
|
100
|
+
readonly list: true;
|
|
101
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,72 +1,89 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { AvPaginationCapability, AvProjectionScope, AvRelationFilterCapability, AvRelationMutationDirective, AvRelationReducer, AvScalarFilterOperator, AvScalarMutationDirective, AvWriteScope, ScalarFilterMode } from "./capability.js";
|
|
2
|
+
import type { AvContract } from "./contract.js";
|
|
3
|
+
import type { AvFieldCheck } from "./field-check.js";
|
|
3
4
|
import type { JsonSchema } from "./json-shape.js";
|
|
4
|
-
import type {
|
|
5
|
+
import type { AvLifecycleTrait } from "./lifecycle-trait.js";
|
|
5
6
|
/** A format name that refines a scalar type, carried in the Contract as data. */
|
|
6
|
-
export type
|
|
7
|
+
export type AvScalarFormat = string;
|
|
7
8
|
/** The projection positions a field can be selected in (at least one). */
|
|
8
|
-
export type
|
|
9
|
+
export type AvProjectionScopes = readonly [
|
|
10
|
+
AvProjectionScope,
|
|
11
|
+
...AvProjectionScope[]
|
|
12
|
+
];
|
|
9
13
|
/**
|
|
10
14
|
* The write positions a field can be written in (at least one). A scope list
|
|
11
|
-
* applies to the top level of a write argument only; see {@link
|
|
15
|
+
* applies to the top level of a write argument only; see {@link AvWriteScope}.
|
|
12
16
|
*/
|
|
13
|
-
export type
|
|
17
|
+
export type AvWriteScopes = readonly [AvWriteScope, ...AvWriteScope[]];
|
|
14
18
|
/**
|
|
15
19
|
* Whether a relation can be selected or included: `true`, or the projection
|
|
16
20
|
* positions it can be used in.
|
|
17
21
|
*/
|
|
18
|
-
export type
|
|
22
|
+
export type AvRelationProjectionCapability = boolean | AvProjectionScopes;
|
|
19
23
|
/**
|
|
20
24
|
* The reducers a relation admits, qualified by the projection positions they are
|
|
21
25
|
* admitted in. The reducer list and the scope list are separate facts: `$count` is
|
|
22
26
|
* one of a closed set of reducers, and the scopes say where the reducer may be
|
|
23
27
|
* asked for.
|
|
24
28
|
*/
|
|
25
|
-
export type
|
|
26
|
-
readonly reducers: readonly
|
|
27
|
-
readonly scopes:
|
|
29
|
+
export type AvScopedRelationReducers = {
|
|
30
|
+
readonly reducers: readonly AvRelationReducer[];
|
|
31
|
+
readonly scopes: AvProjectionScopes;
|
|
28
32
|
};
|
|
29
33
|
/**
|
|
30
34
|
* A relation's reducers: a reducer list, or an object with the reducers and
|
|
31
35
|
* the projection positions they apply in.
|
|
32
36
|
*/
|
|
33
|
-
export type
|
|
37
|
+
export type AvRelationReducerCapability = readonly AvRelationReducer[] | AvScopedRelationReducers;
|
|
34
38
|
/**
|
|
35
39
|
* The mutation directives a relation admits at one write stage, and the write
|
|
36
40
|
* positions they are admitted in. `directives: []` means writable with no
|
|
37
41
|
* directive.
|
|
38
42
|
*/
|
|
39
|
-
export type
|
|
40
|
-
readonly directives: readonly
|
|
41
|
-
readonly scopes:
|
|
43
|
+
export type AvScopedRelationMutations = {
|
|
44
|
+
readonly directives: readonly AvRelationMutationDirective[];
|
|
45
|
+
readonly scopes: AvWriteScopes;
|
|
42
46
|
};
|
|
43
47
|
/**
|
|
44
48
|
* A relation's write capability for `create` or `update`: a directive list, or
|
|
45
49
|
* an object with the directives and the write positions they apply in.
|
|
46
50
|
*/
|
|
47
|
-
export type
|
|
51
|
+
export type AvRelationMutationCapability = readonly AvRelationMutationDirective[] | AvScopedRelationMutations;
|
|
48
52
|
/** What can be done with a scalar field. Scalar capabilities apply in every position. */
|
|
49
|
-
export type
|
|
53
|
+
export type AvScalarFieldCapabilities = {
|
|
50
54
|
readonly select?: boolean;
|
|
51
|
-
readonly filter?: readonly
|
|
55
|
+
readonly filter?: readonly AvScalarFilterOperator[];
|
|
56
|
+
/**
|
|
57
|
+
* The modes the `mode` operator takes on this field: `"default"` (the
|
|
58
|
+
* database's own comparison) always, and `"sensitive"` or `"insensitive"`
|
|
59
|
+
* where the adapter honours them. Present exactly when `filter` offers `mode`.
|
|
60
|
+
*/
|
|
61
|
+
readonly filterModes?: readonly ScalarFilterMode[];
|
|
62
|
+
/**
|
|
63
|
+
* A `json` field's modes when the filter names a `path`: the text compared is
|
|
64
|
+
* the value at that path rather than the whole document, and the database may
|
|
65
|
+
* honour more modes there. Present exactly when `filter` offers `mode` and
|
|
66
|
+
* `path`; without a `path`, `filterModes` applies.
|
|
67
|
+
*/
|
|
68
|
+
readonly pathFilterModes?: readonly ScalarFilterMode[];
|
|
52
69
|
readonly order?: boolean;
|
|
53
70
|
readonly orderNulls?: boolean;
|
|
54
|
-
readonly create?: readonly
|
|
55
|
-
readonly update?: readonly
|
|
71
|
+
readonly create?: readonly AvScalarMutationDirective[];
|
|
72
|
+
readonly update?: readonly AvScalarMutationDirective[];
|
|
56
73
|
};
|
|
57
74
|
/** What can be done with a relation field. */
|
|
58
|
-
export type
|
|
59
|
-
readonly select?:
|
|
60
|
-
readonly include?:
|
|
61
|
-
readonly filter?: readonly
|
|
75
|
+
export type AvRelationFieldCapabilities = {
|
|
76
|
+
readonly select?: AvRelationProjectionCapability;
|
|
77
|
+
readonly include?: AvRelationProjectionCapability;
|
|
78
|
+
readonly filter?: readonly AvRelationFilterCapability[];
|
|
62
79
|
readonly order?: boolean;
|
|
63
|
-
readonly pagination?: readonly
|
|
64
|
-
readonly reducers?:
|
|
65
|
-
readonly create?:
|
|
66
|
-
readonly update?:
|
|
80
|
+
readonly pagination?: readonly AvPaginationCapability[];
|
|
81
|
+
readonly reducers?: AvRelationReducerCapability;
|
|
82
|
+
readonly create?: AvRelationMutationCapability;
|
|
83
|
+
readonly update?: AvRelationMutationCapability;
|
|
67
84
|
/**
|
|
68
85
|
* What the `where` of a nested `$update` or `$delete` through this relation may
|
|
69
|
-
* filter: `"scalar"`
|
|
86
|
+
* filter: `"scalar"` means the target's scalar fields only, combined with
|
|
70
87
|
* `AND`/`OR`/`NOT`, and no relation filter at any depth. Absent: any filter the
|
|
71
88
|
* target takes.
|
|
72
89
|
*/
|
|
@@ -76,53 +93,103 @@ export type RelationFieldCapabilities = {
|
|
|
76
93
|
* The reducers a relation advertises, in any projection position. Use
|
|
77
94
|
* {@link advertisedReducersAt} for one position.
|
|
78
95
|
*/
|
|
79
|
-
export declare function advertisedReducers(capability:
|
|
96
|
+
export declare function advertisedReducers(capability: AvRelationReducerCapability | undefined): readonly AvRelationReducer[] | undefined;
|
|
80
97
|
/** Whether a projection capability holds at one projection position. */
|
|
81
|
-
export declare function holdsAt(capability:
|
|
98
|
+
export declare function holdsAt(capability: AvRelationProjectionCapability | undefined, scope: AvProjectionScope): boolean;
|
|
82
99
|
/**
|
|
83
100
|
* Whether a projection capability holds in **any** projection position. Use
|
|
84
101
|
* {@link holdsAt} when the position is known.
|
|
85
102
|
*/
|
|
86
|
-
export declare function holdsInAnyScope(capability:
|
|
103
|
+
export declare function holdsInAnyScope(capability: AvRelationProjectionCapability | undefined): boolean;
|
|
87
104
|
/**
|
|
88
105
|
* The reducers a relation advertises at one projection position, or
|
|
89
106
|
* `undefined` where it has none there.
|
|
90
107
|
*/
|
|
91
|
-
export declare function advertisedReducersAt(capability:
|
|
108
|
+
export declare function advertisedReducersAt(capability: AvRelationReducerCapability | undefined, scope: AvProjectionScope): readonly AvRelationReducer[] | undefined;
|
|
92
109
|
/**
|
|
93
110
|
* The mutation directives a relation advertises at one write stage, in any
|
|
94
111
|
* write position. `undefined` means the stage is unavailable; `[]` means
|
|
95
112
|
* available with no directive.
|
|
96
113
|
*/
|
|
97
|
-
export declare function advertisedDirectives(capability:
|
|
114
|
+
export declare function advertisedDirectives(capability: AvRelationMutationCapability | undefined): readonly AvRelationMutationDirective[] | undefined;
|
|
98
115
|
/**
|
|
99
116
|
* The mutation directives a relation advertises at one write position, or
|
|
100
117
|
* `undefined` where it is not writable there.
|
|
101
118
|
*/
|
|
102
|
-
export declare function advertisedDirectivesAt(capability:
|
|
119
|
+
export declare function advertisedDirectivesAt(capability: AvRelationMutationCapability | undefined, scope: AvWriteScope): readonly AvRelationMutationDirective[] | undefined;
|
|
103
120
|
/** A scalar field, including an enum-backed one. */
|
|
104
|
-
export type
|
|
121
|
+
export type AvScalarField<C extends AvContract> = {
|
|
105
122
|
readonly kind: "scalar";
|
|
106
123
|
readonly type: {
|
|
107
124
|
readonly scalar: Extract<keyof C["scalars"], string>;
|
|
108
125
|
} | {
|
|
109
126
|
readonly enum: Extract<keyof C["enums"], string>;
|
|
110
127
|
};
|
|
111
|
-
readonly format?:
|
|
128
|
+
readonly format?: AvScalarFormat;
|
|
112
129
|
readonly nullable: boolean;
|
|
113
130
|
readonly list: boolean;
|
|
114
|
-
readonly lifecycle: readonly
|
|
115
|
-
readonly capabilities:
|
|
131
|
+
readonly lifecycle: readonly AvLifecycleTrait[];
|
|
132
|
+
readonly capabilities: AvScalarFieldCapabilities;
|
|
116
133
|
/** A `json` field's shape, as JSON Schema: what every value written to it is. */
|
|
117
134
|
readonly json?: JsonSchema;
|
|
135
|
+
/**
|
|
136
|
+
* The field's validators: the root's checks, then the overlay's, in
|
|
137
|
+
* registration order. On a list field a check applies to each entry, except a
|
|
138
|
+
* `list: true` length check, which applies to the list.
|
|
139
|
+
*/
|
|
140
|
+
readonly validators?: readonly AvFieldCheck[];
|
|
141
|
+
/**
|
|
142
|
+
* `true` when the policy governs the field: it is left out of every default
|
|
143
|
+
* projection, and a caller that wants it names it (`select: ["$defaults",
|
|
144
|
+
* "email"]`).
|
|
145
|
+
*/
|
|
146
|
+
readonly governed?: true;
|
|
118
147
|
};
|
|
119
148
|
/** A relation field; the `target` Resource describes the related row. */
|
|
120
|
-
export type
|
|
149
|
+
export type AvRelationField<C extends AvContract> = {
|
|
121
150
|
readonly kind: "relation";
|
|
122
151
|
readonly target: Extract<keyof C["resources"], string>;
|
|
123
152
|
readonly cardinality: "one" | "many";
|
|
124
153
|
readonly nullable: boolean;
|
|
125
|
-
readonly capabilities:
|
|
154
|
+
readonly capabilities: AvRelationFieldCapabilities;
|
|
155
|
+
/**
|
|
156
|
+
* The target's relation field that is this relation's other end
|
|
157
|
+
* (`User.posts` ↔ `Post.author`): a record written through this relation sits
|
|
158
|
+
* at that field's `"loopback"` write position. Absent when the adapter states
|
|
159
|
+
* no pairing or the layer hides the other end.
|
|
160
|
+
*/
|
|
161
|
+
readonly inverse?: string;
|
|
162
|
+
/**
|
|
163
|
+
* The scalar fields of this Resource that hold the relation's reference, in the
|
|
164
|
+
* order the data source pairs them with the target's key (`Post.category` has
|
|
165
|
+
* `["categoryId"]`). Writing the relation and one of them in one record names
|
|
166
|
+
* the reference twice; inside a record written through the relation's other
|
|
167
|
+
* end they sit at the `"loopback"` position with it. Absent on the end that
|
|
168
|
+
* holds no reference, and where the layer shows none of them.
|
|
169
|
+
*/
|
|
170
|
+
readonly referenceFields?: readonly [string, ...string[]];
|
|
171
|
+
/**
|
|
172
|
+
* `true` when the policy engine's `governed` set names the relation: including
|
|
173
|
+
* it on rows the caller may not read it on refuses the request.
|
|
174
|
+
*/
|
|
175
|
+
readonly governed?: true;
|
|
126
176
|
};
|
|
127
177
|
/** One field of a Resource: a scalar or a relation. */
|
|
128
|
-
export type
|
|
178
|
+
export type AvField<C extends AvContract> = AvScalarField<C> | AvRelationField<C>;
|
|
179
|
+
/**
|
|
180
|
+
* A relation field as the Core Contract states it: an {@link AvRelationField}
|
|
181
|
+
* and, on the end that holds the reference, the target's fields it names.
|
|
182
|
+
*/
|
|
183
|
+
export type AvCoreRelationField<C extends AvContract> = AvRelationField<C> & {
|
|
184
|
+
/**
|
|
185
|
+
* The target's scalar fields that `referenceFields` name, pair by pair in the
|
|
186
|
+
* same order (`Post.author`: `referenceFields: ["authorId"]`,
|
|
187
|
+
* `references: ["id"]`). Present only beside a `referenceFields` the
|
|
188
|
+
* Contract states whole, and only when every one of them is a scalar field
|
|
189
|
+
* the Core Contract shows on the target; absent on the end that holds no
|
|
190
|
+
* reference, where the other end (`inverse`) states the pairs.
|
|
191
|
+
*/
|
|
192
|
+
readonly references?: readonly [string, ...string[]];
|
|
193
|
+
};
|
|
194
|
+
/** One field of a Resource as the Core Contract states it. */
|
|
195
|
+
export type AvCoreField<C extends AvContract> = AvScalarField<C> | AvCoreRelationField<C>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { AvContract } from "./contract.js";
|
|
2
|
+
import type { AvField } from "./field.js";
|
|
3
3
|
/** Keys of `TFields` whose field can be scalar-shaped. */
|
|
4
|
-
export type
|
|
4
|
+
export type AvScalarFieldKey<TFields extends Readonly<Record<string, AvField<AvContract>>>> = Extract<{
|
|
5
5
|
[K in keyof TFields]: [
|
|
6
6
|
Extract<TFields[K], {
|
|
7
7
|
readonly kind: "scalar";
|
|
@@ -9,4 +9,4 @@ export type ScalarFieldKey<TFields extends Readonly<Record<string, Field<Contrac
|
|
|
9
9
|
] extends [never] ? never : K;
|
|
10
10
|
}[keyof TFields], string>;
|
|
11
11
|
/** Non-empty tuple of scalar field keys that identifies at most one Resource. */
|
|
12
|
-
export type
|
|
12
|
+
export type AvIdentifier<TFields extends Readonly<Record<string, AvField<AvContract>>>> = readonly [AvScalarFieldKey<TFields>, ...AvScalarFieldKey<TFields>[]];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type Schema = {
|
|
2
|
+
readonly [key: string]: unknown;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* `value` projected onto `schema` (the `json` field subset): every object down
|
|
6
|
+
* to the members the schema declares, a list member by member, frozen.
|
|
7
|
+
*
|
|
8
|
+
* @throws TypeError when the value is not one the schema describes.
|
|
9
|
+
*/
|
|
10
|
+
export declare function projectJsonValue(value: unknown, schema: Schema): unknown;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
function isRecord(value) {
|
|
2
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
function memberSchema(schema) {
|
|
5
|
+
if (!isRecord(schema)) {
|
|
6
|
+
throw new TypeError("the schema is not one of the forms a ClientContract states");
|
|
7
|
+
}
|
|
8
|
+
return schema;
|
|
9
|
+
}
|
|
10
|
+
function fits(value, schema) {
|
|
11
|
+
if (Object.hasOwn(schema, "const")) {
|
|
12
|
+
return value === schema.const;
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(schema.enum)) {
|
|
15
|
+
return schema.enum.includes(value);
|
|
16
|
+
}
|
|
17
|
+
for (const keyword of ["anyOf", "oneOf"]) {
|
|
18
|
+
const options = schema[keyword];
|
|
19
|
+
if (Array.isArray(options)) {
|
|
20
|
+
return options.some((option) => fits(value, option));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
switch (schema.type) {
|
|
24
|
+
case "null":
|
|
25
|
+
return value === null;
|
|
26
|
+
case "boolean":
|
|
27
|
+
return typeof value === "boolean";
|
|
28
|
+
case "string":
|
|
29
|
+
return typeof value === "string";
|
|
30
|
+
case "number":
|
|
31
|
+
return typeof value === "number";
|
|
32
|
+
case "integer":
|
|
33
|
+
return Number.isInteger(value);
|
|
34
|
+
case "array":
|
|
35
|
+
return Array.isArray(value);
|
|
36
|
+
case "object":
|
|
37
|
+
return isRecord(value);
|
|
38
|
+
default:
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function projectJsonValue(value, schema) {
|
|
43
|
+
if (!fits(value, schema)) {
|
|
44
|
+
throw new TypeError("the value is not the one the ClientContract describes");
|
|
45
|
+
}
|
|
46
|
+
for (const keyword of ["anyOf", "oneOf"]) {
|
|
47
|
+
const options = schema[keyword];
|
|
48
|
+
if (Array.isArray(options)) {
|
|
49
|
+
const option = options.find((candidate) => fits(value, candidate));
|
|
50
|
+
return projectJsonValue(value, option);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (Array.isArray(value)) {
|
|
54
|
+
const prefix = schema.prefixItems;
|
|
55
|
+
const items = Array.isArray(prefix)
|
|
56
|
+
? undefined
|
|
57
|
+
: memberSchema(schema.items);
|
|
58
|
+
return Object.freeze(value.map((member, index) => projectJsonValue(member, items ?? memberSchema(prefix[index]))));
|
|
59
|
+
}
|
|
60
|
+
if (isRecord(value)) {
|
|
61
|
+
const properties = schema.properties;
|
|
62
|
+
if (isRecord(properties)) {
|
|
63
|
+
const copy = {};
|
|
64
|
+
for (const [key, member] of Object.entries(properties)) {
|
|
65
|
+
if (Object.hasOwn(value, key) && value[key] !== undefined) {
|
|
66
|
+
copy[key] = projectJsonValue(value[key], member);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return Object.freeze(copy);
|
|
70
|
+
}
|
|
71
|
+
const values = memberSchema(schema.additionalProperties);
|
|
72
|
+
return Object.freeze(Object.fromEntries(Object.entries(value).map(([key, member]) => [
|
|
73
|
+
key,
|
|
74
|
+
projectJsonValue(member, values),
|
|
75
|
+
])));
|
|
76
|
+
}
|
|
77
|
+
return value;
|
|
78
|
+
}
|