cvx-kit 0.1.29 → 0.1.31
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/README.md +52 -0
- package/dist/auth.d.mts +29 -11
- package/dist/auth.mjs +1 -1
- package/dist/auth.mjs.map +1 -1
- package/dist/effect.d.mts +5 -1
- package/dist/effect.mjs +1 -1
- package/dist/modules/contracts/binding.d.mts +1 -3
- package/dist/modules/contracts/binding.mjs +1 -1
- package/dist/modules/contracts/binding.mjs.map +1 -1
- package/dist/modules/contracts/domain.d.mts +5 -1
- package/dist/modules/contracts/domain.mjs +1 -1
- package/dist/modules/contracts/domain.mjs.map +1 -1
- package/dist/modules/contracts/errors.d.mts +4 -0
- package/dist/modules/contracts/errors.mjs +1 -1
- package/dist/modules/contracts/errors.mjs.map +1 -1
- package/dist/modules/contracts/lazy.mjs +1 -1
- package/dist/modules/contracts/lazy.mjs.map +1 -1
- package/dist/modules/effect/action.d.mts +64 -0
- package/dist/modules/effect/action.mjs +2 -0
- package/dist/modules/effect/action.mjs.map +1 -0
- package/dist/modules/effect/api-runtime.mjs +1 -1
- package/dist/modules/effect/api-runtime.mjs.map +1 -1
- package/dist/modules/effect/client.d.mts +5 -1
- package/dist/modules/effect/client.mjs +1 -1
- package/dist/modules/effect/command.d.mts +15 -9
- package/dist/modules/effect/command.mjs +1 -1
- package/dist/modules/effect/command.mjs.map +1 -1
- package/dist/modules/effect/crud.d.mts +17 -16
- package/dist/modules/effect/domain.d.mts +19 -8
- package/dist/modules/effect/domain.mjs +1 -1
- package/dist/modules/effect/domain.mjs.map +1 -1
- package/dist/modules/effect/errors.d.mts +5 -1
- package/dist/modules/effect/errors.mjs +1 -1
- package/dist/modules/effect/errors.mjs.map +1 -1
- package/dist/modules/effect/failure-audit.d.mts +48 -0
- package/dist/modules/effect/failure-audit.mjs +2 -0
- package/dist/modules/effect/failure-audit.mjs.map +1 -0
- package/dist/modules/effect/failures.d.mts +22 -0
- package/dist/modules/effect/failures.mjs +2 -0
- package/dist/modules/effect/failures.mjs.map +1 -0
- package/dist/modules/effect/foundation.d.mts +6 -1
- package/dist/modules/effect/foundation.mjs +1 -1
- package/dist/modules/effect/foundation.mjs.map +1 -1
- package/dist/modules/effect/operation.d.mts +10 -2
- package/dist/modules/effect/operation.mjs +1 -1
- package/dist/modules/effect/operation.mjs.map +1 -1
- package/dist/modules/effect/query.d.mts +5 -1
- package/dist/modules/effect/query.mjs +1 -1
- package/dist/modules/effect/query.mjs.map +1 -1
- package/dist/modules/effect/scope.d.mts +27 -0
- package/dist/modules/effect/scope.mjs +2 -0
- package/dist/modules/effect/scope.mjs.map +1 -0
- package/dist/relations.mjs +1 -1
- package/dist/relations.mjs.map +1 -1
- package/dist/zod-registration.mjs +1 -1
- package/dist/zod-registration.mjs.map +1 -1
- package/package.json +2 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ContractSchema, LegacyParser, StandardSchema } from "../contracts/contract.mjs";
|
|
2
2
|
import { Observability } from "../../components/foundation/modules/observability/observability.mjs";
|
|
3
|
+
import { RequestScope } from "./scope.mjs";
|
|
3
4
|
import { CallbackError, CallbackRequirements, CheckedEffectDefinition, EffectMiddlewareInput, EffectOperationArgument, EffectOperationError, EffectOperationRequirements, EffectOperationResult, EffectValue, UnwrappedDefaultError, UnwrappedDefaultRequirements } from "./operation.mjs";
|
|
4
5
|
import { EffectFoundation, EffectFoundationOptions } from "./foundation.mjs";
|
|
5
6
|
import { PaginationOptions, PaginationResult } from "convex/server";
|
|
@@ -159,7 +160,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
|
|
|
159
160
|
result: {
|
|
160
161
|
id: Id<Table>;
|
|
161
162
|
};
|
|
162
|
-
}, context: EffectValue<ContextReturned
|
|
163
|
+
}, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
|
|
163
164
|
operation: `${Table["tableName"]}.create`;
|
|
164
165
|
actorId: string;
|
|
165
166
|
aggregate: {
|
|
@@ -183,7 +184,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
|
|
|
183
184
|
result: {
|
|
184
185
|
id: Id<Table>;
|
|
185
186
|
};
|
|
186
|
-
}, context: EffectValue<ContextReturned
|
|
187
|
+
}, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
|
|
187
188
|
operation: `${Table["tableName"]}.create`;
|
|
188
189
|
actorId: string;
|
|
189
190
|
aggregate: {
|
|
@@ -221,7 +222,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
|
|
|
221
222
|
result: {
|
|
222
223
|
ok: true;
|
|
223
224
|
};
|
|
224
|
-
}, context: EffectValue<ContextReturned
|
|
225
|
+
}, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
|
|
225
226
|
operation: `${Table["tableName"]}.update`;
|
|
226
227
|
actorId: string;
|
|
227
228
|
aggregate: {
|
|
@@ -249,7 +250,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
|
|
|
249
250
|
result: {
|
|
250
251
|
ok: true;
|
|
251
252
|
};
|
|
252
|
-
}, context: EffectValue<ContextReturned
|
|
253
|
+
}, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
|
|
253
254
|
operation: `${Table["tableName"]}.update`;
|
|
254
255
|
actorId: string;
|
|
255
256
|
aggregate: {
|
|
@@ -287,7 +288,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
|
|
|
287
288
|
result: {
|
|
288
289
|
ok: true;
|
|
289
290
|
};
|
|
290
|
-
}, context: EffectValue<ContextReturned
|
|
291
|
+
}, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
|
|
291
292
|
operation: `${Table["tableName"]}.archive`;
|
|
292
293
|
actorId: string;
|
|
293
294
|
aggregate: {
|
|
@@ -315,7 +316,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
|
|
|
315
316
|
result: {
|
|
316
317
|
ok: true;
|
|
317
318
|
};
|
|
318
|
-
}, context: EffectValue<ContextReturned
|
|
319
|
+
}, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
|
|
319
320
|
operation: `${Table["tableName"]}.archive`;
|
|
320
321
|
actorId: string;
|
|
321
322
|
aggregate: {
|
|
@@ -342,7 +343,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
|
|
|
342
343
|
audit?: ((resolution: {
|
|
343
344
|
command: z.infer<Table["tools"]["id"]>;
|
|
344
345
|
result: z.infer<Table["publicDto"]> | null;
|
|
345
|
-
}, context: EffectValue<ContextReturned
|
|
346
|
+
}, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => never) | undefined;
|
|
346
347
|
} & {
|
|
347
348
|
middleware?: ((input: EffectMiddlewareInput<EffectValue<ContextReturned>, z.infer<Table["tools"]["id"]>, z.core.input<Table["publicDto"]> | null, Record<never, never>, CallbackError<CheckId> | CallbackError<Get> | CallbackError<GetGuard> | CallbackError<Policy> | CallbackError<Project> | CallbackError<z.core.input<Table["publicDto"]>>, CallbackRequirements<CheckId> | CallbackRequirements<Get> | CallbackRequirements<GetGuard> | CallbackRequirements<Policy> | CallbackRequirements<Project> | CallbackRequirements<z.core.input<Table["publicDto"]>>>) => never) | undefined;
|
|
348
349
|
} & {
|
|
@@ -442,7 +443,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
|
|
|
442
443
|
pageStatus?: "SplitRecommended" | "SplitRequired" | null | undefined;
|
|
443
444
|
completeness?: "byte-budget" | "complete" | "native-limit" | "result-cap" | "row-budget" | undefined;
|
|
444
445
|
};
|
|
445
|
-
}, context: EffectValue<ContextReturned
|
|
446
|
+
}, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => never) | undefined;
|
|
446
447
|
} & {
|
|
447
448
|
middleware?: ((input: EffectMiddlewareInput<EffectValue<ContextReturned>, {
|
|
448
449
|
numItems: number;
|
|
@@ -498,7 +499,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
|
|
|
498
499
|
result: {
|
|
499
500
|
id: Id<Table>;
|
|
500
501
|
};
|
|
501
|
-
}, context: EffectValue<ContextReturned
|
|
502
|
+
}, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
|
|
502
503
|
operation: `${Table["tableName"]}.create`;
|
|
503
504
|
actorId: string;
|
|
504
505
|
aggregate: {
|
|
@@ -522,7 +523,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
|
|
|
522
523
|
result: {
|
|
523
524
|
id: Id<Table>;
|
|
524
525
|
};
|
|
525
|
-
}, context: EffectValue<ContextReturned
|
|
526
|
+
}, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
|
|
526
527
|
operation: `${Table["tableName"]}.create`;
|
|
527
528
|
actorId: string;
|
|
528
529
|
aggregate: {
|
|
@@ -560,7 +561,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
|
|
|
560
561
|
result: {
|
|
561
562
|
ok: true;
|
|
562
563
|
};
|
|
563
|
-
}, context: EffectValue<ContextReturned
|
|
564
|
+
}, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
|
|
564
565
|
operation: `${Table["tableName"]}.update`;
|
|
565
566
|
actorId: string;
|
|
566
567
|
aggregate: {
|
|
@@ -588,7 +589,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
|
|
|
588
589
|
result: {
|
|
589
590
|
ok: true;
|
|
590
591
|
};
|
|
591
|
-
}, context: EffectValue<ContextReturned
|
|
592
|
+
}, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
|
|
592
593
|
operation: `${Table["tableName"]}.update`;
|
|
593
594
|
actorId: string;
|
|
594
595
|
aggregate: {
|
|
@@ -626,7 +627,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
|
|
|
626
627
|
result: {
|
|
627
628
|
ok: true;
|
|
628
629
|
};
|
|
629
|
-
}, context: EffectValue<ContextReturned
|
|
630
|
+
}, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
|
|
630
631
|
operation: `${Table["tableName"]}.archive`;
|
|
631
632
|
actorId: string;
|
|
632
633
|
aggregate: {
|
|
@@ -654,7 +655,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
|
|
|
654
655
|
result: {
|
|
655
656
|
ok: true;
|
|
656
657
|
};
|
|
657
|
-
}, context: EffectValue<ContextReturned
|
|
658
|
+
}, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
|
|
658
659
|
operation: `${Table["tableName"]}.archive`;
|
|
659
660
|
actorId: string;
|
|
660
661
|
aggregate: {
|
|
@@ -681,7 +682,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
|
|
|
681
682
|
audit?: ((resolution: {
|
|
682
683
|
command: z.infer<Table["tools"]["id"]>;
|
|
683
684
|
result: z.infer<Table["publicDto"]> | null;
|
|
684
|
-
}, context: EffectValue<ContextReturned
|
|
685
|
+
}, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => never) | undefined;
|
|
685
686
|
} & {
|
|
686
687
|
middleware?: ((input: EffectMiddlewareInput<EffectValue<ContextReturned>, z.infer<Table["tools"]["id"]>, z.core.input<Table["publicDto"]> | null, Record<never, never>, CallbackError<CheckId> | CallbackError<Get> | CallbackError<GetGuard> | CallbackError<Policy> | CallbackError<Project> | CallbackError<z.core.input<Table["publicDto"]>>, CallbackRequirements<CheckId> | CallbackRequirements<Get> | CallbackRequirements<GetGuard> | CallbackRequirements<Policy> | CallbackRequirements<Project> | CallbackRequirements<z.core.input<Table["publicDto"]>>>) => never) | undefined;
|
|
687
688
|
} & {
|
|
@@ -781,7 +782,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
|
|
|
781
782
|
pageStatus?: "SplitRecommended" | "SplitRequired" | null | undefined;
|
|
782
783
|
completeness?: "byte-budget" | "complete" | "native-limit" | "result-cap" | "row-budget" | undefined;
|
|
783
784
|
};
|
|
784
|
-
}, context: EffectValue<ContextReturned
|
|
785
|
+
}, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => never) | undefined;
|
|
785
786
|
} & {
|
|
786
787
|
middleware?: ((input: EffectMiddlewareInput<EffectValue<ContextReturned>, {
|
|
787
788
|
numItems: number;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { ContractInput, ContractOutput, ContractSchema } from "../contracts/contract.mjs";
|
|
2
|
+
import { ErrorContract } from "../contracts/errors.mjs";
|
|
2
3
|
import { AuditEntryInput } from "../../components/foundation/client.mjs";
|
|
3
4
|
import { DomainOperationContract, ExactOperationKeys } from "../contracts/domain.mjs";
|
|
5
|
+
import { RequestScope } from "./scope.mjs";
|
|
4
6
|
import { CallbackError, CallbackRequirements, CheckedEffectDefinition, CheckedEffectOperation, EffectPreparation, OperationDefinition, effectOperationFactory } from "./operation.mjs";
|
|
5
7
|
import { DeclaredSchemas } from "../contracts/binding.mjs";
|
|
8
|
+
import { EffectErrors } from "./failures.mjs";
|
|
6
9
|
import { Effect } from "effect";
|
|
7
10
|
//#region src/modules/effect/domain.d.ts
|
|
8
11
|
type Supported<A> = A | PromiseLike<A> | Effect.Effect<A, unknown, unknown>;
|
|
@@ -22,7 +25,7 @@ type Forbidden = {
|
|
|
22
25
|
type AuditCallback<Context, Entry extends DomainOperationContract, Value> = (resolution: {
|
|
23
26
|
command: ContractOutput<Entry['input']>;
|
|
24
27
|
result: ContractOutput<Entry['result']>;
|
|
25
|
-
}, context: Context) => Value;
|
|
28
|
+
}, context: Context, scope: RequestScope | undefined) => Value;
|
|
26
29
|
export type SelectedAudit<Definition, Default> = Definition extends {
|
|
27
30
|
audit: infer Override;
|
|
28
31
|
} ? Override : 'audit' extends keyof Definition ? Exclude<Definition['audit' & keyof Definition], undefined> | Default : Default;
|
|
@@ -30,17 +33,23 @@ export type AuditedOperations<Operations, Default> = { [Key in keyof Operations]
|
|
|
30
33
|
audit: SelectedAudit<Operations[Key], Default>;
|
|
31
34
|
}; };
|
|
32
35
|
export type ExactDomainOperations<Operations, Contracts> = ExactOperationKeys<Operations, Contracts> & { [Key in keyof Operations]: Operations[Key] extends BoundKey<Key> ? Operations[Key] : never; };
|
|
33
|
-
type Helper<Context, Entry extends DomainOperationContract, Key, Command extends boolean, Default, BaseError, BaseRequirements> = <Handler extends Supported<ContractInput<Entry['result']>>, Guard extends Supported<void> = never, Preparation extends Supported<EffectPreparation<ContractOutput<Entry['result']>, unknown, unknown>> = never, const Aggregates extends readonly string[] = readonly string[], AuditReturned extends Supported<Audit> = never, Middleware extends Supported<ContractInput<Entry['result']>> = never, const Metadata extends object = Record<never, never>, const Definition extends object = object>(implementation: Definition & Forbidden & Omit<OperationDefinition<Context, Entry['input'], Entry['result'], Record<never, never>, Aggregates, Handler, Guard, Preparation, AuditReturned, Middleware, Metadata, BaseError, BaseRequirements, ContractSchema, never>, 'input' | 'result' | 'classification' | 'replayResult' | 'wire'> & (Command extends true ? [Default] extends [never] ? {
|
|
36
|
+
type Helper<Context, Entry extends DomainOperationContract, Key, Command extends boolean | 'action', Default, BaseError, BaseRequirements> = <Handler extends Supported<ContractInput<Entry['result']>>, Guard extends Supported<void> = never, Preparation extends Supported<EffectPreparation<ContractOutput<Entry['result']>, unknown, unknown>> = never, const Aggregates extends readonly string[] = readonly string[], AuditReturned extends Supported<Audit> = never, Middleware extends Supported<ContractInput<Entry['result']>> = never, const Metadata extends object = Record<never, never>, const Definition extends object = object>(implementation: Definition & Forbidden & Omit<OperationDefinition<Context, Entry['input'], Entry['result'], Record<never, never>, Aggregates, Handler, Guard, Preparation, AuditReturned, Middleware, Metadata, BaseError, BaseRequirements, ContractSchema, never>, 'input' | 'result' | 'classification' | 'replayResult' | 'wire'> & (Command extends true ? [Default] extends [never] ? {
|
|
34
37
|
audit: AuditCallback<Context, Entry, AuditReturned>;
|
|
35
|
-
} : {} : {
|
|
38
|
+
} : {} : Command extends 'action' ? {
|
|
39
|
+
prepare?: never;
|
|
40
|
+
permission?: never;
|
|
41
|
+
} : {
|
|
36
42
|
audit?: never;
|
|
37
43
|
prepare?: never;
|
|
38
44
|
aggregates?: never;
|
|
39
45
|
})) => DeclaredSchemas<Entry> & CheckedEffectDefinition<Context, Schemas<Entry> & Definition & BoundKey<Key>, BaseError, BaseRequirements>;
|
|
40
|
-
type HandlerArguments<Options, Command extends boolean, Default, RequiredAudit> = Command extends true ? [Default] extends [never] ? [options: Options & RequiredAudit] : [options?: Options] : [options?: Options];
|
|
41
|
-
type HandlerHelper<Context, Entries extends Readonly<Record<string, DomainOperationContract>>, Command extends boolean, Default, BaseError, BaseRequirements> = <const Input extends ContractSchema, const Result extends ContractSchema, Key extends keyof Entries, Handler extends Supported<ContractInput<Result>>, Guard extends Supported<void> = never, Preparation extends Supported<EffectPreparation<ContractOutput<Result>, unknown, unknown>> = never, const Aggregates extends readonly string[] = readonly string[], AuditReturned extends Supported<Audit> = never, Middleware extends Supported<ContractInput<Result>> = never, const Metadata extends object = Record<never, never>, const Definition extends object = object>(handler: (input: ContractOutput<Input>, context: Context) => Handler, ...options: HandlerArguments<Definition & Forbidden & {
|
|
46
|
+
type HandlerArguments<Options, Command extends boolean | 'action', Default, RequiredAudit> = Command extends true ? [Default] extends [never] ? [options: Options & RequiredAudit] : [options?: Options] : [options?: Options];
|
|
47
|
+
type HandlerHelper<Context, Entries extends Readonly<Record<string, DomainOperationContract>>, Command extends boolean | 'action', Default, BaseError, BaseRequirements> = <const Input extends ContractSchema, const Result extends ContractSchema, Key extends keyof Entries, Handler extends Supported<ContractInput<Result>>, Guard extends Supported<void> = never, Preparation extends Supported<EffectPreparation<ContractOutput<Result>, unknown, unknown>> = never, const Aggregates extends readonly string[] = readonly string[], AuditReturned extends Supported<Audit> = never, Middleware extends Supported<ContractInput<Result>> = never, const Metadata extends object = Record<never, never>, const Definition extends object = object>(handler: (input: ContractOutput<Input>, context: Context) => Handler, ...options: HandlerArguments<Definition & Forbidden & {
|
|
42
48
|
handler?: never;
|
|
43
|
-
} & Omit<OperationDefinition<Context, Input, Result, Record<never, never>, Aggregates, Handler, Guard, Preparation, AuditReturned, Middleware, Metadata, BaseError, BaseRequirements, ContractSchema, never>, 'handler' | 'input' | 'result' | 'classification' | 'replayResult' | 'wire'> & (Command extends true ? {} : {
|
|
49
|
+
} & Omit<OperationDefinition<Context, Input, Result, Record<never, never>, Aggregates, Handler, Guard, Preparation, AuditReturned, Middleware, Metadata, BaseError, BaseRequirements, ContractSchema, never>, 'handler' | 'input' | 'result' | 'classification' | 'replayResult' | 'wire'> & (Command extends true ? {} : Command extends 'action' ? {
|
|
50
|
+
prepare?: never;
|
|
51
|
+
permission?: never;
|
|
52
|
+
} : {
|
|
44
53
|
audit?: never;
|
|
45
54
|
prepare?: never;
|
|
46
55
|
aggregates?: never;
|
|
@@ -57,7 +66,7 @@ type HandlerHelper<Context, Entries extends Readonly<Record<string, DomainOperat
|
|
|
57
66
|
} & NoInfer<Definition> & BoundKey<Key> & CheckedEffectDefinition<Context, NoInfer<Definition> & {
|
|
58
67
|
handler: (input: ContractOutput<Input>, context: Context) => Handler;
|
|
59
68
|
} & BoundKey<Key>, BaseError, BaseRequirements>;
|
|
60
|
-
export type DomainEffectFactory<Context, Entries extends Readonly<Record<string, DomainOperationContract>>, Command extends boolean, Default = never, BaseError = never, BaseRequirements = never> = { [Kind in Command extends true ? 'command' : 'query']: { readonly [Key in keyof Entries]: Helper<Context, Entries[Key], Key, Command, Default, BaseError, BaseRequirements>; } & {
|
|
69
|
+
export type DomainEffectFactory<Context, Entries extends Readonly<Record<string, DomainOperationContract>>, Command extends boolean | 'action', Default = never, BaseError = never, BaseRequirements = never, Errors = never> = ContractErrorHelpers<Errors> & { [Kind in Command extends true ? 'command' : Command extends 'action' ? 'action' : 'query']: { readonly [Key in keyof Entries]: Helper<Context, Entries[Key], Key, Command, Default, BaseError, BaseRequirements>; } & {
|
|
61
70
|
handler: HandlerHelper<Context, Entries, Command, Default, BaseError, BaseRequirements>;
|
|
62
71
|
}; };
|
|
63
72
|
export type DomainEffectImplementations<Context, Entries extends Readonly<Record<string, DomainOperationContract>>, Required extends boolean = false> = { [Key in keyof Entries]: DeclaredSchemas<Pick<Entries[Key], 'input' | 'result'>> & BoundKey<Key> & CheckedEffectOperation<Context> & {
|
|
@@ -65,8 +74,10 @@ export type DomainEffectImplementations<Context, Entries extends Readonly<Record
|
|
|
65
74
|
} & (Required extends true ? {
|
|
66
75
|
audit: AuditCallback<Context, Entries[Key], Supported<Audit>>;
|
|
67
76
|
} : {}); };
|
|
68
|
-
export declare function domainEffectFactory<Context, Entries extends Readonly<Record<string, DomainOperationContract>>, Command extends boolean, Default, Guard>(entries: Entries, command: Command): DomainEffectFactory<Context, Entries, Command, Default, CallbackError<Guard>, CallbackRequirements<Guard>>;
|
|
77
|
+
export declare function domainEffectFactory<Context, Entries extends Readonly<Record<string, DomainOperationContract>>, Command extends boolean | 'action', Default, Guard>(entries: Entries, command: Command, errors?: object): DomainEffectFactory<Context, Entries, Command, Default, CallbackError<Guard>, CallbackRequirements<Guard>>;
|
|
69
78
|
export type SharedEffectFactory<Context, Guard> = ReturnType<typeof effectOperationFactory<Context, Record<never, never>, NoInfer<CallbackError<Guard>>, NoInfer<CallbackRequirements<Guard>>, false>>;
|
|
70
79
|
export type AuditValue = Supported<Audit>;
|
|
80
|
+
/** A contract that can create its declared errors also gives the factory `fail` and `attempt`. */
|
|
81
|
+
type ContractErrorHelpers<Errors> = [Errors] extends [never] ? {} : Errors extends ErrorContract<infer Definitions> ? EffectErrors<Definitions> : {};
|
|
71
82
|
//#endregion
|
|
72
83
|
//# sourceMappingURL=domain.d.mts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{domainHelpers as e}from"../contracts/binding.mjs";function
|
|
1
|
+
import{domainHelpers as e}from"../contracts/binding.mjs";import{effectErrors as t}from"./failures.mjs";function n(n,i,a){let o=e(n),s={[i===`action`?`action`:i?`command`:`query`]:o};return a&&r(a)&&Object.assign(s,t(a)),s}function r(e){let t=e;return[t.create,t.project,t.decode].every(e=>e instanceof Function)}export{n as domainEffectFactory};
|
|
2
2
|
//# sourceMappingURL=domain.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain.mjs","names":["domainEffectFactory","helpers","domainHelpers","entries","command"],"sources":["../../../src/modules/effect/domain.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-object-parameters -- Internal helper storage is heterogeneous; the exported mapped signatures validate the schema-paired implementation. */\nimport type { Effect } from 'effect'\nimport type { AuditEntryInput } from '../../components/foundation/client'\nimport type { ContractInput, ContractOutput, ContractSchema } from '../contracts/contract'\nimport type { DomainOperationContract, ExactOperationKeys } from '../contracts/domain'\nimport { domainHelpers, type DeclaredSchemas } from '../contracts/binding'\nimport {\n\teffectOperationFactory,\n\ttype OperationDefinition,\n\ttype CheckedEffectDefinition,\n\ttype CheckedEffectOperation,\n\ttype CallbackError,\n\ttype CallbackRequirements,\n\ttype EffectPreparation,\n} from './operation'\n\ntype Supported<A> = A | PromiseLike<A> | Effect.Effect<A, unknown, unknown>\ntype Audit = Omit<AuditEntryInput, 'classification'> | null\ndeclare const domainKey: unique symbol\ntype BoundKey<Key> = { readonly [domainKey]: Key }\ntype Schemas<Entry extends DomainOperationContract> = Pick<Entry, 'input' | 'result'> &\n\tOmit<Entry, 'input' | 'result'>\ntype Forbidden = {\n\tinput?: never\n\tresult?: never\n\tclassification?: never\n\treplayResult?: never\n\twire?: never\n}\ntype AuditCallback<Context, Entry extends DomainOperationContract, Value> = (\n\tresolution: { command: ContractOutput<Entry['input']>; result: ContractOutput<Entry['result']> },\n\tcontext: Context,\n) => Value\nexport type SelectedAudit<Definition, Default> = Definition extends { audit: infer Override }\n\t? Override\n\t: 'audit' extends keyof Definition\n\t\t? Exclude<Definition['audit' & keyof Definition], undefined> | Default\n\t\t: Default\nexport type AuditedOperations<Operations, Default> = {\n\t[Key in keyof Operations]: Omit<Operations[Key], 'audit'> & {\n\t\taudit: SelectedAudit<Operations[Key], Default>\n\t}\n}\nexport type ExactDomainOperations<Operations, Contracts> = ExactOperationKeys<\n\tOperations,\n\tContracts\n> & {\n\t[Key in keyof Operations]: Operations[Key] extends BoundKey<Key> ? Operations[Key] : never\n}\n\ntype Helper<\n\tContext,\n\tEntry extends DomainOperationContract,\n\tKey,\n\tCommand extends boolean,\n\tDefault,\n\tBaseError,\n\tBaseRequirements,\n> = <\n\tHandler extends Supported<ContractInput<Entry['result']>>,\n\tGuard extends Supported<void> = never,\n\tPreparation extends Supported<\n\t\tEffectPreparation<ContractOutput<Entry['result']>, unknown, unknown>\n\t> = never,\n\tconst Aggregates extends readonly string[] = readonly string[],\n\tAuditReturned extends Supported<Audit> = never,\n\tMiddleware extends Supported<ContractInput<Entry['result']>> = never,\n\tconst Metadata extends object = Record<never, never>,\n\tconst Definition extends object = object,\n>(\n\timplementation: Definition &\n\t\tForbidden &\n\t\tOmit<\n\t\t\tOperationDefinition<\n\t\t\t\tContext,\n\t\t\t\tEntry['input'],\n\t\t\t\tEntry['result'],\n\t\t\t\tRecord<never, never>,\n\t\t\t\tAggregates,\n\t\t\t\tHandler,\n\t\t\t\tGuard,\n\t\t\t\tPreparation,\n\t\t\t\tAuditReturned,\n\t\t\t\tMiddleware,\n\t\t\t\tMetadata,\n\t\t\t\tBaseError,\n\t\t\t\tBaseRequirements,\n\t\t\t\tContractSchema,\n\t\t\t\tnever\n\t\t\t>,\n\t\t\t'input' | 'result' | 'classification' | 'replayResult' | 'wire'\n\t\t> &\n\t\t(Command extends true\n\t\t\t? [Default] extends [never]\n\t\t\t\t? { audit: AuditCallback<Context, Entry, AuditReturned> }\n\t\t\t\t: {}\n\t\t\t: { audit?: never; prepare?: never; aggregates?: never }),\n) => DeclaredSchemas<Entry> &\n\tCheckedEffectDefinition<\n\t\tContext,\n\t\tSchemas<Entry> & Definition & BoundKey<Key>,\n\t\tBaseError,\n\t\tBaseRequirements\n\t>\n\ntype HandlerArguments<\n\tOptions,\n\tCommand extends boolean,\n\tDefault,\n\tRequiredAudit,\n> = Command extends true\n\t? [Default] extends [never]\n\t\t? [options: Options & RequiredAudit]\n\t\t: [options?: Options]\n\t: [options?: Options]\n\ntype HandlerHelper<\n\tContext,\n\tEntries extends Readonly<Record<string, DomainOperationContract>>,\n\tCommand extends boolean,\n\tDefault,\n\tBaseError,\n\tBaseRequirements,\n> = <\n\tconst Input extends ContractSchema,\n\tconst Result extends ContractSchema,\n\tKey extends keyof Entries,\n\tHandler extends Supported<ContractInput<Result>>,\n\tGuard extends Supported<void> = never,\n\tPreparation extends Supported<EffectPreparation<ContractOutput<Result>, unknown, unknown>> =\n\t\tnever,\n\tconst Aggregates extends readonly string[] = readonly string[],\n\tAuditReturned extends Supported<Audit> = never,\n\tMiddleware extends Supported<ContractInput<Result>> = never,\n\tconst Metadata extends object = Record<never, never>,\n\tconst Definition extends object = object,\n>(\n\thandler: (input: ContractOutput<Input>, context: Context) => Handler,\n\t...options: HandlerArguments<\n\t\tDefinition &\n\t\t\tForbidden & { handler?: never } & Omit<\n\t\t\t\tOperationDefinition<\n\t\t\t\t\tContext,\n\t\t\t\t\tInput,\n\t\t\t\t\tResult,\n\t\t\t\t\tRecord<never, never>,\n\t\t\t\t\tAggregates,\n\t\t\t\t\tHandler,\n\t\t\t\t\tGuard,\n\t\t\t\t\tPreparation,\n\t\t\t\t\tAuditReturned,\n\t\t\t\t\tMiddleware,\n\t\t\t\t\tMetadata,\n\t\t\t\t\tBaseError,\n\t\t\t\t\tBaseRequirements,\n\t\t\t\t\tContractSchema,\n\t\t\t\t\tnever\n\t\t\t\t>,\n\t\t\t\t'handler' | 'input' | 'result' | 'classification' | 'replayResult' | 'wire'\n\t\t\t> &\n\t\t\t(Command extends true ? {} : { audit?: never; prepare?: never; aggregates?: never }),\n\t\tCommand,\n\t\tDefault,\n\t\t{ audit: AuditCallback<Context, { input: Input; result: Result }, AuditReturned> }\n\t>\n) => DeclaredSchemas<{ input: Input; result: Result }> & {\n\thandler: (input: ContractOutput<Input>, context: Context) => NoInfer<Handler>\n} & NoInfer<Definition> &\n\tBoundKey<Key> &\n\tCheckedEffectDefinition<\n\t\tContext,\n\t\tNoInfer<Definition> & {\n\t\t\thandler: (input: ContractOutput<Input>, context: Context) => Handler\n\t\t} & BoundKey<Key>,\n\t\tBaseError,\n\t\tBaseRequirements\n\t>\n\nexport type DomainEffectFactory<\n\tContext,\n\tEntries extends Readonly<Record<string, DomainOperationContract>>,\n\tCommand extends boolean,\n\tDefault = never,\n\tBaseError = never,\n\tBaseRequirements = never,\n> = {\n\t[Kind in Command extends true ? 'command' : 'query']: {\n\t\treadonly [Key in keyof Entries]: Helper<\n\t\t\tContext,\n\t\t\tEntries[Key],\n\t\t\tKey,\n\t\t\tCommand,\n\t\t\tDefault,\n\t\t\tBaseError,\n\t\t\tBaseRequirements\n\t\t>\n\t} & { handler: HandlerHelper<Context, Entries, Command, Default, BaseError, BaseRequirements> }\n}\n\nexport type DomainEffectImplementations<\n\tContext,\n\tEntries extends Readonly<Record<string, DomainOperationContract>>,\n\tRequired extends boolean = false,\n> = {\n\t[Key in keyof Entries]: DeclaredSchemas<Pick<Entries[Key], 'input' | 'result'>> &\n\t\tBoundKey<Key> &\n\t\tCheckedEffectOperation<Context> & {\n\t\t\thandler: (\n\t\t\t\tinput: ContractOutput<Entries[Key]['input']>,\n\t\t\t\tcontext: Context,\n\t\t\t) => Supported<ContractInput<Entries[Key]['result']>>\n\t\t} & (Required extends true\n\t\t\t? { audit: AuditCallback<Context, Entries[Key], Supported<Audit>> }\n\t\t\t: {})\n}\n\nexport function domainEffectFactory<\n\tContext,\n\tEntries extends Readonly<Record<string, DomainOperationContract>>,\n\tCommand extends boolean,\n\tDefault,\n\tGuard,\n>(\n\tentries: Entries,\n\tcommand: Command,\n): DomainEffectFactory<\n\tContext,\n\tEntries,\n\tCommand,\n\tDefault,\n\tCallbackError<Guard>,\n\tCallbackRequirements<Guard>\n> {\n\tconst helpers = domainHelpers(entries)\n\t// SAFETY: helper signatures check callbacks; registration pairs drafts with their declarations.\n\treturn { [command ? 'command' : 'query']: helpers } as DomainEffectFactory<\n\t\tContext,\n\t\tEntries,\n\t\tCommand,\n\t\tDefault,\n\t\tCallbackError<Guard>,\n\t\tCallbackRequirements<Guard>\n\t>\n}\n\nexport type SharedEffectFactory<Context, Guard> = ReturnType<\n\ttypeof effectOperationFactory<\n\t\tContext,\n\t\tRecord<never, never>,\n\t\tNoInfer<CallbackError<Guard>>,\n\t\tNoInfer<CallbackRequirements<Guard>>,\n\t\tfalse\n\t>\n>\nexport type AuditValue = Supported<Audit>\n"],"mappings":"yDAwNA,SAAgBA,EAOf,EACA,EAQC,CACD,IAAMC,EAAUC,EAAcC,CAAO,EAErC,MAAO,EAAGC,EAAU,UAAY,SAAUH,CAAQ,CAQnD"}
|
|
1
|
+
{"version":3,"file":"domain.mjs","names":["domainEffectFactory","helpers","domainHelpers","entries","factory","command","errors","isFullErrorContract","effectErrors","candidate","member"],"sources":["../../../src/modules/effect/domain.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-object-parameters -- Internal helper storage is heterogeneous; the exported mapped signatures validate the schema-paired implementation. */\nimport type { Effect } from 'effect'\nimport type { AuditEntryInput } from '../../components/foundation/client'\nimport type { ContractInput, ContractOutput, ContractSchema } from '../contracts/contract'\nimport type { DomainOperationContract, ExactOperationKeys } from '../contracts/domain'\nimport { domainHelpers, type DeclaredSchemas } from '../contracts/binding'\nimport type { ErrorContract, ErrorDefinitions } from '../contracts/errors'\nimport { effectErrors, type EffectErrors } from './failures'\nimport {\n\teffectOperationFactory,\n\ttype OperationDefinition,\n\ttype CheckedEffectDefinition,\n\ttype CheckedEffectOperation,\n\ttype CallbackError,\n\ttype CallbackRequirements,\n\ttype EffectPreparation,\n} from './operation'\nimport type { RequestScope } from './scope'\n\ntype Supported<A> = A | PromiseLike<A> | Effect.Effect<A, unknown, unknown>\ntype Audit = Omit<AuditEntryInput, 'classification'> | null\ndeclare const domainKey: unique symbol\ntype BoundKey<Key> = { readonly [domainKey]: Key }\ntype Schemas<Entry extends DomainOperationContract> = Pick<Entry, 'input' | 'result'> &\n\tOmit<Entry, 'input' | 'result'>\ntype Forbidden = {\n\tinput?: never\n\tresult?: never\n\tclassification?: never\n\treplayResult?: never\n\twire?: never\n}\ntype AuditCallback<Context, Entry extends DomainOperationContract, Value> = (\n\tresolution: { command: ContractOutput<Entry['input']>; result: ContractOutput<Entry['result']> },\n\tcontext: Context,\n\tscope: RequestScope | undefined,\n) => Value\nexport type SelectedAudit<Definition, Default> = Definition extends { audit: infer Override }\n\t? Override\n\t: 'audit' extends keyof Definition\n\t\t? Exclude<Definition['audit' & keyof Definition], undefined> | Default\n\t\t: Default\nexport type AuditedOperations<Operations, Default> = {\n\t[Key in keyof Operations]: Omit<Operations[Key], 'audit'> & {\n\t\taudit: SelectedAudit<Operations[Key], Default>\n\t}\n}\nexport type ExactDomainOperations<Operations, Contracts> = ExactOperationKeys<\n\tOperations,\n\tContracts\n> & {\n\t[Key in keyof Operations]: Operations[Key] extends BoundKey<Key> ? Operations[Key] : never\n}\n\ntype Helper<\n\tContext,\n\tEntry extends DomainOperationContract,\n\tKey,\n\tCommand extends boolean | 'action',\n\tDefault,\n\tBaseError,\n\tBaseRequirements,\n> = <\n\tHandler extends Supported<ContractInput<Entry['result']>>,\n\tGuard extends Supported<void> = never,\n\tPreparation extends Supported<\n\t\tEffectPreparation<ContractOutput<Entry['result']>, unknown, unknown>\n\t> = never,\n\tconst Aggregates extends readonly string[] = readonly string[],\n\tAuditReturned extends Supported<Audit> = never,\n\tMiddleware extends Supported<ContractInput<Entry['result']>> = never,\n\tconst Metadata extends object = Record<never, never>,\n\tconst Definition extends object = object,\n>(\n\timplementation: Definition &\n\t\tForbidden &\n\t\tOmit<\n\t\t\tOperationDefinition<\n\t\t\t\tContext,\n\t\t\t\tEntry['input'],\n\t\t\t\tEntry['result'],\n\t\t\t\tRecord<never, never>,\n\t\t\t\tAggregates,\n\t\t\t\tHandler,\n\t\t\t\tGuard,\n\t\t\t\tPreparation,\n\t\t\t\tAuditReturned,\n\t\t\t\tMiddleware,\n\t\t\t\tMetadata,\n\t\t\t\tBaseError,\n\t\t\t\tBaseRequirements,\n\t\t\t\tContractSchema,\n\t\t\t\tnever\n\t\t\t>,\n\t\t\t'input' | 'result' | 'classification' | 'replayResult' | 'wire'\n\t\t> &\n\t\t(Command extends true\n\t\t\t? [Default] extends [never]\n\t\t\t\t? { audit: AuditCallback<Context, Entry, AuditReturned> }\n\t\t\t\t: {}\n\t\t\t: Command extends 'action'\n\t\t\t\t? { prepare?: never; permission?: never }\n\t\t\t\t: { audit?: never; prepare?: never; aggregates?: never }),\n) => DeclaredSchemas<Entry> &\n\tCheckedEffectDefinition<\n\t\tContext,\n\t\tSchemas<Entry> & Definition & BoundKey<Key>,\n\t\tBaseError,\n\t\tBaseRequirements\n\t>\n\ntype HandlerArguments<\n\tOptions,\n\tCommand extends boolean | 'action',\n\tDefault,\n\tRequiredAudit,\n> = Command extends true\n\t? [Default] extends [never]\n\t\t? [options: Options & RequiredAudit]\n\t\t: [options?: Options]\n\t: [options?: Options]\n\ntype HandlerHelper<\n\tContext,\n\tEntries extends Readonly<Record<string, DomainOperationContract>>,\n\tCommand extends boolean | 'action',\n\tDefault,\n\tBaseError,\n\tBaseRequirements,\n> = <\n\tconst Input extends ContractSchema,\n\tconst Result extends ContractSchema,\n\tKey extends keyof Entries,\n\tHandler extends Supported<ContractInput<Result>>,\n\tGuard extends Supported<void> = never,\n\tPreparation extends Supported<EffectPreparation<ContractOutput<Result>, unknown, unknown>> =\n\t\tnever,\n\tconst Aggregates extends readonly string[] = readonly string[],\n\tAuditReturned extends Supported<Audit> = never,\n\tMiddleware extends Supported<ContractInput<Result>> = never,\n\tconst Metadata extends object = Record<never, never>,\n\tconst Definition extends object = object,\n>(\n\thandler: (input: ContractOutput<Input>, context: Context) => Handler,\n\t...options: HandlerArguments<\n\t\tDefinition &\n\t\t\tForbidden & { handler?: never } & Omit<\n\t\t\t\tOperationDefinition<\n\t\t\t\t\tContext,\n\t\t\t\t\tInput,\n\t\t\t\t\tResult,\n\t\t\t\t\tRecord<never, never>,\n\t\t\t\t\tAggregates,\n\t\t\t\t\tHandler,\n\t\t\t\t\tGuard,\n\t\t\t\t\tPreparation,\n\t\t\t\t\tAuditReturned,\n\t\t\t\t\tMiddleware,\n\t\t\t\t\tMetadata,\n\t\t\t\t\tBaseError,\n\t\t\t\t\tBaseRequirements,\n\t\t\t\t\tContractSchema,\n\t\t\t\t\tnever\n\t\t\t\t>,\n\t\t\t\t'handler' | 'input' | 'result' | 'classification' | 'replayResult' | 'wire'\n\t\t\t> &\n\t\t\t(Command extends true\n\t\t\t\t? {}\n\t\t\t\t: Command extends 'action'\n\t\t\t\t\t? { prepare?: never; permission?: never }\n\t\t\t\t\t: { audit?: never; prepare?: never; aggregates?: never }),\n\t\tCommand,\n\t\tDefault,\n\t\t{ audit: AuditCallback<Context, { input: Input; result: Result }, AuditReturned> }\n\t>\n) => DeclaredSchemas<{ input: Input; result: Result }> & {\n\thandler: (input: ContractOutput<Input>, context: Context) => NoInfer<Handler>\n} & NoInfer<Definition> &\n\tBoundKey<Key> &\n\tCheckedEffectDefinition<\n\t\tContext,\n\t\tNoInfer<Definition> & {\n\t\t\thandler: (input: ContractOutput<Input>, context: Context) => Handler\n\t\t} & BoundKey<Key>,\n\t\tBaseError,\n\t\tBaseRequirements\n\t>\n\nexport type DomainEffectFactory<\n\tContext,\n\tEntries extends Readonly<Record<string, DomainOperationContract>>,\n\tCommand extends boolean | 'action',\n\tDefault = never,\n\tBaseError = never,\n\tBaseRequirements = never,\n\tErrors = never,\n> = ContractErrorHelpers<Errors> & {\n\t[Kind in Command extends true ? 'command' : Command extends 'action' ? 'action' : 'query']: {\n\t\treadonly [Key in keyof Entries]: Helper<\n\t\t\tContext,\n\t\t\tEntries[Key],\n\t\t\tKey,\n\t\t\tCommand,\n\t\t\tDefault,\n\t\t\tBaseError,\n\t\t\tBaseRequirements\n\t\t>\n\t} & { handler: HandlerHelper<Context, Entries, Command, Default, BaseError, BaseRequirements> }\n}\n\nexport type DomainEffectImplementations<\n\tContext,\n\tEntries extends Readonly<Record<string, DomainOperationContract>>,\n\tRequired extends boolean = false,\n> = {\n\t[Key in keyof Entries]: DeclaredSchemas<Pick<Entries[Key], 'input' | 'result'>> &\n\t\tBoundKey<Key> &\n\t\tCheckedEffectOperation<Context> & {\n\t\t\thandler: (\n\t\t\t\tinput: ContractOutput<Entries[Key]['input']>,\n\t\t\t\tcontext: Context,\n\t\t\t) => Supported<ContractInput<Entries[Key]['result']>>\n\t\t} & (Required extends true\n\t\t\t? { audit: AuditCallback<Context, Entries[Key], Supported<Audit>> }\n\t\t\t: {})\n}\n\nexport function domainEffectFactory<\n\tContext,\n\tEntries extends Readonly<Record<string, DomainOperationContract>>,\n\tCommand extends boolean | 'action',\n\tDefault,\n\tGuard,\n>(\n\tentries: Entries,\n\tcommand: Command,\n\terrors?: object,\n): DomainEffectFactory<\n\tContext,\n\tEntries,\n\tCommand,\n\tDefault,\n\tCallbackError<Guard>,\n\tCallbackRequirements<Guard>\n> {\n\tconst helpers = domainHelpers(entries)\n\tconst factory = { [command === 'action' ? 'action' : command ? 'command' : 'query']: helpers }\n\tif (errors && isFullErrorContract(errors)) Object.assign(factory, effectErrors(errors))\n\t// SAFETY: helper signatures check callbacks; registration pairs drafts with their declarations.\n\treturn factory as DomainEffectFactory<\n\t\tContext,\n\t\tEntries,\n\t\tCommand,\n\t\tDefault,\n\t\tCallbackError<Guard>,\n\t\tCallbackRequirements<Guard>\n\t>\n}\n\nexport type SharedEffectFactory<Context, Guard> = ReturnType<\n\ttypeof effectOperationFactory<\n\t\tContext,\n\t\tRecord<never, never>,\n\t\tNoInfer<CallbackError<Guard>>,\n\t\tNoInfer<CallbackRequirements<Guard>>,\n\t\tfalse\n\t>\n>\nexport type AuditValue = Supported<Audit>\n\n/** A contract that can create its declared errors also gives the factory `fail` and `attempt`. */\ntype ContractErrorHelpers<Errors> = [Errors] extends [never]\n\t? {}\n\t: Errors extends ErrorContract<infer Definitions>\n\t\t? EffectErrors<Definitions>\n\t\t: {}\n\nfunction isFullErrorContract(\n\terrors: object,\n): errors is Pick<ErrorContract<ErrorDefinitions>, 'create' | 'project' | 'decode'> {\n\t// SAFETY: only the presence of the three callable members is read here.\n\tconst candidate = errors as Partial<Record<'create' | 'project' | 'decode', Function>>\n\treturn [candidate.create, candidate.project, candidate.decode].every(\n\t\t(member) => member instanceof Function,\n\t)\n}\n"],"mappings":"uGAmOA,SAAgBA,EAOf,EACA,EACA,EAQC,CACD,IAAMC,EAAUC,EAAcC,CAAO,EAC/BC,EAAU,EAAGC,IAAY,SAAW,SAAWA,EAAU,UAAY,SAAUJ,CAAQ,EAG7F,OAFIK,GAAUC,EAAoBD,CAAM,GAAG,OAAO,OAAOF,EAASI,EAAaF,CAAM,CAAC,EAE/EF,CAQR,CAoBA,SAASG,EACR,EACmF,CAEnF,IAAME,EAAYH,EAClB,MAAO,CAACG,EAAU,OAAQA,EAAU,QAASA,EAAU,MAAM,CAAC,CAAC,MAC7D,GAAWC,aAAkB,QAC/B,CACD"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { DecodedFailure, ErrorContract, ErrorDefinitions } from "../contracts/errors.mjs";
|
|
2
2
|
import { Cause } from "effect";
|
|
3
3
|
//#region src/modules/effect/errors.d.ts
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Inspect the whole Cause; cleanup defects and other composite reasons cannot become expected data.
|
|
6
|
+
* A single defect projects only when the contract itself recognizes it, such as a declared error
|
|
7
|
+
* that a handler threw instead of failing with; any other defect stays an UnknownFailure.
|
|
8
|
+
*/
|
|
5
9
|
export declare function projectErrorCause<Definitions extends ErrorDefinitions>(contract: Pick<ErrorContract<Definitions>, 'project'>, cause: Cause.Cause<unknown>): DecodedFailure<Definitions>;
|
|
6
10
|
//#endregion
|
|
7
11
|
//# sourceMappingURL=errors.d.mts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Cause as e}from"effect";function t(t,n){if(n.reasons.length!==1)return{_tag:`UnknownFailure`,version:1};let r=n.reasons[0];return e.isFailReason(r)?t.project(r.error):{_tag:`UnknownFailure`,version:1}}export{t as projectErrorCause};
|
|
1
|
+
import{Cause as e}from"effect";function t(t,n){if(n.reasons.length!==1)return{_tag:`UnknownFailure`,version:1};let r=n.reasons[0];return e.isFailReason(r)?t.project(r.error):e.isDieReason(r)?t.project(r.defect):{_tag:`UnknownFailure`,version:1}}export{t as projectErrorCause};
|
|
2
2
|
//# sourceMappingURL=errors.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","names":["projectErrorCause","cause","reason","Cause","contract"],"sources":["../../../src/modules/effect/errors.ts"],"sourcesContent":["import { Cause } from 'effect'\nimport type { DecodedFailure, ErrorContract, ErrorDefinitions } from '../contracts/errors'\n\n
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":["projectErrorCause","cause","reason","Cause","contract"],"sources":["../../../src/modules/effect/errors.ts"],"sourcesContent":["import { Cause } from 'effect'\nimport type { DecodedFailure, ErrorContract, ErrorDefinitions } from '../contracts/errors'\n\n/**\n * Inspect the whole Cause; cleanup defects and other composite reasons cannot become expected data.\n * A single defect projects only when the contract itself recognizes it, such as a declared error\n * that a handler threw instead of failing with; any other defect stays an UnknownFailure.\n */\nexport function projectErrorCause<Definitions extends ErrorDefinitions>(\n\tcontract: Pick<ErrorContract<Definitions>, 'project'>,\n\tcause: Cause.Cause<unknown>,\n): DecodedFailure<Definitions> {\n\tif (cause.reasons.length !== 1) return { _tag: 'UnknownFailure', version: 1 }\n\tconst reason = cause.reasons[0]\n\tif (Cause.isFailReason(reason)) return contract.project(reason.error)\n\tif (Cause.isDieReason(reason)) return contract.project(reason.defect)\n\treturn { _tag: 'UnknownFailure', version: 1 }\n}\n"],"mappings":"+BAQA,SAAgBA,EACf,EACA,EAC8B,CAC9B,GAAIC,EAAM,QAAQ,SAAW,EAAG,MAAO,CAAE,KAAM,iBAAkB,QAAS,CAAE,EAC5E,IAAMC,EAASD,EAAM,QAAQ,GAG7B,OAFIE,EAAM,aAAaD,CAAM,EAAUE,EAAS,QAAQF,EAAO,KAAK,EAChEC,EAAM,YAAYD,CAAM,EAAUE,EAAS,QAAQF,EAAO,MAAM,EAC7D,CAAE,KAAM,iBAAkB,QAAS,CAAE,CAC7C"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ErrorContract, ErrorDefinitions } from "../contracts/errors.mjs";
|
|
2
|
+
import { ScopeState } from "./scope.mjs";
|
|
3
|
+
import { Value } from "convex/values";
|
|
4
|
+
import { Effect, Exit } from "effect";
|
|
5
|
+
//#region src/modules/effect/failure-audit.d.ts
|
|
6
|
+
type JsonRecord = Readonly<Record<string, Value>>;
|
|
7
|
+
type ProjectingContract = Pick<ErrorContract<ErrorDefinitions>, 'project'>;
|
|
8
|
+
/** One failed operation, without raw input, unredacted details, defect messages or stacks. */
|
|
9
|
+
export type FailureAuditEntry = Readonly<{
|
|
10
|
+
kind: 'command' | 'query' | 'action';
|
|
11
|
+
operation: string;
|
|
12
|
+
classification: string;
|
|
13
|
+
/** The declared contract code, or `UNKNOWN_FAILURE` when no contract recognizes the failure. */
|
|
14
|
+
errorCode: string;
|
|
15
|
+
declared: boolean;
|
|
16
|
+
/** The outermost operation of the request and this operation's nesting depth (0 for the root). */
|
|
17
|
+
root: string;
|
|
18
|
+
depth: number;
|
|
19
|
+
/** Present only when the `details` redactor returned a plain JSON record. */
|
|
20
|
+
details?: JsonRecord;
|
|
21
|
+
/** Present only when the `input` redactor returned a plain JSON record. */
|
|
22
|
+
input?: JsonRecord;
|
|
23
|
+
}>;
|
|
24
|
+
/**
|
|
25
|
+
* Host-free failure sink. A failed mutation rolls back every write it made, so failure
|
|
26
|
+
* entries go to logs or log streams; inside queries and mutations `emit` has no `fetch`.
|
|
27
|
+
*/
|
|
28
|
+
export type FailureAuditOptions = Readonly<{
|
|
29
|
+
emit: (entry: FailureAuditEntry) => void | PromiseLike<void>;
|
|
30
|
+
/** Projects failures that the operation's own registry contract does not recognize. */
|
|
31
|
+
errors?: ProjectingContract;
|
|
32
|
+
details?: (details: unknown, errorCode: string, operation: string) => JsonRecord | undefined;
|
|
33
|
+
input?: (input: unknown, operation: string) => JsonRecord | undefined;
|
|
34
|
+
}>;
|
|
35
|
+
type FailureReport = Readonly<{
|
|
36
|
+
kind: FailureAuditEntry['kind'];
|
|
37
|
+
operation: string;
|
|
38
|
+
classification: string;
|
|
39
|
+
input: unknown;
|
|
40
|
+
contract?: ProjectingContract;
|
|
41
|
+
entered: ScopeState | undefined;
|
|
42
|
+
current: ScopeState;
|
|
43
|
+
}>;
|
|
44
|
+
/** Report a failed exit once per failure value in the request; never changes the original outcome. */
|
|
45
|
+
export declare function reportFailure(options: FailureAuditOptions | undefined, exit: Exit.Exit<unknown, unknown>, report: FailureReport): Effect.Effect<void>;
|
|
46
|
+
export declare function reportAuditWriteFailure(options: FailureAuditOptions | undefined, report: Pick<FailureReport, 'operation' | 'classification' | 'entered'>): Effect.Effect<void>;
|
|
47
|
+
//#endregion
|
|
48
|
+
//# sourceMappingURL=failure-audit.d.mts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{isRecord as e}from"../contracts/errors.mjs";import{projectErrorCause as t}from"./errors.mjs";import{observationFailure as n}from"./normalize.mjs";import{Cause as r,Effect as i,Exit as a}from"effect";function o(e,o,s){if(!e||a.isSuccess(o))return i.void;let d=o.cause;return!r.hasFails(d)&&!r.hasDies(d)?i.void:c(e,()=>{let r=n(d);if(r instanceof Object){if(s.current.reported.has(r))return;s.current.reported.add(r)}let i=s.contract?t(s.contract,d):{_tag:`UnknownFailure`,version:1};i._tag!==`DeclaredFailure`&&e.errors&&(i=t(e.errors,d));let a=i._tag===`DeclaredFailure`?i:void 0,o=a?.code??`UNKNOWN_FAILURE`,c=a&&e.details?u(()=>e.details(a.details,o,s.operation)):void 0,f=e.input?u(()=>e.input(s.input,s.operation)):void 0;return Object.assign({kind:s.kind,operation:s.operation,classification:s.classification,errorCode:o,declared:a!==void 0,...l(s)},c===void 0?void 0:{details:c},f===void 0?void 0:{input:f})})}function s(e,t){return e?c(e,()=>({kind:`action`,operation:t.operation,classification:t.classification,errorCode:`ACTION_AUDIT_WRITE_FAILED`,declared:!1,...l(t)})):i.sync(()=>{try{console.error(JSON.stringify({event:`action.audit_write_failed`,errorCode:`ACTION_AUDIT_WRITE_FAILED`,operation:t.operation,classification:t.classification}))}catch{}})}function c(e,t){return i.tryPromise({try:async()=>{let n=t();n&&await e.emit(Object.freeze(n))},catch:()=>void 0}).pipe(i.ignore)}function l(e){return{root:e.entered?.scope.root??e.operation,depth:e.entered?.scope.depth??0}}function u(t){try{let n=t();return e(n)?JSON.parse(JSON.stringify(n)):void 0}catch{return}}export{s as reportAuditWriteFailure,o as reportFailure};
|
|
2
|
+
//# sourceMappingURL=failure-audit.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failure-audit.mjs","names":["reportFailure","options","Exit","exit","Effect","cause","Cause","emitQuietly","failure","observationFailure","report","projected","projectErrorCause","declaredFailure","errorCode","details","redact","input","position","reportAuditWriteFailure","entry","build","value","read","isRecord"],"sources":["../../../src/modules/effect/failure-audit.ts"],"sourcesContent":["import { Cause, Effect, Exit } from 'effect'\nimport type { Value } from 'convex/values'\nimport { isRecord, type ErrorContract, type ErrorDefinitions } from '../contracts/errors'\nimport { projectErrorCause } from './errors'\nimport { observationFailure } from './normalize'\nimport type { ScopeState } from './scope'\n\ntype JsonRecord = Readonly<Record<string, Value>>\ntype ProjectingContract = Pick<ErrorContract<ErrorDefinitions>, 'project'>\n\n/** One failed operation, without raw input, unredacted details, defect messages or stacks. */\nexport type FailureAuditEntry = Readonly<{\n\tkind: 'command' | 'query' | 'action'\n\toperation: string\n\tclassification: string\n\t/** The declared contract code, or `UNKNOWN_FAILURE` when no contract recognizes the failure. */\n\terrorCode: string\n\tdeclared: boolean\n\t/** The outermost operation of the request and this operation's nesting depth (0 for the root). */\n\troot: string\n\tdepth: number\n\t/** Present only when the `details` redactor returned a plain JSON record. */\n\tdetails?: JsonRecord\n\t/** Present only when the `input` redactor returned a plain JSON record. */\n\tinput?: JsonRecord\n}>\n\n/**\n * Host-free failure sink. A failed mutation rolls back every write it made, so failure\n * entries go to logs or log streams; inside queries and mutations `emit` has no `fetch`.\n */\nexport type FailureAuditOptions = Readonly<{\n\temit: (entry: FailureAuditEntry) => void | PromiseLike<void>\n\t/** Projects failures that the operation's own registry contract does not recognize. */\n\terrors?: ProjectingContract\n\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Redactors receive validated declared details of any registered contract.\n\tdetails?: (details: unknown, errorCode: string, operation: string) => JsonRecord | undefined\n\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Redactors receive the operation's decoded input of any registered schema.\n\tinput?: (input: unknown, operation: string) => JsonRecord | undefined\n}>\n\ntype FailureReport = Readonly<{\n\tkind: FailureAuditEntry['kind']\n\toperation: string\n\tclassification: string\n\t// oxlint-disable-next-line anti-slop/no-unknown-type-aliases -- The decoded input of the failed operation; only a redactor may read it.\n\tinput: unknown\n\tcontract?: ProjectingContract\n\tentered: ScopeState | undefined\n\tcurrent: ScopeState\n}>\n\n/** Report a failed exit once per failure value in the request; never changes the original outcome. */\nexport function reportFailure(\n\toptions: FailureAuditOptions | undefined,\n\texit: Exit.Exit<unknown, unknown>,\n\treport: FailureReport,\n): Effect.Effect<void> {\n\tif (!options || Exit.isSuccess(exit)) return Effect.void\n\tconst cause = exit.cause\n\tif (!Cause.hasFails(cause) && !Cause.hasDies(cause)) return Effect.void\n\treturn emitQuietly(options, () => {\n\t\tconst failure = observationFailure(cause)\n\t\tif (failure instanceof Object) {\n\t\t\tif (report.current.reported.has(failure)) return undefined\n\t\t\treport.current.reported.add(failure)\n\t\t}\n\t\tlet projected = report.contract\n\t\t\t? projectErrorCause(report.contract, cause)\n\t\t\t: ({ _tag: 'UnknownFailure', version: 1 } as const)\n\t\tif (projected._tag !== 'DeclaredFailure' && options.errors)\n\t\t\tprojected = projectErrorCause(options.errors, cause)\n\t\tconst declaredFailure = projected._tag === 'DeclaredFailure' ? projected : undefined\n\t\tconst errorCode = declaredFailure?.code ?? 'UNKNOWN_FAILURE'\n\t\tconst details =\n\t\t\tdeclaredFailure && options.details\n\t\t\t\t? redact(() => options.details!(declaredFailure.details, errorCode, report.operation))\n\t\t\t\t: undefined\n\t\tconst input = options.input\n\t\t\t? redact(() => options.input!(report.input, report.operation))\n\t\t\t: undefined\n\t\treturn Object.assign(\n\t\t\t{\n\t\t\t\tkind: report.kind,\n\t\t\t\toperation: report.operation,\n\t\t\t\tclassification: report.classification,\n\t\t\t\terrorCode,\n\t\t\t\tdeclared: declaredFailure !== undefined,\n\t\t\t\t...position(report),\n\t\t\t},\n\t\t\tdetails === undefined ? undefined : { details },\n\t\t\tinput === undefined ? undefined : { input },\n\t\t)\n\t})\n}\n\nexport function reportAuditWriteFailure(\n\toptions: FailureAuditOptions | undefined,\n\treport: Pick<FailureReport, 'operation' | 'classification' | 'entered'>,\n): Effect.Effect<void> {\n\t// Without a sink, still leave a payload-free trace that an audited action went unrecorded.\n\tif (!options)\n\t\treturn Effect.sync(() => {\n\t\t\ttry {\n\t\t\t\tconsole.error(\n\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\tevent: 'action.audit_write_failed',\n\t\t\t\t\t\terrorCode: 'ACTION_AUDIT_WRITE_FAILED',\n\t\t\t\t\t\toperation: report.operation,\n\t\t\t\t\t\tclassification: report.classification,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t} catch {\n\t\t\t\t// The fallback trace is as inert as the sink it replaces.\n\t\t\t}\n\t\t})\n\treturn emitQuietly(options, () => ({\n\t\tkind: 'action',\n\t\toperation: report.operation,\n\t\tclassification: report.classification,\n\t\terrorCode: 'ACTION_AUDIT_WRITE_FAILED',\n\t\tdeclared: false,\n\t\t...position(report),\n\t}))\n}\n\n/** The sink is inert: building or emitting an entry can never change the operation's outcome. */\nfunction emitQuietly(\n\toptions: FailureAuditOptions,\n\tbuild: () => FailureAuditEntry | undefined,\n): Effect.Effect<void> {\n\treturn Effect.tryPromise({\n\t\ttry: async () => {\n\t\t\tconst entry = build()\n\t\t\tif (entry) await options.emit(Object.freeze(entry))\n\t\t},\n\t\tcatch: () => undefined,\n\t}).pipe(Effect.ignore)\n}\n\nfunction position(report: Pick<FailureReport, 'operation' | 'entered'>) {\n\treturn {\n\t\troot: report.entered?.scope.root ?? report.operation,\n\t\tdepth: report.entered?.scope.depth ?? 0,\n\t}\n}\n\nfunction redact(read: () => JsonRecord | undefined): JsonRecord | undefined {\n\ttry {\n\t\tconst value: unknown = read()\n\t\t// Application redactors are untrusted; only a plain record may enter the entry.\n\t\tif (!isRecord(value)) return undefined\n\t\t// SAFETY: the JSON round trip yields plain JSON values, a subset of Convex values.\n\t\treturn JSON.parse(JSON.stringify(value)) as JsonRecord\n\t} catch {\n\t\treturn undefined\n\t}\n}\n"],"mappings":"8MAqDA,SAAgBA,EACf,EACA,EACA,EACsB,CACtB,GAAI,CAACC,GAAWC,EAAK,UAAUC,CAAI,EAAG,OAAOC,EAAO,KACpD,IAAMC,EAAQF,EAAK,MAEnB,MADI,CAACG,EAAM,SAASD,CAAK,GAAK,CAACC,EAAM,QAAQD,CAAK,EAAUD,EAAO,KAC5DG,EAAYN,MAAe,CACjC,IAAMO,EAAUC,EAAmBJ,CAAK,EACxC,GAAIG,aAAmB,OAAQ,CAC9B,GAAIE,EAAO,QAAQ,SAAS,IAAIF,CAAO,EAAG,OAC1CE,EAAO,QAAQ,SAAS,IAAIF,CAAO,CACpC,CACA,IAAIG,EAAYD,EAAO,SACpBE,EAAkBF,EAAO,SAAUL,CAAK,EACvC,CAAE,KAAM,iBAAkB,QAAS,CAAE,EACrCM,EAAU,OAAS,mBAAqBV,EAAQ,SACnD,EAAYW,EAAkBX,EAAQ,OAAQI,CAAK,GACpD,IAAMQ,EAAkBF,EAAU,OAAS,kBAAoBA,EAAY,IAAA,GACrEG,EAAYD,GAAiB,MAAQ,kBACrCE,EACLF,GAAmBZ,EAAQ,QACxBe,MAAaf,EAAQ,QAASY,EAAgB,QAASC,EAAWJ,EAAO,SAAS,CAAC,EACnF,IAAA,GACEO,EAAQhB,EAAQ,MACnBe,MAAaf,EAAQ,MAAOS,EAAO,MAAOA,EAAO,SAAS,CAAC,EAC3D,IAAA,GACH,OAAO,OAAO,OACb,CACC,KAAMA,EAAO,KACb,UAAWA,EAAO,UAClB,eAAgBA,EAAO,eACvB,YACA,SAAUG,IAAoB,IAAA,GAC9B,GAAGK,EAASR,CAAM,CACnB,EACAK,IAAY,IAAA,GAAY,IAAA,GAAY,CAAE,SAAQ,EAC9CE,IAAU,IAAA,GAAY,IAAA,GAAY,CAAE,OAAM,CAC3C,CACD,CAAC,CACF,CAEA,SAAgBE,EACf,EACA,EACsB,CAiBtB,OAfKlB,EAeEM,EAAYN,OAAgB,CAClC,KAAM,SACN,UAAWS,EAAO,UAClB,eAAgBA,EAAO,eACvB,UAAW,4BACX,SAAU,GACV,GAAGQ,EAASR,CAAM,CACnB,EAAE,EArBMN,EAAO,SAAW,CACxB,GAAI,CACH,QAAQ,MACP,KAAK,UAAU,CACd,MAAO,4BACP,UAAW,4BACX,UAAWM,EAAO,UAClB,eAAgBA,EAAO,cACxB,CAAC,CACF,CACD,MAAQ,CAER,CACD,CAAC,CASH,CAGA,SAASH,EACR,EACA,EACsB,CACtB,OAAOH,EAAO,WAAW,CACxB,IAAK,SAAY,CAChB,IAAMgB,EAAQC,EAAM,EAChBD,GAAO,MAAMnB,EAAQ,KAAK,OAAO,OAAOmB,CAAK,CAAC,CACnD,EACA,UAAa,IAAA,EACd,CAAC,CAAC,CAAC,KAAKhB,EAAO,MAAM,CACtB,CAEA,SAASc,EAAS,EAAsD,CACvE,MAAO,CACN,KAAMR,EAAO,SAAS,MAAM,MAAQA,EAAO,UAC3C,MAAOA,EAAO,SAAS,MAAM,OAAS,CACvC,CACD,CAEA,SAASM,EAAO,EAA4D,CAC3E,GAAI,CACH,IAAMM,EAAiBC,EAAK,EAI5B,OAFKC,EAASF,CAAK,EAEZ,KAAK,MAAM,KAAK,UAAUA,CAAK,CAAC,EAFjB,MAGvB,MAAQ,CACP,MACD,CACD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DeclaredError, DeclaredErrorDetails, ErrorContract, ErrorDefinitions } from "../contracts/errors.mjs";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
//#region src/modules/effect/failures.d.ts
|
|
4
|
+
type Code<Definitions extends ErrorDefinitions> = Extract<keyof Definitions, string>;
|
|
5
|
+
/** Details are optional exactly when the code declares no detail fields. */
|
|
6
|
+
type DetailArguments<Definitions extends ErrorDefinitions, Key extends Code<Definitions>> = [keyof Definitions[Key]['details']] extends [never] ? [details?: DeclaredErrorDetails<Definitions, Key>] : [details: DeclaredErrorDetails<Definitions, Key>];
|
|
7
|
+
/** Effect helpers bound to one declared error contract. */
|
|
8
|
+
export type EffectErrors<Definitions extends ErrorDefinitions> = Readonly<{
|
|
9
|
+
/** A yieldable failure with the contract's typed declared error: `return yield* fail('NOT_FOUND')`. */
|
|
10
|
+
fail: <Key extends Code<Definitions>>(code: Key, ...details: DetailArguments<Definitions, NoInfer<Key>>) => Effect.Effect<never, Extract<DeclaredError<Definitions>, {
|
|
11
|
+
code: Key;
|
|
12
|
+
}>>;
|
|
13
|
+
/**
|
|
14
|
+
* Run sync or async work; a thrown declared error of this contract, or a ConvexError carrying
|
|
15
|
+
* one of its declared envelopes, lands in the typed failure channel. Any other throw is a defect.
|
|
16
|
+
*/
|
|
17
|
+
attempt: <Value>(run: () => Value | PromiseLike<Value>) => Effect.Effect<Value, DeclaredError<Definitions>>;
|
|
18
|
+
}>;
|
|
19
|
+
/** Bind `fail` and `attempt` to a declared error contract. */
|
|
20
|
+
export declare function effectErrors<const Definitions extends ErrorDefinitions>(contract: Pick<ErrorContract<Definitions>, 'create' | 'project' | 'decode'>): EffectErrors<Definitions>;
|
|
21
|
+
//#endregion
|
|
22
|
+
//# sourceMappingURL=failures.d.mts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{decodeFailure as e}from"../contracts/errors.mjs";import{Effect as t}from"effect";function n(n){return Object.freeze({fail:(e,...r)=>t.suspend(()=>t.fail(n.create(e,r[0]??{}))),attempt:r=>t.tryPromise({try:async()=>r(),catch:e=>e}).pipe(t.catch(r=>{if(n.project(r)._tag===`DeclaredFailure`)return t.fail(r);let i=e(r,n);return i._tag===`DeclaredFailure`?t.fail(n.create(i.code,i.details)):t.die(r)}))})}export{n as effectErrors};
|
|
2
|
+
//# sourceMappingURL=failures.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failures.mjs","names":["effectErrors","details","Effect","contract","code","run","thrown","decoded","decodeFailure"],"sources":["../../../src/modules/effect/failures.ts"],"sourcesContent":["import { Effect } from 'effect'\nimport {\n\tdecodeFailure,\n\ttype DeclaredError,\n\ttype DeclaredErrorDetails,\n\ttype ErrorContract,\n\ttype ErrorDefinitions,\n} from '../contracts/errors'\n\ntype Code<Definitions extends ErrorDefinitions> = Extract<keyof Definitions, string>\n/** Details are optional exactly when the code declares no detail fields. */\ntype DetailArguments<Definitions extends ErrorDefinitions, Key extends Code<Definitions>> = [\n\tkeyof Definitions[Key]['details'],\n] extends [never]\n\t? [details?: DeclaredErrorDetails<Definitions, Key>]\n\t: [details: DeclaredErrorDetails<Definitions, Key>]\n\n/** Effect helpers bound to one declared error contract. */\nexport type EffectErrors<Definitions extends ErrorDefinitions> = Readonly<{\n\t/** A yieldable failure with the contract's typed declared error: `return yield* fail('NOT_FOUND')`. */\n\tfail: <Key extends Code<Definitions>>(\n\t\tcode: Key,\n\t\t...details: DetailArguments<Definitions, NoInfer<Key>>\n\t) => Effect.Effect<never, Extract<DeclaredError<Definitions>, { code: Key }>>\n\t/**\n\t * Run sync or async work; a thrown declared error of this contract, or a ConvexError carrying\n\t * one of its declared envelopes, lands in the typed failure channel. Any other throw is a defect.\n\t */\n\tattempt: <Value>(\n\t\trun: () => Value | PromiseLike<Value>,\n\t) => Effect.Effect<Value, DeclaredError<Definitions>>\n}>\n\n/** Bind `fail` and `attempt` to a declared error contract. */\nexport function effectErrors<const Definitions extends ErrorDefinitions>(\n\tcontract: Pick<ErrorContract<Definitions>, 'create' | 'project' | 'decode'>,\n): EffectErrors<Definitions> {\n\treturn Object.freeze({\n\t\tfail: (code, ...details) =>\n\t\t\tEffect.suspend(() =>\n\t\t\t\t// SAFETY: omitted details are allowed only for codes that declare no detail fields; `create` validates them.\n\t\t\t\tEffect.fail(contract.create(code, (details[0] ?? {}) as never)),\n\t\t\t),\n\t\tattempt: (run) =>\n\t\t\tEffect.tryPromise({ try: async () => run(), catch: (thrown) => thrown }).pipe(\n\t\t\t\tEffect.catch((thrown) => {\n\t\t\t\t\tif (contract.project(thrown)._tag === 'DeclaredFailure')\n\t\t\t\t\t\t// SAFETY: `project` recognizes only declared errors this contract created.\n\t\t\t\t\t\treturn Effect.fail(thrown as DeclaredError<Definitions>)\n\t\t\t\t\tconst decoded = decodeFailure(thrown, contract)\n\t\t\t\t\tif (decoded._tag === 'DeclaredFailure')\n\t\t\t\t\t\t// SAFETY: `decode` validated these details against this code's declaration.\n\t\t\t\t\t\treturn Effect.fail(contract.create(decoded.code, decoded.details as never))\n\t\t\t\t\treturn Effect.die(thrown)\n\t\t\t\t}),\n\t\t\t),\n\t} satisfies EffectErrors<Definitions>)\n}\n"],"mappings":"wFAkCA,SAAgBA,EACf,EAC4B,CAC5B,OAAO,OAAO,OAAO,CACpB,MAAO,EAAM,GAAGC,IACfC,EAAO,YAENA,EAAO,KAAKC,EAAS,OAAOC,EAAOH,EAAQ,IAAM,CAAC,CAAW,CAAC,CAC/D,EACD,QAAU,GACTC,EAAO,WAAW,CAAE,IAAK,SAAYG,EAAI,EAAG,MAAQ,GAAWC,CAAO,CAAC,CAAC,CAAC,KACxEJ,EAAO,MAAO,GAAW,CACxB,GAAIC,EAAS,QAAQG,CAAM,CAAC,CAAC,OAAS,kBAErC,OAAOJ,EAAO,KAAKI,CAAoC,EACxD,IAAMC,EAAUC,EAAcF,EAAQH,CAAQ,EAI9C,OAHII,EAAQ,OAAS,kBAEbL,EAAO,KAAKC,EAAS,OAAOI,EAAQ,KAAMA,EAAQ,OAAgB,CAAC,EACpEL,EAAO,IAAII,CAAM,CACzB,CAAC,CACF,CACF,CAAqC,CACtC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Observability, ObservabilityOptions } from "../../components/foundation/modules/observability/observability.mjs";
|
|
2
2
|
import { EffectCommandDependencies, bindEffectCommand } from "./command.mjs";
|
|
3
3
|
import { bindEffectQuery } from "./query.mjs";
|
|
4
|
+
import { EffectActionDependencies, bindEffectAction } from "./action.mjs";
|
|
4
5
|
//#region src/modules/effect/foundation.d.ts
|
|
5
6
|
/** Shared host capabilities are bound once; registry resolvers stay invocation-local. */
|
|
6
|
-
export type EffectFoundationOptions = Omit<EffectCommandDependencies, 'observability'> & {
|
|
7
|
+
export type EffectFoundationOptions = Omit<EffectCommandDependencies, 'observability'> & Pick<EffectActionDependencies, 'writeActionAudit'> & {
|
|
7
8
|
observability: ObservabilityOptions;
|
|
8
9
|
};
|
|
9
10
|
export type EffectFoundation<Options extends EffectFoundationOptions> = {
|
|
@@ -13,6 +14,10 @@ export type EffectFoundation<Options extends EffectFoundationOptions> = {
|
|
|
13
14
|
Query: ReturnType<typeof bindEffectQuery<Options & {
|
|
14
15
|
observability: Observability;
|
|
15
16
|
}>>;
|
|
17
|
+
/** Contract-typed Convex actions with context injection, guards, middleware and optional audit. */
|
|
18
|
+
Action: ReturnType<typeof bindEffectAction<Options & {
|
|
19
|
+
observability: Observability;
|
|
20
|
+
}>>;
|
|
16
21
|
observability: Observability;
|
|
17
22
|
};
|
|
18
23
|
export declare function createEffectFoundation<const Options extends EffectFoundationOptions>(options: Options): EffectFoundation<Options>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Observability as e}from"../../components/foundation/modules/observability/observability.mjs";import{bindEffectCommand as t}from"./command.mjs";import{bindEffectQuery as n}from"./query.mjs";function
|
|
1
|
+
import{Observability as e}from"../../components/foundation/modules/observability/observability.mjs";import{bindEffectCommand as t}from"./command.mjs";import{bindEffectQuery as n}from"./query.mjs";import{bindEffectAction as r}from"./action.mjs";function i(i){let a=new e(i.observability),o={...i,observability:a};return{Command:t(o),Query:n(o),Action:r(o),observability:a}}export{i as createEffectFoundation};
|
|
2
2
|
//# sourceMappingURL=foundation.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"foundation.mjs","names":["createEffectFoundation","observability","Observability","options","dependencies","bindEffectCommand","bindEffectQuery"],"sources":["../../../src/modules/effect/foundation.ts"],"sourcesContent":["// oxlint-disable-next-line cvx/component-boundaries -- SAFETY: Internal optional adapter shares the Effect-free Foundation lifecycle and types without entering the Convex component deployment graph.\nimport {\n\tObservability,\n\ttype ObservabilityOptions,\n} from '../../components/foundation/modules/observability/observability'\nimport { bindEffectCommand, type EffectCommandDependencies } from './command'\nimport { bindEffectQuery } from './query'\n\n/** Shared host capabilities are bound once; registry resolvers stay invocation-local. */\nexport type EffectFoundationOptions = Omit<EffectCommandDependencies, 'observability'> & {\n\tobservability: ObservabilityOptions\n}\nexport type EffectFoundation<Options extends EffectFoundationOptions> = {\n\tCommand: ReturnType<typeof bindEffectCommand<Options & { observability: Observability }>>\n\tQuery: ReturnType<typeof bindEffectQuery<Options & { observability: Observability }>>\n\tobservability: Observability\n}\n\nexport function createEffectFoundation<const Options extends EffectFoundationOptions>(\n\toptions: Options,\n): EffectFoundation<Options> {\n\tconst observability = new Observability(options.observability)\n\tconst dependencies = { ...options, observability }\n\treturn {\n\t\tCommand: bindEffectCommand(dependencies),\n\t\tQuery: bindEffectQuery(dependencies),\n\t\tobservability,\n\t}\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"foundation.mjs","names":["createEffectFoundation","observability","Observability","options","dependencies","bindEffectCommand","bindEffectQuery","bindEffectAction"],"sources":["../../../src/modules/effect/foundation.ts"],"sourcesContent":["// oxlint-disable-next-line cvx/component-boundaries -- SAFETY: Internal optional adapter shares the Effect-free Foundation lifecycle and types without entering the Convex component deployment graph.\nimport {\n\tObservability,\n\ttype ObservabilityOptions,\n} from '../../components/foundation/modules/observability/observability'\nimport { bindEffectCommand, type EffectCommandDependencies } from './command'\nimport { bindEffectQuery } from './query'\nimport { bindEffectAction, type EffectActionDependencies } from './action'\n\n/** Shared host capabilities are bound once; registry resolvers stay invocation-local. */\nexport type EffectFoundationOptions = Omit<EffectCommandDependencies, 'observability'> &\n\tPick<EffectActionDependencies, 'writeActionAudit'> & {\n\t\tobservability: ObservabilityOptions\n\t}\nexport type EffectFoundation<Options extends EffectFoundationOptions> = {\n\tCommand: ReturnType<typeof bindEffectCommand<Options & { observability: Observability }>>\n\tQuery: ReturnType<typeof bindEffectQuery<Options & { observability: Observability }>>\n\t/** Contract-typed Convex actions with context injection, guards, middleware and optional audit. */\n\tAction: ReturnType<typeof bindEffectAction<Options & { observability: Observability }>>\n\tobservability: Observability\n}\n\nexport function createEffectFoundation<const Options extends EffectFoundationOptions>(\n\toptions: Options,\n): EffectFoundation<Options> {\n\tconst observability = new Observability(options.observability)\n\tconst dependencies = { ...options, observability }\n\treturn {\n\t\tCommand: bindEffectCommand(dependencies),\n\t\tQuery: bindEffectQuery(dependencies),\n\t\tAction: bindEffectAction(dependencies),\n\t\tobservability,\n\t}\n}\n"],"mappings":"oPAsBA,SAAgBA,EACf,EAC4B,CAC5B,IAAMC,EAAgB,IAAIC,EAAcC,EAAQ,aAAa,EACvDC,EAAe,CAAE,GAAGD,EAAS,eAAc,EACjD,MAAO,CACN,QAASE,EAAkBD,CAAY,EACvC,MAAOE,EAAgBF,CAAY,EACnC,OAAQG,EAAiBH,CAAY,EACrC,eACD,CACD"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ContractInput, ContractOutput, ContractSchema } from "../contracts/contract.mjs";
|
|
2
2
|
import { AuditEntryInput } from "../../components/foundation/client.mjs";
|
|
3
3
|
import { ContractDecoderError, ContractDecoderRequirements } from "./schema.mjs";
|
|
4
|
+
import { RequestScope } from "./scope.mjs";
|
|
4
5
|
import { Effect } from "effect";
|
|
5
6
|
//#region src/modules/effect/operation.d.ts
|
|
6
7
|
/** Ordinary failures are defects; only an explicit Effect supplies a typed error. */
|
|
@@ -108,7 +109,7 @@ export type OperationDefinition<Context, Input extends ContractSchema, Output ex
|
|
|
108
109
|
audit?: (resolution: {
|
|
109
110
|
command: ContractOutput<Input>;
|
|
110
111
|
result: ContractOutput<Output>;
|
|
111
|
-
}, context: Context) => AuditResult;
|
|
112
|
+
}, context: Context, scope: RequestScope | undefined) => AuditResult;
|
|
112
113
|
} & (keyof Extension extends never ? {
|
|
113
114
|
middleware?: (input: EffectMiddlewareInput<Context, ContractOutput<Input>, ContractInput<Output>, Extension, BaseError | CallbackError<Handler | Guard>, BaseRequirements | CallbackRequirements<Handler | Guard>>) => Middleware;
|
|
114
115
|
} : {
|
|
@@ -128,7 +129,7 @@ export declare function effectOperationFactory<Context, Extension extends Record
|
|
|
128
129
|
audit: (resolution: {
|
|
129
130
|
command: ContractOutput<Input>;
|
|
130
131
|
result: ContractOutput<Output>;
|
|
131
|
-
}, context: Context) => AuditResult;
|
|
132
|
+
}, context: Context, scope: RequestScope | undefined) => AuditResult;
|
|
132
133
|
} : {})) => CheckedEffectDefinition<Context, typeof definition, BaseError, BaseRequirements>;
|
|
133
134
|
query: <const Input extends ContractSchema, const Output extends ContractSchema, Handler extends Supported<ContractInput<Output>>, Guard extends Supported<void> = never, Middleware extends Supported<ContractInput<Output>> = never, const Metadata extends object = Record<never, never>, const Wire extends ContractSchema = ContractSchema, const Replay extends ContractSchema = never, const Definition extends object = object>(definition: Definition & OperationDefinition<Context, Input, Output, Extension, readonly string[], Handler, Guard, never, never, Middleware, Metadata, BaseError, BaseRequirements, Wire, Replay> & {
|
|
134
135
|
prepare?: never;
|
|
@@ -137,5 +138,12 @@ export declare function effectOperationFactory<Context, Extension extends Record
|
|
|
137
138
|
replayResult?: never;
|
|
138
139
|
}) => CheckedEffectDefinition<Context, typeof definition, BaseError, BaseRequirements>;
|
|
139
140
|
};
|
|
141
|
+
export declare function effectActionFactory<Context, BaseError = never, BaseRequirements = never>(): {
|
|
142
|
+
action: <const Input extends ContractSchema, const Output extends ContractSchema, Handler extends Supported<ContractInput<Output>>, Guard extends Supported<void> = never, const Aggregates extends readonly string[] = readonly string[], AuditResult extends Supported<Audit<Aggregates> | null> = never, Middleware extends Supported<ContractInput<Output>> = never, const Metadata extends object = Record<never, never>, const Wire extends ContractSchema = ContractSchema, const Definition extends object = object>(definition: Definition & OperationDefinition<Context, Input, Output, Record<never, never>, Aggregates, Handler, Guard, never, AuditResult, Middleware, Metadata, BaseError, BaseRequirements, Wire, never> & {
|
|
143
|
+
prepare?: never;
|
|
144
|
+
permission?: never;
|
|
145
|
+
replayResult?: never;
|
|
146
|
+
}) => CheckedEffectDefinition<Context, typeof definition, BaseError, BaseRequirements>;
|
|
147
|
+
};
|
|
140
148
|
//#endregion
|
|
141
149
|
//# sourceMappingURL=operation.d.mts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(){function e(e){return e}function t(e){return e}function n(e){return e}return{operation:e,command:t,query:n}}export{e as effectOperationFactory};
|
|
1
|
+
function e(){function e(e){return e}function t(e){return e}function n(e){return e}return{operation:e,command:t,query:n}}function t(){function e(e){return e}return{action:e}}export{t as effectActionFactory,e as effectOperationFactory};
|
|
2
2
|
//# sourceMappingURL=operation.mjs.map
|