@aventara/core 1.0.0-rc.0 → 1.0.0-rc.1

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.
Files changed (242) hide show
  1. package/CHANGELOG.md +1140 -0
  2. package/README.md +224 -57
  3. package/dist/adapters/adapter-discovery-diagnostic.d.ts +4 -4
  4. package/dist/adapters/adapter-field.d.ts +11 -11
  5. package/dist/adapters/adapter-identifier.d.ts +6 -6
  6. package/dist/adapters/adapter-model.d.ts +9 -9
  7. package/dist/adapters/adapter-operation-executor.interface.d.ts +4 -4
  8. package/dist/adapters/adapter-operation.d.ts +3 -3
  9. package/dist/adapters/adapter-resource.d.ts +18 -9
  10. package/dist/adapters/adapter-sql-statement.d.ts +19 -0
  11. package/dist/adapters/adapter-transaction-executor.interface.d.ts +19 -0
  12. package/dist/adapters/adapter.interface.d.ts +49 -29
  13. package/dist/avz/avz-check.factory.d.ts +83 -0
  14. package/dist/avz/avz-check.factory.js +116 -0
  15. package/dist/avz/avz-check.registry.d.ts +35 -0
  16. package/dist/avz/avz-check.registry.js +9 -0
  17. package/dist/avz/avz.d.ts +203 -0
  18. package/dist/{json → avz}/avz.js +150 -8
  19. package/dist/{json → avz}/index.d.ts +2 -1
  20. package/dist/{json → avz}/json-shape.registry.d.ts +7 -7
  21. package/dist/{json → avz}/zod-issue.translator.d.ts +8 -2
  22. package/dist/{json → avz}/zod-issue.translator.js +7 -0
  23. package/dist/compiler/contract-compiler-diagnostic.d.ts +31 -5
  24. package/dist/compiler/contract.compiler.d.ts +18 -18
  25. package/dist/compiler/contract.compiler.js +548 -441
  26. package/dist/compiler/create-requirements.projector.d.ts +49 -0
  27. package/dist/compiler/create-requirements.projector.js +423 -0
  28. package/dist/compiler/field-validator.compiler.d.ts +47 -0
  29. package/dist/compiler/field-validator.compiler.js +238 -0
  30. package/dist/config/any-framework-config.d.ts +19 -12
  31. package/dist/config/config-diagnostic.d.ts +11 -4
  32. package/dist/config/config-layer.d.ts +15 -6
  33. package/dist/config/config.resolver.d.ts +74 -31
  34. package/dist/config/config.resolver.js +108 -44
  35. package/dist/config/config.validator.d.ts +7 -7
  36. package/dist/config/config.validator.js +581 -72
  37. package/dist/config/define-resource.d.ts +57 -0
  38. package/dist/config/define-resource.js +14 -0
  39. package/dist/config/effective-fields.d.ts +19 -23
  40. package/dist/config/entrypoint.normalizer.d.ts +1 -1
  41. package/dist/config/exact-framework-config.d.ts +280 -0
  42. package/dist/config/field-compute.resolver.d.ts +19 -0
  43. package/dist/config/field-compute.resolver.js +115 -0
  44. package/dist/config/field-pipeline-config.d.ts +47 -0
  45. package/dist/config/forced-operation.validator.d.ts +10 -0
  46. package/dist/config/forced-operation.validator.js +66 -0
  47. package/dist/config/framework-config.d.ts +110 -39
  48. package/dist/config/framework-exemptions-config.d.ts +91 -0
  49. package/dist/config/framework-exemptions-config.js +1 -0
  50. package/dist/config/framework-field-definition.d.ts +78 -0
  51. package/dist/config/framework-field-definition.js +28 -0
  52. package/dist/config/framework-resources-config.d.ts +116 -0
  53. package/dist/config/framework-resources-config.js +1 -0
  54. package/dist/config/pipeline-config.d.ts +56 -20
  55. package/dist/config/pipeline-tree.resolver.d.ts +79 -0
  56. package/dist/config/pipeline-tree.resolver.js +220 -0
  57. package/dist/config/stage-type.eraser.d.ts +65 -0
  58. package/dist/config/stage-type.eraser.js +1 -0
  59. package/dist/contracts/capability.d.ts +11 -11
  60. package/dist/contracts/client-contract-structure.validator.d.ts +323 -28
  61. package/dist/contracts/client-contract-structure.validator.js +152 -8
  62. package/dist/contracts/contract-canonicalizer.d.ts +19 -3
  63. package/dist/contracts/contract-canonicalizer.js +141 -28
  64. package/dist/contracts/contract-hash.d.ts +12 -7
  65. package/dist/contracts/contract-hash.js +3 -2
  66. package/dist/contracts/contract-limits.d.ts +4 -1
  67. package/dist/contracts/contract-limits.js +1 -0
  68. package/dist/contracts/contract-lookup.d.ts +5 -5
  69. package/dist/contracts/contract-protocol.d.ts +4 -4
  70. package/dist/contracts/contract.d.ts +24 -16
  71. package/dist/contracts/create-requirements.d.ts +35 -0
  72. package/dist/contracts/create-requirements.js +1 -0
  73. package/dist/contracts/enum-definition.d.ts +1 -1
  74. package/dist/contracts/field-check.d.ts +101 -0
  75. package/dist/contracts/field-check.js +1 -0
  76. package/dist/contracts/field.d.ts +52 -42
  77. package/dist/contracts/identifier.d.ts +4 -4
  78. package/dist/contracts/json-shape.d.ts +12 -1
  79. package/dist/contracts/lifecycle-trait.d.ts +2 -2
  80. package/dist/contracts/resource-operations.d.ts +28 -28
  81. package/dist/contracts/resource.d.ts +15 -9
  82. package/dist/contracts/scalar-value-type.d.ts +15 -15
  83. package/dist/contracts/scalar.d.ts +3 -3
  84. package/dist/contracts/transaction-capability.d.ts +1 -1
  85. package/dist/contracts/wire-scalar-format.d.ts +4 -4
  86. package/dist/framework/contract-view.d.ts +213 -147
  87. package/dist/framework/framework-construction.error.d.ts +10 -10
  88. package/dist/framework/framework-construction.error.js +2 -2
  89. package/dist/framework/framework.d.ts +47 -23
  90. package/dist/framework/framework.factory.d.ts +8 -6
  91. package/dist/framework/framework.factory.js +40 -20
  92. package/dist/framework/operation-facade.d.ts +123 -52
  93. package/dist/framework/operation-facade.js +9 -1
  94. package/dist/index.d.ts +55 -50
  95. package/dist/index.js +6 -6
  96. package/dist/internal.d.ts +15 -10
  97. package/dist/internal.js +3 -1
  98. package/dist/operations/operation-arguments.d.ts +267 -202
  99. package/dist/operations/operation-call.d.ts +27 -28
  100. package/dist/operations/operation-identity.d.ts +10 -10
  101. package/dist/operations/operation-result.d.ts +21 -21
  102. package/dist/operations/operation-validator-core.d.ts +6 -6
  103. package/dist/operations/operation-validator-core.js +13 -2
  104. package/dist/operations/operation-validator.d.ts +9 -9
  105. package/dist/operations/projection-scope.resolver.d.ts +6 -6
  106. package/dist/operations/structural-limits.walker.d.ts +6 -6
  107. package/dist/operations/structural-limits.walker.js +145 -0
  108. package/dist/operations/validation-code.d.ts +11 -6
  109. package/dist/operations/validation-code.js +4 -0
  110. package/dist/operations/write-scope.resolver.d.ts +6 -6
  111. package/dist/protocol/absent-route.responder.d.ts +13 -12
  112. package/dist/protocol/absent-route.responder.js +19 -19
  113. package/dist/protocol/contract-document.responder.d.ts +3 -3
  114. package/dist/protocol/contract-document.responder.js +2 -2
  115. package/dist/protocol/http-request.decoder.d.ts +17 -13
  116. package/dist/protocol/http-request.decoder.js +10 -10
  117. package/dist/protocol/http-request.reader.d.ts +3 -3
  118. package/dist/protocol/http-response.encoder.d.ts +4 -4
  119. package/dist/protocol/http-response.encoder.js +94 -55
  120. package/dist/protocol/http-status.table.d.ts +2 -2
  121. package/dist/protocol/operation-response.guard.d.ts +2 -2
  122. package/dist/protocol/protocol-surface.d.ts +4 -4
  123. package/dist/protocol/protocol.binder.d.ts +50 -27
  124. package/dist/protocol/protocol.binder.js +12 -9
  125. package/dist/protocol/protocol.handler.d.ts +22 -13
  126. package/dist/protocol/protocol.handler.js +44 -9
  127. package/dist/protocol/unmounted-route.error.d.ts +4 -4
  128. package/dist/protocol/unmounted-route.error.js +2 -2
  129. package/dist/runtime/caller-data.copier.d.ts +5 -5
  130. package/dist/runtime/caller-data.copier.js +13 -13
  131. package/dist/runtime/caller-data.door.d.ts +6 -6
  132. package/dist/runtime/caller-data.door.js +6 -4
  133. package/dist/runtime/computed-read-runtime.d.ts +7 -6
  134. package/dist/runtime/computed-read-runtime.js +61 -48
  135. package/dist/runtime/computed-value.error.d.ts +6 -6
  136. package/dist/runtime/computed-value.error.js +3 -3
  137. package/dist/runtime/context-executor.runtime.d.ts +59 -0
  138. package/dist/runtime/context-executor.runtime.js +275 -0
  139. package/dist/runtime/create-requirement.d.ts +10 -81
  140. package/dist/runtime/create-requirement.js +80 -57
  141. package/dist/runtime/decimal.d.ts +2 -2
  142. package/dist/runtime/decimal.js +1 -1
  143. package/dist/runtime/diagnostics-reporter.d.ts +53 -27
  144. package/dist/runtime/diagnostics-reporter.js +24 -0
  145. package/dist/runtime/error-boundary.d.ts +65 -8
  146. package/dist/runtime/error-boundary.js +45 -19
  147. package/dist/runtime/execution-options.d.ts +10 -2
  148. package/dist/runtime/field-check.evaluator.d.ts +29 -0
  149. package/dist/runtime/field-check.evaluator.js +521 -0
  150. package/dist/runtime/field-compute.d.ts +64 -0
  151. package/dist/runtime/field-compute.js +1 -0
  152. package/dist/runtime/field-stage.plan.d.ts +15 -0
  153. package/dist/runtime/field-stage.plan.js +27 -0
  154. package/dist/runtime/field-stage.runtime.d.ts +35 -0
  155. package/dist/runtime/field-stage.runtime.js +143 -0
  156. package/dist/runtime/field-validator.runtime.d.ts +11 -0
  157. package/dist/runtime/field-validator.runtime.js +87 -0
  158. package/dist/runtime/framework-error-class.table.d.ts +33 -0
  159. package/dist/runtime/framework-error-class.table.js +25 -0
  160. package/dist/runtime/framework-error.d.ts +68 -8
  161. package/dist/runtime/framework-error.factory.d.ts +4 -0
  162. package/dist/runtime/framework-error.factory.js +15 -0
  163. package/dist/runtime/framework-error.js +23 -2
  164. package/dist/runtime/interceptor-next.error.d.ts +5 -0
  165. package/dist/runtime/interceptor-next.error.js +6 -0
  166. package/dist/runtime/json-value.d.ts +3 -3
  167. package/dist/runtime/level-lifecycle.runtime.d.ts +25 -0
  168. package/dist/runtime/level-lifecycle.runtime.js +42 -0
  169. package/dist/runtime/misuse-reporter.d.ts +12 -12
  170. package/dist/runtime/mutation-planner.d.ts +19 -10
  171. package/dist/runtime/mutation-planner.js +54 -30
  172. package/dist/runtime/nested-write.walker.d.ts +32 -0
  173. package/dist/runtime/nested-write.walker.js +73 -0
  174. package/dist/runtime/operation-request.d.ts +33 -6
  175. package/dist/runtime/operation-response.d.ts +17 -17
  176. package/dist/runtime/operation-runtime.d.ts +113 -25
  177. package/dist/runtime/operation-runtime.js +395 -74
  178. package/dist/runtime/outcome-mapper.d.ts +16 -5
  179. package/dist/runtime/outcome-mapper.js +23 -6
  180. package/dist/runtime/output-validator.d.ts +10 -10
  181. package/dist/runtime/output-validator.js +3 -3
  182. package/dist/runtime/owned-execution.registry.d.ts +6 -6
  183. package/dist/runtime/pipe-output.validator.d.ts +33 -18
  184. package/dist/runtime/pipe-output.validator.js +12 -12
  185. package/dist/runtime/pipeline.d.ts +196 -34
  186. package/dist/runtime/readonly-value.d.ts +32 -0
  187. package/dist/runtime/readonly-value.js +141 -0
  188. package/dist/runtime/request-envelope.validator.d.ts +3 -3
  189. package/dist/runtime/request-envelope.validator.js +12 -7
  190. package/dist/runtime/request-id.d.ts +1 -1
  191. package/dist/runtime/request-state.d.ts +14 -0
  192. package/dist/runtime/request-state.js +1 -0
  193. package/dist/runtime/request-state.resolver.d.ts +12 -0
  194. package/dist/runtime/request-state.resolver.js +20 -0
  195. package/dist/runtime/scalar-runtime.d.ts +31 -16
  196. package/dist/runtime/scalar-runtime.js +16 -18
  197. package/dist/transactions/deferred-operation.d.ts +35 -20
  198. package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
  199. package/dist/transactions/operation-arguments-encoder.js +2 -2
  200. package/dist/transactions/sql-statement.d.ts +77 -0
  201. package/dist/transactions/sql-statement.js +47 -0
  202. package/dist/transactions/sql-statement.validator.d.ts +44 -0
  203. package/dist/transactions/sql-statement.validator.js +134 -0
  204. package/dist/transactions/transaction-envelope.d.ts +4 -4
  205. package/dist/transactions/transaction-integrity-error.d.ts +6 -6
  206. package/dist/transactions/transaction-integrity-error.js +5 -2
  207. package/dist/transactions/transaction-plan-assembler.d.ts +21 -11
  208. package/dist/transactions/transaction-plan-assembler.js +148 -34
  209. package/dist/transactions/transaction-plan-validator.d.ts +29 -20
  210. package/dist/transactions/transaction-plan-validator.js +70 -38
  211. package/dist/transactions/transaction-reference-collector.d.ts +5 -5
  212. package/dist/transactions/transaction-reference-resolver.d.ts +19 -2
  213. package/dist/transactions/transaction-reference-resolver.js +26 -14
  214. package/dist/transactions/transaction-reference-validator.d.ts +34 -4
  215. package/dist/transactions/transaction-reference-validator.js +58 -26
  216. package/dist/transactions/transaction-reference.d.ts +13 -13
  217. package/dist/transactions/transaction-request.d.ts +18 -5
  218. package/dist/transactions/transaction-response.d.ts +6 -6
  219. package/dist/transactions/transaction-runtime.d.ts +8 -7
  220. package/dist/transactions/transaction-runtime.js +166 -50
  221. package/dist/transactions/transaction-settlement.runtime.d.ts +51 -0
  222. package/dist/transactions/transaction-settlement.runtime.js +120 -0
  223. package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
  224. package/dist/transactions/transaction-slot-path-error.js +2 -2
  225. package/dist/transactions/transaction-slot-writer.js +2 -2
  226. package/dist/transactions/transaction-stage.runtime.d.ts +81 -0
  227. package/dist/transactions/transaction-stage.runtime.js +123 -0
  228. package/package.json +6 -5
  229. package/src/runtime/field-check.evaluator.ts +720 -0
  230. package/dist/config/define-fields.d.ts +0 -42
  231. package/dist/config/define-fields.js +0 -3
  232. package/dist/config/framework-behaviors-config.d.ts +0 -30
  233. package/dist/config/framework-fields-config.d.ts +0 -42
  234. package/dist/config/framework-restrictions-config.d.ts +0 -142
  235. package/dist/json/avz.d.ts +0 -96
  236. package/dist/runtime/field-behavior.d.ts +0 -48
  237. /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
  238. /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
  239. /package/dist/{json → avz}/index.js +0 -0
  240. /package/dist/{json → avz}/json-shape.registry.js +0 -0
  241. /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
  242. /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
