@confect/cli 1.0.0-next.0
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 +12 -0
- package/LICENSE +7 -0
- package/dist/FunctionPath.mjs +19 -0
- package/dist/FunctionPath.mjs.map +1 -0
- package/dist/FunctionPaths.mjs +41 -0
- package/dist/FunctionPaths.mjs.map +1 -0
- package/dist/GroupPath.mjs +52 -0
- package/dist/GroupPath.mjs.map +1 -0
- package/dist/GroupPaths.mjs +9 -0
- package/dist/GroupPaths.mjs.map +1 -0
- package/dist/_virtual/rolldown_runtime.mjs +28 -0
- package/dist/cliApp.mjs +13 -0
- package/dist/cliApp.mjs.map +1 -0
- package/dist/confect/codegen.mjs +111 -0
- package/dist/confect/codegen.mjs.map +1 -0
- package/dist/confect/dev.mjs +253 -0
- package/dist/confect/dev.mjs.map +1 -0
- package/dist/confect.mjs +14 -0
- package/dist/confect.mjs.map +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +19 -0
- package/dist/index.mjs.map +1 -0
- package/dist/log.mjs +25 -0
- package/dist/log.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodeCommandExecutor.mjs +12 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodeCommandExecutor.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodeFileSystem.mjs +15 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodeFileSystem.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodePath.mjs +25 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodePath.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodeRuntime.mjs +12 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodeRuntime.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodeTerminal.mjs +17 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodeTerminal.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/commandExecutor.mjs +129 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/commandExecutor.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/error.mjs +43 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/error.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/fileSystem.mjs +329 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/fileSystem.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/path.mjs +51 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/path.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/runtime.mjs +31 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/runtime.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/sink.mjs +24 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/sink.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/stream.mjs +91 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/stream.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/terminal.mjs +75 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/terminal.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/NodeContext.mjs +21 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/NodeContext.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/NodeFileSystem.mjs +15 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/NodeFileSystem.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/NodeRuntime.mjs +15 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/NodeRuntime.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/NodeWorker.mjs +27 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/NodeWorker.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/internal/worker.mjs +71 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/internal/worker.mjs.map +1 -0
- package/dist/packages/cli/package.mjs +6 -0
- package/dist/packages/cli/package.mjs.map +1 -0
- package/dist/packages/core/dist/Spec.mjs +23 -0
- package/dist/packages/core/dist/Spec.mjs.map +1 -0
- package/dist/packages/core/dist/_virtual/rolldown_runtime.mjs +14 -0
- package/dist/packages/core/dist/_virtual/rolldown_runtime.mjs.map +1 -0
- package/dist/services/ConfectDirectory.mjs +31 -0
- package/dist/services/ConfectDirectory.mjs.map +1 -0
- package/dist/services/ConvexDirectory.mjs +41 -0
- package/dist/services/ConvexDirectory.mjs.map +1 -0
- package/dist/services/ProjectRoot.mjs +35 -0
- package/dist/services/ProjectRoot.mjs.map +1 -0
- package/dist/templates.mjs +204 -0
- package/dist/templates.mjs.map +1 -0
- package/dist/utils.mjs +162 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +86 -0
- package/src/FunctionPath.ts +28 -0
- package/src/FunctionPaths.ts +103 -0
- package/src/GroupPath.ts +117 -0
- package/src/GroupPaths.ts +7 -0
- package/src/cliApp.ts +8 -0
- package/src/confect/codegen.ts +228 -0
- package/src/confect/dev.ts +611 -0
- package/src/confect.ts +19 -0
- package/src/index.ts +22 -0
- package/src/log.ts +106 -0
- package/src/services/ConfectDirectory.ts +41 -0
- package/src/services/ConvexDirectory.ts +67 -0
- package/src/services/ProjectRoot.ts +49 -0
- package/src/templates.ts +380 -0
- package/src/utils.ts +332 -0
package/src/GroupPath.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { type GroupSpec, type Spec } from "@confect/core";
|
|
2
|
+
import { Path } from "@effect/platform";
|
|
3
|
+
import {
|
|
4
|
+
Array,
|
|
5
|
+
Data,
|
|
6
|
+
Effect,
|
|
7
|
+
Option,
|
|
8
|
+
pipe,
|
|
9
|
+
Record,
|
|
10
|
+
Schema,
|
|
11
|
+
String,
|
|
12
|
+
} from "effect";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The path to a group in the Confect API.
|
|
16
|
+
*/
|
|
17
|
+
export class GroupPath extends Schema.Class<GroupPath>("GroupPath")({
|
|
18
|
+
pathSegments: Schema.Data(Schema.NonEmptyArray(Schema.NonEmptyString)),
|
|
19
|
+
}) {}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create a GroupPath from path segments.
|
|
23
|
+
*/
|
|
24
|
+
export const make = (pathSegments: readonly [string, ...string[]]): GroupPath =>
|
|
25
|
+
GroupPath.make({ pathSegments: Data.array(pathSegments) });
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Append a group name to a GroupPath to create a new GroupPath.
|
|
29
|
+
*/
|
|
30
|
+
export const append = (groupPath: GroupPath, groupName: string): GroupPath =>
|
|
31
|
+
make([...groupPath.pathSegments, groupName]);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Expects a path string of the form `./group1/group2.ts`, relative to the Convex functions directory.
|
|
35
|
+
*/
|
|
36
|
+
export const fromGroupModulePath = (groupModulePath: string) =>
|
|
37
|
+
Effect.gen(function* () {
|
|
38
|
+
const path = yield* Path.Path;
|
|
39
|
+
|
|
40
|
+
const { dir, name, ext } = path.parse(groupModulePath);
|
|
41
|
+
|
|
42
|
+
if (ext === ".ts") {
|
|
43
|
+
const dirSegments = Array.filter(
|
|
44
|
+
String.split(dir, path.sep),
|
|
45
|
+
String.isNonEmpty,
|
|
46
|
+
);
|
|
47
|
+
yield* Effect.logDebug(Array.append(dirSegments, name));
|
|
48
|
+
return make(Array.append(dirSegments, name));
|
|
49
|
+
} else {
|
|
50
|
+
return yield* Effect.fail(
|
|
51
|
+
new GroupModulePathIsNotATypeScriptFileError({ path: groupModulePath }),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Get the module path for a group, relative to the Convex functions directory.
|
|
58
|
+
*/
|
|
59
|
+
export const modulePath = (groupPath: GroupPath) =>
|
|
60
|
+
Effect.gen(function* () {
|
|
61
|
+
const path = yield* Path.Path;
|
|
62
|
+
|
|
63
|
+
return path.join(...groupPath.pathSegments) + ".ts";
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
export const getGroupSpec = (
|
|
67
|
+
spec: Spec.AnyWithProps,
|
|
68
|
+
groupPath: GroupPath,
|
|
69
|
+
): Option.Option<GroupSpec.AnyWithProps> =>
|
|
70
|
+
pipe(
|
|
71
|
+
groupPath.pathSegments,
|
|
72
|
+
Array.matchLeft({
|
|
73
|
+
onEmpty: () => Option.none(),
|
|
74
|
+
onNonEmpty: (head, tail) =>
|
|
75
|
+
pipe(
|
|
76
|
+
Record.get(spec.groups, head),
|
|
77
|
+
Option.flatMap((group) =>
|
|
78
|
+
Array.isNonEmptyArray(tail)
|
|
79
|
+
? getGroupSpecHelper(group, tail)
|
|
80
|
+
: Option.some(group),
|
|
81
|
+
),
|
|
82
|
+
),
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const getGroupSpecHelper = (
|
|
87
|
+
group: GroupSpec.AnyWithProps,
|
|
88
|
+
remainingPath: ReadonlyArray<string>,
|
|
89
|
+
): Option.Option<GroupSpec.AnyWithProps> =>
|
|
90
|
+
pipe(
|
|
91
|
+
remainingPath,
|
|
92
|
+
Array.matchLeft({
|
|
93
|
+
onEmpty: () => Option.some(group),
|
|
94
|
+
onNonEmpty: (head, tail) =>
|
|
95
|
+
pipe(
|
|
96
|
+
Record.get(group.groups, head),
|
|
97
|
+
Option.flatMap((subGroup) =>
|
|
98
|
+
Array.isNonEmptyArray(tail)
|
|
99
|
+
? getGroupSpecHelper(subGroup, tail)
|
|
100
|
+
: Option.some(subGroup),
|
|
101
|
+
),
|
|
102
|
+
),
|
|
103
|
+
}),
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
export const toString = (groupPath: GroupPath) =>
|
|
107
|
+
Array.join(groupPath.pathSegments, ".");
|
|
108
|
+
|
|
109
|
+
export class GroupModulePathIsNotATypeScriptFileError extends Schema.TaggedError<GroupModulePathIsNotATypeScriptFileError>(
|
|
110
|
+
"GroupModulePathIsNotATypeScriptFileError",
|
|
111
|
+
)("GroupModulePathIsNotATypeScriptFileError", {
|
|
112
|
+
path: Schema.NonEmptyString,
|
|
113
|
+
}) {
|
|
114
|
+
override get message(): string {
|
|
115
|
+
return `Expected group module path to end with .ts, got ${this.path}`;
|
|
116
|
+
}
|
|
117
|
+
}
|
package/src/cliApp.ts
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { Spec } from "@confect/core";
|
|
2
|
+
import { DatabaseSchema } from "@confect/server";
|
|
3
|
+
import { Command } from "@effect/cli";
|
|
4
|
+
import { FileSystem, Path } from "@effect/platform";
|
|
5
|
+
import { Effect, Match, Option } from "effect";
|
|
6
|
+
import * as tsx from "tsx/esm/api";
|
|
7
|
+
import { logCompleted, logFileAdded, logFileModified } from "../log";
|
|
8
|
+
import { ConfectDirectory } from "../services/ConfectDirectory";
|
|
9
|
+
import { ConvexDirectory } from "../services/ConvexDirectory";
|
|
10
|
+
import * as templates from "../templates";
|
|
11
|
+
import {
|
|
12
|
+
generateAuthConfig,
|
|
13
|
+
generateConvexConfig,
|
|
14
|
+
generateCrons,
|
|
15
|
+
generateFunctions,
|
|
16
|
+
generateHttp,
|
|
17
|
+
removePathExtension,
|
|
18
|
+
writeFileStringAndLog,
|
|
19
|
+
} from "../utils";
|
|
20
|
+
|
|
21
|
+
export const codegen = Command.make("codegen", {}, () =>
|
|
22
|
+
Effect.gen(function* () {
|
|
23
|
+
yield* codegenHandler;
|
|
24
|
+
yield* logCompleted("Generated files are up-to-date");
|
|
25
|
+
}),
|
|
26
|
+
).pipe(
|
|
27
|
+
Command.withDescription(
|
|
28
|
+
"Generate `confect/_generated` files and the contents of the `convex` directory (except `tsconfig.json`)",
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export const codegenHandler = Effect.gen(function* () {
|
|
33
|
+
yield* generateConfectGeneratedDirectory;
|
|
34
|
+
yield* Effect.all(
|
|
35
|
+
[generateApi, generateRefs, generateRegisteredFunctions, generateServices],
|
|
36
|
+
{ concurrency: "unbounded" },
|
|
37
|
+
);
|
|
38
|
+
const [functionPaths] = yield* Effect.all(
|
|
39
|
+
[
|
|
40
|
+
generateFunctionModules,
|
|
41
|
+
generateSchema,
|
|
42
|
+
logGenerated(generateHttp),
|
|
43
|
+
logGenerated(generateConvexConfig),
|
|
44
|
+
logGenerated(generateCrons),
|
|
45
|
+
logGenerated(generateAuthConfig),
|
|
46
|
+
],
|
|
47
|
+
{ concurrency: "unbounded" },
|
|
48
|
+
);
|
|
49
|
+
return functionPaths;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const generateConfectGeneratedDirectory = Effect.gen(function* () {
|
|
53
|
+
const fs = yield* FileSystem.FileSystem;
|
|
54
|
+
const path = yield* Path.Path;
|
|
55
|
+
const confectDirectory = yield* ConfectDirectory.get;
|
|
56
|
+
|
|
57
|
+
if (!(yield* fs.exists(path.join(confectDirectory, "_generated")))) {
|
|
58
|
+
yield* fs.makeDirectory(path.join(confectDirectory, "_generated"), {
|
|
59
|
+
recursive: true,
|
|
60
|
+
});
|
|
61
|
+
yield* logFileAdded(path.join(confectDirectory, "_generated") + "/");
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const generateApi = Effect.gen(function* () {
|
|
66
|
+
const path = yield* Path.Path;
|
|
67
|
+
const confectDirectory = yield* ConfectDirectory.get;
|
|
68
|
+
|
|
69
|
+
const apiPath = path.join(confectDirectory, "_generated", "api.ts");
|
|
70
|
+
|
|
71
|
+
const schemaImportPath = yield* removePathExtension(
|
|
72
|
+
path.relative(
|
|
73
|
+
path.dirname(apiPath),
|
|
74
|
+
path.join(confectDirectory, "schema.ts"),
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const specImportPath = yield* removePathExtension(
|
|
79
|
+
path.relative(
|
|
80
|
+
path.dirname(apiPath),
|
|
81
|
+
path.join(confectDirectory, "spec.ts"),
|
|
82
|
+
),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const apiContents = yield* templates.api({
|
|
86
|
+
schemaImportPath,
|
|
87
|
+
specImportPath,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
yield* writeFileStringAndLog(apiPath, apiContents);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const generateFunctionModules = Effect.gen(function* () {
|
|
94
|
+
const path = yield* Path.Path;
|
|
95
|
+
const confectDirectory = yield* ConfectDirectory.get;
|
|
96
|
+
|
|
97
|
+
const specPath = path.join(confectDirectory, "spec.ts");
|
|
98
|
+
const specPathUrl = yield* path.toFileUrl(specPath);
|
|
99
|
+
|
|
100
|
+
const specModule = yield* Effect.promise(() =>
|
|
101
|
+
tsx.tsImport(specPathUrl.href, import.meta.url),
|
|
102
|
+
);
|
|
103
|
+
const spec = specModule.default;
|
|
104
|
+
|
|
105
|
+
if (!Spec.isSpec(spec)) {
|
|
106
|
+
return yield* Effect.die("spec.ts does not export a valid Spec");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return yield* generateFunctions(spec);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const generateSchema = Effect.gen(function* () {
|
|
113
|
+
const path = yield* Path.Path;
|
|
114
|
+
const confectDirectory = yield* ConfectDirectory.get;
|
|
115
|
+
const convexDirectory = yield* ConvexDirectory.get;
|
|
116
|
+
|
|
117
|
+
const confectSchemaPath = path.join(confectDirectory, "schema.ts");
|
|
118
|
+
const confectSchemaUrl = yield* path.toFileUrl(confectSchemaPath);
|
|
119
|
+
|
|
120
|
+
yield* Effect.promise(() =>
|
|
121
|
+
tsx.tsImport(confectSchemaUrl.href, import.meta.url),
|
|
122
|
+
).pipe(
|
|
123
|
+
Effect.andThen((schemaModule) => {
|
|
124
|
+
const defaultExport = schemaModule.default;
|
|
125
|
+
|
|
126
|
+
return DatabaseSchema.isSchema(defaultExport)
|
|
127
|
+
? Effect.succeed(defaultExport)
|
|
128
|
+
: Effect.die("Invalid schema module");
|
|
129
|
+
}),
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const convexSchemaPath = path.join(convexDirectory, "schema.ts");
|
|
133
|
+
|
|
134
|
+
const relativeImportPath = path.relative(
|
|
135
|
+
path.dirname(convexSchemaPath),
|
|
136
|
+
confectSchemaPath,
|
|
137
|
+
);
|
|
138
|
+
const importPathWithoutExt = yield* removePathExtension(relativeImportPath);
|
|
139
|
+
const schemaContents = yield* templates.schema({
|
|
140
|
+
schemaImportPath: importPathWithoutExt,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
yield* writeFileStringAndLog(convexSchemaPath, schemaContents);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const generateServices = Effect.gen(function* () {
|
|
147
|
+
const path = yield* Path.Path;
|
|
148
|
+
const confectDirectory = yield* ConfectDirectory.get;
|
|
149
|
+
|
|
150
|
+
const confectGeneratedDirectory = path.join(confectDirectory, "_generated");
|
|
151
|
+
|
|
152
|
+
const servicesPath = path.join(confectGeneratedDirectory, "services.ts");
|
|
153
|
+
const schemaImportPath = path.relative(
|
|
154
|
+
path.dirname(servicesPath),
|
|
155
|
+
path.join(confectDirectory, "schema"),
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
const servicesContentsString = yield* templates.services({
|
|
159
|
+
schemaImportPath,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
yield* writeFileStringAndLog(servicesPath, servicesContentsString);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const generateRegisteredFunctions = Effect.gen(function* () {
|
|
166
|
+
const path = yield* Path.Path;
|
|
167
|
+
const confectDirectory = yield* ConfectDirectory.get;
|
|
168
|
+
|
|
169
|
+
const confectGeneratedDirectory = path.join(confectDirectory, "_generated");
|
|
170
|
+
|
|
171
|
+
const registeredFunctionsPath = path.join(
|
|
172
|
+
confectGeneratedDirectory,
|
|
173
|
+
"registeredFunctions.ts",
|
|
174
|
+
);
|
|
175
|
+
const implImportPath = yield* removePathExtension(
|
|
176
|
+
path.relative(
|
|
177
|
+
path.dirname(registeredFunctionsPath),
|
|
178
|
+
path.join(confectDirectory, "impl.ts"),
|
|
179
|
+
),
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
const registeredFunctionsContents = yield* templates.registeredFunctions({
|
|
183
|
+
implImportPath,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
yield* writeFileStringAndLog(
|
|
187
|
+
registeredFunctionsPath,
|
|
188
|
+
registeredFunctionsContents,
|
|
189
|
+
);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const generateRefs = Effect.gen(function* () {
|
|
193
|
+
const path = yield* Path.Path;
|
|
194
|
+
const confectDirectory = yield* ConfectDirectory.get;
|
|
195
|
+
|
|
196
|
+
const confectGeneratedDirectory = path.join(confectDirectory, "_generated");
|
|
197
|
+
|
|
198
|
+
const confectSpecPath = path.join(confectDirectory, "spec.ts");
|
|
199
|
+
const refsPath = path.join(confectGeneratedDirectory, "refs.ts");
|
|
200
|
+
|
|
201
|
+
const relativeImportPath = path.relative(
|
|
202
|
+
path.dirname(refsPath),
|
|
203
|
+
confectSpecPath,
|
|
204
|
+
);
|
|
205
|
+
const importPathWithoutExt = yield* removePathExtension(relativeImportPath);
|
|
206
|
+
|
|
207
|
+
const refsContents = yield* templates.refs({
|
|
208
|
+
specImportPath: importPathWithoutExt,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
yield* writeFileStringAndLog(refsPath, refsContents);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const logGenerated = (effect: typeof generateHttp) =>
|
|
215
|
+
effect.pipe(
|
|
216
|
+
Effect.tap(
|
|
217
|
+
Option.match({
|
|
218
|
+
onNone: () => Effect.void,
|
|
219
|
+
onSome: ({ change, convexFilePath }) =>
|
|
220
|
+
Match.value(change).pipe(
|
|
221
|
+
Match.when("Added", () => logFileAdded(convexFilePath)),
|
|
222
|
+
Match.when("Modified", () => logFileModified(convexFilePath)),
|
|
223
|
+
Match.when("Unchanged", () => Effect.void),
|
|
224
|
+
Match.exhaustive,
|
|
225
|
+
),
|
|
226
|
+
}),
|
|
227
|
+
),
|
|
228
|
+
);
|