@gaganref/confect-test 10.3.1-fork.3 → 10.3.1-fork.4
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/dist/TestConfect.d.ts +14 -4
- package/dist/TestConfect.d.ts.map +1 -1
- package/dist/TestConfect.js +6 -2
- package/dist/TestConfect.js.map +1 -1
- package/package.json +3 -3
- package/src/TestConfect.ts +32 -11
package/dist/TestConfect.d.ts
CHANGED
|
@@ -46,6 +46,19 @@ export type TestConfect<ConfectSchema extends DatabaseSchema.AnyWithProps> = {
|
|
|
46
46
|
withIdentity: (userIdentity: Partial<UserIdentity>) => TestConfectWithoutIdentity<ConfectSchema>;
|
|
47
47
|
} & TestConfectWithoutIdentity<ConfectSchema>;
|
|
48
48
|
export declare const TestConfect: <ConfectSchema extends DatabaseSchema.AnyWithProps>() => Context.Service<TestConfect<ConfectSchema>, TestConfect<ConfectSchema>>;
|
|
49
|
+
/**
|
|
50
|
+
* How a test registers one installed component: its own schema and modules, or
|
|
51
|
+
* the `register(t, name)` a component package exports from `<package>/test`,
|
|
52
|
+
* which also registers the package's own children.
|
|
53
|
+
*/
|
|
54
|
+
export type ComponentKit = {
|
|
55
|
+
readonly schema: SchemaDefinition<GenericSchema, boolean>;
|
|
56
|
+
readonly modules: Record<string, () => Promise<any>>;
|
|
57
|
+
} | {
|
|
58
|
+
register(t: {
|
|
59
|
+
readonly registerComponent: RegisterComponent;
|
|
60
|
+
}, name: string): unknown;
|
|
61
|
+
};
|
|
49
62
|
/**
|
|
50
63
|
* Codegen's test-only schema and module registry.
|
|
51
64
|
*/
|
|
@@ -53,10 +66,7 @@ export type Registry<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> = {
|
|
|
53
66
|
readonly schema: DatabaseSchema_;
|
|
54
67
|
readonly convexSchema: SchemaDefinition<GenericSchema, true>;
|
|
55
68
|
readonly modules: Record<string, () => Promise<any>>;
|
|
56
|
-
readonly components: Readonly<Record<string,
|
|
57
|
-
readonly schema: SchemaDefinition<GenericSchema, boolean>;
|
|
58
|
-
readonly modules: Record<string, () => Promise<any>>;
|
|
59
|
-
}>>;
|
|
69
|
+
readonly components: Readonly<Record<string, ComponentKit>>;
|
|
60
70
|
};
|
|
61
71
|
/**
|
|
62
72
|
* The declared app's generated, test-only representation.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestConfect.d.ts","sourceRoot":"","sources":["../src/TestConfect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAa,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,KAAK,EAEV,iCAAiC,EAClC,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EACV,gBAAgB,EAEhB,aAAa,EACb,gBAAgB,EAChB,YAAY,EACb,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAC3B,iCAAiC,CAAC,gBAAgB,CAAC,CAAC,mBAAmB,CAAC,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,iBAAiB,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACnE;;OAE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AAC,EAC7D,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,EAC3C,OAAO,CAAC,EAAE,YAAY,GACrB,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC,CAAC"}
|
package/dist/TestConfect.js
CHANGED
|
@@ -54,6 +54,10 @@ var TestConfectImpl = class {
|
|
|
54
54
|
finishInProgressScheduledFunctions = () => this.testConfectImplWithoutIdentity.finishInProgressScheduledFunctions();
|
|
55
55
|
finishAllScheduledFunctions = (advanceTimers) => this.testConfectImplWithoutIdentity.finishAllScheduledFunctions(advanceTimers);
|
|
56
56
|
};
|
|
57
|
+
const registerKit = (registerComponent, name, kit) => {
|
|
58
|
+
if ("register" in kit) kit.register({ registerComponent }, name);
|
|
59
|
+
else registerComponent(name, kit.schema, kit.modules);
|
|
60
|
+
};
|
|
57
61
|
function layer(appOrSchema, registryOrSchema, modules, options = {}) {
|
|
58
62
|
if (App.isApp(appOrSchema)) {
|
|
59
63
|
const registry = registryOrSchema;
|
|
@@ -64,7 +68,7 @@ function layer(appOrSchema, registryOrSchema, modules, options = {}) {
|
|
|
64
68
|
httpPrefix
|
|
65
69
|
}]),
|
|
66
70
|
register: (registerComponent) => {
|
|
67
|
-
for (const [name, component] of Object.entries(registry.components)) if (mounts.some((mount) => name === mount.name || name.startsWith(`${mount.name}/`))) registerComponent
|
|
71
|
+
for (const [name, component] of Object.entries(registry.components)) if (mounts.some((mount) => name === mount.name || name.startsWith(`${mount.name}/`))) registerKit(registerComponent, name, component);
|
|
68
72
|
}
|
|
69
73
|
});
|
|
70
74
|
}
|
|
@@ -73,7 +77,7 @@ function layer(appOrSchema, registryOrSchema, modules, options = {}) {
|
|
|
73
77
|
return schemaLayer(app.schema, app.convexSchema, app.modules, {
|
|
74
78
|
httpMounts: app.httpMounts,
|
|
75
79
|
register: (registerComponent) => {
|
|
76
|
-
for (const [name, component] of Object.entries(app.components)) registerComponent
|
|
80
|
+
for (const [name, component] of Object.entries(app.components)) registerKit(registerComponent, name, component);
|
|
77
81
|
}
|
|
78
82
|
});
|
|
79
83
|
}
|
package/dist/TestConfect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestConfect.js","names":["MountedHttp.make"],"sources":["../src/TestConfect.ts"],"sourcesContent":["import { App, 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 GenericDataModel,\n GenericMutationCtx,\n GenericSchema,\n SchemaDefinition,\n UserIdentity,\n} from \"convex/server\";\nimport type { Value } from \"convex/values\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Schema from \"effect/Schema\";\nimport * as MountedHttp from \"./internal/MountedHttp\";\n\n/**\n * Register a component's Convex schema and modules at its installation path.\n */\nexport type RegisterComponent =\n TestConvexForDataModelAndIdentity<GenericDataModel>[\"registerComponent\"];\n\n/**\n * An installed component path and the HTTP prefix exposed by its host.\n */\nexport type HttpMount = {\n readonly componentPath: string;\n readonly httpPrefix: string;\n};\n\nexport type LayerOptions = {\n /**\n * Register component kits synchronously before the test service is available.\n */\n readonly register?: (registerComponent: RegisterComponent) => void;\n /**\n * Explicit HTTP mounts. The test layer does not evaluate convex.config.ts.\n */\n readonly httpMounts?: ReadonlyArray<HttpMount>;\n};\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> | Schema.SchemaError\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> | Schema.SchemaError\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> | Schema.SchemaError\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.Codec<A, B>,\n ): Effect.Effect<A, Schema.SchemaError>;\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 registerComponent: (\n componentPath: string,\n schema: SchemaDefinition<GenericSchema, boolean>,\n modules: Record<string, () => Promise<any>>,\n ) => Effect.Effect<void>;\n withIdentity: (\n userIdentity: Partial<UserIdentity>,\n ) => TestConfectWithoutIdentity<ConfectSchema>;\n} & TestConfectWithoutIdentity<ConfectSchema>;\n\nexport const TestConfect = <\n ConfectSchema extends DatabaseSchema.AnyWithProps,\n>() => Context.Service<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 private mountedHttp: ReturnType<typeof MountedHttp.make>,\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> | Schema.SchemaError\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> | Schema.SchemaError\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> | Schema.SchemaError\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.Codec<A, B>,\n ): Effect.Effect<void> | Effect.Effect<A, Schema.SchemaError> => {\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.encodeEffect(returns)),\n Effect.provide(makeMutationLayer(mutationCtx)),\n ),\n ),\n ),\n ).pipe(Effect.andThen(Schema.decodeEffect(returns)));\n }) as TestConfectWithoutIdentity<ConfectSchema>[\"run\"];\n\n readonly fetch = <PathQueryFragment extends string>(\n pathQueryFragment: PathQueryFragment,\n init?: RequestInit,\n ) =>\n Effect.promise(() =>\n this.mountedHttp.fetch(this.testConvex, pathQueryFragment, init),\n );\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 private mountedHttp: ReturnType<typeof MountedHttp.make>,\n ) {\n this.testConfectImplWithoutIdentity = new TestConfectImplWithoutIdentity(\n confectSchema,\n testConvex,\n mountedHttp,\n );\n }\n\n readonly withIdentity = (userIdentity: Partial<UserIdentity>) =>\n new TestConfectImplWithoutIdentity(\n this.confectSchema,\n this.testConvex.withIdentity(userIdentity),\n this.mountedHttp,\n );\n\n readonly registerComponent: TestConfect<ConfectSchema>[\"registerComponent\"] =\n Effect.fn(\"TestConfect.registerComponent\")(\n (componentPath, schema, modules) =>\n Effect.sync(() =>\n this.mountedHttp.register(componentPath, schema, modules),\n ),\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\n/**\n * Codegen's test-only schema and module registry.\n */\nexport type Registry<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> = {\n readonly schema: DatabaseSchema_;\n readonly convexSchema: SchemaDefinition<GenericSchema, true>;\n readonly modules: Record<string, () => Promise<any>>;\n readonly components: Readonly<\n Record<\n string,\n {\n readonly schema: SchemaDefinition<GenericSchema, boolean>;\n readonly modules: Record<string, () => Promise<any>>;\n }\n >\n >;\n};\n\n/**\n * The declared app's generated, test-only representation.\n */\nexport type DeclaredApp<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> =\n Registry<DatabaseSchema_> & {\n readonly httpMounts: ReadonlyArray<HttpMount>;\n };\n\n/**\n * Build a fresh test backend from a declaration and its generated\n * `confect/_generated/testing` registry, without restating component mounts.\n */\nexport function layer<DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n app: DeclaredApp<DatabaseSchema_>,\n): Layer.Layer<TestConfect<DatabaseSchema_>>;\nexport function layer<\n A extends App.Any,\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n>(\n app: A,\n registry: Registry<DatabaseSchema_> & {\n readonly components: Readonly<\n Record<\n keyof NoInfer<A>[\"mounts\"],\n Registry<DatabaseSchema_>[\"components\"][string]\n >\n >;\n },\n): Layer.Layer<TestConfect<DatabaseSchema_>>;\nexport function layer<DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n databaseSchema: DatabaseSchema_,\n convexSchemaDefinition: SchemaDefinition<GenericSchema, true>,\n modules: Record<string, () => Promise<any>>,\n options?: LayerOptions,\n): Layer.Layer<TestConfect<DatabaseSchema_>>;\nexport function layer<DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n appOrSchema: App.Any | DeclaredApp<DatabaseSchema_> | DatabaseSchema_,\n registryOrSchema?:\n | Registry<DatabaseSchema_>\n | SchemaDefinition<GenericSchema, true>,\n modules?: Record<string, () => Promise<any>>,\n options: LayerOptions = {},\n): Layer.Layer<TestConfect<DatabaseSchema_>> {\n if (App.isApp(appOrSchema)) {\n const registry = registryOrSchema as Registry<DatabaseSchema_>;\n const mounts = App.mounts(appOrSchema);\n return schemaLayer(\n registry.schema,\n registry.convexSchema,\n registry.modules,\n {\n httpMounts: mounts.flatMap(({ name, httpPrefix }) =>\n httpPrefix === undefined ? [] : [{ componentPath: name, httpPrefix }],\n ),\n register: (registerComponent) => {\n for (const [name, component] of Object.entries(registry.components)) {\n if (\n mounts.some(\n (mount) =>\n name === mount.name || name.startsWith(`${mount.name}/`),\n )\n ) {\n registerComponent(name, component.schema, component.modules);\n }\n }\n },\n },\n );\n }\n if (\"httpMounts\" in appOrSchema) {\n const app = appOrSchema as DeclaredApp<DatabaseSchema_>;\n return schemaLayer(app.schema, app.convexSchema, app.modules, {\n httpMounts: app.httpMounts,\n register: (registerComponent) => {\n for (const [name, component] of Object.entries(app.components)) {\n registerComponent(name, component.schema, component.modules);\n }\n },\n });\n }\n return schemaLayer(\n appOrSchema as DatabaseSchema_,\n registryOrSchema as SchemaDefinition<GenericSchema, true>,\n modules!,\n options,\n );\n}\n\nconst schemaLayer = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n databaseSchema: DatabaseSchema_,\n convexSchemaDefinition: SchemaDefinition<GenericSchema, true>,\n modules: Record<string, () => Promise<any>>,\n options: LayerOptions = {},\n): Layer.Layer<TestConfect<DatabaseSchema_>> =>\n Layer.sync(TestConfect<DatabaseSchema_>(), () => {\n const testConvex = convexTest(convexSchemaDefinition, modules);\n const mountedHttp = MountedHttp.make(options.httpMounts ?? [], (...args) =>\n testConvex.registerComponent(...args),\n );\n options.register?.(mountedHttp.register);\n return new TestConfectImpl(databaseSchema, testConvex as any, mountedHttp);\n });\n"],"mappings":";;;;;;;;;;;;;;AA6GA,MAAa,oBAEN,QAAQ,QAAoC,2BAA2B;AAE9E,IAAM,iCAAN,MAEuD;CAE3C;CACA;CAGA;CALV,YACE,eACA,YAGA,aACA;EALQ,KAAA,gBAAA;EACA,KAAA,aAAA;EAGA,KAAA,cAAA;CACP;CAEH,SACE,UACA,GAAG,SAKH,IAAI,aACF,UACC,KAAK,MAAM,CAAC,IACZ,mBAAmB,gBAClB,KAAK,WAAW,MAAM,mBAA0B,WAAW,CAC/D;CAEF,YACE,aACA,GAAG,SAKH,IAAI,aACF,aACC,KAAK,MAAM,CAAC,IACZ,mBAAmB,gBAClB,KAAK,WAAW,SAAS,mBAA0B,WAAW,CAClE;CAEF,UACE,WACA,GAAG,SAKH,IAAI,aACF,WACC,KAAK,MAAM,CAAC,IACZ,mBAAmB,gBAClB,KAAK,WAAW,OAAO,mBAA0B,WAAW,CAChE;CAEF,QAKE,SAKA,YAC+D;EAC/D,MAAM,qBACJ,gBAIA,yB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W,kBAAkB,GAAG,IAAI,CACtC;CACA,QAAQ,WAAW,YAAY,QAAQ;CACvC,OAAO,IAAI,gBAAgB,gBAAgB,YAAmB,WAAW;AAC3E,CAAC"}
|
|
1
|
+
{"version":3,"file":"TestConfect.js","names":["MountedHttp.make"],"sources":["../src/TestConfect.ts"],"sourcesContent":["import { App, 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 GenericDataModel,\n GenericMutationCtx,\n GenericSchema,\n SchemaDefinition,\n UserIdentity,\n} from \"convex/server\";\nimport type { Value } from \"convex/values\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Schema from \"effect/Schema\";\nimport * as MountedHttp from \"./internal/MountedHttp\";\n\n/**\n * Register a component's Convex schema and modules at its installation path.\n */\nexport type RegisterComponent =\n TestConvexForDataModelAndIdentity<GenericDataModel>[\"registerComponent\"];\n\n/**\n * An installed component path and the HTTP prefix exposed by its host.\n */\nexport type HttpMount = {\n readonly componentPath: string;\n readonly httpPrefix: string;\n};\n\nexport type LayerOptions = {\n /**\n * Register component kits synchronously before the test service is available.\n */\n readonly register?: (registerComponent: RegisterComponent) => void;\n /**\n * Explicit HTTP mounts. The test layer does not evaluate convex.config.ts.\n */\n readonly httpMounts?: ReadonlyArray<HttpMount>;\n};\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> | Schema.SchemaError\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> | Schema.SchemaError\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> | Schema.SchemaError\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.Codec<A, B>,\n ): Effect.Effect<A, Schema.SchemaError>;\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 registerComponent: (\n componentPath: string,\n schema: SchemaDefinition<GenericSchema, boolean>,\n modules: Record<string, () => Promise<any>>,\n ) => Effect.Effect<void>;\n withIdentity: (\n userIdentity: Partial<UserIdentity>,\n ) => TestConfectWithoutIdentity<ConfectSchema>;\n} & TestConfectWithoutIdentity<ConfectSchema>;\n\nexport const TestConfect = <\n ConfectSchema extends DatabaseSchema.AnyWithProps,\n>() => Context.Service<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 private mountedHttp: ReturnType<typeof MountedHttp.make>,\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> | Schema.SchemaError\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> | Schema.SchemaError\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> | Schema.SchemaError\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.Codec<A, B>,\n ): Effect.Effect<void> | Effect.Effect<A, Schema.SchemaError> => {\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.encodeEffect(returns)),\n Effect.provide(makeMutationLayer(mutationCtx)),\n ),\n ),\n ),\n ).pipe(Effect.andThen(Schema.decodeEffect(returns)));\n }) as TestConfectWithoutIdentity<ConfectSchema>[\"run\"];\n\n readonly fetch = <PathQueryFragment extends string>(\n pathQueryFragment: PathQueryFragment,\n init?: RequestInit,\n ) =>\n Effect.promise(() =>\n this.mountedHttp.fetch(this.testConvex, pathQueryFragment, init),\n );\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 private mountedHttp: ReturnType<typeof MountedHttp.make>,\n ) {\n this.testConfectImplWithoutIdentity = new TestConfectImplWithoutIdentity(\n confectSchema,\n testConvex,\n mountedHttp,\n );\n }\n\n readonly withIdentity = (userIdentity: Partial<UserIdentity>) =>\n new TestConfectImplWithoutIdentity(\n this.confectSchema,\n this.testConvex.withIdentity(userIdentity),\n this.mountedHttp,\n );\n\n readonly registerComponent: TestConfect<ConfectSchema>[\"registerComponent\"] =\n Effect.fn(\"TestConfect.registerComponent\")(\n (componentPath, schema, modules) =>\n Effect.sync(() =>\n this.mountedHttp.register(componentPath, schema, modules),\n ),\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\n/**\n * How a test registers one installed component: its own schema and modules, or\n * the `register(t, name)` a component package exports from `<package>/test`,\n * which also registers the package's own children.\n */\nexport type ComponentKit =\n | {\n readonly schema: SchemaDefinition<GenericSchema, boolean>;\n readonly modules: Record<string, () => Promise<any>>;\n }\n | {\n register(\n t: { readonly registerComponent: RegisterComponent },\n name: string,\n ): unknown;\n };\n\nconst registerKit = (\n registerComponent: RegisterComponent,\n name: string,\n kit: ComponentKit,\n) => {\n if (\"register\" in kit) {\n kit.register({ registerComponent }, name);\n } else {\n registerComponent(name, kit.schema, kit.modules);\n }\n};\n\n/**\n * Codegen's test-only schema and module registry.\n */\nexport type Registry<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> = {\n readonly schema: DatabaseSchema_;\n readonly convexSchema: SchemaDefinition<GenericSchema, true>;\n readonly modules: Record<string, () => Promise<any>>;\n readonly components: Readonly<Record<string, ComponentKit>>;\n};\n\n/**\n * The declared app's generated, test-only representation.\n */\nexport type DeclaredApp<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> =\n Registry<DatabaseSchema_> & {\n readonly httpMounts: ReadonlyArray<HttpMount>;\n };\n\n/**\n * Build a fresh test backend from a declaration and its generated\n * `confect/_generated/testing` registry, without restating component mounts.\n */\nexport function layer<DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n app: DeclaredApp<DatabaseSchema_>,\n): Layer.Layer<TestConfect<DatabaseSchema_>>;\nexport function layer<\n A extends App.Any,\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n>(\n app: A,\n registry: Registry<DatabaseSchema_> & {\n readonly components: Readonly<\n Record<\n keyof NoInfer<A>[\"mounts\"],\n Registry<DatabaseSchema_>[\"components\"][string]\n >\n >;\n },\n): Layer.Layer<TestConfect<DatabaseSchema_>>;\nexport function layer<DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n databaseSchema: DatabaseSchema_,\n convexSchemaDefinition: SchemaDefinition<GenericSchema, true>,\n modules: Record<string, () => Promise<any>>,\n options?: LayerOptions,\n): Layer.Layer<TestConfect<DatabaseSchema_>>;\nexport function layer<DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n appOrSchema: App.Any | DeclaredApp<DatabaseSchema_> | DatabaseSchema_,\n registryOrSchema?:\n | Registry<DatabaseSchema_>\n | SchemaDefinition<GenericSchema, true>,\n modules?: Record<string, () => Promise<any>>,\n options: LayerOptions = {},\n): Layer.Layer<TestConfect<DatabaseSchema_>> {\n if (App.isApp(appOrSchema)) {\n const registry = registryOrSchema as Registry<DatabaseSchema_>;\n const mounts = App.mounts(appOrSchema);\n return schemaLayer(\n registry.schema,\n registry.convexSchema,\n registry.modules,\n {\n httpMounts: mounts.flatMap(({ name, httpPrefix }) =>\n httpPrefix === undefined ? [] : [{ componentPath: name, httpPrefix }],\n ),\n register: (registerComponent) => {\n for (const [name, component] of Object.entries(registry.components)) {\n if (\n mounts.some(\n (mount) =>\n name === mount.name || name.startsWith(`${mount.name}/`),\n )\n ) {\n registerKit(registerComponent, name, component);\n }\n }\n },\n },\n );\n }\n if (\"httpMounts\" in appOrSchema) {\n const app = appOrSchema as DeclaredApp<DatabaseSchema_>;\n return schemaLayer(app.schema, app.convexSchema, app.modules, {\n httpMounts: app.httpMounts,\n register: (registerComponent) => {\n for (const [name, component] of Object.entries(app.components)) {\n registerKit(registerComponent, name, component);\n }\n },\n });\n }\n return schemaLayer(\n appOrSchema as DatabaseSchema_,\n registryOrSchema as SchemaDefinition<GenericSchema, true>,\n modules!,\n options,\n );\n}\n\nconst schemaLayer = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n databaseSchema: DatabaseSchema_,\n convexSchemaDefinition: SchemaDefinition<GenericSchema, true>,\n modules: Record<string, () => Promise<any>>,\n options: LayerOptions = {},\n): Layer.Layer<TestConfect<DatabaseSchema_>> =>\n Layer.sync(TestConfect<DatabaseSchema_>(), () => {\n const testConvex = convexTest(convexSchemaDefinition, modules);\n const mountedHttp = MountedHttp.make(options.httpMounts ?? [], (...args) =>\n testConvex.registerComponent(...args),\n );\n options.register?.(mountedHttp.register);\n return new TestConfectImpl(databaseSchema, testConvex as any, mountedHttp);\n });\n"],"mappings":";;;;;;;;;;;;;;AA6GA,MAAa,oBAEN,QAAQ,QAAoC,2BAA2B;AAE9E,IAAM,iCAAN,MAEuD;CAE3C;CACA;CAGA;CALV,YACE,eACA,YAGA,aACA;EALQ,KAAA,gBAAA;EACA,KAAA,aAAA;EAGA,KAAA,cAAA;CACP;CAEH,SACE,UACA,GAAG,SAKH,IAAI,aACF,UACC,KAAK,MAAM,CAAC,IACZ,mBAAmB,gBAClB,KAAK,WAAW,MAAM,mBAA0B,WAAW,CAC/D;CAEF,YACE,aACA,GAAG,SAKH,I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AS;GAC5D,YAAY,IAAI;GAChB,WAAW,sBAAsB;IAC/B,KAAK,MAAM,CAAC,MAAM,cAAc,OAAO,QAAQ,IAAI,UAAU,GAC3D,YAAY,mBAAmB,MAAM,SAAS;GAElD;EACF,CAAC;CACH;CACA,OAAO,YACL,aACA,kBACA,SACA,OACF;AACF;AAEA,MAAM,eACJ,gBACA,wBACA,SACA,UAAwB,CAAC,MAEzB,MAAM,KAAK,YAA6B,SAAS;CAC/C,MAAM,aAAa,WAAW,wBAAwB,OAAO;CAC7D,MAAM,cAAcA,KAAiB,QAAQ,cAAc,CAAC,IAAI,GAAG,SACjE,WAAW,kBAAkB,GAAG,IAAI,CACtC;CACA,QAAQ,WAAW,YAAY,QAAQ;CACvC,OAAO,IAAI,gBAAgB,gBAAgB,YAAmB,WAAW;AAC3E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gaganref/confect-test",
|
|
3
|
-
"version": "10.3.1-fork.
|
|
3
|
+
"version": "10.3.1-fork.4",
|
|
4
4
|
"peerDependencies": {
|
|
5
|
-
"@confect/core": "npm:@gaganref/confect-core@10.3.1-fork.
|
|
6
|
-
"@confect/server": "npm:@gaganref/confect-server@10.3.1-fork.
|
|
5
|
+
"@confect/core": "npm:@gaganref/confect-core@10.3.1-fork.4",
|
|
6
|
+
"@confect/server": "npm:@gaganref/confect-server@10.3.1-fork.4",
|
|
7
7
|
"convex": "^1.32.0",
|
|
8
8
|
"convex-test": ">=0.0.50 <0.1.0",
|
|
9
9
|
"effect": "^4.0.0"
|
package/src/TestConfect.ts
CHANGED
|
@@ -300,6 +300,35 @@ class TestConfectImpl<
|
|
|
300
300
|
);
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
+
/**
|
|
304
|
+
* How a test registers one installed component: its own schema and modules, or
|
|
305
|
+
* the `register(t, name)` a component package exports from `<package>/test`,
|
|
306
|
+
* which also registers the package's own children.
|
|
307
|
+
*/
|
|
308
|
+
export type ComponentKit =
|
|
309
|
+
| {
|
|
310
|
+
readonly schema: SchemaDefinition<GenericSchema, boolean>;
|
|
311
|
+
readonly modules: Record<string, () => Promise<any>>;
|
|
312
|
+
}
|
|
313
|
+
| {
|
|
314
|
+
register(
|
|
315
|
+
t: { readonly registerComponent: RegisterComponent },
|
|
316
|
+
name: string,
|
|
317
|
+
): unknown;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const registerKit = (
|
|
321
|
+
registerComponent: RegisterComponent,
|
|
322
|
+
name: string,
|
|
323
|
+
kit: ComponentKit,
|
|
324
|
+
) => {
|
|
325
|
+
if ("register" in kit) {
|
|
326
|
+
kit.register({ registerComponent }, name);
|
|
327
|
+
} else {
|
|
328
|
+
registerComponent(name, kit.schema, kit.modules);
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
303
332
|
/**
|
|
304
333
|
* Codegen's test-only schema and module registry.
|
|
305
334
|
*/
|
|
@@ -307,15 +336,7 @@ export type Registry<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> = {
|
|
|
307
336
|
readonly schema: DatabaseSchema_;
|
|
308
337
|
readonly convexSchema: SchemaDefinition<GenericSchema, true>;
|
|
309
338
|
readonly modules: Record<string, () => Promise<any>>;
|
|
310
|
-
readonly components: Readonly<
|
|
311
|
-
Record<
|
|
312
|
-
string,
|
|
313
|
-
{
|
|
314
|
-
readonly schema: SchemaDefinition<GenericSchema, boolean>;
|
|
315
|
-
readonly modules: Record<string, () => Promise<any>>;
|
|
316
|
-
}
|
|
317
|
-
>
|
|
318
|
-
>;
|
|
339
|
+
readonly components: Readonly<Record<string, ComponentKit>>;
|
|
319
340
|
};
|
|
320
341
|
|
|
321
342
|
/**
|
|
@@ -380,7 +401,7 @@ export function layer<DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(
|
|
|
380
401
|
name === mount.name || name.startsWith(`${mount.name}/`),
|
|
381
402
|
)
|
|
382
403
|
) {
|
|
383
|
-
registerComponent
|
|
404
|
+
registerKit(registerComponent, name, component);
|
|
384
405
|
}
|
|
385
406
|
}
|
|
386
407
|
},
|
|
@@ -393,7 +414,7 @@ export function layer<DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(
|
|
|
393
414
|
httpMounts: app.httpMounts,
|
|
394
415
|
register: (registerComponent) => {
|
|
395
416
|
for (const [name, component] of Object.entries(app.components)) {
|
|
396
|
-
registerComponent
|
|
417
|
+
registerKit(registerComponent, name, component);
|
|
397
418
|
}
|
|
398
419
|
},
|
|
399
420
|
});
|