@gaganref/confect-server 10.3.1-fork.5 → 10.3.1-fork.50

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.
Files changed (147) hide show
  1. package/dist/ActionCall.d.ts +30 -0
  2. package/dist/ActionCall.d.ts.map +1 -0
  3. package/dist/ActionCall.js +41 -0
  4. package/dist/ActionCall.js.map +1 -0
  5. package/dist/ActionRunner.d.ts +1 -1
  6. package/dist/ActionRunner.d.ts.map +1 -1
  7. package/dist/ActionRunner.js +3 -3
  8. package/dist/ActionRunner.js.map +1 -1
  9. package/dist/AiGatewayDecisionClient.js +1 -1
  10. package/dist/AiGatewayLanguageClient.js +1 -1
  11. package/dist/Auth.d.ts +13 -1
  12. package/dist/Auth.d.ts.map +1 -1
  13. package/dist/Auth.js +13 -3
  14. package/dist/Auth.js.map +1 -1
  15. package/dist/Callback.js +4 -4
  16. package/dist/ConvexConfigProvider.js +2 -2
  17. package/dist/ConvexFunctionDefinitions.d.ts.map +1 -1
  18. package/dist/ConvexFunctionDefinitions.js +4 -4
  19. package/dist/ConvexFunctionDefinitions.js.map +1 -1
  20. package/dist/ConvexLogger.js +1 -1
  21. package/dist/CronJobs.js +6 -6
  22. package/dist/DatabaseSchema.js +2 -2
  23. package/dist/DatabaseWriter.d.ts +36 -2
  24. package/dist/DatabaseWriter.d.ts.map +1 -1
  25. package/dist/DatabaseWriter.js +55 -8
  26. package/dist/DatabaseWriter.js.map +1 -1
  27. package/dist/ExecutionMetadata.js +1 -1
  28. package/dist/FunctionImpl.js +2 -2
  29. package/dist/FunctionRegistryItem.d.ts +1 -0
  30. package/dist/FunctionRegistryItem.d.ts.map +1 -1
  31. package/dist/FunctionRegistryItem.js +2 -1
  32. package/dist/FunctionRegistryItem.js.map +1 -1
  33. package/dist/GroupImpl.d.ts +21 -2
  34. package/dist/GroupImpl.d.ts.map +1 -1
  35. package/dist/GroupImpl.js +21 -22
  36. package/dist/GroupImpl.js.map +1 -1
  37. package/dist/GroupRegistry.d.ts +1 -0
  38. package/dist/GroupRegistry.d.ts.map +1 -1
  39. package/dist/GroupRegistry.js +10 -3
  40. package/dist/GroupRegistry.js.map +1 -1
  41. package/dist/Handler.d.ts +8 -4
  42. package/dist/Handler.d.ts.map +1 -1
  43. package/dist/Handler.js.map +1 -1
  44. package/dist/HttpRouter.d.ts +2 -0
  45. package/dist/HttpRouter.d.ts.map +1 -1
  46. package/dist/HttpRouter.js +17 -8
  47. package/dist/HttpRouter.js.map +1 -1
  48. package/dist/MiddlewareImpl.js +1 -1
  49. package/dist/MutationRunner.d.ts +1 -1
  50. package/dist/MutationRunner.d.ts.map +1 -1
  51. package/dist/MutationRunner.js +3 -3
  52. package/dist/MutationRunner.js.map +1 -1
  53. package/dist/MutationTransactionContext.d.ts.map +1 -1
  54. package/dist/MutationTransactionContext.js +4 -3
  55. package/dist/MutationTransactionContext.js.map +1 -1
  56. package/dist/OfficialComponent.d.ts +60 -0
  57. package/dist/OfficialComponent.d.ts.map +1 -0
  58. package/dist/OfficialComponent.js +71 -0
  59. package/dist/OfficialComponent.js.map +1 -0
  60. package/dist/QueryInitializer.js +2 -2
  61. package/dist/QueryRunner.js +2 -2
  62. package/dist/QueryStream.d.ts +120 -12
  63. package/dist/QueryStream.d.ts.map +1 -1
  64. package/dist/QueryStream.js +143 -41
  65. package/dist/QueryStream.js.map +1 -1
  66. package/dist/QueryStreamCursor.js +1 -1
  67. package/dist/QueryStreamIndexPrefix.js +1 -1
  68. package/dist/QueryStreamIndexRange.js +2 -2
  69. package/dist/QueryStreamKey.js +1 -1
  70. package/dist/QueryStreamKeyBounds.js +2 -2
  71. package/dist/QueryStreamKeyLayout.js +2 -2
  72. package/dist/QueryStreamKeyValues.js +2 -2
  73. package/dist/QueryStreamPagination.js +1 -1
  74. package/dist/QueryStreamReadBudget.d.ts +3 -2
  75. package/dist/QueryStreamReadBudget.d.ts.map +1 -1
  76. package/dist/QueryStreamReadBudget.js +8 -5
  77. package/dist/QueryStreamReadBudget.js.map +1 -1
  78. package/dist/QueryTransactionContext.js +2 -2
  79. package/dist/RegisteredConvexFunction.d.ts +10 -5
  80. package/dist/RegisteredConvexFunction.d.ts.map +1 -1
  81. package/dist/RegisteredConvexFunction.js +45 -29
  82. package/dist/RegisteredConvexFunction.js.map +1 -1
  83. package/dist/RegisteredFunction.d.ts +39 -22
  84. package/dist/RegisteredFunction.d.ts.map +1 -1
  85. package/dist/RegisteredFunction.js +155 -42
  86. package/dist/RegisteredFunction.js.map +1 -1
  87. package/dist/RegisteredNodeFunction.d.ts +1 -1
  88. package/dist/RegisteredNodeFunction.d.ts.map +1 -1
  89. package/dist/RegisteredNodeFunction.js +10 -6
  90. package/dist/RegisteredNodeFunction.js.map +1 -1
  91. package/dist/RegistryItems.d.ts +7 -0
  92. package/dist/RegistryItems.d.ts.map +1 -1
  93. package/dist/RegistryItems.js +8 -3
  94. package/dist/RegistryItems.js.map +1 -1
  95. package/dist/RequestMetadata.js +1 -1
  96. package/dist/Scheduler.d.ts.map +1 -1
  97. package/dist/Scheduler.js +11 -10
  98. package/dist/Scheduler.js.map +1 -1
  99. package/dist/Storage.js +1 -1
  100. package/dist/StorageActionWriter.js +1 -1
  101. package/dist/StorageReader.js +1 -1
  102. package/dist/StorageWriter.js +1 -1
  103. package/dist/TransactionMetadata.js +1 -1
  104. package/dist/VectorSearch.js +1 -1
  105. package/dist/index.d.ts +2 -0
  106. package/dist/index.d.ts.map +1 -1
  107. package/dist/index.js +20 -18
  108. package/dist/internal/AiGatewayDecisionClient.js +1 -1
  109. package/dist/internal/AiGatewayLanguageClient.js +1 -1
  110. package/dist/internal/AiGatewayServiceToken.js +1 -1
  111. package/dist/internal/DocumentPatch.d.ts +16 -0
  112. package/dist/internal/DocumentPatch.d.ts.map +1 -0
  113. package/dist/internal/DocumentPatch.js +36 -0
  114. package/dist/internal/DocumentPatch.js.map +1 -0
  115. package/dist/internal/observability.d.ts +5 -0
  116. package/dist/internal/observability.d.ts.map +1 -0
  117. package/dist/internal/observability.js +21 -0
  118. package/dist/internal/observability.js.map +1 -0
  119. package/dist/internal/reservedArgument.d.ts +8 -0
  120. package/dist/internal/reservedArgument.d.ts.map +1 -0
  121. package/dist/internal/reservedArgument.js +30 -0
  122. package/dist/internal/reservedArgument.js.map +1 -0
  123. package/package.json +5 -5
  124. package/src/ActionCall.ts +83 -0
  125. package/src/ActionRunner.ts +3 -2
  126. package/src/Auth.ts +23 -1
  127. package/src/ConvexFunctionDefinitions.ts +2 -1
  128. package/src/DatabaseWriter.ts +183 -25
  129. package/src/FunctionRegistryItem.ts +4 -0
  130. package/src/GroupImpl.ts +61 -8
  131. package/src/GroupRegistry.ts +7 -3
  132. package/src/Handler.ts +21 -5
  133. package/src/HttpRouter.ts +54 -4
  134. package/src/MutationRunner.ts +3 -2
  135. package/src/MutationTransactionContext.ts +2 -1
  136. package/src/OfficialComponent.ts +167 -0
  137. package/src/QueryStream.ts +391 -61
  138. package/src/QueryStreamReadBudget.ts +19 -6
  139. package/src/RegisteredConvexFunction.ts +35 -2
  140. package/src/RegisteredFunction.ts +251 -45
  141. package/src/RegisteredNodeFunction.ts +11 -1
  142. package/src/RegistryItems.ts +31 -0
  143. package/src/Scheduler.ts +13 -16
  144. package/src/index.ts +2 -0
  145. package/src/internal/DocumentPatch.ts +87 -0
  146. package/src/internal/observability.ts +27 -0
  147. package/src/internal/reservedArgument.ts +56 -0
@@ -1,20 +1,22 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import { layer } from "./ConvexConfigProvider.js";
3
3
  import { layer as layer$1 } from "./ConvexLogger.js";
4
+ import { memoized } from "./internal/observability.js";
4
5
  import { actionLayer, baseActionLayer } from "./RegisteredFunction.js";
5
6
  import * as Context from "effect/Context";
6
- import * as Layer from "effect/Layer";
7
7
  import * as Effect from "effect/Effect";
8
+ import * as Layer from "effect/Layer";
9
+ import * as Array from "effect/Array";
8
10
  import { ROUTABLE_HTTP_METHODS, httpActionGeneric, httpRouter } from "convex/server";
9
11
  import * as Schema from "effect/Schema";
10
12
  import * as Match from "effect/Match";
11
- import * as Array from "effect/Array";
12
13
  import * as SchemaAST from "effect/SchemaAST";
13
- import * as Console from "effect/Console";
14
14
  import * as Config from "effect/Config";
15
+ import * as Console from "effect/Console";
15
16
  import * as FindMyWay from "effect/http/FindMyWay";
16
17
  import * as HttpApi from "effect/http-api/HttpApi";
17
18
  import * as HttpRouter from "effect/http/HttpRouter";
19
+ import * as HttpMiddleware from "effect/http/HttpMiddleware";
18
20
  import * as HttpServer from "effect/http/HttpServer";
19
21
  //#region src/HttpRouter.ts
