@confect/test 1.0.0-next.0
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 +13 -0
- package/LICENSE +7 -0
- package/dist/TestConfect.d.ts +30 -0
- package/dist/TestConfect.d.ts.map +1 -0
- package/dist/TestConfect.js +68 -0
- package/dist/TestConfect.js.map +1 -0
- package/dist/_virtual/rolldown_runtime.js +13 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/package.json +75 -0
- package/src/TestConfect.ts +269 -0
- package/src/index.ts +1 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright 2024 RJ Dellecese
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Ref } from "@confect/core";
|
|
2
|
+
import { DatabaseSchema, RegisteredFunctions } from "@confect/server";
|
|
3
|
+
import { Context, Effect, Layer, ParseResult, Schema } from "effect";
|
|
4
|
+
import { UserIdentity } from "convex/server";
|
|
5
|
+
import { Value } from "convex/values";
|
|
6
|
+
|
|
7
|
+
//#region src/TestConfect.d.ts
|
|
8
|
+
declare namespace TestConfect_d_exports {
|
|
9
|
+
export { TestConfect, TestConfectWithoutIdentity, layer };
|
|
10
|
+
}
|
|
11
|
+
type TestConfectWithoutIdentity<ConfectSchema extends DatabaseSchema.AnyWithProps> = {
|
|
12
|
+
query: <QueryRef extends Ref.AnyQuery>(queryRef: QueryRef, args: Ref.Args<QueryRef>["Type"]) => Effect.Effect<Ref.Returns<QueryRef>["Type"], ParseResult.ParseError>;
|
|
13
|
+
mutation: <MutationRef extends Ref.AnyMutation>(mutationRef: MutationRef, args: Ref.Args<MutationRef>["Type"]) => Effect.Effect<Ref.Returns<MutationRef>["Type"], ParseResult.ParseError>;
|
|
14
|
+
action: <ActionRef extends Ref.AnyAction>(actionRef: ActionRef, args: Ref.Args<ActionRef>["Type"]) => Effect.Effect<Ref.Returns<ActionRef>["Type"], ParseResult.ParseError>;
|
|
15
|
+
run: {
|
|
16
|
+
<E>(handler: Effect.Effect<void, E, RegisteredFunctions.MutationServices<ConfectSchema>>): Effect.Effect<void>;
|
|
17
|
+
<A, B extends Value, E>(handler: Effect.Effect<A, E, RegisteredFunctions.MutationServices<ConfectSchema>>, returns: Schema.Schema<A, B>): Effect.Effect<A, ParseResult.ParseError>;
|
|
18
|
+
};
|
|
19
|
+
fetch: (pathQueryFragment: string, init?: RequestInit) => Effect.Effect<Response>;
|
|
20
|
+
finishInProgressScheduledFunctions: () => Effect.Effect<void>;
|
|
21
|
+
finishAllScheduledFunctions: (advanceTimers: () => void) => Effect.Effect<void>;
|
|
22
|
+
};
|
|
23
|
+
type TestConfect<ConfectSchema extends DatabaseSchema.AnyWithProps> = {
|
|
24
|
+
withIdentity: (userIdentity: Partial<UserIdentity>) => TestConfectWithoutIdentity<ConfectSchema>;
|
|
25
|
+
} & TestConfectWithoutIdentity<ConfectSchema>;
|
|
26
|
+
declare const TestConfect: <ConfectSchema extends DatabaseSchema.AnyWithProps>() => Context.Tag<TestConfect<ConfectSchema>, TestConfect<ConfectSchema>>;
|
|
27
|
+
declare const layer: <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(databaseSchema: DatabaseSchema_, modules: Record<string, () => Promise<any>>) => () => Layer.Layer<TestConfect<DatabaseSchema_>>;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { TestConfect, TestConfectWithoutIdentity, TestConfect_d_exports, layer };
|
|
30
|
+
//# sourceMappingURL=TestConfect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestConfect.d.ts","names":[],"sources":["../src/TestConfect.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;KAaY,iDACY,cAAA,CAAe;2BAEZ,GAAA,CAAI,oBACjB,gBACJ,GAAA,CAAI,KAAK,sBACZ,MAAA,CAAO,OAAO,GAAA,CAAI,QAAQ,mBAAmB,WAAA,CAAY;iCAC/B,GAAA,CAAI,0BACpB,mBACP,GAAA,CAAI,KAAK,yBACZ,MAAA,CAAO,OAAO,GAAA,CAAI,QAAQ,sBAAsB,WAAA,CAAY;6BACtC,GAAA,CAAI,sBAClB,iBACL,GAAA,CAAI,KAAK,uBACZ,MAAA,CAAO,OAAO,GAAA,CAAI,QAAQ,oBAAoB,WAAA,CAAY;;iBAIlD,MAAA,CAAO,aAEd,GACA,mBAAA,CAAoB,iBAAiB,kBAEtC,MAAA,CAAO;IAvBF,CAAA,CAAA,EAAA,UAwBM,KAxBN,EAAA,CAAA,CAAA,CAAA,OAA0B,EAyBvB,MAAA,CAAO,MAzBgB,CA0B9B,CA1B8B,EA2B9B,CA3B8B,EA4B9B,mBAAA,CAAoB,gBA5BU,CA4BO,aA5BP,CAAA,CAAA,EAAA,OAAA,EA8BvB,MAAA,CAAO,MA9BgB,CA8BT,CA9BS,EA8BN,CA9BM,CAAA,CAAA,EA+B/B,MAAA,CAAO,MA/BwB,CA+BjB,CA/BiB,EA+Bd,WAAA,CAAY,UA/BE,CAAA;EACd,CAAA;EAEG,KAAI,EAAA,CAAA,iBAAA,EAAA,MAAA,EAAA,IAAA,CAAA,EAgCpB,WAhCoB,EAAA,GAiCxB,MAAA,CAAO,MAjCiB,CAiCV,QAjCU,CAAA;EACjB,kCAAA,EAAA,GAAA,GAiC8B,MAAA,CAAO,MAjCrC,CAAA,IAAA,CAAA;EACK,2BAAA,EAAA,CAAA,aAAA,EAAA,GAAA,GAAA,IAAA,EAAA,GAmCZ,MAAA,CAAO,MAnCK,CAAA,IAAA,CAAA;CAAT;AACuB,KAqCrB,WArCqB,CAAA,sBAqCa,cAAA,CAAe,YArC5B,CAAA,GAAA;EAAZ,YAAI,EAAA,CAAA,YAAA,EAuCP,OAvCO,CAuCC,YAvCD,CAAA,EAAA,GAwClB,0BAxCkB,CAwCS,aAxCT,CAAA;CAA2B,GAyChD,0BAzC4D,CAyCjC,aAzCiC,CAAA;AAAzD,cA2CM,WA3CC,EAAA,CAAA,sBA4CU,cAAA,CAAe,YA5CzB,CAAA,GAAA,GA4CqC,OAAA,CAAA,GA5CrC,CA4CqC,WA5CrC,CA4CqC,aA5CrC,CAAA,EA4CqC,WA5CrC,CA4CqC,aA5CrC,CAAA,CAAA;AACuB,cAsOxB,KAtOwB,EAAA,CAAA,wBAuOV,cAAA,CAAe,YAvOL,CAAA,CAAA,cAAA,EAwOjB,eAxOiB,EAAA,OAAA,EAyOxB,MAzOwB,CAAA,MAAA,EAAA,GAAA,GAyOH,OAzOG,CAAA,GAAA,CAAA,CAAA,EAAA,GAAA,GAAA,GA2O/B,KAAA,CAAM,KA3OyB,CA2OnB,WA3OmB,CA2OP,eA3OO,CAAA,CAAA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { __export } from "./_virtual/rolldown_runtime.js";
|
|
2
|
+
import { Ref } from "@confect/core";
|
|
3
|
+
import { RegisteredFunctions } from "@confect/server";
|
|
4
|
+
import { convexTest } from "convex-test";
|
|
5
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
6
|
+
|
|
7
|
+
//#region src/TestConfect.ts
|
|
8
|
+
var TestConfect_exports = /* @__PURE__ */ __export({
|
|
9
|
+
TestConfect: () => TestConfect,
|
|
10
|
+
layer: () => layer
|
|
11
|
+
});
|
|
12
|
+
const TestConfect = () => Context.GenericTag("@confect/test/TestConfect");
|
|
13
|
+
var TestConfectImplWithoutIdentity = class {
|
|
14
|
+
constructor(confectSchema, testConvex) {
|
|
15
|
+
this.confectSchema = confectSchema;
|
|
16
|
+
this.testConvex = testConvex;
|
|
17
|
+
}
|
|
18
|
+
query = (queryRef, args) => Effect.gen(this, function* () {
|
|
19
|
+
const query = Ref.getFunction(queryRef);
|
|
20
|
+
const queryName = Ref.getConvexFunctionName(queryRef);
|
|
21
|
+
const encodedArgs = yield* Schema.encode(query.args)(args);
|
|
22
|
+
const encodedReturns = yield* Effect.promise(() => this.testConvex.query(queryName, encodedArgs));
|
|
23
|
+
return yield* Schema.decode(query.returns)(encodedReturns);
|
|
24
|
+
});
|
|
25
|
+
mutation = (mutationRef, args) => Effect.gen(this, function* () {
|
|
26
|
+
const mutation = Ref.getFunction(mutationRef);
|
|
27
|
+
const mutationName = Ref.getConvexFunctionName(mutationRef);
|
|
28
|
+
const encodedArgs = yield* Schema.encode(mutation.args)(args);
|
|
29
|
+
const encodedReturns = yield* Effect.promise(() => this.testConvex.mutation(mutationName, encodedArgs));
|
|
30
|
+
return yield* Schema.decode(mutation.returns)(encodedReturns);
|
|
31
|
+
});
|
|
32
|
+
action = (actionRef, args) => Effect.gen(this, function* () {
|
|
33
|
+
const action = Ref.getFunction(actionRef);
|
|
34
|
+
const actionName = Ref.getConvexFunctionName(actionRef);
|
|
35
|
+
const encodedArgs = yield* Schema.encode(action.args)(args);
|
|
36
|
+
const encodedReturns = yield* Effect.promise(() => this.testConvex.action(actionName, encodedArgs));
|
|
37
|
+
return yield* Schema.decode(action.returns)(encodedReturns);
|
|
38
|
+
});
|
|
39
|
+
run = ((handler, returns) => {
|
|
40
|
+
const makeMutationLayer = (mutationCtx) => RegisteredFunctions.mutationLayer(this.confectSchema, mutationCtx);
|
|
41
|
+
return returns === void 0 ? Effect.promise(() => this.testConvex.run((mutationCtx) => Effect.runPromise(handler.pipe(Effect.asVoid, Effect.provide(makeMutationLayer(mutationCtx)))))) : Effect.promise(() => this.testConvex.run((mutationCtx) => Effect.runPromise(handler.pipe(Effect.andThen(Schema.encode(returns)), Effect.provide(makeMutationLayer(mutationCtx)))))).pipe(Effect.andThen(Schema.decode(returns)));
|
|
42
|
+
});
|
|
43
|
+
fetch = (pathQueryFragment, init) => Effect.promise(() => this.testConvex.fetch(pathQueryFragment, init));
|
|
44
|
+
finishInProgressScheduledFunctions = () => Effect.promise(() => this.testConvex.finishInProgressScheduledFunctions());
|
|
45
|
+
finishAllScheduledFunctions = (advanceTimers) => Effect.promise(() => this.testConvex.finishAllScheduledFunctions(advanceTimers));
|
|
46
|
+
};
|
|
47
|
+
var TestConfectImpl = class {
|
|
48
|
+
testConfectImplWithoutIdentity;
|
|
49
|
+
constructor(confectSchema, testConvex) {
|
|
50
|
+
this.confectSchema = confectSchema;
|
|
51
|
+
this.testConvex = testConvex;
|
|
52
|
+
this.testConvex = testConvex;
|
|
53
|
+
this.testConfectImplWithoutIdentity = new TestConfectImplWithoutIdentity(confectSchema, testConvex);
|
|
54
|
+
}
|
|
55
|
+
withIdentity = (userIdentity) => new TestConfectImplWithoutIdentity(this.confectSchema, this.testConvex.withIdentity(userIdentity));
|
|
56
|
+
query = (queryRef, args) => this.testConfectImplWithoutIdentity.query(queryRef, args);
|
|
57
|
+
mutation = (mutationRef, args) => this.testConfectImplWithoutIdentity.mutation(mutationRef, args);
|
|
58
|
+
action = (actionRef, args) => this.testConfectImplWithoutIdentity.action(actionRef, args);
|
|
59
|
+
run = ((handler, returns) => this.testConfectImplWithoutIdentity.run(handler, returns));
|
|
60
|
+
fetch = (pathQueryFragment, init) => this.testConfectImplWithoutIdentity.fetch(pathQueryFragment, init);
|
|
61
|
+
finishInProgressScheduledFunctions = () => this.testConfectImplWithoutIdentity.finishInProgressScheduledFunctions();
|
|
62
|
+
finishAllScheduledFunctions = (advanceTimers) => this.testConfectImplWithoutIdentity.finishAllScheduledFunctions(advanceTimers);
|
|
63
|
+
};
|
|
64
|
+
const layer = (databaseSchema, modules) => () => Layer.sync(TestConfect(), () => new TestConfectImpl(databaseSchema, convexTest(databaseSchema.convexSchemaDefinition, modules)));
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { TestConfect, TestConfect_exports, layer };
|
|
68
|
+
//# sourceMappingURL=TestConfect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestConfect.js","names":["confectSchema: ConfectSchema","testConvex: TestConvexForDataModel<\n DataModel.ToConvex<DataModel.FromSchema<ConfectSchema>>\n >","testConvex: TestConvexForDataModelAndIdentity<\n DataModel.ToConvex<DataModel.FromSchema<ConfectSchema>>\n >"],"sources":["../src/TestConfect.ts"],"sourcesContent":["import { Ref } from \"@confect/core\";\nimport type { DatabaseSchema, DataModel } from \"@confect/server\";\nimport { RegisteredFunctions } from \"@confect/server\";\nimport type {\n TestConvexForDataModel,\n TestConvexForDataModelAndIdentity,\n} from \"convex-test\";\nimport { convexTest } from \"convex-test\";\nimport type { GenericMutationCtx, UserIdentity } from \"convex/server\";\nimport type { Value } from \"convex/values\";\nimport type { ParseResult } from \"effect\";\nimport { Context, Effect, Layer, Schema } from \"effect\";\n\nexport type TestConfectWithoutIdentity<\n ConfectSchema extends DatabaseSchema.AnyWithProps,\n> = {\n query: <QueryRef extends Ref.AnyQuery>(\n queryRef: QueryRef,\n args: Ref.Args<QueryRef>[\"Type\"],\n ) => Effect.Effect<Ref.Returns<QueryRef>[\"Type\"], ParseResult.ParseError>;\n mutation: <MutationRef extends Ref.AnyMutation>(\n mutationRef: MutationRef,\n args: Ref.Args<MutationRef>[\"Type\"],\n ) => Effect.Effect<Ref.Returns<MutationRef>[\"Type\"], ParseResult.ParseError>;\n action: <ActionRef extends Ref.AnyAction>(\n actionRef: ActionRef,\n args: Ref.Args<ActionRef>[\"Type\"],\n ) => Effect.Effect<Ref.Returns<ActionRef>[\"Type\"], ParseResult.ParseError>;\n // TODO: Make this API better\n run: {\n <E>(\n handler: Effect.Effect<\n void,\n E,\n RegisteredFunctions.MutationServices<ConfectSchema>\n >,\n ): Effect.Effect<void>;\n <A, B extends Value, E>(\n handler: Effect.Effect<\n A,\n E,\n RegisteredFunctions.MutationServices<ConfectSchema>\n >,\n returns: Schema.Schema<A, B>,\n ): Effect.Effect<A, ParseResult.ParseError>;\n };\n fetch: (\n pathQueryFragment: string,\n init?: RequestInit,\n ) => Effect.Effect<Response>;\n finishInProgressScheduledFunctions: () => Effect.Effect<void>;\n finishAllScheduledFunctions: (\n advanceTimers: () => void,\n ) => Effect.Effect<void>;\n};\n\nexport type TestConfect<ConfectSchema extends DatabaseSchema.AnyWithProps> = {\n withIdentity: (\n userIdentity: Partial<UserIdentity>,\n ) => TestConfectWithoutIdentity<ConfectSchema>;\n} & TestConfectWithoutIdentity<ConfectSchema>;\n\nexport const TestConfect = <\n ConfectSchema extends DatabaseSchema.AnyWithProps,\n>() =>\n Context.GenericTag<TestConfect<ConfectSchema>>(\"@confect/test/TestConfect\");\n\nclass TestConfectImplWithoutIdentity<\n ConfectSchema extends DatabaseSchema.AnyWithProps,\n> implements TestConfectWithoutIdentity<ConfectSchema>\n{\n constructor(\n private confectSchema: ConfectSchema,\n private testConvex: TestConvexForDataModel<\n DataModel.ToConvex<DataModel.FromSchema<ConfectSchema>>\n >,\n ) {}\n\n readonly query = <QueryRef extends Ref.AnyQuery>(\n queryRef: QueryRef,\n args: Ref.Args<QueryRef>[\"Type\"],\n ): Effect.Effect<Ref.Returns<QueryRef>[\"Type\"], ParseResult.ParseError> =>\n Effect.gen(this, function* () {\n const query = Ref.getFunction(queryRef);\n const queryName = Ref.getConvexFunctionName(queryRef);\n\n const encodedArgs = yield* Schema.encode(query.args)(args);\n\n const encodedReturns = yield* Effect.promise(() =>\n this.testConvex.query(queryName as any, encodedArgs),\n );\n\n return yield* Schema.decode(query.returns)(encodedReturns);\n });\n\n readonly mutation = <MutationRef extends Ref.AnyMutation>(\n mutationRef: MutationRef,\n args: Ref.Args<MutationRef>[\"Type\"],\n ): Effect.Effect<Ref.Returns<MutationRef>[\"Type\"], ParseResult.ParseError> =>\n Effect.gen(this, function* () {\n const mutation = Ref.getFunction(mutationRef);\n const mutationName = Ref.getConvexFunctionName(mutationRef);\n\n const encodedArgs = yield* Schema.encode(mutation.args)(args);\n\n const encodedReturns = yield* Effect.promise(() =>\n this.testConvex.mutation(mutationName as any, encodedArgs),\n );\n\n return yield* Schema.decode(mutation.returns)(encodedReturns);\n });\n\n readonly action = <ActionRef extends Ref.AnyAction>(\n actionRef: ActionRef,\n args: Ref.Args<ActionRef>[\"Type\"],\n ): Effect.Effect<Ref.Returns<ActionRef>[\"Type\"], ParseResult.ParseError> =>\n Effect.gen(this, function* () {\n const action = Ref.getFunction(actionRef);\n const actionName = Ref.getConvexFunctionName(actionRef);\n\n const encodedArgs = yield* Schema.encode(action.args)(args);\n\n const encodedReturns = yield* Effect.promise(() =>\n this.testConvex.action(actionName as any, encodedArgs),\n );\n\n return yield* Schema.decode(action.returns)(encodedReturns);\n });\n\n readonly run: TestConfectWithoutIdentity<ConfectSchema>[\"run\"] = (<\n A,\n B extends Value,\n E,\n >(\n handler: Effect.Effect<\n A,\n E,\n RegisteredFunctions.MutationServices<ConfectSchema>\n >,\n returns?: Schema.Schema<A, B>,\n ): Effect.Effect<void> | Effect.Effect<A, ParseResult.ParseError> => {\n const makeMutationLayer = (\n mutationCtx: GenericMutationCtx<\n DataModel.ToConvex<DataModel.FromSchema<ConfectSchema>>\n >,\n ): Layer.Layer<RegisteredFunctions.MutationServices<ConfectSchema>> =>\n RegisteredFunctions.mutationLayer(\n this.confectSchema,\n mutationCtx,\n ) as Layer.Layer<RegisteredFunctions.MutationServices<ConfectSchema>>;\n\n return returns === undefined\n ? Effect.promise(() =>\n this.testConvex.run((mutationCtx) =>\n Effect.runPromise(\n handler.pipe(\n Effect.asVoid,\n Effect.provide(makeMutationLayer(mutationCtx)),\n ),\n ),\n ),\n )\n : Effect.promise(() =>\n this.testConvex.run((mutationCtx) =>\n Effect.runPromise(\n handler.pipe(\n Effect.andThen(Schema.encode(returns)),\n Effect.provide(makeMutationLayer(mutationCtx)),\n ),\n ),\n ),\n ).pipe(Effect.andThen(Schema.decode(returns)));\n }) as TestConfectWithoutIdentity<ConfectSchema>[\"run\"];\n\n readonly fetch = <PathQueryFragment extends string>(\n pathQueryFragment: PathQueryFragment,\n init?: RequestInit,\n ) => Effect.promise(() => this.testConvex.fetch(pathQueryFragment, init));\n\n readonly finishInProgressScheduledFunctions = () =>\n Effect.promise(() => this.testConvex.finishInProgressScheduledFunctions());\n\n readonly finishAllScheduledFunctions = (advanceTimers: () => void) =>\n Effect.promise(() =>\n this.testConvex.finishAllScheduledFunctions(advanceTimers),\n );\n}\n\nclass TestConfectImpl<ConfectSchema extends DatabaseSchema.AnyWithProps>\n implements TestConfect<ConfectSchema>\n{\n private readonly testConfectImplWithoutIdentity: TestConfectImplWithoutIdentity<ConfectSchema>;\n\n constructor(\n private confectSchema: ConfectSchema,\n private testConvex: TestConvexForDataModelAndIdentity<\n DataModel.ToConvex<DataModel.FromSchema<ConfectSchema>>\n >,\n ) {\n this.testConvex = testConvex;\n this.testConfectImplWithoutIdentity = new TestConfectImplWithoutIdentity(\n confectSchema,\n testConvex,\n );\n }\n\n readonly withIdentity = (userIdentity: Partial<UserIdentity>) =>\n new TestConfectImplWithoutIdentity(\n this.confectSchema,\n this.testConvex.withIdentity(userIdentity),\n );\n\n readonly query = <QueryRef extends Ref.AnyQuery>(\n queryRef: QueryRef,\n args: Ref.Args<QueryRef>[\"Type\"],\n ) => this.testConfectImplWithoutIdentity.query(queryRef, args);\n\n readonly mutation = <MutationRef extends Ref.AnyMutation>(\n mutationRef: MutationRef,\n args: Ref.Args<MutationRef>[\"Type\"],\n ) => this.testConfectImplWithoutIdentity.mutation(mutationRef, args);\n\n readonly action = <ActionRef extends Ref.AnyAction>(\n actionRef: ActionRef,\n args: Ref.Args<ActionRef>[\"Type\"],\n ) => this.testConfectImplWithoutIdentity.action(actionRef, args);\n\n readonly run: TestConfect<ConfectSchema>[\"run\"] = ((\n handler: any,\n returns?: any,\n ) =>\n this.testConfectImplWithoutIdentity.run(\n handler,\n returns,\n )) as TestConfect<ConfectSchema>[\"run\"];\n\n readonly fetch = <PathQueryFragment extends string>(\n pathQueryFragment: PathQueryFragment,\n init?: RequestInit,\n ) => this.testConfectImplWithoutIdentity.fetch(pathQueryFragment, init);\n\n readonly finishInProgressScheduledFunctions = () =>\n this.testConfectImplWithoutIdentity.finishInProgressScheduledFunctions();\n\n readonly finishAllScheduledFunctions = (advanceTimers: () => void) =>\n this.testConfectImplWithoutIdentity.finishAllScheduledFunctions(\n advanceTimers,\n );\n}\n\nexport const layer =\n <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n databaseSchema: DatabaseSchema_,\n modules: Record<string, () => Promise<any>>,\n ) =>\n (): Layer.Layer<TestConfect<DatabaseSchema_>> =>\n Layer.sync(\n TestConfect<DatabaseSchema_>(),\n () =>\n new TestConfectImpl(\n databaseSchema,\n convexTest(\n databaseSchema.convexSchemaDefinition,\n modules,\n ) as unknown as TestConvexForDataModelAndIdentity<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n ),\n );\n"],"mappings":"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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (all) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
return target;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __export };
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@confect/test",
|
|
3
|
+
"version": "1.0.0-next.0",
|
|
4
|
+
"description": "Confect test utilities",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/rjdellecese/confect.git"
|
|
8
|
+
},
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/rjdellecese/confect/issues"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://confect.rjdellecese.com",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"type": "module",
|
|
15
|
+
"files": [
|
|
16
|
+
"CHANGELOG.md",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"README.md",
|
|
19
|
+
"dist",
|
|
20
|
+
"package.json",
|
|
21
|
+
"src"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./*": {
|
|
29
|
+
"types": "./dist/*.d.ts",
|
|
30
|
+
"default": "./dist/*.js"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json",
|
|
33
|
+
"./internal/*": null
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"effect",
|
|
37
|
+
"convex",
|
|
38
|
+
"testing"
|
|
39
|
+
],
|
|
40
|
+
"author": "RJ Dellecese",
|
|
41
|
+
"license": "ISC",
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@effect/language-service": "0.56.0",
|
|
44
|
+
"@eslint/js": "9.39.1",
|
|
45
|
+
"@tsconfig/strictest": "2.0.8",
|
|
46
|
+
"@types/node": "24.10.1",
|
|
47
|
+
"eslint": "9.39.1",
|
|
48
|
+
"prettier": "3.6.2",
|
|
49
|
+
"tsdown": "0.16.4",
|
|
50
|
+
"typescript": "5.9.3",
|
|
51
|
+
"typescript-eslint": "8.46.4"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"convex": "^1.30.0",
|
|
55
|
+
"convex-test": "^0.0.38",
|
|
56
|
+
"effect": "^3.19.3",
|
|
57
|
+
"@confect/core": "1.0.0-next.0",
|
|
58
|
+
"@confect/server": "1.0.0-next.0"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=22",
|
|
62
|
+
"pnpm": ">=10"
|
|
63
|
+
},
|
|
64
|
+
"main": "./dist/index.js",
|
|
65
|
+
"module": "./dist/index.js",
|
|
66
|
+
"types": "./dist/index.d.ts",
|
|
67
|
+
"scripts": {
|
|
68
|
+
"build": "tsdown --config-loader unrun",
|
|
69
|
+
"dev": "tsdown --watch",
|
|
70
|
+
"typecheck": "tsc --noEmit --project tsconfig.json",
|
|
71
|
+
"fix": "prettier --write . && eslint --fix . --max-warnings=0",
|
|
72
|
+
"lint": "prettier --check . && eslint . --max-warnings=0",
|
|
73
|
+
"clean": "rm -rf dist coverage node_modules"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { Ref } from "@confect/core";
|
|
2
|
+
import type { DatabaseSchema, DataModel } from "@confect/server";
|
|
3
|
+
import { RegisteredFunctions } from "@confect/server";
|
|
4
|
+
import type {
|
|
5
|
+
TestConvexForDataModel,
|
|
6
|
+
TestConvexForDataModelAndIdentity,
|
|
7
|
+
} from "convex-test";
|
|
8
|
+
import { convexTest } from "convex-test";
|
|
9
|
+
import type { GenericMutationCtx, UserIdentity } from "convex/server";
|
|
10
|
+
import type { Value } from "convex/values";
|
|
11
|
+
import type { ParseResult } from "effect";
|
|
12
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
13
|
+
|
|
14
|
+
export type TestConfectWithoutIdentity<
|
|
15
|
+
ConfectSchema extends DatabaseSchema.AnyWithProps,
|
|
16
|
+
> = {
|
|
17
|
+
query: <QueryRef extends Ref.AnyQuery>(
|
|
18
|
+
queryRef: QueryRef,
|
|
19
|
+
args: Ref.Args<QueryRef>["Type"],
|
|
20
|
+
) => Effect.Effect<Ref.Returns<QueryRef>["Type"], ParseResult.ParseError>;
|
|
21
|
+
mutation: <MutationRef extends Ref.AnyMutation>(
|
|
22
|
+
mutationRef: MutationRef,
|
|
23
|
+
args: Ref.Args<MutationRef>["Type"],
|
|
24
|
+
) => Effect.Effect<Ref.Returns<MutationRef>["Type"], ParseResult.ParseError>;
|
|
25
|
+
action: <ActionRef extends Ref.AnyAction>(
|
|
26
|
+
actionRef: ActionRef,
|
|
27
|
+
args: Ref.Args<ActionRef>["Type"],
|
|
28
|
+
) => Effect.Effect<Ref.Returns<ActionRef>["Type"], ParseResult.ParseError>;
|
|
29
|
+
// TODO: Make this API better
|
|
30
|
+
run: {
|
|
31
|
+
<E>(
|
|
32
|
+
handler: Effect.Effect<
|
|
33
|
+
void,
|
|
34
|
+
E,
|
|
35
|
+
RegisteredFunctions.MutationServices<ConfectSchema>
|
|
36
|
+
>,
|
|
37
|
+
): Effect.Effect<void>;
|
|
38
|
+
<A, B extends Value, E>(
|
|
39
|
+
handler: Effect.Effect<
|
|
40
|
+
A,
|
|
41
|
+
E,
|
|
42
|
+
RegisteredFunctions.MutationServices<ConfectSchema>
|
|
43
|
+
>,
|
|
44
|
+
returns: Schema.Schema<A, B>,
|
|
45
|
+
): Effect.Effect<A, ParseResult.ParseError>;
|
|
46
|
+
};
|
|
47
|
+
fetch: (
|
|
48
|
+
pathQueryFragment: string,
|
|
49
|
+
init?: RequestInit,
|
|
50
|
+
) => Effect.Effect<Response>;
|
|
51
|
+
finishInProgressScheduledFunctions: () => Effect.Effect<void>;
|
|
52
|
+
finishAllScheduledFunctions: (
|
|
53
|
+
advanceTimers: () => void,
|
|
54
|
+
) => Effect.Effect<void>;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type TestConfect<ConfectSchema extends DatabaseSchema.AnyWithProps> = {
|
|
58
|
+
withIdentity: (
|
|
59
|
+
userIdentity: Partial<UserIdentity>,
|
|
60
|
+
) => TestConfectWithoutIdentity<ConfectSchema>;
|
|
61
|
+
} & TestConfectWithoutIdentity<ConfectSchema>;
|
|
62
|
+
|
|
63
|
+
export const TestConfect = <
|
|
64
|
+
ConfectSchema extends DatabaseSchema.AnyWithProps,
|
|
65
|
+
>() =>
|
|
66
|
+
Context.GenericTag<TestConfect<ConfectSchema>>("@confect/test/TestConfect");
|
|
67
|
+
|
|
68
|
+
class TestConfectImplWithoutIdentity<
|
|
69
|
+
ConfectSchema extends DatabaseSchema.AnyWithProps,
|
|
70
|
+
> implements TestConfectWithoutIdentity<ConfectSchema>
|
|
71
|
+
{
|
|
72
|
+
constructor(
|
|
73
|
+
private confectSchema: ConfectSchema,
|
|
74
|
+
private testConvex: TestConvexForDataModel<
|
|
75
|
+
DataModel.ToConvex<DataModel.FromSchema<ConfectSchema>>
|
|
76
|
+
>,
|
|
77
|
+
) {}
|
|
78
|
+
|
|
79
|
+
readonly query = <QueryRef extends Ref.AnyQuery>(
|
|
80
|
+
queryRef: QueryRef,
|
|
81
|
+
args: Ref.Args<QueryRef>["Type"],
|
|
82
|
+
): Effect.Effect<Ref.Returns<QueryRef>["Type"], ParseResult.ParseError> =>
|
|
83
|
+
Effect.gen(this, function* () {
|
|
84
|
+
const query = Ref.getFunction(queryRef);
|
|
85
|
+
const queryName = Ref.getConvexFunctionName(queryRef);
|
|
86
|
+
|
|
87
|
+
const encodedArgs = yield* Schema.encode(query.args)(args);
|
|
88
|
+
|
|
89
|
+
const encodedReturns = yield* Effect.promise(() =>
|
|
90
|
+
this.testConvex.query(queryName as any, encodedArgs),
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
return yield* Schema.decode(query.returns)(encodedReturns);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
readonly mutation = <MutationRef extends Ref.AnyMutation>(
|
|
97
|
+
mutationRef: MutationRef,
|
|
98
|
+
args: Ref.Args<MutationRef>["Type"],
|
|
99
|
+
): Effect.Effect<Ref.Returns<MutationRef>["Type"], ParseResult.ParseError> =>
|
|
100
|
+
Effect.gen(this, function* () {
|
|
101
|
+
const mutation = Ref.getFunction(mutationRef);
|
|
102
|
+
const mutationName = Ref.getConvexFunctionName(mutationRef);
|
|
103
|
+
|
|
104
|
+
const encodedArgs = yield* Schema.encode(mutation.args)(args);
|
|
105
|
+
|
|
106
|
+
const encodedReturns = yield* Effect.promise(() =>
|
|
107
|
+
this.testConvex.mutation(mutationName as any, encodedArgs),
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
return yield* Schema.decode(mutation.returns)(encodedReturns);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
readonly action = <ActionRef extends Ref.AnyAction>(
|
|
114
|
+
actionRef: ActionRef,
|
|
115
|
+
args: Ref.Args<ActionRef>["Type"],
|
|
116
|
+
): Effect.Effect<Ref.Returns<ActionRef>["Type"], ParseResult.ParseError> =>
|
|
117
|
+
Effect.gen(this, function* () {
|
|
118
|
+
const action = Ref.getFunction(actionRef);
|
|
119
|
+
const actionName = Ref.getConvexFunctionName(actionRef);
|
|
120
|
+
|
|
121
|
+
const encodedArgs = yield* Schema.encode(action.args)(args);
|
|
122
|
+
|
|
123
|
+
const encodedReturns = yield* Effect.promise(() =>
|
|
124
|
+
this.testConvex.action(actionName as any, encodedArgs),
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
return yield* Schema.decode(action.returns)(encodedReturns);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
readonly run: TestConfectWithoutIdentity<ConfectSchema>["run"] = (<
|
|
131
|
+
A,
|
|
132
|
+
B extends Value,
|
|
133
|
+
E,
|
|
134
|
+
>(
|
|
135
|
+
handler: Effect.Effect<
|
|
136
|
+
A,
|
|
137
|
+
E,
|
|
138
|
+
RegisteredFunctions.MutationServices<ConfectSchema>
|
|
139
|
+
>,
|
|
140
|
+
returns?: Schema.Schema<A, B>,
|
|
141
|
+
): Effect.Effect<void> | Effect.Effect<A, ParseResult.ParseError> => {
|
|
142
|
+
const makeMutationLayer = (
|
|
143
|
+
mutationCtx: GenericMutationCtx<
|
|
144
|
+
DataModel.ToConvex<DataModel.FromSchema<ConfectSchema>>
|
|
145
|
+
>,
|
|
146
|
+
): Layer.Layer<RegisteredFunctions.MutationServices<ConfectSchema>> =>
|
|
147
|
+
RegisteredFunctions.mutationLayer(
|
|
148
|
+
this.confectSchema,
|
|
149
|
+
mutationCtx,
|
|
150
|
+
) as Layer.Layer<RegisteredFunctions.MutationServices<ConfectSchema>>;
|
|
151
|
+
|
|
152
|
+
return returns === undefined
|
|
153
|
+
? Effect.promise(() =>
|
|
154
|
+
this.testConvex.run((mutationCtx) =>
|
|
155
|
+
Effect.runPromise(
|
|
156
|
+
handler.pipe(
|
|
157
|
+
Effect.asVoid,
|
|
158
|
+
Effect.provide(makeMutationLayer(mutationCtx)),
|
|
159
|
+
),
|
|
160
|
+
),
|
|
161
|
+
),
|
|
162
|
+
)
|
|
163
|
+
: Effect.promise(() =>
|
|
164
|
+
this.testConvex.run((mutationCtx) =>
|
|
165
|
+
Effect.runPromise(
|
|
166
|
+
handler.pipe(
|
|
167
|
+
Effect.andThen(Schema.encode(returns)),
|
|
168
|
+
Effect.provide(makeMutationLayer(mutationCtx)),
|
|
169
|
+
),
|
|
170
|
+
),
|
|
171
|
+
),
|
|
172
|
+
).pipe(Effect.andThen(Schema.decode(returns)));
|
|
173
|
+
}) as TestConfectWithoutIdentity<ConfectSchema>["run"];
|
|
174
|
+
|
|
175
|
+
readonly fetch = <PathQueryFragment extends string>(
|
|
176
|
+
pathQueryFragment: PathQueryFragment,
|
|
177
|
+
init?: RequestInit,
|
|
178
|
+
) => Effect.promise(() => this.testConvex.fetch(pathQueryFragment, init));
|
|
179
|
+
|
|
180
|
+
readonly finishInProgressScheduledFunctions = () =>
|
|
181
|
+
Effect.promise(() => this.testConvex.finishInProgressScheduledFunctions());
|
|
182
|
+
|
|
183
|
+
readonly finishAllScheduledFunctions = (advanceTimers: () => void) =>
|
|
184
|
+
Effect.promise(() =>
|
|
185
|
+
this.testConvex.finishAllScheduledFunctions(advanceTimers),
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
class TestConfectImpl<ConfectSchema extends DatabaseSchema.AnyWithProps>
|
|
190
|
+
implements TestConfect<ConfectSchema>
|
|
191
|
+
{
|
|
192
|
+
private readonly testConfectImplWithoutIdentity: TestConfectImplWithoutIdentity<ConfectSchema>;
|
|
193
|
+
|
|
194
|
+
constructor(
|
|
195
|
+
private confectSchema: ConfectSchema,
|
|
196
|
+
private testConvex: TestConvexForDataModelAndIdentity<
|
|
197
|
+
DataModel.ToConvex<DataModel.FromSchema<ConfectSchema>>
|
|
198
|
+
>,
|
|
199
|
+
) {
|
|
200
|
+
this.testConvex = testConvex;
|
|
201
|
+
this.testConfectImplWithoutIdentity = new TestConfectImplWithoutIdentity(
|
|
202
|
+
confectSchema,
|
|
203
|
+
testConvex,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
readonly withIdentity = (userIdentity: Partial<UserIdentity>) =>
|
|
208
|
+
new TestConfectImplWithoutIdentity(
|
|
209
|
+
this.confectSchema,
|
|
210
|
+
this.testConvex.withIdentity(userIdentity),
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
readonly query = <QueryRef extends Ref.AnyQuery>(
|
|
214
|
+
queryRef: QueryRef,
|
|
215
|
+
args: Ref.Args<QueryRef>["Type"],
|
|
216
|
+
) => this.testConfectImplWithoutIdentity.query(queryRef, args);
|
|
217
|
+
|
|
218
|
+
readonly mutation = <MutationRef extends Ref.AnyMutation>(
|
|
219
|
+
mutationRef: MutationRef,
|
|
220
|
+
args: Ref.Args<MutationRef>["Type"],
|
|
221
|
+
) => this.testConfectImplWithoutIdentity.mutation(mutationRef, args);
|
|
222
|
+
|
|
223
|
+
readonly action = <ActionRef extends Ref.AnyAction>(
|
|
224
|
+
actionRef: ActionRef,
|
|
225
|
+
args: Ref.Args<ActionRef>["Type"],
|
|
226
|
+
) => this.testConfectImplWithoutIdentity.action(actionRef, args);
|
|
227
|
+
|
|
228
|
+
readonly run: TestConfect<ConfectSchema>["run"] = ((
|
|
229
|
+
handler: any,
|
|
230
|
+
returns?: any,
|
|
231
|
+
) =>
|
|
232
|
+
this.testConfectImplWithoutIdentity.run(
|
|
233
|
+
handler,
|
|
234
|
+
returns,
|
|
235
|
+
)) as TestConfect<ConfectSchema>["run"];
|
|
236
|
+
|
|
237
|
+
readonly fetch = <PathQueryFragment extends string>(
|
|
238
|
+
pathQueryFragment: PathQueryFragment,
|
|
239
|
+
init?: RequestInit,
|
|
240
|
+
) => this.testConfectImplWithoutIdentity.fetch(pathQueryFragment, init);
|
|
241
|
+
|
|
242
|
+
readonly finishInProgressScheduledFunctions = () =>
|
|
243
|
+
this.testConfectImplWithoutIdentity.finishInProgressScheduledFunctions();
|
|
244
|
+
|
|
245
|
+
readonly finishAllScheduledFunctions = (advanceTimers: () => void) =>
|
|
246
|
+
this.testConfectImplWithoutIdentity.finishAllScheduledFunctions(
|
|
247
|
+
advanceTimers,
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export const layer =
|
|
252
|
+
<DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(
|
|
253
|
+
databaseSchema: DatabaseSchema_,
|
|
254
|
+
modules: Record<string, () => Promise<any>>,
|
|
255
|
+
) =>
|
|
256
|
+
(): Layer.Layer<TestConfect<DatabaseSchema_>> =>
|
|
257
|
+
Layer.sync(
|
|
258
|
+
TestConfect<DatabaseSchema_>(),
|
|
259
|
+
() =>
|
|
260
|
+
new TestConfectImpl(
|
|
261
|
+
databaseSchema,
|
|
262
|
+
convexTest(
|
|
263
|
+
databaseSchema.convexSchemaDefinition,
|
|
264
|
+
modules,
|
|
265
|
+
) as unknown as TestConvexForDataModelAndIdentity<
|
|
266
|
+
DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>
|
|
267
|
+
>,
|
|
268
|
+
),
|
|
269
|
+
);
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as TestConfect from "./TestConfect";
|