@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,29 +1,51 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { AvRelationFieldCapabilities, AvScalarFieldCapabilities, AvScalarFormat } from "../contracts/field.js";
|
|
2
|
+
import type { AvLifecycleTrait } from "../contracts/lifecycle-trait.js";
|
|
3
|
+
import type { AvAdapterModel } from "./adapter-model.js";
|
|
4
4
|
/** Provider-observable lifecycle facts available during adapter discovery. */
|
|
5
|
-
export type
|
|
5
|
+
export type AvAdapterLifecycleTrait = Extract<AvLifecycleTrait, "DEFAULTED" | "GENERATED_ON_CREATE" | "GENERATED_ON_UPDATE">;
|
|
6
6
|
/** Scalar-shaped provider field expressed only in Aventara vocabulary. */
|
|
7
|
-
export type
|
|
7
|
+
export type AvAdapterScalarField<M extends AvAdapterModel> = {
|
|
8
8
|
readonly kind: "scalar";
|
|
9
9
|
readonly type: {
|
|
10
10
|
readonly scalar: Extract<keyof M["scalars"], string>;
|
|
11
11
|
} | {
|
|
12
12
|
readonly enum: Extract<keyof M["enums"], string>;
|
|
13
13
|
};
|
|
14
|
-
readonly format?:
|
|
14
|
+
readonly format?: AvScalarFormat;
|
|
15
15
|
readonly nullable: boolean;
|
|
16
16
|
readonly list: boolean;
|
|
17
|
-
readonly lifecycle: readonly
|
|
18
|
-
readonly capabilities:
|
|
17
|
+
readonly lifecycle: readonly AvAdapterLifecycleTrait[];
|
|
18
|
+
readonly capabilities: AvScalarFieldCapabilities;
|
|
19
19
|
};
|
|
20
20
|
/** A discovered relation field; the `target` Resource describes the related row. */
|
|
21
|
-
export type
|
|
21
|
+
export type AvAdapterRelationField<M extends AvAdapterModel> = {
|
|
22
22
|
readonly kind: "relation";
|
|
23
23
|
readonly target: Extract<keyof M["resources"], string>;
|
|
24
24
|
readonly cardinality: "one" | "many";
|
|
25
25
|
readonly nullable: boolean;
|
|
26
|
-
readonly capabilities:
|
|
26
|
+
readonly capabilities: AvRelationFieldCapabilities;
|
|
27
|
+
/**
|
|
28
|
+
* The target's relation field that is this relation's other end, when the data
|
|
29
|
+
* source pairs them (`User.posts` ↔ `Post.author`; a self-relation's two ends
|
|
30
|
+
* name each other). Absent: no pairing is stated, and no write is read as
|
|
31
|
+
* walking a relation back.
|
|
32
|
+
*/
|
|
33
|
+
readonly inverse?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The scalar fields of this Resource that hold the relation's reference, in
|
|
36
|
+
* the order the data source pairs them with the target's key
|
|
37
|
+
* (`Post.author` → `["authorId"]`), on an optional relation as on a required
|
|
38
|
+
* one. Absent on the end that holds no reference (`User.posts`); never empty.
|
|
39
|
+
*/
|
|
40
|
+
readonly referenceFields?: readonly [string, ...string[]];
|
|
41
|
+
/**
|
|
42
|
+
* The target's scalar fields that `referenceFields` name, pair by pair in
|
|
43
|
+
* the same order (`Post.author`: `referenceFields: ["authorId"]`,
|
|
44
|
+
* `references: ["id"]`, so `Post.authorId` holds `User.id`). Stated only
|
|
45
|
+
* beside `referenceFields`, with as many entries; absent on the end that
|
|
46
|
+
* holds no reference, where the other end (`inverse`) states the pairs.
|
|
47
|
+
*/
|
|
48
|
+
readonly references?: readonly [string, ...string[]];
|
|
27
49
|
};
|
|
28
50
|
/** One field the adapter discovered: a scalar or a relation. */
|
|
29
|
-
export type
|
|
51
|
+
export type AvAdapterField<M extends AvAdapterModel> = AvAdapterScalarField<M> | AvAdapterRelationField<M>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { AvAdapterField } from "./adapter-field.js";
|
|
2
|
+
import type { AvAdapterModel } from "./adapter-model.js";
|
|
3
3
|
/** Keys of `TFields` whose discovered field can be scalar-shaped. */
|
|
4
|
-
export type
|
|
4
|
+
export type AvAdapterScalarFieldKey<TFields extends Readonly<Record<string, AvAdapterField<AvAdapterModel>>>> = Extract<{
|
|
5
5
|
[K in keyof TFields]: [
|
|
6
6
|
Extract<TFields[K], {
|
|
7
7
|
readonly kind: "scalar";
|
|
@@ -9,7 +9,16 @@ export type AdapterScalarFieldKey<TFields extends Readonly<Record<string, Adapte
|
|
|
9
9
|
] extends [never] ? never : K;
|
|
10
10
|
}[keyof TFields], string>;
|
|
11
11
|
/** Non-empty scalar-field tuple discovered as provider uniqueness. */
|
|
12
|
-
export type
|
|
13
|
-
|
|
14
|
-
...
|
|
12
|
+
export type AvAdapterIdentifier<TFields extends Readonly<Record<string, AvAdapterField<AvAdapterModel>>>> = readonly [
|
|
13
|
+
AvAdapterScalarFieldKey<TFields>,
|
|
14
|
+
...AvAdapterScalarFieldKey<TFields>[]
|
|
15
15
|
];
|
|
16
|
+
/**
|
|
17
|
+
* The Resource's identifier as the Adapter states it first: in the Adapter's
|
|
18
|
+
* own order (an ORM adapter's is its schema's, so the primary key). The Core
|
|
19
|
+
* Contract sorts identifiers for its hash, so its first one is the
|
|
20
|
+
* alphabetically first (`email` before `id`) and says nothing about which is
|
|
21
|
+
* the primary key; the model keeps the order it declared. Empty for a Resource
|
|
22
|
+
* the model does not hold or that has no identifier.
|
|
23
|
+
*/
|
|
24
|
+
export declare function adapterPrimaryIdentifier(model: AvAdapterModel, resource: string): readonly string[];
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AvConfigComputedFields } from "../config/computed-fields.js";
|
|
2
|
+
import type { AvEnumDefinition } from "../contracts/enum-definition.js";
|
|
2
3
|
import type { ReferenceWriteLimit } from "../contracts/reference-write-limit.js";
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
4
|
+
import type { AvScalarRegistry } from "../contracts/scalar.js";
|
|
5
|
+
import type { AvTransactionCapability } from "../contracts/transaction-capability.js";
|
|
6
|
+
import type { AvAdapterResource } from "./adapter-resource.js";
|
|
6
7
|
/**
|
|
7
8
|
* Canonical provider-discovery facts before framework configuration or
|
|
8
9
|
* Contract compilation is applied.
|
|
9
10
|
*/
|
|
10
|
-
export interface
|
|
11
|
+
export interface AvAdapterModel {
|
|
11
12
|
/** The scalar types the data source supports. */
|
|
12
|
-
readonly scalars:
|
|
13
|
+
readonly scalars: AvScalarRegistry;
|
|
13
14
|
/** The enums the data source declares, by name. */
|
|
14
|
-
readonly enums: Readonly<Record<string,
|
|
15
|
+
readonly enums: Readonly<Record<string, AvEnumDefinition>>;
|
|
15
16
|
/** The discovered Resources, by name. */
|
|
16
|
-
readonly resources: Readonly<Record<string,
|
|
17
|
+
readonly resources: Readonly<Record<string, AvAdapterResource<this>>>;
|
|
17
18
|
/** Whether the adapter can run interactive transactions. */
|
|
18
|
-
readonly transactions:
|
|
19
|
+
readonly transactions: AvTransactionCapability;
|
|
19
20
|
/**
|
|
20
21
|
* `"uniform"` when the data source takes one record's references only one
|
|
21
22
|
* way at a time: every relation that holds a reference written as a
|
|
@@ -23,4 +24,12 @@ export interface AdapterModel {
|
|
|
23
24
|
* either way. Compiled into every Contract.
|
|
24
25
|
*/
|
|
25
26
|
readonly referenceWrites?: ReferenceWriteLimit;
|
|
27
|
+
/**
|
|
28
|
+
* Type-only, never present at runtime: which fields the configuration's write
|
|
29
|
+
* compute fills, as an adapter's generate step read them off the
|
|
30
|
+
* configuration's type. A variant's guards, pipes and filters may leave
|
|
31
|
+
* exactly those out of a create. Absent: any create field may be computed, so
|
|
32
|
+
* those stages require none.
|
|
33
|
+
*/
|
|
34
|
+
readonly "~computedFields"?: AvConfigComputedFields;
|
|
26
35
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { AvAdapterModel } from "./adapter-model.js";
|
|
2
|
+
import type { AvAdapterOperation } from "./adapter-operation.js";
|
|
3
3
|
/**
|
|
4
4
|
* Executes one operation against the provider, directly or inside a provider
|
|
5
5
|
* transaction.
|
|
6
6
|
*/
|
|
7
|
-
export interface
|
|
7
|
+
export interface AvAdapterOperationExecutor<M extends AvAdapterModel = AvAdapterModel> {
|
|
8
8
|
/** Runs one validated operation and resolves its raw result. */
|
|
9
|
-
execute(operation:
|
|
9
|
+
execute(operation: AvAdapterOperation<M>): Promise<unknown>;
|
|
10
10
|
}
|
|
@@ -1,12 +1,27 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AvOperationIdentity } from "../operations/operation-identity.js";
|
|
2
2
|
import type { SemanticOperationArguments } from "../operations/operation-validator.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { AvAdapterModel } from "./adapter-model.js";
|
|
4
4
|
/**
|
|
5
|
-
* Provider execution request after framework semantic validation.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Provider execution request after framework semantic validation. Operation
|
|
6
|
+
* identity and arguments remain provider-neutral; adapters receive only validated
|
|
7
|
+
* semantic argument objects, never raw transport input.
|
|
8
|
+
*
|
|
9
|
+
* Three shapes exist here only, each an `AND`: a list of conditions in the general
|
|
10
|
+
* `where` grammar the addressed row must also meet.
|
|
11
|
+
*
|
|
12
|
+
* - The flat unique selector of an `update.unique` or a `delete.unique` may carry
|
|
13
|
+
* it. A row the selector names that misses them is a miss (the same `null` as a
|
|
14
|
+
* row that is not there).
|
|
15
|
+
* - A `cursor` may carry it, at the root of a `find.many` and in a to-many
|
|
16
|
+
* relation's arguments. A row the cursor names that misses them is a cursor that
|
|
17
|
+
* names no row: the same answer as a cursor on a row that is not there.
|
|
18
|
+
* - A row the selector names that misses them, or no row, is refused: the adapter
|
|
19
|
+
* fails the operation with `A4002`.
|
|
20
|
+
*
|
|
21
|
+
* An adapter must honour it or refuse the operation, never drop it: dropping it
|
|
22
|
+
* would write a row the conditions exclude, or position a page at one.
|
|
8
23
|
*/
|
|
9
|
-
export type
|
|
24
|
+
export type AvAdapterOperation<M extends AvAdapterModel = AvAdapterModel> = AvOperationIdentity & {
|
|
10
25
|
readonly resource: Extract<keyof M["resources"], string>;
|
|
11
26
|
readonly arguments: SemanticOperationArguments;
|
|
12
27
|
};
|
|
@@ -1,20 +1,34 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
1
|
+
import type { AvCreateRequirements } from "../contracts/create-requirements.js";
|
|
2
|
+
import type { AvResourceOperations } from "../contracts/resource-operations.js";
|
|
3
|
+
import type { AvAdapterField } from "./adapter-field.js";
|
|
4
|
+
import type { AvAdapterIdentifier } from "./adapter-identifier.js";
|
|
5
|
+
import type { AvAdapterModel } from "./adapter-model.js";
|
|
5
6
|
/** A discovered Resource's fields, by name. */
|
|
6
|
-
export type
|
|
7
|
+
export type AvAdapterFieldMap<M extends AvAdapterModel> = Readonly<Record<string, AvAdapterField<M>>>;
|
|
7
8
|
/**
|
|
8
9
|
* The field names the adapter discovered for Resource `R`, before any
|
|
9
10
|
* configuration adds to them.
|
|
10
11
|
*/
|
|
11
|
-
export type
|
|
12
|
+
export type AvAdapterFieldKey<M extends AvAdapterModel, R extends Extract<keyof M["resources"], string>> = Extract<keyof M["resources"][R]["fields"], string>;
|
|
12
13
|
/** Provider-discovered facts for one Aventara Resource candidate. */
|
|
13
|
-
export type
|
|
14
|
+
export type AvAdapterResource<M extends AvAdapterModel, TFields extends AvAdapterFieldMap<M> = AvAdapterFieldMap<M>> = {
|
|
14
15
|
/** The Resource's fields, by name. */
|
|
15
16
|
readonly fields: TFields;
|
|
16
17
|
/** The field tuples that identify at most one row. */
|
|
17
|
-
readonly identifiers: readonly
|
|
18
|
+
readonly identifiers: readonly AvAdapterIdentifier<TFields>[];
|
|
18
19
|
/** The standard operations the data source can run for this Resource. */
|
|
19
|
-
readonly operations:
|
|
20
|
+
readonly operations: AvResourceOperations;
|
|
21
|
+
/**
|
|
22
|
+
* What a create cannot do without, in the store's own terms: every field it
|
|
23
|
+
* requires, every required to-one relation with its reference fields, and
|
|
24
|
+
* the relation (`parentSupplies`) through which a nested create gets them
|
|
25
|
+
* from its parent. Absent when it requires nothing, or when the adapter
|
|
26
|
+
* cannot say; nothing is then checked or typed before the store.
|
|
27
|
+
*/
|
|
28
|
+
readonly createRequirements?: AvCreateRequirements;
|
|
29
|
+
/**
|
|
30
|
+
* The database schema the store keeps this Resource in (a PostgreSQL schema,
|
|
31
|
+
* say), when the store has schemas and the model names one. Absent otherwise.
|
|
32
|
+
*/
|
|
33
|
+
readonly schema?: string;
|
|
20
34
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AvDecimal } from "../runtime/decimal.js";
|
|
2
|
+
import type { AvJsonValue } from "../runtime/json-value.js";
|
|
3
|
+
/**
|
|
4
|
+
* One value a developer SQL statement binds, after every `$ref` in it was
|
|
5
|
+
* resolved: a primitive, a `Date`, a {@link AvDecimal}, a `Uint8Array`, or a
|
|
6
|
+
* plain object or array, which is a JSON value and is bound as JSON text. Never
|
|
7
|
+
* spliced into the statement's text.
|
|
8
|
+
*/
|
|
9
|
+
export type AvAdapterSqlValue = string | number | boolean | bigint | null | Date | AvDecimal | Uint8Array | AvJsonValue;
|
|
10
|
+
/**
|
|
11
|
+
* One developer SQL statement, as `framework.appTx.$sql` wrote it: the static
|
|
12
|
+
* text of its tagged template, and the values written between those pieces, in
|
|
13
|
+
* order. `strings` holds exactly one entry more than `values`. The adapter binds
|
|
14
|
+
* every value as a parameter of the statement; no value ever becomes SQL text.
|
|
15
|
+
*/
|
|
16
|
+
export type AvAdapterSqlStatement = {
|
|
17
|
+
readonly strings: readonly string[];
|
|
18
|
+
readonly values: readonly AvAdapterSqlValue[];
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AvAdapterModel } from "./adapter-model.js";
|
|
2
|
+
import type { AvAdapterOperationExecutor } from "./adapter-operation-executor.interface.js";
|
|
3
|
+
import type { AvAdapterSqlStatement } from "./adapter-sql-statement.js";
|
|
4
|
+
/**
|
|
5
|
+
* What an Adapter's `transaction` callback is handed: the transaction-scoped
|
|
6
|
+
* operation executor, and — when the Adapter declares `sqlStatements` — the
|
|
7
|
+
* statement runner `framework.appTx.$sql` steps run through.
|
|
8
|
+
*/
|
|
9
|
+
export interface AvAdapterTransactionExecutor<M extends AvAdapterModel = AvAdapterModel> extends AvAdapterOperationExecutor<M> {
|
|
10
|
+
/**
|
|
11
|
+
* Runs one developer SQL statement on the open transaction, every value bound
|
|
12
|
+
* as a parameter, and resolves the rows it returned (none for a statement that
|
|
13
|
+
* returns no rows). Present exactly when the Adapter declares `sqlStatements`.
|
|
14
|
+
*
|
|
15
|
+
* A failure is thrown like an operation's: a deliberate `AvError` for
|
|
16
|
+
* an outcome the Adapter classified, anything else to be answered `A3001`.
|
|
17
|
+
*/
|
|
18
|
+
executeSql?(statement: AvAdapterSqlStatement): Promise<readonly unknown[]>;
|
|
19
|
+
}
|
|
@@ -1,50 +1,80 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AvConfigComputedFields } from "../config/computed-fields.js";
|
|
2
2
|
import type { ReferentialActionTable } from "../runtime/referential-action.js";
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
3
|
+
import type { AvAdapterModel } from "./adapter-model.js";
|
|
4
|
+
import type { AvAdapterOperationExecutor } from "./adapter-operation-executor.interface.js";
|
|
5
|
+
import type { AvAdapterSqlStatement } from "./adapter-sql-statement.js";
|
|
6
|
+
import type { AvAdapterTransactionExecutor } from "./adapter-transaction-executor.interface.js";
|
|
5
7
|
/** Provider-specific implementation of Aventara discovery and execution. */
|
|
6
|
-
export interface
|
|
8
|
+
export interface AvAdapter<M extends AvAdapterModel = AvAdapterModel> extends AvAdapterOperationExecutor<M> {
|
|
7
9
|
/**
|
|
8
10
|
* What the adapter discovered about the data source, in Aventara's vocabulary.
|
|
9
11
|
* Read once, synchronously, when the framework is constructed.
|
|
10
12
|
*/
|
|
11
13
|
readonly model: M;
|
|
12
14
|
/**
|
|
13
|
-
* Optional referential actions: for each Resource that holds a reference,
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* Optional referential actions: for each Resource that holds a reference, every
|
|
16
|
+
* relation holding one: the fields that hold it (`references`) and what deleting a
|
|
17
|
+
* referenced row does to its rows. Read once when the framework is constructed;
|
|
18
|
+
* never part of a Contract or its hash.
|
|
19
|
+
*
|
|
20
|
+
* An edge listed under Resource `R` says that deleting a `target` row does
|
|
21
|
+
* `onDelete` to rows of `R`, and that `R`'s `references` fields hold the relation
|
|
22
|
+
* `field`'s reference.
|
|
17
23
|
*
|
|
18
|
-
*
|
|
19
|
-
* `
|
|
20
|
-
*
|
|
24
|
+
* The same edges say which side of a relation holds its key: a nested `$connect`,
|
|
25
|
+
* `$disconnect` or `$set` on a to-one relation the parent holds runs none of the
|
|
26
|
+
* target's stages, and otherwise runs the target's `update` guards.
|
|
21
27
|
*
|
|
22
|
-
* When absent, no cascade is planned and no transaction plan is refused
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
28
|
+
* When absent, no cascade is planned and no transaction plan is refused because of
|
|
29
|
+
* one (`V1019`); a write that sets a relation and a field holding its reference
|
|
30
|
+
* both is not refused before the store; and every nested `$connect`, `$disconnect`
|
|
31
|
+
* or `$set` runs the target's `update` guards.
|
|
26
32
|
*/
|
|
27
33
|
readonly referentialActions?: ReferentialActionTable;
|
|
28
34
|
/**
|
|
29
|
-
* Optional
|
|
30
|
-
*
|
|
31
|
-
*
|
|
35
|
+
* Optional: which fields the configuration's write compute fills, as the
|
|
36
|
+
* Adapter's generate step read them when it wrote the model's type (the same
|
|
37
|
+
* statement as the type's `"~computedFields"`). When the Framework is
|
|
38
|
+
* constructed it is compared with the configuration, and a difference is a
|
|
39
|
+
* warning that the generated types are stale (`aventara:prepare` regenerates
|
|
40
|
+
* them); it changes no behaviour. Never part of a Contract or its hash.
|
|
41
|
+
*/
|
|
42
|
+
readonly computedFields?: AvConfigComputedFields;
|
|
43
|
+
/**
|
|
44
|
+
* Optional: `true` when the Adapter runs developer SQL statements: standalone
|
|
45
|
+
* through its own {@link executeSql}, and, when it has `transaction`, inside a
|
|
46
|
+
* transaction through the `executeSql` of the executor that callback is handed
|
|
47
|
+
* (`AvAdapterTransactionExecutor.executeSql`). `framework.appTx.$sql` steps and
|
|
48
|
+
* `ctx.$sql` need it. Read once when the framework is constructed; never part
|
|
49
|
+
* of a Contract or its hash.
|
|
50
|
+
*
|
|
51
|
+
* When absent, a plan holding an `appTx.$sql` step is refused before the
|
|
52
|
+
* transaction opens (`A2002`/`V1006` at the step), and so is every `ctx.$sql`.
|
|
53
|
+
*/
|
|
54
|
+
readonly sqlStatements?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Runs one developer SQL statement outside any transaction, as a plain
|
|
57
|
+
* statement, every value bound as a parameter, and resolves the rows it
|
|
58
|
+
* returned (none for a statement that returns no rows). Present exactly when
|
|
59
|
+
* the Adapter declares `sqlStatements`. `ctx.$sql` outside a transaction runs
|
|
60
|
+
* through it.
|
|
32
61
|
*
|
|
33
|
-
*
|
|
34
|
-
* the
|
|
62
|
+
* A failure is thrown like an operation's: a deliberate `AvError` for an
|
|
63
|
+
* outcome the Adapter classified, anything else to be answered `A3001`.
|
|
35
64
|
*/
|
|
36
|
-
readonly
|
|
65
|
+
executeSql?(statement: AvAdapterSqlStatement): Promise<readonly unknown[]>;
|
|
37
66
|
/**
|
|
38
67
|
* Optional callback transaction capability, required exactly when the
|
|
39
68
|
* discovered model declares `transactions: "interactive"`. The callback
|
|
40
|
-
* receives only a transaction-scoped
|
|
41
|
-
*
|
|
69
|
+
* receives only a transaction-scoped executor, never the provider client
|
|
70
|
+
* itself, and every step of a plan executes through it.
|
|
42
71
|
*
|
|
43
|
-
* The implementation must reject with the exact value `work` threw
|
|
44
|
-
* never a wrapper
|
|
45
|
-
* implied by that rejection.
|
|
46
|
-
*
|
|
47
|
-
* not perform network I/O or unrelated slow work.
|
|
72
|
+
* The implementation must reject with the exact value `work` threw (by identity,
|
|
73
|
+
* never a wrapper) and must not resolve after `work` rejected; rollback is
|
|
74
|
+
* implied by that rejection. Every step's interceptors and hooks, and the touched
|
|
75
|
+
* Resources' transaction stages, run inside `work` while the provider transaction
|
|
76
|
+
* is open, so they must not perform network I/O or unrelated slow work. A step's
|
|
77
|
+
* guards, pipes and validators run before it opens.
|
|
48
78
|
*/
|
|
49
|
-
transaction?<T>(work: (executor:
|
|
79
|
+
transaction?<T>(work: (executor: AvAdapterTransactionExecutor<M>) => Promise<T>): Promise<T>;
|
|
50
80
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type AvZCheck } from "./avz-check.registry.js";
|
|
2
|
+
/** The fields a bound applies to, by the kind of value it was written as. */
|
|
3
|
+
type BoundTarget<Value> = Value extends Date ? "datetime" : Value extends bigint ? "bigint" | "decimal" : "number" | "decimal";
|
|
4
|
+
/** A value below `value`. */
|
|
5
|
+
export declare const lt: <const Value extends number | bigint | Date>(value: Value) => AvZCheck<BoundTarget<Value>>;
|
|
6
|
+
/** A value at most `value`. */
|
|
7
|
+
export declare const lte: <const Value extends number | bigint | Date>(value: Value) => AvZCheck<BoundTarget<Value>>;
|
|
8
|
+
/** A value above `value`. */
|
|
9
|
+
export declare const gt: <const Value extends number | bigint | Date>(value: Value) => AvZCheck<BoundTarget<Value>>;
|
|
10
|
+
/** A value at least `value`. */
|
|
11
|
+
export declare const gte: <const Value extends number | bigint | Date>(value: Value) => AvZCheck<BoundTarget<Value>>;
|
|
12
|
+
/** A value above zero. */
|
|
13
|
+
export declare const positive: () => AvZCheck<"number" | "bigint" | "decimal">;
|
|
14
|
+
/** A value at least zero. */
|
|
15
|
+
export declare const nonnegative: () => AvZCheck<"number" | "bigint" | "decimal">;
|
|
16
|
+
/** A value below zero. */
|
|
17
|
+
export declare const negative: () => AvZCheck<"number" | "bigint" | "decimal">;
|
|
18
|
+
/** A value at most zero. */
|
|
19
|
+
export declare const nonpositive: () => AvZCheck<"number" | "bigint" | "decimal">;
|
|
20
|
+
/** A multiple of `value` (not zero). */
|
|
21
|
+
export declare const multipleOf: <const Value extends number | bigint>(value: Value) => AvZCheck<Value extends bigint ? "bigint" | "decimal" : "number" | "decimal">;
|
|
22
|
+
/** A string of at most `maximum` characters (Unicode code points). */
|
|
23
|
+
export declare const maxLength: (maximum: number) => AvZCheck<"string">;
|
|
24
|
+
/** A string of at least `minimum` characters (Unicode code points). */
|
|
25
|
+
export declare const minLength: (minimum: number) => AvZCheck<"string">;
|
|
26
|
+
/** A string of exactly `length` characters (Unicode code points). */
|
|
27
|
+
export declare const length: (exact: number) => AvZCheck<"string">;
|
|
28
|
+
/** A list of at most `maximum` entries. */
|
|
29
|
+
export declare const maxItems: (maximum: number) => AvZCheck<"list">;
|
|
30
|
+
/** A list of at least `minimum` entries. */
|
|
31
|
+
export declare const minItems: (minimum: number) => AvZCheck<"list">;
|
|
32
|
+
/** Bytes of at most `maximum` in length. */
|
|
33
|
+
export declare const maxSize: (maximum: number) => AvZCheck<"bytes">;
|
|
34
|
+
/** Bytes of at least `minimum` in length. */
|
|
35
|
+
export declare const minSize: (minimum: number) => AvZCheck<"bytes">;
|
|
36
|
+
/** Bytes of exactly `size` in length. */
|
|
37
|
+
export declare const size: (exact: number) => AvZCheck<"bytes">;
|
|
38
|
+
/** A string `pattern` matches (a JavaScript regular expression; its flags count). */
|
|
39
|
+
export declare const regex: (pattern: RegExp) => AvZCheck<"string">;
|
|
40
|
+
/** A string containing `value`. */
|
|
41
|
+
export declare const includes: (value: string) => AvZCheck<"string">;
|
|
42
|
+
/** A string starting with `prefix`. */
|
|
43
|
+
export declare const startsWith: (prefix: string) => AvZCheck<"string">;
|
|
44
|
+
/** A string ending with `suffix`. */
|
|
45
|
+
export declare const endsWith: (suffix: string) => AvZCheck<"string">;
|
|
46
|
+
/** A string with no uppercase letter (A–Z). */
|
|
47
|
+
export declare const lowercase: () => AvZCheck<"string">;
|
|
48
|
+
/** A string with no lowercase letter (a–z). */
|
|
49
|
+
export declare const uppercase: () => AvZCheck<"string">;
|
|
50
|
+
export declare const email: () => AvZCheck<"string">;
|
|
51
|
+
export declare const url: () => AvZCheck<"string">;
|
|
52
|
+
export declare const emoji: () => AvZCheck<"string">;
|
|
53
|
+
export declare const uuid: () => AvZCheck<"string">;
|
|
54
|
+
export declare const guid: () => AvZCheck<"string">;
|
|
55
|
+
export declare const nanoid: () => AvZCheck<"string">;
|
|
56
|
+
export declare const cuid: () => AvZCheck<"string">;
|
|
57
|
+
export declare const cuid2: () => AvZCheck<"string">;
|
|
58
|
+
export declare const ulid: () => AvZCheck<"string">;
|
|
59
|
+
export declare const xid: () => AvZCheck<"string">;
|
|
60
|
+
export declare const ksuid: () => AvZCheck<"string">;
|
|
61
|
+
export declare const ipv4: () => AvZCheck<"string">;
|
|
62
|
+
export declare const ipv6: () => AvZCheck<"string">;
|
|
63
|
+
export declare const cidrv4: () => AvZCheck<"string">;
|
|
64
|
+
export declare const cidrv6: () => AvZCheck<"string">;
|
|
65
|
+
export declare const base64: () => AvZCheck<"string">;
|
|
66
|
+
export declare const base64url: () => AvZCheck<"string">;
|
|
67
|
+
export declare const jsonString: () => AvZCheck<"string">;
|
|
68
|
+
export declare const e164: () => AvZCheck<"string">;
|
|
69
|
+
export declare const creditCard: () => AvZCheck<"string">;
|
|
70
|
+
export declare const iban: () => AvZCheck<"string">;
|
|
71
|
+
export declare const jwt: () => AvZCheck<"string">;
|
|
72
|
+
/** zod's ISO 8601 formats, as `z.iso` names them. */
|
|
73
|
+
export declare const iso: Readonly<{
|
|
74
|
+
/** A date-time in UTC (`Z`), seconds required, any fraction (`z.iso.datetime()`). */
|
|
75
|
+
datetime: () => AvZCheck<"string">;
|
|
76
|
+
/** A calendar date, `YYYY-MM-DD` (`z.iso.date()`). */
|
|
77
|
+
date: () => AvZCheck<"string">;
|
|
78
|
+
/** A time, `HH:MM` with optional seconds and fraction (`z.iso.time()`). */
|
|
79
|
+
time: () => AvZCheck<"string">;
|
|
80
|
+
/** A duration such as `P3DT4H` (`z.iso.duration()`). */
|
|
81
|
+
duration: () => AvZCheck<"string">;
|
|
82
|
+
}>;
|
|
83
|
+
export {};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { registerAvZCheck, } from "./avz-check.registry.js";
|
|
2
|
+
const CHECK_PROTOTYPE = Object.freeze(Object.create(null));
|
|
3
|
+
function build(data) {
|
|
4
|
+
const check = Object.freeze(Object.assign(Object.create(CHECK_PROTOTYPE), data));
|
|
5
|
+
registerAvZCheck(check, Object.freeze({ ...data }));
|
|
6
|
+
return check;
|
|
7
|
+
}
|
|
8
|
+
function bound(builder, value) {
|
|
9
|
+
if ((typeof value === "number" && Number.isFinite(value)) ||
|
|
10
|
+
typeof value === "bigint" ||
|
|
11
|
+
(value instanceof Date && !Number.isNaN(value.getTime()))) {
|
|
12
|
+
return value instanceof Date ? new Date(value.getTime()) : value;
|
|
13
|
+
}
|
|
14
|
+
throw new TypeError(`AvZ.${builder}: the bound must be a finite number, a bigint or a valid Date.`);
|
|
15
|
+
}
|
|
16
|
+
function count(builder, value) {
|
|
17
|
+
if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0) {
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
throw new TypeError(`AvZ.${builder}: the length must be a non-negative integer.`);
|
|
21
|
+
}
|
|
22
|
+
function text(builder, value) {
|
|
23
|
+
if (typeof value === "string") {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
throw new TypeError(`AvZ.${builder}: the text must be a string.`);
|
|
27
|
+
}
|
|
28
|
+
const range = (builder, check, inclusive) => (value) => build({ check, value: bound(builder, value), inclusive });
|
|
29
|
+
const sign = (check, inclusive) => () => build({ check, value: 0, inclusive });
|
|
30
|
+
export const lt = range("lt", "less_than", false);
|
|
31
|
+
export const lte = range("lte", "less_than", true);
|
|
32
|
+
export const gt = range("gt", "greater_than", false);
|
|
33
|
+
export const gte = range("gte", "greater_than", true);
|
|
34
|
+
export const positive = sign("greater_than", false);
|
|
35
|
+
export const nonnegative = sign("greater_than", true);
|
|
36
|
+
export const negative = sign("less_than", false);
|
|
37
|
+
export const nonpositive = sign("less_than", true);
|
|
38
|
+
export const multipleOf = (value) => {
|
|
39
|
+
const step = bound("multipleOf", value);
|
|
40
|
+
if (step instanceof Date || step === 0 || step === 0n) {
|
|
41
|
+
throw new TypeError("AvZ.multipleOf: the step must be a non-zero finite number or bigint.");
|
|
42
|
+
}
|
|
43
|
+
return build({ check: "multiple_of", value: step });
|
|
44
|
+
};
|
|
45
|
+
export const maxLength = (maximum) => build({ check: "max_length", maximum: count("maxLength", maximum) });
|
|
46
|
+
export const minLength = (minimum) => build({ check: "min_length", minimum: count("minLength", minimum) });
|
|
47
|
+
export const length = (exact) => build({ check: "length_equals", length: count("length", exact) });
|
|
48
|
+
export const maxItems = (maximum) => build({
|
|
49
|
+
check: "max_length",
|
|
50
|
+
maximum: count("maxItems", maximum),
|
|
51
|
+
list: true,
|
|
52
|
+
});
|
|
53
|
+
export const minItems = (minimum) => build({
|
|
54
|
+
check: "min_length",
|
|
55
|
+
minimum: count("minItems", minimum),
|
|
56
|
+
list: true,
|
|
57
|
+
});
|
|
58
|
+
export const maxSize = (maximum) => build({ check: "max_size", maximum: count("maxSize", maximum) });
|
|
59
|
+
export const minSize = (minimum) => build({ check: "min_size", minimum: count("minSize", minimum) });
|
|
60
|
+
export const size = (exact) => build({ check: "size_equals", size: count("size", exact) });
|
|
61
|
+
export const regex = (pattern) => {
|
|
62
|
+
if (!(pattern instanceof RegExp)) {
|
|
63
|
+
throw new TypeError("AvZ.regex: the pattern must be a RegExp.");
|
|
64
|
+
}
|
|
65
|
+
return build({
|
|
66
|
+
check: "string_format",
|
|
67
|
+
format: "regex",
|
|
68
|
+
pattern: { source: pattern.source, flags: pattern.flags },
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
export const includes = (value) => build({
|
|
72
|
+
check: "string_format",
|
|
73
|
+
format: "includes",
|
|
74
|
+
includes: text("includes", value),
|
|
75
|
+
});
|
|
76
|
+
export const startsWith = (prefix) => build({
|
|
77
|
+
check: "string_format",
|
|
78
|
+
format: "starts_with",
|
|
79
|
+
prefix: text("startsWith", prefix),
|
|
80
|
+
});
|
|
81
|
+
export const endsWith = (suffix) => build({
|
|
82
|
+
check: "string_format",
|
|
83
|
+
format: "ends_with",
|
|
84
|
+
suffix: text("endsWith", suffix),
|
|
85
|
+
});
|
|
86
|
+
export const lowercase = () => build({ check: "string_format", format: "lowercase" });
|
|
87
|
+
export const uppercase = () => build({ check: "string_format", format: "uppercase" });
|
|
88
|
+
const named = (format) => () => build({ check: "string_format", format });
|
|
89
|
+
export const email = named("email");
|
|
90
|
+
export const url = named("url");
|
|
91
|
+
export const emoji = named("emoji");
|
|
92
|
+
export const uuid = named("uuid");
|
|
93
|
+
export const guid = named("guid");
|
|
94
|
+
export const nanoid = named("nanoid");
|
|
95
|
+
export const cuid = named("cuid");
|
|
96
|
+
export const cuid2 = named("cuid2");
|
|
97
|
+
export const ulid = named("ulid");
|
|
98
|
+
export const xid = named("xid");
|
|
99
|
+
export const ksuid = named("ksuid");
|
|
100
|
+
export const ipv4 = named("ipv4");
|
|
101
|
+
export const ipv6 = named("ipv6");
|
|
102
|
+
export const cidrv4 = named("cidrv4");
|
|
103
|
+
export const cidrv6 = named("cidrv6");
|
|
104
|
+
export const base64 = named("base64");
|
|
105
|
+
export const base64url = named("base64url");
|
|
106
|
+
export const jsonString = named("json_string");
|
|
107
|
+
export const e164 = named("e164");
|
|
108
|
+
export const creditCard = named("credit_card");
|
|
109
|
+
export const iban = named("iban");
|
|
110
|
+
export const jwt = named("jwt");
|
|
111
|
+
export const iso = Object.freeze({
|
|
112
|
+
datetime: named("datetime"),
|
|
113
|
+
date: named("date"),
|
|
114
|
+
time: named("time"),
|
|
115
|
+
duration: named("duration"),
|
|
116
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AvFieldCheck } from "../contracts/field-check.js";
|
|
2
|
+
declare const avzCheckTarget: unique symbol;
|
|
3
|
+
/**
|
|
4
|
+
* What a check applies to: a field's scalar type (`int` and `float` are
|
|
5
|
+
* `"number"`), a Json Shape node (a string, a number or an integer), or a list's
|
|
6
|
+
* own length (`"list"`).
|
|
7
|
+
*/
|
|
8
|
+
export type AvZCheckTarget = "string" | "number" | "bigint" | "decimal" | "datetime" | "bytes" | "list";
|
|
9
|
+
/**
|
|
10
|
+
* A declarative check built with `AvZ` from `@aventara/core/avz` (`AvZ.maxLength(80)`,
|
|
11
|
+
* `AvZ.email()`, …): a field validator, or a check on a Json Shape node.
|
|
12
|
+
*/
|
|
13
|
+
export interface AvZCheck<Target extends AvZCheckTarget = never> {
|
|
14
|
+
readonly [avzCheckTarget]: (target: Target) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A check as `AvZ` built it: the Contract's form, except that a bound or a step
|
|
18
|
+
* is the value the developer wrote (a number, a bigint or a `Date`) until the
|
|
19
|
+
* compiler writes it in the form of the field it lands on.
|
|
20
|
+
*/
|
|
21
|
+
export type AvZAuthoredCheck = {
|
|
22
|
+
readonly check: "less_than" | "greater_than";
|
|
23
|
+
readonly value: number | bigint | Date;
|
|
24
|
+
readonly inclusive: boolean;
|
|
25
|
+
} | {
|
|
26
|
+
readonly check: "multiple_of";
|
|
27
|
+
readonly value: number | bigint;
|
|
28
|
+
} | Exclude<AvFieldCheck, {
|
|
29
|
+
readonly check: "less_than" | "greater_than" | "multiple_of";
|
|
30
|
+
}>;
|
|
31
|
+
/** Records `check` as built by `AvZ`. For `@aventara/core/avz` only. */
|
|
32
|
+
export declare function registerAvZCheck(check: object, data: AvZAuthoredCheck): void;
|
|
33
|
+
/** The check `value` is, or `undefined` when `AvZ` did not build it. */
|
|
34
|
+
export declare function avzCheckOf(value: unknown): AvZAuthoredCheck | undefined;
|
|
35
|
+
export {};
|