@gaganref/confect-test 10.3.1-fork.4 → 10.3.1-fork.6

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.
@@ -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 * 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,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AAI,SAAS;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"}
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.js\";\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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AAe,KAAA,IAAY,CAAC,IAAI,CAAC;IAAE,eAAe;IAAM;GAAW,CAAC,CACtE;GACA,WAAW,sBAAsB;IAC/B,KAAK,MAAM,CAAC,MAAM,cAAc,OAAO,QAAQ,SAAS,UAAU,GAChE,IACE,OAAO,MACJ,UACC,SAAS,MAAM,QAAQ,KAAK,WAAW,GAAG,MAAM,KAAK,EAAE,CAC3D,GAEA,YAAY,mBAAmB,MAAM,SAAS;GAGpD;EACF,CACF;CACF;CACA,IAAI,gBAAgB,aAAa;EAC/B,MAAM,MAAM;EACZ,OAAO,YAAY,IAAI,QAAQ,IAAI,cAAc,IAAI,SAAS;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/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * as TestConfect from "./TestConfect";
1
+ export * as TestConfect from "./TestConfect.js";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { TestConvexForDataModel } from "convex-test";
2
2
  import type { GenericDataModel } from "convex/server";
3
- import type { HttpMount, RegisterComponent } from "../TestConfect";
3
+ import type { HttpMount, RegisterComponent } from "../TestConfect.js";
4
4
  export declare const make: (mounts: ReadonlyArray<HttpMount>, registerComponent: RegisterComponent) => {
5
5
  register: (componentPath: string, schema: import("convex/server").SchemaDefinition<import("convex/server").GenericSchema, boolean>, glob: Record<string, () => Promise<any>>) => void;
6
6
  fetch: <DataModel extends GenericDataModel>(accessor: TestConvexForDataModel<DataModel>, path: string, init?: RequestInit) => Promise<Response>;
@@ -1 +1 @@
1
- {"version":3,"file":"MountedHttp.d.ts","sourceRoot":"","sources":["../../src/internal/MountedHttp.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,KAAK,EACV,gBAAgB,EAKjB,MAAM,eAAe,CAAC;AAIvB,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAmFnE,eAAO,MAAM,IAAI,WACP,aAAa,CAAC,SAAS,CAAC,qBACb,iBAAiB;;YAoGrB,SAAS,SAAS,gBAAgB,YACrC,sBAAsB,CAAC,SAAS,CAAC,QACrC,MAAM,SACL,WAAW,KACjB,OAAO,CAAC,QAAQ,CAAC;CAgErB,CAAC"}
1
+ {"version":3,"file":"MountedHttp.d.ts","sourceRoot":"","sources":["../../src/internal/MountedHttp.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,KAAK,EACV,gBAAgB,EAKjB,MAAM,eAAe,CAAC;AAIvB,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAmFtE,eAAO,MAAM,IAAI,WACP,aAAa,CAAC,SAAS,CAAC,qBACb,iBAAiB;;YAoGrB,SAAS,SAAS,gBAAgB,YACrC,sBAAsB,CAAC,SAAS,CAAC,QACrC,MAAM,SACL,WAAW,KACjB,OAAO,CAAC,QAAQ,CAAC;CAgErB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"MountedHttp.js","names":[],"sources":["../../src/internal/MountedHttp.ts"],"sourcesContent":["/* oxlint-disable effecttsgo/async-function -- This convex-test adapter uses Promise callbacks and temporarily overrides the real process environment consumed by HTTP module construction. */\nimport type { TestConvexForDataModel } from \"convex-test\";\nimport type {\n GenericDataModel,\n HttpRouter,\n FunctionReference,\n RoutableMethod,\n PublicHttpAction,\n} from \"convex/server\";\nimport { actionGeneric } from \"convex/server\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport type { HttpMount, RegisterComponent } from \"../TestConfect\";\n\ndeclare const process: { env: Record<string, string | undefined> };\n\nclass InvalidHttpMount extends Schema.TaggedError<InvalidHttpMount>()(\n \"InvalidHttpMount\",\n {\n componentPath: Schema.String,\n httpPrefix: Schema.String,\n message: Schema.String,\n },\n) {}\n\nclass ComponentHttpError extends Schema.TaggedError<ComponentHttpError>()(\n \"ComponentHttpError\",\n { componentPath: Schema.String, message: Schema.String },\n) {}\n\nclass InvalidFetchPath extends Schema.TaggedError<InvalidFetchPath>()(\n \"InvalidFetchPath\",\n { path: Schema.String, message: Schema.String },\n) {}\n\ntype NormalizedMount = {\n readonly componentPath: string;\n readonly prefix: string;\n};\n\nconst normalizeMounts = (mounts: ReadonlyArray<HttpMount>) => {\n const normalized: Array<NormalizedMount> = [];\n for (const mount of mounts) {\n if (!mount.httpPrefix.startsWith(\"/\") || /[?#]/.test(mount.httpPrefix)) {\n return Result.fail(\n new InvalidHttpMount({\n ...mount,\n message:\n \"httpPrefix must be an absolute path without a query or fragment.\",\n }),\n );\n }\n const prefix = mount.httpPrefix.replace(/\\/+$/, \"\");\n if (normalized.some((previous) => previous.prefix === prefix)) {\n return Result.fail(\n new InvalidHttpMount({\n ...mount,\n message: \"Each httpPrefix must select one component installation.\",\n }),\n );\n }\n normalized.push({ componentPath: mount.componentPath, prefix });\n }\n return Result.succeed(\n normalized.sort((a, b) => b.prefix.length - a.prefix.length),\n );\n};\n\ntype HttpRequest = {\n siteUrl: string;\n url: string;\n pathname: string;\n method: string;\n headers: Array<[string, string]>;\n body: ArrayBuffer | null;\n};\n\ntype HttpResponse = {\n status: number;\n statusText: string;\n headers: Array<[string, string]>;\n body: ArrayBuffer;\n};\n\n// Convex omits this runtime entry point from its published declarations.\nconst isInvokable = (\n action: PublicHttpAction,\n): action is PublicHttpAction & {\n invokeHttpAction(request: Request): Promise<Response>;\n} =>\n \"invokeHttpAction\" in action && typeof action.invokeHttpAction === \"function\";\n\nconst bridgeModule = \"__confect_test_http\";\nconst defaultSiteUrl = \"https://some.convex.site\";\n\nexport const make = (\n mounts: ReadonlyArray<HttpMount>,\n registerComponent: RegisterComponent,\n) => {\n const normalized = normalizeMounts(mounts);\n if (Result.isFailure(normalized)) throw normalized.failure;\n const registered = new Set<string>();\n let tail = Promise.resolve();\n\n const register: RegisterComponent = (componentPath, schema, modules) => {\n if (\n !normalized.success.some((mount) => mount.componentPath === componentPath)\n ) {\n registerComponent(componentPath, schema, modules);\n return;\n }\n const generated = Object.keys(modules).find((key) =>\n key.includes(\"_generated\"),\n );\n const root = generated?.split(\"_generated\", 2)[0];\n const moduleLoaders = Object.fromEntries(\n Object.entries(modules).map(([path, load]) => [\n path.replace(/\\.[^.]+$/, \"\"),\n load,\n ]),\n );\n const loadHttp =\n root === undefined ? undefined : moduleLoaders[`${root}http`];\n if (root === undefined || loadHttp === undefined) {\n throw new ComponentHttpError({\n componentPath,\n message:\n \"Mounted components need an HTTP module and Convex _generated modules.\",\n });\n }\n const bridgePath = `${root}${bridgeModule}.ts`;\n if (`${root}${bridgeModule}` in moduleLoaders) {\n throw new ComponentHttpError({\n componentPath,\n message: `${bridgeModule} is reserved for mounted HTTP tests.`,\n });\n }\n const routers = new Map<string, Promise<HttpRouter>>();\n const invoke = actionGeneric({\n handler: async (_ctx, args: HttpRequest): Promise<HttpResponse> => {\n const previousSiteUrl = process.env.CONVEX_SITE_URL;\n try {\n process.env.CONVEX_SITE_URL = args.siteUrl;\n let router = routers.get(args.siteUrl);\n if (router === undefined) {\n router = loadHttp().then(\n (module: { default: HttpRouter }) => module.default,\n );\n routers.set(args.siteUrl, router);\n }\n const route = (await router).lookup(\n args.pathname,\n args.method as RoutableMethod,\n );\n let response: Response;\n if (route === null) {\n response = new Response(\n `No HttpAction routed for ${args.pathname}`,\n { status: 404 },\n );\n } else {\n const action = route[0];\n if (!isInvokable(action)) {\n throw new ComponentHttpError({\n componentPath,\n message:\n \"This Convex version does not expose invokeHttpAction for HTTP tests.\",\n });\n }\n // Convex selects on the relative path and passes the full URL to the handler.\n response = await action.invokeHttpAction(\n new Request(args.url, {\n method: args.method,\n headers: args.headers,\n ...(args.body === null ? {} : { body: args.body }),\n }),\n );\n }\n return {\n status: response.status,\n statusText: response.statusText,\n headers: [...response.headers],\n body: await response.arrayBuffer(),\n };\n } finally {\n if (previousSiteUrl === undefined) delete process.env.CONVEX_SITE_URL;\n else process.env.CONVEX_SITE_URL = previousSiteUrl;\n }\n },\n });\n registerComponent(componentPath, schema, {\n ...modules,\n [bridgePath]: () => Promise.resolve({ invoke }),\n });\n registered.add(componentPath);\n };\n\n const fetch = <DataModel extends GenericDataModel>(\n accessor: TestConvexForDataModel<DataModel>,\n path: string,\n init?: RequestInit,\n ): Promise<Response> => {\n if (normalized.success.length === 0) return accessor.fetch(path, init);\n const run = async () => {\n if (!path.startsWith(\"/\")) {\n throw new InvalidFetchPath({\n path,\n message: 'Path given to fetch must start with a \"/\".',\n });\n }\n const pathname = new URL(`${defaultSiteUrl}${path}`).pathname;\n const mount = normalized.success.find(\n ({ prefix }) =>\n pathname === prefix || pathname.startsWith(`${prefix}/`),\n );\n if (mount === undefined) return accessor.fetch(path, init);\n if (!registered.has(mount.componentPath)) {\n throw new ComponentHttpError({\n componentPath: mount.componentPath,\n message: \"Register the mounted component before calling fetch.\",\n });\n }\n const appSiteUrl = (\n process.env.CONVEX_SITE_URL || defaultSiteUrl\n ).replace(/\\/$/, \"\");\n const request = new Request(new URL(`${appSiteUrl}${path}`), init);\n // convex-test encodes exact component paths in test-only function handles.\n const reference =\n `function://${mount.componentPath};${bridgeModule}:invoke` as unknown as FunctionReference<\n \"action\",\n \"public\",\n HttpRequest,\n HttpResponse\n >;\n const response = await accessor.action(reference, {\n siteUrl: `${appSiteUrl}${mount.prefix}`,\n url: request.url,\n pathname: pathname.slice(mount.prefix.length) || \"/\",\n method: request.method,\n headers: [...request.headers],\n body:\n request.method === \"GET\" || request.method === \"HEAD\"\n ? null\n : await request.arrayBuffer(),\n });\n return new Response(\n request.method === \"HEAD\" || [204, 205, 304].includes(response.status)\n ? null\n : response.body,\n {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n },\n );\n };\n const result = tail.then(run);\n tail = result.then(\n () => undefined,\n () => undefined,\n );\n return result;\n };\n\n return { register, fetch };\n};\n"],"mappings":";;;;AAgBA,IAAM,mBAAN,cAA+B,OAAO,YAA8B,CAAC,CACnE,oBACA;CACE,eAAe,OAAO;CACtB,YAAY,OAAO;CACnB,SAAS,OAAO;AAClB,CACF,CAAC,CAAC,CAAC;AAEH,IAAM,qBAAN,cAAiC,OAAO,YAAgC,CAAC,CACvE,sBACA;CAAE,eAAe,OAAO;CAAQ,SAAS,OAAO;AAAO,CACzD,CAAC,CAAC,CAAC;AAEH,IAAM,mBAAN,cAA+B,OAAO,YAA8B,CAAC,CACnE,oBACA;CAAE,MAAM,OAAO;CAAQ,SAAS,OAAO;AAAO,CAChD,CAAC,CAAC,CAAC;AAOH,MAAM,mBAAmB,WAAqC;CAC5D,MAAM,aAAqC,CAAC;CAC5C,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAAI,CAAC,MAAM,WAAW,WAAW,GAAG,KAAK,OAAO,KAAK,MAAM,UAAU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AAS,MACb;IACE,QAAQ,SAAS;IACjB,YAAY,SAAS;IACrB,SAAS,SAAS;GACpB,CACF;EACF;EACA,MAAM,SAAS,KAAK,KAAK,GAAG;EAC5B,OAAO,OAAO,WACN,KAAA,SACA,KAAA,CACR;EACA,OAAO;CACT;CAEA,OAAO;EAAE;EAAU;CAAM;AAC3B"}
1
+ {"version":3,"file":"MountedHttp.js","names":[],"sources":["../../src/internal/MountedHttp.ts"],"sourcesContent":["/* oxlint-disable effecttsgo/async-function -- This convex-test adapter uses Promise callbacks and temporarily overrides the real process environment consumed by HTTP module construction. */\nimport type { TestConvexForDataModel } from \"convex-test\";\nimport type {\n GenericDataModel,\n HttpRouter,\n FunctionReference,\n RoutableMethod,\n PublicHttpAction,\n} from \"convex/server\";\nimport { actionGeneric } from \"convex/server\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport type { HttpMount, RegisterComponent } from \"../TestConfect.js\";\n\ndeclare const process: { env: Record<string, string | undefined> };\n\nclass InvalidHttpMount extends Schema.TaggedError<InvalidHttpMount>()(\n \"InvalidHttpMount\",\n {\n componentPath: Schema.String,\n httpPrefix: Schema.String,\n message: Schema.String,\n },\n) {}\n\nclass ComponentHttpError extends Schema.TaggedError<ComponentHttpError>()(\n \"ComponentHttpError\",\n { componentPath: Schema.String, message: Schema.String },\n) {}\n\nclass InvalidFetchPath extends Schema.TaggedError<InvalidFetchPath>()(\n \"InvalidFetchPath\",\n { path: Schema.String, message: Schema.String },\n) {}\n\ntype NormalizedMount = {\n readonly componentPath: string;\n readonly prefix: string;\n};\n\nconst normalizeMounts = (mounts: ReadonlyArray<HttpMount>) => {\n const normalized: Array<NormalizedMount> = [];\n for (const mount of mounts) {\n if (!mount.httpPrefix.startsWith(\"/\") || /[?#]/.test(mount.httpPrefix)) {\n return Result.fail(\n new InvalidHttpMount({\n ...mount,\n message:\n \"httpPrefix must be an absolute path without a query or fragment.\",\n }),\n );\n }\n const prefix = mount.httpPrefix.replace(/\\/+$/, \"\");\n if (normalized.some((previous) => previous.prefix === prefix)) {\n return Result.fail(\n new InvalidHttpMount({\n ...mount,\n message: \"Each httpPrefix must select one component installation.\",\n }),\n );\n }\n normalized.push({ componentPath: mount.componentPath, prefix });\n }\n return Result.succeed(\n normalized.sort((a, b) => b.prefix.length - a.prefix.length),\n );\n};\n\ntype HttpRequest = {\n siteUrl: string;\n url: string;\n pathname: string;\n method: string;\n headers: Array<[string, string]>;\n body: ArrayBuffer | null;\n};\n\ntype HttpResponse = {\n status: number;\n statusText: string;\n headers: Array<[string, string]>;\n body: ArrayBuffer;\n};\n\n// Convex omits this runtime entry point from its published declarations.\nconst isInvokable = (\n action: PublicHttpAction,\n): action is PublicHttpAction & {\n invokeHttpAction(request: Request): Promise<Response>;\n} =>\n \"invokeHttpAction\" in action && typeof action.invokeHttpAction === \"function\";\n\nconst bridgeModule = \"__confect_test_http\";\nconst defaultSiteUrl = \"https://some.convex.site\";\n\nexport const make = (\n mounts: ReadonlyArray<HttpMount>,\n registerComponent: RegisterComponent,\n) => {\n const normalized = normalizeMounts(mounts);\n if (Result.isFailure(normalized)) throw normalized.failure;\n const registered = new Set<string>();\n let tail = Promise.resolve();\n\n const register: RegisterComponent = (componentPath, schema, modules) => {\n if (\n !normalized.success.some((mount) => mount.componentPath === componentPath)\n ) {\n registerComponent(componentPath, schema, modules);\n return;\n }\n const generated = Object.keys(modules).find((key) =>\n key.includes(\"_generated\"),\n );\n const root = generated?.split(\"_generated\", 2)[0];\n const moduleLoaders = Object.fromEntries(\n Object.entries(modules).map(([path, load]) => [\n path.replace(/\\.[^.]+$/, \"\"),\n load,\n ]),\n );\n const loadHttp =\n root === undefined ? undefined : moduleLoaders[`${root}http`];\n if (root === undefined || loadHttp === undefined) {\n throw new ComponentHttpError({\n componentPath,\n message:\n \"Mounted components need an HTTP module and Convex _generated modules.\",\n });\n }\n const bridgePath = `${root}${bridgeModule}.ts`;\n if (`${root}${bridgeModule}` in moduleLoaders) {\n throw new ComponentHttpError({\n componentPath,\n message: `${bridgeModule} is reserved for mounted HTTP tests.`,\n });\n }\n const routers = new Map<string, Promise<HttpRouter>>();\n const invoke = actionGeneric({\n handler: async (_ctx, args: HttpRequest): Promise<HttpResponse> => {\n const previousSiteUrl = process.env.CONVEX_SITE_URL;\n try {\n process.env.CONVEX_SITE_URL = args.siteUrl;\n let router = routers.get(args.siteUrl);\n if (router === undefined) {\n router = loadHttp().then(\n (module: { default: HttpRouter }) => module.default,\n );\n routers.set(args.siteUrl, router);\n }\n const route = (await router).lookup(\n args.pathname,\n args.method as RoutableMethod,\n );\n let response: Response;\n if (route === null) {\n response = new Response(\n `No HttpAction routed for ${args.pathname}`,\n { status: 404 },\n );\n } else {\n const action = route[0];\n if (!isInvokable(action)) {\n throw new ComponentHttpError({\n componentPath,\n message:\n \"This Convex version does not expose invokeHttpAction for HTTP tests.\",\n });\n }\n // Convex selects on the relative path and passes the full URL to the handler.\n response = await action.invokeHttpAction(\n new Request(args.url, {\n method: args.method,\n headers: args.headers,\n ...(args.body === null ? {} : { body: args.body }),\n }),\n );\n }\n return {\n status: response.status,\n statusText: response.statusText,\n headers: [...response.headers],\n body: await response.arrayBuffer(),\n };\n } finally {\n if (previousSiteUrl === undefined) delete process.env.CONVEX_SITE_URL;\n else process.env.CONVEX_SITE_URL = previousSiteUrl;\n }\n },\n });\n registerComponent(componentPath, schema, {\n ...modules,\n [bridgePath]: () => Promise.resolve({ invoke }),\n });\n registered.add(componentPath);\n };\n\n const fetch = <DataModel extends GenericDataModel>(\n accessor: TestConvexForDataModel<DataModel>,\n path: string,\n init?: RequestInit,\n ): Promise<Response> => {\n if (normalized.success.length === 0) return accessor.fetch(path, init);\n const run = async () => {\n if (!path.startsWith(\"/\")) {\n throw new InvalidFetchPath({\n path,\n message: 'Path given to fetch must start with a \"/\".',\n });\n }\n const pathname = new URL(`${defaultSiteUrl}${path}`).pathname;\n const mount = normalized.success.find(\n ({ prefix }) =>\n pathname === prefix || pathname.startsWith(`${prefix}/`),\n );\n if (mount === undefined) return accessor.fetch(path, init);\n if (!registered.has(mount.componentPath)) {\n throw new ComponentHttpError({\n componentPath: mount.componentPath,\n message: \"Register the mounted component before calling fetch.\",\n });\n }\n const appSiteUrl = (\n process.env.CONVEX_SITE_URL || defaultSiteUrl\n ).replace(/\\/$/, \"\");\n const request = new Request(new URL(`${appSiteUrl}${path}`), init);\n // convex-test encodes exact component paths in test-only function handles.\n const reference =\n `function://${mount.componentPath};${bridgeModule}:invoke` as unknown as FunctionReference<\n \"action\",\n \"public\",\n HttpRequest,\n HttpResponse\n >;\n const response = await accessor.action(reference, {\n siteUrl: `${appSiteUrl}${mount.prefix}`,\n url: request.url,\n pathname: pathname.slice(mount.prefix.length) || \"/\",\n method: request.method,\n headers: [...request.headers],\n body:\n request.method === \"GET\" || request.method === \"HEAD\"\n ? null\n : await request.arrayBuffer(),\n });\n return new Response(\n request.method === \"HEAD\" || [204, 205, 304].includes(response.status)\n ? null\n : response.body,\n {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n },\n );\n };\n const result = tail.then(run);\n tail = result.then(\n () => undefined,\n () => undefined,\n );\n return result;\n };\n\n return { register, fetch };\n};\n"],"mappings":";;;;AAgBA,IAAM,mBAAN,cAA+B,OAAO,YAA8B,CAAC,CACnE,oBACA;CACE,eAAe,OAAO;CACtB,YAAY,OAAO;CACnB,SAAS,OAAO;AAClB,CACF,CAAC,CAAC,CAAC;AAEH,IAAM,qBAAN,cAAiC,OAAO,YAAgC,CAAC,CACvE,sBACA;CAAE,eAAe,OAAO;CAAQ,SAAS,OAAO;AAAO,CACzD,CAAC,CAAC,CAAC;AAEH,IAAM,mBAAN,cAA+B,OAAO,YAA8B,CAAC,CACnE,oBACA;CAAE,MAAM,OAAO;CAAQ,SAAS,OAAO;AAAO,CAChD,CAAC,CAAC,CAAC;AAOH,MAAM,mBAAmB,WAAqC;CAC5D,MAAM,aAAqC,CAAC;CAC5C,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAA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;IAAK;IAAK;GAAG,CAAC,CAAC,SAAS,SAAS,MAAM,IACjE,OACA,SAAS,MACb;IACE,QAAQ,SAAS;IACjB,YAAY,SAAS;IACrB,SAAS,SAAS;GACpB,CACF;EACF;EACA,MAAM,SAAS,KAAK,KAAK,GAAG;EAC5B,OAAO,OAAO,WACN,KAAA,SACA,KAAA,CACR;EACA,OAAO;CACT;CAEA,OAAO;EAAE;EAAU;CAAM;AAC3B"}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@gaganref/confect-test",
3
- "version": "10.3.1-fork.4",
3
+ "version": "10.3.1-fork.6",
4
4
  "peerDependencies": {
5
- "@confect/core": "npm:@gaganref/confect-core@10.3.1-fork.4",
6
- "@confect/server": "npm:@gaganref/confect-server@10.3.1-fork.4",
5
+ "@confect/core": "npm:@gaganref/confect-core@10.3.1-fork.6",
6
+ "@confect/server": "npm:@gaganref/confect-server@10.3.1-fork.6",
7
7
  "convex": "^1.32.0",
8
8
  "convex-test": ">=0.0.50 <0.1.0",
9
9
  "effect": "^4.0.0"
@@ -18,7 +18,7 @@ import * as Context from "effect/Context";
18
18
  import * as Effect from "effect/Effect";
19
19
  import * as Layer from "effect/Layer";
20
20
  import * as Schema from "effect/Schema";
21
- import * as MountedHttp from "./internal/MountedHttp";
21
+ import * as MountedHttp from "./internal/MountedHttp.js";
22
22
 
23
23
  /**
24
24
  * Register a component's Convex schema and modules at its installation path.
package/src/index.ts CHANGED
@@ -1 +1 @@
1
- export * as TestConfect from "./TestConfect";
1
+ export * as TestConfect from "./TestConfect.js";
@@ -10,7 +10,7 @@ import type {
10
10
  import { actionGeneric } from "convex/server";
11
11
  import * as Result from "effect/Result";
12
12
  import * as Schema from "effect/Schema";
13
- import type { HttpMount, RegisterComponent } from "../TestConfect";
13
+ import type { HttpMount, RegisterComponent } from "../TestConfect.js";
14
14
 
15
15
  declare const process: { env: Record<string, string | undefined> };
16
16