@@ -1,14 +1,14 @@
1
- import type { Contract } from "../contracts/contract.js";
2
- import type { OperationIdentity } from "../operations/operation-identity.js";
3
- import type { ValidationIssue } from "../operations/validation-code.js";
1
+ import type { AvContract } from "../contracts/contract.js";
2
+ import type { AvOperationIdentity } from "../operations/operation-identity.js";
3
+ import type { AvValidationIssue } from "../operations/validation-code.js";
4
4
  import type { ReadProjectionPlan } from "./computed-read-runtime.js";
5
5
  export type OutputValidationResult = {
6
6
  readonly ok: true;
7
7
  } | {
8
8
  readonly ok: false;
9
- readonly issues: readonly ValidationIssue[];
9
+ readonly issues: readonly AvValidationIssue[];
10
10
  };
11
- type OutputOperation = OperationIdentity & {
11
+ type OutputOperation = AvOperationIdentity & {
12
12
  readonly resource: string;
13
13
  };
14
14
  /**
@@ -16,11 +16,11 @@ type OutputOperation = OperationIdentity & {
16
16
  * validation: whose result it was and what the validator found. The caller
17
17
  * receives the generic `A3000` and never this.
18
18
  */
19
- export declare class OutputValidationError extends Error {
20
- readonly issues: readonly ValidationIssue[];
21
- readonly name = "OutputValidationError";
22
- constructor(operation: OutputOperation, issues: readonly ValidationIssue[]);
19
+ export declare class AvOutputValidationError extends Error {
20
+ readonly issues: readonly AvValidationIssue[];
21
+ readonly name = "AvOutputValidationError";
22
+ constructor(operation: OutputOperation, issues: readonly AvValidationIssue[]);
23
23
  }
24
24
  /** Validate final operation output against fixed cardinality and executed projection. */
25
- export declare function validateOperationOutput(contract: Contract, operation: OutputOperation, projection: ReadProjectionPlan | undefined, value: unknown): OutputValidationResult;
25
+ export declare function validateOperationOutput(contract: AvContract, operation: OutputOperation, projection: ReadProjectionPlan | undefined, value: unknown): OutputValidationResult;
26
26
  export {};
@@ -1,5 +1,5 @@
1
1
  import { lookupField, lookupResource } from "../contracts/contract-lookup.js";
2
- import { advertisedReducers } from "../contracts/field.js";
2
+ import { advertisedReducers, } from "../contracts/field.js";
3
3
  import { normalizeScalarFieldValue } from "./scalar-runtime.js";
4
4
  function issue(message, path = ["data"]) {
5
5
  return { ok: false, issues: [{ path, code: "V1001", message }] };
@@ -168,9 +168,9 @@ function validateProjection(contract, operation, projection, value) {
168
168
  ? validateExactRecord(contract, value, projection, ["data"])
169
169
  : { ok: true };
170
170
  }
171
- export class OutputValidationError extends Error {
171
+ export class AvOutputValidationError extends Error {
172
172
  issues;
173
- name = "OutputValidationError";
173
+ name = "AvOutputValidationError";
174
174
  constructor(operation, issues) {
175
175
  const [first] = issues;
176
176
  super(`The result of ${operation.resource}.${operation.family}.${operation.variant} does not satisfy its Contract${first === undefined
@@ -1,11 +1,11 @@
1
- import type { ClientTransactionRequest } from "../transactions/transaction-request.js";
2
- import type { TransactionResponse } from "../transactions/transaction-response.js";
3
- import type { ClientOperationRequest } from "./operation-request.js";
4
- import type { OperationResponse } from "./operation-response.js";
1
+ import type { AgentTransactionRequest, ClientTransactionRequest } from "../transactions/transaction-request.js";
2
+ import type { AvTransactionResponse } from "../transactions/transaction-response.js";
3
+ import type { RemoteOperationRequest } from "./operation-request.js";
4
+ import type { AvOperationResponse } from "./operation-response.js";
5
5
  /** The two entries that run a request the protocol decoded itself, uncopied. */
6
6
  export type OwnedExecution = {
7
- readonly execute: (request: ClientOperationRequest) => Promise<OperationResponse>;
8
- readonly executeTransaction: (request: ClientTransactionRequest) => Promise<TransactionResponse>;
7
+ readonly execute: (request: RemoteOperationRequest) => Promise<AvOperationResponse>;
8
+ readonly executeTransaction: (request: ClientTransactionRequest | AgentTransactionRequest) => Promise<AvTransactionResponse>;
9
9
  };
10
10
  /** Records `framework`'s owned entries; called once, at construction. */
11
11
  export declare function recordOwnedExecution(framework: object, execution: OwnedExecution): void;
@@ -1,7 +1,8 @@
1
- import type { Contract, CoreContract } from "../contracts/contract.js";
2
- import type { OperationIdentity } from "../operations/operation-identity.js";
3
- import type { ValidationIssue } from "../operations/validation-code.js";
4
- import type { OperationFailureResponse } from "./operation-response.js";
1
+ import type { AvContract, AvContractCore } from "../contracts/contract.js";
2
+ import type { AvOperationIdentity } from "../operations/operation-identity.js";
3
+ import type { OperationValidationOptions } from "../operations/operation-validator.js";
4
+ import type { AvValidationIssue } from "../operations/validation-code.js";
5
+ import type { AvOperationFailureResponse } from "./operation-response.js";
5
6
  /**
6
7
  * The check a pipe's output passes before it can reach the Adapter.
7
8
  *
@@ -12,37 +13,51 @@ import type { OperationFailureResponse } from "./operation-response.js";
12
13
  * are held to the **server's** rules — the Core Contract, plus the fields the
13
14
  * active scope itself adds (they are virtual: computed, then stripped before
14
15
  * the Adapter call) — in the values' runtime forms (`bigint`, `Date`,
15
- * `Decimal`, `Uint8Array`), which is what every pipe receives.
16
+ * `AvDecimal`, `Uint8Array`), which is what every pipe receives.
16
17
  *
17
18
  * A refusal is the server's defect, not the caller's: `A3004
18
19
  * PIPE_OUTPUT_INVALID`, a 500 that tells the caller no more than any internal
19
20
  * failure does — {@link PIPE_OUTPUT_FAILURE_MESSAGE}, and the step in a plan.
20
21
  * The pipe, the operation, the first offending field and its V-code go to the
21
- * diagnostics channel only, as a {@link PipeOutputError}: they name server
22
+ * diagnostics channel only, as a {@link AvPipeOutputError}: they name server
22
23
  * internals — a pipe's function name, a field the caller's Contract hides.
23
24
  */
24
25
  /** The one text every `A3004` carries on the wire. */
25
26
  export declare const PIPE_OUTPUT_FAILURE_MESSAGE = "A server pipeline produced invalid arguments.";
26
27
  /** The error the diagnostics channel receives for a refused pipe output. */
27
- export declare class PipeOutputError extends Error {
28
- readonly issues: readonly ValidationIssue[];
29
- readonly name = "PipeOutputError";
30
- constructor(message: string, issues: readonly ValidationIssue[]);
28
+ export declare class AvPipeOutputError extends Error {
29
+ readonly issues: readonly AvValidationIssue[];
30
+ readonly name = "AvPipeOutputError";
31
+ constructor(message: string, issues: readonly AvValidationIssue[]);
31
32
  }
33
+ /** A refused stage output: the `A3004` answer and what diagnostics are told. */
34
+ export type RefusedStageOutput = {
35
+ readonly response: AvOperationFailureResponse;
36
+ readonly error: AvPipeOutputError;
37
+ };
32
38
  /**
33
39
  * `undefined` when the pipe's output passes the server's rules; otherwise the
34
40
  * `A3004` failure, and the error the diagnostics channel is told.
35
41
  */
36
42
  export declare function refusePipeOutput(contracts: {
37
- readonly core: CoreContract;
38
- readonly active: Contract;
39
- }, request: OperationIdentity & {
43
+ readonly core: AvContractCore;
44
+ readonly active: AvContract;
45
+ }, request: AvOperationIdentity & {
40
46
  readonly resource: string;
41
47
  }, args: unknown,
42
48
  /** The pipe that produced `args`, named in the message by its function name. */
43
49
  pipe: unknown,
44
- /** Its position in the effective pipe list (root pipes first). */
45
- index: number): {
46
- readonly response: OperationFailureResponse;
47
- readonly error: PipeOutputError;
48
- } | undefined;
50
+ /** Its position in the effective pipe list (outer levels first). */
51
+ index: number,
52
+ /** A plan step's pipes run before BEGIN, its `$ref` slots unresolved: these admit them. */
53
+ options?: OperationValidationOptions): RefusedStageOutput | undefined;
54
+ /**
55
+ * {@link refusePipeOutput} for any stage that changed the arguments; `subject`
56
+ * names it in the diagnostic (`Field pipes`, `Transaction pipes`).
57
+ */
58
+ export declare function refuseStageOutput(contracts: {
59
+ readonly core: AvContractCore;
60
+ readonly active: AvContract;
61
+ }, request: AvOperationIdentity & {
62
+ readonly resource: string;
63
+ }, args: unknown, subject: string, options?: OperationValidationOptions): RefusedStageOutput | undefined;
@@ -27,15 +27,12 @@ function serverContractFor(core, active) {
27
27
  }
28
28
  return view;
29
29
  }
30
- function serverIssues(contract, request, args) {
31
- const validation = validateOperationArguments(contract, {
32
- ...request,
33
- arguments: args,
34
- });
30
+ function serverIssues(contract, request, args, options) {
31
+ const validation = validateOperationArguments(contract, { ...request, arguments: args }, options);
35
32
  if (!validation.ok) {
36
33
  return validation.issues;
37
34
  }
38
- const normalization = normalizeOperationScalarValues(contract, { ...request, arguments: validation.arguments }, "application");
35
+ const normalization = normalizeOperationScalarValues(contract, { ...request, arguments: validation.arguments }, "application", options);
39
36
  return normalization.ok ? [] : normalization.issues;
40
37
  }
41
38
  function pipeLabel(pipe, index) {
@@ -55,25 +52,28 @@ function fieldOf(issue) {
55
52
  const relative = path[0] === "arguments" ? path.slice(1) : path;
56
53
  return relative.length === 0 ? "(arguments)" : relative.join(".");
57
54
  }
58
- export class PipeOutputError extends Error {
55
+ export class AvPipeOutputError extends Error {
59
56
  issues;
60
- name = "PipeOutputError";
57
+ name = "AvPipeOutputError";
61
58
  constructor(message, issues) {
62
59
  super(message);
63
60
  this.issues = issues;
64
61
  }
65
62
  }
66
- export function refusePipeOutput(contracts, request, args, pipe, index) {
67
- const issues = serverIssues(serverContractFor(contracts.core, contracts.active), request, args);
63
+ export function refusePipeOutput(contracts, request, args, pipe, index, options) {
64
+ return refuseStageOutput(contracts, request, args, `Pipe ${pipeLabel(pipe, index)}`, options);
65
+ }
66
+ export function refuseStageOutput(contracts, request, args, subject, options) {
67
+ const issues = serverIssues(serverContractFor(contracts.core, contracts.active), request, args, options);
68
68
  const [first] = issues;
69
69
  if (first === undefined) {
70
70
  return undefined;
71
71
  }
72
- const message = `Pipe ${pipeLabel(pipe, index)} returned arguments for ${request.resource}.${request.family}.${request.variant} that the server contract refuses at "${fieldOf(first)}" (${first.code}: ${first.message})`;
72
+ const message = `${subject} returned arguments for ${request.resource}.${request.family}.${request.variant} that the server contract refuses at "${fieldOf(first)}" (${first.code}: ${first.message})`;
73
73
  return {
74
74
  response: operationFailure("A3004", {
75
75
  message: PIPE_OUTPUT_FAILURE_MESSAGE,
76
76
  }),
77
- error: new PipeOutputError(message, issues),
77
+ error: new AvPipeOutputError(message, issues),
78
78
  };
79
79
  }
@@ -1,54 +1,216 @@
1
- import type { AdapterModel } from "../adapters/adapter-model.js";
2
- import type { RequestOrigin } from "../config/config-layer.js";
3
- import type { FrameworkResourceKey } from "../config/framework-fields-config.js";
4
- import type { Contract } from "../contracts/contract.js";
5
- import type { OperationFamily } from "../operations/operation-identity.js";
6
- import type { FrameworkError } from "./framework-error.js";
1
+ import type { AvAdapterModel } from "../adapters/adapter-model.js";
2
+ import type { AvAdapterSqlValue } from "../adapters/adapter-sql-statement.js";
3
+ import type { AvRequestOrigin } from "../config/config-layer.js";
4
+ import type { AvConfigResourceKey } from "../config/framework-field-definition.js";
5
+ import type { AvContract } from "../contracts/contract.js";
6
+ import type { AvApplicationScalarForms } from "../contracts/scalar-value-type.js";
7
+ import type { AvContractApplicationView } from "../framework/contract-view.js";
8
+ import type { AvContextOperations } from "../framework/operation-facade.js";
9
+ import type { AvOperationArgumentsFor, AvResourceKey } from "../operations/operation-arguments.js";
10
+ import type { AvOperationFamily, AvOperationIdentity } from "../operations/operation-identity.js";
11
+ import type { AvTransactionReference } from "../transactions/transaction-reference.js";
12
+ import type { AvError } from "./framework-error.js";
13
+ import type { AvDeepReadonly, AvDeepReadonlyLeaf } from "./readonly-value.js";
14
+ import type { AvState } from "./request-state.js";
7
15
  /**
8
16
  * What a pipeline is told about the HTTP request a client-origin operation arrived on.
9
17
  */
10
- export type PipelineTransportContext = {
18
+ export type AvTransportContext = {
11
19
  readonly method: "POST";
12
20
  readonly headers: Readonly<Record<string, string>>;
13
21
  };
14
- /** What a pipeline callback is told about the operation it is wrapping. */
15
- export type PipelineContext<M extends AdapterModel = AdapterModel> = {
16
- readonly contract: Contract;
17
- readonly origin: RequestOrigin;
18
- readonly resource: FrameworkResourceKey<M>;
19
- readonly family: OperationFamily;
20
- readonly variant: string;
21
- readonly args: unknown;
22
- readonly requestId: string;
23
- readonly transport?: PipelineTransportContext;
22
+ /** What a pipeline ctx states about the request, whatever the stage. */
23
+ type AvContextFacts = {
24
+ /** `"application"` for server code and ctx calls, `"client"` for a remote caller. */
25
+ readonly $origin: AvRequestOrigin;
26
+ readonly $requestId: string;
27
+ /** The HTTP request a client-origin operation arrived on, when it did. */
28
+ readonly $transport?: AvTransportContext;
29
+ /** The active Contract: the Application or the Client Contract. */
30
+ readonly $contract: AvContract;
31
+ /**
32
+ * The request's state: the one writable per-request space. Every stage of the
33
+ * request, a transaction's steps and transaction stages, and the ctx calls they
34
+ * make share this object. Seeded by the caller or the host; `{}` otherwise. Its
35
+ * members are the application's, declared by augmenting {@link AvState}.
36
+ */
37
+ readonly $state: AvState;
38
+ };
39
+ /**
40
+ * `ctx.$sql`: a developer SQL statement, written only as a tagged template —
41
+ * ``await ctx.$sql<Row>`insert into audit (actor) values (${actorId})` `` — run at
42
+ * once. Every interpolated value is bound as a parameter, never spliced into the
43
+ * text. It runs in the current transaction; outside one, as a plain statement,
44
+ * with no transaction opened around it. Resolves the rows the statement returned.
45
+ */
46
+ export type AvContextSql = <Row = unknown>(strings: TemplateStringsArray, ...values: readonly AvAdapterSqlValue[]) => Promise<Row[]>;
47
+ /**
48
+ * The arguments a variant-level stage is told: the operation's arguments under
49
+ * the model's Application Contract view, in the application forms, a reference
50
+ * position admitting an unresolved `$ref`. `unknown` for a model whose Resource
51
+ * names are not literal.
52
+ */
53
+ export type AvStageArguments<M extends AvAdapterModel, R extends string, F extends AvOperationFamily, V extends string> = string extends R ? unknown : R extends AvResourceKey<AvContractApplicationView<M>> ? AvOperationArgumentsFor<AvContractApplicationView<M>, R, Extract<AvOperationIdentity, {
54
+ readonly family: F;
55
+ readonly variant: V;
56
+ }>, AvApplicationScalarForms, AvApplicationScalarForms> : unknown;
57
+ /**
58
+ * What a pipeline callback is told about the operation it is wrapping, and the
59
+ * framework's executor: `ctx.<Resource>.<family>.<variant>(args)`, `ctx.$sql` and
60
+ * `ctx.$transaction`. Every framework member is `$`-prefixed.
61
+ *
62
+ * A ctx call is raw and application-origin: it runs the Framework Validation
63
+ * Layer, field pipes, field validators and compute, and no developer stage
64
+ * (guards, pipes, hooks, interceptors, filters, field write guards, transaction
65
+ * stages), so a hook's call never re-enters the hook. It joins the current
66
+ * transaction when there is one, and resolves the operation's data or throws an
67
+ * `AvError`.
68
+ */
69
+ export type AvContext<M extends AvAdapterModel = AvAdapterModel, R extends string = AvConfigResourceKey<M>, F extends AvOperationFamily = AvOperationFamily, V extends string = string, A = unknown> = AvContextOperations<M> & AvContextFacts & {
70
+ /**
71
+ * The operation the stage wraps. For a nested write's target `resource` is the
72
+ * target, `family` the family its directive maps to, `variant` is `"one"` and
73
+ * `nested` is `true`.
74
+ */
75
+ readonly $operation: {
76
+ readonly resource: R;
77
+ readonly family: F;
78
+ readonly variant: V;
79
+ readonly nested?: true;
80
+ };
81
+ /**
82
+ * The arguments, deep-frozen: as the caller sent them in a guard, as the pipes
83
+ * returned them in a pipe, and the validated arguments the operation executes in
84
+ * an interceptor, a hook or a filter. Only a pipe changes them, by returning new
85
+ * ones; writing to them throws a `TypeError`. At a variant, typed as that
86
+ * operation's arguments ({@link AvStageArguments}), deep read-only; above it,
87
+ * `unknown`.
88
+ */
89
+ readonly $args: AvDeepReadonly<A>;
90
+ readonly $sql: AvContextSql;
91
+ /**
92
+ * Runs `work` in a transaction, `tx` being this ctx bound to it, and resolves
93
+ * what `work` resolved; a throw rolls it back. Inside an open transaction it
94
+ * opens nothing and joins it.
95
+ */
96
+ $transaction<T>(work: (tx: AvContext<M, R, F, V, A>) => Promise<T>): Promise<T>;
24
97
  };
25
98
  /** Allows or denies an operation; returning `false` answers `A4001`. */
26
- export type Guard<M extends AdapterModel = AdapterModel> = {
27
- guard(context: PipelineContext<M>): boolean | undefined | Promise<boolean | undefined>;
99
+ export type AvGuard<M extends AvAdapterModel = AvAdapterModel, R extends string = AvConfigResourceKey<M>, F extends AvOperationFamily = AvOperationFamily, V extends string = string, A = unknown> = {
100
+ guard(context: AvContext<M, R, F, V, A>): boolean | undefined | Promise<boolean | undefined>;
28
101
  }["guard"];
29
102
  /**
30
- * Transforms the arguments before the operation runs; returning `undefined`
31
- * keeps them as they are.
103
+ * Transforms the arguments before the validators judge them: the only stage
104
+ * that changes them. `args` is deep-frozen, so a pipe returns new arguments;
105
+ * returning `undefined` keeps them as they are. At a variant, `args` and the
106
+ * return are typed as that operation's arguments ({@link AvStageArguments}),
107
+ * `args` deep read-only.
32
108
  */
33
- export type Pipe<M extends AdapterModel = AdapterModel> = {
34
- pipe(args: unknown, context: PipelineContext<M>): unknown | Promise<unknown>;
109
+ export type AvPipe<M extends AvAdapterModel = AvAdapterModel, R extends string = AvConfigResourceKey<M>, F extends AvOperationFamily = AvOperationFamily, V extends string = string, A = unknown> = {
110
+ pipe(args: PipeArguments<A>, context: AvContext<M, R, F, V, A>): PipeResult<PipeArguments<A>>;
35
111
  }["pipe"];
36
- /** Runs just before the operation executes. */
37
- export type BeforeHook<M extends AdapterModel = AdapterModel> = {
38
- before(context: PipelineContext<M>): void | Promise<void>;
112
+ /**
113
+ * A variant pipe's arguments and return: the operation's arguments, deep
114
+ * read-only, each member closed to inference.
115
+ */
116
+ type PipeArguments<T> = T extends AvDeepReadonlyLeaf | AvTransactionReference ? T : T extends object ? {
117
+ readonly [K in keyof T]: NoInfer<PipeArguments<Exclude<T[K], undefined>>>;
118
+ } : T;
119
+ /** What a pipe returns: arguments of type `A`, or `undefined` to keep them. */
120
+ type PipeResult<A> = unknown extends A ? any : // biome-ignore lint/suspicious/noConfusingVoidType: a pipe written as `() => void sideEffect()` keeps the arguments, as `undefined` does
121
+ A | undefined | void | Promise<A | undefined | void>;
122
+ /** Runs just before the operation executes, inside every interceptor; `ctx.$args` is deep-frozen. */
123
+ export type AvBeforeHook<M extends AvAdapterModel = AvAdapterModel, R extends string = AvConfigResourceKey<M>, F extends AvOperationFamily = AvOperationFamily, V extends string = string, A = unknown> = {
124
+ before(context: AvContext<M, R, F, V, A>): void | Promise<void>;
39
125
  }["before"];
40
- /** Runs after the operation succeeds, with its result. */
41
- export type AfterHook<M extends AdapterModel = AdapterModel> = {
42
- after(result: unknown, context: PipelineContext<M>): void | Promise<void>;
126
+ /**
127
+ * Runs after the operation succeeds, with its result, deep-frozen; an
128
+ * interceptor may still answer a different one.
129
+ */
130
+ export type AvAfterHook<M extends AvAdapterModel = AvAdapterModel, R extends string = AvConfigResourceKey<M>, F extends AvOperationFamily = AvOperationFamily, V extends string = string, A = unknown> = {
131
+ after(result: unknown, context: AvContext<M, R, F, V, A>): void | Promise<void>;
43
132
  }["after"];
44
133
  /** Wraps the operation's execution; call `next()` to run it and get its result. */
45
- export type Interceptor<M extends AdapterModel = AdapterModel> = {
46
- intercept(context: PipelineContext<M>, next: () => Promise<unknown>): Promise<unknown>;
134
+ export type AvInterceptor<M extends AvAdapterModel = AvAdapterModel, R extends string = AvConfigResourceKey<M>, F extends AvOperationFamily = AvOperationFamily, V extends string = string, A = unknown> = {
135
+ intercept(context: AvContext<M, R, F, V, A>, next: () => Promise<unknown>): Promise<unknown>;
47
136
  }["intercept"];
48
137
  /**
49
- * Turns a thrown error into a {@link FrameworkError} to answer with; returning
138
+ * Turns a thrown error into a {@link AvError} to answer with; returning
50
139
  * `undefined` passes the error on.
51
140
  */
52
- export type Filter<M extends AdapterModel = AdapterModel> = {
53
- filter(error: unknown, context: PipelineContext<M>): FrameworkError | undefined | Promise<FrameworkError | undefined>;
141
+ export type AvFilter<M extends AvAdapterModel = AvAdapterModel, R extends string = AvConfigResourceKey<M>, F extends AvOperationFamily = AvOperationFamily, V extends string = string, A = unknown> = {
142
+ filter(error: unknown, context: AvContext<M, R, F, V, A>): AvError | undefined | Promise<AvError | undefined>;
143
+ }["filter"];
144
+ /**
145
+ * A pure transform of the value the caller sent for one scalar field: value in,
146
+ * value out, no context. Returning `undefined` keeps the value.
147
+ */
148
+ export type AvFieldPipe = (value: unknown) => unknown | Promise<unknown>;
149
+ /**
150
+ * Write-only admission for one field: refuses the operation when the caller sends
151
+ * the field. Returning `false` answers `A4001`.
152
+ */
153
+ export type AvFieldGuard<M extends AvAdapterModel = AvAdapterModel, R extends string = AvConfigResourceKey<M>> = {
154
+ guard(value: unknown, context: AvContext<M, R, "create" | "update" | "upsert">): boolean | undefined | Promise<boolean | undefined>;
155
+ }["guard"];
156
+ /**
157
+ * One plan step as a transaction stage reads it: an operation step with its
158
+ * `$ref`s unresolved, or a SQL step, which names no Resource.
159
+ */
160
+ export type AvTransactionStep<M extends AvAdapterModel = AvAdapterModel> = {
161
+ readonly resource: AvConfigResourceKey<M>;
162
+ readonly family: AvOperationFamily;
163
+ readonly variant: string;
164
+ readonly args: unknown;
165
+ readonly sql?: never;
166
+ } | {
167
+ readonly sql: {
168
+ readonly strings: readonly string[] | undefined;
169
+ readonly values: readonly unknown[];
170
+ };
171
+ readonly resource?: never;
172
+ readonly family?: never;
173
+ readonly variant?: never;
174
+ readonly args?: never;
175
+ };
176
+ /**
177
+ * What a Resource's transaction stage is told: the plan, not one operation
178
+ * (`$operation` is absent), and the executor, bound to the transaction.
179
+ */
180
+ export type AvTransactionContext<M extends AvAdapterModel = AvAdapterModel> = AvContextOperations<M> & AvContextFacts & {
181
+ /** The plan, in step order, `$ref`s unresolved, deep-frozen. */
182
+ readonly $args: readonly AvTransactionStep<M>[];
183
+ readonly $sql: AvContextSql;
184
+ /** Runs `work` inside this transaction (it opens nothing): `tx` is this ctx. */
185
+ $transaction<T>(work: (tx: AvTransactionContext<M>) => Promise<T>): Promise<T>;
186
+ };
187
+ /** Allows or denies a whole transaction; returning `false` answers `A4001`. */
188
+ export type AvTransactionGuard<M extends AvAdapterModel = AvAdapterModel> = {
189
+ guard(context: AvTransactionContext<M>): boolean | undefined | Promise<boolean | undefined>;
190
+ }["guard"];
191
+ /**
192
+ * Transforms the plan before any step runs; returning `undefined` keeps it. The
193
+ * plan it is given is deep-frozen, so it returns a new one. A
194
+ * returned plan keeps its steps (the same number, each on the same operation,
195
+ * each SQL step as it was); only an operation step's `args` may change.
196
+ */
197
+ export type AvTransactionPipe<M extends AvAdapterModel = AvAdapterModel> = {
198
+ pipe(plan: readonly AvTransactionStep<M>[], context: AvTransactionContext<M>): readonly AvTransactionStep[] | undefined | Promise<readonly AvTransactionStep[] | undefined>;
199
+ }["pipe"];
200
+ /** Runs inside the transaction before its steps. */
201
+ export type AvTransactionBeforeHook<M extends AvAdapterModel = AvAdapterModel> = {
202
+ before(context: AvTransactionContext<M>): void | Promise<void>;
203
+ }["before"];
204
+ /** Runs inside the transaction after its steps, with every step's result, deep-frozen. */
205
+ export type AvTransactionAfterHook<M extends AvAdapterModel = AvAdapterModel> = {
206
+ after(results: unknown, context: AvTransactionContext<M>): void | Promise<void>;
207
+ }["after"];
208
+ /** Wraps the transaction's steps; call `next()` to run them. */
209
+ export type AvTransactionInterceptor<M extends AvAdapterModel = AvAdapterModel> = {
210
+ intercept(context: AvTransactionContext<M>, next: () => Promise<unknown>): Promise<unknown>;
211
+ }["intercept"];
212
+ /** Turns an error thrown inside the transaction into a {@link AvError}. */
213
+ export type AvTransactionFilter<M extends AvAdapterModel = AvAdapterModel> = {
214
+ filter(error: unknown, context: AvTransactionContext<M>): AvError | undefined | Promise<AvError | undefined>;
54
215
  }["filter"];
216
+ export {};
@@ -0,0 +1,32 @@
1
+ import { AvDecimal } from "./decimal.js";
2
+ /** A value `AvDeepReadonly` leaves as it is: a primitive, a function, or a scalar instance. */
3
+ export type AvDeepReadonlyLeaf = string | number | boolean | bigint | symbol | null | undefined | Date | Uint8Array | AvDecimal | ((...args: never[]) => unknown);
4
+ /**
5
+ * `T` with every property, element and nested property read-only: what a stage
6
+ * that only reads is told. Arrays become read-only arrays; a `Date`, a
7
+ * `Uint8Array`, an `AvDecimal` and functions are left as they are.
8
+ */
9
+ export type AvDeepReadonly<T> = T extends AvDeepReadonlyLeaf ? T : T extends object ? {
10
+ readonly [K in keyof T]: AvDeepReadonly<T[K]>;
11
+ } : T;
12
+ /**
13
+ * Freezes `value` in place, every nested plain object and array included, and
14
+ * returns it. Accessor properties are not read. For data the framework owns: the
15
+ * copy taken at the door, a body parsed for this request alone, a pipe's output.
16
+ */
17
+ export declare function deepFreeze<T>(value: T): T;
18
+ /**
19
+ * A deep-frozen copy of `value`'s plain objects and arrays, every `Date` and
20
+ * `Uint8Array` in it copied too, the original left as it is: what a stage that
21
+ * only reads is told — the validated arguments after validation, a result in an
22
+ * after hook — so neither what is written nor the result the caller receives can
23
+ * be changed through it.
24
+ */
25
+ export declare function frozenCopy<T>(value: T): AvDeepReadonly<T>;
26
+ /**
27
+ * A read-only view of `value`: reads see the live value, nested plain objects
28
+ * and arrays as views too, and any write, definition or deletion throws a
29
+ * `TypeError` naming `subject` (one subject per value: the first view's). The
30
+ * value itself stays writable for its owner.
31
+ */
32
+ export declare function readonlyView<T>(value: T, subject: string): AvDeepReadonly<T>;
@@ -0,0 +1,141 @@
1
+ import { AvDecimal } from "./decimal.js";
2
+ function isContainer(value) {
3
+ if (value === null || typeof value !== "object") {
4
+ return false;
5
+ }
6
+ if (Array.isArray(value)) {
7
+ return true;
8
+ }
9
+ if (value instanceof AvDecimal) {
10
+ return false;
11
+ }
12
+ const prototype = Object.getPrototypeOf(value);
13
+ return prototype === Object.prototype || prototype === null;
14
+ }
15
+ const DEEP_FROZEN = new WeakSet();
16
+ export function deepFreeze(value) {
17
+ if (!isContainer(value) || DEEP_FROZEN.has(value)) {
18
+ return value;
19
+ }
20
+ Object.freeze(value);
21
+ DEEP_FROZEN.add(value);
22
+ for (const key of Reflect.ownKeys(value)) {
23
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
24
+ if (descriptor !== undefined && "value" in descriptor) {
25
+ deepFreeze(descriptor.value);
26
+ }
27
+ }
28
+ return value;
29
+ }
30
+ function scalarCopy(value) {
31
+ if (value instanceof Date) {
32
+ return new Date(value.getTime());
33
+ }
34
+ if (value instanceof Uint8Array) {
35
+ return value.slice();
36
+ }
37
+ return undefined;
38
+ }
39
+ export function frozenCopy(value) {
40
+ const copies = new Map();
41
+ const copy = (current) => {
42
+ const scalar = scalarCopy(current);
43
+ if (scalar !== undefined) {
44
+ return scalar;
45
+ }
46
+ if (!isContainer(current)) {
47
+ return current;
48
+ }
49
+ if (copies.has(current)) {
50
+ return copies.get(current);
51
+ }
52
+ copies.set(current, current);
53
+ const entries = [];
54
+ let changed = !DEEP_FROZEN.has(current);
55
+ for (const key of Reflect.ownKeys(current)) {
56
+ const descriptor = Object.getOwnPropertyDescriptor(current, key);
57
+ if (descriptor === undefined ||
58
+ !("value" in descriptor) ||
59
+ (Array.isArray(current) && key === "length")) {
60
+ continue;
61
+ }
62
+ const next = copy(descriptor.value);
63
+ changed ||= next !== descriptor.value;
64
+ entries.push([key, descriptor, next]);
65
+ }
66
+ if (!changed) {
67
+ copies.set(current, current);
68
+ return current;
69
+ }
70
+ const target = Array.isArray(current)
71
+ ? new Array(current.length)
72
+ : Object.create(Object.getPrototypeOf(current));
73
+ for (const [key, descriptor, next] of entries) {
74
+ Object.defineProperty(target, key, {
75
+ value: next,
76
+ enumerable: descriptor.enumerable ?? false,
77
+ writable: true,
78
+ configurable: true,
79
+ });
80
+ }
81
+ const frozen = deepFreeze(target);
82
+ copies.set(current, frozen);
83
+ return frozen;
84
+ };
85
+ return copy(value);
86
+ }
87
+ function readOnlyWrite(subject) {
88
+ return new TypeError(`${subject} is read-only here.`);
89
+ }
90
+ const VIEWS = new WeakMap();
91
+ export function readonlyView(value, subject) {
92
+ if (!isContainer(value)) {
93
+ return value;
94
+ }
95
+ const known = VIEWS.get(value);
96
+ if (known !== undefined) {
97
+ return known;
98
+ }
99
+ const real = value;
100
+ const standIn = Array.isArray(value)
101
+ ? []
102
+ : Object.create(Object.getPrototypeOf(value));
103
+ const refuse = () => {
104
+ throw readOnlyWrite(subject);
105
+ };
106
+ const view = new Proxy(standIn, {
107
+ get: (_target, key) => readonlyView(real[key], subject),
108
+ has: (_target, key) => key in real,
109
+ ownKeys: () => Reflect.ownKeys(real),
110
+ getOwnPropertyDescriptor: (target, key) => {
111
+ const descriptor = Reflect.getOwnPropertyDescriptor(real, key);
112
+ if (descriptor === undefined) {
113
+ return undefined;
114
+ }
115
+ if (Reflect.getOwnPropertyDescriptor(target, key)?.configurable === false) {
116
+ return {
117
+ value: descriptor.value,
118
+ enumerable: false,
119
+ writable: true,
120
+ configurable: false,
121
+ };
122
+ }
123
+ return "value" in descriptor
124
+ ? {
125
+ value: readonlyView(descriptor.value, subject),
126
+ enumerable: descriptor.enumerable ?? false,
127
+ writable: false,
128
+ configurable: true,
129
+ }
130
+ : { ...descriptor, configurable: true };
131
+ },
132
+ getPrototypeOf: () => Object.getPrototypeOf(real),
133
+ set: refuse,
134
+ defineProperty: refuse,
135
+ deleteProperty: refuse,
136
+ setPrototypeOf: refuse,
137
+ preventExtensions: refuse,
138
+ });
139
+ VIEWS.set(value, view);
140
+ return view;
141
+ }
@@ -1,5 +1,5 @@
1
- import type { ValidationIssue } from "../operations/validation-code.js";
1
+ import type { AvValidationIssue } from "../operations/validation-code.js";
2
2
  /** The issues of one malformed operation request envelope; empty when well formed. */
3
- export declare function validateOperationEnvelope(request: unknown): readonly ValidationIssue[];
3
+ export declare function validateOperationEnvelope(request: unknown): readonly AvValidationIssue[];
4
4
  /** The issues of one malformed transaction request envelope; empty when well formed. */
5
- export declare function validateTransactionEnvelope(request: unknown): readonly ValidationIssue[];
5
+ export declare function validateTransactionEnvelope(request: unknown): readonly AvValidationIssue[];