@confect/server 9.0.0-next.0 → 9.0.0-next.10
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 +299 -4
- package/dist/ActionCtx.d.ts +4 -11
- package/dist/ActionCtx.d.ts.map +1 -1
- package/dist/ActionCtx.js +1 -1
- package/dist/ActionCtx.js.map +1 -1
- package/dist/ActionRunner.d.ts +8 -13
- package/dist/ActionRunner.d.ts.map +1 -1
- package/dist/ActionRunner.js +4 -3
- package/dist/ActionRunner.js.map +1 -1
- package/dist/Auth.d.ts +17 -23
- package/dist/Auth.d.ts.map +1 -1
- package/dist/Auth.js +5 -1
- package/dist/Auth.js.map +1 -1
- package/dist/BlobNotFoundError.d.ts +6 -12
- package/dist/BlobNotFoundError.d.ts.map +1 -1
- package/dist/BlobNotFoundError.js +1 -1
- package/dist/BlobNotFoundError.js.map +1 -1
- package/dist/ConvexConfigProvider.d.ts +2 -9
- package/dist/ConvexConfigProvider.d.ts.map +1 -1
- package/dist/ConvexConfigProvider.js +6 -1
- package/dist/ConvexConfigProvider.js.map +1 -1
- package/dist/CronJob.d.ts +12 -19
- package/dist/CronJob.d.ts.map +1 -1
- package/dist/CronJob.js +1 -1
- package/dist/CronJob.js.map +1 -1
- package/dist/CronJobs.d.ts +11 -18
- package/dist/CronJobs.d.ts.map +1 -1
- package/dist/CronJobs.js +11 -4
- package/dist/CronJobs.js.map +1 -1
- package/dist/DataModel.d.ts +24 -29
- package/dist/DataModel.d.ts.map +1 -1
- package/dist/DatabaseReader.d.ts +4323 -64
- package/dist/DatabaseReader.d.ts.map +1 -1
- package/dist/DatabaseReader.js +6 -6
- package/dist/DatabaseReader.js.map +1 -1
- package/dist/DatabaseSchema.d.ts +38 -130
- package/dist/DatabaseSchema.d.ts.map +1 -1
- package/dist/DatabaseSchema.js +20 -30
- package/dist/DatabaseSchema.js.map +1 -1
- package/dist/DatabaseWriter.d.ts +38 -42
- package/dist/DatabaseWriter.d.ts.map +1 -1
- package/dist/DatabaseWriter.js +8 -5
- package/dist/DatabaseWriter.js.map +1 -1
- package/dist/Document.d.ts +28 -37
- package/dist/Document.d.ts.map +1 -1
- package/dist/Document.js +5 -1
- package/dist/Document.js.map +1 -1
- package/dist/FunctionImpl.d.ts +30 -29
- package/dist/FunctionImpl.d.ts.map +1 -1
- package/dist/FunctionImpl.js +25 -14
- package/dist/FunctionImpl.js.map +1 -1
- package/dist/GroupImpl.d.ts +45 -41
- package/dist/GroupImpl.d.ts.map +1 -1
- package/dist/GroupImpl.js +42 -35
- package/dist/GroupImpl.js.map +1 -1
- package/dist/Handler.d.ts +34 -40
- package/dist/Handler.d.ts.map +1 -1
- package/dist/HttpApi.d.ts +21 -25
- package/dist/HttpApi.d.ts.map +1 -1
- package/dist/HttpApi.js +11 -6
- package/dist/HttpApi.js.map +1 -1
- package/dist/MutationCtx.d.ts +4 -11
- package/dist/MutationCtx.d.ts.map +1 -1
- package/dist/MutationCtx.js +1 -1
- package/dist/MutationCtx.js.map +1 -1
- package/dist/MutationRunner.d.ts +8 -13
- package/dist/MutationRunner.d.ts.map +1 -1
- package/dist/MutationRunner.js +4 -3
- package/dist/MutationRunner.js.map +1 -1
- package/dist/OrderedQuery.d.ts +16 -21
- package/dist/OrderedQuery.d.ts.map +1 -1
- package/dist/OrderedQuery.js +4 -1
- package/dist/OrderedQuery.js.map +1 -1
- package/dist/QueryCtx.d.ts +4 -11
- package/dist/QueryCtx.d.ts.map +1 -1
- package/dist/QueryCtx.js +1 -1
- package/dist/QueryCtx.js.map +1 -1
- package/dist/QueryInitializer.d.ts +34 -39
- package/dist/QueryInitializer.d.ts.map +1 -1
- package/dist/QueryInitializer.js +5 -1
- package/dist/QueryInitializer.js.map +1 -1
- package/dist/QueryRunner.d.ts +8 -13
- package/dist/QueryRunner.d.ts.map +1 -1
- package/dist/QueryRunner.js +4 -3
- package/dist/QueryRunner.js.map +1 -1
- package/dist/RegisteredConvexFunction.d.ts +1107 -60
- package/dist/RegisteredConvexFunction.d.ts.map +1 -1
- package/dist/RegisteredConvexFunction.js +14 -9
- package/dist/RegisteredConvexFunction.js.map +1 -1
- package/dist/RegisteredFunction.d.ts +48 -64
- package/dist/RegisteredFunction.d.ts.map +1 -1
- package/dist/RegisteredFunction.js +9 -5
- package/dist/RegisteredFunction.js.map +1 -1
- package/dist/RegisteredFunctions.d.ts +48 -26
- package/dist/RegisteredFunctions.d.ts.map +1 -1
- package/dist/RegisteredFunctions.js +22 -9
- package/dist/RegisteredFunctions.js.map +1 -1
- package/dist/RegisteredNodeFunction.d.ts +4 -14
- package/dist/RegisteredNodeFunction.d.ts.map +1 -1
- package/dist/RegisteredNodeFunction.js +5 -4
- package/dist/RegisteredNodeFunction.js.map +1 -1
- package/dist/RegistryItem.d.ts +17 -27
- package/dist/RegistryItem.d.ts.map +1 -1
- package/dist/RegistryItem.js +1 -1
- package/dist/RegistryItem.js.map +1 -1
- package/dist/Scheduler.d.ts +16 -20
- package/dist/Scheduler.d.ts.map +1 -1
- package/dist/Scheduler.js +10 -6
- package/dist/Scheduler.js.map +1 -1
- package/dist/SchemaToValidator.d.ts +71 -64
- package/dist/SchemaToValidator.d.ts.map +1 -1
- package/dist/SchemaToValidator.js +15 -3
- package/dist/SchemaToValidator.js.map +1 -1
- package/dist/StorageActionWriter.d.ts +21 -28
- package/dist/StorageActionWriter.d.ts.map +1 -1
- package/dist/StorageActionWriter.js +4 -1
- package/dist/StorageActionWriter.js.map +1 -1
- package/dist/StorageReader.d.ts +14 -21
- package/dist/StorageReader.d.ts.map +1 -1
- package/dist/StorageReader.js +5 -1
- package/dist/StorageReader.js.map +1 -1
- package/dist/StorageWriter.d.ts +16 -23
- package/dist/StorageWriter.d.ts.map +1 -1
- package/dist/StorageWriter.js +4 -1
- package/dist/StorageWriter.js.map +1 -1
- package/dist/Table.d.ts +204 -197
- package/dist/Table.d.ts.map +1 -1
- package/dist/Table.js +72 -62
- package/dist/Table.js.map +1 -1
- package/dist/TableInfo.d.ts +35 -41
- package/dist/TableInfo.d.ts.map +1 -1
- package/dist/VectorSearch.d.ts +30 -35
- package/dist/VectorSearch.d.ts.map +1 -1
- package/dist/VectorSearch.js +3 -1
- package/dist/VectorSearch.js.map +1 -1
- package/dist/index.d.ts +35 -36
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -5
- package/dist/internal/utils.d.ts +9 -11
- package/dist/internal/utils.d.ts.map +1 -1
- package/dist/internal/utils.js +3 -1
- package/dist/internal/utils.js.map +1 -1
- package/dist/node.d.ts +2 -2
- package/dist/node.d.ts.map +1 -0
- package/dist/tsconfig.src.tsbuildinfo +1 -0
- package/package.json +50 -59
- package/src/ActionCtx.ts +1 -1
- package/src/ActionRunner.ts +2 -1
- package/src/Auth.ts +5 -1
- package/src/BlobNotFoundError.ts +1 -1
- package/src/ConvexConfigProvider.ts +6 -8
- package/src/CronJob.ts +1 -1
- package/src/CronJobs.ts +8 -10
- package/src/DatabaseReader.ts +18 -21
- package/src/DatabaseSchema.ts +38 -98
- package/src/DatabaseWriter.ts +13 -6
- package/src/Document.ts +5 -1
- package/src/FunctionImpl.ts +36 -44
- package/src/GroupImpl.ts +54 -81
- package/src/HttpApi.ts +8 -9
- package/src/MutationCtx.ts +1 -1
- package/src/MutationRunner.ts +2 -1
- package/src/OrderedQuery.ts +5 -1
- package/src/QueryCtx.ts +1 -1
- package/src/QueryInitializer.ts +15 -3
- package/src/QueryRunner.ts +2 -1
- package/src/RegisteredConvexFunction.ts +11 -7
- package/src/RegisteredFunction.ts +5 -1
- package/src/RegisteredFunctions.ts +69 -93
- package/src/RegisteredNodeFunction.ts +7 -6
- package/src/RegistryItem.ts +1 -1
- package/src/Scheduler.ts +5 -1
- package/src/SchemaToValidator.ts +14 -16
- package/src/StorageActionWriter.ts +4 -1
- package/src/StorageReader.ts +5 -1
- package/src/StorageWriter.ts +4 -1
- package/src/Table.ts +253 -132
- package/src/VectorSearch.ts +3 -1
- package/src/index.ts +0 -1
- package/src/internal/utils.ts +3 -1
- package/dist/Api.d.ts +0 -30
- package/dist/Api.d.ts.map +0 -1
- package/dist/Api.js +0 -26
- package/dist/Api.js.map +0 -1
- package/dist/GroupPath.d.ts +0 -8
- package/dist/GroupPath.d.ts.map +0 -1
- package/dist/GroupPath.js +0 -10
- package/dist/GroupPath.js.map +0 -1
- package/src/Api.ts +0 -75
- package/src/GroupPath.ts +0 -43
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegisteredConvexFunction.d.ts","
|
|
1
|
+
{"version":3,"file":"RegisteredConvexFunction.d.ts","sourceRoot":"","sources":["../src/RegisteredConvexFunction.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,kBAAkB,EAOxB,MAAM,eAAe,CAAC;AAIvB,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAE/B,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,KAAK,SAAS,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,KAAK,YAAY,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,eAAO,MAAM,IAAI,GACf,g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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAkBxE,CAAC;AAEJ,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,cAAc,CAAC,YAAY,IACnE,cAAc,CAAC,cAAc,CAAC,MAAM,CAAC,GACrC,cAAc,CAAC,cAAc,CAAC,MAAM,CAAC,GACrC,IAAI,CAAC,IAAI,GACT,SAAS,CAAC,SAAS,GACnB,aAAa,GACb,aAAa,GACb,WAAW,CAAC,WAAW,GACvB,cAAc,CAAC,cAAc,GAC7B,WAAW,CAAC,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -7,24 +7,29 @@ import { layer as layer$2 } from "./DatabaseWriter.js";
|
|
|
7
7
|
import { layer as layer$3 } from "./MutationRunner.js";
|
|
8
8
|
import { layer as layer$4 } from "./QueryRunner.js";
|
|
9
9
|
import { layer as layer$5 } from "./Scheduler.js";
|
|
10
|
-
import { StorageReader
|
|
11
|
-
import { StorageWriter
|
|
10
|
+
import { StorageReader } from "./StorageReader.js";
|
|
11
|
+
import { StorageWriter } from "./StorageWriter.js";
|
|
12
12
|
import { MutationCtx } from "./MutationCtx.js";
|
|
13
13
|
import { QueryCtx } from "./QueryCtx.js";
|
|
14
14
|
import { actionFunctionBase, actionLayer, runHandlerPromise } from "./RegisteredFunction.js";
|
|
15
|
-
import { Clock, Effect, Layer, Match, Schema, pipe } from "effect";
|
|
16
15
|
import { actionGeneric, internalActionGeneric, internalMutationGeneric, internalQueryGeneric, mutationGeneric, queryGeneric } from "convex/server";
|
|
16
|
+
import * as Layer from "effect/Layer";
|
|
17
|
+
import { pipe } from "effect/Function";
|
|
18
|
+
import * as Effect from "effect/Effect";
|
|
19
|
+
import * as Schema from "effect/Schema";
|
|
20
|
+
import * as Match from "effect/Match";
|
|
21
|
+
import * as Clock from "effect/Clock";
|
|
17
22
|
|
|
18
23
|
//#region src/RegisteredConvexFunction.ts
|
|
19
24
|
var RegisteredConvexFunction_exports = /* @__PURE__ */ __exportAll({
|
|
20
25
|
make: () => make,
|
|
21
26
|
mutationLayer: () => mutationLayer
|
|
22
27
|
});
|
|
23
|
-
const make = (
|
|
28
|
+
const make = (databaseSchema, { functionSpec, handler }) => Match.value(functionSpec.functionProvenance).pipe(Match.tag("Convex", () => handler), Match.tag("Confect", () => {
|
|
24
29
|
const { functionVisibility, functionProvenance } = functionSpec;
|
|
25
30
|
return Match.value(functionSpec.runtimeAndFunctionType.functionType).pipe(Match.when("query", () => {
|
|
26
31
|
return Match.value(functionVisibility).pipe(Match.when("public", () => queryGeneric), Match.when("internal", () => internalQueryGeneric), Match.exhaustive)(queryFunction({
|
|
27
|
-
databaseSchema
|
|
32
|
+
databaseSchema,
|
|
28
33
|
args: functionProvenance.args,
|
|
29
34
|
returns: functionProvenance.returns,
|
|
30
35
|
error: functionProvenance.error,
|
|
@@ -32,14 +37,14 @@ const make = (api, { functionSpec, handler }) => Match.value(functionSpec.functi
|
|
|
32
37
|
}));
|
|
33
38
|
}), Match.when("mutation", () => {
|
|
34
39
|
return Match.value(functionVisibility).pipe(Match.when("public", () => mutationGeneric), Match.when("internal", () => internalMutationGeneric), Match.exhaustive)(mutationFunction({
|
|
35
|
-
databaseSchema
|
|
40
|
+
databaseSchema,
|
|
36
41
|
args: functionProvenance.args,
|
|
37
42
|
returns: functionProvenance.returns,
|
|
38
43
|
error: functionProvenance.error,
|
|
39
44
|
handler
|
|
40
45
|
}));
|
|
41
46
|
}), Match.when("action", () => {
|
|
42
|
-
return Match.value(functionVisibility).pipe(Match.when("public", () => actionGeneric), Match.when("internal", () => internalActionGeneric), Match.exhaustive)(convexActionFunction(
|
|
47
|
+
return Match.value(functionVisibility).pipe(Match.when("public", () => actionGeneric), Match.when("internal", () => internalActionGeneric), Match.exhaustive)(convexActionFunction(databaseSchema, {
|
|
43
48
|
args: functionProvenance.args,
|
|
44
49
|
returns: functionProvenance.returns,
|
|
45
50
|
error: functionProvenance.error,
|
|
@@ -84,10 +89,10 @@ const queryFunction = ({ databaseSchema, args, returns, error, handler }) => ({
|
|
|
84
89
|
args: compileArgsSchema(args),
|
|
85
90
|
returns: compileReturnsSchema(returns),
|
|
86
91
|
handler: (ctx, actualArgs) => withStubbedDateNow((clock) => Effect.gen(function* () {
|
|
87
|
-
return yield* pipe(yield* handler(yield* pipe(actualArgs, Schema.decode(args), Effect.orDie)).pipe(Effect.provide(Layer.mergeAll(layer$1(databaseSchema, ctx.db), layer(ctx.auth), StorageReader
|
|
92
|
+
return yield* pipe(yield* handler(yield* pipe(actualArgs, Schema.decode(args), Effect.orDie)).pipe(Effect.provide(Layer.mergeAll(layer$1(databaseSchema, ctx.db), layer(ctx.auth), StorageReader.layer(ctx.storage), layer$4(ctx.runQuery), Layer.succeed(QueryCtx(), ctx), Layer.setConfigProvider(make$1())))), Schema.encode(returns), Effect.orDie);
|
|
88
93
|
}).pipe(Effect.withClock(clock), runHandlerPromise(error)))
|
|
89
94
|
});
|
|
90
|
-
const mutationLayer = (schema, ctx) => Layer.mergeAll(layer$1(schema, ctx.db), layer$2(schema, ctx.db), layer(ctx.auth), layer$5(ctx.scheduler), StorageReader
|
|
95
|
+
const mutationLayer = (schema, ctx) => Layer.mergeAll(layer$1(schema, ctx.db), layer$2(schema, ctx.db), layer(ctx.auth), layer$5(ctx.scheduler), StorageReader.layer(ctx.storage), StorageWriter.layer(ctx.storage), layer$4(ctx.runQuery), layer$3(ctx.runMutation), Layer.succeed(MutationCtx(), ctx), Layer.setConfigProvider(make$1()));
|
|
91
96
|
const mutationFunction = ({ databaseSchema, args, returns, error, handler }) => ({
|
|
92
97
|
args: compileArgsSchema(args),
|
|
93
98
|
returns: compileReturnsSchema(returns),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegisteredConvexFunction.js","names":["SchemaToValidator.compileArgsSchema","SchemaToValidator.compileReturnsSchema","DatabaseReader.layer","Auth.layer","StorageReader","QueryRunner.layer","QueryCtx.QueryCtx","ConvexConfigProvider.make","RegisteredFunction.runHandlerPromise","DatabaseWriter.layer","Scheduler.layer","StorageWriter","MutationRunner.layer","MutationCtx.MutationCtx","RegisteredFunction.actionFunctionBase","RegisteredFunction.actionLayer"],"sources":["../src/RegisteredConvexFunction.ts"],"sourcesContent":["import type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport {\n actionGeneric,\n type DefaultFunctionArgs,\n type GenericMutationCtx,\n type GenericQueryCtx,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n mutationGeneric,\n queryGeneric,\n} from \"convex/server\";\nimport type { Value } from \"convex/values\";\nimport { Clock, Effect, Layer, Match, pipe, Schema } from \"effect\";\nimport type * as Api from \"./Api\";\nimport * as Auth from \"./Auth\";\nimport * as ConvexConfigProvider from \"./ConvexConfigProvider\";\nimport * as DatabaseReader from \"./DatabaseReader\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport * as DatabaseWriter from \"./DatabaseWriter\";\nimport type * as DataModel from \"./DataModel\";\nimport type * as Handler from \"./Handler\";\nimport * as MutationCtx from \"./MutationCtx\";\nimport * as MutationRunner from \"./MutationRunner\";\nimport * as QueryCtx from \"./QueryCtx\";\nimport * as QueryRunner from \"./QueryRunner\";\nimport * as RegisteredFunction from \"./RegisteredFunction\";\nimport type * as RegistryItem from \"./RegistryItem\";\nimport * as Scheduler from \"./Scheduler\";\nimport * as SchemaToValidator from \"./SchemaToValidator\";\nimport { StorageReader } from \"./StorageReader\";\nimport { StorageWriter } from \"./StorageWriter\";\n\nexport const make = <Api_ extends Api.AnyWithPropsWithRuntime<\"Convex\">>(\n api: Api_,\n { functionSpec, handler }: RegistryItem.AnyWithProps,\n): RegisteredFunction.Any =>\n Match.value(functionSpec.functionProvenance).pipe(\n Match.tag(\"Convex\", () => handler as RegisteredFunction.Any),\n Match.tag(\"Confect\", () => {\n const { functionVisibility, functionProvenance } =\n functionSpec as FunctionSpec.AnyConfect;\n\n return Match.value(functionSpec.runtimeAndFunctionType.functionType).pipe(\n Match.when(\"query\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => queryGeneric),\n Match.when(\"internal\", () => internalQueryGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n queryFunction({\n databaseSchema: api.databaseSchema,\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n error: functionProvenance.error,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.when(\"mutation\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => mutationGeneric),\n Match.when(\"internal\", () => internalMutationGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n mutationFunction({\n databaseSchema: api.databaseSchema,\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n error: functionProvenance.error,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.when(\"action\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => actionGeneric),\n Match.when(\"internal\", () => internalActionGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n convexActionFunction(api.databaseSchema, {\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n error: functionProvenance.error,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.exhaustive,\n );\n }),\n Match.exhaustive,\n );\n\n/**\n * Convex's query cache is invalidated by any Date.now() call during handler\n * execution. Effect's unsafeFork calls Date.now() when constructing a\n * FiberId.Runtime, which trips the cache for every confect-wrapped query. We\n * stub Date.now to 0 for the span of the handler; queries are forbidden from\n * relying on real time for correctness anyway.\n *\n * Users who explicitly want the real timestamp can still reach it via Effect's\n * Clock service (Clock.currentTimeMillis/Clock.currentTimeNanos). We provide a\n * Clock whose user-facing Effects call realDateNow (Convex's tracker) directly,\n * making Clock an explicit opt-in to cache invalidation. The unsafe methods\n * used internally by Effect (logging, span events, scheduler) return constants\n * so they never touch the tracker—caching is not broken by default.\n */\nconst unpatchedClock = (realDateNow: () => number): Clock.Clock => {\n const defaultClock = Clock.make();\n return {\n ...defaultClock,\n unsafeCurrentTimeMillis: () => 0,\n unsafeCurrentTimeNanos: () => 0n,\n currentTimeMillis: Effect.sync(() => realDateNow()),\n currentTimeNanos: Effect.sync(() => BigInt(realDateNow()) * 1_000_000n),\n };\n};\n\nconst withStubbedDateNow = async <T>(\n queryHandler: (clock: Clock.Clock) => Promise<T>,\n): Promise<T> => {\n const realDateNow = Date.now;\n const clock = unpatchedClock(realDateNow);\n Date.now = () => 0;\n try {\n return await queryHandler(clock);\n } finally {\n Date.now = realDateNow;\n }\n};\n\nconst queryFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>({\n databaseSchema,\n args,\n returns,\n error,\n handler,\n}: {\n databaseSchema: DatabaseSchema_;\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema<Error, Value> | undefined;\n handler: (\n a: Args,\n ) => Effect.Effect<\n Returns,\n E,\n | DatabaseReader.DatabaseReader<DatabaseSchema_>\n | Auth.Auth\n | StorageReader\n | QueryRunner.QueryRunner\n | QueryCtx.QueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >\n >;\n}) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericQueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n actualArgs: ConvexArgs,\n ): Promise<ConvexReturns> =>\n withStubbedDateNow((clock) =>\n Effect.gen(function* () {\n const decodedArgs = yield* pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n );\n const decodedReturns = yield* handler(decodedArgs).pipe(\n Effect.provide(\n Layer.mergeAll(\n DatabaseReader.layer(databaseSchema, ctx.db),\n Auth.layer(ctx.auth),\n StorageReader.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n Layer.succeed(\n QueryCtx.QueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >(),\n ctx,\n ),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n ),\n ),\n );\n return yield* pipe(\n decodedReturns,\n Schema.encode(returns),\n Effect.orDie,\n );\n }).pipe(\n Effect.withClock(clock),\n RegisteredFunction.runHandlerPromise(error),\n ),\n ),\n});\n\nexport const mutationLayer = <Schema extends DatabaseSchema.AnyWithProps>(\n schema: Schema,\n ctx: GenericMutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,\n) =>\n Layer.mergeAll(\n DatabaseReader.layer(schema, ctx.db),\n DatabaseWriter.layer(schema, ctx.db),\n Auth.layer(ctx.auth),\n Scheduler.layer(ctx.scheduler),\n StorageReader.layer(ctx.storage),\n StorageWriter.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n MutationRunner.layer(ctx.runMutation),\n Layer.succeed(\n MutationCtx.MutationCtx<\n DataModel.ToConvex<DataModel.FromSchema<Schema>>\n >(),\n ctx,\n ),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n );\n\nexport type MutationServices<Schema extends DatabaseSchema.AnyWithProps> =\n | DatabaseReader.DatabaseReader<Schema>\n | DatabaseWriter.DatabaseWriter<Schema>\n | Auth.Auth\n | Scheduler.Scheduler\n | StorageReader\n | StorageWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | MutationCtx.MutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>;\n\nconst mutationFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>({\n databaseSchema,\n args,\n returns,\n error,\n handler,\n}: {\n databaseSchema: DatabaseSchema_;\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema<Error, Value> | undefined;\n handler: (\n a: Args,\n ) => Effect.Effect<Returns, E, MutationServices<DatabaseSchema_>>;\n}) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericMutationCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n actualArgs: ConvexArgs,\n ): Promise<ConvexReturns> =>\n Effect.gen(function* () {\n const decodedArgs = yield* pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n );\n const decodedReturns = yield* handler(decodedArgs).pipe(\n Effect.provide(mutationLayer(databaseSchema, ctx)),\n );\n return yield* pipe(decodedReturns, Schema.encode(returns), Effect.orDie);\n }).pipe(RegisteredFunction.runHandlerPromise(error)),\n});\n\nconst convexActionFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>(\n schema: DatabaseSchema_,\n {\n args,\n returns,\n error,\n handler,\n }: {\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema.AnyNoContext | undefined;\n handler: (\n a: Args,\n ) => Effect.Effect<\n Returns,\n E,\n RegisteredFunction.ActionServices<DatabaseSchema_>\n >;\n },\n) =>\n RegisteredFunction.actionFunctionBase({\n args,\n returns,\n error,\n handler,\n createLayer: (ctx) =>\n Layer.mergeAll(\n RegisteredFunction.action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,IACD,EACD,MAAM,kBAAkBN,QAA2B,CAAC,CACrD;AAaH,MAAM,oBAOJ,EACA,gBACA,MACA,SACA,OACA,eASK;CACL,MAAMP,kBAAoC,KAAK;CAC/C,SAASC,qBAAuC,QAAQ;CACxD,UACE,KAGA,eAEA,OAAO,IAAI,aAAa;AAStB,SAAO,OAAO,KAHS,OAAO,QALV,OAAO,KACzB,YACA,OAAO,OAAO,KAAK,EACnB,OAAO,MACR,CACiD,CAAC,KACjD,OAAO,QAAQ,cAAc,gBAAgB,IAAI,CAAC,CACnD,EACkC,OAAO,OAAO,QAAQ,EAAE,OAAO,MAAM;GACxE,CAAC,KAAKO,kBAAqC,MAAM,CAAC;CACvD;AAED,MAAM,wBAQJ,QACA,EACE,MACA,SACA,OACA,cAcFM,mBAAsC;CACpC;CACA;CACA;CACA;CACA,cAAc,QACZ,MAAM,SACJC,YAA+B,QAAQ,IAAI,EAC3C,MAAM,kBAAkBR,QAA2B,CAAC,CACrD;CACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"RegisteredConvexFunction.js","names":["SchemaToValidator.compileArgsSchema","SchemaToValidator.compileReturnsSchema","DatabaseReader.layer","Auth.layer","QueryRunner.layer","QueryCtx.QueryCtx","ConvexConfigProvider.make","RegisteredFunction.runHandlerPromise","DatabaseWriter.layer","Scheduler.layer","MutationRunner.layer","MutationCtx.MutationCtx","RegisteredFunction.actionFunctionBase","RegisteredFunction.actionLayer"],"sources":["../src/RegisteredConvexFunction.ts"],"sourcesContent":["import type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport {\n actionGeneric,\n type DefaultFunctionArgs,\n type GenericMutationCtx,\n type GenericQueryCtx,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n mutationGeneric,\n queryGeneric,\n} from \"convex/server\";\nimport type { Value } from \"convex/values\";\nimport { pipe } from \"effect/Function\";\nimport * as Clock from \"effect/Clock\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Match from \"effect/Match\";\nimport * as Schema from \"effect/Schema\";\nimport * as Auth from \"./Auth\";\nimport * as ConvexConfigProvider from \"./ConvexConfigProvider\";\nimport * as DatabaseReader from \"./DatabaseReader\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport * as DatabaseWriter from \"./DatabaseWriter\";\nimport type * as DataModel from \"./DataModel\";\nimport type * as Handler from \"./Handler\";\nimport * as MutationCtx from \"./MutationCtx\";\nimport * as MutationRunner from \"./MutationRunner\";\nimport * as QueryCtx from \"./QueryCtx\";\nimport * as QueryRunner from \"./QueryRunner\";\nimport * as RegisteredFunction from \"./RegisteredFunction\";\nimport type * as RegistryItem from \"./RegistryItem\";\nimport * as Scheduler from \"./Scheduler\";\nimport * as SchemaToValidator from \"./SchemaToValidator\";\nimport { StorageReader } from \"./StorageReader\";\nimport { StorageWriter } from \"./StorageWriter\";\n\nexport const make = (\n databaseSchema: DatabaseSchema.AnyWithProps,\n { functionSpec, handler }: RegistryItem.AnyWithProps,\n): RegisteredFunction.Any =>\n Match.value(functionSpec.functionProvenance).pipe(\n Match.tag(\"Convex\", () => handler as RegisteredFunction.Any),\n Match.tag(\"Confect\", () => {\n const { functionVisibility, functionProvenance } =\n functionSpec as FunctionSpec.AnyConfect;\n\n return Match.value(functionSpec.runtimeAndFunctionType.functionType).pipe(\n Match.when(\"query\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => queryGeneric),\n Match.when(\"internal\", () => internalQueryGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n queryFunction({\n databaseSchema,\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n error: functionProvenance.error,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.when(\"mutation\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => mutationGeneric),\n Match.when(\"internal\", () => internalMutationGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n mutationFunction({\n databaseSchema,\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n error: functionProvenance.error,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.when(\"action\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => actionGeneric),\n Match.when(\"internal\", () => internalActionGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n convexActionFunction(databaseSchema, {\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n error: functionProvenance.error,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.exhaustive,\n );\n }),\n Match.exhaustive,\n );\n\n/**\n * Convex's query cache is invalidated by any Date.now() call during handler\n * execution. Effect's unsafeFork calls Date.now() when constructing a\n * FiberId.Runtime, which trips the cache for every confect-wrapped query. We\n * stub Date.now to 0 for the span of the handler; queries are forbidden from\n * relying on real time for correctness anyway.\n *\n * Users who explicitly want the real timestamp can still reach it via Effect's\n * Clock service (Clock.currentTimeMillis/Clock.currentTimeNanos). We provide a\n * Clock whose user-facing Effects call realDateNow (Convex's tracker) directly,\n * making Clock an explicit opt-in to cache invalidation. The unsafe methods\n * used internally by Effect (logging, span events, scheduler) return constants\n * so they never touch the tracker—caching is not broken by default.\n */\nconst unpatchedClock = (realDateNow: () => number): Clock.Clock => {\n const defaultClock = Clock.make();\n return {\n ...defaultClock,\n unsafeCurrentTimeMillis: () => 0,\n unsafeCurrentTimeNanos: () => 0n,\n currentTimeMillis: Effect.sync(() => realDateNow()),\n currentTimeNanos: Effect.sync(() => BigInt(realDateNow()) * 1_000_000n),\n };\n};\n\nconst withStubbedDateNow = async <T>(\n queryHandler: (clock: Clock.Clock) => Promise<T>,\n): Promise<T> => {\n const realDateNow = Date.now;\n const clock = unpatchedClock(realDateNow);\n Date.now = () => 0;\n try {\n return await queryHandler(clock);\n } finally {\n Date.now = realDateNow;\n }\n};\n\nconst queryFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>({\n databaseSchema,\n args,\n returns,\n error,\n handler,\n}: {\n databaseSchema: DatabaseSchema_;\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema<Error, Value> | undefined;\n handler: (\n a: Args,\n ) => Effect.Effect<\n Returns,\n E,\n | DatabaseReader.DatabaseReader<DatabaseSchema_>\n | Auth.Auth\n | StorageReader\n | QueryRunner.QueryRunner\n | QueryCtx.QueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >\n >;\n}) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericQueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n actualArgs: ConvexArgs,\n ): Promise<ConvexReturns> =>\n withStubbedDateNow((clock) =>\n Effect.gen(function* () {\n const decodedArgs = yield* pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n );\n const decodedReturns = yield* handler(decodedArgs).pipe(\n Effect.provide(\n Layer.mergeAll(\n DatabaseReader.layer(databaseSchema, ctx.db),\n Auth.layer(ctx.auth),\n StorageReader.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n Layer.succeed(\n QueryCtx.QueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >(),\n ctx,\n ),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n ),\n ),\n );\n return yield* pipe(\n decodedReturns,\n Schema.encode(returns),\n Effect.orDie,\n );\n }).pipe(\n Effect.withClock(clock),\n RegisteredFunction.runHandlerPromise(error),\n ),\n ),\n});\n\nexport const mutationLayer = <Schema extends DatabaseSchema.AnyWithProps>(\n schema: Schema,\n ctx: GenericMutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,\n) =>\n Layer.mergeAll(\n DatabaseReader.layer(schema, ctx.db),\n DatabaseWriter.layer(schema, ctx.db),\n Auth.layer(ctx.auth),\n Scheduler.layer(ctx.scheduler),\n StorageReader.layer(ctx.storage),\n StorageWriter.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n MutationRunner.layer(ctx.runMutation),\n Layer.succeed(\n MutationCtx.MutationCtx<\n DataModel.ToConvex<DataModel.FromSchema<Schema>>\n >(),\n ctx,\n ),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n );\n\nexport type MutationServices<Schema extends DatabaseSchema.AnyWithProps> =\n | DatabaseReader.DatabaseReader<Schema>\n | DatabaseWriter.DatabaseWriter<Schema>\n | Auth.Auth\n | Scheduler.Scheduler\n | StorageReader\n | StorageWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | MutationCtx.MutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>;\n\nconst mutationFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>({\n databaseSchema,\n args,\n returns,\n error,\n handler,\n}: {\n databaseSchema: DatabaseSchema_;\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema<Error, Value> | undefined;\n handler: (\n a: Args,\n ) => Effect.Effect<Returns, E, MutationServices<DatabaseSchema_>>;\n}) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericMutationCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n actualArgs: ConvexArgs,\n ): Promise<ConvexReturns> =>\n Effect.gen(function* () {\n const decodedArgs = yield* pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n );\n const decodedReturns = yield* handler(decodedArgs).pipe(\n Effect.provide(mutationLayer(databaseSchema, ctx)),\n );\n return yield* pipe(decodedReturns, Schema.encode(returns), Effect.orDie);\n }).pipe(RegisteredFunction.runHandlerPromise(error)),\n});\n\nconst convexActionFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>(\n schema: DatabaseSchema_,\n {\n args,\n returns,\n error,\n handler,\n }: {\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema.AnyNoContext | undefined;\n handler: (\n a: Args,\n ) => Effect.Effect<\n Returns,\n E,\n RegisteredFunction.ActionServices<DatabaseSchema_>\n >;\n },\n) =>\n RegisteredFunction.actionFunctionBase({\n args,\n returns,\n error,\n handler,\n createLayer: (ctx) =>\n Layer.mergeAll(\n RegisteredFunction.actionLayer(schema, ctx),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n ),\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,MAAa,QACX,gBACA,EAAE,cAAc,cAEhB,MAAM,MAAM,aAAa,mBAAmB,CAAC,KAC3C,MAAM,IAAI,gBAAgB,QAAkC,EAC5D,MAAM,IAAI,iBAAiB;CACzB,MAAM,EAAE,oBAAoB,uBAC1B;AAEF,QAAO,MAAM,MAAM,aAAa,uBAAuB,aAAa,CAAC,KACnE,MAAM,KAAK,eAAe;AAOxB,SANwB,MAAM,MAAM,mBAAmB,CAAC,KACtD,MAAM,KAAK,gBAAgB,aAAa,EACxC,MAAM,KAAK,kBAAkB,qBAAqB,EAClD,MAAM,WACP,CAGC,cAAc;GACZ;GACA,MAAM,mBAAmB;GACzB,SAAS,mBAAmB;GAC5B,OAAO,mBAAmB;GACjB;GACV,CAAC,CACH;GACD,EACF,MAAM,KAAK,kBAAkB;AAO3B,SANwB,MAAM,MAAM,mBAAmB,CAAC,KACtD,MAAM,KAAK,gBAAgB,gBAAgB,EAC3C,MAAM,KAAK,kBAAkB,wBAAwB,EACrD,MAAM,WACP,CAGC,iBAAiB;GACf;GACA,MAAM,mBAAmB;GACzB,SAA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CACF,EAGC,OAAO,OAAO,QAAQ,EACtB,OAAO,MACR;GACD,CAAC,KACD,OAAO,UAAU,MAAM,EACvBC,kBAAqC,MAAM,CAC5C,CACF;CACJ;AAED,MAAa,iBACX,QACA,QAEA,MAAM,SACJL,QAAqB,QAAQ,IAAI,GAAG,EACpCM,QAAqB,QAAQ,IAAI,GAAG,EACpCL,MAAW,IAAI,KAAK,EACpBM,QAAgB,IAAI,UAAU,EAC9B,cAAc,MAAM,IAAI,QAAQ,EAChC,cAAc,MAAM,IAAI,QAAQ,EAChCL,QAAkB,IAAI,SAAS,EAC/BM,QAAqB,IAAI,YAAY,EACrC,MAAM,QACJC,aAEG,EACH,IACD,EACD,MAAM,kBAAkBL,QAA2B,CAAC,CACrD;AAaH,MAAM,oBAOJ,EACA,gBACA,MACA,SACA,OACA,eASK;CACL,MAAMN,kBAAoC,KAAK;CAC/C,SAASC,qBAAuC,QAAQ;CACxD,UACE,KAGA,eAEA,OAAO,IAAI,aAAa;AAStB,SAAO,OAAO,KAHS,OAAO,QALV,OAAO,KACzB,YACA,OAAO,OAAO,KAAK,EACnB,OAAO,MACR,CACiD,CAAC,KACjD,OAAO,QAAQ,cAAc,gBAAgB,IAAI,CAAC,CACnD,EACkC,OAAO,OAAO,QAAQ,EAAE,OAAO,MAAM;GACxE,CAAC,KAAKM,kBAAqC,MAAM,CAAC;CACvD;AAED,MAAM,wBAQJ,QACA,EACE,MACA,SACA,OACA,cAcFK,mBAAsC;CACpC;CACA;CACA;CACA;CACA,cAAc,QACZ,MAAM,SACJC,YAA+B,QAAQ,IAAI,EAC3C,MAAM,kBAAkBP,QAA2B,CAAC,CACrD;CACJ,CAAC"}
|
|
@@ -1,41 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import * as
|
|
15
|
-
import * as
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import * as
|
|
19
|
-
import
|
|
20
|
-
|
|
21
|
-
import * as effect_Duration0 from "effect/Duration";
|
|
22
|
-
import * as effect_DateTime0 from "effect/DateTime";
|
|
23
|
-
import * as effect_ParseResult0 from "effect/ParseResult";
|
|
24
|
-
|
|
25
|
-
//#region src/RegisteredFunction.d.ts
|
|
26
|
-
declare namespace RegisteredFunction_d_exports {
|
|
27
|
-
export { ActionServices, Any, ConvexRegisteredFunction, RegisteredFunction, actionFunctionBase, actionLayer, runHandlerPromise };
|
|
28
|
-
}
|
|
29
|
-
type Any = RegisteredQuery<FunctionVisibility, DefaultFunctionArgs, any> | RegisteredMutation<FunctionVisibility, DefaultFunctionArgs, any> | RegisteredAction<FunctionVisibility, DefaultFunctionArgs, any>;
|
|
1
|
+
import type { FunctionSpec, RuntimeAndFunctionType } from "@confect/core";
|
|
2
|
+
import type * as FunctionProvenance from "@confect/core/FunctionProvenance";
|
|
3
|
+
import { type DefaultFunctionArgs, type FunctionVisibility, type GenericActionCtx, type RegisteredAction, type RegisteredMutation, type RegisteredQuery } from "convex/server";
|
|
4
|
+
import type { Value } from "convex/values";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
import * as ActionCtx from "./ActionCtx";
|
|
9
|
+
import * as ActionRunner from "./ActionRunner";
|
|
10
|
+
import * as Auth from "./Auth";
|
|
11
|
+
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
12
|
+
import type * as DataModel from "./DataModel";
|
|
13
|
+
import * as MutationRunner from "./MutationRunner";
|
|
14
|
+
import * as QueryRunner from "./QueryRunner";
|
|
15
|
+
import * as Scheduler from "./Scheduler";
|
|
16
|
+
import * as StorageActionWriter from "./StorageActionWriter";
|
|
17
|
+
import * as StorageReader from "./StorageReader";
|
|
18
|
+
import * as StorageWriter from "./StorageWriter";
|
|
19
|
+
import * as VectorSearch from "./VectorSearch";
|
|
20
|
+
export type Any = RegisteredQuery<FunctionVisibility, DefaultFunctionArgs, any> | RegisteredMutation<FunctionVisibility, DefaultFunctionArgs, any> | RegisteredAction<FunctionVisibility, DefaultFunctionArgs, any>;
|
|
30
21
|
type ConfectRegisteredFunction<FunctionSpec_ extends FunctionSpec.AnyWithProps> = FunctionSpec.EncodedArgs<FunctionSpec_> extends infer Args_ extends DefaultFunctionArgs ? RuntimeAndFunctionType.GetFunctionType<FunctionSpec_["runtimeAndFunctionType"]> extends "query" ? RegisteredQuery<FunctionSpec.GetFunctionVisibility<FunctionSpec_>, Args_, Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>> : RuntimeAndFunctionType.GetFunctionType<FunctionSpec_["runtimeAndFunctionType"]> extends "mutation" ? RegisteredMutation<FunctionSpec.GetFunctionVisibility<FunctionSpec_>, Args_, Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>> : RuntimeAndFunctionType.GetFunctionType<FunctionSpec_["runtimeAndFunctionType"]> extends "action" ? RegisteredAction<FunctionSpec.GetFunctionVisibility<FunctionSpec_>, Args_, Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>> : never : never;
|
|
31
|
-
type ConvexRegisteredFunction<FunctionSpec_ extends FunctionSpec.AnyWithProps> = FunctionSpec_ extends {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
export type ConvexRegisteredFunction<FunctionSpec_ extends FunctionSpec.AnyWithProps> = FunctionSpec_ extends {
|
|
23
|
+
functionProvenance: {
|
|
24
|
+
_tag: "Convex";
|
|
25
|
+
_args: infer Args_ extends DefaultFunctionArgs;
|
|
26
|
+
_returns: infer Returns_;
|
|
27
|
+
};
|
|
37
28
|
} ? RuntimeAndFunctionType.GetFunctionType<FunctionSpec_["runtimeAndFunctionType"]> extends "query" ? RegisteredQuery<FunctionSpec.GetFunctionVisibility<FunctionSpec_>, Args_, Returns_> : RuntimeAndFunctionType.GetFunctionType<FunctionSpec_["runtimeAndFunctionType"]> extends "mutation" ? RegisteredMutation<FunctionSpec.GetFunctionVisibility<FunctionSpec_>, Args_, Returns_> : RuntimeAndFunctionType.GetFunctionType<FunctionSpec_["runtimeAndFunctionType"]> extends "action" ? RegisteredAction<FunctionSpec.GetFunctionVisibility<FunctionSpec_>, Args_, Returns_> : never : never;
|
|
38
|
-
type RegisteredFunction<FunctionSpec_ extends FunctionSpec.AnyWithProps> = FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<FunctionSpec_, FunctionProvenance.AnyConvex> ? ConvexRegisteredFunction<FunctionSpec_> : FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<FunctionSpec_, FunctionProvenance.AnyConfect> ? ConfectRegisteredFunction<FunctionSpec_> : never;
|
|
29
|
+
export type RegisteredFunction<FunctionSpec_ extends FunctionSpec.AnyWithProps> = FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<FunctionSpec_, FunctionProvenance.AnyConvex> ? ConvexRegisteredFunction<FunctionSpec_> : FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<FunctionSpec_, FunctionProvenance.AnyConfect> ? ConfectRegisteredFunction<FunctionSpec_> : never;
|
|
39
30
|
/**
|
|
40
31
|
* Run the `Effect` as a `Promise`. The error schema acts as an allowlist of
|
|
41
32
|
* failures that may be surfaced to the client as a `ConvexError`:
|
|
@@ -51,36 +42,29 @@ type RegisteredFunction<FunctionSpec_ extends FunctionSpec.AnyWithProps> = Funct
|
|
|
51
42
|
* error channel—reaches the client as a `ConvexError`. The fiber dies and
|
|
52
43
|
* `runPromise` rejects with a generic failure.
|
|
53
44
|
*/
|
|
54
|
-
declare const runHandlerPromise: (errorSchema: Schema.Schema.AnyNoContext | undefined) => <A, E>(effect: Effect.Effect<A, E>) => Promise<A>;
|
|
55
|
-
declare const actionFunctionBase: <Schema extends AnyWithProps, Args, ConvexArgs extends DefaultFunctionArgs, Returns, ConvexReturns, E, R>({
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}: {
|
|
62
|
-
args: Schema.Schema<Args, ConvexArgs>;
|
|
63
|
-
returns: Schema.Schema<Returns, ConvexReturns>;
|
|
64
|
-
error: Schema.Schema<Error, Value> | undefined;
|
|
65
|
-
handler: (a: Args) => Effect.Effect<Returns, E, R>;
|
|
66
|
-
createLayer: (ctx: GenericActionCtx<ToConvex<FromSchema<Schema>>>) => Layer.Layer<R>;
|
|
45
|
+
export declare const runHandlerPromise: (errorSchema: Schema.Schema.AnyNoContext | undefined) => <A, E>(effect: Effect.Effect<A, E>) => Promise<A>;
|
|
46
|
+
export declare const actionFunctionBase: <Schema extends DatabaseSchema.AnyWithProps, Args, ConvexArgs extends DefaultFunctionArgs, Returns, ConvexReturns, E, R>({ args, returns, error, handler, createLayer, }: {
|
|
47
|
+
args: Schema.Schema<Args, ConvexArgs>;
|
|
48
|
+
returns: Schema.Schema<Returns, ConvexReturns>;
|
|
49
|
+
error: Schema.Schema<Error, Value> | undefined;
|
|
50
|
+
handler: (a: Args) => Effect.Effect<Returns, E, R>;
|
|
51
|
+
createLayer: (ctx: GenericActionCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>) => Layer.Layer<R>;
|
|
67
52
|
}) => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
53
|
+
args: import("convex/values").PropertyValidators;
|
|
54
|
+
returns: import("convex/values").Validator<any, any, any>;
|
|
55
|
+
handler: (ctx: GenericActionCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>, actualArgs: ConvexArgs) => Promise<ConvexReturns>;
|
|
71
56
|
};
|
|
72
|
-
type ActionServices<DatabaseSchema_ extends AnyWithProps> = Scheduler
|
|
73
|
-
declare const actionLayer: <DatabaseSchema_ extends AnyWithProps>(databaseSchema: DatabaseSchema_, ctx: GenericActionCtx<ToConvex<FromSchema<DatabaseSchema_>>>) => Layer.Layer<Auth
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
} |
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
57
|
+
export type ActionServices<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> = Scheduler.Scheduler | Auth.Auth | StorageReader.StorageReader | StorageWriter.StorageWriter | StorageActionWriter.StorageActionWriter | QueryRunner.QueryRunner | MutationRunner.MutationRunner | ActionRunner.ActionRunner | VectorSearch.VectorSearch<DataModel.FromSchema<DatabaseSchema_>> | ActionCtx.ActionCtx<DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>>;
|
|
58
|
+
export declare const actionLayer: <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(databaseSchema: DatabaseSchema_, ctx: GenericActionCtx<DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>>) => Layer.Layer<(<Action extends import("@confect/core/Ref").AnyAction>(action: Action, ...args: import("@confect/core/Ref").OptionalArgs<Action>) => Effect.Effect<import("@confect/core/Ref").Returns<Action>, import("@confect/core/Ref").Error<Action> | import("effect/ParseResult").ParseError>) | Auth.Auth | (<Mutation extends import("@confect/core/Ref").AnyMutation>(mutation: Mutation, ...args: import("@confect/core/Ref").OptionalArgs<Mutation>) => Effect.Effect<import("@confect/core/Ref").Returns<Mutation>, import("@confect/core/Ref").Error<Mutation> | import("effect/ParseResult").ParseError>) | (<Query extends import("@confect/core/Ref").AnyQuery>(query: Query, ...args: import("@confect/core/Ref").OptionalArgs<Query>) => Effect.Effect<import("@confect/core/Ref").Returns<Query>, import("@confect/core/Ref").Error<Query> | import("effect/ParseResult").ParseError>) | {
|
|
59
|
+
runAfter: <Ref_ extends import("@confect/core/Ref").AnyMutation | import("@confect/core/Ref").AnyAction>(delay: import("effect/Duration").Duration, ref: Ref_, ...args: import("@confect/core/Ref").OptionalArgs<Ref_>) => Effect.Effect<import("convex/values").GenericId<"_scheduled_functions">, never, never>;
|
|
60
|
+
runAt: <Ref_ extends import("@confect/core/Ref").AnyMutation | import("@confect/core/Ref").AnyAction>(dateTime: import("effect/DateTime").DateTime, ref: Ref_, ...args: import("@confect/core/Ref").OptionalArgs<Ref_>) => Effect.Effect<import("convex/values").GenericId<"_scheduled_functions">, never, never>;
|
|
61
|
+
} | StorageActionWriter.StorageActionWriter | StorageReader.StorageReader | StorageWriter.StorageWriter | GenericActionCtx<DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>> | (<TableName extends DataModel.TableNames<DataModel.FromSchema<DatabaseSchema_>>, IndexName extends keyof import("convex/server").VectorIndexes<import("convex/server").NamedTableInfo<DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>, TableName>>>(tableName: TableName, indexName: IndexName, query: {
|
|
62
|
+
vector: number[];
|
|
63
|
+
limit?: number;
|
|
64
|
+
filter?: (q: import("convex/server").VectorFilterBuilder<import("convex/server").DocumentByInfo<import("convex/server").NamedTableInfo<DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>, TableName>>, import("convex/server").NamedVectorIndex<import("convex/server").NamedTableInfo<DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>, TableName>, IndexName>>) => import("convex/server").FilterExpression<boolean>;
|
|
80
65
|
}) => Effect.Effect<{
|
|
81
|
-
|
|
82
|
-
|
|
66
|
+
_id: import("convex/values").GenericId<TableName>;
|
|
67
|
+
_score: number;
|
|
83
68
|
}[], never, never>), never, never>;
|
|
84
|
-
|
|
85
|
-
export { ActionServices, Any, ConvexRegisteredFunction, RegisteredFunction, RegisteredFunction_d_exports, actionFunctionBase, actionLayer, runHandlerPromise };
|
|
69
|
+
export {};
|
|
86
70
|
//# sourceMappingURL=RegisteredFunction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegisteredFunction.d.ts","
|
|
1
|
+
{"version":3,"file":"RegisteredFunction.d.ts","sourceRoot":"","sources":["../src/RegisteredFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,E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CAAC,EAAE,IAAI,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACnD,WAAW,EAAE,CACX,GAAG,EAAE,gBAAgB,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,KACpE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;CACrB;;;mBAIQ,gBAAgB,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,cAC3D,UAAU,KACrB,OAAO,CAAC,aAAa,CAAC;CAYzB,CAAC;AAEH,MAAM,MAAM,cAAc,CACxB,eAAe,SAAS,cAAc,CAAC,YAAY,IAEjD,SAAS,CAAC,SAAS,GACnB,IAAI,CAAC,IAAI,GACT,aAAa,CAAC,aAAa,GAC3B,aAAa,CAAC,aAAa,GAC3B,mBAAmB,CAAC,mBAAmB,GACvC,WAAW,CAAC,WAAW,GACvB,cAAc,CAAC,cAAc,GAC7B,YAAY,CAAC,YAAY,GACzB,YAAY,CAAC,YAAY,CAAC,SAAS,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,GAChE,SAAS,CAAC,SAAS,CACjB,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAC1D,CAAC;AAEN,eAAO,MAAM,WAAW,GACtB,eAAe,SAAS,cAAc,CAAC,YAAY,EAEnD,gBAAgB,eAAe,EAC/B,KAAK,gBAAgB,CACnB,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAC1D;;;;;;;;;;kCAkBA,CAAC"}
|
|
@@ -6,12 +6,16 @@ import { compileArgsSchema, compileReturnsSchema } from "./SchemaToValidator.js"
|
|
|
6
6
|
import { layer as layer$2 } from "./MutationRunner.js";
|
|
7
7
|
import { layer as layer$3 } from "./QueryRunner.js";
|
|
8
8
|
import { layer as layer$4 } from "./Scheduler.js";
|
|
9
|
-
import { StorageActionWriter
|
|
10
|
-
import { StorageReader
|
|
11
|
-
import { StorageWriter
|
|
9
|
+
import { StorageActionWriter } from "./StorageActionWriter.js";
|
|
10
|
+
import { StorageReader } from "./StorageReader.js";
|
|
11
|
+
import { StorageWriter } from "./StorageWriter.js";
|
|
12
12
|
import { layer as layer$5 } from "./VectorSearch.js";
|
|
13
|
-
import { Effect, Either, Layer, Schema, pipe } from "effect";
|
|
14
13
|
import "convex/server";
|
|
14
|
+
import * as Layer from "effect/Layer";
|
|
15
|
+
import { pipe } from "effect/Function";
|
|
16
|
+
import * as Effect from "effect/Effect";
|
|
17
|
+
import * as Schema from "effect/Schema";
|
|
18
|
+
import * as Either from "effect/Either";
|
|
15
19
|
import { ConvexError } from "convex/values";
|
|
16
20
|
|
|
17
21
|
//#region src/RegisteredFunction.ts
|
|
@@ -52,7 +56,7 @@ const actionFunctionBase = ({ args, returns, error, handler, createLayer }) => (
|
|
|
52
56
|
return yield* pipe(yield* handler(yield* pipe(actualArgs, Schema.decode(args), Effect.orDie)).pipe(Effect.provide(createLayer(ctx))), Schema.encode(returns), Effect.orDie);
|
|
53
57
|
}).pipe(runHandlerPromise(error))
|
|
54
58
|
});
|
|
55
|
-
const actionLayer = (databaseSchema, ctx) => Layer.mergeAll(layer$4(ctx.scheduler), layer$1(ctx.auth), StorageReader
|
|
59
|
+
const actionLayer = (databaseSchema, ctx) => Layer.mergeAll(layer$4(ctx.scheduler), layer$1(ctx.auth), StorageReader.layer(ctx.storage), StorageWriter.layer(ctx.storage), StorageActionWriter.layer(ctx.storage), layer$3(ctx.runQuery), layer$2(ctx.runMutation), layer(ctx.runAction), layer$5(ctx.vectorSearch), Layer.succeed(ActionCtx(), ctx));
|
|
56
60
|
|
|
57
61
|
//#endregion
|
|
58
62
|
export { RegisteredFunction_exports, actionFunctionBase, actionLayer, runHandlerPromise };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegisteredFunction.js","names":["SchemaToValidator.compileArgsSchema","SchemaToValidator.compileReturnsSchema","Scheduler.layer","Auth.layer","QueryRunner.layer","MutationRunner.layer","ActionRunner.layer","VectorSearch.layer","ActionCtx.ActionCtx"],"sources":["../src/RegisteredFunction.ts"],"sourcesContent":["import type { FunctionSpec, RuntimeAndFunctionType } from \"@confect/core\";\nimport type * as FunctionProvenance from \"@confect/core/FunctionProvenance\";\nimport {\n type DefaultFunctionArgs,\n type FunctionVisibility,\n type GenericActionCtx,\n type RegisteredAction,\n type RegisteredMutation,\n type RegisteredQuery,\n} from \"convex/server\";\nimport type { Value } from \"convex/values\";\nimport { ConvexError } from \"convex/values\";\nimport { Effect
|
|
1
|
+
{"version":3,"file":"RegisteredFunction.js","names":["SchemaToValidator.compileArgsSchema","SchemaToValidator.compileReturnsSchema","Scheduler.layer","Auth.layer","QueryRunner.layer","MutationRunner.layer","ActionRunner.layer","VectorSearch.layer","ActionCtx.ActionCtx"],"sources":["../src/RegisteredFunction.ts"],"sourcesContent":["import type { FunctionSpec, RuntimeAndFunctionType } from \"@confect/core\";\nimport type * as FunctionProvenance from \"@confect/core/FunctionProvenance\";\nimport {\n type DefaultFunctionArgs,\n type FunctionVisibility,\n type GenericActionCtx,\n type RegisteredAction,\n type RegisteredMutation,\n type RegisteredQuery,\n} from \"convex/server\";\nimport type { Value } from \"convex/values\";\nimport { ConvexError } from \"convex/values\";\nimport { pipe } from \"effect/Function\";\nimport * as Effect from \"effect/Effect\";\nimport * as Either from \"effect/Either\";\nimport * as Layer from \"effect/Layer\";\nimport * as Schema from \"effect/Schema\";\nimport * as ActionCtx from \"./ActionCtx\";\nimport * as ActionRunner from \"./ActionRunner\";\nimport * as Auth from \"./Auth\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport type * as DataModel from \"./DataModel\";\nimport * as MutationRunner from \"./MutationRunner\";\nimport * as QueryRunner from \"./QueryRunner\";\nimport * as Scheduler from \"./Scheduler\";\nimport * as SchemaToValidator from \"./SchemaToValidator\";\nimport * as StorageActionWriter from \"./StorageActionWriter\";\nimport * as StorageReader from \"./StorageReader\";\nimport * as StorageWriter from \"./StorageWriter\";\nimport * as VectorSearch from \"./VectorSearch\";\n\nexport type Any =\n | RegisteredQuery<FunctionVisibility, DefaultFunctionArgs, any>\n | RegisteredMutation<FunctionVisibility, DefaultFunctionArgs, any>\n | RegisteredAction<FunctionVisibility, DefaultFunctionArgs, any>;\n\ntype ConfectRegisteredFunction<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n> =\n FunctionSpec.EncodedArgs<FunctionSpec_> extends infer Args_ extends\n DefaultFunctionArgs\n ? RuntimeAndFunctionType.GetFunctionType<\n FunctionSpec_[\"runtimeAndFunctionType\"]\n > extends \"query\"\n ? RegisteredQuery<\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n Args_,\n Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>\n >\n : RuntimeAndFunctionType.GetFunctionType<\n FunctionSpec_[\"runtimeAndFunctionType\"]\n > extends \"mutation\"\n ? RegisteredMutation<\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n Args_,\n Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>\n >\n : RuntimeAndFunctionType.GetFunctionType<\n FunctionSpec_[\"runtimeAndFunctionType\"]\n > extends \"action\"\n ? RegisteredAction<\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n Args_,\n Promise<FunctionSpec.EncodedReturns<FunctionSpec_>>\n >\n : never\n : never;\n\nexport type ConvexRegisteredFunction<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n> = FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Convex\";\n _args: infer Args_ extends DefaultFunctionArgs;\n _returns: infer Returns_;\n };\n}\n ? RuntimeAndFunctionType.GetFunctionType<\n FunctionSpec_[\"runtimeAndFunctionType\"]\n > extends \"query\"\n ? RegisteredQuery<\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n Args_,\n Returns_\n >\n : RuntimeAndFunctionType.GetFunctionType<\n FunctionSpec_[\"runtimeAndFunctionType\"]\n > extends \"mutation\"\n ? RegisteredMutation<\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n Args_,\n Returns_\n >\n : RuntimeAndFunctionType.GetFunctionType<\n FunctionSpec_[\"runtimeAndFunctionType\"]\n > extends \"action\"\n ? RegisteredAction<\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n Args_,\n Returns_\n >\n : never\n : never;\n\nexport type RegisteredFunction<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n> =\n FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<\n FunctionSpec_,\n FunctionProvenance.AnyConvex\n >\n ? ConvexRegisteredFunction<FunctionSpec_>\n : FunctionSpec_ extends FunctionSpec.WithFunctionProvenance<\n FunctionSpec_,\n FunctionProvenance.AnyConfect\n >\n ? ConfectRegisteredFunction<FunctionSpec_>\n : never;\n\n/**\n * Run the `Effect` as a `Promise`. The error schema acts as an allowlist of\n * failures that may be surfaced to the client as a `ConvexError`:\n *\n * - With a schema: typed errors are schema-encoded and wrapped in a\n * `ConvexError`, then thrown so Convex surfaces the data to the client.\n * `Effect.either` escapes the failure channel before `runPromise` so the thrown\n * `ConvexError` retains its `Symbol.for(\"ConvexError\")` identity instead of\n * being wrapped in Effect's `FiberFailure`.\n *\n * - Without a schema: every failure is converted to a defect via\n * `Effect.orDie`, so nothing—not even a `ConvexError` the handler placed in its\n * error channel—reaches the client as a `ConvexError`. The fiber dies and\n * `runPromise` rejects with a generic failure.\n */\nexport const runHandlerPromise =\n (errorSchema: Schema.Schema.AnyNoContext | undefined) =>\n <A, E>(effect: Effect.Effect<A, E>): Promise<A> => {\n if (errorSchema === undefined) {\n return Effect.runPromise(Effect.orDie(effect));\n }\n const withConvexError = effect.pipe(\n Effect.catchAll((typedError) =>\n pipe(\n Schema.encode(errorSchema)(typedError),\n Effect.orDie,\n Effect.andThen((encodedError) =>\n Effect.fail(new ConvexError(encodedError)),\n ),\n ),\n ),\n );\n return Effect.runPromise(Effect.either(withConvexError)).then(\n Either.match({\n onLeft: (error) => {\n throw error;\n },\n onRight: (value) => value,\n }),\n );\n };\n\nexport const actionFunctionBase = <\n Schema extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n R,\n>({\n args,\n returns,\n error,\n handler,\n createLayer,\n}: {\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema<Error, Value> | undefined;\n handler: (a: Args) => Effect.Effect<Returns, E, R>;\n createLayer: (\n ctx: GenericActionCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,\n ) => Layer.Layer<R>;\n}) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericActionCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,\n actualArgs: ConvexArgs,\n ): Promise<ConvexReturns> =>\n Effect.gen(function* () {\n const decodedArgs = yield* pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n );\n const decodedReturns = yield* handler(decodedArgs).pipe(\n Effect.provide(createLayer(ctx)),\n );\n return yield* pipe(decodedReturns, Schema.encode(returns), Effect.orDie);\n }).pipe(runHandlerPromise(error)),\n});\n\nexport type ActionServices<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n> =\n | Scheduler.Scheduler\n | Auth.Auth\n | StorageReader.StorageReader\n | StorageWriter.StorageWriter\n | StorageActionWriter.StorageActionWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | ActionRunner.ActionRunner\n | VectorSearch.VectorSearch<DataModel.FromSchema<DatabaseSchema_>>\n | ActionCtx.ActionCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >;\n\nexport const actionLayer = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n>(\n databaseSchema: DatabaseSchema_,\n ctx: GenericActionCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n) =>\n Layer.mergeAll(\n Scheduler.layer(ctx.scheduler),\n Auth.layer(ctx.auth),\n StorageReader.StorageReader.layer(ctx.storage),\n StorageWriter.StorageWriter.layer(ctx.storage),\n StorageActionWriter.StorageActionWriter.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n MutationRunner.layer(ctx.runMutation),\n ActionRunner.layer(ctx.runAction),\n VectorSearch.layer(ctx.vectorSearch),\n Layer.succeed(\n ActionCtx.ActionCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >(),\n ctx,\n ),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsIA,MAAa,qBACV,iBACM,WAA4C;AACjD,KAAI,gBAAgB,OAClB,QAAO,OAAO,WAAW,OAAO,MAAM,OAAO,CAAC;CAEhD,MAAM,kBAAkB,OAAO,KAC7B,OAAO,UAAU,eACf,KACE,OAAO,OAAO,YAAY,CAAC,WAAW,EACtC,OAAO,OACP,OAAO,SAAS,iBACd,OAAO,KAAK,IAAI,YAAY,aAAa,CAAC,CAC3C,CACF,CACF,CACF;AACD,QAAO,OAAO,WAAW,OAAO,OAAO,gBAAgB,CAAC,CAAC,KACvD,OAAO,MAAM;EACX,SAAS,UAAU;AACjB,SAAM;;EAER,UAAU,UAAU;EACrB,CAAC,CACH;;AAGL,MAAa,sBAQX,EACA,MACA,SACA,OACA,SACA,mBASK;CACL,MAAMA,kBAAoC,KAAK;CAC/C,SAASC,qBAAuC,QAAQ;CACxD,UACE,KACA,eAEA,OAAO,IAAI,aAAa;AAStB,SAAO,OAAO,KAHS,OAAO,QALV,OAAO,KACzB,YACA,OAAO,OAAO,KAAK,EACnB,OAAO,MACR,CACiD,CAAC,KACjD,OAAO,QAAQ,YAAY,IAAI,CAAC,CACjC,EACkC,OAAO,OAAO,QAAQ,EAAE,OAAO,MAAM;GACxE,CAAC,KAAK,kBAAkB,MAAM,CAAC;CACpC;AAkBD,MAAa,eAGX,gBACA,QAIA,MAAM,SACJC,QAAgB,IAAI,UAAU,EAC9BC,QAAW,IAAI,KAAK,gBACQ,MAAM,IAAI,QAAQ,gBAClB,MAAM,IAAI,QAAQ,sBACN,MAAM,IAAI,QAAQ,EAC1DC,QAAkB,IAAI,SAAS,EAC/BC,QAAqB,IAAI,YAAY,EACrCC,MAAmB,IAAI,UAAU,EACjCC,QAAmB,IAAI,aAAa,EACpC,MAAM,QACJC,WAEG,EACH,IACD,CACF"}
|
|
@@ -1,33 +1,55 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import * as
|
|
7
|
-
import * as
|
|
8
|
-
import * as
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
type
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import type * as FunctionSpec from "@confect/core/FunctionSpec";
|
|
2
|
+
import type * as GroupSpec from "@confect/core/GroupSpec";
|
|
3
|
+
import type * as Spec from "@confect/core/Spec";
|
|
4
|
+
import type { Layer, Types } from "effect";
|
|
5
|
+
import type * as DatabaseSchema from "./DatabaseSchema";
|
|
6
|
+
import type * as GroupImpl from "./GroupImpl";
|
|
7
|
+
import type * as RegisteredFunction from "./RegisteredFunction";
|
|
8
|
+
import * as RegistryItem from "./RegistryItem";
|
|
9
|
+
export type RegisteredFunctions<Spec_ extends Spec.AnyWithProps> = Types.Simplify<RegisteredFunctionsHelper<Spec.Groups<Spec_>>>;
|
|
10
|
+
type RegisteredFunctionsHelper<Groups extends GroupSpec.AnyWithProps> = {
|
|
11
|
+
[GroupName in GroupSpec.Name<Groups>]: GroupSpec.WithName<Groups, GroupName> extends infer Group extends GroupSpec.AnyWithProps ? RegisteredFunctionsForGroupSpec<Group> : never;
|
|
12
|
+
};
|
|
13
|
+
/** The `RegisteredFunction` record for a group's own declared functions. */
|
|
14
|
+
type RegisteredFunctionsOf<Group extends GroupSpec.AnyWithProps> = {
|
|
15
|
+
[FunctionName in FunctionSpec.Name<GroupSpec.Functions<Group>>]: FunctionSpec.WithName<GroupSpec.Functions<Group>, FunctionName> extends infer FunctionSpec_ extends FunctionSpec.AnyWithProps ? RegisteredFunction.RegisteredFunction<FunctionSpec_> : never;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The registered-functions record for a single group, derived from the group's
|
|
19
|
+
* own `GroupSpec`: its declared functions, plus any nested subgroups it carries
|
|
20
|
+
* directly. This is the node that `buildForGroup` returns — computed from the
|
|
21
|
+
* leaf `GroupSpec` itself rather than by navigating the project-wide assembled
|
|
22
|
+
* `Spec` to a dot-path, so the per-group registry's type depends only on its
|
|
23
|
+
* own leaf. For the filesystem layout a leaf `GroupSpec` carries no subgroups
|
|
24
|
+
* (subdirectory children are assembled separately into `_generated/spec.ts`),
|
|
25
|
+
* so this resolves to just the leaf's functions.
|
|
26
|
+
*/
|
|
27
|
+
export type RegisteredFunctionsForGroupSpec<Group extends GroupSpec.AnyWithProps> = GroupSpec.Groups<Group> extends infer SubGroups extends GroupSpec.AnyWithProps ? Types.Simplify<RegisteredFunctionsHelper<SubGroups> & RegisteredFunctionsOf<Group>> : RegisteredFunctionsOf<Group>;
|
|
28
|
+
export interface AnyWithProps {
|
|
29
|
+
readonly [key: string]: RegisteredFunction.Any | AnyWithProps;
|
|
18
30
|
}
|
|
19
|
-
type RegisteredFunctionsAtPath<Tree, Path extends string> = Path extends `${infer Head}.${infer Tail}` ? Head extends keyof Tree ? Tree[Head] extends AnyWithProps ? RegisteredFunctionsAtPath<Tree[Head], Tail> : never : never : Path extends keyof Tree ? Tree[Path] : never;
|
|
20
|
-
type ForGroupPath<Spec_ extends Spec.AnyWithProps, Path extends string> = RegisteredFunctionsAtPath<RegisteredFunctions<Spec_>, Path>;
|
|
21
31
|
/**
|
|
22
32
|
* Build the registered Convex functions for a single group from its finalized
|
|
23
33
|
* `GroupImpl` layer.
|
|
24
34
|
*
|
|
25
|
-
* The `groupLayer` parameter requires `GroupImpl<
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
35
|
+
* The `groupLayer` parameter requires `GroupImpl<"Finalized">`, so impls that
|
|
36
|
+
* were never piped through `GroupImpl.finalize` (and impls with unmet
|
|
37
|
+
* `FunctionImpl` requirements, which cannot be finalized) are rejected at the
|
|
38
|
+
* codegen boundary, not just deep inside Convex at runtime.
|
|
39
|
+
*
|
|
40
|
+
* The group layer is built with a fresh, isolated `Registry` (rather than the
|
|
41
|
+
* globally-cached default `Context.Reference`), so each `FunctionImpl.make`
|
|
42
|
+
* registers under its flat, single-segment function-name key without colliding
|
|
43
|
+
* with any other group built in the same process — the built registry holds
|
|
44
|
+
* exactly this group's functions at the top level.
|
|
45
|
+
*
|
|
46
|
+
* Only the runtime `databaseSchema` value is needed at runtime (it is forwarded
|
|
47
|
+
* to `makeRegisteredFunction` to build each function's ctx services); the
|
|
48
|
+
* group's `GroupSpec` is supplied purely as the `Group` type parameter to shape
|
|
49
|
+
* the returned record. The generated caller passes it explicitly and imports
|
|
50
|
+
* the leaf spec type-only (`typeof import("…/<group>.spec")["default"]`), so a
|
|
51
|
+
* function's bundle never imports a spec module at runtime.
|
|
29
52
|
*/
|
|
30
|
-
declare const buildForGroup: <
|
|
31
|
-
|
|
32
|
-
export { AnyWithProps, ForGroupPath, RegisteredFunctions, RegisteredFunctions_d_exports, buildForGroup };
|
|
53
|
+
export declare const buildForGroup: <Group extends GroupSpec.AnyWithProps>(databaseSchema: DatabaseSchema.AnyWithProps, groupLayer: Layer.Layer<GroupImpl.GroupImpl<"Finalized">>, makeRegisteredFunction: (databaseSchema: DatabaseSchema.AnyWithProps, registryItem: RegistryItem.AnyWithProps) => RegisteredFunction.Any) => RegisteredFunctionsForGroupSpec<Group>;
|
|
54
|
+
export {};
|
|
33
55
|
//# sourceMappingURL=RegisteredFunctions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegisteredFunctions.d.ts","
|
|
1
|
+
{"version":3,"file":"RegisteredFunctions.d.ts","sourceRoot":"","sources":["../src/RegisteredFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,YAAY,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,KAAK,SAAS,MAAM,yBAAyB,CAAC;AAE1D,OAAO,KAAK,KAAK,IAAI,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAG3C,OAAO,KAAK,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,KAAK,SAAS,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,KAAK,kBAAkB,MAAM,sBAAsB,CAAC;AAChE,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAE/C,MAAM,MAAM,mBAAmB,CAAC,KAAK,SAAS,IAAI,CAAC,YAAY,IAC7D,KAAK,CAAC,QAAQ,CAAC,yBAAyB,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEhE,KAAK,yBAAyB,CAAC,MAAM,SAAS,SAAS,CAAC,YAAY,IAAI;KACrE,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,QAAQ,CACvD,MAAM,EACN,SAAS,CACV,SAAS,MAAM,KAAK,SAAS,SAAS,CAAC,YAAY,GAChD,+BAA+B,CAAC,KAAK,CAAC,GACtC,KAAK;CACV,CAAC;AAEF,4EAA4E;AAC5E,KAAK,qBAAqB,CAAC,KAAK,SAAS,SAAS,CAAC,YAAY,IAAI;KAChE,YAAY,IAAI,YAAY,CAAC,IAAI,CAChC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAC3B,GAAG,YAAY,CAAC,QAAQ,CACvB,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,EAC1B,YAAY,CACb,SAAS,MAAM,aAAa,SAAS,YAAY,CAAC,YAAY,GAC3D,kBAAkB,CAAC,kBAAkB,CAAC,aAAa,CAAC,GACpD,KAAK;CACV,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,+BAA+B,CACzC,KAAK,SAAS,SAAS,CAAC,YAAY,IAEpC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,MAAM,SAAS,SAAS,SAAS,CAAC,YAAY,GAC1E,KAAK,CAAC,QAAQ,CACZ,yBAAyB,CAAC,SAAS,CAAC,GAAG,qBAAqB,CAAC,KAAK,CAAC,CACpE,GACD,qBAAqB,CAAC,KAAK,CAAC,CAAC;AAEnC,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAAC,GAAG,GAAG,YAAY,CAAC;CAC/D;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,SAAS,SAAS,CAAC,YAAY,EAChE,gBAAgB,cAAc,CAAC,YAAY,EAC3C,YAAY,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,EACzD,wBAAwB,CACtB,cAAc,EAAE,cAAc,CAAC,YAAY,EAC3C,YAAY,EAAE,YAAY,CAAC,YAAY,KACpC,kBAAkB,CAAC,GAAG,KAC1B,+BAA+B,CAAC,KAAK,CAkBvC,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { mapLeaves } from "./internal/utils.js";
|
|
3
3
|
import { isRegistryItem } from "./RegistryItem.js";
|
|
4
|
-
import
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
5
|
import * as Registry from "@confect/core/Registry";
|
|
6
|
+
import * as Ref from "effect/Ref";
|
|
6
7
|
|
|
7
8
|
//#region src/RegisteredFunctions.ts
|
|
8
9
|
var RegisteredFunctions_exports = /* @__PURE__ */ __exportAll({ buildForGroup: () => buildForGroup });
|
|
@@ -10,17 +11,29 @@ var RegisteredFunctions_exports = /* @__PURE__ */ __exportAll({ buildForGroup: (
|
|
|
10
11
|
* Build the registered Convex functions for a single group from its finalized
|
|
11
12
|
* `GroupImpl` layer.
|
|
12
13
|
*
|
|
13
|
-
* The `groupLayer` parameter requires `GroupImpl<
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* The `groupLayer` parameter requires `GroupImpl<"Finalized">`, so impls that
|
|
15
|
+
* were never piped through `GroupImpl.finalize` (and impls with unmet
|
|
16
|
+
* `FunctionImpl` requirements, which cannot be finalized) are rejected at the
|
|
17
|
+
* codegen boundary, not just deep inside Convex at runtime.
|
|
18
|
+
*
|
|
19
|
+
* The group layer is built with a fresh, isolated `Registry` (rather than the
|
|
20
|
+
* globally-cached default `Context.Reference`), so each `FunctionImpl.make`
|
|
21
|
+
* registers under its flat, single-segment function-name key without colliding
|
|
22
|
+
* with any other group built in the same process — the built registry holds
|
|
23
|
+
* exactly this group's functions at the top level.
|
|
24
|
+
*
|
|
25
|
+
* Only the runtime `databaseSchema` value is needed at runtime (it is forwarded
|
|
26
|
+
* to `makeRegisteredFunction` to build each function's ctx services); the
|
|
27
|
+
* group's `GroupSpec` is supplied purely as the `Group` type parameter to shape
|
|
28
|
+
* the returned record. The generated caller passes it explicitly and imports
|
|
29
|
+
* the leaf spec type-only (`typeof import("…/<group>.spec")["default"]`), so a
|
|
30
|
+
* function's bundle never imports a spec module at runtime.
|
|
17
31
|
*/
|
|
18
|
-
const buildForGroup = (
|
|
19
|
-
|
|
32
|
+
const buildForGroup = (databaseSchema, groupLayer, makeRegisteredFunction) => {
|
|
33
|
+
return mapLeaves(Effect.gen(function* () {
|
|
20
34
|
const registry = yield* Registry.Registry;
|
|
21
35
|
return yield* Ref.get(registry);
|
|
22
|
-
}).pipe(Effect.provide(groupLayer), Effect.runSync), isRegistryItem, (registryItem) => makeRegisteredFunction(
|
|
23
|
-
return pipe(String.split(groupPath, "."), Array.reduce(Option.some(registeredFunctions), (currentNode, segment) => currentNode.pipe(Option.filter(Predicate.isRecord), Option.flatMap((nodeRecord) => segment in nodeRecord ? Option.some(nodeRecord[segment]) : Option.none()))), Option.getOrThrowWith(() => /* @__PURE__ */ new Error(`No functions registered for group path "${groupPath}"`)));
|
|
36
|
+
}).pipe(Effect.provide(groupLayer), Effect.provideService(Registry.Registry, Ref.unsafeMake({})), Effect.runSync), isRegistryItem, (registryItem) => makeRegisteredFunction(databaseSchema, registryItem));
|
|
24
37
|
};
|
|
25
38
|
|
|
26
39
|
//#endregion
|