@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.
Files changed (190) hide show
  1. package/CHANGELOG.md +299 -4
  2. package/dist/ActionCtx.d.ts +4 -11
  3. package/dist/ActionCtx.d.ts.map +1 -1
  4. package/dist/ActionCtx.js +1 -1
  5. package/dist/ActionCtx.js.map +1 -1
  6. package/dist/ActionRunner.d.ts +8 -13
  7. package/dist/ActionRunner.d.ts.map +1 -1
  8. package/dist/ActionRunner.js +4 -3
  9. package/dist/ActionRunner.js.map +1 -1
  10. package/dist/Auth.d.ts +17 -23
  11. package/dist/Auth.d.ts.map +1 -1
  12. package/dist/Auth.js +5 -1
  13. package/dist/Auth.js.map +1 -1
  14. package/dist/BlobNotFoundError.d.ts +6 -12
  15. package/dist/BlobNotFoundError.d.ts.map +1 -1
  16. package/dist/BlobNotFoundError.js +1 -1
  17. package/dist/BlobNotFoundError.js.map +1 -1
  18. package/dist/ConvexConfigProvider.d.ts +2 -9
  19. package/dist/ConvexConfigProvider.d.ts.map +1 -1
  20. package/dist/ConvexConfigProvider.js +6 -1
  21. package/dist/ConvexConfigProvider.js.map +1 -1
  22. package/dist/CronJob.d.ts +12 -19
  23. package/dist/CronJob.d.ts.map +1 -1
  24. package/dist/CronJob.js +1 -1
  25. package/dist/CronJob.js.map +1 -1
  26. package/dist/CronJobs.d.ts +11 -18
  27. package/dist/CronJobs.d.ts.map +1 -1
  28. package/dist/CronJobs.js +11 -4
  29. package/dist/CronJobs.js.map +1 -1
  30. package/dist/DataModel.d.ts +24 -29
  31. package/dist/DataModel.d.ts.map +1 -1
  32. package/dist/DatabaseReader.d.ts +4323 -64
  33. package/dist/DatabaseReader.d.ts.map +1 -1
  34. package/dist/DatabaseReader.js +6 -6
  35. package/dist/DatabaseReader.js.map +1 -1
  36. package/dist/DatabaseSchema.d.ts +38 -130
  37. package/dist/DatabaseSchema.d.ts.map +1 -1
  38. package/dist/DatabaseSchema.js +20 -30
  39. package/dist/DatabaseSchema.js.map +1 -1
  40. package/dist/DatabaseWriter.d.ts +38 -42
  41. package/dist/DatabaseWriter.d.ts.map +1 -1
  42. package/dist/DatabaseWriter.js +8 -5
  43. package/dist/DatabaseWriter.js.map +1 -1
  44. package/dist/Document.d.ts +28 -37
  45. package/dist/Document.d.ts.map +1 -1
  46. package/dist/Document.js +5 -1
  47. package/dist/Document.js.map +1 -1
  48. package/dist/FunctionImpl.d.ts +30 -29
  49. package/dist/FunctionImpl.d.ts.map +1 -1
  50. package/dist/FunctionImpl.js +25 -14
  51. package/dist/FunctionImpl.js.map +1 -1
  52. package/dist/GroupImpl.d.ts +45 -41
  53. package/dist/GroupImpl.d.ts.map +1 -1
  54. package/dist/GroupImpl.js +42 -35
  55. package/dist/GroupImpl.js.map +1 -1
  56. package/dist/Handler.d.ts +34 -40
  57. package/dist/Handler.d.ts.map +1 -1
  58. package/dist/HttpApi.d.ts +21 -25
  59. package/dist/HttpApi.d.ts.map +1 -1
  60. package/dist/HttpApi.js +11 -6
  61. package/dist/HttpApi.js.map +1 -1
  62. package/dist/MutationCtx.d.ts +4 -11
  63. package/dist/MutationCtx.d.ts.map +1 -1
  64. package/dist/MutationCtx.js +1 -1
  65. package/dist/MutationCtx.js.map +1 -1
  66. package/dist/MutationRunner.d.ts +8 -13
  67. package/dist/MutationRunner.d.ts.map +1 -1
  68. package/dist/MutationRunner.js +4 -3
  69. package/dist/MutationRunner.js.map +1 -1
  70. package/dist/OrderedQuery.d.ts +16 -21
  71. package/dist/OrderedQuery.d.ts.map +1 -1
  72. package/dist/OrderedQuery.js +4 -1
  73. package/dist/OrderedQuery.js.map +1 -1
  74. package/dist/QueryCtx.d.ts +4 -11
  75. package/dist/QueryCtx.d.ts.map +1 -1
  76. package/dist/QueryCtx.js +1 -1
  77. package/dist/QueryCtx.js.map +1 -1
  78. package/dist/QueryInitializer.d.ts +34 -39
  79. package/dist/QueryInitializer.d.ts.map +1 -1
  80. package/dist/QueryInitializer.js +5 -1
  81. package/dist/QueryInitializer.js.map +1 -1
  82. package/dist/QueryRunner.d.ts +8 -13
  83. package/dist/QueryRunner.d.ts.map +1 -1
  84. package/dist/QueryRunner.js +4 -3
  85. package/dist/QueryRunner.js.map +1 -1
  86. package/dist/RegisteredConvexFunction.d.ts +1107 -60
  87. package/dist/RegisteredConvexFunction.d.ts.map +1 -1
  88. package/dist/RegisteredConvexFunction.js +14 -9
  89. package/dist/RegisteredConvexFunction.js.map +1 -1
  90. package/dist/RegisteredFunction.d.ts +48 -64
  91. package/dist/RegisteredFunction.d.ts.map +1 -1
  92. package/dist/RegisteredFunction.js +9 -5
  93. package/dist/RegisteredFunction.js.map +1 -1
  94. package/dist/RegisteredFunctions.d.ts +48 -26
  95. package/dist/RegisteredFunctions.d.ts.map +1 -1
  96. package/dist/RegisteredFunctions.js +22 -9
  97. package/dist/RegisteredFunctions.js.map +1 -1
  98. package/dist/RegisteredNodeFunction.d.ts +4 -14
  99. package/dist/RegisteredNodeFunction.d.ts.map +1 -1
  100. package/dist/RegisteredNodeFunction.js +5 -4
  101. package/dist/RegisteredNodeFunction.js.map +1 -1
  102. package/dist/RegistryItem.d.ts +17 -27
  103. package/dist/RegistryItem.d.ts.map +1 -1
  104. package/dist/RegistryItem.js +1 -1
  105. package/dist/RegistryItem.js.map +1 -1
  106. package/dist/Scheduler.d.ts +16 -20
  107. package/dist/Scheduler.d.ts.map +1 -1
  108. package/dist/Scheduler.js +10 -6
  109. package/dist/Scheduler.js.map +1 -1
  110. package/dist/SchemaToValidator.d.ts +71 -64
  111. package/dist/SchemaToValidator.d.ts.map +1 -1
  112. package/dist/SchemaToValidator.js +15 -3
  113. package/dist/SchemaToValidator.js.map +1 -1
  114. package/dist/StorageActionWriter.d.ts +21 -28
  115. package/dist/StorageActionWriter.d.ts.map +1 -1
  116. package/dist/StorageActionWriter.js +4 -1
  117. package/dist/StorageActionWriter.js.map +1 -1
  118. package/dist/StorageReader.d.ts +14 -21
  119. package/dist/StorageReader.d.ts.map +1 -1
  120. package/dist/StorageReader.js +5 -1
  121. package/dist/StorageReader.js.map +1 -1
  122. package/dist/StorageWriter.d.ts +16 -23
  123. package/dist/StorageWriter.d.ts.map +1 -1
  124. package/dist/StorageWriter.js +4 -1
  125. package/dist/StorageWriter.js.map +1 -1
  126. package/dist/Table.d.ts +204 -197
  127. package/dist/Table.d.ts.map +1 -1
  128. package/dist/Table.js +72 -62
  129. package/dist/Table.js.map +1 -1
  130. package/dist/TableInfo.d.ts +35 -41
  131. package/dist/TableInfo.d.ts.map +1 -1
  132. package/dist/VectorSearch.d.ts +30 -35
  133. package/dist/VectorSearch.d.ts.map +1 -1
  134. package/dist/VectorSearch.js +3 -1
  135. package/dist/VectorSearch.js.map +1 -1
  136. package/dist/index.d.ts +35 -36
  137. package/dist/index.d.ts.map +1 -0
  138. package/dist/index.js +4 -5
  139. package/dist/internal/utils.d.ts +9 -11
  140. package/dist/internal/utils.d.ts.map +1 -1
  141. package/dist/internal/utils.js +3 -1
  142. package/dist/internal/utils.js.map +1 -1
  143. package/dist/node.d.ts +2 -2
  144. package/dist/node.d.ts.map +1 -0
  145. package/dist/tsconfig.src.tsbuildinfo +1 -0
  146. package/package.json +50 -59
  147. package/src/ActionCtx.ts +1 -1
  148. package/src/ActionRunner.ts +2 -1
  149. package/src/Auth.ts +5 -1
  150. package/src/BlobNotFoundError.ts +1 -1
  151. package/src/ConvexConfigProvider.ts +6 -8
  152. package/src/CronJob.ts +1 -1
  153. package/src/CronJobs.ts +8 -10
  154. package/src/DatabaseReader.ts +18 -21
  155. package/src/DatabaseSchema.ts +38 -98
  156. package/src/DatabaseWriter.ts +13 -6
  157. package/src/Document.ts +5 -1
  158. package/src/FunctionImpl.ts +36 -44
  159. package/src/GroupImpl.ts +54 -81
  160. package/src/HttpApi.ts +8 -9
  161. package/src/MutationCtx.ts +1 -1
  162. package/src/MutationRunner.ts +2 -1
  163. package/src/OrderedQuery.ts +5 -1
  164. package/src/QueryCtx.ts +1 -1
  165. package/src/QueryInitializer.ts +15 -3
  166. package/src/QueryRunner.ts +2 -1
  167. package/src/RegisteredConvexFunction.ts +11 -7
  168. package/src/RegisteredFunction.ts +5 -1
  169. package/src/RegisteredFunctions.ts +69 -93
  170. package/src/RegisteredNodeFunction.ts +7 -6
  171. package/src/RegistryItem.ts +1 -1
  172. package/src/Scheduler.ts +5 -1
  173. package/src/SchemaToValidator.ts +14 -16
  174. package/src/StorageActionWriter.ts +4 -1
  175. package/src/StorageReader.ts +5 -1
  176. package/src/StorageWriter.ts +4 -1
  177. package/src/Table.ts +253 -132
  178. package/src/VectorSearch.ts +3 -1
  179. package/src/index.ts +0 -1
  180. package/src/internal/utils.ts +3 -1
  181. package/dist/Api.d.ts +0 -30
  182. package/dist/Api.d.ts.map +0 -1
  183. package/dist/Api.js +0 -26
  184. package/dist/Api.js.map +0 -1
  185. package/dist/GroupPath.d.ts +0 -8
  186. package/dist/GroupPath.d.ts.map +0 -1
  187. package/dist/GroupPath.js +0 -10
  188. package/dist/GroupPath.js.map +0 -1
  189. package/src/Api.ts +0 -75
  190. package/src/GroupPath.ts +0 -43
