@confect/test 9.0.0-next.6 → 9.0.0-next.8
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 +39 -0
- package/dist/TestConfect.d.ts +5 -1
- package/dist/TestConfect.d.ts.map +1 -1
- package/dist/TestConfect.js +4 -1
- package/dist/TestConfect.js.map +1 -1
- package/package.json +3 -3
- package/src/TestConfect.ts +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# @confect/test
|
|
2
2
|
|
|
3
|
+
## 9.0.0-next.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3fec285: Import Effect from its submodule paths internally to shrink per-function cold-start bundles.
|
|
8
|
+
|
|
9
|
+
Confect's packages now import Effect modules from their submodule paths (`import * as Schema from "effect/Schema"`) instead of the `"effect"` barrel (`import { Schema } from "effect"`).
|
|
10
|
+
|
|
11
|
+
### Why
|
|
12
|
+
|
|
13
|
+
A barrel import of a namespace re-export defeats esbuild's tree-shaking: accessing `Schema.X` from `import { Schema } from "effect"` retains the _entire_ `Schema` namespace, because the bundler can't prune property access on the barrel's `export * as Schema`. So every Convex function's cold-start bundle was pulling all of `effect/Schema` and `effect/Stream` — and, transitively through Schema's `Arbitrary`, `fast-check` — whether the function used them or not.
|
|
14
|
+
|
|
15
|
+
Importing from the submodule path tree-shakes normally. On a minimal function this cut the bundle esbuild produces by ~54% (the `effect/Schema` module alone by ~75%) and its cold-start module-evaluation time by ~35%, with `fast-check` dropped entirely. This is also the import style Effect v4 recommends, so it's forward-compatible. A `no-restricted-imports` ESLint rule now enforces it across the codebase (type-only imports and `@effect/vitest` are exempt).
|
|
16
|
+
|
|
17
|
+
No API changes — your existing code keeps working.
|
|
18
|
+
|
|
19
|
+
### Getting the full win in your own code
|
|
20
|
+
|
|
21
|
+
This change shrinks the Confect code in every function bundle, but a function's bundle also includes your own `confect/tables/*` and `*.spec.ts` files. esbuild retains the union across all importers, so a single barrel import anywhere in a function's module graph re-pins the whole `effect/Schema` namespace and undoes the reduction. To get the full bundle/cold-start savings, import Effect from its submodule paths in your own Confect files too:
|
|
22
|
+
|
|
23
|
+
```diff
|
|
24
|
+
- import { Schema } from "effect";
|
|
25
|
+
+ import * as Schema from "effect/Schema";
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Bare helpers (`pipe`, `flow`, `identity`) come from `"effect/Function"`.
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [3fec285]
|
|
31
|
+
- @confect/core@9.0.0-next.8
|
|
32
|
+
- @confect/server@9.0.0-next.8
|
|
33
|
+
|
|
34
|
+
## 9.0.0-next.7
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- Updated dependencies [5d19484]
|
|
39
|
+
- @confect/core@9.0.0-next.7
|
|
40
|
+
- @confect/server@9.0.0-next.7
|
|
41
|
+
|
|
3
42
|
## 9.0.0-next.6
|
|
4
43
|
|
|
5
44
|
### Major Changes
|
package/dist/TestConfect.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { Ref } from "@confect/core";
|
|
2
2
|
import { DatabaseSchema, RegisteredConvexFunction } from "@confect/server";
|
|
3
|
-
import
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
4
7
|
import { GenericSchema, SchemaDefinition, UserIdentity } from "convex/server";
|
|
5
8
|
import { Value } from "convex/values";
|
|
9
|
+
import { ParseResult } from "effect";
|
|
6
10
|
|
|
7
11
|
//#region src/TestConfect.d.ts
|
|
8
12
|
declare namespace TestConfect_d_exports {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestConfect.d.ts","names":[],"sources":["../src/TestConfect.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"TestConfect.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CAAO,QAAA;EACnB,kCAAA,QAA0C,MAAA,CAAO,MAAA;EACjD,2BAAA,GACE,aAAA,iBACG,MAAA,CAAO,MAAA;AAAA;AAAA,KAGF,WAAA,uBAAkC,cAAA,CAAe,YAAA;EAC3D,YAAA,GACE,YAAA,EAAc,OAAA,CAAQ,YAAA,MACnB,0BAAA,CAA2B,aAAA;AAAA,IAC9B,0BAAA,CAA2B,aAAA;AAAA,cAElB,WAAA,yBACW,cAAA,CAAe,YAAA,OAAY,OAAA,CAAA,GAAA,CAAA,WAAA,CAAA,aAAA,GAAA,WAAA,CAAA,aAAA;AAAA,cAmLtC,KAAA,2BACc,cAAA,CAAe,YAAA,EACtC,cAAA,EAAgB,eAAA,EAChB,sBAAA,EAAwB,gBAAA,CAAiB,aAAA,SACzC,OAAA,EAAS,MAAA,eAAqB,OAAA,iBAE5B,KAAA,CAAM,KAAA,CAAM,WAAA,CAAY,eAAA"}
|
package/dist/TestConfect.js
CHANGED
|
@@ -2,7 +2,10 @@ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
|
2
2
|
import { Ref } from "@confect/core";
|
|
3
3
|
import { RegisteredConvexFunction } from "@confect/server";
|
|
4
4
|
import { convexTest } from "convex-test";
|
|
5
|
-
import
|
|
5
|
+
import * as Context from "effect/Context";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Layer from "effect/Layer";
|
|
8
|
+
import * as Schema from "effect/Schema";
|
|
6
9
|
|
|
7
10
|
//#region src/TestConfect.ts
|
|
8
11
|
var TestConfect_exports = /* @__PURE__ */ __exportAll({
|
package/dist/TestConfect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestConfect.js","names":[],"sources":["../src/TestConfect.ts"],"sourcesContent":["import { Ref } from \"@confect/core\";\nimport type { DatabaseSchema, DataModel } from \"@confect/server\";\nimport { RegisteredConvexFunction } from \"@confect/server\";\nimport type {\n TestConvexForDataModel,\n TestConvexForDataModelAndIdentity,\n} from \"convex-test\";\nimport { convexTest } from \"convex-test\";\nimport type {\n GenericMutationCtx,\n GenericSchema,\n SchemaDefinition,\n UserIdentity,\n} 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.OptionalArgs<QueryRef>\n ) => Effect.Effect<\n Ref.Returns<QueryRef>,\n Ref.Error<QueryRef> | ParseResult.ParseError\n >;\n mutation: <MutationRef extends Ref.AnyMutation>(\n mutationRef: MutationRef,\n ...args: Ref.OptionalArgs<MutationRef>\n ) => Effect.Effect<\n Ref.Returns<MutationRef>,\n Ref.Error<MutationRef> | ParseResult.ParseError\n >;\n action: <ActionRef extends Ref.AnyAction>(\n actionRef: ActionRef,\n ...args: Ref.OptionalArgs<ActionRef>\n ) => Effect.Effect<\n Ref.Returns<ActionRef>,\n Ref.Error<ActionRef> | ParseResult.ParseError\n >;\n run: {\n <E>(\n handler: Effect.Effect<\n void,\n E,\n RegisteredConvexFunction.MutationServices<ConfectSchema>\n >,\n ): Effect.Effect<void>;\n <A, B extends Value, E>(\n handler: Effect.Effect<\n A,\n E,\n RegisteredConvexFunction.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 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.OptionalArgs<QueryRef>\n ): Effect.Effect<\n Ref.Returns<QueryRef>,\n Ref.Error<QueryRef> | ParseResult.ParseError\n > =>\n Ref.runWithCodec(\n queryRef,\n (args[0] ?? {}) as Ref.Args<QueryRef>,\n (functionReference, encodedArgs) =>\n this.testConvex.query(functionReference as any, encodedArgs),\n );\n\n readonly mutation = <MutationRef extends Ref.AnyMutation>(\n mutationRef: MutationRef,\n ...args: Ref.OptionalArgs<MutationRef>\n ): Effect.Effect<\n Ref.Returns<MutationRef>,\n Ref.Error<MutationRef> | ParseResult.ParseError\n > =>\n Ref.runWithCodec(\n mutationRef,\n (args[0] ?? {}) as Ref.Args<MutationRef>,\n (functionReference, encodedArgs) =>\n this.testConvex.mutation(functionReference as any, encodedArgs),\n );\n\n readonly action = <ActionRef extends Ref.AnyAction>(\n actionRef: ActionRef,\n ...args: Ref.OptionalArgs<ActionRef>\n ): Effect.Effect<\n Ref.Returns<ActionRef>,\n Ref.Error<ActionRef> | ParseResult.ParseError\n > =>\n Ref.runWithCodec(\n actionRef,\n (args[0] ?? {}) as Ref.Args<ActionRef>,\n (functionReference, encodedArgs) =>\n this.testConvex.action(functionReference as any, encodedArgs),\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 RegisteredConvexFunction.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<RegisteredConvexFunction.MutationServices<ConfectSchema>> =>\n RegisteredConvexFunction.mutationLayer(\n this.confectSchema,\n mutationCtx,\n ) as Layer.Layer<\n RegisteredConvexFunction.MutationServices<ConfectSchema>\n >;\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<\n ConfectSchema extends DatabaseSchema.AnyWithProps,\n> implements TestConfect<ConfectSchema> {\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.OptionalArgs<QueryRef>\n ) => this.testConfectImplWithoutIdentity.query(queryRef, ...args);\n\n readonly mutation = <MutationRef extends Ref.AnyMutation>(\n mutationRef: MutationRef,\n ...args: Ref.OptionalArgs<MutationRef>\n ) => this.testConfectImplWithoutIdentity.mutation(mutationRef, ...args);\n\n readonly action = <ActionRef extends Ref.AnyAction>(\n actionRef: ActionRef,\n ...args: Ref.OptionalArgs<ActionRef>\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 convexSchemaDefinition: SchemaDefinition<GenericSchema, true>,\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(convexSchemaDefinition, modules) as any,\n ),\n );\n"],"mappings":";;;;;;;;;;;AA2EA,MAAa,oBA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Q;EACA;AAIR,OAAK,aAAa;AAClB,OAAK,iCAAiC,IAAI,+BACxC,eACA,WACD;;CAGH,AAAS,gBAAgB,iBACvB,IAAI,+BACF,KAAK,eACL,KAAK,WAAW,aAAa,aAAa,CAC3C;CAEH,AAAS,SACP,UACA,GAAG,SACA,KAAK,+BAA+B,MAAM,UAAU,GAAG,KAAK;CAEjE,AAAS,YACP,aACA,GAAG,SACA,KAAK,+BAA+B,SAAS,aAAa,GAAG,KAAK;CAEvE,AAAS,UACP,WACA,GAAG,SACA,KAAK,+BAA+B,OAAO,WAAW,GAAG,KAAK;CAEnE,AAAS,QACP,SACA,YAEA,KAAK,+BAA+B,IAClC,SACA,QACD;CAEH,AAAS,SACP,mBACA,SACG,KAAK,+BAA+B,MAAM,mBAAmB,KAAK;CAEvE,AAAS,2CACP,KAAK,+BAA+B,oCAAoC;CAE1E,AAAS,+BAA+B,kBACtC,KAAK,+BAA+B,4BAClC,cACD;;AAGL,MAAa,SAET,gBACA,wBACA,kBAGA,MAAM,KACJ,aAA8B,QAE5B,IAAI,gBACF,gBACA,WAAW,wBAAwB,QAAQ,CAC5C,CACJ"}
|
|
1
|
+
{"version":3,"file":"TestConfect.js","names":[],"sources":["../src/TestConfect.ts"],"sourcesContent":["import { Ref } from \"@confect/core\";\nimport type { DatabaseSchema, DataModel } from \"@confect/server\";\nimport { RegisteredConvexFunction } from \"@confect/server\";\nimport type {\n TestConvexForDataModel,\n TestConvexForDataModelAndIdentity,\n} from \"convex-test\";\nimport { convexTest } from \"convex-test\";\nimport type {\n GenericMutationCtx,\n GenericSchema,\n SchemaDefinition,\n UserIdentity,\n} from \"convex/server\";\nimport type { Value } from \"convex/values\";\nimport type { ParseResult } from \"effect\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Schema from \"effect/Schema\";\n\nexport type TestConfectWithoutIdentity<\n ConfectSchema extends DatabaseSchema.AnyWithProps,\n> = {\n query: <QueryRef extends Ref.AnyQuery>(\n queryRef: QueryRef,\n ...args: Ref.OptionalArgs<QueryRef>\n ) => Effect.Effect<\n Ref.Returns<QueryRef>,\n Ref.Error<QueryRef> | ParseResult.ParseError\n >;\n mutation: <MutationRef extends Ref.AnyMutation>(\n mutationRef: MutationRef,\n ...args: Ref.OptionalArgs<MutationRef>\n ) => Effect.Effect<\n Ref.Returns<MutationRef>,\n Ref.Error<MutationRef> | ParseResult.ParseError\n >;\n action: <ActionRef extends Ref.AnyAction>(\n actionRef: ActionRef,\n ...args: Ref.OptionalArgs<ActionRef>\n ) => Effect.Effect<\n Ref.Returns<ActionRef>,\n Ref.Error<ActionRef> | ParseResult.ParseError\n >;\n run: {\n <E>(\n handler: Effect.Effect<\n void,\n E,\n RegisteredConvexFunction.MutationServices<ConfectSchema>\n >,\n ): Effect.Effect<void>;\n <A, B extends Value, E>(\n handler: Effect.Effect<\n A,\n E,\n RegisteredConvexFunction.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 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.OptionalArgs<QueryRef>\n ): Effect.Effect<\n Ref.Returns<QueryRef>,\n Ref.Error<QueryRef> | ParseResult.ParseError\n > =>\n Ref.runWithCodec(\n queryRef,\n (args[0] ?? {}) as Ref.Args<QueryRef>,\n (functionReference, encodedArgs) =>\n this.testConvex.query(functionReference as any, encodedArgs),\n );\n\n readonly mutation = <MutationRef extends Ref.AnyMutation>(\n mutationRef: MutationRef,\n ...args: Ref.OptionalArgs<MutationRef>\n ): Effect.Effect<\n Ref.Returns<MutationRef>,\n Ref.Error<MutationRef> | ParseResult.ParseError\n > =>\n Ref.runWithCodec(\n mutationRef,\n (args[0] ?? {}) as Ref.Args<MutationRef>,\n (functionReference, encodedArgs) =>\n this.testConvex.mutation(functionReference as any, encodedArgs),\n );\n\n readonly action = <ActionRef extends Ref.AnyAction>(\n actionRef: ActionRef,\n ...args: Ref.OptionalArgs<ActionRef>\n ): Effect.Effect<\n Ref.Returns<ActionRef>,\n Ref.Error<ActionRef> | ParseResult.ParseError\n > =>\n Ref.runWithCodec(\n actionRef,\n (args[0] ?? {}) as Ref.Args<ActionRef>,\n (functionReference, encodedArgs) =>\n this.testConvex.action(functionReference as any, encodedArgs),\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 RegisteredConvexFunction.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<RegisteredConvexFunction.MutationServices<ConfectSchema>> =>\n RegisteredConvexFunction.mutationLayer(\n this.confectSchema,\n mutationCtx,\n ) as Layer.Layer<\n RegisteredConvexFunction.MutationServices<ConfectSchema>\n >;\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<\n ConfectSchema extends DatabaseSchema.AnyWithProps,\n> implements TestConfect<ConfectSchema> {\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.OptionalArgs<QueryRef>\n ) => this.testConfectImplWithoutIdentity.query(queryRef, ...args);\n\n readonly mutation = <MutationRef extends Ref.AnyMutation>(\n mutationRef: MutationRef,\n ...args: Ref.OptionalArgs<MutationRef>\n ) => this.testConfectImplWithoutIdentity.mutation(mutationRef, ...args);\n\n readonly action = <ActionRef extends Ref.AnyAction>(\n actionRef: ActionRef,\n ...args: Ref.OptionalArgs<ActionRef>\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 convexSchemaDefinition: SchemaDefinition<GenericSchema, true>,\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(convexSchemaDefinition, modules) as any,\n ),\n );\n"],"mappings":";;;;;;;;;;;;;;AA8EA,MAAa,oBAGX,QAAQ,WAAuC,4BAA4B;AAE7E,IAAM,iCAAN,MAEuD;CACrD,YACE,AAAQ,eACR,AAAQ,YAGR;EAJQ;EACA;;CAKV,AAAS,SACP,UACA,GAAG,SAKH,IAAI,aACF,UACC,KAAK,MAAM,EAAE,GACb,mBAAmB,gBAClB,KAAK,WAAW,MAAM,mBAA0B,YAAY,CAC/D;CAEH,AAAS,YACP,aACA,GAAG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KAAK,+BAA+B,SAAS,aAAa,GAAG,KAAK;CAEvE,AAAS,UACP,WACA,GAAG,SACA,KAAK,+BAA+B,OAAO,WAAW,GAAG,KAAK;CAEnE,AAAS,QACP,SACA,YAEA,KAAK,+BAA+B,IAClC,SACA,QACD;CAEH,AAAS,SACP,mBACA,SACG,KAAK,+BAA+B,MAAM,mBAAmB,KAAK;CAEvE,AAAS,2CACP,KAAK,+BAA+B,oCAAoC;CAE1E,AAAS,+BAA+B,kBACtC,KAAK,+BAA+B,4BAClC,cACD;;AAGL,MAAa,SAET,gBACA,wBACA,kBAGA,MAAM,KACJ,aAA8B,QAE5B,IAAI,gBACF,gBACA,WAAW,wBAAwB,QAAQ,CAC5C,CACJ"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@confect/test",
|
|
3
3
|
"description": "Utilities for testing Confect apps without a live Convex backend",
|
|
4
|
-
"version": "9.0.0-next.
|
|
4
|
+
"version": "9.0.0-next.8",
|
|
5
5
|
"author": "RJ Dellecese",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/rjdellecese/confect/issues"
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"convex": "1.39.1",
|
|
53
53
|
"convex-test": "^0.0.50",
|
|
54
54
|
"effect": "^3.21.2",
|
|
55
|
-
"@confect/core": "^9.0.0-next.
|
|
56
|
-
"@confect/server": "^9.0.0-next.
|
|
55
|
+
"@confect/core": "^9.0.0-next.8",
|
|
56
|
+
"@confect/server": "^9.0.0-next.8"
|
|
57
57
|
},
|
|
58
58
|
"repository": {
|
|
59
59
|
"type": "git",
|
package/src/TestConfect.ts
CHANGED
|
@@ -14,7 +14,10 @@ import type {
|
|
|
14
14
|
} from "convex/server";
|
|
15
15
|
import type { Value } from "convex/values";
|
|
16
16
|
import type { ParseResult } from "effect";
|
|
17
|
-
import
|
|
17
|
+
import * as Context from "effect/Context";
|
|
18
|
+
import * as Effect from "effect/Effect";
|
|
19
|
+
import * as Layer from "effect/Layer";
|
|
20
|
+
import * as Schema from "effect/Schema";
|
|
18
21
|
|
|
19
22
|
export type TestConfectWithoutIdentity<
|
|
20
23
|
ConfectSchema extends DatabaseSchema.AnyWithProps,
|