@confect/server 9.0.0-next.0 → 9.0.0-next.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +299 -4
- package/dist/ActionCtx.d.ts +4 -11
- package/dist/ActionCtx.d.ts.map +1 -1
- package/dist/ActionCtx.js +1 -1
- package/dist/ActionCtx.js.map +1 -1
- package/dist/ActionRunner.d.ts +8 -13
- package/dist/ActionRunner.d.ts.map +1 -1
- package/dist/ActionRunner.js +4 -3
- package/dist/ActionRunner.js.map +1 -1
- package/dist/Auth.d.ts +17 -23
- package/dist/Auth.d.ts.map +1 -1
- package/dist/Auth.js +5 -1
- package/dist/Auth.js.map +1 -1
- package/dist/BlobNotFoundError.d.ts +6 -12
- package/dist/BlobNotFoundError.d.ts.map +1 -1
- package/dist/BlobNotFoundError.js +1 -1
- package/dist/BlobNotFoundError.js.map +1 -1
- package/dist/ConvexConfigProvider.d.ts +2 -9
- package/dist/ConvexConfigProvider.d.ts.map +1 -1
- package/dist/ConvexConfigProvider.js +6 -1
- package/dist/ConvexConfigProvider.js.map +1 -1
- package/dist/CronJob.d.ts +12 -19
- package/dist/CronJob.d.ts.map +1 -1
- package/dist/CronJob.js +1 -1
- package/dist/CronJob.js.map +1 -1
- package/dist/CronJobs.d.ts +11 -18
- package/dist/CronJobs.d.ts.map +1 -1
- package/dist/CronJobs.js +11 -4
- package/dist/CronJobs.js.map +1 -1
- package/dist/DataModel.d.ts +24 -29
- package/dist/DataModel.d.ts.map +1 -1
- package/dist/DatabaseReader.d.ts +4323 -64
- package/dist/DatabaseReader.d.ts.map +1 -1
- package/dist/DatabaseReader.js +6 -6
- package/dist/DatabaseReader.js.map +1 -1
- package/dist/DatabaseSchema.d.ts +38 -130
- package/dist/DatabaseSchema.d.ts.map +1 -1
- package/dist/DatabaseSchema.js +20 -30
- package/dist/DatabaseSchema.js.map +1 -1
- package/dist/DatabaseWriter.d.ts +38 -42
- package/dist/DatabaseWriter.d.ts.map +1 -1
- package/dist/DatabaseWriter.js +8 -5
- package/dist/DatabaseWriter.js.map +1 -1
- package/dist/Document.d.ts +28 -37
- package/dist/Document.d.ts.map +1 -1
- package/dist/Document.js +5 -1
- package/dist/Document.js.map +1 -1
- package/dist/FunctionImpl.d.ts +30 -29
- package/dist/FunctionImpl.d.ts.map +1 -1
- package/dist/FunctionImpl.js +25 -14
- package/dist/FunctionImpl.js.map +1 -1
- package/dist/GroupImpl.d.ts +45 -41
- package/dist/GroupImpl.d.ts.map +1 -1
- package/dist/GroupImpl.js +42 -35
- package/dist/GroupImpl.js.map +1 -1
- package/dist/Handler.d.ts +34 -40
- package/dist/Handler.d.ts.map +1 -1
- package/dist/HttpApi.d.ts +21 -25
- package/dist/HttpApi.d.ts.map +1 -1
- package/dist/HttpApi.js +11 -6
- package/dist/HttpApi.js.map +1 -1
- package/dist/MutationCtx.d.ts +4 -11
- package/dist/MutationCtx.d.ts.map +1 -1
- package/dist/MutationCtx.js +1 -1
- package/dist/MutationCtx.js.map +1 -1
- package/dist/MutationRunner.d.ts +8 -13
- package/dist/MutationRunner.d.ts.map +1 -1
- package/dist/MutationRunner.js +4 -3
- package/dist/MutationRunner.js.map +1 -1
- package/dist/OrderedQuery.d.ts +16 -21
- package/dist/OrderedQuery.d.ts.map +1 -1
- package/dist/OrderedQuery.js +4 -1
- package/dist/OrderedQuery.js.map +1 -1
- package/dist/QueryCtx.d.ts +4 -11
- package/dist/QueryCtx.d.ts.map +1 -1
- package/dist/QueryCtx.js +1 -1
- package/dist/QueryCtx.js.map +1 -1
- package/dist/QueryInitializer.d.ts +34 -39
- package/dist/QueryInitializer.d.ts.map +1 -1
- package/dist/QueryInitializer.js +5 -1
- package/dist/QueryInitializer.js.map +1 -1
- package/dist/QueryRunner.d.ts +8 -13
- package/dist/QueryRunner.d.ts.map +1 -1
- package/dist/QueryRunner.js +4 -3
- package/dist/QueryRunner.js.map +1 -1
- package/dist/RegisteredConvexFunction.d.ts +1107 -60
- package/dist/RegisteredConvexFunction.d.ts.map +1 -1
- package/dist/RegisteredConvexFunction.js +14 -9
- package/dist/RegisteredConvexFunction.js.map +1 -1
- package/dist/RegisteredFunction.d.ts +48 -64
- package/dist/RegisteredFunction.d.ts.map +1 -1
- package/dist/RegisteredFunction.js +9 -5
- package/dist/RegisteredFunction.js.map +1 -1
- package/dist/RegisteredFunctions.d.ts +48 -26
- package/dist/RegisteredFunctions.d.ts.map +1 -1
- package/dist/RegisteredFunctions.js +22 -9
- package/dist/RegisteredFunctions.js.map +1 -1
- package/dist/RegisteredNodeFunction.d.ts +4 -14
- package/dist/RegisteredNodeFunction.d.ts.map +1 -1
- package/dist/RegisteredNodeFunction.js +5 -4
- package/dist/RegisteredNodeFunction.js.map +1 -1
- package/dist/RegistryItem.d.ts +17 -27
- package/dist/RegistryItem.d.ts.map +1 -1
- package/dist/RegistryItem.js +1 -1
- package/dist/RegistryItem.js.map +1 -1
- package/dist/Scheduler.d.ts +16 -20
- package/dist/Scheduler.d.ts.map +1 -1
- package/dist/Scheduler.js +10 -6
- package/dist/Scheduler.js.map +1 -1
- package/dist/SchemaToValidator.d.ts +71 -64
- package/dist/SchemaToValidator.d.ts.map +1 -1
- package/dist/SchemaToValidator.js +15 -3
- package/dist/SchemaToValidator.js.map +1 -1
- package/dist/StorageActionWriter.d.ts +21 -28
- package/dist/StorageActionWriter.d.ts.map +1 -1
- package/dist/StorageActionWriter.js +4 -1
- package/dist/StorageActionWriter.js.map +1 -1
- package/dist/StorageReader.d.ts +14 -21
- package/dist/StorageReader.d.ts.map +1 -1
- package/dist/StorageReader.js +5 -1
- package/dist/StorageReader.js.map +1 -1
- package/dist/StorageWriter.d.ts +16 -23
- package/dist/StorageWriter.d.ts.map +1 -1
- package/dist/StorageWriter.js +4 -1
- package/dist/StorageWriter.js.map +1 -1
- package/dist/Table.d.ts +204 -197
- package/dist/Table.d.ts.map +1 -1
- package/dist/Table.js +72 -62
- package/dist/Table.js.map +1 -1
- package/dist/TableInfo.d.ts +35 -41
- package/dist/TableInfo.d.ts.map +1 -1
- package/dist/VectorSearch.d.ts +30 -35
- package/dist/VectorSearch.d.ts.map +1 -1
- package/dist/VectorSearch.js +3 -1
- package/dist/VectorSearch.js.map +1 -1
- package/dist/index.d.ts +35 -36
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -5
- package/dist/internal/utils.d.ts +9 -11
- package/dist/internal/utils.d.ts.map +1 -1
- package/dist/internal/utils.js +3 -1
- package/dist/internal/utils.js.map +1 -1
- package/dist/node.d.ts +2 -2
- package/dist/node.d.ts.map +1 -0
- package/dist/tsconfig.src.tsbuildinfo +1 -0
- package/package.json +50 -59
- package/src/ActionCtx.ts +1 -1
- package/src/ActionRunner.ts +2 -1
- package/src/Auth.ts +5 -1
- package/src/BlobNotFoundError.ts +1 -1
- package/src/ConvexConfigProvider.ts +6 -8
- package/src/CronJob.ts +1 -1
- package/src/CronJobs.ts +8 -10
- package/src/DatabaseReader.ts +18 -21
- package/src/DatabaseSchema.ts +38 -98
- package/src/DatabaseWriter.ts +13 -6
- package/src/Document.ts +5 -1
- package/src/FunctionImpl.ts +36 -44
- package/src/GroupImpl.ts +54 -81
- package/src/HttpApi.ts +8 -9
- package/src/MutationCtx.ts +1 -1
- package/src/MutationRunner.ts +2 -1
- package/src/OrderedQuery.ts +5 -1
- package/src/QueryCtx.ts +1 -1
- package/src/QueryInitializer.ts +15 -3
- package/src/QueryRunner.ts +2 -1
- package/src/RegisteredConvexFunction.ts +11 -7
- package/src/RegisteredFunction.ts +5 -1
- package/src/RegisteredFunctions.ts +69 -93
- package/src/RegisteredNodeFunction.ts +7 -6
- package/src/RegistryItem.ts +1 -1
- package/src/Scheduler.ts +5 -1
- package/src/SchemaToValidator.ts +14 -16
- package/src/StorageActionWriter.ts +4 -1
- package/src/StorageReader.ts +5 -1
- package/src/StorageWriter.ts +4 -1
- package/src/Table.ts +253 -132
- package/src/VectorSearch.ts +3 -1
- package/src/index.ts +0 -1
- package/src/internal/utils.ts +3 -1
- package/dist/Api.d.ts +0 -30
- package/dist/Api.d.ts.map +0 -1
- package/dist/Api.js +0 -26
- package/dist/Api.js.map +0 -1
- package/dist/GroupPath.d.ts +0 -8
- package/dist/GroupPath.d.ts.map +0 -1
- package/dist/GroupPath.js +0 -10
- package/dist/GroupPath.js.map +0 -1
- package/src/Api.ts +0 -75
- package/src/GroupPath.ts +0 -43
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
|
-
"
|
|
6
|
-
|
|
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.
|
|
71
|
+
"@confect/core": "^9.0.0-next.10"
|
|
77
72
|
},
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
73
|
+
"repository": {
|
|
74
|
+
"type": "git",
|
|
75
|
+
"url": "https://github.com/rjdellecese/confect.git"
|
|
81
76
|
},
|
|
82
|
-
"
|
|
83
|
-
"
|
|
77
|
+
"sideEffects": false,
|
|
78
|
+
"type": "module",
|
|
84
79
|
"types": "./dist/index.d.ts",
|
|
85
80
|
"scripts": {
|
|
86
|
-
"
|
|
87
|
-
"
|
|
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
|
-
"
|
|
92
|
-
"
|
|
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
|
|
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");
|
package/src/ActionRunner.ts
CHANGED
|
@@ -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
|
|
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 {
|
|
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(
|
package/src/BlobNotFoundError.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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";
|
package/src/DatabaseReader.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { GenericDatabaseReader } from "convex/server";
|
|
2
|
-
import
|
|
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 =
|
|
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
|
|
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> =
|
|
30
|
-
|
|
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
|
-
}
|
|
37
|
-
|
|
38
|
-
>)
|
|
39
|
-
: ({
|
|
29
|
+
}
|
|
30
|
+
: {
|
|
40
31
|
get: convexDatabaseReader.get,
|
|
41
32
|
query: convexDatabaseReader.query,
|
|
42
|
-
}
|
|
43
|
-
|
|
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,
|
package/src/DatabaseSchema.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import
|
|
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
|
|
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:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
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
|
-
*
|
|
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 =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
+
});
|
package/src/DatabaseWriter.ts
CHANGED
|
@@ -6,7 +6,11 @@ import type {
|
|
|
6
6
|
WithoutSystemFields,
|
|
7
7
|
} from "convex/server";
|
|
8
8
|
import type { GenericId } from "convex/values";
|
|
9
|
-
import {
|
|
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
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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 {
|
|
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";
|
package/src/FunctionImpl.ts
CHANGED
|
@@ -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
|
|
5
|
-
import
|
|
6
|
-
import
|
|
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<
|
|
30
|
-
`@confect/server/FunctionImpl/${
|
|
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
|
-
|
|
43
|
+
DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
|
|
35
44
|
Group extends GroupSpec.AnyWithProps,
|
|
36
45
|
const FunctionName extends FunctionSpec.Name<GroupSpec.Functions<Group>>,
|
|
37
46
|
>(
|
|
38
|
-
|
|
47
|
+
_databaseSchema: DatabaseSchema_,
|
|
39
48
|
group: Group,
|
|
40
49
|
functionName: FunctionName,
|
|
41
50
|
handler: Handler.WithName<
|
|
42
|
-
|
|
51
|
+
DatabaseSchema_,
|
|
43
52
|
GroupSpec.Functions<Group>,
|
|
44
53
|
FunctionName
|
|
45
54
|
>,
|
|
46
|
-
): Layer.Layer<FunctionImpl<
|
|
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<
|
|
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
|
-
[
|
|
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
|
|
80
|
+
* Get the function implementation service type for a specific function name.
|
|
79
81
|
*/
|
|
80
|
-
export type
|
|
81
|
-
|
|
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<
|
|
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>;
|