package/package.json CHANGED
@@ -1,47 +1,11 @@
1
1
  {
2
2
  "name": "@confect/server",
3
- "version": "9.0.0-next.0",
4
3
  "description": "Backend bindings to the Convex platform",
5
- "repository": {
6
- "type": "git",
7
- "url": "https://github.com/rjdellecese/confect.git"
8
- },
4
+ "version": "9.0.0-next.10",
5
+ "author": "RJ Dellecese",
9
6
  "bugs": {
10
7
  "url": "https://github.com/rjdellecese/confect/issues"
11
8
  },
12
- "homepage": "https://confect.dev",
13
- "sideEffects": false,
14
- "type": "module",
15
- "files": [
16
- "CHANGELOG.md",
17
- "LICENSE",
18
- "README.md",
19
- "dist",
20
- "package.json",
21
- "src"
22
- ],
23
- "exports": {
24
- ".": {
25
- "types": "./dist/index.d.ts",
26
- "default": "./dist/index.js"
27
- },
28
- "./*": {
29
- "types": "./dist/*.d.ts",
30
- "default": "./dist/*.js"
31
- },
32
- "./package.json": "./package.json",
33
- "./internal/*": null,
34
- "./node": {
35
- "types": "./dist/node.d.ts",
36
- "default": "./dist/node.js"
37
- }
38
- },
39
- "keywords": [
40
- "effect",
41
- "convex"
42
- ],
43
- "author": "RJ Dellecese",
44
- "license": "ISC",
45
9
  "devDependencies": {
46
10
  "@ark/attest": "0.56.0",
47
11
  "@effect/cluster": "0.58.2",
@@ -51,50 +15,77 @@
51
15
  "@effect/sql": "0.51.1",
52
16
  "@effect/vitest": "0.29.0",
53
17
  "@effect/workflow": "0.18.1",
54
- "@eslint/js": "10.0.1",
55
18
  "@swc/jest": "0.2.39",
56
19
  "@types/node": "25.3.3",
57
20
  "@vitest/coverage-v8": "3.2.4",
58
21
  "convex-test": "0.0.50",
59
22
  "dotenv": "17.3.1",
60
23
  "effect": "3.21.2",
61
- "eslint": "10.0.2",
62
- "prettier": "3.8.1",
63
24
  "tsdown": "0.20.3",
64
25
  "tsx": "4.21.0",
65
26
  "typescript": "5.9.3",
66
- "typescript-eslint": "8.56.1",
67
27
  "vite": "7.3.1",
68
28
  "vite-tsconfig-paths": "6.1.1",
69
29
  "vitest": "3.2.4"
70
30
  },
31
+ "engines": {
32
+ "node": ">=22"
33
+ },
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "default": "./dist/index.js"
38
+ },
39
+ "./*": {
40
+ "types": "./dist/*.d.ts",
41
+ "default": "./dist/*.js"
42
+ },
43
+ "./package.json": "./package.json",
44
+ "./internal/*": null,
45
+ "./node": {
46
+ "types": "./dist/node.d.ts",
47
+ "default": "./dist/node.js"
48
+ }
49
+ },
50
+ "files": [
51
+ "CHANGELOG.md",
52
+ "LICENSE",
53
+ "README.md",
54
+ "dist",
55
+ "package.json",
56
+ "src"
57
+ ],
58
+ "homepage": "https://confect.dev",
59
+ "keywords": [
60
+ "convex",
61
+ "effect"
62
+ ],
63
+ "license": "ISC",
64
+ "main": "./dist/index.js",
65
+ "module": "./dist/index.js",
71
66
  "peerDependencies": {
72
67
  "@effect/platform": "^0.96.1",
73
68
  "@effect/platform-node": "^0.106.0",
74
69
  "convex": "1.39.1",
75
70
  "effect": "^3.21.2",
76
- "@confect/core": "^9.0.0-next.0"
71
+ "@confect/core": "^9.0.0-next.10"
77
72
  },
