@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
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { Array, Effect } from "effect";
|
|
2
|
+
import CodeBlockWriter_ from "code-block-writer";
|
|
3
|
+
|
|
4
|
+
//#region src/templates.ts
|
|
5
|
+
const functions = ({ groupPath, functionNames, registeredFunctionsImportPath }) => Effect.gen(function* () {
|
|
6
|
+
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
7
|
+
yield* cbw.writeLine(`import registeredFunctions from "${registeredFunctionsImportPath}";`);
|
|
8
|
+
yield* cbw.newLine();
|
|
9
|
+
for (const functionName of functionNames) yield* cbw.writeLine(`export const ${functionName} = registeredFunctions.${Array.join([...groupPath.pathSegments, functionName], ".")};`);
|
|
10
|
+
return yield* cbw.toString();
|
|
11
|
+
});
|
|
12
|
+
const schema = ({ schemaImportPath }) => Effect.gen(function* () {
|
|
13
|
+
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
14
|
+
yield* cbw.writeLine(`import schemaDefinition from "${schemaImportPath}";`);
|
|
15
|
+
yield* cbw.newLine();
|
|
16
|
+
yield* cbw.writeLine(`export default schemaDefinition.convexSchemaDefinition;`);
|
|
17
|
+
return yield* cbw.toString();
|
|
18
|
+
});
|
|
19
|
+
const http = ({ httpImportPath }) => Effect.gen(function* () {
|
|
20
|
+
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
21
|
+
yield* cbw.writeLine(`import http from "${httpImportPath}";`);
|
|
22
|
+
yield* cbw.newLine();
|
|
23
|
+
yield* cbw.writeLine(`export default http;`);
|
|
24
|
+
return yield* cbw.toString();
|
|
25
|
+
});
|
|
26
|
+
const convexConfig = ({ appImportPath }) => Effect.gen(function* () {
|
|
27
|
+
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
28
|
+
yield* cbw.writeLine(`import app from "${appImportPath}";`);
|
|
29
|
+
yield* cbw.newLine();
|
|
30
|
+
yield* cbw.writeLine(`export default app;`);
|
|
31
|
+
return yield* cbw.toString();
|
|
32
|
+
});
|
|
33
|
+
const crons = ({ cronsImportPath }) => Effect.gen(function* () {
|
|
34
|
+
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
35
|
+
yield* cbw.writeLine(`import crons from "${cronsImportPath}";`);
|
|
36
|
+
yield* cbw.newLine();
|
|
37
|
+
yield* cbw.writeLine(`export default crons;`);
|
|
38
|
+
return yield* cbw.toString();
|
|
39
|
+
});
|
|
40
|
+
const authConfig = ({ authImportPath }) => Effect.gen(function* () {
|
|
41
|
+
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
42
|
+
yield* cbw.writeLine(`import auth from "${authImportPath}";`);
|
|
43
|
+
yield* cbw.newLine();
|
|
44
|
+
yield* cbw.writeLine(`export default auth;`);
|
|
45
|
+
return yield* cbw.toString();
|
|
46
|
+
});
|
|
47
|
+
const refs = ({ specImportPath }) => Effect.gen(function* () {
|
|
48
|
+
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
49
|
+
yield* cbw.writeLine(`import { Refs } from "@confect/core";`);
|
|
50
|
+
yield* cbw.writeLine(`import spec from "${specImportPath}";`);
|
|
51
|
+
yield* cbw.blankLine();
|
|
52
|
+
yield* cbw.writeLine(`export const { public: api, internal } = Refs.make(spec);`);
|
|
53
|
+
return yield* cbw.toString();
|
|
54
|
+
});
|
|
55
|
+
const api = ({ schemaImportPath, specImportPath }) => Effect.gen(function* () {
|
|
56
|
+
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
57
|
+
yield* cbw.writeLine(`import { Api } from "@confect/server";`);
|
|
58
|
+
yield* cbw.writeLine(`import schema from "${schemaImportPath}";`);
|
|
59
|
+
yield* cbw.writeLine(`import spec from "${specImportPath}";`);
|
|
60
|
+
yield* cbw.blankLine();
|
|
61
|
+
yield* cbw.writeLine(`export default Api.make(schema, spec);`);
|
|
62
|
+
return yield* cbw.toString();
|
|
63
|
+
});
|
|
64
|
+
const registeredFunctions = ({ implImportPath }) => Effect.gen(function* () {
|
|
65
|
+
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
66
|
+
yield* cbw.writeLine(`import { RegisteredFunctions } from "@confect/server";`);
|
|
67
|
+
yield* cbw.writeLine(`import impl from "${implImportPath}";`);
|
|
68
|
+
yield* cbw.blankLine();
|
|
69
|
+
yield* cbw.writeLine(`export default RegisteredFunctions.make(impl);`);
|
|
70
|
+
return yield* cbw.toString();
|
|
71
|
+
});
|
|
72
|
+
const services = ({ schemaImportPath }) => Effect.gen(function* () {
|
|
73
|
+
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
74
|
+
yield* cbw.writeLine("import {");
|
|
75
|
+
yield* cbw.indent(Effect.gen(function* () {
|
|
76
|
+
yield* cbw.writeLine("ActionCtx as ActionCtx_,");
|
|
77
|
+
yield* cbw.writeLine("ActionRunner as ActionRunner_,");
|
|
78
|
+
yield* cbw.writeLine("Auth as Auth_,");
|
|
79
|
+
yield* cbw.writeLine("type DataModel,");
|
|
80
|
+
yield* cbw.writeLine("DatabaseReader as DatabaseReader_,");
|
|
81
|
+
yield* cbw.writeLine("DatabaseWriter as DatabaseWriter_,");
|
|
82
|
+
yield* cbw.writeLine("MutationCtx as MutationCtx_,");
|
|
83
|
+
yield* cbw.writeLine("MutationRunner as MutationRunner_,");
|
|
84
|
+
yield* cbw.writeLine("QueryCtx as QueryCtx_,");
|
|
85
|
+
yield* cbw.writeLine("QueryRunner as QueryRunner_,");
|
|
86
|
+
yield* cbw.writeLine("Scheduler as Scheduler_,");
|
|
87
|
+
yield* cbw.writeLine("Storage,");
|
|
88
|
+
yield* cbw.writeLine("VectorSearch as VectorSearch_,");
|
|
89
|
+
}));
|
|
90
|
+
yield* cbw.writeLine(`} from "@confect/server";`);
|
|
91
|
+
yield* cbw.writeLine(`import type schemaDefinition from "${schemaImportPath}";`);
|
|
92
|
+
yield* cbw.blankLine();
|
|
93
|
+
yield* cbw.writeLine("export const Auth = Auth_.Auth;");
|
|
94
|
+
yield* cbw.writeLine("export type Auth = typeof Auth.Identifier;");
|
|
95
|
+
yield* cbw.blankLine();
|
|
96
|
+
yield* cbw.writeLine("export const Scheduler = Scheduler_.Scheduler;");
|
|
97
|
+
yield* cbw.writeLine("export type Scheduler = typeof Scheduler.Identifier;");
|
|
98
|
+
yield* cbw.blankLine();
|
|
99
|
+
yield* cbw.writeLine("export const StorageReader = Storage.StorageReader;");
|
|
100
|
+
yield* cbw.writeLine("export type StorageReader = typeof StorageReader.Identifier;");
|
|
101
|
+
yield* cbw.blankLine();
|
|
102
|
+
yield* cbw.writeLine("export const StorageWriter = Storage.StorageWriter;");
|
|
103
|
+
yield* cbw.writeLine("export type StorageWriter = typeof StorageWriter.Identifier;");
|
|
104
|
+
yield* cbw.blankLine();
|
|
105
|
+
yield* cbw.writeLine("export const StorageActionWriter = Storage.StorageActionWriter;");
|
|
106
|
+
yield* cbw.writeLine("export type StorageActionWriter = typeof StorageActionWriter.Identifier;");
|
|
107
|
+
yield* cbw.blankLine();
|
|
108
|
+
yield* cbw.writeLine("export const VectorSearch =");
|
|
109
|
+
yield* cbw.indent(cbw.writeLine("VectorSearch_.VectorSearch<DataModel.FromSchema<typeof schemaDefinition>>();"));
|
|
110
|
+
yield* cbw.writeLine("export type VectorSearch = typeof VectorSearch.Identifier;");
|
|
111
|
+
yield* cbw.blankLine();
|
|
112
|
+
yield* cbw.writeLine("export const DatabaseReader =");
|
|
113
|
+
yield* cbw.indent(cbw.writeLine("DatabaseReader_.DatabaseReader<typeof schemaDefinition>();"));
|
|
114
|
+
yield* cbw.writeLine("export type DatabaseReader = typeof DatabaseReader.Identifier;");
|
|
115
|
+
yield* cbw.blankLine();
|
|
116
|
+
yield* cbw.writeLine("export const DatabaseWriter =");
|
|
117
|
+
yield* cbw.indent(cbw.writeLine("DatabaseWriter_.DatabaseWriter<typeof schemaDefinition>();"));
|
|
118
|
+
yield* cbw.writeLine("export type DatabaseWriter = typeof DatabaseWriter.Identifier;");
|
|
119
|
+
yield* cbw.blankLine();
|
|
120
|
+
yield* cbw.writeLine("export const QueryRunner = QueryRunner_.QueryRunner;");
|
|
121
|
+
yield* cbw.writeLine("export type QueryRunner = typeof QueryRunner.Identifier;");
|
|
122
|
+
yield* cbw.blankLine();
|
|
123
|
+
yield* cbw.writeLine("export const MutationRunner = MutationRunner_.MutationRunner;");
|
|
124
|
+
yield* cbw.writeLine("export type MutationRunner = typeof MutationRunner.Identifier;");
|
|
125
|
+
yield* cbw.blankLine();
|
|
126
|
+
yield* cbw.writeLine("export const ActionRunner = ActionRunner_.ActionRunner;");
|
|
127
|
+
yield* cbw.writeLine("export type ActionRunner = typeof ActionRunner.Identifier;");
|
|
128
|
+
yield* cbw.blankLine();
|
|
129
|
+
yield* cbw.writeLine("export const QueryCtx =");
|
|
130
|
+
yield* cbw.indent(Effect.gen(function* () {
|
|
131
|
+
yield* cbw.writeLine("QueryCtx_.QueryCtx<");
|
|
132
|
+
yield* cbw.indent(cbw.writeLine("DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>"));
|
|
133
|
+
yield* cbw.writeLine(">();");
|
|
134
|
+
}));
|
|
135
|
+
yield* cbw.writeLine("export type QueryCtx = typeof QueryCtx.Identifier;");
|
|
136
|
+
yield* cbw.blankLine();
|
|
137
|
+
yield* cbw.writeLine("export const MutationCtx =");
|
|
138
|
+
yield* cbw.indent(Effect.gen(function* () {
|
|
139
|
+
yield* cbw.writeLine("MutationCtx_.MutationCtx<");
|
|
140
|
+
yield* cbw.indent(cbw.writeLine("DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>"));
|
|
141
|
+
yield* cbw.writeLine(">();");
|
|
142
|
+
}));
|
|
143
|
+
yield* cbw.writeLine("export type MutationCtx = typeof MutationCtx.Identifier;");
|
|
144
|
+
yield* cbw.blankLine();
|
|
145
|
+
yield* cbw.writeLine("export const ActionCtx =");
|
|
146
|
+
yield* cbw.indent(Effect.gen(function* () {
|
|
147
|
+
yield* cbw.writeLine("ActionCtx_.ActionCtx<");
|
|
148
|
+
yield* cbw.indent(cbw.writeLine("DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>"));
|
|
149
|
+
yield* cbw.writeLine(">();");
|
|
150
|
+
}));
|
|
151
|
+
yield* cbw.writeLine("export type ActionCtx = typeof ActionCtx.Identifier;");
|
|
152
|
+
return yield* cbw.toString();
|
|
153
|
+
});
|
|
154
|
+
var CodeBlockWriter = class {
|
|
155
|
+
writer;
|
|
156
|
+
constructor(opts) {
|
|
157
|
+
this.writer = new CodeBlockWriter_(opts);
|
|
158
|
+
}
|
|
159
|
+
indent(eff) {
|
|
160
|
+
return Effect.gen(this, function* () {
|
|
161
|
+
const indentationLevel = this.writer.getIndentationLevel();
|
|
162
|
+
this.writer.setIndentationLevel(indentationLevel + 1);
|
|
163
|
+
yield* eff;
|
|
164
|
+
this.writer.setIndentationLevel(indentationLevel);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
writeLine(line) {
|
|
168
|
+
return Effect.sync(() => {
|
|
169
|
+
this.writer.writeLine(line);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
write(text) {
|
|
173
|
+
return Effect.sync(() => {
|
|
174
|
+
this.writer.write(text);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
quote(text) {
|
|
178
|
+
return Effect.sync(() => {
|
|
179
|
+
this.writer.quote(text);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
conditionalWriteLine(condition, text) {
|
|
183
|
+
return Effect.sync(() => {
|
|
184
|
+
this.writer.conditionalWriteLine(condition, text);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
newLine() {
|
|
188
|
+
return Effect.sync(() => {
|
|
189
|
+
this.writer.newLine();
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
blankLine() {
|
|
193
|
+
return Effect.sync(() => {
|
|
194
|
+
this.writer.blankLine();
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
toString() {
|
|
198
|
+
return Effect.sync(() => this.writer.toString());
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
//#endregion
|
|
203
|
+
export { api, authConfig, convexConfig, crons, functions, http, refs, registeredFunctions, schema, services };
|
|
204
|
+
//# sourceMappingURL=templates.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.mjs","names":[],"sources":["../src/templates.ts"],"sourcesContent":["import type { Options as CodeBlockWriterOptions } from \"code-block-writer\";\nimport CodeBlockWriter_ from \"code-block-writer\";\nimport { Array, Effect } from \"effect\";\nimport type * as GroupPath from \"./GroupPath\";\n\nexport const functions = ({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n}: {\n groupPath: GroupPath.GroupPath;\n functionNames: string[];\n registeredFunctionsImportPath: string;\n}) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(\n `import registeredFunctions from \"${registeredFunctionsImportPath}\";`,\n );\n yield* cbw.newLine();\n for (const functionName of functionNames) {\n yield* cbw.writeLine(\n `export const ${functionName} = registeredFunctions.${Array.join([...groupPath.pathSegments, functionName], \".\")};`,\n );\n }\n\n return yield* cbw.toString();\n });\n\nexport const schema = ({ schemaImportPath }: { schemaImportPath: string }) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import schemaDefinition from \"${schemaImportPath}\";`);\n yield* cbw.newLine();\n yield* cbw.writeLine(\n `export default schemaDefinition.convexSchemaDefinition;`,\n );\n\n return yield* cbw.toString();\n });\n\nexport const http = ({ httpImportPath }: { httpImportPath: string }) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import http from \"${httpImportPath}\";`);\n yield* cbw.newLine();\n yield* cbw.writeLine(`export default http;`);\n\n return yield* cbw.toString();\n });\n\nexport const convexConfig = ({ appImportPath }: { appImportPath: string }) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import app from \"${appImportPath}\";`);\n yield* cbw.newLine();\n yield* cbw.writeLine(`export default app;`);\n\n return yield* cbw.toString();\n });\n\nexport const crons = ({ cronsImportPath }: { cronsImportPath: string }) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import crons from \"${cronsImportPath}\";`);\n yield* cbw.newLine();\n yield* cbw.writeLine(`export default crons;`);\n\n return yield* cbw.toString();\n });\n\nexport const authConfig = ({ authImportPath }: { authImportPath: string }) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import auth from \"${authImportPath}\";`);\n yield* cbw.newLine();\n yield* cbw.writeLine(`export default auth;`);\n\n return yield* cbw.toString();\n });\n\nexport const refs = ({ specImportPath }: { specImportPath: string }) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import { Refs } from \"@confect/core\";`);\n yield* cbw.writeLine(`import spec from \"${specImportPath}\";`);\n yield* cbw.blankLine();\n yield* cbw.writeLine(\n `export const { public: api, internal } = Refs.make(spec);`,\n );\n\n return yield* cbw.toString();\n });\n\nexport const api = ({\n schemaImportPath,\n specImportPath,\n}: {\n schemaImportPath: string;\n specImportPath: string;\n}) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import { Api } from \"@confect/server\";`);\n yield* cbw.writeLine(`import schema from \"${schemaImportPath}\";`);\n yield* cbw.writeLine(`import spec from \"${specImportPath}\";`);\n yield* cbw.blankLine();\n yield* cbw.writeLine(`export default Api.make(schema, spec);`);\n\n return yield* cbw.toString();\n });\n\nexport const registeredFunctions = ({\n implImportPath,\n}: {\n implImportPath: string;\n}) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(\n `import { RegisteredFunctions } from \"@confect/server\";`,\n );\n yield* cbw.writeLine(`import impl from \"${implImportPath}\";`);\n yield* cbw.blankLine();\n yield* cbw.writeLine(`export default RegisteredFunctions.make(impl);`);\n\n return yield* cbw.toString();\n });\n\nexport const services = ({ schemaImportPath }: { schemaImportPath: string }) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n // Imports\n yield* cbw.writeLine(\"import {\");\n yield* cbw.indent(\n Effect.gen(function* () {\n yield* cbw.writeLine(\"ActionCtx as ActionCtx_,\");\n yield* cbw.writeLine(\"ActionRunner as ActionRunner_,\");\n yield* cbw.writeLine(\"Auth as Auth_,\");\n yield* cbw.writeLine(\"type DataModel,\");\n yield* cbw.writeLine(\"DatabaseReader as DatabaseReader_,\");\n yield* cbw.writeLine(\"DatabaseWriter as DatabaseWriter_,\");\n yield* cbw.writeLine(\"MutationCtx as MutationCtx_,\");\n yield* cbw.writeLine(\"MutationRunner as MutationRunner_,\");\n yield* cbw.writeLine(\"QueryCtx as QueryCtx_,\");\n yield* cbw.writeLine(\"QueryRunner as QueryRunner_,\");\n yield* cbw.writeLine(\"Scheduler as Scheduler_,\");\n yield* cbw.writeLine(\"Storage,\");\n yield* cbw.writeLine(\"VectorSearch as VectorSearch_,\");\n }),\n );\n yield* cbw.writeLine(`} from \"@confect/server\";`);\n yield* cbw.writeLine(\n `import type schemaDefinition from \"${schemaImportPath}\";`,\n );\n yield* cbw.blankLine();\n\n // Auth\n yield* cbw.writeLine(\"export const Auth = Auth_.Auth;\");\n yield* cbw.writeLine(\"export type Auth = typeof Auth.Identifier;\");\n yield* cbw.blankLine();\n\n // Scheduler\n yield* cbw.writeLine(\"export const Scheduler = Scheduler_.Scheduler;\");\n yield* cbw.writeLine(\n \"export type Scheduler = typeof Scheduler.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // StorageReader\n yield* cbw.writeLine(\"export const StorageReader = Storage.StorageReader;\");\n yield* cbw.writeLine(\n \"export type StorageReader = typeof StorageReader.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // StorageWriter\n yield* cbw.writeLine(\"export const StorageWriter = Storage.StorageWriter;\");\n yield* cbw.writeLine(\n \"export type StorageWriter = typeof StorageWriter.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // StorageActionWriter\n yield* cbw.writeLine(\n \"export const StorageActionWriter = Storage.StorageActionWriter;\",\n );\n yield* cbw.writeLine(\n \"export type StorageActionWriter = typeof StorageActionWriter.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // VectorSearch\n yield* cbw.writeLine(\"export const VectorSearch =\");\n yield* cbw.indent(\n cbw.writeLine(\n \"VectorSearch_.VectorSearch<DataModel.FromSchema<typeof schemaDefinition>>();\",\n ),\n );\n yield* cbw.writeLine(\n \"export type VectorSearch = typeof VectorSearch.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // DatabaseReader\n yield* cbw.writeLine(\"export const DatabaseReader =\");\n yield* cbw.indent(\n cbw.writeLine(\n \"DatabaseReader_.DatabaseReader<typeof schemaDefinition>();\",\n ),\n );\n yield* cbw.writeLine(\n \"export type DatabaseReader = typeof DatabaseReader.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // DatabaseWriter\n yield* cbw.writeLine(\"export const DatabaseWriter =\");\n yield* cbw.indent(\n cbw.writeLine(\n \"DatabaseWriter_.DatabaseWriter<typeof schemaDefinition>();\",\n ),\n );\n yield* cbw.writeLine(\n \"export type DatabaseWriter = typeof DatabaseWriter.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // QueryRunner\n yield* cbw.writeLine(\n \"export const QueryRunner = QueryRunner_.QueryRunner;\",\n );\n yield* cbw.writeLine(\n \"export type QueryRunner = typeof QueryRunner.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // MutationRunner\n yield* cbw.writeLine(\n \"export const MutationRunner = MutationRunner_.MutationRunner;\",\n );\n yield* cbw.writeLine(\n \"export type MutationRunner = typeof MutationRunner.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // ActionRunner\n yield* cbw.writeLine(\n \"export const ActionRunner = ActionRunner_.ActionRunner;\",\n );\n yield* cbw.writeLine(\n \"export type ActionRunner = typeof ActionRunner.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // QueryCtx\n yield* cbw.writeLine(\"export const QueryCtx =\");\n yield* cbw.indent(\n Effect.gen(function* () {\n yield* cbw.writeLine(\"QueryCtx_.QueryCtx<\");\n yield* cbw.indent(\n cbw.writeLine(\n \"DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>\",\n ),\n );\n yield* cbw.writeLine(\">();\");\n }),\n );\n yield* cbw.writeLine(\"export type QueryCtx = typeof QueryCtx.Identifier;\");\n yield* cbw.blankLine();\n\n // MutationCtx\n yield* cbw.writeLine(\"export const MutationCtx =\");\n yield* cbw.indent(\n Effect.gen(function* () {\n yield* cbw.writeLine(\"MutationCtx_.MutationCtx<\");\n yield* cbw.indent(\n cbw.writeLine(\n \"DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>\",\n ),\n );\n yield* cbw.writeLine(\">();\");\n }),\n );\n yield* cbw.writeLine(\n \"export type MutationCtx = typeof MutationCtx.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // ActionCtx\n yield* cbw.writeLine(\"export const ActionCtx =\");\n yield* cbw.indent(\n Effect.gen(function* () {\n yield* cbw.writeLine(\"ActionCtx_.ActionCtx<\");\n yield* cbw.indent(\n cbw.writeLine(\n \"DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>\",\n ),\n );\n yield* cbw.writeLine(\">();\");\n }),\n );\n yield* cbw.writeLine(\n \"export type ActionCtx = typeof ActionCtx.Identifier;\",\n );\n\n return yield* cbw.toString();\n });\n\nclass CodeBlockWriter {\n private readonly writer: CodeBlockWriter_;\n\n constructor(opts?: Partial<CodeBlockWriterOptions>) {\n this.writer = new CodeBlockWriter_(opts);\n }\n\n indent<E = never, R = never>(\n eff: Effect.Effect<void, E, R>,\n ): Effect.Effect<void, E, R> {\n return Effect.gen(this, function* () {\n const indentationLevel = this.writer.getIndentationLevel();\n this.writer.setIndentationLevel(indentationLevel + 1);\n yield* eff;\n this.writer.setIndentationLevel(indentationLevel);\n });\n }\n\n writeLine<E = never, R = never>(line: string): Effect.Effect<void, E, R> {\n return Effect.sync(() => {\n this.writer.writeLine(line);\n });\n }\n\n write<E = never, R = never>(text: string): Effect.Effect<void, E, R> {\n return Effect.sync(() => {\n this.writer.write(text);\n });\n }\n\n quote<E = never, R = never>(text: string): Effect.Effect<void, E, R> {\n return Effect.sync(() => {\n this.writer.quote(text);\n });\n }\n\n conditionalWriteLine<E = never, R = never>(\n condition: boolean,\n text: string,\n ): Effect.Effect<void, E, R> {\n return Effect.sync(() => {\n this.writer.conditionalWriteLine(condition, text);\n });\n }\n\n newLine<E = never, R = never>(): Effect.Effect<void, E, R> {\n return Effect.sync(() => {\n this.writer.newLine();\n });\n }\n\n blankLine<E = never, R = never>(): Effect.Effect<void, E, R> {\n return Effect.sync(() => {\n this.writer.blankLine();\n });\n }\n\n toString<E = never, R = never>(): Effect.Effect<string, E, R> {\n return Effect.sync(() => this.writer.toString());\n }\n}\n"],"mappings":";;;;AAKA,MAAa,aAAa,EACxB,WACA,eACA,oCAMA,OAAO,IAAI,aAAa;CACtB,MAAM,MAAM,IAAI,gBAAgB,EAAE,sBAAsB,GAAG,CAAC;AAE5D,QAAO,IAAI,UACT,oCAAoC,8BAA8B,IACnE;AACD,QAAO,IAAI,SAAS;AACpB,MAAK,MAAM,gBAAgB,cACzB,QAAO,IAAI,UACT,gBAAgB,aAAa,yBAAyB,MAAM,KAAK,CAAC,GAAG,UAAU,cAAc,aAAa,EAAE,IAAI,CAAC,GAClH;AAGH,QAAO,OAAO,IAAI,UAAU;EAC5B;AAEJ,MAAa,UAAU,EAAE,uBACvB,OAAO,IAAI,aAAa;CACtB,MAAM,MAAM,IAAI,gBAAgB,EAAE,sBAAsB,GAAG,CAAC;AAE5D,QAAO,IAAI,UAAU,iCAAiC,iBAAiB,IAAI;AAC3E,QAAO,IAAI,SAAS;AACpB,QAAO,IAAI,UACT,0DACD;AAED,QAAO,OAAO,IAAI,UAAU;EAC5B;AAEJ,MAAa,QAAQ,EAAE,qBACrB,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AO,MAAM,KAAK;IACvB;;CAGJ,qBACE,WACA,MAC2B;AAC3B,SAAO,OAAO,WAAW;AACvB,QAAK,OAAO,qBAAqB,WAAW,KAAK;IACjD;;CAGJ,UAA2D;AACzD,SAAO,OAAO,WAAW;AACvB,QAAK,OAAO,SAAS;IACrB;;CAGJ,YAA6D;AAC3D,SAAO,OAAO,WAAW;AACvB,QAAK,OAAO,WAAW;IACvB;;CAGJ,WAA8D;AAC5D,SAAO,OAAO,WAAW,KAAK,OAAO,UAAU,CAAC"}
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { fromGroupModulePath, getGroupSpec, modulePath } from "./GroupPath.mjs";
|
|
2
|
+
import { logFileAdded, logFileModified, logFileRemoved } from "./log.mjs";
|
|
3
|
+
import { ConvexDirectory } from "./services/ConvexDirectory.mjs";
|
|
4
|
+
import { ConfectDirectory } from "./services/ConfectDirectory.mjs";
|
|
5
|
+
import { authConfig, convexConfig, crons, functions, http } from "./templates.mjs";
|
|
6
|
+
import { GroupPaths } from "./GroupPaths.mjs";
|
|
7
|
+
import { groupPaths, make } from "./FunctionPaths.mjs";
|
|
8
|
+
import { Array, Effect, HashSet, Option, Order, Record, String, pipe } from "effect";
|
|
9
|
+
import { FileSystem, Path } from "@effect/platform";
|
|
10
|
+
|
|
11
|
+
//#region src/utils.ts
|
|
12
|
+
const removePathExtension = (pathStr) => Effect.gen(function* () {
|
|
13
|
+
const path = yield* Path.Path;
|
|
14
|
+
return String.slice(0, -path.extname(pathStr).length)(pathStr);
|
|
15
|
+
});
|
|
16
|
+
const writeFileStringAndLog = (filePath, contents) => Effect.gen(function* () {
|
|
17
|
+
const fs = yield* FileSystem.FileSystem;
|
|
18
|
+
if (!(yield* fs.exists(filePath))) {
|
|
19
|
+
yield* fs.writeFileString(filePath, contents);
|
|
20
|
+
yield* logFileAdded(filePath);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if ((yield* fs.readFileString(filePath)) !== contents) {
|
|
24
|
+
yield* fs.writeFileString(filePath, contents);
|
|
25
|
+
yield* logFileModified(filePath);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const findProjectRoot = Effect.gen(function* () {
|
|
29
|
+
const fs = yield* FileSystem.FileSystem;
|
|
30
|
+
const path = yield* Path.Path;
|
|
31
|
+
const startDir = path.resolve(".");
|
|
32
|
+
const root = path.parse(startDir).root;
|
|
33
|
+
const directories = Array.unfold(startDir, (dir) => dir === root ? Option.none() : Option.some([dir, path.dirname(dir)]));
|
|
34
|
+
const projectRoot = yield* Effect.findFirst(directories, (dir) => fs.exists(path.join(dir, "package.json")));
|
|
35
|
+
return Option.getOrElse(projectRoot, () => startDir);
|
|
36
|
+
});
|
|
37
|
+
const writeFileString = (filePath, contents) => Effect.gen(function* () {
|
|
38
|
+
const fs = yield* FileSystem.FileSystem;
|
|
39
|
+
if (!(yield* fs.exists(filePath))) {
|
|
40
|
+
yield* fs.writeFileString(filePath, contents);
|
|
41
|
+
return "Added";
|
|
42
|
+
}
|
|
43
|
+
if ((yield* fs.readFileString(filePath)) !== contents) {
|
|
44
|
+
yield* fs.writeFileString(filePath, contents);
|
|
45
|
+
return "Modified";
|
|
46
|
+
}
|
|
47
|
+
return "Unchanged";
|
|
48
|
+
});
|
|
49
|
+
const generateGroupModule = ({ groupPath, functionNames }) => Effect.gen(function* () {
|
|
50
|
+
const fs = yield* FileSystem.FileSystem;
|
|
51
|
+
const path = yield* Path.Path;
|
|
52
|
+
const convexDirectory = yield* ConvexDirectory.get;
|
|
53
|
+
const confectDirectory = yield* ConfectDirectory.get;
|
|
54
|
+
const relativeModulePath = yield* modulePath(groupPath);
|
|
55
|
+
const modulePath$1 = path.join(convexDirectory, relativeModulePath);
|
|
56
|
+
const directoryPath = path.dirname(modulePath$1);
|
|
57
|
+
if (!(yield* fs.exists(directoryPath))) yield* fs.makeDirectory(directoryPath, { recursive: true });
|
|
58
|
+
const registeredFunctionsPath = path.join(confectDirectory, "_generated", "registeredFunctions.ts");
|
|
59
|
+
const registeredFunctionsImportPath = yield* removePathExtension(path.relative(path.dirname(modulePath$1), registeredFunctionsPath));
|
|
60
|
+
const functionsContentsString = yield* functions({
|
|
61
|
+
groupPath,
|
|
62
|
+
functionNames,
|
|
63
|
+
registeredFunctionsImportPath
|
|
64
|
+
});
|
|
65
|
+
if (!(yield* fs.exists(modulePath$1))) {
|
|
66
|
+
yield* fs.writeFileString(modulePath$1, functionsContentsString);
|
|
67
|
+
return "Added";
|
|
68
|
+
}
|
|
69
|
+
if ((yield* fs.readFileString(modulePath$1)) !== functionsContentsString) {
|
|
70
|
+
yield* fs.writeFileString(modulePath$1, functionsContentsString);
|
|
71
|
+
return "Modified";
|
|
72
|
+
}
|
|
73
|
+
return "Unchanged";
|
|
74
|
+
});
|
|
75
|
+
const logGroupPaths = (groupPaths$1, logFn) => Effect.gen(function* () {
|
|
76
|
+
const path = yield* Path.Path;
|
|
77
|
+
const convexDirectory = yield* ConvexDirectory.get;
|
|
78
|
+
yield* Effect.forEach(groupPaths$1, (gp) => Effect.gen(function* () {
|
|
79
|
+
const relativeModulePath = yield* modulePath(gp);
|
|
80
|
+
yield* logFn(path.join(convexDirectory, relativeModulePath));
|
|
81
|
+
}));
|
|
82
|
+
});
|
|
83
|
+
const generateFunctions = (spec) => Effect.gen(function* () {
|
|
84
|
+
const path = yield* Path.Path;
|
|
85
|
+
const convexDirectory = yield* ConvexDirectory.get;
|
|
86
|
+
const groupPathsFromFs = yield* getGroupPathsFromFs;
|
|
87
|
+
const functionPaths = make(spec);
|
|
88
|
+
const groupPathsFromSpec = groupPaths(functionPaths);
|
|
89
|
+
const overlappingGroupPaths = GroupPaths.make(HashSet.intersection(groupPathsFromFs, groupPathsFromSpec));
|
|
90
|
+
yield* Effect.forEach(overlappingGroupPaths, (groupPath) => Effect.gen(function* () {
|
|
91
|
+
if ((yield* generateGroupModule({
|
|
92
|
+
groupPath,
|
|
93
|
+
functionNames: pipe((yield* getGroupSpec(spec, groupPath)).functions, Record.values, Array.sortBy(Order.mapInput(Order.string, (fn) => fn.name)), Array.map((fn) => fn.name))
|
|
94
|
+
})) === "Modified") {
|
|
95
|
+
const relativeModulePath = yield* modulePath(groupPath);
|
|
96
|
+
yield* logFileModified(path.join(convexDirectory, relativeModulePath));
|
|
97
|
+
}
|
|
98
|
+
}));
|
|
99
|
+
const extinctGroupPaths = GroupPaths.make(HashSet.difference(groupPathsFromFs, groupPathsFromSpec));
|
|
100
|
+
yield* removeGroups(extinctGroupPaths);
|
|
101
|
+
yield* logGroupPaths(extinctGroupPaths, logFileRemoved);
|
|
102
|
+
const newGroupPaths = GroupPaths.make(HashSet.difference(groupPathsFromSpec, groupPathsFromFs));
|
|
103
|
+
yield* writeGroups(spec, newGroupPaths);
|
|
104
|
+
yield* logGroupPaths(newGroupPaths, logFileAdded);
|
|
105
|
+
return functionPaths;
|
|
106
|
+
});
|
|
107
|
+
const getGroupPathsFromFs = Effect.gen(function* () {
|
|
108
|
+
const fs = yield* FileSystem.FileSystem;
|
|
109
|
+
const path = yield* Path.Path;
|
|
110
|
+
const convexDirectory = yield* ConvexDirectory.get;
|
|
111
|
+
const RESERVED_CONVEX_TS_FILE_NAMES = new Set([
|
|
112
|
+
"schema.ts",
|
|
113
|
+
"http.ts",
|
|
114
|
+
"crons.ts",
|
|
115
|
+
"auth.config.ts",
|
|
116
|
+
"convex.config.ts"
|
|
117
|
+
]);
|
|
118
|
+
return pipe(yield* pipe(yield* fs.readDirectory(convexDirectory, { recursive: true }), Array.filter((convexPath) => path.extname(convexPath) === ".ts" && !RESERVED_CONVEX_TS_FILE_NAMES.has(path.basename(convexPath)) && path.basename(path.dirname(convexPath)) !== "_generated"), Effect.forEach((groupModulePath) => fromGroupModulePath(groupModulePath))), HashSet.fromIterable, GroupPaths.make);
|
|
119
|
+
});
|
|
120
|
+
const removeGroups = (groupPaths$1) => Effect.gen(function* () {
|
|
121
|
+
const fs = yield* FileSystem.FileSystem;
|
|
122
|
+
const path = yield* Path.Path;
|
|
123
|
+
const convexDirectory = yield* ConvexDirectory.get;
|
|
124
|
+
yield* Effect.all(HashSet.map(groupPaths$1, (groupPath) => Effect.gen(function* () {
|
|
125
|
+
const relativeModulePath = yield* modulePath(groupPath);
|
|
126
|
+
const modulePath$1 = path.join(convexDirectory, relativeModulePath);
|
|
127
|
+
yield* Effect.logDebug(`Removing group '${relativeModulePath}'...`);
|
|
128
|
+
yield* fs.remove(modulePath$1);
|
|
129
|
+
yield* Effect.logDebug(`Group '${relativeModulePath}' removed`);
|
|
130
|
+
})), { concurrency: "unbounded" });
|
|
131
|
+
});
|
|
132
|
+
const writeGroups = (spec, groupPaths$1) => Effect.forEach(groupPaths$1, (groupPath) => Effect.gen(function* () {
|
|
133
|
+
const functionNames = pipe((yield* getGroupSpec(spec, groupPath)).functions, Record.values, Array.sortBy(Order.mapInput(Order.string, (fn) => fn.name)), Array.map((fn) => fn.name));
|
|
134
|
+
yield* Effect.logDebug(`Generating group ${groupPath}...`);
|
|
135
|
+
yield* generateGroupModule({
|
|
136
|
+
groupPath,
|
|
137
|
+
functionNames
|
|
138
|
+
});
|
|
139
|
+
yield* Effect.logDebug(`Group ${groupPath} generated`);
|
|
140
|
+
}));
|
|
141
|
+
const generateOptionalFile = (confectFile, convexFile, generateContents) => Effect.gen(function* () {
|
|
142
|
+
const fs = yield* FileSystem.FileSystem;
|
|
143
|
+
const path = yield* Path.Path;
|
|
144
|
+
const confectDirectory = yield* ConfectDirectory.get;
|
|
145
|
+
const convexDirectory = yield* ConvexDirectory.get;
|
|
146
|
+
const confectFilePath = path.join(confectDirectory, confectFile);
|
|
147
|
+
if (!(yield* fs.exists(confectFilePath))) return Option.none();
|
|
148
|
+
const convexFilePath = path.join(convexDirectory, convexFile);
|
|
149
|
+
const change = yield* writeFileString(convexFilePath, yield* generateContents(yield* removePathExtension(path.relative(path.dirname(convexFilePath), confectFilePath))));
|
|
150
|
+
return Option.some({
|
|
151
|
+
change,
|
|
152
|
+
convexFilePath
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
const generateHttp = generateOptionalFile("http.ts", "http.ts", (importPath) => http({ httpImportPath: importPath }));
|
|
156
|
+
const generateConvexConfig = generateOptionalFile("app.ts", "convex.config.ts", (importPath) => convexConfig({ appImportPath: importPath }));
|
|
157
|
+
const generateCrons = generateOptionalFile("crons.ts", "crons.ts", (importPath) => crons({ cronsImportPath: importPath }));
|
|
158
|
+
const generateAuthConfig = generateOptionalFile("auth.ts", "auth.config.ts", (importPath) => authConfig({ authImportPath: importPath }));
|
|
159
|
+
|
|
160
|
+
//#endregion
|
|
161
|
+
export { generateAuthConfig, generateConvexConfig, generateCrons, generateFunctions, generateHttp, removeGroups, removePathExtension, writeFileStringAndLog, writeGroups };
|
|
162
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":["GroupPath.modulePath","modulePath","templates.functions","groupPaths","FunctionPaths.make","FunctionPaths.groupPaths","GroupPath.getGroupSpec","GroupPath.fromGroupModulePath","templates.http","templates.convexConfig","templates.crons","templates.authConfig"],"sources":["../src/utils.ts"],"sourcesContent":["import type { FunctionSpec, Spec } from \"@confect/core\";\nimport { FileSystem, Path } from \"@effect/platform\";\nimport type { PlatformError } from \"@effect/platform/Error\";\nimport {\n Array,\n Effect,\n HashSet,\n Option,\n Order,\n pipe,\n Record,\n String,\n} from \"effect\";\nimport * as FunctionPaths from \"./FunctionPaths\";\nimport * as GroupPath from \"./GroupPath\";\nimport * as GroupPaths from \"./GroupPaths\";\nimport { logFileAdded, logFileModified, logFileRemoved } from \"./log\";\nimport { ConfectDirectory } from \"./services/ConfectDirectory\";\nimport { ConvexDirectory } from \"./services/ConvexDirectory\";\nimport * as templates from \"./templates\";\n\nexport const removePathExtension = (pathStr: string) =>\n Effect.gen(function* () {\n const path = yield* Path.Path;\n\n return String.slice(0, -path.extname(pathStr).length)(pathStr);\n });\n\nexport const writeFileStringAndLog = (filePath: string, contents: string) =>\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n if (!(yield* fs.exists(filePath))) {\n yield* fs.writeFileString(filePath, contents);\n yield* logFileAdded(filePath);\n return;\n }\n const existing = yield* fs.readFileString(filePath);\n if (existing !== contents) {\n yield* fs.writeFileString(filePath, contents);\n yield* logFileModified(filePath);\n }\n });\n\nexport const findProjectRoot = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n\n const startDir = path.resolve(\".\");\n const root = path.parse(startDir).root;\n\n const directories = Array.unfold(startDir, (dir) =>\n dir === root\n ? Option.none()\n : Option.some([dir, path.dirname(dir)] as const),\n );\n\n const projectRoot = yield* Effect.findFirst(directories, (dir) =>\n fs.exists(path.join(dir, \"package.json\")),\n );\n\n return Option.getOrElse(projectRoot, () => startDir);\n});\n\nexport type WriteChange = \"Added\" | \"Modified\" | \"Unchanged\";\n\nexport const writeFileString = (\n filePath: string,\n contents: string,\n): Effect.Effect<WriteChange, PlatformError, FileSystem.FileSystem> =>\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n\n if (!(yield* fs.exists(filePath))) {\n yield* fs.writeFileString(filePath, contents);\n return \"Added\";\n }\n const existing = yield* fs.readFileString(filePath);\n if (existing !== contents) {\n yield* fs.writeFileString(filePath, contents);\n return \"Modified\";\n }\n return \"Unchanged\";\n });\n\nexport const generateGroupModule = ({\n groupPath,\n functionNames,\n}: {\n groupPath: GroupPath.GroupPath;\n functionNames: string[];\n}) =>\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const relativeModulePath = yield* GroupPath.modulePath(groupPath);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n\n const directoryPath = path.dirname(modulePath);\n if (!(yield* fs.exists(directoryPath))) {\n yield* fs.makeDirectory(directoryPath, { recursive: true });\n }\n\n const registeredFunctionsPath = path.join(\n confectDirectory,\n \"_generated\",\n \"registeredFunctions.ts\",\n );\n const registeredFunctionsImportPath = yield* removePathExtension(\n path.relative(path.dirname(modulePath), registeredFunctionsPath),\n );\n\n const functionsContentsString = yield* templates.functions({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n });\n\n if (!(yield* fs.exists(modulePath))) {\n yield* fs.writeFileString(modulePath, functionsContentsString);\n return \"Added\" as const;\n }\n const existing = yield* fs.readFileString(modulePath);\n if (existing !== functionsContentsString) {\n yield* fs.writeFileString(modulePath, functionsContentsString);\n return \"Modified\" as const;\n }\n return \"Unchanged\" as const;\n });\n\nconst logGroupPaths = <R>(\n groupPaths: GroupPaths.GroupPaths,\n logFn: (fullPath: string) => Effect.Effect<void, never, R>,\n) =>\n Effect.gen(function* () {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n yield* Effect.forEach(groupPaths, (gp) =>\n Effect.gen(function* () {\n const relativeModulePath = yield* GroupPath.modulePath(gp);\n yield* logFn(path.join(convexDirectory, relativeModulePath));\n }),\n );\n });\n\nexport const generateFunctions = (spec: Spec.AnyWithProps) =>\n Effect.gen(function* () {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n const groupPathsFromFs = yield* getGroupPathsFromFs;\n const functionPaths = FunctionPaths.make(spec);\n const groupPathsFromSpec = FunctionPaths.groupPaths(functionPaths);\n\n const overlappingGroupPaths = GroupPaths.GroupPaths.make(\n HashSet.intersection(groupPathsFromFs, groupPathsFromSpec),\n );\n yield* Effect.forEach(overlappingGroupPaths, (groupPath) =>\n Effect.gen(function* () {\n const group = yield* GroupPath.getGroupSpec(spec, groupPath);\n const functionNames = pipe(\n group.functions,\n Record.values,\n Array.sortBy(\n Order.mapInput(\n Order.string,\n (fn: FunctionSpec.AnyWithProps) => fn.name,\n ),\n ),\n Array.map((fn) => fn.name),\n );\n const result = yield* generateGroupModule({ groupPath, functionNames });\n if (result === \"Modified\") {\n const relativeModulePath = yield* GroupPath.modulePath(groupPath);\n yield* logFileModified(\n path.join(convexDirectory, relativeModulePath),\n );\n }\n }),\n );\n\n const extinctGroupPaths = GroupPaths.GroupPaths.make(\n HashSet.difference(groupPathsFromFs, groupPathsFromSpec),\n );\n yield* removeGroups(extinctGroupPaths);\n yield* logGroupPaths(extinctGroupPaths, logFileRemoved);\n\n const newGroupPaths = GroupPaths.GroupPaths.make(\n HashSet.difference(groupPathsFromSpec, groupPathsFromFs),\n );\n yield* writeGroups(spec, newGroupPaths);\n yield* logGroupPaths(newGroupPaths, logFileAdded);\n\n return functionPaths;\n });\n\nconst getGroupPathsFromFs = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n const RESERVED_CONVEX_TS_FILE_NAMES = new Set([\n \"schema.ts\",\n \"http.ts\",\n \"crons.ts\",\n \"auth.config.ts\",\n \"convex.config.ts\",\n ]);\n\n const allConvexPaths = yield* fs.readDirectory(convexDirectory, {\n recursive: true,\n });\n const groupPathArray = yield* pipe(\n allConvexPaths,\n Array.filter(\n (convexPath) =>\n path.extname(convexPath) === \".ts\" &&\n !RESERVED_CONVEX_TS_FILE_NAMES.has(path.basename(convexPath)) &&\n path.basename(path.dirname(convexPath)) !== \"_generated\",\n ),\n Effect.forEach((groupModulePath) =>\n GroupPath.fromGroupModulePath(groupModulePath),\n ),\n );\n return pipe(groupPathArray, HashSet.fromIterable, GroupPaths.GroupPaths.make);\n});\n\nexport const removeGroups = (groupPaths: GroupPaths.GroupPaths) =>\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n yield* Effect.all(\n HashSet.map(groupPaths, (groupPath) =>\n Effect.gen(function* () {\n const relativeModulePath = yield* GroupPath.modulePath(groupPath);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n\n yield* Effect.logDebug(`Removing group '${relativeModulePath}'...`);\n\n yield* fs.remove(modulePath);\n yield* Effect.logDebug(`Group '${relativeModulePath}' removed`);\n }),\n ),\n { concurrency: \"unbounded\" },\n );\n });\n\nexport const writeGroups = (\n spec: Spec.AnyWithProps,\n groupPaths: GroupPaths.GroupPaths,\n) =>\n Effect.forEach(groupPaths, (groupPath) =>\n Effect.gen(function* () {\n const group = yield* GroupPath.getGroupSpec(spec, groupPath);\n\n const functionNames = pipe(\n group.functions,\n Record.values,\n Array.sortBy(\n Order.mapInput(\n Order.string,\n (fn: FunctionSpec.AnyWithProps) => fn.name,\n ),\n ),\n Array.map((fn) => fn.name),\n );\n\n yield* Effect.logDebug(`Generating group ${groupPath}...`);\n yield* generateGroupModule({\n groupPath,\n functionNames,\n });\n yield* Effect.logDebug(`Group ${groupPath} generated`);\n }),\n );\n\nconst generateOptionalFile = (\n confectFile: string,\n convexFile: string,\n generateContents: (importPath: string) => Effect.Effect<string>,\n) =>\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const convexDirectory = yield* ConvexDirectory.get;\n\n const confectFilePath = path.join(confectDirectory, confectFile);\n\n if (!(yield* fs.exists(confectFilePath))) {\n return Option.none();\n }\n\n const convexFilePath = path.join(convexDirectory, convexFile);\n const relativeImportPath = path.relative(\n path.dirname(convexFilePath),\n confectFilePath,\n );\n const importPathWithoutExt = yield* removePathExtension(relativeImportPath);\n const contents = yield* generateContents(importPathWithoutExt);\n const change = yield* writeFileString(convexFilePath, contents);\n return Option.some({ change, convexFilePath });\n });\n\nexport const generateHttp = generateOptionalFile(\n \"http.ts\",\n \"http.ts\",\n (importPath) => templates.http({ httpImportPath: importPath }),\n);\n\nexport const generateConvexConfig = generateOptionalFile(\n \"app.ts\",\n \"convex.config.ts\",\n (importPath) => templates.convexConfig({ appImportPath: importPath }),\n);\n\nexport const generateCrons = generateOptionalFile(\n \"crons.ts\",\n \"crons.ts\",\n (importPath) => templates.crons({ cronsImportPath: importPath }),\n);\n\nexport const generateAuthConfig = generateOptionalFile(\n \"auth.ts\",\n \"auth.config.ts\",\n (importPath) => templates.authConfig({ authImportPath: importPath }),\n);\n"],"mappings":";;;;;;;;;;;AAqBA,MAAa,uBAAuB,YAClC,OAAO,IAAI,aAAa;CACtB,MAAM,OAAO,OAAO,KAAK;AAEzB,QAAO,OAAO,MAAM,GAAG,CAAC,KAAK,QAAQ,QAAQ,CAAC,OAAO,CAAC,QAAQ;EAC9D;AAEJ,MAAa,yBAAyB,UAAkB,aACtD,OAAO,IAAI,aAAa;CACtB,MAAM,KAAK,OAAO,WAAW;AAC7B,KAAI,EAAE,OAAO,GAAG,OAAO,SAAS,GAAG;AACjC,SAAO,GAAG,gBAAgB,UAAU,SAAS;AAC7C,SAAO,aAAa,SAAS;AAC7B;;AAGF,MADiB,OAAO,GAAG,eAAe,SAAS,MAClC,UAAU;AACzB,SAAO,GAAG,gBAAgB,UAAU,SAAS;AAC7C,SAAO,gBAAgB,SAAS;;EAElC;AAEJ,MAAa,kBAAkB,OAAO,IAAI,aAAa;CACrD,MAAM,KAAK,OAAO,WAAW;CAC7B,MAAM,OAAO,OAAO,KAAK;CAEzB,MAAM,WAAW,KAAK,QAAQ,IAAI;CAClC,MAAM,OAAO,KAAK,MAAM,SAAS,CAAC;CAElC,MAAM,cAAc,MAAM,OAAO,WAAW,QAC1C,QAAQ,OACJ,OAAO,MAAM,GACb,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,IAAI,CAAC,CAAU,CACnD;CAED,MAAM,cAAc,OAAO,OAAO,UAAU,cAAc,QACxD,GAAG,OAAO,KAAK,KAAK,KAAK,eAAe,CAAC,CAC1C;AAED,QAAO,OAAO,UAAU,mBAAmB,SAAS;EACpD;AAIF,MAAa,mBACX,UACA,aAEA,OAAO,IAAI,aAAa;CACtB,MAAM,KAAK,OAAO,WAAW;AAE7B,KAAI,EAAE,OAAO,GAAG,OAAO,SAAS,GAAG;AACjC,SAAO,GAAG,gBAAg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OAAO,OAAO,KAAK;CACzB,MAAM,mBAAmB,OAAO,iBAAiB;CACjD,MAAM,kBAAkB,OAAO,gBAAgB;CAE/C,MAAM,kBAAkB,KAAK,KAAK,kBAAkB,YAAY;AAEhE,KAAI,EAAE,OAAO,GAAG,OAAO,gBAAgB,EACrC,QAAO,OAAO,MAAM;CAGtB,MAAM,iBAAiB,KAAK,KAAK,iBAAiB,WAAW;CAO7D,MAAM,SAAS,OAAO,gBAAgB,gBADrB,OAAO,iBADK,OAAO,oBAJT,KAAK,SAC9B,KAAK,QAAQ,eAAe,EAC5B,gBACD,CAC0E,CACb,CACC;AAC/D,QAAO,OAAO,KAAK;EAAE;EAAQ;EAAgB,CAAC;EAC9C;AAEJ,MAAa,eAAe,qBAC1B,WACA,YACC,eAAeE,KAAe,EAAE,gBAAgB,YAAY,CAAC,CAC/D;AAED,MAAa,uBAAuB,qBAClC,UACA,qBACC,eAAeC,aAAuB,EAAE,eAAe,YAAY,CAAC,CACtE;AAED,MAAa,gBAAgB,qBAC3B,YACA,aACC,eAAeC,MAAgB,EAAE,iBAAiB,YAAY,CAAC,CACjE;AAED,MAAa,qBAAqB,qBAChC,WACA,mBACC,eAAeC,WAAqB,EAAE,gBAAgB,YAAY,CAAC,CACrE"}
|
package/package.json
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@confect/cli",
|
|
3
|
+
"version": "1.0.0-next.0",
|
|
4
|
+
"description": "Confect CLI",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/rjdellecese/confect.git"
|
|
8
|
+
},
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/rjdellecese/confect/issues"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://confect.rjdellecese.com",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"type": "module",
|
|
15
|
+
"bin": {
|
|
16
|
+
"confect": "./dist/index.mjs"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"CHANGELOG.md",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"README.md",
|
|
22
|
+
"dist",
|
|
23
|
+
"package.json",
|
|
24
|
+
"src"
|
|
25
|
+
],
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"effect",
|
|
35
|
+
"convex",
|
|
36
|
+
"cli"
|
|
37
|
+
],
|
|
38
|
+
"author": "RJ Dellecese",
|
|
39
|
+
"license": "ISC",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@effect/cli": "^0.72.1",
|
|
42
|
+
"@effect/printer": "^0.47.0",
|
|
43
|
+
"@effect/printer-ansi": "^0.47.0",
|
|
44
|
+
"code-block-writer": "^13.0.3",
|
|
45
|
+
"esbuild": "^0.25.0",
|
|
46
|
+
"tsx": "^4.19.2"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@effect/language-service": "0.56.0",
|
|
50
|
+
"@effect/platform-node": "0.100.0",
|
|
51
|
+
"@effect/vitest": "0.27.0",
|
|
52
|
+
"@eslint/js": "9.39.1",
|
|
53
|
+
"@tsconfig/strictest": "2.0.8",
|
|
54
|
+
"@types/node": "24.10.1",
|
|
55
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
56
|
+
"eslint": "9.39.1",
|
|
57
|
+
"prettier": "3.6.2",
|
|
58
|
+
"tsdown": "0.16.4",
|
|
59
|
+
"typescript": "5.9.3",
|
|
60
|
+
"typescript-eslint": "8.46.4",
|
|
61
|
+
"vite": "7.2.2",
|
|
62
|
+
"vite-tsconfig-paths": "5.1.4",
|
|
63
|
+
"vitest": "3.2.4"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"@effect/platform": "^0.93.2",
|
|
67
|
+
"effect": "^3.19.3",
|
|
68
|
+
"@confect/server": "1.0.0-next.0"
|
|
69
|
+
},
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": ">=22",
|
|
72
|
+
"pnpm": ">=10"
|
|
73
|
+
},
|
|
74
|
+
"main": "./dist/index.js",
|
|
75
|
+
"module": "./dist/index.js",
|
|
76
|
+
"types": "./dist/index.d.ts",
|
|
77
|
+
"scripts": {
|
|
78
|
+
"build": "tsdown --config-loader unrun",
|
|
79
|
+
"dev": "tsdown --watch",
|
|
80
|
+
"test": "vitest run",
|
|
81
|
+
"typecheck": "tsc --noEmit --project tsconfig.json",
|
|
82
|
+
"fix": "prettier --write . && eslint --fix . --max-warnings=0",
|
|
83
|
+
"lint": "prettier --check . && eslint . --max-warnings=0",
|
|
84
|
+
"clean": "rm -rf dist coverage node_modules"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import * as GroupPath from "./GroupPath";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The path to a function in the Confect API.
|
|
6
|
+
*/
|
|
7
|
+
export class FunctionPath extends Schema.Class<FunctionPath>("FunctionPath")({
|
|
8
|
+
// TODO: Support root-level functions (also must be supported in the other packages, e.g. `core` and `server`)
|
|
9
|
+
groupPath: GroupPath.GroupPath,
|
|
10
|
+
name: Schema.NonEmptyString,
|
|
11
|
+
}) {}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Get the group path from a function path.
|
|
15
|
+
*/
|
|
16
|
+
export const groupPath = (functionPath: FunctionPath): GroupPath.GroupPath =>
|
|
17
|
+
functionPath.groupPath;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get the function name from a function path.
|
|
21
|
+
*/
|
|
22
|
+
export const name = (functionPath: FunctionPath): string => functionPath.name;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Get the function path as a string.
|
|
26
|
+
*/
|
|
27
|
+
export const toString = (functionPath: FunctionPath): string =>
|
|
28
|
+
`${GroupPath.toString(functionPath.groupPath)}.${functionPath.name}`;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { GroupSpec, Spec } from "@confect/core";
|
|
2
|
+
import { HashSet, Option, pipe, Record, Schema } from "effect";
|
|
3
|
+
import * as FunctionPath from "./FunctionPath";
|
|
4
|
+
import * as GroupPath from "./GroupPath";
|
|
5
|
+
import * as GroupPaths from "./GroupPaths";
|
|
6
|
+
|
|
7
|
+
export const FunctionPaths = Schema.HashSetFromSelf(
|
|
8
|
+
FunctionPath.FunctionPath,
|
|
9
|
+
).pipe(Schema.brand("@confect/cli/FunctionPaths"));
|
|
10
|
+
export type FunctionPaths = typeof FunctionPaths.Type;
|
|
11
|
+
|
|
12
|
+
export const make = (spec: Spec.AnyWithProps): FunctionPaths =>
|
|
13
|
+
makeHelper(spec.groups, Option.none(), FunctionPaths.make(HashSet.empty()));
|
|
14
|
+
|
|
15
|
+
const makeHelper = (
|
|
16
|
+
groups: {
|
|
17
|
+
[key: string]: GroupSpec.AnyWithProps;
|
|
18
|
+
},
|
|
19
|
+
currentGroupPath: Option.Option<GroupPath.GroupPath>,
|
|
20
|
+
apiPaths: FunctionPaths,
|
|
21
|
+
): FunctionPaths =>
|
|
22
|
+
Record.reduce(groups, apiPaths, (acc, group, groupName) => {
|
|
23
|
+
const groupPath = Option.match(currentGroupPath, {
|
|
24
|
+
onNone: () => GroupPath.make([groupName]),
|
|
25
|
+
onSome: (path) => GroupPath.append(path, groupName),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const accWithFunctions = Record.reduce(
|
|
29
|
+
group.functions,
|
|
30
|
+
acc,
|
|
31
|
+
(acc_, _fn, functionName) =>
|
|
32
|
+
FunctionPaths.make(
|
|
33
|
+
HashSet.add(
|
|
34
|
+
acc_,
|
|
35
|
+
FunctionPath.FunctionPath.make({
|
|
36
|
+
groupPath,
|
|
37
|
+
name: functionName,
|
|
38
|
+
}),
|
|
39
|
+
),
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return makeHelper(group.groups, Option.some(groupPath), accWithFunctions);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export const groupPaths = (
|
|
47
|
+
functionPaths: FunctionPaths,
|
|
48
|
+
): GroupPaths.GroupPaths =>
|
|
49
|
+
pipe(
|
|
50
|
+
functionPaths,
|
|
51
|
+
HashSet.map(FunctionPath.groupPath),
|
|
52
|
+
GroupPaths.GroupPaths.make,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export const diff = (
|
|
56
|
+
previousFunctions: FunctionPaths,
|
|
57
|
+
currentFunctions: FunctionPaths,
|
|
58
|
+
): {
|
|
59
|
+
functionsAdded: FunctionPaths;
|
|
60
|
+
functionsRemoved: FunctionPaths;
|
|
61
|
+
groupsRemoved: GroupPaths.GroupPaths;
|
|
62
|
+
groupsAdded: GroupPaths.GroupPaths;
|
|
63
|
+
groupsChanged: GroupPaths.GroupPaths;
|
|
64
|
+
} => {
|
|
65
|
+
const currentGroups = groupPaths(currentFunctions);
|
|
66
|
+
const previousGroups = groupPaths(previousFunctions);
|
|
67
|
+
|
|
68
|
+
const groupsAdded = GroupPaths.GroupPaths.make(
|
|
69
|
+
HashSet.difference(currentGroups, previousGroups),
|
|
70
|
+
);
|
|
71
|
+
const groupsRemoved = GroupPaths.GroupPaths.make(
|
|
72
|
+
HashSet.difference(previousGroups, currentGroups),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const functionsAdded = FunctionPaths.make(
|
|
76
|
+
HashSet.difference(currentFunctions, previousFunctions),
|
|
77
|
+
);
|
|
78
|
+
const existingGroupsToWhichFunctionsWereAdded = GroupPaths.GroupPaths.make(
|
|
79
|
+
HashSet.intersection(currentGroups, groupPaths(functionsAdded)),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const functionsRemoved = FunctionPaths.make(
|
|
83
|
+
HashSet.difference(previousFunctions, currentFunctions),
|
|
84
|
+
);
|
|
85
|
+
const existingGroupsToWhichFunctionsWereRemoved = GroupPaths.GroupPaths.make(
|
|
86
|
+
HashSet.intersection(previousGroups, groupPaths(functionsRemoved)),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const groupsChanged = pipe(
|
|
90
|
+
existingGroupsToWhichFunctionsWereAdded,
|
|
91
|
+
HashSet.union(existingGroupsToWhichFunctionsWereRemoved),
|
|
92
|
+
HashSet.difference(HashSet.union(groupsAdded, groupsRemoved)),
|
|
93
|
+
GroupPaths.GroupPaths.make,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
functionsAdded,
|
|
98
|
+
functionsRemoved,
|
|
99
|
+
groupsRemoved,
|
|
100
|
+
groupsAdded,
|
|
101
|
+
groupsChanged,
|
|
102
|
+
};
|
|
103
|
+
};
|