@aventara/core 1.0.0-rc.8 → 1.0.0-rc.9

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 (44) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/ERRORS.md +2 -2
  3. package/README.md +75 -6
  4. package/dist/compiler/contract-compiler-diagnostic.guidance.js +2 -2
  5. package/dist/config/config.resolver.d.ts +2 -0
  6. package/dist/config/config.resolver.js +7 -2
  7. package/dist/config/config.validator.js +36 -12
  8. package/dist/config/exact-framework-config.d.ts +11 -1
  9. package/dist/config/framework-config.d.ts +9 -0
  10. package/dist/contracts/contract-canonicalizer.js +2 -0
  11. package/dist/framework/contract-view.d.ts +9 -1
  12. package/dist/framework/framework-construction.error.js +2 -0
  13. package/dist/framework/framework.d.ts +22 -1
  14. package/dist/framework/framework.factory.js +29 -10
  15. package/dist/framework/operation-facade.d.ts +53 -6
  16. package/dist/index.d.ts +2 -1
  17. package/dist/internal.d.ts +1 -0
  18. package/dist/internal.js +1 -0
  19. package/dist/policy/access-provider.interface.d.ts +36 -0
  20. package/dist/policy/access-provider.interface.js +1 -0
  21. package/dist/policy/access-provider.registry.d.ts +9 -0
  22. package/dist/policy/access-provider.registry.js +10 -0
  23. package/dist/policy/policy-startup.validator.js +10 -10
  24. package/dist/prebuilt/core-version.generated.d.ts +1 -1
  25. package/dist/prebuilt/core-version.generated.js +1 -1
  26. package/dist/prebuilt/prebuilt-inputs.fingerprint.js +16 -1
  27. package/dist/protocol/http-response.encoder.js +2 -2
  28. package/dist/runtime/caller-data.copier.js +3 -4
  29. package/dist/runtime/core-class.brand.d.ts +10 -0
  30. package/dist/runtime/core-class.brand.js +21 -0
  31. package/dist/runtime/decimal.d.ts +14 -0
  32. package/dist/runtime/decimal.js +21 -0
  33. package/dist/runtime/diagnostics-reporter.js +13 -1
  34. package/dist/runtime/framework-error.js +9 -0
  35. package/dist/runtime/readonly-value.d.ts +1 -1
  36. package/dist/runtime/readonly-value.js +2 -2
  37. package/dist/runtime/scalar-runtime.js +4 -5
  38. package/dist/transactions/operation-arguments-encoder.js +8 -3
  39. package/dist/transactions/sql-statement.validator.js +2 -2
  40. package/dist/transactions/transaction-integrity-error.js +2 -0
  41. package/dist/transactions/transaction-plan-assembler.d.ts +9 -2
  42. package/dist/transactions/transaction-plan-assembler.js +17 -2
  43. package/dist/transactions/transaction-slot-path-error.js +2 -0
  44. package/package.json +1 -1
@@ -20,8 +20,8 @@ import type { AvContractApplicationView, ClientContractView } from "./contract-v
20
20
  type OpaqueSurface = {
21
21
  readonly [resource: string]: unknown;
22
22
  };
23
- /** The four typed surfaces of an `AvFramework`, named by the member that holds each. */
24
- type FacadeSurface = "application" | "client" | "appTx" | "clientTx";
23
+ /** The typed surfaces of an `AvFramework`, named by the member that holds each. */
24
+ type FacadeSurface = "application" | "client" | "serverClient" | "appTx" | "clientTx" | "serverClientTx";
25
25
  /** `framework.application.<Resource>.<family>.<variant>` when the variant takes a `select` or `include`. */
26
26
  export type AvApplicationProjectingCall<in out C extends AvContract, in out R extends AvResourceKey<C>, in out I extends AvOperationIdentity> = ProjectingCall<C, R, I, AvOperationArgumentsFor<C, R, I, AvApplicationScalarForms>, AvApplicationScalarForms, AvExecutionOptions>;
27
27
  /** `framework.application.<Resource>.<family>.<variant>` when it does not (the `count` variants). */
@@ -38,13 +38,28 @@ export type AvAppTxPlainCall<in out C extends AvContract, in out R extends AvRes
38
38
  export type AvClientTxProjectingCall<in out C extends AvContract, in out R extends AvResourceKey<C>, in out I extends AvOperationIdentity> = DeferredProjectingCall<C, R, I, DeferredArguments<C, R, I, AvWireScalarForms, AvApplicationScalarForms>, AvApplicationScalarForms, "client">;
39
39
  /** `framework.clientTx.<Resource>.<family>.<variant>` when it does not. */
40
40
  export type AvClientTxPlainCall<in out C extends AvContract, in out R extends AvResourceKey<C>, in out I extends AvOperationIdentity> = DeferredPlainCall<C, R, I, DeferredArguments<C, R, I, AvWireScalarForms, AvApplicationScalarForms>, AvApplicationScalarForms, "client">;