78
- "engines": {
79
- "node": ">=22",
80
- "pnpm": ">=10"
73
+ "repository": {
74
+ "type": "git",
75
+ "url": "https://github.com/rjdellecese/confect.git"
81
76
  },
82
- "main": "./dist/index.js",
83
- "module": "./dist/index.js",
77
+ "sideEffects": false,
78
+ "type": "module",
84
79
  "types": "./dist/index.d.ts",
85
80
  "scripts": {
86
- "build": "tsdown --config-loader unrun",
87
- "dev": "tsdown --watch",
81
+ "bench": "tsx test/SchemaToValidator.bench.ts && tsx test/Document.bench.ts",
82
+ "clean": "rm -rf dist coverage node_modules",
83
+ "codegen:local-backend": "cd test/local-backend/fixtures && pnpm confect codegen && CONVEX_AGENT_MODE=anonymous pnpm convex dev --once --typecheck=disable --tail-logs=disable",
84
+ "codegen:mock-backend": "cd test/mock-backend/fixtures && pnpm confect codegen && CONVEX_AGENT_MODE=anonymous pnpm convex dev --once --typecheck=disable --tail-logs=disable",
85
+ "dev": "tsdown --watch --config-loader unrun",
88
86
  "test": "vitest run",
89
- "test:mock-backend": "vitest run --config vitest.mock-backend.config.ts",
90
87
  "test:local-backend": "vitest run --config vitest.local-backend.config.ts",
91
- "codegen:mock-backend": "cd test/mock-backend/fixtures && pnpm confect codegen && CONVEX_AGENT_MODE=anonymous pnpm convex dev --once --typecheck=disable --tail-logs=disable",
92
- "codegen:local-backend": "cd test/local-backend/fixtures && pnpm confect codegen && CONVEX_AGENT_MODE=anonymous pnpm convex dev --once --typecheck=disable --tail-logs=disable",
93
- "typecheck": "tsc --noEmit --project tsconfig.json",
94
- "fix": "prettier --write . && eslint --fix . --max-warnings=0",
95
- "format": "prettier --check .",
96
- "lint": "eslint . --max-warnings=0",
97
- "bench": "tsx test/SchemaToValidator.bench.ts && tsx test/Document.bench.ts",
98
- "clean": "rm -rf dist coverage node_modules"
88
+ "test:mock-backend": "vitest run --config vitest.mock-backend.config.ts",
89
+ "typecheck": "tsc -b tsconfig.src.json"
99
90
  }
100
91
  }
