@shivaedev/effect-trpc 0.3.4 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -1
- package/README.md +93 -0
- package/dist/adapter.d.ts +6 -5
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +2 -1
- package/dist/adapter.js.map +1 -1
- package/dist/client/rejection.d.ts +11 -0
- package/dist/client/rejection.d.ts.map +1 -0
- package/dist/client/rejection.js +9 -0
- package/dist/client/rejection.js.map +1 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +2 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/context-bridge.d.ts.map +1 -1
- package/dist/internal/context-bridge.js +1 -2
- package/dist/internal/context-bridge.js.map +1 -1
- package/dist/internal/loose.d.ts +4 -0
- package/dist/internal/loose.d.ts.map +1 -0
- package/dist/internal/loose.js +7 -0
- package/dist/internal/loose.js.map +1 -0
- package/dist/internal/procedure-handler.d.ts +5 -12
- package/dist/internal/procedure-handler.d.ts.map +1 -1
- package/dist/internal/procedure-handler.js +3 -4
- package/dist/internal/procedure-handler.js.map +1 -1
- package/dist/internal/procedure-types.d.ts +17 -4
- package/dist/internal/procedure-types.d.ts.map +1 -1
- package/dist/internal/runtime.d.ts +4 -4
- package/dist/internal/runtime.d.ts.map +1 -1
- package/dist/internal/runtime.js +5 -13
- package/dist/internal/runtime.js.map +1 -1
- package/dist/internal/subscription-handler.d.ts +5 -12
- package/dist/internal/subscription-handler.d.ts.map +1 -1
- package/dist/internal/subscription-handler.js +5 -6
- package/dist/internal/subscription-handler.js.map +1 -1
- package/dist/procedure.d.ts +6 -8
- package/dist/procedure.d.ts.map +1 -1
- package/dist/procedure.js +8 -17
- package/dist/procedure.js.map +1 -1
- package/dist/rejection-formatter.d.ts +18 -0
- package/dist/rejection-formatter.d.ts.map +1 -0
- package/dist/rejection-formatter.js +24 -0
- package/dist/rejection-formatter.js.map +1 -0
- package/dist/rejection.d.ts +26 -0
- package/dist/rejection.d.ts.map +1 -0
- package/dist/rejection.js +32 -0
- package/dist/rejection.js.map +1 -0
- package/dist/request-services.d.ts.map +1 -1
- package/dist/request-services.js.map +1 -1
- package/dist/request-signal.d.ts.map +1 -1
- package/dist/request-signal.js.map +1 -1
- package/dist/testing/any-test-layer.d.ts +3 -0
- package/dist/testing/any-test-layer.d.ts.map +1 -0
- package/dist/testing/any-test-layer.js +2 -0
- package/dist/testing/any-test-layer.js.map +1 -0
- package/dist/testing/caller.d.ts +5 -3
- package/dist/testing/caller.d.ts.map +1 -1
- package/dist/testing/caller.js +12 -11
- package/dist/testing/caller.js.map +1 -1
- package/dist/testing/types.d.ts +5 -4
- package/dist/testing/types.d.ts.map +1 -1
- package/dist/testing/vitest.d.ts +4 -3
- package/dist/testing/vitest.d.ts.map +1 -1
- package/dist/testing/vitest.js +13 -14
- package/dist/testing/vitest.js.map +1 -1
- package/dist/testing.d.ts +3 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +12 -3
- package/src/adapter.ts +24 -76
- package/src/client/rejection.ts +19 -0
- package/src/client.ts +1 -0
- package/src/errors.ts +8 -19
- package/src/index.ts +9 -6
- package/src/internal/context-bridge.ts +3 -10
- package/src/internal/loose.ts +14 -0
- package/src/internal/procedure-handler.ts +11 -34
- package/src/internal/procedure-types.ts +37 -50
- package/src/internal/runtime.ts +14 -49
- package/src/internal/subscription-handler.ts +15 -47
- package/src/procedure.ts +33 -142
- package/src/rejection-formatter.ts +33 -0
- package/src/rejection.ts +60 -0
- package/src/request-services.ts +5 -25
- package/src/request-signal.ts +1 -4
- package/src/testing/any-test-layer.ts +3 -0
- package/src/testing/caller.ts +29 -32
- package/src/testing/types.ts +15 -47
- package/src/testing/vitest.ts +19 -51
- package/src/testing.ts +3 -3
- package/src/types.ts +3 -12
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { Effect, Layer, Schema, Stream } from "effect";
|
|
2
2
|
import { RequestSignal } from "../request-signal.js";
|
|
3
|
+
import { acceptParsedInput } from "./loose.js";
|
|
3
4
|
export const makeSubscriptionHandler = (runtime, resolver, requestServices, procedure, outputSchema) => {
|
|
4
|
-
const tracedResolver = Effect.fnUntraced(resolver);
|
|
5
|
+
const tracedResolver = Effect.fnUntraced(acceptParsedInput(resolver));
|
|
5
6
|
return async (invocation) => {
|
|
6
7
|
const info = { ...procedure, path: invocation.path };
|
|
7
8
|
const requestLayer = Layer.merge(requestServices.layer(invocation.ctx), Layer.succeed(RequestSignal, invocation.signal));
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
return await runtime.runStream(stream, {
|
|
9
|
+
const stream = Stream.unwrap(Effect.suspend(() => runtime.instrument(tracedResolver(invocation.input), info))).pipe(Stream.provide(requestLayer));
|
|
10
|
+
const decoded = outputSchema === undefined ? stream : Stream.mapEffect(stream, (value) => Schema.decodeUnknownEffect(outputSchema)(value));
|
|
11
|
+
return await runtime.runStream(decoded, {
|
|
13
12
|
procedure: info,
|
|
14
13
|
...(invocation.signal === undefined ? {} : { signal: invocation.signal }),
|
|
15
14
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription-handler.js","sourceRoot":"","sources":["../../src/internal/subscription-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"subscription-handler.js","sourceRoot":"","sources":["../../src/internal/subscription-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,E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AM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC;SACzE,CAAC,CAAC;IACJ,CAAC,CAAC;AACH,CAAC,CAAC"}
|
package/dist/procedure.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import type { TRPCMutationProcedure,
|
|
1
|
+
import type { TRPCMutationProcedure, TRPCQueryProcedure, TRPCSubscriptionProcedure } from "@trpc/server";
|
|
2
2
|
import { Schema } from "effect";
|
|
3
|
-
import type { DefaultValue, EffectProcedureResolver, EffectSubscriptionResolver, IntersectIfDefined, ResolverContext } from "./internal/procedure-types.
|
|
4
|
-
import type { RuntimeBridge } from "./internal/runtime.
|
|
5
|
-
import type { EffectProcedureRequestServices } from "./request-services.
|
|
6
|
-
type Builder<Context, Meta, ContextOverrides, InputIn, InputOut, OutputIn, OutputOut> = TRPCProcedureBuilder<Context, Meta, ContextOverrides, InputIn, InputOut, OutputIn, OutputOut, false>;
|
|
3
|
+
import type { DefaultValue, EffectProcedureResolver, EffectSubscriptionResolver, IntersectIfDefined, ProcedureBuilderSurface, ResolverContext } from "./internal/procedure-types.ts";
|
|
4
|
+
import type { RuntimeBridge } from "./internal/runtime.ts";
|
|
5
|
+
import type { EffectProcedureRequestServices } from "./request-services.ts";
|
|
7
6
|
export declare class EffectProcedureBuilder<Context, Meta, ContextOverrides, InputIn, InputOut, OutputIn, OutputOut, ProvidedServices, LayerError, RuntimeRequirements> {
|
|
8
7
|
private readonly builder;
|
|
9
8
|
private readonly requestServices;
|
|
10
9
|
private readonly runtime;
|
|
11
10
|
private readonly subscriptionBuilder;
|
|
12
11
|
private readonly subscriptionOutput?;
|
|
13
|
-
constructor(builder:
|
|
12
|
+
constructor(builder: ProcedureBuilderSurface<ResolverContext<Context, Meta, ContextOverrides>>, requestServices: EffectProcedureRequestServices<ResolverContext<Context, Meta, ContextOverrides>, ProvidedServices, LayerError>, runtime: RuntimeBridge<RuntimeRequirements>, subscriptionBuilder?: ProcedureBuilderSurface<ResolverContext<Context, Meta, ContextOverrides>>, subscriptionOutput?: Schema.ConstraintDecoder<unknown> | undefined);
|
|
14
13
|
input<SchemaValue extends Schema.ConstraintDecoder<unknown>>(schema: SchemaValue): EffectProcedureBuilder<Context, Meta, ContextOverrides, IntersectIfDefined<InputIn, SchemaValue["Encoded"]>, IntersectIfDefined<InputOut, SchemaValue["Type"]>, OutputIn, OutputOut, ProvidedServices, LayerError, RuntimeRequirements>;
|
|
15
14
|
output<SchemaValue extends Schema.ConstraintDecoder<unknown>>(schema: SchemaValue): EffectProcedureBuilder<Context, Meta, ContextOverrides, InputIn, InputOut, IntersectIfDefined<OutputIn, SchemaValue["Encoded"]>, IntersectIfDefined<OutputOut, SchemaValue["Type"]>, ProvidedServices, LayerError, RuntimeRequirements>;
|
|
16
15
|
query<Output>(resolver: EffectProcedureResolver<DefaultValue<InputOut, undefined>, ProvidedServices | NoInfer<RuntimeRequirements>, DefaultValue<OutputIn, Output>>): TRPCQueryProcedure<{
|
|
@@ -28,7 +27,6 @@ export declare class EffectProcedureBuilder<Context, Meta, ContextOverrides, Inp
|
|
|
28
27
|
output: AsyncIterable<DefaultValue<OutputOut, Output>, void, unknown>;
|
|
29
28
|
meta: Meta;
|
|
30
29
|
}>;
|
|
31
|
-
private
|
|
30
|
+
private handler;
|
|
32
31
|
}
|
|
33
|
-
export {};
|
|
34
32
|
//# sourceMappingURL=procedure.d.ts.map
|
package/dist/procedure.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"procedure.d.ts","sourceRoot":"","sources":["../src/procedure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"procedure.d.ts","sourceRoot":"","sources":["../src/procedure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;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,CACnC,YAAY,CAAC,QAAQ,EAAE,SAAS,CAAC,EACjC,gBAAgB,GAAG,OAAO,CAAC,mBAAmB,CAAC,EAC/C,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAC9B,GACC,yBAAyB,CAAC;QAC5B,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACnC,MAAM,EAAE,aAAa,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACtE,IAAI,EAAE,IAAI,CAAC;KACX,CAAC;IAaF,OAAO,CAAC,OAAO;CAGf"}
|
package/dist/procedure.js
CHANGED
|
@@ -16,32 +16,23 @@ export class EffectProcedureBuilder {
|
|
|
16
16
|
this.subscriptionOutput = subscriptionOutput;
|
|
17
17
|
}
|
|
18
18
|
input(schema) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
return new EffectProcedureBuilder(next, this.requestServices, this.runtime, subscriptionNext, this.subscriptionOutput);
|
|
19
|
+
const parser = Schema.toStandardSchemaV1(schema);
|
|
20
|
+
return new EffectProcedureBuilder(this.builder.input(parser), this.requestServices, this.runtime, this.subscriptionBuilder.input(parser), this.subscriptionOutput);
|
|
22
21
|
}
|
|
23
22
|
output(schema) {
|
|
24
|
-
|
|
25
|
-
return new EffectProcedureBuilder(next, this.requestServices, this.runtime, this.subscriptionBuilder, schema);
|
|
23
|
+
return new EffectProcedureBuilder(this.builder.output(Schema.toStandardSchemaV1(schema)), this.requestServices, this.runtime, this.subscriptionBuilder, schema);
|
|
26
24
|
}
|
|
27
25
|
query(resolver) {
|
|
28
|
-
return this.
|
|
26
|
+
return this.builder.query(this.handler("query", resolver));
|
|
29
27
|
}
|
|
30
28
|
mutation(resolver) {
|
|
31
|
-
return this.
|
|
29
|
+
return this.builder.mutation(this.handler("mutation", resolver));
|
|
32
30
|
}
|
|
33
31
|
subscription(resolver) {
|
|
34
|
-
|
|
35
|
-
captureStackTrace: captureStackTrace(),
|
|
36
|
-
type: "subscription",
|
|
37
|
-
}, this.subscriptionOutput);
|
|
38
|
-
return this.subscriptionBuilder.subscription(handler);
|
|
32
|
+
return this.subscriptionBuilder.subscription(makeSubscriptionHandler(this.runtime, resolver, this.requestServices, { captureStackTrace: captureStackTrace(), type: "subscription" }, this.subscriptionOutput));
|
|
39
33
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return type === "query"
|
|
43
|
-
? this.builder.query(handler)
|
|
44
|
-
: this.builder.mutation(handler);
|
|
34
|
+
handler(type, resolver) {
|
|
35
|
+
return makeProcedureHandler(this.runtime, resolver, this.requestServices, { captureStackTrace: captureStackTrace(), type });
|
|
45
36
|
}
|
|
46
37
|
}
|
|
47
38
|
//# sourceMappingURL=procedure.js.map
|
package/dist/procedure.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"procedure.js","sourceRoot":"","sources":["../src/procedure.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"procedure.js","sourceRoot":"","sources":["../src/procedure.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAUvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAG7E,MAAM,OAAO,sBAAsB;IAahB;IACA;IACA;IACA;IACA;IALlB,YACkB,OAAkF,EAClF,eAA+H,EAC/H,OAA2C,EAC3C,sBAAsB,OAAO,EAC7B,kBAAsD;QAJtD,YAAO,GAAP,OAAO,CAA2E;QAClF,oBAAe,GAAf,eAAe,CAAgH;QAC/H,YAAO,GAAP,OAAO,CAAoC;QAC3C,wBAAmB,GAAnB,mBAAmB,CAAU;QAC7B,uBAAkB,GAAlB,kBAAkB,CAAoC;IACrE,CAAC;IAEJ,KAAK,CACJ,M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CAAC,eAAe,EAAE,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7H,CAAC;CACD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type TRPCDefaultErrorShape, type TRPCError } from "@trpc/server";
|
|
2
|
+
import type { EncodedRejection } from "./client/rejection.ts";
|
|
3
|
+
export interface RejectionData {
|
|
4
|
+
readonly rejection?: EncodedRejection;
|
|
5
|
+
}
|
|
6
|
+
export type RejectionErrorShape = TRPCDefaultErrorShape & {
|
|
7
|
+
readonly data: RejectionData;
|
|
8
|
+
};
|
|
9
|
+
export declare const withRejection: <Shape extends {
|
|
10
|
+
readonly data: object;
|
|
11
|
+
}>(shape: Shape, error: TRPCError) => Shape & {
|
|
12
|
+
readonly data: RejectionData;
|
|
13
|
+
};
|
|
14
|
+
export declare const rejectionFormatter: ({ shape, error }: {
|
|
15
|
+
readonly shape: TRPCDefaultErrorShape;
|
|
16
|
+
readonly error: TRPCError;
|
|
17
|
+
}) => RejectionErrorShape;
|
|
18
|
+
//# sourceMappingURL=rejection-formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rejection-formatter.d.ts","sourceRoot":"","sources":["../src/rejection-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,qBAAqB,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AACjG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC;CACtC;AAED,MAAM,MAAM,mBAAmB,GAAG,qBAAqB,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC;AAkB3F,eAAO,MAAM,aAAa,GAAI,KAAK,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,OAAO,KAAK,EAAE,OAAO,SAAS,KAAG,KAAK,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAA;CAG7I,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,kBAAkB;IAAE,QAAQ,CAAC,KAAK,EAAE,qBAAqB,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;CAAE,KAAG,mBAChG,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { StandardSchemaV1Error } from "@trpc/server";
|
|
2
|
+
import { RejectionError } from "./rejection.js";
|
|
3
|
+
const inputRejection = ({ issues: [issue] }) => {
|
|
4
|
+
if (issue === undefined)
|
|
5
|
+
return undefined;
|
|
6
|
+
const field = (issue.path ?? []).map((segment) => String(typeof segment === "object" ? segment.key : segment)).join(".");
|
|
7
|
+
return field === ""
|
|
8
|
+
? { _tag: "BadRequest", message: issue.message, invalidInput: true }
|
|
9
|
+
: { _tag: "BadRequest", message: issue.message, field, invalidInput: true };
|
|
10
|
+
};
|
|
11
|
+
const declared = ({ invalidInput: _reserved, ...rejection }) => rejection;
|
|
12
|
+
const rejectionFrom = (error) => {
|
|
13
|
+
if (error instanceof RejectionError)
|
|
14
|
+
return declared(error.rejection);
|
|
15
|
+
if (error.code === "BAD_REQUEST" && error.cause instanceof StandardSchemaV1Error)
|
|
16
|
+
return inputRejection(error.cause);
|
|
17
|
+
return undefined;
|
|
18
|
+
};
|
|
19
|
+
export const withRejection = (shape, error) => {
|
|
20
|
+
const rejection = rejectionFrom(error);
|
|
21
|
+
return rejection === undefined ? shape : { ...shape, data: { ...shape.data, rejection } };
|
|
22
|
+
};
|
|
23
|
+
export const rejectionFormatter = ({ shape, error }) => withRejection(shape, error);
|
|
24
|
+
//# sourceMappingURL=rejection-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rejection-formatter.js","sourceRoot":"","sources":["../src/rejection-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,E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a,GAAG,CAA0C,KAAY,EAAE,KAAgB,EAA4C,EAAE;IAClJ,MAAM,SAAS,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACvC,OAAO,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC;AAC3F,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,EAAwE,EAAuB,EAAE,CACjJ,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type TRPC_ERROR_CODE_KEY, TRPCError } from "@trpc/server";
|
|
2
|
+
import { Effect, Schema } from "effect";
|
|
3
|
+
export declare const rejectionCode: (tag: string) => TRPC_ERROR_CODE_KEY;
|
|
4
|
+
declare const DeclaredRejection: Schema.StructWithRest<Schema.Struct<{
|
|
5
|
+
readonly _tag: Schema.String;
|
|
6
|
+
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
|
|
7
|
+
export type DeclaredRejection = typeof DeclaredRejection.Type;
|
|
8
|
+
interface InvalidInputIsReserved {
|
|
9
|
+
readonly "invalidInput is reserved for the mark on input that did not parse": never;
|
|
10
|
+
}
|
|
11
|
+
interface DeclaredEncoding {
|
|
12
|
+
readonly _tag: string;
|
|
13
|
+
readonly invalidInput?: InvalidInputIsReserved;
|
|
14
|
+
}
|
|
15
|
+
export declare class RejectionError extends TRPCError {
|
|
16
|
+
readonly rejection: DeclaredRejection;
|
|
17
|
+
constructor(rejection: DeclaredRejection, code?: TRPC_ERROR_CODE_KEY);
|
|
18
|
+
}
|
|
19
|
+
export interface RejectWithOptions<Tag extends string> {
|
|
20
|
+
readonly code?: (tag: Tag) => TRPC_ERROR_CODE_KEY;
|
|
21
|
+
}
|
|
22
|
+
export declare function rejectWith<S extends Schema.ConstraintCodec<{
|
|
23
|
+
readonly _tag: string;
|
|
24
|
+
}, DeclaredEncoding, unknown, unknown>>(schema: S, options?: RejectWithOptions<S["Type"]["_tag"]>): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, Exclude<E, S["Type"]> | RejectionError, R | S["EncodingServices"]>;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=rejection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rejection.d.ts","sourceRoot":"","sources":["../src/rejection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAYxC,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,KAAG,mBAA+D,CAAC;AAE5G,QAAA,MAAM,iBAAiB;;6DAAgH,CAAC;AAExI,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAC,IAAI,CAAC;AAE9D,UAAU,sBAAsB;IAC/B,QAAQ,CAAC,mEAAmE,EAAE,KAAK,CAAC;CACpF;AAED,UAAU,gBAAgB;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,YAAY,CAAC,EAAE,sBAAsB,CAAC;CAC/C;AAED,qBAAa,cAAe,SAAQ,SAAS;IAC5C,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;gBAE1B,SAAS,EAAE,iBAAiB,EAAE,IAAI,GAAE,mBAAmD;CAInG;AAED,MAAM,WAAW,iBAAiB,CAAC,GAAG,SAAS,MAAM;IACpD,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,mBAAmB,CAAC;CAClD;AAQD,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,eAAe,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,gBAAgB,EAAE,OAAO,EAAE,OAAO,CAAC,EACzH,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,GAC5C,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,cAAc,EAAE,CAAC,GAAG,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { TRPCError } from "@trpc/server";
|
|
2
|
+
import { Effect, Schema } from "effect";
|
|
3
|
+
const TAXONOMY_CODES = new Map([
|
|
4
|
+
["NotFound", "NOT_FOUND"],
|
|
5
|
+
["Unauthorized", "UNAUTHORIZED"],
|
|
6
|
+
["Forbidden", "FORBIDDEN"],
|
|
7
|
+
["Conflict", "CONFLICT"],
|
|
8
|
+
["PreconditionFailed", "PRECONDITION_FAILED"],
|
|
9
|
+
["TooManyRequests", "TOO_MANY_REQUESTS"],
|
|
10
|
+
["AuthUnavailable", "SERVICE_UNAVAILABLE"],
|
|
11
|
+
]);
|
|
12
|
+
export const rejectionCode = (tag) => TAXONOMY_CODES.get(tag) ?? "BAD_REQUEST";
|
|
13
|
+
const DeclaredRejection = Schema.StructWithRest(Schema.Struct({ _tag: Schema.String }), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
14
|
+
export class RejectionError extends TRPCError {
|
|
15
|
+
rejection;
|
|
16
|
+
constructor(rejection, code = rejectionCode(rejection._tag)) {
|
|
17
|
+
super({ code, message: typeof rejection.message === "string" ? rejection.message : rejection._tag });
|
|
18
|
+
this.rejection = rejection;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const encodeRejection = (schema) => {
|
|
22
|
+
const encode = Schema.encodeUnknownEffect(schema);
|
|
23
|
+
const tagged = Schema.decodeUnknownEffect(DeclaredRejection);
|
|
24
|
+
return (rejection) => Effect.orDie(Effect.flatMap(encode(rejection), tagged));
|
|
25
|
+
};
|
|
26
|
+
export function rejectWith(schema, options) {
|
|
27
|
+
const is = Schema.is(schema);
|
|
28
|
+
const encode = encodeRejection(schema);
|
|
29
|
+
const code = options?.code ?? rejectionCode;
|
|
30
|
+
return (self) => Effect.catchIf(self, is, (rejection) => Effect.flatMap(encode(rejection), (encoded) => Effect.fail(new RejectionError(encoded, code(encoded._tag)))));
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=rejection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rejection.js","sourceRoot":"","sources":["../src/rejection.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,SAAS,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,cAAc,GAAG,IAAI,GAAG,CAA8B;IAC3D,CAAC,UAAU,EAAE,WAAW,CAAC;IACzB,CAAC,cAAc,EAAE,cAAc,CAAC;IAChC,CAAC,WAAW,EAAE,WAAW,CAAC;IAC1B,CAAC,UAAU,EAAE,UAAU,CAAC;IACxB,CAAC,oBAAoB,EAAE,qBAAqB,CAAC;IAC7C,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;IACxC,CAAC,iBAAiB,EAAE,qBAAqB,CAAC;CAC1C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAW,EAAuB,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,aAAa,CAAC;AAE5G,MAAM,iBAAiB,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,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C,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAC5G,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-services.d.ts","sourceRoot":"","sources":["../src/request-services.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,IAAI,WAAW,EAAS,MAAM,QAAQ,CAAC;AAE1D,MAAM,WAAW,8BAA8B,
|
|
1
|
+
{"version":3,"file":"request-services.d.ts","sourceRoot":"","sources":["../src/request-services.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,IAAI,WAAW,EAAS,MAAM,QAAQ,CAAC;AAE1D,MAAM,WAAW,8BAA8B,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,GAAG,KAAK;IACnF,QAAQ,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,WAAW,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;CAC7E;AAED,eAAO,MAAM,mBAAmB,GAAI,OAAO,EAAE,YAAY,EAAE,KAAK,GAAG,KAAK,EACvE,OAAO,CAAC,OAAO,EAAE,OAAO,KAAK,WAAW,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,KACjE,8BAA8B,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,CAAgB,CAAC;AAE/E,eAAO,MAAM,qBAAqB,GACjC,WAAW,EACX,OAAO,SAAS,WAAW,EAC3B,gBAAgB,EAChB,SAAS,EACT,sBAAsB,EACtB,eAAe,EACf,sBAAsB,SAAS,gBAAgB,GAAG,gBAAgB,EAElE,MAAM,8BAA8B,CAAC,WAAW,EAAE,gBAAgB,EAAE,SAAS,CAAC,EAC9E,YAAY,CAAC,OAAO,EAAE,OAAO,KAAK,WAAW,CAAC,KAAK,CAAC,sBAAsB,EAAE,eAAe,EAAE,sBAAsB,CAAC,KAClH,8BAA8B,CAAC,OAAO,EAAE,gBAAgB,GAAG,sBAAsB,EAAE,SAAS,GAAG,eAAe,CACT,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-services.js","sourceRoot":"","sources":["../src/request-services.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"request-services.js","sourceRoot":"","sources":["../src/request-services.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,EAAE,MAAM,QAAQ,CAAC;AAM1D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAClC,KAAmE,EACJ,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AAE/E,MAAM,CAAC,MAAM,qBAAqB,GAAG,CASpC,IAA8E,EAC9E,UAAoH,EACF,EAAE,CACpH,mBAAmB,CAAC,CAAC,OAAgB,EAAE,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-signal.d.ts","sourceRoot":"","sources":["../src/request-signal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,wEAAwE;AACxE,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"request-signal.d.ts","sourceRoot":"","sources":["../src/request-signal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,wEAAwE;AACxE,eAAO,MAAM,aAAa,4CAAwH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-signal.js","sourceRoot":"","sources":["../src/request-signal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,wEAAwE;AACxE,MAAM,CAAC,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,
|
|
1
|
+
{"version":3,"file":"request-signal.js","sourceRoot":"","sources":["../src/request-signal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,wEAAwE;AACxE,MAAM,CAAC,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,CAA0B,sCAAsC,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"any-test-layer.d.ts","sourceRoot":"","sources":["../../src/testing/any-test-layer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEpC,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"any-test-layer.js","sourceRoot":"","sources":["../../src/testing/any-test-layer.ts"],"names":[],"mappings":""}
|
package/dist/testing/caller.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type TRPCError } from "@trpc/server";
|
|
2
2
|
import { type Context, Effect } from "effect";
|
|
3
|
-
import type { EffectTRPCAdapter } from "../adapter.
|
|
3
|
+
import type { EffectTRPCAdapter } from "../adapter.ts";
|
|
4
4
|
export type EffectCaller<Caller> = {
|
|
5
5
|
readonly [Key in keyof Caller]: Caller[Key] extends (...arguments_: infer Arguments) => Promise<infer Result> ? (...arguments_: Arguments) => Effect.Effect<Result, TRPCError> : Caller[Key] extends (...arguments_: infer Arguments) => infer Result ? (...arguments_: Arguments) => Result : Caller[Key] extends Record<string, unknown> ? EffectCaller<Caller[Key]> : Caller[Key];
|
|
6
6
|
};
|
|
7
7
|
export type EffectCallerFactory<Options, Caller> = EffectCaller<Caller> & ((options?: Options) => EffectCaller<Caller>);
|
|
8
|
-
|
|
9
|
-
export declare
|
|
8
|
+
type Adapter = Pick<EffectTRPCAdapter<never>, "runWithServices">;
|
|
9
|
+
export declare function makeEffectCaller<Caller extends object, Services>(adapter: Adapter, promiseCaller: Caller, services: Context.Context<Services>): EffectCaller<Caller>;
|
|
10
|
+
export declare function makeEffectCallerFactory<Options, Caller extends object, Services>(adapter: Adapter, createCaller: (options?: Options) => Caller, services: Context.Context<Services>): EffectCallerFactory<Options, Caller>;
|
|
11
|
+
export {};
|
|
10
12
|
//# sourceMappingURL=caller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caller.d.ts","sourceRoot":"","sources":["../../src/testing/caller.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,MAAM,MAAM,YAAY,CAAC,MAAM,IAAI;IAClC,QAAQ,EAAE,GAAG,IAAI,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,
|
|
1
|
+
{"version":3,"file":"caller.d.ts","sourceRoot":"","sources":["../../src/testing/caller.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,MAAM,MAAM,YAAY,CAAC,MAAM,IAAI;IAClC,QAAQ,EAAE,GAAG,IAAI,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CA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@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { getTRPCErrorFromUnknown } from "@trpc/server";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
|
-
|
|
3
|
+
const member = (node, segment) => (typeof node === "object" && node !== null) || typeof node === "function" ? Reflect.get(node, segment) : undefined;
|
|
4
|
+
const invoke = (promiseCaller, path, argumentsList) => {
|
|
5
|
+
const leaf = path.reduce(member, promiseCaller);
|
|
6
|
+
return typeof leaf === "function"
|
|
7
|
+
? Promise.resolve(Reflect.apply(leaf, undefined, argumentsList))
|
|
8
|
+
: Promise.reject(new TypeError(`${path.join(".")} is not a procedure`));
|
|
9
|
+
};
|
|
10
|
+
export function makeEffectCaller(adapter, promiseCaller, services) {
|
|
4
11
|
const build = (path) => new Proxy(Object.assign(() => undefined, { path }), {
|
|
5
12
|
apply(_target, _this, argumentsList) {
|
|
6
13
|
return Effect.tryPromise({
|
|
7
14
|
catch: getTRPCErrorFromUnknown,
|
|
8
|
-
try: () => adapter.runWithServices(services, () =>
|
|
9
|
-
let leaf = promiseCaller;
|
|
10
|
-
for (const segment of path) {
|
|
11
|
-
leaf = leaf[segment];
|
|
12
|
-
}
|
|
13
|
-
return leaf(...argumentsList);
|
|
14
|
-
}),
|
|
15
|
+
try: () => adapter.runWithServices(services, () => invoke(promiseCaller, path, argumentsList)),
|
|
15
16
|
});
|
|
16
17
|
},
|
|
17
18
|
get(_target, property) {
|
|
@@ -22,8 +23,8 @@ export const makeEffectCaller = (adapter, promiseCaller, services) => {
|
|
|
22
23
|
},
|
|
23
24
|
});
|
|
24
25
|
return build([]);
|
|
25
|
-
}
|
|
26
|
-
export
|
|
26
|
+
}
|
|
27
|
+
export function makeEffectCallerFactory(adapter, createCaller, services) {
|
|
27
28
|
const defaultCaller = makeEffectCaller(adapter, createCaller(), services);
|
|
28
29
|
const target = (options) => makeEffectCaller(adapter, createCaller(options), services);
|
|
29
30
|
return new Proxy(target, {
|
|
@@ -37,5 +38,5 @@ export const makeEffectCallerFactory = (adapter, createCaller, services) => {
|
|
|
37
38
|
return Reflect.get(defaultCaller, property);
|
|
38
39
|
},
|
|
39
40
|
});
|
|
40
|
-
}
|
|
41
|
+
}
|
|
41
42
|
//# sourceMappingURL=caller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caller.js","sourceRoot":"","sources":["../../src/testing/caller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAkB,MAAM,cAAc,CAAC;AACvE,OAAO,EAAgB,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"caller.js","sourceRoot":"","sources":["../../src/testing/caller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAkB,MAAM,cAAc,CAAC;AACvE,OAAO,EAAgB,MAAM,EAAE,MAAM,QAAQ,CAAC;AAiB9C,MAAM,MAAM,GAAG,CAAC,IAAa,EAAE,OAAe,EAAW,EAAE,CAC1D,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAEpH,MAAM,MAAM,GAAG,CAAC,aAAqB,EAAE,IAA2B,EAAE,aAAqC,EAAoB,EAAE;IAC9H,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAU,MAAM,EAAE,aAAa,CAAC,CAAC;IACzD,OAAO,OAAO,IAAI,KAAK,UAAU;QAChC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;QAChE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC,CAAC;AAC1E,CAAC,CAAC;AA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CAAC;gBACzB,OAAO,SAAS,CAAC;YAClB,CAAC;YACD,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;gBAClC,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;YACjD,CAAC;YACD,OAAO,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;QAC7C,CAAC;KACD,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/testing/types.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { TestContext, Vitest } from "@effect/vitest";
|
|
2
2
|
import type { EffectClock, EffectTestOptions } from "@shivaedev/effect-test";
|
|
3
3
|
import type { Effect, Layer } from "effect";
|
|
4
|
-
import type { EffectTRPCAdapter } from "../adapter.
|
|
5
|
-
import type {
|
|
4
|
+
import type { EffectTRPCAdapter } from "../adapter.ts";
|
|
5
|
+
import type { AnyTestLayer } from "./any-test-layer.ts";
|
|
6
|
+
import type { EffectCallerFactory } from "./caller.ts";
|
|
6
7
|
export type TrpcHarnessTest<Harness, Provided> = <A, Eff extends Effect.Effect<unknown, unknown, Provided>>(name: string, body: (harness: Harness, context: TestContext) => Generator<Eff, A, never>, options?: number | EffectTestOptions) => void;
|
|
7
8
|
export interface TrpcHarnessTester<Harness, Provided> extends TrpcHarnessTest<Harness, Provided> {
|
|
8
9
|
readonly skip: TrpcHarnessTest<Harness, Provided>;
|
|
@@ -20,14 +21,14 @@ export type TrpcIt<Options, Caller, Provided> = Vitest.Methods & {
|
|
|
20
21
|
export type TrpcHarnessIt<Harness, Provided> = Vitest.Methods & {
|
|
21
22
|
readonly effectTRPC: TrpcHarnessTester<Harness, Provided>;
|
|
22
23
|
};
|
|
23
|
-
export interface MakeTrpcItOptions<CreateCaller extends (...arguments_: never[]) => object, TestLayer extends
|
|
24
|
+
export interface MakeTrpcItOptions<CreateCaller extends (...arguments_: never[]) => object, TestLayer extends AnyTestLayer> {
|
|
24
25
|
readonly adapter: Pick<EffectTRPCAdapter<never>, "runWithServices">;
|
|
25
26
|
readonly around?: <A, E>(effect: Effect.Effect<A, E, Layer.Success<TestLayer>>) => Effect.Effect<A, unknown, Layer.Success<TestLayer>>;
|
|
26
27
|
readonly clock?: EffectClock;
|
|
27
28
|
readonly createCaller: CreateCaller;
|
|
28
29
|
readonly layer: TestLayer;
|
|
29
30
|
}
|
|
30
|
-
export interface MakeTrpcHarnessItOptions<CreateCaller extends (...arguments_: never[]) => object, TestLayer extends
|
|
31
|
+
export interface MakeTrpcHarnessItOptions<CreateCaller extends (...arguments_: never[]) => object, TestLayer extends AnyTestLayer, Harness> extends MakeTrpcItOptions<CreateCaller, TestLayer> {
|
|
31
32
|
readonly makeHarness: (trpc: EffectCallerFactory<CallerOptions<CreateCaller>, CallerResult<CreateCaller>>, context: TestContext) => Effect.Effect<Harness, unknown, Layer.Success<TestLayer>>;
|
|
32
33
|
}
|
|
33
34
|
export type CallerOptions<CreateCaller> = CreateCaller extends (...arguments_: infer Arguments) => object ? Arguments[0] : never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/testing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,MAAM,eAAe,CAAC,OAAO,EAAE,QAAQ,IAAI,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/testing/types.ts"],"names":[],"mappings":"AAAA,OAAO,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,GACN,KAAK,GACN,KAAK,CAAC"}
|
package/dist/testing/vitest.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Layer } from "effect";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
export declare
|
|
2
|
+
import type { AnyTestLayer } from "./any-test-layer.ts";
|
|
3
|
+
import type { CallerOptions, CallerResult, MakeTrpcHarnessItOptions, MakeTrpcItOptions, TrpcHarnessIt, TrpcIt } from "./types.ts";
|
|
4
|
+
export declare function makeTrpcHarnessIt<CreateCaller extends (...arguments_: never[]) => object, TestLayer extends AnyTestLayer, Harness>(options: MakeTrpcHarnessItOptions<CreateCaller, TestLayer, Harness>): TrpcHarnessIt<Harness, Layer.Success<TestLayer>>;
|
|
5
|
+
export declare const makeTrpcIt: <CreateCaller extends (...arguments_: never[]) => object, TestLayer extends AnyTestLayer>(options: MakeTrpcItOptions<CreateCaller, TestLayer>) => TrpcIt<CallerOptions<CreateCaller>, CallerResult<CreateCaller>, Layer.Success<TestLayer>>;
|
|
5
6
|
//# sourceMappingURL=vitest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest.d.ts","sourceRoot":"","sources":["../../src/testing/vitest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"vitest.d.ts","sourceRoot":"","sources":["../../src/testing/vitest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAclI,wBAAgB,iBAAiB,CAAC,YAAY,SAAS,CAAC,GAAG,UAAU,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,SAAS,SAAS,YAAY,EAAE,OAAO,EACjI,OAAO,EAAE,wBAAwB,CAAC,YAAY,EAAE,SAAS,EAAE,OAAO,CAAC,GACjE,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;AAmBpD,eAAO,MAAM,UAAU,GAAI,YAAY,SAAS,CAAC,GAAG,UAAU,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,SAAS,SAAS,YAAY,EACjH,SAAS,iBAAiB,CAAC,YAAY,EAAE,SAAS,CAAC,KACjD,MAAM,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAIxF,CAAC"}
|
package/dist/testing/vitest.js
CHANGED
|
@@ -2,30 +2,29 @@ import { it as effectIt } from "@effect/vitest";
|
|
|
2
2
|
import { makeEffectIt } from "@shivaedev/effect-test";
|
|
3
3
|
import { Effect } from "effect";
|
|
4
4
|
import { makeEffectCallerFactory } from "./caller.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
5
|
+
function withEffectTRPC(tester) {
|
|
6
|
+
return new Proxy(effectIt, {
|
|
7
|
+
get(target, property, receiver) {
|
|
8
|
+
if (property === "effectTRPC") {
|
|
9
|
+
return tester;
|
|
10
|
+
}
|
|
11
|
+
return Reflect.get(target, property, receiver);
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export function makeTrpcHarnessIt(options) {
|
|
14
16
|
const { effectApp } = makeEffectIt({
|
|
15
17
|
around: options.around,
|
|
16
18
|
clock: options.clock,
|
|
17
19
|
layer: options.layer,
|
|
18
20
|
makeHarness: (context) => Effect.gen(function* () {
|
|
19
21
|
const services = yield* Effect.context();
|
|
20
|
-
const trpc = makeEffectCallerFactory(options.adapter,
|
|
21
|
-
// CreateCaller is a rest-never function type. The option and
|
|
22
|
-
// result aliases are the factory TypeScript cannot recover here.
|
|
23
|
-
options.createCaller, services);
|
|
22
|
+
const trpc = makeEffectCallerFactory(options.adapter, options.createCaller, services);
|
|
24
23
|
return yield* options.makeHarness(trpc, context);
|
|
25
24
|
}),
|
|
26
25
|
});
|
|
27
26
|
return withEffectTRPC(effectApp);
|
|
28
|
-
}
|
|
27
|
+
}
|
|
29
28
|
export const makeTrpcIt = (options) => makeTrpcHarnessIt({
|
|
30
29
|
...options,
|
|
31
30
|
makeHarness: (trpc) => Effect.succeed(trpc),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest.js","sourceRoot":"","sources":["../../src/testing/vitest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,QAAQ,EAAe,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAc,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"vitest.js","sourceRoot":"","sources":["../../src/testing/vitest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,QAAQ,EAAe,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAc,MAAM,QAAQ,CAAC;AAE5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAItD,SAAS,cAAc,CAAC,MAAe;IACtC,OAAO,IAAI,KAAK,CAAC,QAAQ,EAAE;QAC1B,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ;YAC7B,IAAI,QAAQ,KAAK,YAAY,EAAE,CAAC;gBAC/B,OAAO,MAAM,CAAC;YACf,CAAC;YACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAChD,CAAC;KACD,CAAC,CAAC;AACJ,CAAC;AAKD,MAAM,UAAU,iBAAiB,CAChC,OAAoF;IAEpF,MAAM,EAAE,SAAS,EAAE,GAAG,YAAY,CAAC;QAClC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE,CACxB,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;YACnB,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,EAA4B,CAAC;YACnE,MAAM,IAAI,GAAG,uBAAuB,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;YACtF,OAAO,KAAK,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAClD,CAAC,CAAC;KACH,CAAC,CAAC;IAEH,OAAO,cAAc,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CACzB,OAAmD,EACyC,EAAE,CAC9F,iBAAiB,CAAC;IACjB,GAAG,OAAO;IACV,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;CAC3C,CAAC,CAAC"}
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { type EffectCaller, type EffectCallerFactory, makeEffectCaller, makeEffectCallerFactory, } from "./testing/caller.
|
|
2
|
-
export type { CallerOptions, CallerResult, MakeTrpcHarnessItOptions, MakeTrpcItOptions, TrpcHarnessIt, TrpcHarnessTest, TrpcHarnessTester, TrpcIt, TrpcTest, TrpcTester, } from "./testing/types.
|
|
3
|
-
export { makeTrpcHarnessIt, makeTrpcIt } from "./testing/vitest.
|
|
1
|
+
export { type EffectCaller, type EffectCallerFactory, makeEffectCaller, makeEffectCallerFactory, } from "./testing/caller.ts";
|
|
2
|
+
export type { CallerOptions, CallerResult, MakeTrpcHarnessItOptions, MakeTrpcItOptions, TrpcHarnessIt, TrpcHarnessTest, TrpcHarnessTester, TrpcIt, TrpcTest, TrpcTester, } from "./testing/types.ts";
|
|
3
|
+
export { makeTrpcHarnessIt, makeTrpcIt } from "./testing/vitest.ts";
|
|
4
4
|
//# sourceMappingURL=testing.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE7C,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,OAAO,GAAG,cAAc,CAAC;AAElE,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IACrD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;CAC7B;AAED,MAAM,WAAW,sBAAuB,SAAQ,aAAa;IAC5D,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAC;CACtC;AAED,MAAM,MAAM,qBAAqB,GAAG,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE7C,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,OAAO,GAAG,cAAc,CAAC;AAElE,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IACrD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;CAC7B;AAED,MAAM,WAAW,sBAAuB,SAAQ,aAAa;IAC5D,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAC;CACtC;AAED,MAAM,MAAM,qBAAqB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,sBAAsB,KAAK,SAAS,GAAG,SAAS,CAAC;AAE/G,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,aAAa,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAEjI,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,aAAa,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/effect-trpc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Effect-native procedures and testing for tRPC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,6 +30,12 @@
|
|
|
30
30
|
"import": "./dist/index.js",
|
|
31
31
|
"default": "./dist/index.js"
|
|
32
32
|
},
|
|
33
|
+
"./client": {
|
|
34
|
+
"types": "./dist/client.d.ts",
|
|
35
|
+
"source": "./src/client.ts",
|
|
36
|
+
"import": "./dist/client.js",
|
|
37
|
+
"default": "./dist/client.js"
|
|
38
|
+
},
|
|
33
39
|
"./testing": {
|
|
34
40
|
"types": "./dist/testing.d.ts",
|
|
35
41
|
"source": "./src/testing.ts",
|
|
@@ -43,7 +49,7 @@
|
|
|
43
49
|
"provenance": true
|
|
44
50
|
},
|
|
45
51
|
"dependencies": {
|
|
46
|
-
"@shivaedev/effect-test": "0.1.
|
|
52
|
+
"@shivaedev/effect-test": "0.1.2"
|
|
47
53
|
},
|
|
48
54
|
"peerDependencies": {
|
|
49
55
|
"@effect/vitest": "4.0.0-rc.112",
|
|
@@ -57,12 +63,15 @@
|
|
|
57
63
|
},
|
|
58
64
|
"devDependencies": {
|
|
59
65
|
"@effect/vitest": "4.0.0-rc.112",
|
|
66
|
+
"@trpc/client": "11.18.0",
|
|
60
67
|
"@trpc/server": "11.18.0",
|
|
61
68
|
"@types/node": "24.10.1",
|
|
62
69
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
63
70
|
"effect": "4.0.0-rc.112",
|
|
71
|
+
"superjson": "2.2.6",
|
|
64
72
|
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
65
|
-
"vitest": "4.1.9"
|
|
73
|
+
"vitest": "4.1.9",
|
|
74
|
+
"@shivaedev/effect-contract": "0.1.0"
|
|
66
75
|
},
|
|
67
76
|
"scripts": {
|
|
68
77
|
"build": "node --eval \"import('node:fs').then(({ rmSync }) => rmSync('dist', { force: true, recursive: true }))\" && tsc6 --project tsconfig.build.json",
|