41
+ /**
42
+ * `framework.serverClient.<Resource>.<family>.<variant>` when the variant takes a `select` or `include`:
43
+ * the Client Contract's view, application forms in.
44
+ */
45
+ export type AvServerClientProjectingCall<in out C extends AvContract, in out R extends AvResourceKey<C>, in out I extends AvOperationIdentity> = ProjectingCall<C, R, I, AvOperationArgumentsFor<C, R, I, AvApplicationScalarForms>, AvApplicationScalarForms, AvExecutionOptions>;
46
+ /** `framework.serverClient.<Resource>.<family>.<variant>` when it does not. */
47
+ export type AvServerClientPlainCall<in out C extends AvContract, in out R extends AvResourceKey<C>, in out I extends AvOperationIdentity> = PlainCall<C, R, I, AvOperationArgumentsFor<C, R, I, AvApplicationScalarForms>, AvApplicationScalarForms, AvExecutionOptions>;
48
+ /**
49
+ * `framework.serverClientTx.<Resource>.<family>.<variant>` when the variant takes a `select` or `include`:
50
+ * the Client Contract's view, application forms in, a client-origin handle out.
51
+ */
52
+ export type AvServerClientTxProjectingCall<in out C extends AvContract, in out R extends AvResourceKey<C>, in out I extends AvOperationIdentity> = DeferredProjectingCall<C, R, I, DeferredArguments<C, R, I, AvApplicationScalarForms, AvApplicationScalarForms>, AvApplicationScalarForms, "client">;
53
+ /** `framework.serverClientTx.<Resource>.<family>.<variant>` when it does not. */
54
+ export type AvServerClientTxPlainCall<in out C extends AvContract, in out R extends AvResourceKey<C>, in out I extends AvOperationIdentity> = DeferredPlainCall<C, R, I, DeferredArguments<C, R, I, AvApplicationScalarForms, AvApplicationScalarForms>, AvApplicationScalarForms, "client">;
41
55
  /**
42
56
  * One variant on a surface: a direct call (application or wire forms), or a
43
- * deferred one for a transaction (`appTx`, `clientTx`), projecting when its
44
- * arguments carry a `select` (as `AvOperationCall` and `AvDeferredOperationCall`
45
- * decide it).
57
+ * deferred one for a transaction (`appTx`, `clientTx`, `serverClientTx`),
58
+ * projecting when its arguments carry a `select` (as `AvOperationCall` and
59
+ * `AvDeferredOperationCall` decide it). `serverClient` and `serverClientTx` take
60
+ * the application forms over the Client Contract's view.
46
61
  */
47
- type SurfaceCall<C extends AvContract, R extends AvResourceKey<C>, I extends AvOperationIdentity, S extends FacadeSurface> = S extends "application" ? "select" extends keyof AvOperationArgumentsFor<C, R, I, AvApplicationScalarForms> ? AvApplicationProjectingCall<C, R, I> : AvApplicationPlainCall<C, R, I> : S extends "client" ? "select" extends keyof AvOperationArgumentsFor<C, R, I, AvWireScalarForms> ? AvClientProjectingCall<C, R, I> : AvClientPlainCall<C, R, I> : S extends "appTx" ? "select" extends keyof DeferredArguments<C, R, I, AvApplicationScalarForms, AvApplicationScalarForms> ? AvAppTxProjectingCall<C, R, I> : AvAppTxPlainCall<C, R, I> : "select" extends keyof DeferredArguments<C, R, I, AvWireScalarForms, AvApplicationScalarForms> ? AvClientTxProjectingCall<C, R, I> : AvClientTxPlainCall<C, R, I>;
62
+ type SurfaceCall<C extends AvContract, R extends AvResourceKey<C>, I extends AvOperationIdentity, S extends FacadeSurface> = S extends "application" ? "select" extends keyof AvOperationArgumentsFor<C, R, I, AvApplicationScalarForms> ? AvApplicationProjectingCall<C, R, I> : AvApplicationPlainCall<C, R, I> : S extends "client" ? "select" extends keyof AvOperationArgumentsFor<C, R, I, AvWireScalarForms> ? AvClientProjectingCall<C, R, I> : AvClientPlainCall<C, R, I> : S extends "serverClient" ? "select" extends keyof AvOperationArgumentsFor<C, R, I, AvApplicationScalarForms> ? AvServerClientProjectingCall<C, R, I> : AvServerClientPlainCall<C, R, I> : S extends "appTx" ? "select" extends keyof DeferredArguments<C, R, I, AvApplicationScalarForms, AvApplicationScalarForms> ? AvAppTxProjectingCall<C, R, I> : AvAppTxPlainCall<C, R, I> : S extends "clientTx" ? "select" extends keyof DeferredArguments<C, R, I, AvWireScalarForms, AvApplicationScalarForms> ? AvClientTxProjectingCall<C, R, I> : AvClientTxPlainCall<C, R, I> : "select" extends keyof DeferredArguments<C, R, I, AvApplicationScalarForms, AvApplicationScalarForms> ? AvServerClientTxProjectingCall<C, R, I> : AvServerClientTxPlainCall<C, R, I>;
48
63
  /** The families view `C` advertises on Resource `R`. */
49
64
  type FamilyKey<C extends AvContract, R extends AvResourceKey<C>> = keyof AvOperationGrammar<C>[R];
50
65
  /** One family node of surface `S`; the public names below are its four instances. */
@@ -55,10 +70,14 @@ type FamilyNode<C extends AvContract, S extends FacadeSurface, R extends AvResou
55
70
  export type AvApplicationFamilyFacade<in out C extends AvContract, in out R extends AvResourceKey<C>, in out F extends FamilyKey<C, R>> = FamilyNode<C, "application", R, F>;
56
71
  /** `framework.client.<Resource>.<family>`: one direct call per variant, wire forms. */
57
72
  export type AvClientFamilyFacade<in out C extends AvContract, in out R extends AvResourceKey<C>, in out F extends FamilyKey<C, R>> = FamilyNode<C, "client", R, F>;
73
+ /** `framework.serverClient.<Resource>.<family>`: one direct call per variant, application forms. */
74
+ export type AvServerClientFamilyFacade<in out C extends AvContract, in out R extends AvResourceKey<C>, in out F extends FamilyKey<C, R>> = FamilyNode<C, "serverClient", R, F>;
58
75
  /** `framework.appTx.<Resource>.<family>`: one deferred operation per variant. */
59
76
  export type AvAppTxFamilyFacade<in out C extends AvContract, in out R extends AvResourceKey<C>, in out F extends FamilyKey<C, R>> = FamilyNode<C, "appTx", R, F>;
60
77
  /** `framework.clientTx.<Resource>.<family>`: one deferred operation per variant. */
61
78
  export type AvClientTxFamilyFacade<in out C extends AvContract, in out R extends AvResourceKey<C>, in out F extends FamilyKey<C, R>> = FamilyNode<C, "clientTx", R, F>;