package/src/ActionCtx.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { GenericActionCtx, GenericDataModel } from "convex/server";
2
- import { Context } from "effect";
2
+ import * as Context from "effect/Context";
3
3
 
4
4
  export const ActionCtx = <DataModel extends GenericDataModel>() =>
5
5
  Context.GenericTag<GenericActionCtx<DataModel>>("@confect/server/ActionCtx");
@@ -1,7 +1,8 @@
1
1
  import * as Ref from "@confect/core/Ref";
2
2
  import { type GenericActionCtx } from "convex/server";
3
3
  import type { ParseResult, Effect } from "effect";
4
- import { Context, Layer } from "effect";
4
+ import * as Context from "effect/Context";
5
+ import * as Layer from "effect/Layer";
5
6
 
6
7
  const make =
7
8
  (runAction: GenericActionCtx<any>["runAction"]) =>
package/src/Auth.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import type { Auth as ConvexAuth } from "convex/server";
2
- import { Effect, flow, Layer, Option, Schema } from "effect";
2
+ import { flow } from "effect/Function";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Layer from "effect/Layer";
5
+ import * as Option from "effect/Option";
6
+ import * as Schema from "effect/Schema";
3
7
 
4
8
  const make = (auth: ConvexAuth) => ({
5
9
  getUserIdentity: Effect.promise(() => auth.getUserIdentity()).pipe(
@@ -1,4 +1,4 @@
1
- import { Schema } from "effect";
1
+ import * as Schema from "effect/Schema";
2
2
 
3
3
  export class BlobNotFoundError extends Schema.TaggedError<BlobNotFoundError>()(
4
4
  "BlobNotFoundError",
@@ -1,11 +1,9 @@
1
- import {
2
- Array,
3
- ConfigError,
4
- ConfigProvider,
5
- ConfigProviderPathPatch,
6
- Effect,
7
- pipe,
8
- } from "effect";
1
+ import { pipe } from "effect/Function";
2
+ import * as Array from "effect/Array";
3
+ import * as ConfigError from "effect/ConfigError";
4
+ import * as ConfigProvider from "effect/ConfigProvider";
5
+ import * as ConfigProviderPathPatch from "effect/ConfigProviderPathPatch";
6
+ import * as Effect from "effect/Effect";
9
7
 
10
8
  declare const process: { env: Record<string, string | undefined> };
11
9
 
package/src/CronJob.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Ref } from "@confect/core";
2
2
  import type { Cron, Duration } from "effect";
3
- import { Predicate } from "effect";
3
+ import * as Predicate from "effect/Predicate";
4
4
 
5
5
  export const TypeId = "@confect/server/CronJob";
6
6
  export type TypeId = typeof TypeId;
package/src/CronJobs.ts CHANGED
@@ -1,16 +1,14 @@
1
1
  import { Ref } from "@confect/core";
2
2
  import type { CronJob as ConvexCronJob } from "convex/server";
3
3
  import { cronJobs as makeConvexCrons, type Crons } from "convex/server";
4
- import {
5
- Array,
6
- Cron,
7
- Duration,
8
- Match,
9
- Order,
10
- pipe,
11
- Predicate,
12
- Record,
13
- } from "effect";
4
+ import { pipe } from "effect/Function";
5
+ import * as Array from "effect/Array";
6
+ import * as Cron from "effect/Cron";
7
+ import * as Duration from "effect/Duration";
8
+ import * as Match from "effect/Match";
9
+ import * as Order from "effect/Order";
10
+ import * as Predicate from "effect/Predicate";
11
+ import * as Record from "effect/Record";
14
12
  import type * as CronJob from "./CronJob";
15
13
 
16
14
  export const TypeId = "@confect/server/CronJobs";
@@ -1,7 +1,8 @@
1
1
  import type { GenericDatabaseReader } from "convex/server";
2
- import { Array, Context, Layer } from "effect";
2
+ import * as Context from "effect/Context";
3
+ import * as Layer from "effect/Layer";
3
4
  import type { BaseDatabaseReader } from "@confect/core/Types";
4
- import * as DatabaseSchema from "./DatabaseSchema";
5
+ import type * as DatabaseSchema from "./DatabaseSchema";
5
6
  import type * as DataModel from "./DataModel";
6
7
  import * as QueryInitializer from "./QueryInitializer";
7
8
  import * as Table from "./Table";
@@ -13,35 +14,31 @@ export const make = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(
13
14
  >,
14
15
  ) => {
15
16
  type Tables = DatabaseSchema.Tables<DatabaseSchema_>;
16
- type IncludedTables = DatabaseSchema.IncludeSystemTables<Tables>;
17
- const extendedTables = DatabaseSchema.extendWithSystemTables(
18
- databaseSchema.tables as Table.TablesRecord<Tables>,
19
- );
17
+ type IncludedTables = Tables | Table.SystemTables;
20
18
 
21
19
  return {
22
20
  table: <const TableName extends Table.Name<IncludedTables>>(
23
21
  tableName: TableName,
24
22
  ) => {
25
- const table = Object.values(extendedTables).find(
26
- (def) => def.name === tableName,
27
- ) as Table.WithName<IncludedTables, TableName>;
23
+ const isSystem = Object.hasOwn(Table.systemTables, tableName);
28
24
 
29
- const baseDatabaseReader: BaseDatabaseReader<any> = Array.some(
30
- Object.values(Table.systemTables),
31
- (systemTableDef) => systemTableDef.name === tableName,
32
- )
33
- ? ({
25
+ const baseDatabaseReader: BaseDatabaseReader<any> = isSystem
26
+ ? {
34
27
  get: convexDatabaseReader.system.get,
35
28
  query: convexDatabaseReader.system.query,
36
- } as BaseDatabaseReader<
37
- DataModel.ToConvex<DataModel.FromTables<Table.SystemTables>>
38
- >)
39
- : ({
29
+ }
30
+ : {
40
31
  get: convexDatabaseReader.get,
41
32
  query: convexDatabaseReader.query,
42
- } as BaseDatabaseReader<
43
- DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>
44
- >);
33
+ };
34
+
35
+ const table = (
36
+ isSystem
37
+ ? (Table.systemTables as Record<string, Table.AnyWithProps>)[
38
+ tableName
39
+ ]
40
+ : databaseSchema.tables[tableName]
41
+ ) as Table.WithName<IncludedTables, TableName>;
45
42
 
46
43
  return QueryInitializer.make<IncludedTables, TableName>(
47
44
  tableName,
@@ -1,10 +1,5 @@
1
- import type { Expand, GenericSchema } from "convex/server";
2
- import {
3
- defineSchema as defineConvexSchema,
4
- type SchemaDefinition,
5
- } from "convex/server";
6
- import { Array, pipe, Predicate, Record } from "effect";
7
- import * as Table from "./Table";
1
+ import * as Predicate from "effect/Predicate";
2
+ import type * as Table from "./Table";
8
3
 
9
4
  export const TypeId = "@confect/server/DatabaseSchema";
10
5
  export type TypeId = typeof TypeId;
@@ -17,29 +12,25 @@ export const isDatabaseSchema = (u: unknown): u is Any =>
17
12
  Predicate.hasProperty(u, TypeId);
18
13
 
19
14
  /**
20
- * A schema definition tracks the schema and its Convex schema definition.
15
+ * A schema definition holding a record of bound `Table`s keyed by table
16
+ * name. Codegen emits a single static `DatabaseSchema.make({ ... })` call;
17
+ * laziness lives entirely on each `Table` (its `Fields`, `Doc`, and
18
+ * `tableDefinition` are lazy memoised getters), so this layer is a plain
19
+ * record indirection with no module-loading or async machinery.
21
20
  */
22
21
  export interface DatabaseSchema<Tables_ extends Table.AnyWithProps = never> {
23
22
  readonly [TypeId]: TypeId;
24
- readonly tables: Table.TablesRecord<Tables_>;
25
- readonly convexSchemaDefinition: SchemaDefinition<
26
- ConvexDatabaseSchemaFromTables<Tables_>,
27
- true
28
- >;
29
-
30
- /**
31
- * Add a table definition to the schema.
32
- */
33
- addTable<TableDef extends Table.AnyWithProps>(
34
- table: TableDef,
35
- ): DatabaseSchema<Tables_ | TableDef>;
23
+ readonly tables: {
24
+ readonly [TableName in Table.Name<Tables_>]: Table.WithName<
25
+ Tables_,
26
+ TableName
27
+ >;
28
+ };
36
29
  }
37
30
 
38
31
  export interface AnyWithProps {
39
32
  readonly [TypeId]: TypeId;
40
33
  readonly tables: Record<string, Table.AnyWithProps>;
41
- readonly convexSchemaDefinition: SchemaDefinition<GenericSchema, true>;
42
- addTable<TableDef extends Table.AnyWithProps>(table: TableDef): AnyWithProps;
43
34
  }
44
35
 
45
36
  export type Tables<DatabaseSchema_ extends AnyWithProps> =
@@ -53,82 +44,31 @@ export type TableNames<DatabaseSchema_ extends AnyWithProps> = Table.Name<
53
44
  export type TableWithName<
54
45
  DatabaseSchema_ extends AnyWithProps,
55
46
  TableName extends TableNames<DatabaseSchema_>,
56
- > = Extract<Tables<DatabaseSchema_>, { readonly name: TableName }>;
57
-
58
- const Proto = {
59
- [TypeId]: TypeId,
60
-
61
- addTable<TableDef extends Table.AnyWithProps>(
62
- this: DatabaseSchema<Table.AnyWithProps>,
63
- table: TableDef,
64
- ) {
65
- const tablesArray = Object.values(this.tables) as Table.AnyWithProps[];
66
- const newTablesArray = [...tablesArray, table];
67
-
68
- return makeProto({
69
- tables: Record.set(this.tables, table.name, table),
70
- convexSchemaDefinition: pipe(
71
- newTablesArray,
72
- Array.map(
73
- ({ name, tableDefinition }) => [name, tableDefinition] as const,
74
- ),
75
- Record.fromEntries,
76
- defineConvexSchema,
77
- ),
78
- });
79
- },
80
- };
81
-
82
- const makeProto = <Tables_ extends Table.AnyWithProps>({
83
- tables,
84
- convexSchemaDefinition,
85
- }: {
86
- tables: Record.ReadonlyRecord<string, Tables_>;
87
- convexSchemaDefinition: SchemaDefinition<GenericSchema, true>;
88
- }): DatabaseSchema<Tables_> =>
89
- Object.assign(Object.create(Proto), {
90
- tables,
91
- convexSchemaDefinition,
92
- });
47
+ > = Extract<Tables<DatabaseSchema_>, { readonly tableName: TableName }>;
93
48
 
94
49
  /**
95
- * Create an empty schema definition. Add tables incrementally via `addTable`.
50
+ * Construct a `DatabaseSchema` from a record of bound `Table`s. The empty
51
+ * case is `DatabaseSchema.make({})`. The `Tables_` union is inferred from
52
+ * the value record's values, so codegen-emitted calls of the form
53
+ * `DatabaseSchema.make({ notes, tags, users })` do not need an explicit
54
+ * type argument.
55
+ *
56
+ * Invariant: each record **key must equal its value's `tableName`**. The
57
+ * record is stored verbatim and later read by key (`databaseSchema.tables[
58
+ * tableName]` in `DatabaseReader`/`DatabaseWriter`), so a key that diverges
59
+ * from the bound table's name would make those lookups silently miss. The
60
+ * type signature does not enforce this — codegen upholds it by deriving both
61
+ * the key and the table name from the same filename (and the shorthand
62
+ * `{ notes, tags, users }` form it emits makes them identical by
63
+ * construction). Hand-written calls must preserve it.
96
64
  */
97
- export const make = (): DatabaseSchema<never> =>
98
- makeProto({
99
- tables: Record.empty(),
100
- convexSchemaDefinition: defineConvexSchema({}),
101
- });
102
-
103
- export type ConvexDatabaseSchemaFromTables<Tables_ extends Table.AnyWithProps> =
104
- Expand<{
105
- [TableName in Table.Name<Tables_> & string]: Table.WithName<
106
- Tables_,
107
- TableName
108
- >["tableDefinition"];
109
- }>;
110
-
111
- // System tables
112
-
113
- export const systemSchema = make()
114
- .addTable(Table.scheduledFunctionsTable)
115
- .addTable(Table.storageTable);
116
-
117
- export const extendWithSystemTables = <Tables_ extends Table.AnyWithProps>(
118
- tables: Table.TablesRecord<Tables_>,
119
- ): ExtendWithSystemTables<Tables_> =>
120
- ({
121
- ...tables,
122
- ...Table.systemTables,
123
- }) as ExtendWithSystemTables<Tables_>;
124
-
125
- export type ExtendWithSystemTables<Tables_ extends Table.AnyWithProps> =
126
- Table.TablesRecord<Tables_ | Table.SystemTables>;
127
-
128
- export type IncludeSystemTables<Tables_ extends Table.AnyWithProps> =
129
- | Tables_
130
- | Table.SystemTables extends infer T
131
- ? T extends Table.AnyWithProps
132
- ? T
133
- : never
134
- : never;
65
+ export const make = <
66
+ const TablesRecord extends Record<string, Table.AnyWithProps>,
67
+ >(
68
+ tables: TablesRecord,
69
+ ): DatabaseSchema<TablesRecord[keyof TablesRecord]> => ({
70
+ [TypeId]: TypeId,
71
+ tables: tables as unknown as DatabaseSchema<
72
+ TablesRecord[keyof TablesRecord]
73
+ >["tables"],
74
+ });
@@ -6,7 +6,11 @@ import type {
6
6
  WithoutSystemFields,
7
7
  } from "convex/server";
8
8
  import type { GenericId } from "convex/values";
9
- import { Context, Effect, Layer, pipe, Record } from "effect";
9
+ import { pipe } from "effect/Function";
10
+ import * as Context from "effect/Context";
11
+ import * as Effect from "effect/Effect";
12
+ import * as Layer from "effect/Layer";
13
+ import * as Record from "effect/Record";
10
14
  import type * as DatabaseSchema from "./DatabaseSchema";
11
15
  import type * as DataModel from "./DataModel";
12
16
  import type { DocumentByName as DocumentByName_ } from "./DataModel";
@@ -22,14 +26,13 @@ export const make = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(
22
26
  >,
23
27
  ) => {
24
28
  type DataModel_ = DataModel.FromSchema<DatabaseSchema_>;
25
- const tables = databaseSchema.tables as Record<string, Table.AnyWithProps>;
26
29
 
27
30
  const table = <const TableName extends DataModel.TableNames<DataModel_>>(
28
31
  tableName: TableName,
29
32
  ) => {
30
- const tableDef = tables[tableName]!;
31
- const tableSchema = tableDef.Fields as TableInfo.TableSchema<
32
- DataModel.TableInfoWithName_<DataModel_, TableName>
33
+ const tableDef = databaseSchema.tables[tableName] as Table.WithName<
34
+ DatabaseSchema.Tables<DatabaseSchema_>,
35
+ TableName
33
36
  >;
34
37
 
35
38
  const insert = (
@@ -63,6 +66,10 @@ export const make = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(
63
66
  >,
64
67
  ) =>
65
68
  Effect.gen(function* () {
69
+ const tableSchema = tableDef.Fields as TableInfo.TableSchema<
70
+ DataModel.TableInfoWithName_<DataModel_, TableName>
71
+ >;
72
+
66
73
  const originalDecodedDoc = yield* QueryInitializer.getById(
67
74
  tableName,
68
75
  convexDatabaseWriter as any,
@@ -100,7 +107,7 @@ export const make = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(
100
107
  const updatedEncodedDoc = yield* Document.encode(
101
108
  value,
102
109
  tableName,
103
- tableSchema,
110
+ tableDef.Fields,
104
111
  );
105
112
 
106
113
  yield* Effect.promise(() =>
package/src/Document.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import * as SystemFields from "@confect/core/SystemFields";
2
- import { Effect, Function, ParseResult, pipe, Schema } from "effect";
2
+ import { pipe } from "effect/Function";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Function from "effect/Function";
5
+ import * as ParseResult from "effect/ParseResult";
6
+ import * as Schema from "effect/Schema";
3
7
  import type { ReadonlyRecord } from "effect/Record";
4
8
  import type * as DataModel from "./DataModel";
5
9
  import type { ReadonlyValue } from "./SchemaToValidator";
@@ -1,64 +1,69 @@
1
1
  import type * as FunctionSpec from "@confect/core/FunctionSpec";
2
2
  import type * as GroupSpec from "@confect/core/GroupSpec";
3
3
  import * as Registry from "@confect/core/Registry";
4
- import { Context, Effect, Layer, Ref, String } from "effect";
5
- import type * as Api from "./Api";
6
- import { resolveGroupPathUnsafe } from "./GroupPath";
4
+ import * as Context from "effect/Context";
5
+ import * as Effect from "effect/Effect";
6
+ import * as Layer from "effect/Layer";
7
+ import * as Ref from "effect/Ref";
8
+ import type * as DatabaseSchema from "./DatabaseSchema";
7
9
  import type * as Handler from "./Handler";
8
10
  import { setNestedProperty } from "./internal/utils";
9
11
  import * as RegistryItem from "./RegistryItem";
10
12
 
11
- export interface FunctionImpl<
12
- GroupPath_ extends string,
13
- FunctionName extends string,
14
- > {
15
- readonly groupPath: GroupPath_;
13
+ export interface FunctionImpl<FunctionName extends string> {
16
14
  readonly functionName: FunctionName;
17
15
  }
18
16
 
19
- export const FunctionImpl = <
20
- GroupPath_ extends string,
21
- FunctionName extends string,
22
- >({
23
- groupPath,
17
+ export const FunctionImpl = <FunctionName extends string>({
24
18
  functionName,
25
19
  }: {
26
- groupPath: GroupPath_;
27
20
  functionName: FunctionName;
28
21
  }) =>
29
- Context.GenericTag<FunctionImpl<GroupPath_, FunctionName>>(
30
- `@confect/server/FunctionImpl/${groupPath}/${functionName}`,
22
+ Context.GenericTag<FunctionImpl<FunctionName>>(
23
+ `@confect/server/FunctionImpl/${functionName}`,
31
24
  );
32
25
 
26
+ /**
27
+ * Register a single function's implementation into the group's `Registry`.
28
+ *
29
+ * The function is registered under a flat, single-segment key (its own
30
+ * `functionName`), not a project-wide dot-path. Each group's impl layer is
31
+ * built in isolation — `RegisteredFunctions.buildForGroup` (and the CLI's
32
+ * `validateImpl`) provide a fresh `Registry` per group — so function names
33
+ * only need to be unique within their own group.
34
+ *
35
+ * `databaseSchema` is retained purely as a type-level carrier: the handler's
36
+ * ctx-service requirements (`DatabaseReader`, `QueryCtx<DataModel>`, …) are
37
+ * derived from it via `Handler.WithName`. It is not read at runtime — the
38
+ * generated per-group registry forwards the schema value to the function
39
+ * builders — so impls depend on `_generated/schema` (table schemas) rather than
40
+ * `_generated/api` (which transitively imports every function spec).
41
+ */
33
42
  export const make = <
34
- Api_ extends Api.AnyWithProps,
43
+ DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
35
44
  Group extends GroupSpec.AnyWithProps,
36
45
  const FunctionName extends FunctionSpec.Name<GroupSpec.Functions<Group>>,
37
46
  >(
38
- api: Api_,
47
+ _databaseSchema: DatabaseSchema_,
39
48
  group: Group,
40
49
  functionName: FunctionName,
41
50
  handler: Handler.WithName<
42
- Api.Schema<Api_>,
51
+ DatabaseSchema_,
43
52
  GroupSpec.Functions<Group>,
44
53
  FunctionName
45
54
  >,
46
- ): Layer.Layer<FunctionImpl<string, FunctionName>> => {
47
- const groupPath = resolveGroupPathUnsafe(api.spec, group);
55
+ ): Layer.Layer<FunctionImpl<FunctionName>> => {
48
56
  const functionSpec = group.functions[functionName]!;
49
57
 
50
58
  return Layer.effect(
51
- FunctionImpl<string, FunctionName>({
52
- groupPath,
53
- functionName,
54
- }),
59
+ FunctionImpl<FunctionName>({ functionName }),
55
60
  Effect.gen(function* () {
56
61
  const registry = yield* Registry.Registry;
57
62
 
58
63
  yield* Ref.update(registry, (registryItems) =>
59
64
  setNestedProperty(
60
65
  registryItems,
61
- [...String.split(groupPath, "."), functionName],
66
+ [functionName],
62
67
  RegistryItem.make({
63
68
  functionSpec,
64
69
  handler,
@@ -66,21 +71,16 @@ export const make = <
66
71
  ),
67
72
  );
68
73
 
69
- return {
70
- groupPath,
71
- functionName,
72
- };
74
+ return { functionName };
73
75
  }),
74
76
  );
75
77
  };
76
78
 
77
79
  /**
78
- * Get the function implementation service type for a specific group path and function name.
80
+ * Get the function implementation service type for a specific function name.
79
81
  */
80
- export type ForGroupPathAndFunction<
81
- GroupPath_ extends string,
82
- FunctionName extends string,
83
- > = FunctionImpl<GroupPath_, FunctionName>;
82
+ export type ForFunction<FunctionName extends string> =
83
+ FunctionImpl<FunctionName>;
84
84
 
85
85
  /**
86
86
  * Get all function implementation services required for a group spec.
@@ -90,14 +90,6 @@ export type FromGroupSpec<Group extends GroupSpec.AnyWithProps> =
90
90
  GroupSpec.Functions<Group>
91
91
  > extends infer FunctionNames extends string
92
92
  ? FunctionNames extends string
93
- ? FunctionImpl<string, FunctionNames>
93
+ ? FunctionImpl<FunctionNames>
94
94
  : never
95
95
  : never;
96
-
97
- /**
98
- * @deprecated Use {@link FromGroupSpec} instead.
99
- */
100
- export type FromGroupAtPath<
101
- _GroupPath extends string,
102
- Group extends GroupSpec.AnyWithProps,
103
- > = FromGroupSpec<Group>;