20
22
  var HttpRouter_exports = /* @__PURE__ */ __exportAll({
@@ -40,22 +42,29 @@ var HttpRouter_exports = /* @__PURE__ */ __exportAll({
40
42
  * exact paths first and longer path prefixes before the catch-all, so they take
41
43
  * precedence.
42
44
  */
43
- const make = (routes, options) => makeWithLayer(routes, baseActionLayer, options?.api);
45
+ const make = (routes, options) => makeWithLayer(routes, baseActionLayer, options?.api, options?.observability);
44
46
  /**
45
47
  * Derive HTTP capabilities and ID scopes from the generated database schema.
46
48
  * Component routes are relative to their installation's HTTP mount prefix.
47
49
  * Supply `{ api }` as in {@link make}; labels stay component-relative.
48
50
  */
49
- const forSchema = (schema) => (routes, options) => makeWithLayer(Match.value(schema.target.kind).pipe(Match.when("app", () => routes), Match.when("component", () => routes.pipe(Layer.provide(componentRouter))), Match.exhaustive), (ctx) => actionLayer(schema, ctx), options?.api);
51
+ const forSchema = (schema) => (routes, options) => makeWithLayer(Match.value(schema.target.kind).pipe(Match.when("app", () => routes), Match.when("component", () => routes.pipe(Layer.provide(componentRouter))), Match.exhaustive), (ctx) => actionLayer(schema, ctx), options?.api, options?.observability, schema.target.kind === "component");
50
52
  const componentRouter = Layer.effect(HttpRouter.HttpRouter, Effect.gen(function* () {
51
53
  const router = yield* HttpRouter.HttpRouter;
52
54
  const siteUrl = yield* Config.schema(Schema.URLFromString, "CONVEX_SITE_URL");
53
55
  return router.prefixed(siteUrl.pathname);
54
56
  }).pipe(Effect.orDie));
55
- const makeWithLayer = (routes, layer$2, api) => {
57
+ const makeWithLayer = (routes, layer$2, api, observability, siteRelative = false) => {
56
58
  applyMonkeyPatches();
57
- const AppLayer = routes.pipe(Layer.provideMerge(layer$1), Layer.provideMerge(layer), Layer.provide(HttpServer.layerServices));
58
- const { handler } = HttpRouter.toWebHandler(AppLayer, { disableLogger: true });
59
+ const spanName = Layer.effect(HttpMiddleware.SpanNameGenerator, Effect.gen(function* () {
60
+ const prefix = siteRelative ? (yield* Config.schema(Schema.URLFromString, "CONVEX_SITE_URL")).pathname.replace(/\/$/, "") : "";
61
+ return (request) => convexHttpRouter.lookup(new URL(request.originalUrl).pathname.slice(prefix.length) || "/", request.method)?.[2] ?? "/*";
62
+ }).pipe(Effect.orDie));
63
+ const AppLayer = routes.pipe(Layer.provideMerge(observability === void 0 ? layer$1 : Layer.merge(memoized(observability), spanName)), Layer.provideMerge(layer), Layer.provide(HttpServer.layerServices));
64
+ const { handler } = HttpRouter.toWebHandler(AppLayer, {
65
+ disableLogger: true,
66
+ ...observability === void 0 ? {} : { middleware: (effect) => Effect.andThen(Effect.annotateCurrentSpan("kind", "httpAction"), effect) }
67
+ });
59
68
  const httpAction = httpActionGeneric((ctx, request) => {
60
69
  const services = Effect.runSync(Effect.scoped(Layer.build(layer$2(ctx))));
61
70
  return handler(request, Context.add(services, Console.Console, globalThis.console));
@@ -1 +1 @@
1
- {"version":3,"file":"HttpRouter.js","names":["RegisteredFunction.baseActionLayer","RegisteredFunction.actionLayer","ConvexLogger.layer","ConvexConfigProvider.layer","layer"],"sources":["../src/HttpRouter.ts"],"sourcesContent":["import {\n type HttpRouter as ConvexHttpRouter,\n httpActionGeneric,\n httpRouter,\n ROUTABLE_HTTP_METHODS,\n type RouteSpecWithPathPrefix,\n type GenericActionCtx,\n type GenericDataModel,\n} from \"convex/server\";\nimport * as Array from \"effect/Array\";\nimport * as Console from \"effect/Console\";\nimport * as Context from \"effect/Context\";\nimport * as Config from \"effect/Config\";\nimport * as Effect from \"effect/Effect\";\nimport type * as FileSystem from \"effect/FileSystem\";\nimport * as Layer from \"effect/Layer\";\nimport * as Match from \"effect/Match\";\nimport type * as Path from \"effect/Path\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaAST from \"effect/SchemaAST\";\nimport * as FindMyWay from \"effect/http/FindMyWay\";\nimport * as HttpApi from \"effect/http-api/HttpApi\";\nimport type * as HttpApiGroup from \"effect/http-api/HttpApiGroup\";\nimport type * as Etag from \"effect/http/Etag\";\nimport type * as HttpPlatform from \"effect/http/HttpPlatform\";\nimport * as HttpRouter from \"effect/http/HttpRouter\";\nimport * as HttpServer from \"effect/http/HttpServer\";\nimport type * as ActionRunner from \"./ActionRunner.js\";\nimport type * as Auth from \"./Auth.js\";\nimport type { ExecutionMetadata } from \"./ExecutionMetadata.js\";\nimport type { RequestMetadata } from \"./RequestMetadata.js\";\nimport type * as DatabaseSchema from \"./DatabaseSchema.js\";\nimport type * as DataModel from \"./DataModel.js\";\nimport type * as Handler from \"./Handler.js\";\nimport * as ConvexConfigProvider from \"./ConvexConfigProvider.js\";\nimport * as ConvexLogger from \"./ConvexLogger.js\";\nimport type * as MutationRunner from \"./MutationRunner.js\";\nimport type * as QueryRunner from \"./QueryRunner.js\";\nimport * as RegisteredFunction from \"./RegisteredFunction.js\";\nimport type * as Scheduler from \"./Scheduler.js\";\nimport type { Storage } from \"./Storage.js\";\nimport type { StorageActionWriter } from \"./StorageActionWriter.js\";\nimport type { StorageReader } from \"./StorageReader.js\";\nimport type { StorageWriter } from \"./StorageWriter.js\";\n\n/**\n * The Confect services available to HTTP route handlers and middleware,\n * supplied per request from the Convex action context.\n */\nexport type Services =\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | ActionRunner.ActionRunner\n | Scheduler.Scheduler\n | Auth.Auth\n | ExecutionMetadata\n | RequestMetadata\n | Storage\n | StorageReader\n | StorageWriter\n | StorageActionWriter;\n\n/**\n * A layer that registers routes on the HTTP router—the input to {@link make}.\n *\n * Compose it from Effect's `effect/http` and `effect/http-api` modules:\n * `HttpApiBuilder.layer(api)` registers an `HttpApi`'s endpoints (provide its\n * group handler layers with `Layer.provide`), `HttpApiScalar.layer(api, ...)`\n * serves interactive API docs, `HttpRouter.add` registers a plain route, and\n * `HttpRouter.middleware(fn, { global: true })` applies middleware to every\n * route. Merge any number of these with `Layer.mergeAll`.\n *\n * Route handlers and middleware may require any of the Confect {@link Services},\n * which surface as request-level `Requires` markers and are supplied per\n * request. Anything else the layer requires is a type error—notably, an\n * `HttpApiBuilder.layer(api)` whose group handler layers are not provided\n * leaves an `HttpApiGroup.ToService` requirement behind, so a missing handler\n * group is caught at compile time.\n *\n * Layers are built with Confect's Convex-aware `ConfigProvider` in context, so\n * `Config` reads (e.g. in `Layer.unwrap`) resolve against Convex environment\n * variables.\n */\nexport type Routes<Services_ = Services> = Layer.Layer<\n never,\n never,\n | HttpRouter.HttpRouter\n | Etag.Generator\n | FileSystem.FileSystem\n | HttpPlatform.HttpPlatform\n | Path.Path\n | HttpRouter.Request<\"Requires\", Services_>\n | HttpRouter.Request<\"GlobalRequires\", Services_>\n | HttpRouter.Request<\"Error\", any>\n | HttpRouter.Request<\"GlobalError\", any>\n>;\n\n/**\n * Create a Convex HTTP router serving the given routes.\n *\n * A single catch-all `httpAction` is registered for every routable method under\n * the path prefix `\"/\"`, making the Effect router the single source of truth\n * for paths: place an API with `HttpApi.prefix` or absolute route paths.\n * Requests that match no route receive the Effect router's 404 response.\n *\n * Supply `{ api }` with the `HttpApi` registered by the routes layer to show\n * endpoint patterns in Convex completion logs and the dashboard. Requests that\n * match no reflected endpoint keep the catch-all completion label. Without the\n * option, Convex reports the catch-all registrations. Application endpoints\n * must not overlap component HTTP mounts: Convex also uses dashboard route\n * entries to select between application and component routers.\n *\n * Plain Convex routes can still be added to the returned router—Convex matches\n * exact paths first and longer path prefixes before the catch-all, so they take\n * precedence.\n */\nexport const make = <Id extends string, Groups extends HttpApiGroup.Constraint>(\n routes: Routes,\n options?: { readonly api?: HttpApi.HttpApi<Id, Groups> | undefined },\n): ConvexHttpRouter =>\n makeWithLayer(routes, RegisteredFunction.baseActionLayer, options?.api);\n\n/**\n * Derive HTTP capabilities and ID scopes from the generated database schema.\n * Component routes are relative to their installation's HTTP mount prefix.\n * Supply `{ api }` as in {@link make}; labels stay component-relative.\n */\nexport const forSchema =\n <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n schema: DatabaseSchema_,\n ) =>\n <Id extends string, Groups extends HttpApiGroup.Constraint>(\n routes: Routes<Handler.ActionServices<DatabaseSchema_>>,\n options?: { readonly api?: HttpApi.HttpApi<Id, Groups> | undefined },\n ): ConvexHttpRouter =>\n makeWithLayer<\n Handler.ActionServices<DatabaseSchema_>,\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>,\n Id,\n Groups\n >(\n Match.value(schema.target.kind).pipe(\n Match.when(\"app\", () => routes),\n Match.when(\"component\", () =>\n routes.pipe(Layer.provide(componentRouter)),\n ),\n Match.exhaustive,\n ),\n (ctx) => RegisteredFunction.actionLayer(schema, ctx),\n options?.api,\n );\n\n// Convex uses a component-relative path to select its HTTP action but passes\n// the original request URL to that action. Its CONVEX_SITE_URL includes the\n// installation's full mount prefix (including parent mounts). Prefixing the\n// Effect router preserves relative routes without rewriting the Request body.\nconst componentRouter = Layer.effect(\n HttpRouter.HttpRouter,\n Effect.gen(function* () {\n const router = yield* HttpRouter.HttpRouter;\n const siteUrl = yield* Config.schema(\n Schema.URLFromString,\n \"CONVEX_SITE_URL\",\n );\n return router.prefixed(siteUrl.pathname);\n }).pipe(Effect.orDie),\n);\n\nconst makeWithLayer = <\n Services_,\n DataModel_ extends GenericDataModel,\n Id extends string,\n Groups extends HttpApiGroup.Constraint,\n>(\n routes: Routes<Services_>,\n layer: (ctx: GenericActionCtx<DataModel_>) => Layer.Layer<Services_>,\n api: HttpApi.HttpApi<Id, Groups> | undefined,\n): ConvexHttpRouter => {\n applyMonkeyPatches();\n\n // Provided (not just merged) so that route layers' own construction—e.g.\n // a `Layer.unwrap` reading `Config`—resolves configuration through the\n // Convex-aware provider; merged so that request fibers—endpoint handlers\n // and middleware—do too.\n const AppLayer = routes.pipe(\n Layer.provideMerge(ConvexLogger.layer),\n Layer.provideMerge(ConvexConfigProvider.layer),\n Layer.provide(HttpServer.layerServices),\n );\n\n // The Confect service requirements of route handlers and middleware surface\n // as request-level `Requires` markers on the layer, which the web handler\n // exposes as a per-request context argument.\n const { handler } = HttpRouter.toWebHandler(AppLayer, {\n disableLogger: true,\n });\n\n const httpAction = httpActionGeneric((ctx, request): Promise<Response> => {\n // The ctx-backed service layers are all synchronous and finalizer-free,\n // so the scope can close as soon as the context is built.\n // Convex's HTTP registration erases the data model. The supplied generated\n // schema restores it; this does not change the runtime context or services.\n const services = Effect.runSync(\n Effect.scoped(\n Layer.build(layer(ctx as unknown as GenericActionCtx<DataModel_>)),\n ),\n );\n return handler(\n request,\n Context.add(services, Console.Console, globalThis.console),\n );\n });\n\n const convexHttpRouter = httpRouter();\n\n Array.forEach(ROUTABLE_HTTP_METHODS, (method) => {\n const routeSpec: RouteSpecWithPathPrefix = {\n pathPrefix: \"/\",\n method,\n handler: httpAction,\n };\n convexHttpRouter.route(routeSpec);\n });\n\n if (api !== undefined) {\n const matcher = FindMyWay.make<string>();\n const reflected: ReturnType<ConvexHttpRouter[\"getRoutes\"]> = [];\n HttpApi.reflect(api, {\n onGroup: () => {},\n onEndpoint: ({ endpoint }) => {\n const method = ROUTABLE_HTTP_METHODS.find(\n (candidate) => candidate === endpoint.method,\n );\n if (method === undefined) return;\n const path = apiRouterPath(\n endpoint.path as FindMyWay.PathInput,\n endpoint.params,\n );\n matcher.on(method, path, endpoint.path);\n // Effect also matches a wildcard route's base path without its slash.\n if (path.endsWith(\"/*\")) {\n matcher.on(method, path.slice(0, -2) as `/${string}`, endpoint.path);\n }\n reflected.push([endpoint.path, method, httpAction]);\n },\n });\n reflected.sort(\n ([pathA, methodA], [pathB, methodB]) =>\n pathA.localeCompare(pathB) || methodA.localeCompare(methodB),\n );\n\n const getRoutes = convexHttpRouter.getRoutes;\n convexHttpRouter.getRoutes = () =>\n reflected.length === 0\n ? getRoutes()\n : [\n ...getRoutes().filter(([, , action]) => action !== httpAction),\n ...reflected,\n ];\n const lookup = convexHttpRouter.lookup;\n convexHttpRouter.lookup = (path, method) => {\n const match = lookup(path, method);\n if (match === null || match[0] !== httpAction) return match;\n const normalized = match[1];\n const reflectedPath = matcher.find(normalized, path)?.handler;\n return reflectedPath === undefined\n ? match\n : [httpAction, normalized, reflectedPath];\n };\n }\n\n return convexHttpRouter;\n};\n\n/*!\n * apiRouterPath is adapted from Effect 4.0.1 http-api/internal/path.ts.\n *\n * MIT License\n *\n * Copyright (c) 2023 Effectful Technologies Inc\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n// Match Effect's HttpApiBuilder path normalization, which is not publicly\n// exported (effect/http-api/internal/path.ts). Undeclared colons are literals;\n// declared params followed by a literal suffix need an explicit regex boundary.\nconst apiRouterPath = (\n path: FindMyWay.PathInput,\n params: Schema.Top | undefined,\n): FindMyWay.PathInput => {\n if (params === undefined || !path.includes(\":\")) return path;\n let ast = params.ast;\n while (ast.encoding !== undefined) {\n ast = ast.encoding[ast.encoding.length - 1].to;\n }\n if (!SchemaAST.isObjects(ast) || ast.indexSignatures.length !== 0)\n return path;\n const names = new Set(\n ast.propertySignatures.map((property) => String(property.name)),\n );\n let normalized = \"\";\n let depth = 0;\n let regexStart = -1;\n for (let i = 0; i < path.length; i++) {\n const char = path[i];\n if (depth > 0 || i === regexStart) {\n normalized += char;\n if (char === \"\\\\\") normalized += path[++i] ?? \"\";\n else if (char === \"(\") depth++;\n else if (char === \")\") depth--;\n } else if (char !== \":\") {\n normalized += char;\n } else if (path[i + 1] === \":\") {\n normalized += \"::\";\n i++;\n } else {\n const param = /^:(\\w+)/.exec(path.slice(i));\n if (param !== null && names.has(param[1])) {\n normalized += param[0];\n i += param[0].length - 1;\n const next = path[i + 1];\n if (next === \"(\") regexStart = i + 1;\n else if (next !== undefined && !\"/.-?\".includes(next))\n normalized += \"(.*?)\";\n } else {\n normalized += \"::\";\n }\n }\n }\n return normalized as FindMyWay.PathInput;\n};\n\n// These are necessary until the Convex runtime supports these APIs. See\n// https://discord.com/channels/1019350475847499849/1281364098419785760\n// Each patch is applied only where the API is actually broken, so runtimes\n// with working implementations—Node under convex-test, notably, where\n// `new AbortSignal()` is an illegal constructor—keep their native behavior.\nconst applyMonkeyPatches = () => {\n const urlCredentialsBroken = (() => {\n try {\n return new URL(\"https://confect.dev\").username === undefined;\n } catch {\n return true;\n }\n })();\n if (urlCredentialsBroken) {\n URL = class extends URL {\n override get username() {\n return \"\";\n }\n override get password() {\n return \"\";\n }\n };\n }\n\n const requestSignalBroken = (() => {\n try {\n return new Request(\"https://confect.dev\").signal === undefined;\n } catch {\n return true;\n }\n })();\n if (requestSignalBroken) {\n // `configurable` so repeated definition—e.g. module re-evaluation in a\n // long-lived environment—does not throw.\n Object.defineProperty(Request.prototype, \"signal\", {\n get: () => new AbortSignal(),\n configurable: true,\n });\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHA,MAAa,QACX,QACA,YAEA,cAAc,QAAQA,iBAAoC,SAAS,GAAG;;;;;;AAOxE,MAAa,aAET,YAGA,QACA,YAEA,cAME,MAAM,MAAM,OAAO,OAAO,IAAI,CAAC,CAAC,KAC9B,MAAM,KAAK,aAAa,MAAM,GAC9B,MAAM,KAAK,mBACT,OAAO,KAAK,MAAM,QAAQ,eAAe,CAAC,CAC5C,GACA,MAAM,UACR,IACC,QAAQC,YAA+B,QAAQ,GAAG,GACnD,SAAS,GACX;AAMJ,MAAM,kBAAkB,MAAM,OAC5B,WAAW,YACX,OAAO,IAAI,aAAa;CACtB,MAAM,SAAS,OAAO,WAAW;CACjC,MAAM,UAAU,OAAO,OAAO,OAC5B,OAAO,eACP,iBACF;CACA,OAAO,OAAO,SAAS,QAAQ,QAAQ;AACzC,CAAC,CAAC,CAAC,KAAK,OAAO,KAAK,CACtB;AAEA,MAAM,iBAMJ,QACA,SACA,QACqB;CACrB,mBAAmB;CAMnB,MAAM,WAAW,OAAO,KACtB,MAAM,aAAaC,OAAkB,GACrC,MAAM,aAAaC,KAA0B,GAC7C,MAAM,QAAQ,WAAW,aAAa,CACxC;CAKA,MAAM,EAAE,YAAY,WAAW,aAAa,UAAU,EACpD,eAAe,KACjB,CAAC;CAED,MAAM,aAAa,mBAAmB,KAAK,YAA+B;EAKxE,MAAM,WAAW,OAAO,QACtB,OAAO,OACL,MAAM,MAAMC,QAAM,GAA8C,CAAC,CACnE,CACF;EACA,OAAO,QACL,SACA,QAAQ,IAAI,UAAU,QAAQ,SAAS,WAAW,OAAO,CAC3D;CACF,CAAC;CAED,MAAM,mBAAmB,WAAW;CAEpC,MAAM,QAAQ,wBAAwB,WAAW;EAC/C,MAAM,YAAqC;GACzC,YAAY;GAC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A,IAAa,WAAW;GACtB,OAAO;EACT;CACF;CAUF,WAPmC;EACjC,IAAI;GACF,OAAO,IAAI,QAAQ,qBAAqB,CAAC,CAAC,WAAW,KAAA;EACvD,QAAQ;GACN,OAAO;EACT;CACF,EAAA,CACsB,GAGpB,OAAO,eAAe,QAAQ,WAAW,UAAU;EACjD,WAAW,IAAI,YAAY;EAC3B,cAAc;CAChB,CAAC;AAEL"}
1
+ {"version":3,"file":"HttpRouter.js","names":["RegisteredFunction.baseActionLayer","RegisteredFunction.actionLayer","ConvexLogger.layer","ObservabilityRuntime.memoized","ConvexConfigProvider.layer","layer"],"sources":["../src/HttpRouter.ts"],"sourcesContent":["import {\n type HttpRouter as ConvexHttpRouter,\n httpActionGeneric,\n httpRouter,\n ROUTABLE_HTTP_METHODS,\n type RouteSpecWithPathPrefix,\n type GenericActionCtx,\n type GenericDataModel,\n} from \"convex/server\";\nimport * as Array from \"effect/Array\";\nimport * as Console from \"effect/Console\";\nimport * as Context from \"effect/Context\";\nimport * as Config from \"effect/Config\";\nimport * as Effect from \"effect/Effect\";\nimport type * as FileSystem from \"effect/FileSystem\";\nimport * as Layer from \"effect/Layer\";\nimport * as Match from \"effect/Match\";\nimport type * as Path from \"effect/Path\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaAST from \"effect/SchemaAST\";\nimport * as FindMyWay from \"effect/http/FindMyWay\";\nimport * as HttpApi from \"effect/http-api/HttpApi\";\nimport type * as HttpApiGroup from \"effect/http-api/HttpApiGroup\";\nimport type * as Etag from \"effect/http/Etag\";\nimport type * as HttpPlatform from \"effect/http/HttpPlatform\";\nimport * as HttpRouter from \"effect/http/HttpRouter\";\nimport * as HttpMiddleware from \"effect/http/HttpMiddleware\";\nimport type * as HttpServerRequest from \"effect/http/HttpServerRequest\";\nimport * as HttpServer from \"effect/http/HttpServer\";\nimport type * as ActionRunner from \"./ActionRunner.js\";\nimport type * as Auth from \"./Auth.js\";\nimport type { ExecutionMetadata } from \"./ExecutionMetadata.js\";\nimport type { RequestMetadata } from \"./RequestMetadata.js\";\nimport type * as DatabaseSchema from \"./DatabaseSchema.js\";\nimport type * as DataModel from \"./DataModel.js\";\nimport type * as Handler from \"./Handler.js\";\nimport * as ConvexConfigProvider from \"./ConvexConfigProvider.js\";\nimport * as ObservabilityRuntime from \"./internal/observability.js\";\nimport * as ConvexLogger from \"./ConvexLogger.js\";\nimport type * as MutationRunner from \"./MutationRunner.js\";\nimport type * as QueryRunner from \"./QueryRunner.js\";\nimport * as RegisteredFunction from \"./RegisteredFunction.js\";\nimport type * as Scheduler from \"./Scheduler.js\";\nimport type { Storage } from \"./Storage.js\";\nimport type { StorageActionWriter } from \"./StorageActionWriter.js\";\nimport type { StorageReader } from \"./StorageReader.js\";\nimport type { StorageWriter } from \"./StorageWriter.js\";\n\n/**\n * The Confect services available to HTTP route handlers and middleware,\n * supplied per request from the Convex action context.\n */\nexport type Services =\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | ActionRunner.ActionRunner\n | Scheduler.Scheduler\n | Auth.Auth\n | ExecutionMetadata\n | RequestMetadata\n | Storage\n | StorageReader\n | StorageWriter\n | StorageActionWriter;\n\n/**\n * A layer that registers routes on the HTTP router—the input to {@link make}.\n *\n * Compose it from Effect's `effect/http` and `effect/http-api` modules:\n * `HttpApiBuilder.layer(api)` registers an `HttpApi`'s endpoints (provide its\n * group handler layers with `Layer.provide`), `HttpApiScalar.layer(api, ...)`\n * serves interactive API docs, `HttpRouter.add` registers a plain route, and\n * `HttpRouter.middleware(fn, { global: true })` applies middleware to every\n * route. Merge any number of these with `Layer.mergeAll`.\n *\n * Route handlers and middleware may require any of the Confect {@link Services},\n * which surface as request-level `Requires` markers and are supplied per\n * request. Anything else the layer requires is a type error—notably, an\n * `HttpApiBuilder.layer(api)` whose group handler layers are not provided\n * leaves an `HttpApiGroup.ToService` requirement behind, so a missing handler\n * group is caught at compile time.\n *\n * Layers are built with Confect's Convex-aware `ConfigProvider` in context, so\n * `Config` reads (e.g. in `Layer.unwrap`) resolve against Convex environment\n * variables.\n */\nexport type Routes<Services_ = Services> = Layer.Layer<\n never,\n never,\n | HttpRouter.HttpRouter\n | Etag.Generator\n | FileSystem.FileSystem\n | HttpPlatform.HttpPlatform\n | Path.Path\n | HttpRouter.Request<\"Requires\", Services_>\n | HttpRouter.Request<\"GlobalRequires\", Services_>\n | HttpRouter.Request<\"Error\", any>\n | HttpRouter.Request<\"GlobalError\", any>\n>;\n\n/**\n * Create a Convex HTTP router serving the given routes.\n *\n * A single catch-all `httpAction` is registered for every routable method under\n * the path prefix `\"/\"`, making the Effect router the single source of truth\n * for paths: place an API with `HttpApi.prefix` or absolute route paths.\n * Requests that match no route receive the Effect router's 404 response.\n *\n * Supply `{ api }` with the `HttpApi` registered by the routes layer to show\n * endpoint patterns in Convex completion logs and the dashboard. Requests that\n * match no reflected endpoint keep the catch-all completion label. Without the\n * option, Convex reports the catch-all registrations. Application endpoints\n * must not overlap component HTTP mounts: Convex also uses dashboard route\n * entries to select between application and component routers.\n *\n * Plain Convex routes can still be added to the returned router—Convex matches\n * exact paths first and longer path prefixes before the catch-all, so they take\n * precedence.\n */\nexport const make = <Id extends string, Groups extends HttpApiGroup.Constraint>(\n routes: Routes,\n options?: {\n readonly observability?: Layer.Layer<never> | undefined;\n readonly api?: HttpApi.HttpApi<Id, Groups> | undefined;\n },\n): ConvexHttpRouter =>\n makeWithLayer(\n routes,\n RegisteredFunction.baseActionLayer,\n options?.api,\n options?.observability,\n );\n\n/**\n * Derive HTTP capabilities and ID scopes from the generated database schema.\n * Component routes are relative to their installation's HTTP mount prefix.\n * Supply `{ api }` as in {@link make}; labels stay component-relative.\n */\nexport const forSchema =\n <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n schema: DatabaseSchema_,\n ) =>\n <Id extends string, Groups extends HttpApiGroup.Constraint>(\n routes: Routes<Handler.ActionServices<DatabaseSchema_>>,\n options?: {\n readonly observability?: Layer.Layer<never> | undefined;\n readonly api?: HttpApi.HttpApi<Id, Groups> | undefined;\n },\n ): ConvexHttpRouter =>\n makeWithLayer<\n Handler.ActionServices<DatabaseSchema_>,\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>,\n Id,\n Groups\n >(\n Match.value(schema.target.kind).pipe(\n Match.when(\"app\", () => routes),\n Match.when(\"component\", () =>\n routes.pipe(Layer.provide(componentRouter)),\n ),\n Match.exhaustive,\n ),\n (ctx) => RegisteredFunction.actionLayer(schema, ctx),\n options?.api,\n options?.observability,\n schema.target.kind === \"component\",\n );\n\n// Convex uses a component-relative path to select its HTTP action but passes\n// the original request URL to that action. Its CONVEX_SITE_URL includes the\n// installation's full mount prefix (including parent mounts). Prefixing the\n// Effect router preserves relative routes without rewriting the Request body.\nconst componentRouter = Layer.effect(\n HttpRouter.HttpRouter,\n Effect.gen(function* () {\n const router = yield* HttpRouter.HttpRouter;\n const siteUrl = yield* Config.schema(\n Schema.URLFromString,\n \"CONVEX_SITE_URL\",\n );\n return router.prefixed(siteUrl.pathname);\n }).pipe(Effect.orDie),\n);\n\nconst makeWithLayer = <\n Services_,\n DataModel_ extends GenericDataModel,\n Id extends string,\n Groups extends HttpApiGroup.Constraint,\n>(\n routes: Routes<Services_>,\n layer: (ctx: GenericActionCtx<DataModel_>) => Layer.Layer<Services_>,\n api: HttpApi.HttpApi<Id, Groups> | undefined,\n observability?: Layer.Layer<never>,\n siteRelative = false,\n): ConvexHttpRouter => {\n applyMonkeyPatches();\n\n const spanName = Layer.effect(\n HttpMiddleware.SpanNameGenerator,\n Effect.gen(function* () {\n const prefix = siteRelative\n ? (yield* Config.schema(\n Schema.URLFromString,\n \"CONVEX_SITE_URL\",\n )).pathname.replace(/\\/$/, \"\")\n : \"\";\n return (request: HttpServerRequest.HttpServerRequest) =>\n convexHttpRouter.lookup(\n new URL(request.originalUrl).pathname.slice(prefix.length) || \"/\",\n request.method as (typeof ROUTABLE_HTTP_METHODS)[number],\n )?.[2] ?? \"/*\";\n }).pipe(Effect.orDie),\n );\n\n // Provided (not just merged) so that route layers' own construction—e.g.\n // a `Layer.unwrap` reading `Config`—resolves configuration through the\n // Convex-aware provider; merged so that request fibers—endpoint handlers\n // and middleware—do too.\n const AppLayer = routes.pipe(\n Layer.provideMerge(\n observability === undefined\n ? ConvexLogger.layer\n : Layer.merge(ObservabilityRuntime.memoized(observability), spanName),\n ),\n Layer.provideMerge(ConvexConfigProvider.layer),\n Layer.provide(HttpServer.layerServices),\n );\n\n // The Confect service requirements of route handlers and middleware surface\n // as request-level `Requires` markers on the layer, which the web handler\n // exposes as a per-request context argument.\n const { handler } = HttpRouter.toWebHandler(AppLayer, {\n disableLogger: true,\n /* oxlint-disable effecttsgo/any-unknown-in-error-context -- Keep Effect's erased HTTP boundary errors intact. */\n ...(observability === undefined\n ? {}\n : {\n middleware: (effect) =>\n Effect.andThen(\n Effect.annotateCurrentSpan(\"kind\", \"httpAction\"),\n effect,\n ),\n }),\n /* oxlint-enable effecttsgo/any-unknown-in-error-context */\n });\n\n const httpAction = httpActionGeneric((ctx, request): Promise<Response> => {\n // The ctx-backed service layers are all synchronous and finalizer-free,\n // so the scope can close as soon as the context is built.\n // Convex's HTTP registration erases the data model. The supplied generated\n // schema restores it; this does not change the runtime context or services.\n const services = Effect.runSync(\n Effect.scoped(\n Layer.build(layer(ctx as unknown as GenericActionCtx<DataModel_>)),\n ),\n );\n return handler(\n request,\n Context.add(services, Console.Console, globalThis.console),\n );\n });\n\n const convexHttpRouter = httpRouter();\n\n Array.forEach(ROUTABLE_HTTP_METHODS, (method) => {\n const routeSpec: RouteSpecWithPathPrefix = {\n pathPrefix: \"/\",\n method,\n handler: httpAction,\n };\n convexHttpRouter.route(routeSpec);\n });\n\n if (api !== undefined) {\n const matcher = FindMyWay.make<string>();\n const reflected: ReturnType<ConvexHttpRouter[\"getRoutes\"]> = [];\n HttpApi.reflect(api, {\n onGroup: () => {},\n onEndpoint: ({ endpoint }) => {\n const method = ROUTABLE_HTTP_METHODS.find(\n (candidate) => candidate === endpoint.method,\n );\n if (method === undefined) return;\n const path = apiRouterPath(\n endpoint.path as FindMyWay.PathInput,\n endpoint.params,\n );\n matcher.on(method, path, endpoint.path);\n // Effect also matches a wildcard route's base path without its slash.\n if (path.endsWith(\"/*\")) {\n matcher.on(method, path.slice(0, -2) as `/${string}`, endpoint.path);\n }\n reflected.push([endpoint.path, method, httpAction]);\n },\n });\n reflected.sort(\n ([pathA, methodA], [pathB, methodB]) =>\n pathA.localeCompare(pathB) || methodA.localeCompare(methodB),\n );\n\n const getRoutes = convexHttpRouter.getRoutes;\n convexHttpRouter.getRoutes = () =>\n reflected.length === 0\n ? getRoutes()\n : [\n ...getRoutes().filter(([, , action]) => action !== httpAction),\n ...reflected,\n ];\n const lookup = convexHttpRouter.lookup;\n convexHttpRouter.lookup = (path, method) => {\n const match = lookup(path, method);\n if (match === null || match[0] !== httpAction) return match;\n const normalized = match[1];\n const reflectedPath = matcher.find(normalized, path)?.handler;\n return reflectedPath === undefined\n ? match\n : [httpAction, normalized, reflectedPath];\n };\n }\n\n return convexHttpRouter;\n};\n\n/*!\n * apiRouterPath is adapted from Effect 4.0.1 http-api/internal/path.ts.\n *\n * MIT License\n *\n * Copyright (c) 2023 Effectful Technologies Inc\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n// Match Effect's HttpApiBuilder path normalization, which is not publicly\n// exported (effect/http-api/internal/path.ts). Undeclared colons are literals;\n// declared params followed by a literal suffix need an explicit regex boundary.\nconst apiRouterPath = (\n path: FindMyWay.PathInput,\n params: Schema.Top | undefined,\n): FindMyWay.PathInput => {\n if (params === undefined || !path.includes(\":\")) return path;\n let ast = params.ast;\n while (ast.encoding !== undefined) {\n ast = ast.encoding[ast.encoding.length - 1].to;\n }\n if (!SchemaAST.isObjects(ast) || ast.indexSignatures.length !== 0)\n return path;\n const names = new Set(\n ast.propertySignatures.map((property) => String(property.name)),\n );\n let normalized = \"\";\n let depth = 0;\n let regexStart = -1;\n for (let i = 0; i < path.length; i++) {\n const char = path[i];\n if (depth > 0 || i === regexStart) {\n normalized += char;\n if (char === \"\\\\\") normalized += path[++i] ?? \"\";\n else if (char === \"(\") depth++;\n else if (char === \")\") depth--;\n } else if (char !== \":\") {\n normalized += char;\n } else if (path[i + 1] === \":\") {\n normalized += \"::\";\n i++;\n } else {\n const param = /^:(\\w+)/.exec(path.slice(i));\n if (param !== null && names.has(param[1])) {\n normalized += param[0];\n i += param[0].length - 1;\n const next = path[i + 1];\n if (next === \"(\") regexStart = i + 1;\n else if (next !== undefined && !\"/.-?\".includes(next))\n normalized += \"(.*?)\";\n } else {\n normalized += \"::\";\n }\n }\n }\n return normalized as FindMyWay.PathInput;\n};\n\n// These are necessary until the Convex runtime supports these APIs. See\n// https://discord.com/channels/1019350475847499849/1281364098419785760\n// Each patch is applied only where the API is actually broken, so runtimes\n// with working implementations—Node under convex-test, notably, where\n// `new AbortSignal()` is an illegal constructor—keep their native behavior.\nconst applyMonkeyPatches = () => {\n const urlCredentialsBroken = (() => {\n try {\n return new URL(\"https://confect.dev\").username === undefined;\n } catch {\n return true;\n }\n })();\n if (urlCredentialsBroken) {\n URL = class extends URL {\n override get username() {\n return \"\";\n }\n override get password() {\n return \"\";\n }\n };\n }\n\n const requestSignalBroken = (() => {\n try {\n return new Request(\"https://confect.dev\").signal === undefined;\n } catch {\n return true;\n }\n })();\n if (requestSignalBroken) {\n // `configurable` so repeated definition—e.g. module re-evaluation in a\n // long-lived environment—does not throw.\n Object.defineProperty(Request.prototype, \"signal\", {\n get: () => new AbortSignal(),\n configurable: true,\n });\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuHA,MAAa,QACX,QACA,YAKA,cACE,QACAA,iBACA,SAAS,KACT,SAAS,aACX;;;;;;AAOF,MAAa,aAET,YAGA,QACA,YAKA,cAME,MAAM,MAAM,OAAO,OAAO,IAAI,CAAC,CAAC,KAC9B,MAAM,KAAK,aAAa,MAAM,GAC9B,MAAM,KAAK,mBACT,OAAO,KAAK,MAAM,QAAQ,eAAe,CAAC,CAC5C,GACA,MAAM,UACR,IACC,QAAQC,YAA+B,QAAQ,GAAG,GACnD,SAAS,KACT,SAAS,eACT,OAAO,OAAO,SAAS,WACzB;AAMJ,MAAM,kBAAkB,MAAM,OAC5B,WAAW,YACX,OAAO,IAAI,aAAa;CACtB,MAAM,SAAS,OAAO,WAAW;CACjC,MAAM,UAAU,OAAO,OAAO,OAC5B,OAAO,eACP,iBACF;CACA,OAAO,OAAO,SAAS,QAAQ,QAAQ;AACzC,CAAC,CAAC,CAAC,KAAK,OAAO,KAAK,CACtB;AAEA,MAAM,iBAMJ,QACA,SACA,KACA,eACA,eAAe,UACM;CACrB,mBAAmB;CAEnB,MAAM,WAAW,MAAM,OACrB,eAAe,mBACf,OAAO,IAAI,aAAa;EACtB,MAAM,SAAS,gBACV,OAAO,OAAO,OACb,OAAO,eACP,iBACF,EAAA,CAAG,SAAS,QAAQ,OAAO,EAAE,IAC7B;EACJ,QAAQ,YACN,iBAA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EACpC,MAAM,OAAO,KAAK;EAClB,IAAI,QAAQ,KAAK,MAAM,YAAY;GACjC,cAAc;GACd,IAAI,SAAS,MAAM,cAAc,KAAK,EAAE,MAAM;QACzC,IAAI,SAAS,KAAK;QAClB,IAAI,SAAS,KAAK;EACzB,OAAO,IAAI,SAAS,KAClB,cAAc;OACT,IAAI,KAAK,IAAI,OAAO,KAAK;GAC9B,cAAc;GACd;EACF,OAAO;GACL,MAAM,QAAQ,UAAU,KAAK,KAAK,MAAM,CAAC,CAAC;GAC1C,IAAI,UAAU,QAAQ,MAAM,IAAI,MAAM,EAAE,GAAG;IACzC,cAAc,MAAM;IACpB,KAAK,MAAM,EAAE,CAAC,SAAS;IACvB,MAAM,OAAO,KAAK,IAAI;IACtB,IAAI,SAAS,KAAK,aAAa,IAAI;SAC9B,IAAI,SAAS,KAAA,KAAa,CAAC,OAAO,SAAS,IAAI,GAClD,cAAc;GAClB,OACE,cAAc;EAElB;CACF;CACA,OAAO;AACT;AAOA,MAAM,2BAA2B;CAQ/B,WAPoC;EAClC,IAAI;GACF,OAAO,IAAI,IAAI,qBAAqB,CAAC,CAAC,aAAa,KAAA;EACrD,QAAQ;GACN,OAAO;EACT;CACF,EAAA,CACuB,GACrB,MAAM,cAAc,IAAI;EACtB,IAAa,WAAW;GACtB,OAAO;EACT;EACA,IAAa,WAAW;GACtB,OAAO;EACT;CACF;CAUF,WAPmC;EACjC,IAAI;GACF,OAAO,IAAI,QAAQ,qBAAqB,CAAC,CAAC,WAAW,KAAA;EACvD,QAAQ;GACN,OAAO;EACT;CACF,EAAA,CACsB,GAGpB,OAAO,eAAe,QAAQ,WAAW,UAAU;EACjD,WAAW,IAAI,YAAY;EAC3B,cAAc;CAChB,CAAC;AAEL"}
@@ -3,8 +3,8 @@ import { Registry } from "./Registry.js";
3
3
  import { TypeId, registryKey } from "./MiddlewareRegistryItem.js";
4
4
  import { setNestedProperty } from "./internal/utils.js";
5
5
  import * as Context from "effect/Context";
6
- import * as Layer from "effect/Layer";
7
6
  import * as Effect from "effect/Effect";
7
+ import * as Layer from "effect/Layer";
8
8
  import * as MiddlewareSpec from "@confect/core/MiddlewareSpec";
9
9
  import * as Ref from "effect/Ref";
10
10
  //#region src/MiddlewareImpl.ts
@@ -1,4 +1,4 @@
1
- import * as Ref from "@confect/core/Ref";
1
+ import type * as Ref from "@confect/core/Ref";
2
2
  import type { GenericActionCtx } from "convex/server";
3
3
  import * as Context from "effect/Context";
4
4
  import * as Effect from "effect/Effect";
@@ -1 +1 @@
1
- {"version":3,"file":"MutationRunner.d.ts","sourceRoot":"","sources":["../src/MutationRunner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,0BAA0B,MAAM,iCAAiC,CAAC;AAE9E,MAAM,MAAM,OAAO,GAAG,0BAA0B,CAAC,eAAe,CAAC;AAmDjE,eAAO,MAAM,cAAc;;SA5CJ,QAAQ,SAAS,GAAG,CAAC,WAAW,YACzC,QAAQ,WACT,CAAC,GAAG,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,EAAE,SAAS,CAAC,GAC5D,MAAM,CAAC,MAAM,CACd,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,EACrB,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,WAAW,CACzC;SACoB,QAAQ,SAAS,GAAG,CAAC,WAAW,YACzC,QAAQ,QACZ,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,WACf,OAAO,GAAG,SAAS,GAC3B,MAAM,CAAC,MA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AG,CAAC,IAAI,CAAC,QAAQ,CAAC,WACf,OAAO,GAAG,SAAS,GAC3B,MAAM,CAAC,MAAM,CACd,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,EACrB,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,WAAW,EACxC,0BAA0B,CAAC,0BAA0B,CACtD;;gBAmC+C,CAAC"}
@@ -1,9 +1,9 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { runWithCodec } from "./internal/reservedArgument.js";
2
3
  import { MutationTransactionContext } from "./MutationTransactionContext.js";
3
4
  import * as Context from "effect/Context";
4
- import * as Layer from "effect/Layer";
5
- import * as Ref from "@confect/core/Ref";
6
5
  import * as Effect from "effect/Effect";
6
+ import * as Layer from "effect/Layer";
7
7
  //#region src/MutationRunner.ts
8
8
  var MutationRunner_exports = /* @__PURE__ */ __exportAll({
9
9
  MutationRunner: () => MutationRunner,
@@ -15,7 +15,7 @@ const make = (nativeRunMutation) => {
15
15
  return run(Effect.gen(function* () {
16
16
  const actualArgs = args ?? {};
17
17
  if (options !== void 0) return yield* (yield* MutationTransactionContext).runMutation(mutation, actualArgs, options);
18
- return yield* Ref.runWithCodec(mutation, actualArgs, (ref, encodedArgs) => nativeRunMutation(ref, encodedArgs));
18
+ return yield* runWithCodec(mutation, actualArgs, (ref, encodedArgs) => nativeRunMutation(ref, encodedArgs));
19
19
  }));
20
20
  }
21
21
  return { runMutation };
@@ -1 +1 @@
1
- {"version":3,"file":"MutationRunner.js","names":["MutationTransactionContext.MutationTransactionContext"],"sources":["../src/MutationRunner.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport type { GenericActionCtx } from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport type * as Schema from \"effect/Schema\";\nimport * as MutationTransactionContext from \"./MutationTransactionContext.js\";\n\nexport type Options = MutationTransactionContext.MutationOptions;\n\nconst run = Effect.fn(\"MutationRunner.runMutation\")(\n <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> => effect,\n);\n\nconst make = (nativeRunMutation: GenericActionCtx<any>[\"runMutation\"]) => {\n function runMutation<Mutation extends Ref.AnyMutation>(\n mutation: Mutation,\n ...args: [...Ref.OptionalArgs<Mutation>, options?: undefined]\n ): Effect.Effect<\n Ref.Returns<Mutation>,\n Ref.Error<Mutation> | Schema.SchemaError\n >;\n function runMutation<Mutation extends Ref.AnyMutation>(\n mutation: Mutation,\n args: Ref.Args<Mutation>,\n options: Options | undefined,\n ): Effect.Effect<\n Ref.Returns<Mutation>,\n Ref.Error<Mutation> | Schema.SchemaError,\n MutationTransactionContext.MutationTransactionContext\n >;\n function runMutation<Mutation extends Ref.AnyMutation>(\n mutation: Mutation,\n args?: Ref.Args<Mutation>,\n options?: Options,\n ): Effect.Effect<\n Ref.Returns<Mutation>,\n Ref.Error<Mutation> | Schema.SchemaError,\n MutationTransactionContext.MutationTransactionContext\n > {\n return run(\n Effect.gen(function* () {\n const actualArgs = (args ?? {}) as Ref.Args<Mutation>;\n if (options !== undefined) {\n const controls =\n yield* MutationTransactionContext.MutationTransactionContext;\n return yield* controls.runMutation(mutation, actualArgs, options);\n }\n return yield* Ref.runWithCodec(\n mutation,\n actualArgs,\n (ref, encodedArgs) => nativeRunMutation(ref, encodedArgs),\n );\n }),\n );\n }\n return { runMutation };\n};\n\nexport const MutationRunner = Context.Service<ReturnType<typeof make>>(\n \"@confect/server/MutationRunner\",\n);\nexport type MutationRunner = typeof MutationRunner.Identifier;\n\nexport const layer = (runMutation: GenericActionCtx<any>[\"runMutation\"]) =>\n Layer.succeed(MutationRunner, make(runMutation));\n"],"mappings":";;;;;;;;;;;AAUA,MAAM,MAAM,OAAO,GAAG,4BAA4B,CAAC,EACvC,WAA2D,MACvE;AAEA,MAAM,QAAQ,sBAA4D;CAiBxE,SAAS,YACP,UACA,MACA,SAKA;EACA,OAAO,IACL,OAAO,IAAI,aAAa;GACtB,MAAM,aAAc,QAAQ,CAAC;GAC7B,IAAI,YAAY,KAAA,GAGd,OAAO,QAAO,OADLA,2BAAAA,CACc,YAAY,UAAU,YAAY,OAAO;GAElE,OAAO,OAAO,IAAI,aAChB,UACA,aACC,KAAK,gBAAgB,kBAAkB,KAAK,WAAW,CAC1D;EACF,CAAC,CACH;CACF;CACA,OAAO,EAAE,YAAY;AACvB;AAEA,MAAa,iBAAiB,QAAQ,QACpC,gCACF;AAGA,MAAa,SAAS,gBACpB,MAAM,QAAQ,gBAAgB,KAAK,WAAW,CAAC"}
1
+ {"version":3,"file":"MutationRunner.js","names":["MutationTransactionContext.MutationTransactionContext","ReservedArgument.runWithCodec"],"sources":["../src/MutationRunner.ts"],"sourcesContent":["import * as ReservedArgument from \"./internal/reservedArgument.js\";\nimport type * as Ref from \"@confect/core/Ref\";\nimport type { GenericActionCtx } from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport type * as Schema from \"effect/Schema\";\nimport * as MutationTransactionContext from \"./MutationTransactionContext.js\";\n\nexport type Options = MutationTransactionContext.MutationOptions;\n\nconst run = Effect.fn(\"MutationRunner.runMutation\")(\n <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> => effect,\n);\n\nconst make = (nativeRunMutation: GenericActionCtx<any>[\"runMutation\"]) => {\n function runMutation<Mutation extends Ref.AnyMutation>(\n mutation: Mutation,\n ...args: [...Ref.OptionalArgs<Mutation>, options?: undefined]\n ): Effect.Effect<\n Ref.Returns<Mutation>,\n Ref.Error<Mutation> | Schema.SchemaError\n >;\n function runMutation<Mutation extends Ref.AnyMutation>(\n mutation: Mutation,\n args: Ref.Args<Mutation>,\n options: Options | undefined,\n ): Effect.Effect<\n Ref.Returns<Mutation>,\n Ref.Error<Mutation> | Schema.SchemaError,\n MutationTransactionContext.MutationTransactionContext\n >;\n function runMutation<Mutation extends Ref.AnyMutation>(\n mutation: Mutation,\n args?: Ref.Args<Mutation>,\n options?: Options,\n ): Effect.Effect<\n Ref.Returns<Mutation>,\n Ref.Error<Mutation> | Schema.SchemaError,\n MutationTransactionContext.MutationTransactionContext\n > {\n return run(\n Effect.gen(function* () {\n const actualArgs = (args ?? {}) as Ref.Args<Mutation>;\n if (options !== undefined) {\n const controls =\n yield* MutationTransactionContext.MutationTransactionContext;\n return yield* controls.runMutation(mutation, actualArgs, options);\n }\n return yield* ReservedArgument.runWithCodec(\n mutation,\n actualArgs,\n (ref, encodedArgs) => nativeRunMutation(ref, encodedArgs),\n );\n }),\n );\n }\n return { runMutation };\n};\n\nexport const MutationRunner = Context.Service<ReturnType<typeof make>>(\n \"@confect/server/MutationRunner\",\n);\nexport type MutationRunner = typeof MutationRunner.Identifier;\n\nexport const layer = (runMutation: GenericActionCtx<any>[\"runMutation\"]) =>\n Layer.succeed(MutationRunner, make(runMutation));\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,MAAM,OAAO,GAAG,4BAA4B,CAAC,EACvC,WAA2D,MACvE;AAEA,MAAM,QAAQ,sBAA4D;CAiBxE,SAAS,YACP,UACA,MACA,SAKA;EACA,OAAO,IACL,OAAO,IAAI,aAAa;GACtB,MAAM,aAAc,QAAQ,CAAC;GAC7B,IAAI,YAAY,KAAA,GAGd,OAAO,QAAO,OADLA,2BAAAA,CACc,YAAY,UAAU,YAAY,OAAO;GAElE,OAAO,OAAOC,aACZ,UACA,aACC,KAAK,gBAAgB,kBAAkB,KAAK,WAAW,CAC1D;EACF,CAAC,CACH;CACF;CACA,OAAO,EAAE,YAAY;AACvB;AAEA,MAAa,iBAAiB,QAAQ,QACpC,gCACF;AAGA,MAAa,SAAS,gBACpB,MAAM,QAAQ,gBAAgB,KAAK,WAAW,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"MutationTransactionContext.d.ts","sourceRoot":"","sources":["../src/MutationTransactionContext.ts"],"names":[],"mappings":"AAAA,OAAO,KA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CAAC;AAC/E,MAAM,MAAM,YAAY,GAAG,uBAAuB,CAAC;;eAM9C,KAAK,SAAS,GAAG,CAAC,QAAQ;kBAU1B,QAAQ,SAAS,GAAG,CAAC,WAAW;;AAWrC,qBAAa,0BAA2B,SAAQ,+BAGC;CAAG;AAEpD,eAAO,MAAM,KAAK,QACX,IAAI,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,EAAE,UAAU,GAAG,aAAa,CAAC,0DACpB,CAAC"}
@@ -1,8 +1,9 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
- import * as Context from "effect/Context";
3
- import * as Layer from "effect/Layer";
2
+ import { runWithCodec } from "./internal/reservedArgument.js";
4
3
  import * as Ref from "@confect/core/Ref";
4
+ import * as Context from "effect/Context";
5
5
  import * as Effect from "effect/Effect";
6
+ import * as Layer from "effect/Layer";
6
7
  //#region src/MutationTransactionContext.ts
7
8
  var MutationTransactionContext_exports = /* @__PURE__ */ __exportAll({
8
9
  MutationTransactionContext: () => MutationTransactionContext,
@@ -10,7 +11,7 @@ var MutationTransactionContext_exports = /* @__PURE__ */ __exportAll({
10
11
  });
11
12
  const make = (ctx) => ({
12
13
  runQuery: Effect.fn("MutationTransactionContext.runQuery")((query, args, options) => Ref.runWithCodec(query, args, (ref, encodedArgs) => ctx.runQuery(ref, encodedArgs, options))),
13
- runMutation: Effect.fn("MutationTransactionContext.runMutation")((mutation, args, options) => Ref.runWithCodec(mutation, args, (ref, encodedArgs) => ctx.runMutation(ref, encodedArgs, options)))
14
+ runMutation: Effect.fn("MutationTransactionContext.runMutation")((mutation, args, options) => runWithCodec(mutation, args, (ref, encodedArgs) => ctx.runMutation(ref, encodedArgs, options)))
14
15
  });
15
16
  var MutationTransactionContext = class extends Context.Service()("@confect/server/MutationTransactionContext") {};
16
17
  const layer = (ctx) => Layer.succeed(MutationTransactionContext, make(ctx));
@@ -1 +1 @@
1
- {"version":3,"file":"MutationTransactionContext.js","names":[],"sources":["../src/MutationTransactionContext.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport type {\n AdvancedRunQueryOptions,\n GenericDataModel,\n GenericMutationCtx,\n} from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport type { Options as MutationOptions } from \"./QueryTransactionContext.js\";\n\nexport type { TransactionLimits } from \"convex/server\";\nexport type { Options as MutationOptions } from \"./QueryTransactionContext.js\";\nexport type QueryOptions = AdvancedRunQueryOptions;\n\nconst make = (\n ctx: Pick<GenericMutationCtx<GenericDataModel>, \"runQuery\" | \"runMutation\">,\n) => ({\n runQuery: Effect.fn(\"MutationTransactionContext.runQuery\")(\n <Query extends Ref.AnyQuery>(\n query: Query,\n args: Ref.Args<Query>,\n options: QueryOptions,\n ) =>\n Ref.runWithCodec(query, args, (ref, encodedArgs) =>\n ctx.runQuery(ref, encodedArgs, options),\n ),\n ),\n runMutation: Effect.fn(\"MutationTransactionContext.runMutation\")(\n <Mutation extends Ref.AnyMutation>(\n mutation: Mutation,\n args: Ref.Args<Mutation>,\n options: MutationOptions,\n ) =>\n Ref.runWithCodec(mutation, args, (ref, encodedArgs) =>\n ctx.runMutation(ref, encodedArgs, options),\n ),\n ),\n});\n\nexport class MutationTransactionContext extends Context.Service<\n MutationTransactionContext,\n ReturnType<typeof make>\n>()(\"@confect/server/MutationTransactionContext\") {}\n\nexport const layer = (\n ctx: Pick<GenericMutationCtx<GenericDataModel>, \"runQuery\" | \"runMutation\">,\n) => Layer.succeed(MutationTransactionContext, make(ctx));\n"],"mappings":";;;;;;;;;;AAeA,MAAM,QACJ,SACI;CACJ,UAAU,OAAO,GAAG,qCAAqC,CAAC,EAEtD,OACA,MACA,YAEA,IAAI,aAAa,OAAO,OAAO,KAAK,gBAClC,IAAI,SAAS,KAAK,aAAa,OAAO,CACxC,CACJ;CACA,aAAa,OAAO,GAAG,wCAAwC,CAAC,EAE5D,UACA,MACA,YAEA,IAAI,aAAa,UAAU,OAAO,KAAK,gBACrC,IAAI,YAAY,KAAK,aAAa,OAAO,CAC3C,CACJ;AACF;AAEA,IAAa,6BAAb,cAAgD,QAAQ,QAGtD,CAAC,CAAC,4CAA4C,CAAC,CAAC,CAAC;AAEnD,MAAa,SACX,QACG,MAAM,QAAQ,4BAA4B,KAAK,GAAG,CAAC"}
1
+ {"version":3,"file":"MutationTransactionContext.js","names":["ReservedArgument.runWithCodec"],"sources":["../src/MutationTransactionContext.ts"],"sourcesContent":["import * as ReservedArgument from \"./internal/reservedArgument.js\";\nimport * as Ref from \"@confect/core/Ref\";\nimport type {\n AdvancedRunQueryOptions,\n GenericDataModel,\n GenericMutationCtx,\n} from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport type { Options as MutationOptions } from \"./QueryTransactionContext.js\";\n\nexport type { TransactionLimits } from \"convex/server\";\nexport type { Options as MutationOptions } from \"./QueryTransactionContext.js\";\nexport type QueryOptions = AdvancedRunQueryOptions;\n\nconst make = (\n ctx: Pick<GenericMutationCtx<GenericDataModel>, \"runQuery\" | \"runMutation\">,\n) => ({\n runQuery: Effect.fn(\"MutationTransactionContext.runQuery\")(\n <Query extends Ref.AnyQuery>(\n query: Query,\n args: Ref.Args<Query>,\n options: QueryOptions,\n ) =>\n Ref.runWithCodec(query, args, (ref, encodedArgs) =>\n ctx.runQuery(ref, encodedArgs, options),\n ),\n ),\n runMutation: Effect.fn(\"MutationTransactionContext.runMutation\")(\n <Mutation extends Ref.AnyMutation>(\n mutation: Mutation,\n args: Ref.Args<Mutation>,\n options: MutationOptions,\n ) =>\n ReservedArgument.runWithCodec(mutation, args, (ref, encodedArgs) =>\n ctx.runMutation(ref, encodedArgs, options),\n ),\n ),\n});\n\nexport class MutationTransactionContext extends Context.Service<\n MutationTransactionContext,\n ReturnType<typeof make>\n>()(\"@confect/server/MutationTransactionContext\") {}\n\nexport const layer = (\n ctx: Pick<GenericMutationCtx<GenericDataModel>, \"runQuery\" | \"runMutation\">,\n) => Layer.succeed(MutationTransactionContext, make(ctx));\n"],"mappings":";;;;;;;;;;;AAgBA,MAAM,QACJ,SACI;CACJ,UAAU,OAAO,GAAG,qCAAqC,CAAC,EAEtD,OACA,MACA,YAEA,IAAI,aAAa,OAAO,OAAO,KAAK,gBAClC,IAAI,SAAS,KAAK,aAAa,OAAO,CACxC,CACJ;CACA,aAAa,OAAO,GAAG,wCAAwC,CAAC,EAE5D,UACA,MACA,YAEAA,aAA8B,UAAU,OAAO,KAAK,gBAClD,IAAI,YAAY,KAAK,aAAa,OAAO,CAC3C,CACJ;AACF;AAEA,IAAa,6BAAb,cAAgD,QAAQ,QAGtD,CAAC,CAAC,4CAA4C,CAAC,CAAC,CAAC;AAEnD,MAAa,SACX,QACG,MAAM,QAAQ,4BAA4B,KAAK,GAAG,CAAC"}
@@ -0,0 +1,60 @@
1
+ import * as Ref from "@confect/core/Ref";
2
+ import type { DefaultFunctionArgs, GenericActionCtx, GenericDataModel, GenericMutationCtx, GenericQueryCtx } from "convex/server";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Schema from "effect/Schema";
5
+ import type * as ActionRunner from "./ActionRunner.js";
6
+ import type * as MutationRunner from "./MutationRunner.js";
7
+ import type * as QueryRunner from "./QueryRunner.js";
8
+ declare const ComponentCallFailed_base: Schema.Class<ComponentCallFailed, Schema.TaggedStruct<"ComponentCallFailed", {
9
+ readonly component: Schema.String;
10
+ readonly method: Schema.String;
11
+ readonly cause: Schema.Defect;
12
+ }>, import("effect/Cause").YieldableError>;
13
+ /**
14
+ * An official component's method rejected. `cause` is the rejection as thrown.
15
+ */
16
+ export declare class ComponentCallFailed extends ComponentCallFailed_base {
17
+ }
18
+ declare const unsupported: unique symbol;
19
+ type Unsupported = typeof unsupported;
20
+ type Needs<Param> = [GenericActionCtx<GenericDataModel>] extends [Param] ? [GenericMutationCtx<GenericDataModel>] extends [Param] ? [GenericQueryCtx<GenericDataModel>] extends [Param] ? QueryRunner.QueryRunner : MutationRunner.MutationRunner : [GenericQueryCtx<GenericDataModel>] extends [Param] ? Unsupported : ActionRunner.ActionRunner : Unsupported;
21
+ type Method<Official> = {
22
+ [K in keyof Official & string]: Official[K] extends (ctx: infer Ctx, ...args: infer _Args) => Promise<unknown> ? Needs<Ctx> extends Unsupported ? never : K : never;
23
+ }[keyof Official & string];
24
+ type Call<F> = F extends (ctx: infer Ctx, ...args: infer Args) => Promise<infer A> ? (...args: Args) => Effect.Effect<A, never, Needs<Ctx>> : never;
25
+ type Lifted<Official> = <M extends Method<Official>>(method: M, ...args: Parameters<Call<Official[M]>>) => ReturnType<Call<Official[M]>>;
26
+ /**
27
+ * Lift official promise methods, deriving each capability from its ctx
28
+ * parameter. A rejection is caller misuse, a limit or a platform fault rather
29
+ * than a domain fact, so it dies.
30
+ */
31
+ export declare const make: <Official extends object>(component: string, official: Official) => Lifted<Official>;
32
+ /**
33
+ * A function reference with its encoded arguments, ready for an official method
34
+ * that takes both.
35
+ */
36
+ export interface Fn<R extends Ref.Any> {
37
+ readonly reference: Ref.FunctionReference<R>;
38
+ readonly args: DefaultFunctionArgs;
39
+ }
40
+ /**
41
+ * Choose whether an official component call forwards the caller's carrier.
42
+ */
43
+ export interface EncodeCallOptions {
44
+ /**
45
+ * Forward the caller's carrier to reserving mutations and actions. Use `none`
46
+ * when the component replays or compares the stored arguments.
47
+ */
48
+ readonly carrier: "forward" | "none";
49
+ }
50
+ /**
51
+ * Encode a ref's arguments through its codecs to the wire record an official
52
+ * method expects, with an explicit carrier policy.
53
+ */
54
+ export declare const encodeCall: <R extends Ref.Any>(ref: R, args: NoInfer<Ref.Args<R>>, options: EncodeCallOptions) => Effect.Effect<Fn<R>>;
55
+ /**
56
+ * Encode a callback's real field without fabricating the rest of its arguments.
57
+ */
58
+ export declare const encodeField: <R extends Ref.AnyConfect, K extends keyof Ref.Args<R> & keyof Ref.ArgsFields<R>>(ref: R, key: K, value: NoInfer<Ref.Args<R>[K]>) => Effect.Effect<unknown>;
59
+ export {};
60
+ //# sourceMappingURL=OfficialComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OfficialComponent.d.ts","sourceRoot":"","sources":["../src/OfficialComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAEvD,OAAO,KAAK,KAAK,cAAc,MAAM,qBAAqB,CAAC;AAE3D,OAAO,KAAK,KAAK,WAAW,MAAM,kBAAkB,CAAC;;;;;;AAGrD;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,wBAGxC;CAAG;AAEJ,OAAO,CAAC,MAAM,WAAW,EAAE,OAAO,MAAM,CAAC;AACzC,KAAK,WAAW,GAAG,OAAO,WAAW,CAAC;AACtC,KAAK,KAAK,CAAC,KAAK,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACpE,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACpD,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACjD,WAAW,CAAC,WAAW,GACvB,cAAc,CAAC,cAAc,GAC/B,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACjD,WAAW,GACX,YAAY,CAAC,YAAY,GAC7B,WAAW,CAAC;AAEhB,KAAK,MAAM,CAAC,QAAQ,IAAI;KACrB,CAAC,IAAI,MAAM,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,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G;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,GAAG,CAAC,GAAG,OACrC,CAAC,QACA,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WACjB,iBAAiB,KACzB,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAanB,CAAC;AAEJ;;GAEG;AACH,eAAO,MAAM,WAAW,GACtB,CAAC,SAAS,GAAG,CAAC,UAAU,EACxB,CAAC,SAAS,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,OAEhD,CAAC,OACD,CAAC,SACC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAC7B,MAAM,CAAC,MAAM,CAAC,OAAO,CAMvB,CAAC"}
@@ -0,0 +1,71 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { encodeArgs } from "./internal/reservedArgument.js";
3
+ import { ActionCtx } from "./ActionCtx.js";
4
+ import { MutationCtx } from "./MutationCtx.js";
5
+ import { QueryCtx } from "./QueryCtx.js";
6
+ import * as Ref from "@confect/core/Ref";
7
+ import * as Effect from "effect/Effect";
8
+ import * as Schema from "effect/Schema";
9
+ import * as Option from "effect/Option";
10
+ //#region src/OfficialComponent.ts
11
+ var OfficialComponent_exports = /* @__PURE__ */ __exportAll({
12
+ ComponentCallFailed: () => ComponentCallFailed,
13
+ encodeCall: () => encodeCall,
14
+ encodeField: () => encodeField,
15
+ make: () => make
16
+ });
17
+ /**
18
+ * An official component's method rejected. `cause` is the rejection as thrown.
19
+ */
20
+ var ComponentCallFailed = class extends Schema.TaggedError()("ComponentCallFailed", {
21
+ component: Schema.String,
22
+ method: Schema.String,
23
+ cause: Schema.Defect()
24
+ }) {};
25
+ /**
26
+ * Lift official promise methods, deriving each capability from its ctx
27
+ * parameter. A rejection is caller misuse, a limit or a platform fault rather
28
+ * than a domain fact, so it dies.
29
+ */
30
+ const make = (component, official) => {
31
+ const context = Effect.gen(function* () {
32
+ const action = yield* Effect.serviceOption(ActionCtx());
33
+ if (Option.isSome(action)) return action.value;
34
+ const mutation = yield* Effect.serviceOption(MutationCtx());
35
+ if (Option.isSome(mutation)) return mutation.value;
36
+ const query = yield* Effect.serviceOption(QueryCtx());
37
+ if (Option.isSome(query)) return query.value;
38
+ return yield* Effect.die(/* @__PURE__ */ new Error(`${component} called outside a Confect handler`));
39
+ });
40
+ return Effect.fn(`${component}.call`)(function* (method, ...args) {
41
+ const ctx = yield* context;
42
+ const invoke = official[method];
43
+ return yield* Effect.tryPromise({
44
+ try: () => invoke.call(official, ctx, ...args),
45
+ catch: (cause) => ComponentCallFailed.make({
46
+ component,
47
+ method,
48
+ cause
49
+ })
50
+ }).pipe(Effect.orDie);
51
+ });
52
+ };
53
+ /**
54
+ * Encode a ref's arguments through its codecs to the wire record an official
55
+ * method expects, with an explicit carrier policy.
56
+ */
57
+ const encodeCall = (ref, args, options) => (options.carrier === "forward" ? encodeArgs(ref, args) : Ref.encodeArgs(ref, args)).pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.Unknown))), Effect.map((encoded) => ({
58
+ reference: Ref.getFunctionReference(ref),
59
+ args: encoded
60
+ })), Effect.orDie);
61
+ /**
62
+ * Encode a callback's real field without fabricating the rest of its arguments.
63
+ */
64
+ const encodeField = (ref, key, value) => {
65
+ const fields = ref.args.fields;
66
+ return Schema.encodeUnknownEffect(fields[key])(value).pipe(Effect.orDie);
67
+ };
68
+ //#endregion
69
+ export { ComponentCallFailed, OfficialComponent_exports, encodeCall, encodeField, make };
70
+
71
+ //# sourceMappingURL=OfficialComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OfficialComponent.js","names":["ActionCtx.ActionCtx","MutationCtx.MutationCtx","QueryCtx.QueryCtx","ReservedArgument.encodeArgs"],"sources":["../src/OfficialComponent.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport type {\n DefaultFunctionArgs,\n GenericActionCtx,\n GenericDataModel,\n GenericMutationCtx,\n GenericQueryCtx,\n} from \"convex/server\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\nimport * as ActionCtx from \"./ActionCtx.js\";\nimport type * as ActionRunner from \"./ActionRunner.js\";\nimport * as MutationCtx from \"./MutationCtx.js\";\nimport type * as MutationRunner from \"./MutationRunner.js\";\nimport * as QueryCtx from \"./QueryCtx.js\";\nimport type * as QueryRunner from \"./QueryRunner.js\";\nimport * as ReservedArgument from \"./internal/reservedArgument.js\";\n\n/**\n * An official component's method rejected. `cause` is the rejection as thrown.\n */\nexport class ComponentCallFailed extends Schema.TaggedError<ComponentCallFailed>()(\n \"ComponentCallFailed\",\n { component: Schema.String, method: Schema.String, cause: Schema.Defect() },\n) {}\n\ndeclare const unsupported: unique symbol;\ntype Unsupported = typeof unsupported;\ntype Needs<Param> = [GenericActionCtx<GenericDataModel>] extends [Param]\n ? [GenericMutationCtx<GenericDataModel>] extends [Param]\n ? [GenericQueryCtx<GenericDataModel>] extends [Param]\n ? QueryRunner.QueryRunner\n : MutationRunner.MutationRunner\n : [GenericQueryCtx<GenericDataModel>] extends [Param]\n ? Unsupported\n : ActionRunner.ActionRunner\n : Unsupported;\n\ntype Method<Official> = {\n [K in keyof Official & string]: Official[K] extends (\n ctx: infer Ctx,\n ...args: infer _Args\n ) => Promise<unknown>\n ? Needs<Ctx> extends Unsupported\n ? never\n : K\n : never;\n}[keyof Official & string];\n\ntype Call<F> = F extends (\n ctx: infer Ctx,\n ...args: infer Args\n) => Promise<infer A>\n ? (...args: Args) => Effect.Effect<A, never, Needs<Ctx>>\n : never;\n\ntype Lifted<Official> = <M extends Method<Official>>(\n method: M,\n ...args: Parameters<Call<Official[M]>>\n) => ReturnType<Call<Official[M]>>;\n\n/**\n * Lift official promise methods, deriving each capability from its ctx\n * parameter. A rejection is caller misuse, a limit or a platform fault rather\n * than a domain fact, so it dies.\n */\nexport const make = <Official extends object>(\n component: string,\n official: Official,\n): Lifted<Official> => {\n const context = Effect.gen(function* () {\n const action = yield* Effect.serviceOption(\n ActionCtx.ActionCtx<GenericDataModel>(),\n );\n if (Option.isSome(action)) return action.value;\n const mutation = yield* Effect.serviceOption(\n MutationCtx.MutationCtx<GenericDataModel>(),\n );\n if (Option.isSome(mutation)) return mutation.value;\n const query = yield* Effect.serviceOption(\n QueryCtx.QueryCtx<GenericDataModel>(),\n );\n if (Option.isSome(query)) return query.value;\n return yield* Effect.die(\n new Error(`${component} called outside a Confect handler`),\n );\n });\n const call = Effect.fn(`${component}.call`)(function* (\n method: Method<Official>,\n ...args: unknown[]\n ) {\n const ctx = yield* context;\n // Method selects promise methods whose first argument accepts a native handler context.\n const invoke = official[method] as (\n native: typeof ctx,\n ...args: unknown[]\n ) => Promise<unknown>;\n return yield* Effect.tryPromise({\n try: () => invoke.call(official, ctx, ...args),\n catch: (cause) => ComponentCallFailed.make({ component, method, cause }),\n }).pipe(Effect.orDie);\n });\n // Confect installs the native ctx with the runner capability inferred by Needs.\n return call as unknown as Lifted<Official>;\n};\n\n/**\n * A function reference with its encoded arguments, ready for an official method\n * that takes both.\n */\nexport interface Fn<R extends Ref.Any> {\n readonly reference: Ref.FunctionReference<R>;\n readonly args: DefaultFunctionArgs;\n}\n\n/**\n * Choose whether an official component call forwards the caller's carrier.\n */\nexport interface EncodeCallOptions {\n /**\n * Forward the caller's carrier to reserving mutations and actions. Use `none`\n * when the component replays or compares the stored arguments.\n */\n readonly carrier: \"forward\" | \"none\";\n}\n\n/**\n * Encode a ref's arguments through its codecs to the wire record an official\n * method expects, with an explicit carrier policy.\n */\nexport const encodeCall = <R extends Ref.Any>(\n ref: R,\n args: NoInfer<Ref.Args<R>>,\n options: EncodeCallOptions,\n): Effect.Effect<Fn<R>> =>\n (options.carrier === \"forward\"\n ? ReservedArgument.encodeArgs(ref, args)\n : Ref.encodeArgs(ref, args)\n ).pipe(\n Effect.flatMap(\n Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.Unknown)),\n ),\n Effect.map((encoded) => ({\n reference: Ref.getFunctionReference(ref),\n args: encoded,\n })),\n Effect.orDie,\n );\n\n/**\n * Encode a callback's real field without fabricating the rest of its arguments.\n */\nexport const encodeField = <\n R extends Ref.AnyConfect,\n K extends keyof Ref.Args<R> & keyof Ref.ArgsFields<R>,\n>(\n ref: R,\n key: K,\n value: NoInfer<Ref.Args<R>[K]>,\n): Effect.Effect<unknown> => {\n const fields = ref.args.fields as Record<\n keyof Ref.ArgsFields<R>,\n Schema.Codec<unknown, unknown>\n >;\n return Schema.encodeUnknownEffect(fields[key])(value).pipe(Effect.orDie);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsBA,IAAa,sBAAb,cAAyC,OAAO,YAAiC,CAAC,CAChF,uBACA;CAAE,WAAW,OAAO;CAAQ,QAAQ,OAAO;CAAQ,OAAO,OAAO,OAAO;AAAE,CAC5E,CAAC,CAAC,CAAC;;;;;;AA0CH,MAAa,QACX,WACA,aACqB;CACrB,MAAM,UAAU,OAAO,IAAI,aAAa;EACtC,MAAM,SAAS,OAAO,OAAO,cAC3BA,UAAsC,CACxC;EACA,IAAI,OAAO,OAAO,MAAM,GAAG,OAAO,OAAO;EACzC,MAAM,WAAW,OAAO,OAAO,cAC7BC,YAA0C,CAC5C;EACA,IAAI,OAAO,OAAO,QAAQ,GAAG,OAAO,SAAS;EAC7C,MAAM,QAAQ,OAAO,OAAO,cAC1BC,SAAoC,CACtC;EACA,IAAI,OAAO,OAAO,KAAK,GAAG,OAAO,MAAM;EACvC,OAAO,OAAO,OAAO,oBACnB,IAAI,MAAM,GAAG,UAAU,kCAAkC,CAC3D;CACF,CAAC;CAiBD,OAhBa,OAAO,GAAG,GAAG,UAAU,MAAM,CAAC,CAAC,WAC1C,QACA,GAAG,MACH;EACA,MAAM,MAAM,OAAO;EAEnB,MAAM,SAAS,SAAS;EAIxB,OAAO,OAAO,OAAO,WAAW;GAC9B,WAAW,OAAO,KAAK,UAAU,KAAK,GAAG,IAAI;GAC7C,QAAQ,UAAU,oBAAoB,KAAK;IAAE;IAAW;IAAQ;GAAM,CAAC;EACzE,CAAC,CAAC,CAAC,KAAK,OAAO,KAAK;CACtB,CAEU;AACZ;;;;;AA0BA,MAAa,cACX,KACA,MACA,aAEC,QAAQ,YAAY,YACjBC,WAA4B,KAAK,IAAI,IACrC,IAAI,WAAW,KAAK,IAAI,EAAA,CAC1B,KACA,OAAO,QACL,OAAO,oBAAoB,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,CAAC,CACzE,GACA,OAAO,KAAK,aAAa;CACvB,WAAW,IAAI,qBAAqB,GAAG;CACvC,MAAM;AACR,EAAE,GACF,OAAO,KACT;;;;AAKF,MAAa,eAIX,KACA,KACA,UAC2B;CAC3B,MAAM,SAAS,IAAI,KAAK;CAIxB,OAAO,OAAO,oBAAoB,OAAO,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,OAAO,KAAK;AACzE"}
@@ -4,11 +4,11 @@ import { make as make$1 } from "./OrderedQuery.js";
4
4
  import { builder } from "./QueryStreamIndexRange.js";
5
5
  import { fromReflection } from "./QueryStream.js";
6
6
  import * as Effect from "effect/Effect";
7
+ import * as Predicate from "effect/Predicate";
8
+ import * as Array from "effect/Array";
7
9
  import * as Schema from "effect/Schema";
8
10
  import { pipe } from "effect/Function";
9
11
  import * as Option from "effect/Option";
10
- import * as Array from "effect/Array";
11
- import * as Predicate from "effect/Predicate";
12
12
  import * as Result from "effect/Result";
13
13
  //#region src/QueryInitializer.ts
14
14
  var QueryInitializer_exports = /* @__PURE__ */ __exportAll({
@@ -1,10 +1,10 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import { MutationTransactionContext } from "./MutationTransactionContext.js";
3
3
  import { QueryTransactionContext } from "./QueryTransactionContext.js";
4
- import * as Context from "effect/Context";
5
- import * as Layer from "effect/Layer";
6
4
  import * as Ref from "@confect/core/Ref";
5
+ import * as Context from "effect/Context";
7
6
  import * as Effect from "effect/Effect";
7
+ import * as Layer from "effect/Layer";
8
8
  //#region src/QueryRunner.ts
9
9
  var QueryRunner_exports = /* @__PURE__ */ __exportAll({
10
10
  QueryRunner: () => QueryRunner,