79
+ /** `framework.serverClientTx.<Resource>.<family>`: one deferred operation per variant, application forms. */
80
+ export type AvServerClientTxFamilyFacade<in out C extends AvContract, in out R extends AvResourceKey<C>, in out F extends FamilyKey<C, R>> = FamilyNode<C, "serverClientTx", R, F>;
62
81
  /** `framework.application.<Resource>`: one {@link AvApplicationFamilyFacade} per family. */
63
82
  export type AvApplicationResourceFacade<in out C extends AvContract, in out R extends AvResourceKey<C>> = {
64
83
  readonly [F in FamilyKey<C, R>]: AvApplicationFamilyFacade<C, R, F>;
@@ -67,6 +86,10 @@ export type AvApplicationResourceFacade<in out C extends AvContract, in out R ex
67
86
  export type AvClientResourceFacade<in out C extends AvContract, in out R extends AvResourceKey<C>> = {
68
87
  readonly [F in FamilyKey<C, R>]: AvClientFamilyFacade<C, R, F>;
69
88
  };
89
+ /** `framework.serverClient.<Resource>`: one {@link AvServerClientFamilyFacade} per family. */
90
+ export type AvServerClientResourceFacade<in out C extends AvContract, in out R extends AvResourceKey<C>> = {
91
+ readonly [F in FamilyKey<C, R>]: AvServerClientFamilyFacade<C, R, F>;
92
+ };
70
93
  /** `framework.appTx.<Resource>`: one {@link AvAppTxFamilyFacade} per family. */
71
94
  export type AvAppTxResourceFacade<in out C extends AvContract, in out R extends AvResourceKey<C>> = {
72
95
  readonly [F in FamilyKey<C, R>]: AvAppTxFamilyFacade<C, R, F>;
@@ -75,6 +98,10 @@ export type AvAppTxResourceFacade<in out C extends AvContract, in out R extends
75
98
  export type AvClientTxResourceFacade<in out C extends AvContract, in out R extends AvResourceKey<C>> = {
76
99
  readonly [F in FamilyKey<C, R>]: AvClientTxFamilyFacade<C, R, F>;
77
100
  };
101
+ /** `framework.serverClientTx.<Resource>`: one {@link AvServerClientTxFamilyFacade} per family. */
102
+ export type AvServerClientTxResourceFacade<in out C extends AvContract, in out R extends AvResourceKey<C>> = {
103
+ readonly [F in FamilyKey<C, R>]: AvServerClientTxFamilyFacade<C, R, F>;
104
+ };
78
105
  /**
79
106
  * `framework.application`: one {@link AvApplicationResourceFacade} per Resource
80
107
  * of `C`, the Application Contract's view.
@@ -89,6 +116,13 @@ export type AvApplicationFacade<C extends AvContract> = {
89
116
  export type AvClientFacade<C extends AvContract> = {
90
117
  readonly [R in AvResourceKey<C>]: AvClientResourceFacade<C, R>;
91
118
  };
119
+ /**
120
+ * `framework.serverClient`: one {@link AvServerClientResourceFacade} per Resource
121
+ * of `C`, the Client Contract's view, taking application forms.
122
+ */
123
+ export type AvServerClientFacade<C extends AvContract> = {
124
+ readonly [R in AvResourceKey<C>]: AvServerClientResourceFacade<C, R>;
125
+ };
92
126
  /** `framework.appTx.$sql`: the developer SQL step only an application transaction has. */
93
127
  type ApplicationSqlStep = {
94
128
  /**
@@ -112,18 +146,31 @@ export type AvAppTxFacade<C extends AvContract> = {
112
146
  export type AvClientTxFacade<C extends AvContract> = {
113
147
  readonly [R in AvResourceKey<C>]: AvClientTxResourceFacade<C, R>;
114
148
  };
149
+ /**
150
+ * `framework.serverClientTx`: one {@link AvServerClientTxResourceFacade} per
151
+ * Resource of `C`, the Client Contract's view, taking application forms.
152
+ */
153
+ export type AvServerClientTxFacade<C extends AvContract> = {
154
+ readonly [R in AvResourceKey<C>]: AvServerClientTxResourceFacade<C, R>;
155
+ };
115
156
  type ApplicationSurface<C> = C extends AvContract ? string extends AvResourceKey<C> ? OpaqueSurface : AvApplicationFacade<C> : never;
116
157
  type ClientSurface<C> = C extends AvContract ? string extends AvResourceKey<C> ? OpaqueSurface : AvClientFacade<C> : never;
158
+ type ServerClientSurface<C> = C extends AvContract ? string extends AvResourceKey<C> ? OpaqueSurface : AvServerClientFacade<C> : never;
117
159
  type ApplicationDeferredSurface<C> = C extends AvContract ? string extends AvResourceKey<C> ? OpaqueSurface & ApplicationSqlStep : AvAppTxFacade<C> : never;
118
160
  type ClientDeferredSurface<C> = C extends AvContract ? string extends AvResourceKey<C> ? OpaqueSurface : AvClientTxFacade<C> : never;
161
+ type ServerClientDeferredSurface<C> = C extends AvContract ? string extends AvResourceKey<C> ? OpaqueSurface : AvServerClientTxFacade<C> : never;
119
162
  /** `framework.application`'s type: {@link AvApplicationFacade}, or opaque. */
120
163
  export type ApplicationOperations<M extends AvAdapterModel, Cfg> = ApplicationSurface<AvContractApplicationView<M, Cfg>>;
121
164
  /** `framework.client`'s type: {@link AvClientFacade}, or opaque. */
122
165
  export type ClientOperations<M extends AvAdapterModel, Cfg> = ClientSurface<ClientContractView<M, Cfg>>;
166
+ /** `framework.serverClient`'s type: {@link AvServerClientFacade}, or opaque. */
167
+ export type ServerClientOperations<M extends AvAdapterModel, Cfg> = ServerClientSurface<ClientContractView<M, Cfg>>;
123
168
  /** `framework.appTx`'s type: {@link AvAppTxFacade}, or opaque with `$sql`. */
124
169
  export type ApplicationTransactionBuilders<M extends AvAdapterModel, Cfg> = ApplicationDeferredSurface<AvContractApplicationView<M, Cfg>>;
125
170
  /** `framework.clientTx`'s type: {@link AvClientTxFacade}, or opaque. */
126
171
  export type ClientTransactionBuilders<M extends AvAdapterModel, Cfg> = ClientDeferredSurface<ClientContractView<M, Cfg>>;
172
+ /** `framework.serverClientTx`'s type: {@link AvServerClientTxFacade}, or opaque. */
173
+ export type ServerClientTransactionBuilders<M extends AvAdapterModel, Cfg> = ServerClientDeferredSurface<ClientContractView<M, Cfg>>;
127
174
  /**
128
175
  * The Resources of a pipeline ctx: `ctx.<Resource>.<family>.<variant>(args)`,
129
176
  * application-origin, resolving the operation's data.
package/dist/index.d.ts CHANGED
@@ -32,12 +32,13 @@ export { createFramework } from "./framework/framework.factory.js";
32
32
  export type { AvFramework } from "./framework/framework.js";
33
33
  export type { AvConstructionDiagnostic, AvConstructionStage, } from "./framework/framework-construction.error.js";
34
34
  export { AvConstructionError } from "./framework/framework-construction.error.js";
35
- export type { AvApplicationFacade, AvApplicationFamilyFacade, AvApplicationPlainCall, AvApplicationProjectingCall, AvApplicationResourceFacade, AvAppTxFacade, AvAppTxFamilyFacade, AvAppTxPlainCall, AvAppTxProjectingCall, AvAppTxResourceFacade, AvClientFacade, AvClientFamilyFacade, AvClientPlainCall, AvClientProjectingCall, AvClientResourceFacade, AvClientTxFacade, AvClientTxFamilyFacade, AvClientTxPlainCall, AvClientTxProjectingCall, AvClientTxResourceFacade, } from "./framework/operation-facade.js";
35
+ export type { AvApplicationFacade, AvApplicationFamilyFacade, AvApplicationPlainCall, AvApplicationProjectingCall, AvApplicationResourceFacade, AvAppTxFacade, AvAppTxFamilyFacade, AvAppTxPlainCall, AvAppTxProjectingCall, AvAppTxResourceFacade, AvClientFacade, AvClientFamilyFacade, AvClientPlainCall, AvClientProjectingCall, AvClientResourceFacade, AvClientTxFacade, AvClientTxFamilyFacade, AvClientTxPlainCall, AvClientTxProjectingCall, AvClientTxResourceFacade, AvServerClientFacade, AvServerClientFamilyFacade, AvServerClientPlainCall, AvServerClientProjectingCall, AvServerClientResourceFacade, AvServerClientTxFacade, AvServerClientTxFamilyFacade, AvServerClientTxPlainCall, AvServerClientTxProjectingCall, AvServerClientTxResourceFacade, } from "./framework/operation-facade.js";
36
36
  export type { AvCreateDataInput, AvCursorInput, AvFieldKey, AvIncludeInput, AvNoAdvertisedMember, AvNullsOrder, AvOperationArgumentMap, AvOperationArgumentsFor, AvOrderByEntry, AvOrderByInput, AvProjectionEntry, AvRelationProjectionInput, AvResourceKey, AvScalarFilterOperands, AvScalarOrderInput, AvScalarWhereInput, AvSelectInput, AvSortDirection, AvUniqueWhereInput, AvUpdateDataInput, AvWhereInput, } from "./operations/operation-arguments.js";
37
37
  export type { AvDeferredOperationCall, AvOperationCall, AvOperationGrammar, AvOperationSlot, } from "./operations/operation-call.js";
38
38
  export type { AvOperationFamily, AvOperationIdentity, AvOperationVariant, } from "./operations/operation-identity.js";
39
39
  export type { AvOperationResultFor } from "./operations/operation-result.js";
40
40
  export type { AvValidationCode, AvValidationIssue, } from "./operations/validation-code.js";
41
+ export type { AvAccessProvider } from "./policy/access-provider.interface.js";
41
42
  export type { AvPolicyEngine, AvPolicyWhere, } from "./policy/policy-engine.js";
42
43
  export type { AvPrebuiltContracts } from "./prebuilt/prebuilt-contracts.js";
43
44
  export { AvDecimal } from "./runtime/decimal.js";
@@ -32,6 +32,7 @@ export type { AvDatabaseRefusal } from "./operations/database-refusal.js";
32
32
  export { DATABASE_REFUSALS } from "./operations/database-refusal.js";
33
33
  export type { SemanticOperationArguments } from "./operations/operation-validator.js";
34
34
  export { VALIDATION_CODES } from "./operations/validation-code.js";
35
+ export { accessStateOf } from "./policy/access-provider.registry.js";
35
36
  export { prebuiltFileChanges } from "./prebuilt/prebuilt-changes.js";
36
37
  export { emitPrebuiltContracts, prebuiltContractsOf, } from "./prebuilt/prebuilt-contracts.emitter.js";
37
38
  export { mcpFailureReporterOf } from "./runtime/diagnostics-reporter.js";
package/dist/internal.js CHANGED
@@ -13,6 +13,7 @@ export { BUILT_IN_SCALARS } from "./contracts/scalar.js";
13
13
  export { TRANSACTION_CAPABILITIES } from "./contracts/transaction-capability.js";
14
14
  export { DATABASE_REFUSALS } from "./operations/database-refusal.js";
15
15
  export { VALIDATION_CODES } from "./operations/validation-code.js";
16
+ export { accessStateOf } from "./policy/access-provider.registry.js";
16
17
  export { prebuiltFileChanges } from "./prebuilt/prebuilt-changes.js";
17
18
  export { emitPrebuiltContracts, prebuiltContractsOf, } from "./prebuilt/prebuilt-contracts.emitter.js";
18
19
  export { mcpFailureReporterOf } from "./runtime/diagnostics-reporter.js";
@@ -0,0 +1,36 @@
1
+ import type { AvState } from "../runtime/request-state.js";
2
+ import type { AvPolicyEngine } from "./policy-engine.js";
3
+ /**
4
+ * What the framework's `access` option takes: the policy engine every client
5
+ * and agent request is checked against, and how a request's state is seeded.
6
+ * Aventara Access provides one; one written by hand works the same way.
7
+ *
8
+ * The request's principal is `ctx.$state.me` (`null` when it is absent), so
9
+ * `state` names it as `me`. With `access`, the configuration states no
10
+ * `policy`, and the host no `state` of its own.
11
+ */
12
+ export interface AvAccessProvider {
13
+ /** The policy engine (`AvPolicyEngine`), asked about every client and agent request. */
14
+ readonly policy: AvPolicyEngine;
15
+ /**
16
+ * Seeds a request's `ctx.$state` from its headers (a Web `Headers`): `me`, the principal the
17
+ * policy is asked about (`null` for an anonymous caller), and anything else
18
+ * the stages read. Called once per request by the host. `request` is the
19
+ * host's own request when it has one: Express's `req`, Fastify's
20
+ * `request`, or the Next.js route handler's `Request`. A throw is answered
21
+ * like any developer failure: a thrown `AvError` as its own outcome,
22
+ * anything else as an internal failure.
23
+ */
24
+ state(input: {
25
+ readonly headers: {
26
+ get(name: string): string | null;
27
+ has(name: string): boolean;
28
+ forEach(callback: (value: string, name: string) => void): void;
29
+ };
30
+ readonly request?: unknown;
31
+ }): (AvState & {
32
+ readonly me: unknown;
33
+ }) | Promise<AvState & {
34
+ readonly me: unknown;
35
+ }>;
36
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { AvAccessProvider } from "./access-provider.interface.js";
2
+ /** Records the provider `framework` was configured with; called once, at construction. */
3
+ export declare function recordAccessProvider(framework: object, access: AvAccessProvider | undefined): void;
4
+ /**
5
+ * The `state` of the provider `framework` was configured with (`access`),
6
+ * called on the provider; `undefined` for a Framework without `access`, or a
7
+ * value that is no constructed Framework.
8
+ */
9
+ export declare function accessStateOf(framework: object): AvAccessProvider["state"] | undefined;
@@ -0,0 +1,10 @@
1
+ const ACCESS_PROVIDERS = new WeakMap();
2
+ export function recordAccessProvider(framework, access) {
3
+ if (access !== undefined) {
4
+ ACCESS_PROVIDERS.set(framework, access);
5
+ }
6
+ }
7
+ export function accessStateOf(framework) {
8
+ const access = ACCESS_PROVIDERS.get(framework);
9
+ return access === undefined ? undefined : (input) => access.state(input);
10
+ }
@@ -3,10 +3,10 @@ const TO_MANY_OPERATORS = new Set(["some", "every", "none"]);
3
3
  function invalid(path, message) {
4
4
  return { code: "CONFIG_INVALID_VALUE", path, message };
5
5
  }
6
- function governedDiagnostics(core, governed) {
6
+ function governedDiagnostics(core, { at, governed }) {
7
7
  const diagnostics = [];
8
8
  for (const [resourceName, names] of Object.entries(governed)) {
9
- const path = `policy.engine.governed.${resourceName}`;
9
+ const path = `${at}.governed.${resourceName}`;
10
10
  const resource = lookupResource(core, resourceName);
11
11
  if (resource === undefined) {
12
12
  diagnostics.push(invalid(path, `"${resourceName}" is no Resource of the Core Contract`));
@@ -20,9 +20,9 @@ function governedDiagnostics(core, governed) {
20
20
  }
21
21
  return diagnostics;
22
22
  }
23
- function afterCheckDiagnostics(core, afterChecks) {
23
+ function afterCheckDiagnostics(core, { at, afterChecks }) {
24
24
  return Object.keys(afterChecks).flatMap((resourceName) => {
25
- const path = `policy.engine.afterChecks.${resourceName}`;
25
+ const path = `${at}.afterChecks.${resourceName}`;
26
26
  return lookupResource(core, resourceName) === undefined
27
27
  ? [invalid(path, `"${resourceName}" is no Resource of the Core Contract`)]
28
28
  : [];
@@ -82,10 +82,10 @@ function pathFault(core, path) {
82
82
  }
83
83
  return `the path ends at Resource "${current}", not at a field`;
84
84
  }
85
- function pathDiagnostics(core, paths) {
85
+ function pathDiagnostics(core, policy) {
86
86
  const diagnostics = [];
87
- for (const [rule, list] of Object.entries(paths)) {
88
- const at = `policy.engine.paths.${rule}`;
87
+ for (const [rule, list] of Object.entries(policy.paths)) {
88
+ const at = `${policy.at}.paths.${rule}`;
89
89
  for (const path of list) {
90
90
  const fault = pathFault(core, path);
91
91
  if (fault !== undefined) {
@@ -97,8 +97,8 @@ function pathDiagnostics(core, paths) {
97
97
  }
98
98
  export function policyStartupDiagnostics(core, policy) {
99
99
  return [
100
- ...governedDiagnostics(core, policy.governed),
101
- ...pathDiagnostics(core, policy.paths),
102
- ...afterCheckDiagnostics(core, policy.afterChecks),
100
+ ...governedDiagnostics(core, policy),
101
+ ...pathDiagnostics(core, policy),
102
+ ...afterCheckDiagnostics(core, policy),
103
103
  ];
104
104
  }
@@ -1,2 +1,2 @@
1
1
  /** The version of this `@aventara/core`. */
2
- export declare const CORE_VERSION = "1.0.0-rc.8";
2
+ export declare const CORE_VERSION = "1.0.0-rc.9";
@@ -1 +1 @@
1
- export const CORE_VERSION = "1.0.0-rc.8";
1
+ export const CORE_VERSION = "1.0.0-rc.9";
@@ -126,12 +126,27 @@ function policyInput(policy) {
126
126
  : undefined;
127
127
  return { ...policy, engine: { governed: governed ?? null } };
128
128
  }
129
+ function accessInput(access) {
130
+ if (!isRecord(access)) {
131
+ return access;
132
+ }
133
+ const engine = access.policy;
134
+ const governed = engine !== null && typeof engine === "object"
135
+ ? engine.governed
136
+ : undefined;
137
+ return { policy: { governed: governed ?? null } };
138
+ }
129
139
  function authoredInputs(config) {
130
140
  const authored = config;
131
141
  const root = {};
132
142
  for (const key of Object.keys(authored)) {
133
143
  if (!NOT_INPUTS.has(key)) {
134
- root[key] = key === "policy" ? policyInput(authored[key]) : authored[key];
144
+ root[key] =
145
+ key === "policy"
146
+ ? policyInput(authored[key])
147
+ : key === "access"
148
+ ? accessInput(authored[key])
149
+ : authored[key];
135
150
  }
136
151
  }
137
152
  return root;
@@ -1,5 +1,5 @@
1
1
  import { encodeBase64, WIRE_SCALAR_PATTERNS, } from "../contracts/wire-scalar-format.js";
2
- import { AvDecimal } from "../runtime/decimal.js";
2
+ import { isAvDecimal } from "../runtime/decimal.js";
3
3
  import { SERIALIZATION_FAILURE_MESSAGE } from "../runtime/error-boundary.js";
4
4
  import { operationFailure, } from "../runtime/operation-response.js";
5
5
  import { httpStatus } from "./http-status.table.js";
@@ -161,7 +161,7 @@ function scalarWireText(value) {
161
161
  }
162
162
  return JSON.stringify(wire);
163
163
  }
164
- if (value instanceof AvDecimal) {
164
+ if (isAvDecimal(value)) {
165
165
  return JSON.stringify(value.toString());
166
166
  }
167
167
  if (value instanceof Uint8Array) {
@@ -1,4 +1,4 @@
1
- import { AvDecimal } from "./decimal.js";
1
+ import { AvDecimal, decimalDigitsOf, isAvDecimal } from "./decimal.js";
2
2
  const FAILURE_MESSAGES = {
3
3
  "unreadable-value": "Value could not be read.",
4
4
  "non-plain-value": "Value must be plain data.",
@@ -19,7 +19,6 @@ const NO_POLICY = {};
19
19
  const OBJECT_PROTOTYPE = Object.prototype;
20
20
  const DATE_PROTOTYPE = Date.prototype;
21
21
  const dateValueOf = Date.prototype.getTime;
22
- const decimalValueOf = AvDecimal.prototype.toString;
23
22
  const FAST_WALK_DEPTH = 256;
24
23
  const SLOW_WALK = Symbol("slow walk");
25
24
  class FastWalkFailure {
@@ -33,8 +32,8 @@ function copyValueType(value, prototype) {
33
32
  if (prototype === DATE_PROTOTYPE || value instanceof Date) {
34
33
  return new Date(dateValueOf.call(value));
35
34
  }
36
- if (value instanceof AvDecimal) {
37
- return new AvDecimal(decimalValueOf.call(value));
35
+ if (isAvDecimal(value)) {
36
+ return new AvDecimal(decimalDigitsOf(value));
38
37
  }
39
38
  if (value instanceof Uint8Array) {
40
39
  return new Uint8Array(value);
@@ -0,0 +1,10 @@
1
+ /** The registered symbol every copy of this major brands class `name` with. */
2
+ export declare function coreBrandOf(name: string): symbol;
3
+ /** Whether `value` carries `brand`, wherever it was made: one `in`. */
4
+ export declare function hasCoreBrand(value: unknown, brand: symbol): boolean;
5
+ /**
6
+ * Brands `type`'s prototype as `name` and makes `instanceof type` read the brand.
7
+ * A developer's own subclass of `type` inherits the static `Symbol.hasInstance`, so
8
+ * on any constructor but `type` itself it answers as `instanceof` always does.
9
+ */
10
+ export declare function brandCoreClass(type: abstract new (...args: never[]) => object, name: string): symbol;
@@ -0,0 +1,21 @@
1
+ import { CORE_VERSION } from "../prebuilt/core-version.generated.js";
2
+ const CORE_MAJOR = CORE_VERSION.slice(0, CORE_VERSION.indexOf("."));
3
+ export function coreBrandOf(name) {
4
+ return Symbol.for(`aventara.core.${name}@${CORE_MAJOR}`);
5
+ }
6
+ export function hasCoreBrand(value, brand) {
7
+ return typeof value === "object" && value !== null && brand in value;
8
+ }
9
+ const ordinaryHasInstance = Function.prototype[Symbol.hasInstance];
10
+ export function brandCoreClass(type, name) {
11
+ const brand = coreBrandOf(name);
12
+ Object.defineProperty(type.prototype, brand, { value: true });
13
+ Object.defineProperty(type, Symbol.hasInstance, {
14
+ value: function hasInstance(value) {
15
+ return this === type
16
+ ? hasCoreBrand(value, brand)
17
+ : ordinaryHasInstance.call(this, value);
18
+ },
19
+ });
20
+ return brand;
21
+ }
@@ -12,3 +12,17 @@ export declare class AvDecimal {
12
12
  */
13
13
  toJSON(): string;
14
14
  }
15
+ /**
16
+ * Whether `value` is an `AvDecimal`, made by this copy of core or by another of
17
+ * its major: one `in`, for the hot paths that ask about every value.
18
+ */
19
+ export declare function isAvDecimal(value: unknown): value is AvDecimal;
20
+ /**
21
+ * The digits of `value`, read without running anything the caller could have put
22
+ * on it when this copy made it. Another copy's decimal is read through its own
23
+ * `toString`, which only that copy can answer; what it returns is checked as a
24
+ * decimal string, so the caller's copy keeps the grammar.
25
+ *
26
+ * @throws TypeError when another copy's decimal does not answer a decimal string.
27
+ */
28
+ export declare function decimalDigitsOf(value: AvDecimal): string;
@@ -1,6 +1,11 @@
1
1
  import { WIRE_SCALAR_PATTERNS } from "../contracts/wire-scalar-format.js";
2
+ import { brandCoreClass, hasCoreBrand } from "./core-class.brand.js";
3
+ let ownDigitsOf;
2
4
  export class AvDecimal {
3
5
  #value;
6
+ static {
7
+ ownDigitsOf = (value) => (#value in value ? value.#value : undefined);
8
+ }
4
9
  constructor(value) {
5
10
  if (typeof value !== "string") {
6
11
  throw new TypeError("Decimal value must be a string.");
@@ -17,3 +22,19 @@ export class AvDecimal {
17
22
  return this.#value;
18
23
  }
19
24
  }
25
+ const DECIMAL_BRAND = brandCoreClass(AvDecimal, "AvDecimal");
26
+ export function isAvDecimal(value) {
27
+ return hasCoreBrand(value, DECIMAL_BRAND);
28
+ }
29
+ export function decimalDigitsOf(value) {
30
+ const own = ownDigitsOf(value);
31
+ if (own !== undefined) {
32
+ return own;
33
+ }
34
+ const digits = value.toString();
35
+ if (typeof digits !== "string" ||
36
+ !WIRE_SCALAR_PATTERNS.decimal.test(digits)) {
37
+ throw new TypeError("Decimal value must be a valid decimal string.");
38
+ }
39
+ return digits;
40
+ }
@@ -1,3 +1,4 @@
1
+ import { coreBrandOf } from "./core-class.brand.js";
1
2
  import { internalFailure, } from "./operation-response.js";
2
3
  import { requestIdOf } from "./request-id.js";
3
4
  const IGNORE_DIAGNOSTIC = () => undefined;
@@ -31,7 +32,18 @@ export function createReporter(sink, identity) {
31
32
  }
32
33
  };
33
34
  }
34
- const CONFIGURED_SINKS = new WeakMap();
35
+ const CONFIGURED_SINKS = sharedSinkRegistry();
36
+ function sharedSinkRegistry() {
37
+ const key = coreBrandOf("diagnostics");
38
+ const holder = globalThis;
39
+ const existing = holder[key];
40
+ if (existing instanceof WeakMap) {
41
+ return existing;
42
+ }
43
+ const registry = new WeakMap();
44
+ Object.defineProperty(holder, key, { value: registry });
45
+ return registry;
46
+ }
35
47
  export function mcpFailureReporterOf(framework) {
36
48
  const sink = CONFIGURED_SINKS.get(framework);
37
49
  return (error) => {
@@ -1,3 +1,4 @@
1
+ import { brandCoreClass } from "./core-class.brand.js";
1
2
  export class AvError extends Error {
2
3
  name = "AvError";
3
4
  code;
@@ -30,3 +31,11 @@ export class AvProtocolError extends AvError {
30
31
  export class AvContractMismatchError extends AvError {
31
32
  name = "AvContractMismatchError";
32
33
  }
34
+ brandCoreClass(AvError, "AvError");
35
+ brandCoreClass(AvValidationError, "AvValidationError");
36
+ brandCoreClass(AvNotFoundError, "AvNotFoundError");
37
+ brandCoreClass(AvConflictError, "AvConflictError");
38
+ brandCoreClass(AvAuthError, "AvAuthError");
39
+ brandCoreClass(AvInternalError, "AvInternalError");
40
+ brandCoreClass(AvProtocolError, "AvProtocolError");
41
+ brandCoreClass(AvContractMismatchError, "AvContractMismatchError");
@@ -1,4 +1,4 @@
1
- import { AvDecimal } from "./decimal.js";
1
+ import { type AvDecimal } from "./decimal.js";
2
2
  /** A value `AvDeepReadonly` leaves as it is: a primitive, a function, or a scalar instance. */
3
3
  export type AvDeepReadonlyLeaf = string | number | boolean | bigint | symbol | null | undefined | Date | Uint8Array | AvDecimal | ((...args: never[]) => unknown);
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { AvDecimal } from "./decimal.js";
1
+ import { isAvDecimal } from "./decimal.js";
2
2
  function isContainer(value) {
3
3
  if (value === null || typeof value !== "object") {
4
4
  return false;
@@ -6,7 +6,7 @@ function isContainer(value) {
6
6
  if (Array.isArray(value)) {
7
7
  return true;
8
8
  }
9
- if (value instanceof AvDecimal) {
9
+ if (isAvDecimal(value)) {
10
10
  return false;
11
11
  }
12
12
  const prototype = Object.getPrototypeOf(value);
@@ -4,7 +4,7 @@ import { FILTER_MODES, } from "../contracts/capability.js";
4
4
  import { lookupField, lookupOwn, lookupResource, } from "../contracts/contract-lookup.js";
5
5
  import { decodeBase64, WIRE_SCALAR_PATTERNS, } from "../contracts/wire-scalar-format.js";
6
6
  import { routeTransactionReferenceCandidate, } from "../transactions/transaction-reference.js";
7
- import { AvDecimal } from "./decimal.js";
7
+ import { AvDecimal, isAvDecimal } from "./decimal.js";
8
8
  import { fieldCheckIssues } from "./field-check.evaluator.js";
9
9
  const INT_MIN = -(2 ** 31);
10
10
  const INT_MAX = 2 ** 31 - 1;
@@ -238,10 +238,9 @@ function normalizeScalarAtom(contract, field, value, origin, path, allowNull) {
238
238
  break;
239
239
  case "decimal":
240
240
  if (origin === "application") {
241
- normalized =
242
- value instanceof AvDecimal
243
- ? { ok: true, value }
244
- : { ok: false, issues: [typeIssue(path, "an Aventara Decimal")] };
241
+ normalized = isAvDecimal(value)
242
+ ? { ok: true, value }
243
+ : { ok: false, issues: [typeIssue(path, "an Aventara Decimal")] };
245
244
  }
246
245
  else if (typeof value !== "string") {
247
246
  normalized = {
@@ -1,6 +1,6 @@
1
1
  import { lookupField, lookupResource } from "../contracts/contract-lookup.js";
2
2
  import { encodeBase64 } from "../contracts/wire-scalar-format.js";
3
- import { AvDecimal } from "../runtime/decimal.js";
3
+ import { isAvDecimal } from "../runtime/decimal.js";
4
4
  import { isRelationMutationDirective, RELATION_MUTATION_RECORD_SITES, } from "../runtime/mutation-planner.js";
5
5
  import { isTransactionReferenceCandidate } from "./transaction-reference.js";
6
6
  function isPlainRecord(value) {
@@ -27,9 +27,11 @@ function encodeScalarAtom(field, value) {
27
27
  case "bigint":
28
28
  return typeof value === "bigint" ? value.toString(10) : value;
29
29
  case "decimal":
30
- return value instanceof AvDecimal ? value.toString() : value;
30
+ return isAvDecimal(value) ? value.toString() : value;
31
31
  case "datetime":
32
- return value instanceof Date ? value.toISOString() : value;
32
+ return value instanceof Date && !Number.isNaN(value.getTime())
33
+ ? value.toISOString()
34
+ : value;
33
35
  case "bytes":
34
36
  return value instanceof Uint8Array ? encodeBase64(value) : value;
35
37
  default:
@@ -282,6 +284,9 @@ function isUniqueOperation(operation) {
282
284
  operation.family === "upsert"));
283
285
  }
284
286
  export function encodeOperationArgumentsForWire(contract, operation, args) {
287
+ if (!isPlainRecord(args)) {
288
+ return args;
289
+ }
285
290
  const encoded = cloneRecord(args);
286
291
  if (hasOwnWireProperty(args, "where")) {
287
292
  encoded.where = isUniqueOperation(operation)
@@ -1,7 +1,7 @@
1
1
  import { validationIssue } from "../operations/validation-code.js";
2
2
  import { AvCallerDataError, locateCallerDataError, } from "../runtime/caller-data.copier.js";
3
3
  import { refuseCallerData } from "../runtime/caller-data.door.js";
4
- import { AvDecimal } from "../runtime/decimal.js";
4
+ import { isAvDecimal } from "../runtime/decimal.js";
5
5
  import { planStepPath } from "../runtime/error-boundary.js";
6
6
  import { operationFailure } from "../runtime/operation-response.js";
7
7
  import { mapValidationOutcome } from "../runtime/outcome-mapper.js";
@@ -19,7 +19,7 @@ export function normalizeSqlValue(value, path) {
19
19
  typeof value === "string" ||
20
20
  typeof value === "boolean" ||
21
21
  typeof value === "bigint" ||
22
- value instanceof AvDecimal ||
22
+ isAvDecimal(value) ||
23
23
  value instanceof Uint8Array) {
24
24
  return { ok: true, value };
25
25
  }
@@ -1,3 +1,4 @@
1
+ import { brandCoreClass } from "../runtime/core-class.brand.js";
1
2
  const TRANSACTION_INTEGRITY_MESSAGES = {
2
3
  "transaction-unavailable": "Adapter transaction function is unavailable.",
3
4
  "resolved-after-abort": "Adapter transaction resolved after the framework requested rollback.",
@@ -15,3 +16,4 @@ export class AvTransactionIntegrityError extends Error {
15
16
  this.violation = violation;
16
17
  }
17
18
  }
19
+ brandCoreClass(AvTransactionIntegrityError, "AvTransactionIntegrityError");
@@ -9,6 +9,8 @@ import type { PlannedSqlStatement } from "./sql-statement.js";
9
9
  import type { TransactionOperationOrigin } from "./transaction-request.js";
10
10
  /** The origin a handle's builder gives it. */
11
11
  type HandleOrigin = "application" | "client";
12
+ /** The scalar forms a builder takes its arguments in. */
13
+ type ArgumentForms = "wire" | "application";
12
14
  /** One wire node, exactly as the transaction runtime receives it. */
13
15
  type WireOperationNode = {
14
16
  readonly resource: string;
@@ -37,8 +39,13 @@ export type AssembledTransactionPlan = {
37
39
  readonly response: AvOperationFailureResponse;
38
40
  };
39
41
  export type TransactionPlanAssembler = {
40
- /** Defers one operation into a handle; nothing runs. */
41
- defer(origin: HandleOrigin, resource: string, identity: AvOperationIdentity, args: unknown): AvOperation<unknown>;
42
+ /**
43
+ * Defers one operation into a handle; nothing runs. `forms` says which scalar
44
+ * forms a client-origin handle's arguments are in: `"wire"` (`clientTx`, the
45
+ * default) or `"application"` (`serverClientTx`), encoded into the wire forms
46
+ * from the builder's copy.
47
+ */
48
+ defer(origin: HandleOrigin, resource: string, identity: AvOperationIdentity, args: unknown, forms?: ArgumentForms): AvOperation<unknown>;
42
49
  /** Defers one `appTx.$sql` statement into a handle; nothing runs. */
43
50
  deferSql(strings: unknown, values: readonly unknown[]): AvOperation<unknown>;
44
51
  /** Binds a list of handles into the passive plan, or refuses it. */