@monorise/cli 1.0.5 → 3.0.1

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/dist/cli.d.ts CHANGED
@@ -1,4 +1 @@
1
1
  #!/usr/bin/env node
2
- import 'tsx';
3
- import 'tsconfig-paths/register.js';
4
- //# sourceMappingURL=cli.d.ts.map
package/dist/cli.js CHANGED
@@ -1,104 +1,98 @@
1
1
  #!/usr/bin/env node
2
- import 'tsx';
3
- import 'tsconfig-paths/register.js';
4
- import fs from 'node:fs';
5
- import path from 'node:path';
6
- async function main() {
7
- // Check for monorise.config.ts or monorise.config.js
8
- const configFilePathTS = path.resolve('./monorise.config.ts');
9
- const configFilePathJS = path.resolve('./monorise.config.js');
10
- let configFilePath;
11
- if (fs.existsSync(configFilePathTS)) {
12
- configFilePath = configFilePathTS;
13
- }
14
- else if (fs.existsSync(configFilePathJS)) {
15
- configFilePath = configFilePathJS;
16
- }
17
- else {
18
- throw new Error('Neither monorise.config.ts nor monorise.config.js found in the root of the project.');
19
- }
20
- // Dynamically import the config file
21
- const monoriseConfig = await import(configFilePath);
22
- const configDir = path.resolve(monoriseConfig.default.configDir);
23
- const configOutputPath = path.join(configDir, 'index.ts');
24
- const initialOutputContent = `
2
+
3
+ // cli.ts
4
+ import "tsx";
5
+ import "tsconfig-paths/register.js";
6
+ import fs from "fs";
7
+ import path from "path";
8
+ import chokidar from "chokidar";
9
+ function kebabToCamel(str) {
10
+ return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
11
+ }
12
+ function kebabToPascal(kebab) {
13
+ return kebab.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
14
+ }
15
+ async function generateConfigFile(configDir, monoriseOutputDir) {
16
+ const configOutputPath = path.join(monoriseOutputDir, "config.ts");
17
+ const initialConfigContent = `
25
18
  export enum Entity {}
26
19
  `;
27
- // Clean up and initialize index.ts file, so that tsconfig resolves import correctly
28
- fs.writeFileSync(configOutputPath, initialOutputContent);
29
- const files = fs
30
- .readdirSync(configDir)
31
- .filter((file) => file.endsWith('.ts') && file !== 'index.ts');
32
- const names = new Set();
33
- const nameRegex = /^[a-z]+(-[a-z]+)*$/;
34
- const imports = [];
35
- const importTypes = [];
36
- const arrayElements = [];
37
- const enumEntries = [];
38
- const typeEntries = [];
39
- const schemaMapEntries = [];
40
- const configEntries = [];
41
- const schemaEntries = [];
42
- const allowedEntityEntries = [];
43
- const entityWithEmailAuthEntries = [];
44
- for (const file of files) {
45
- const fullPath = path.join(configDir, file);
46
- const module = await import(fullPath);
47
- const config = module.default;
48
- // Validate name
49
- if (!nameRegex.test(config.name)) {
50
- throw new Error(`Invalid name format: ${config.name} in ${file}. Must be kebab-case.`);
51
- }
52
- if (names.has(config.name)) {
53
- throw new Error(`Duplicate name found: ${config.name} in ${file}`);
54
- }
55
- names.add(config.name);
56
- // Generate import and array element
57
- const fileName = file.replace(/\.ts$/, '');
58
- const variableName = kebabToCamel(fileName);
59
- imports.push(`import ${variableName} from './${fileName}';`);
60
- importTypes.push(`import type ${variableName} from './${fileName}';`);
61
- arrayElements.push(variableName);
62
- // Generate enum entry
63
- const enumKey = config.name.toUpperCase().replace(/-/g, '_');
64
- enumEntries.push(`${enumKey} = '${config.name}'`);
65
- typeEntries.push(`export type ${kebabToPascal(config.name)}Type = z.infer<(typeof ${variableName})['finalSchema']>;`);
66
- schemaMapEntries.push(`${kebabToCamel(config.name)}: ${kebabToPascal(config.name)}Type;`);
67
- // Generate config entry
68
- configEntries.push(`[Entity.${enumKey}]: ${kebabToCamel(config.name)},`);
69
- schemaEntries.push(`[Entity.${enumKey}]: ${kebabToCamel(config.name)}.finalSchema,`);
70
- allowedEntityEntries.push(`Entity.${enumKey}`);
71
- if (config.authMethod?.email) {
72
- entityWithEmailAuthEntries.push(`Entity.${enumKey}`);
73
- }
20
+ fs.writeFileSync(configOutputPath, initialConfigContent);
21
+ const files = fs.readdirSync(configDir).filter((file) => file.endsWith(".ts") && file !== "index.ts");
22
+ const names = /* @__PURE__ */ new Set();
23
+ const nameRegex = /^[a-z]+(-[a-z]+)*$/;
24
+ const imports = [];
25
+ const enumEntries = [];
26
+ const typeEntries = [];
27
+ const schemaMapEntries = [];
28
+ const configEntries = [];
29
+ const schemaEntries = [];
30
+ const allowedEntityEntries = [];
31
+ const entityWithEmailAuthEntries = [];
32
+ const relativePathToConfigDir = path.relative(monoriseOutputDir, configDir);
33
+ const importPathPrefix = relativePathToConfigDir ? `${relativePathToConfigDir}/` : "./";
34
+ for (const file of files) {
35
+ const fullPath = path.join(configDir, file);
36
+ const module = await import(fullPath);
37
+ const config = module.default;
38
+ if (!nameRegex.test(config.name)) {
39
+ throw new Error(
40
+ `Invalid name format: ${config.name} in ${file}. Must be kebab-case.`
41
+ );
42
+ }
43
+ if (names.has(config.name)) {
44
+ throw new Error(`Duplicate name found: ${config.name} in ${file}`);
74
45
  }
75
- const outputContent = `
46
+ names.add(config.name);
47
+ const fileName = file.replace(/\.ts$/, "");
48
+ const variableName = kebabToCamel(fileName);
49
+ imports.push(
50
+ `import ${variableName} from '${importPathPrefix}${fileName}';`
51
+ );
52
+ const enumKey = config.name.toUpperCase().replace(/-/g, "_");
53
+ enumEntries.push(`${enumKey} = '${config.name}'`);
54
+ typeEntries.push(
55
+ `export type ${kebabToPascal(config.name)}Type = z.infer<(typeof ${variableName})['finalSchema']>;`
56
+ );
57
+ schemaMapEntries.push(
58
+ `[Entity.${enumKey}]: ${kebabToPascal(config.name)}Type;`
59
+ );
60
+ configEntries.push(`[Entity.${enumKey}]: ${kebabToCamel(config.name)},`);
61
+ schemaEntries.push(
62
+ `[Entity.${enumKey}]: ${kebabToCamel(config.name)}.finalSchema,`
63
+ );
64
+ allowedEntityEntries.push(`Entity.${enumKey}`);
65
+ if (config.authMethod?.email) {
66
+ entityWithEmailAuthEntries.push(`Entity.${enumKey}`);
67
+ }
68
+ }
69
+ const configOutputContent = `
76
70
  import type { z } from 'zod';
77
- ${imports.join('\n')}
71
+ ${imports.join("\n")}
78
72
 
79
73
  export enum Entity {
80
- ${enumEntries.join(',\n ')}
74
+ ${enumEntries.join(",\n ")}
81
75
  }
82
76
 
83
- ${typeEntries.join('\n')}
77
+ ${typeEntries.join("\n")}
84
78
 
85
79
  export interface EntitySchemaMap {
86
- ${schemaMapEntries.join('\n ')}
80
+ ${schemaMapEntries.join("\n ")}
87
81
  }
88
82
 
89
83
  const EntityConfig = {
90
- ${configEntries.join('\n ')}
84
+ ${configEntries.join("\n ")}
91
85
  };
92
86
 
93
87
  const FormSchema = {
94
- ${schemaEntries.join('\n ')}
88
+ ${schemaEntries.join("\n ")}
95
89
  };
96
90
 
97
91
  const AllowedEntityTypes = [
98
- ${allowedEntityEntries.join(',\n ')}
92
+ ${allowedEntityEntries.join(",\n ")}
99
93
  ];
100
94
 
101
- const EmailAuthEnabledEntities = [${entityWithEmailAuthEntries.join(', ')}];
95
+ const EmailAuthEnabledEntities: Entity[] = [${entityWithEmailAuthEntries.join(", ")}];
102
96
 
103
97
  export {
104
98
  EntityConfig,
@@ -107,32 +101,361 @@ export {
107
101
  EmailAuthEnabledEntities,
108
102
  };
109
103
 
104
+ const config = {
105
+ EntityConfig,
106
+ FormSchema,
107
+ AllowedEntityTypes,
108
+ EmailAuthEnabledEntities,
109
+ };
110
+
111
+ export default config;
112
+
110
113
  declare module '@monorise/base' {
111
114
  export enum Entity {
112
- ${enumEntries.join(',\n ')}
115
+ ${enumEntries.join(",\n ")}
113
116
  }
114
117
 
115
- ${typeEntries.join('\n ')}
118
+ ${typeEntries.join("\n ")}
116
119
 
117
120
  export interface EntitySchemaMap {
118
- ${schemaMapEntries.join('\n ')}
121
+ ${schemaMapEntries.join("\n ")}
119
122
  }
120
123
  }
121
124
  `;
122
- fs.writeFileSync(configOutputPath, outputContent);
123
- console.log('Successfully generated entity configurations and enum!');
125
+ fs.writeFileSync(configOutputPath, configOutputContent);
126
+ console.log("Successfully generated config.ts!");
127
+ return configOutputPath;
124
128
  }
125
- function kebabToCamel(str) {
126
- return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
129
+ async function generateHandleFile(monoriseConfig, projectRoot, monoriseOutputDir) {
130
+ const handleOutputPath = path.join(monoriseOutputDir, "handle.ts");
131
+ const customRoutesPath = monoriseConfig.customRoutes;
132
+ let routesImportLine = "";
133
+ let appHandlerPayload = "{}";
134
+ if (customRoutesPath) {
135
+ const absoluteCustomRoutesPath = path.resolve(
136
+ projectRoot,
137
+ customRoutesPath
138
+ );
139
+ if (!fs.existsSync(absoluteCustomRoutesPath) && !fs.existsSync(`${absoluteCustomRoutesPath}.ts`) && !fs.existsSync(`${absoluteCustomRoutesPath}.js`)) {
140
+ throw new Error(
141
+ `Custom routes file not found: '${absoluteCustomRoutesPath}'. Please ensure 'customRoutes' in monorise.config.ts points to a valid file.`
142
+ );
143
+ }
144
+ let routesModule;
145
+ try {
146
+ routesModule = await import(absoluteCustomRoutesPath);
147
+ } catch (e) {
148
+ throw new Error(
149
+ `Failed to load custom routes file at '${absoluteCustomRoutesPath}'. Ensure it's a valid JavaScript/TypeScript module. Error: ${e.message}`
150
+ );
151
+ }
152
+ const routesExport = routesModule.default;
153
+ if (!routesExport || routesExport === null || typeof routesExport === "object" && !("get" in routesExport && "post" in routesExport && "use" in routesExport)) {
154
+ throw new Error(
155
+ `Custom routes file at '${absoluteCustomRoutesPath}' must default export an instance of Hono (or an object with .get, .post, .use methods). Or a function that consume the dependency container provided by route handler.`
156
+ );
157
+ }
158
+ let relativePathToRoutes = path.relative(
159
+ monoriseOutputDir,
160
+ absoluteCustomRoutesPath
161
+ );
162
+ relativePathToRoutes = relativePathToRoutes.replace(
163
+ /\.(ts|js|mjs|cjs)$/,
164
+ ""
165
+ );
166
+ routesImportLine = `import routes from '${relativePathToRoutes}';`;
167
+ appHandlerPayload = "{ routes }";
168
+ }
169
+ const combinedContent = `
170
+ import CoreFactory from 'monorise/core';
171
+ import config from './config';
172
+ ${routesImportLine ? `${routesImportLine}
173
+ ` : ""}const coreFactory = new CoreFactory(config);
174
+
175
+ export const replicationHandler = coreFactory.replicationProcessor;
176
+ export const mutualHandler = coreFactory.mutualProcessor;
177
+ export const tagHandler = coreFactory.tagProcessor;
178
+ export const treeHandler = coreFactory.prejoinProcessor;
179
+ export const appHandler = coreFactory.appHandler(${appHandlerPayload});
180
+ `;
181
+ fs.writeFileSync(handleOutputPath, combinedContent);
182
+ console.log("Successfully generated handle.ts!");
183
+ return handleOutputPath;
127
184
  }
128
- function kebabToPascal(kebab) {
129
- return kebab
130
- .split('-')
131
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
132
- .join('');
185
+ async function generateFiles(rootPath) {
186
+ const baseDir = rootPath ? path.resolve(rootPath) : process.cwd();
187
+ const configFilePathTS = path.join(baseDir, "monorise.config.ts");
188
+ const configFilePathJS = path.join(baseDir, "monorise.config.js");
189
+ let configFilePath;
190
+ if (fs.existsSync(configFilePathTS)) {
191
+ configFilePath = configFilePathTS;
192
+ } else if (fs.existsSync(configFilePathJS)) {
193
+ configFilePath = configFilePathJS;
194
+ } else {
195
+ throw new Error(
196
+ "Neither monorise.config.ts nor monorise.config.js found in the root of the project."
197
+ );
198
+ }
199
+ const projectRoot = path.dirname(configFilePath);
200
+ const monoriseConfigModule = await import(configFilePath);
201
+ const monoriseConfig = monoriseConfigModule.default;
202
+ const configDir = path.resolve(projectRoot, monoriseConfig.configDir);
203
+ const monoriseOutputDir = path.join(projectRoot, ".monorise");
204
+ fs.mkdirSync(monoriseOutputDir, { recursive: true });
205
+ await generateConfigFile(configDir, monoriseOutputDir);
206
+ await generateHandleFile(monoriseConfig, projectRoot, monoriseOutputDir);
207
+ return configDir;
133
208
  }
134
- main().catch((err) => {
135
- console.error('Generation failed:', err);
209
+ var MONORISE_LOGO = `
210
+
211
+
212
+
213
+ \u2591\u2591\u2591\u2591\u2591\u2591\u2591
214
+ \u2591\u2591\u2592\u2592\u2592\u2591\u2591\u2591\u2591\u2591\u2591\u2592\u2592\u2592\u2591
215
+ \u2591\u2592\u2592\u2591 \u2591\u2592\u2592\u2591
216
+ \u2591\u2592\u2592\u2591 \u2591\u2592\u2592\u2591
217
+ \u2591\u2592\u2591 \u2591\u2592\u2592\u2591
218
+ \u2591\u2592\u2592\u2591 \u2592\u2592\u2592\u2591
219
+ \u2591\u2592\u2591\u2591\u2591\u2592\u2591 \u2591\u2592\u2591\u2591\u2592\u2592\u2591
220
+ \u2591\u2592\u2592\u2591 \u2591\u2592\u2592\u2592\u2591 \u2591\u2592\u2592\u2591 \u2591\u2592\u2591\u2591
221
+ \u2591\u2592\u2592 \u2591\u2592\u2592\u2591 \u2591\u2592\u2592\u2591 \u2591\u2592\u2591 \u2591\u2592\u2591 \u2591\u2592\u2591
222
+ \u2591\u2592\u2592\u2591 \u2591\u2592\u2591 \u2591\u2592\u2591\u2591\u2592\u2592\u2591\u2591\u2591 \u2591\u2591\u2592\u2592\u2591\u2591\u2592\u2591 \u2591\u2592\u2592 \u2591\u2592\u2591
223
+ \u2591\u2591\u2592\u2591 \u2591\u2592\u2591 \u2591\u2592\u2591 \u2591\u2592\u2592\u2591\u2591\u2592\u2592\u2592\u2592\u2592\u2592\u2591\u2591\u2592\u2591 \u2591\u2592\u2591\u2591 \u2591\u2592\u2591 \u2591\u2592\u2591
224
+ \u2591\u2592\u2591 \u2591\u2591\u2592\u2591 \u2591\u2592\u2591 \u2591\u2591\u2591 \u2591\u2592\u2591 \u2591\u2591 \u2591\u2592\u2591 \u2591\u2592\u2591 \u2591\u2592\u2591\u2591 \u2591\u2591\u2592\u2591
225
+ \u2591\u2592\u2591 \u2591\u2592\u2591 \u2591\u2592\u2591 \u2591\u2592 \u2591\u2591 \u2591\u2592\u2591 \u2591\u2592\u2591 \u2591\u2592\u2591 \u2591\u2592\u2591 \u2591\u2591\u2591\u2591
226
+ \u2591\u2591\u2591 \u2591\u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591 \u2592\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591\u2591
227
+ \u2591\u2591\u2591 \u2591\u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591\u2591
228
+ \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591 \u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591
229
+ \u2591\u2591\u2591 \u2591\u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591 \u2591\u2591\u2591 \u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591
230
+ \u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591
231
+ \u2591\u2591 \u2591\u2591 \u2591\u2591 \u2591\u2591 \u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591\u2591 \u2591\u2591\u2591
232
+ \u2591\u2591\u2591 \u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591
233
+ \u2591\u2591\u2591\u2591\u2591\u2592\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2592\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 \u2591 \u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591
234
+ \u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591 \u2591\u2591\u2591
235
+ \u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2592\u2591\u2591\u2591\u2591\u2591\u2591\u2592\u2591\u2591\u2591\u2591
236
+ \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591
237
+ \u2591\u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591 \u2591\u2592\u2591
238
+ \u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591
239
+ \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591
240
+ \u2591\u2592\u2592\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2592\u2592\u2591\u2591 \u2591\u2591\u2592\u2592\u2592\u2591\u2591 \u2591\u2592\u2592\u2591\u2591 \u2591\u2591\u2591\u2591
241
+ \u2591\u2592\u2591 \u2591\u2591\u2592\u2592\u2591 \u2591\u2592\u2591 \u2591\u2592\u2592\u2591 \u2591\u2591\u2592\u2591
242
+ \u2591\u2592\u2591 \u2591\u2591\u2591\u2591\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2591\u2591 \u2591\u2592\u2591 \u2592\u2592\u2591 \u2591\u2591\u2592\u2592\u2592\u2591
243
+ \u2591\u2592\u2592\u2592\u2592\u2592\u2591\u2591\u2591 \u2591\u2591\u2591\u2592\u2592\u2592\u2592\u2592\u2591 \u2592\u2592\u2591 \u2591\u2592\u2592\u2592\u2592\u2592\u2592\u2591
244
+ \u2591\u2592\u2592\u2591 \u2591\u2592\u2592\u2592\u2592 \u2592\u2592\u2592 \u2592\u2592\u2592
245
+ \u2591\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2591\u2591 \u2591\u2592\u2592\u2592\u2592\u2592\u2591 \u2591\u2592\u2592
246
+ \u2592\u2592\u2592 \u2591\u2591\u2592\u2592\u2592\u2592\u2592\u2592\u2591 \u2592\u2592\u2592 \u2591\u2592\u2592
247
+ \u2592\u2592\u2592 \u2591\u2592\u2592\u2592\u2592 \u2591\u2592\u2592\u2592\u2591
248
+ \u2592\u2593\u2593\u2593\u2592\u2592\u2592\u2593\u2593\u2592\u2592\u2592\u2591 \u2592\u2592\u2592\u2591\u2591\u2592\u2592\u2591
249
+ \u2592\u2593\u2591 \u2591\u2592\u2592\u2593\u2593\u2592\u2591 \u2592\u2593\u2593\u2591
250
+ \u2591\u2592\u2593\u2591 \u2591\u2592\u2593\u2592\u2591\u2592\u2593\u2592
251
+ \u2591\u2592\u2593\u2592\u2591 \u2591\u2592\u2593\u2593\u2592
252
+ \u2591\u2592\u2592\u2593\u2593\u2593\u2593\u2593\u2593\u2592\u2592\u2591
253
+
254
+
255
+
256
+ `;
257
+ async function runInitCommand(rootPath) {
258
+ const projectRoot = rootPath ? path.resolve(rootPath) : process.cwd();
259
+ console.log(MONORISE_LOGO);
260
+ console.log(`Initializing Monorise project in ${projectRoot}...`);
261
+ const monoriseConfigTsPath = path.join(projectRoot, "monorise.config.ts");
262
+ const monoriseConfigContent = `
263
+ const config = {
264
+ configDir: './monorise/entities',
265
+ // custom route file should export default an Hono object.
266
+ // customRoutes: './path/to/custom/routes.ts'
267
+ };
268
+
269
+ export default config;
270
+ `;
271
+ if (!fs.existsSync(monoriseConfigTsPath)) {
272
+ fs.writeFileSync(monoriseConfigTsPath, monoriseConfigContent.trimStart());
273
+ console.log(`Created ${path.relative(projectRoot, monoriseConfigTsPath)}`);
274
+ } else {
275
+ console.log(
276
+ `${path.relative(projectRoot, monoriseConfigTsPath)} already exists. Skipping.`
277
+ );
278
+ }
279
+ const monoriseEntitiesDir = path.join(projectRoot, "monorise", "entities");
280
+ fs.mkdirSync(monoriseEntitiesDir, { recursive: true });
281
+ const userEntityTsPath = path.join(monoriseEntitiesDir, "user.ts");
282
+ const userEntityContent = `
283
+ import { createEntityConfig } from 'monorise/base';
284
+ import { z } from 'zod';
285
+
286
+ const baseSchema = z
287
+ .object({
288
+ displayName: z
289
+ .string()
290
+ .min(1, 'Please provide a name for this user account'),
291
+ firstName: z.string().min(1, 'Please provide first name'),
292
+ lastName: z.string().min(1, 'Please provide last name'),
293
+ jobTitle: z.string(),
294
+ })
295
+ .partial();
296
+
297
+ const config = createEntityConfig({
298
+ name: 'user',
299
+ baseSchema,
300
+ });
301
+
302
+ export default config;
303
+ `;
304
+ if (!fs.existsSync(userEntityTsPath)) {
305
+ fs.writeFileSync(userEntityTsPath, userEntityContent.trimStart());
306
+ console.log(`Created ${path.relative(projectRoot, userEntityTsPath)}`);
307
+ } else {
308
+ console.log(
309
+ `${path.relative(projectRoot, userEntityTsPath)} already exists. Skipping.`
310
+ );
311
+ }
312
+ const packageJsonPath = path.join(projectRoot, "package.json");
313
+ if (fs.existsSync(packageJsonPath)) {
314
+ try {
315
+ const packageJsonContent = fs.readFileSync(packageJsonPath, "utf8");
316
+ const packageJson = JSON.parse(packageJsonContent);
317
+ if (packageJson.type !== "module") {
318
+ packageJson.type = "module";
319
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
320
+ console.log(
321
+ `Updated 'type' to 'module' in ${path.relative(projectRoot, packageJsonPath)}`
322
+ );
323
+ } else {
324
+ console.log(
325
+ `'type: "module"' already set in ${path.relative(projectRoot, packageJsonPath)}. Skipping.`
326
+ );
327
+ }
328
+ } catch (error) {
329
+ console.error(
330
+ `Error reading or parsing ${path.relative(projectRoot, packageJsonPath)}:`,
331
+ error
332
+ );
333
+ }
334
+ } else {
335
+ console.warn(
336
+ `Warning: ${path.relative(projectRoot, packageJsonPath)} not found. Cannot update 'type'.`
337
+ );
338
+ }
339
+ const tsconfigPath = path.join(projectRoot, "tsconfig.json");
340
+ if (fs.existsSync(tsconfigPath)) {
341
+ try {
342
+ const tsconfigContent = fs.readFileSync(tsconfigPath, "utf8");
343
+ const tsconfig = JSON.parse(tsconfigContent);
344
+ if (!tsconfig.compilerOptions) {
345
+ tsconfig.compilerOptions = {};
346
+ }
347
+ if (!tsconfig.compilerOptions.paths) {
348
+ tsconfig.compilerOptions.paths = {};
349
+ }
350
+ const pathKey = "#/monorise/*";
351
+ const pathValue = ["./.monorise/*"];
352
+ if (!tsconfig.compilerOptions.paths[pathKey]) {
353
+ tsconfig.compilerOptions.paths[pathKey] = pathValue;
354
+ fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2));
355
+ console.log(
356
+ `Added '${pathKey}' path alias in ${path.relative(projectRoot, tsconfigPath)}`
357
+ );
358
+ } else {
359
+ console.log(
360
+ `'${pathKey}' path alias already set in ${path.relative(projectRoot, tsconfigPath)}. Skipping.`
361
+ );
362
+ }
363
+ } catch (error) {
364
+ console.error(
365
+ `Error updating ${path.relative(projectRoot, tsconfigPath)}:`,
366
+ error
367
+ );
368
+ }
369
+ } else {
370
+ console.warn(
371
+ `Warning: ${path.relative(projectRoot, tsconfigPath)} not found. Cannot add path alias.`
372
+ );
373
+ }
374
+ console.log("Monorise initialization complete!");
375
+ }
376
+ async function runDevCommand(configDir, rootPath) {
377
+ console.log(MONORISE_LOGO);
378
+ console.log(`Watching for changes in ${configDir}...`);
379
+ const watcher = chokidar.watch(configDir, {
380
+ ignored: (watchedPath) => {
381
+ const fileName = path.basename(watchedPath);
382
+ return fileName === "index.ts" || // Old name, still ignore in case it exists
383
+ fileName === "config.ts" || // Generated config file
384
+ fileName === "processors.ts" || // Generated processors file
385
+ fileName === "app.ts" || // Generated app file
386
+ fileName.startsWith(".") || watchedPath.endsWith(".js") || watchedPath.endsWith(".jsx") || watchedPath.endsWith(".d.ts");
387
+ },
388
+ persistent: true,
389
+ ignoreInitial: true
390
+ });
391
+ watcher.on("add", async (filePath) => {
392
+ console.log(`File ${filePath} has been added. Regenerating...`);
393
+ try {
394
+ await generateFiles(rootPath);
395
+ } catch (err) {
396
+ console.error("Regeneration failed:", err);
397
+ }
398
+ });
399
+ watcher.on("change", async (filePath) => {
400
+ console.log(`File ${filePath} has been changed. Regenerating...`);
401
+ try {
402
+ await generateFiles(rootPath);
403
+ } catch (err) {
404
+ console.error("Regeneration failed:", err);
405
+ }
406
+ });
407
+ watcher.on("unlink", async (filePath) => {
408
+ console.log(`File ${filePath} has been removed. Regenerating...`);
409
+ try {
410
+ await generateFiles(rootPath);
411
+ } catch (err) {
412
+ console.error("Regeneration failed:", err);
413
+ }
414
+ });
415
+ process.on("SIGINT", () => {
416
+ console.log("Monorise dev terminated. Closing watcher and sst dev...");
417
+ watcher.close();
418
+ process.exit(0);
419
+ });
420
+ process.on("SIGTERM", () => {
421
+ console.log("Monorise dev terminated. Closing watcher and sst dev...");
422
+ watcher.close();
423
+ process.exit(0);
424
+ });
425
+ }
426
+ async function runBuildCommand(rootPath) {
427
+ console.log("Starting sst build...");
428
+ await generateFiles(rootPath);
429
+ }
430
+ async function main() {
431
+ const args = process.argv.slice(2);
432
+ const command = args[0];
433
+ let rootPath;
434
+ const rootFlagIndex = args.indexOf("--config-root");
435
+ if (rootFlagIndex > -1 && args[rootFlagIndex + 1]) {
436
+ rootPath = args[rootFlagIndex + 1];
437
+ }
438
+ try {
439
+ if (command === "dev") {
440
+ const configDir = await generateFiles(rootPath);
441
+ await runDevCommand(configDir, rootPath);
442
+ } else if (command === "build") {
443
+ await runBuildCommand(rootPath);
444
+ } else if (command === "init") {
445
+ await runInitCommand(rootPath);
446
+ } else {
447
+ console.error(
448
+ "Unknown command. Usage: monorise [dev|build|init] [--config-root <path>]"
449
+ );
450
+ process.exit(1);
451
+ }
452
+ } catch (err) {
453
+ console.error("Monorise process failed:", err);
136
454
  process.exit(1);
455
+ }
456
+ }
457
+ main().catch((err) => {
458
+ console.error("Monorise encountered an unhandled error:", err);
459
+ process.exit(1);
137
460
  });
138
461
  //# sourceMappingURL=cli.js.map
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../cli.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,CAAC;AACb,OAAO,4BAA4B,CAAC;AACpC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,KAAK,UAAU,IAAI;IACjB,qDAAqD;IACrD,MAAM,gBAAgB,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAC9D,MAAM,gBAAgB,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAE9D,IAAI,cAAsB,CAAC;IAC3B,IAAI,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACpC,cAAc,GAAG,gBAAgB,CAAC;IACpC,CAAC;SAAM,IAAI,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC3C,cAAc,GAAG,gBAAgB,CAAC;IACpC,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CACb,qFAAqF,CACtF,CAAC;IACJ,CAAC;IAED,qCAAqC;IACrC,MAAM,cAAc,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC;IACpD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAEjE,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAC1D,MAAM,oBAAoB,GAAG;;CAE9B,CAAC;IAEA,o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AC,EAAE,CAAC,CAAC;AACd,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;IACzC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
1
+ {"version":3,"sources":["../cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport 'tsx';\nimport 'tsconfig-paths/register.js';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport chokidar from 'chokidar';\n\nfunction kebabToCamel(str: string): string {\n return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());\n}\n\nfunction kebabToPascal(kebab: string): string {\n return kebab\n .split('-')\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\n .join('');\n}\n\nasync function generateConfigFile(\n configDir: string,\n monoriseOutputDir: string,\n): Promise<string> {\n const configOutputPath = path.join(monoriseOutputDir, 'config.ts');\n const initialConfigContent = `\nexport enum Entity {}\n`;\n fs.writeFileSync(configOutputPath, initialConfigContent);\n\n const files = fs\n .readdirSync(configDir)\n .filter((file) => file.endsWith('.ts') && file !== 'index.ts');\n\n const names = new Set<string>();\n const nameRegex = /^[a-z]+(-[a-z]+)*$/;\n const imports: string[] = [];\n\n const enumEntries: string[] = [];\n const typeEntries: string[] = [];\n const schemaMapEntries: string[] = [];\n const configEntries: string[] = [];\n const schemaEntries: string[] = [];\n const allowedEntityEntries: string[] = [];\n const entityWithEmailAuthEntries: string[] = [];\n\n const relativePathToConfigDir = path.relative(monoriseOutputDir, configDir);\n const importPathPrefix = relativePathToConfigDir\n ? `${relativePathToConfigDir}/`\n : './';\n\n for (const file of files) {\n const fullPath = path.join(configDir, file);\n const module = await import(fullPath);\n const config = module.default;\n\n if (!nameRegex.test(config.name)) {\n throw new Error(\n `Invalid name format: ${config.name} in ${file}. Must be kebab-case.`,\n );\n }\n\n if (names.has(config.name)) {\n throw new Error(`Duplicate name found: ${config.name} in ${file}`);\n }\n names.add(config.name);\n\n const fileName = file.replace(/\\.ts$/, '');\n const variableName = kebabToCamel(fileName);\n imports.push(\n `import ${variableName} from '${importPathPrefix}${fileName}';`,\n );\n\n const enumKey = config.name.toUpperCase().replace(/-/g, '_');\n enumEntries.push(`${enumKey} = '${config.name}'`);\n typeEntries.push(\n `export type ${kebabToPascal(config.name)}Type = z.infer<(typeof ${variableName})['finalSchema']>;`,\n );\n schemaMapEntries.push(\n `[Entity.${enumKey}]: ${kebabToPascal(config.name)}Type;`,\n );\n\n configEntries.push(`[Entity.${enumKey}]: ${kebabToCamel(config.name)},`);\n schemaEntries.push(\n `[Entity.${enumKey}]: ${kebabToCamel(config.name)}.finalSchema,`,\n );\n\n allowedEntityEntries.push(`Entity.${enumKey}`);\n\n if (config.authMethod?.email) {\n entityWithEmailAuthEntries.push(`Entity.${enumKey}`);\n }\n }\n\n const configOutputContent = `\nimport type { z } from 'zod';\n${imports.join('\\n')}\n\nexport enum Entity {\n ${enumEntries.join(',\\n ')}\n}\n\n${typeEntries.join('\\n')}\n\nexport interface EntitySchemaMap {\n ${schemaMapEntries.join('\\n ')}\n}\n\nconst EntityConfig = {\n ${configEntries.join('\\n ')}\n};\n\nconst FormSchema = {\n ${schemaEntries.join('\\n ')}\n};\n\nconst AllowedEntityTypes = [\n ${allowedEntityEntries.join(',\\n ')}\n];\n\nconst EmailAuthEnabledEntities: Entity[] = [${entityWithEmailAuthEntries.join(', ')}];\n\nexport {\n EntityConfig,\n FormSchema,\n AllowedEntityTypes,\n EmailAuthEnabledEntities,\n};\n\nconst config = {\n EntityConfig,\n FormSchema,\n AllowedEntityTypes,\n EmailAuthEnabledEntities,\n};\n\nexport default config;\n\ndeclare module '@monorise/base' {\n export enum Entity {\n ${enumEntries.join(',\\n ')}\n }\n\n ${typeEntries.join('\\n ')}\n\n export interface EntitySchemaMap {\n ${schemaMapEntries.join('\\n ')}\n }\n}\n`;\n\n fs.writeFileSync(configOutputPath, configOutputContent);\n console.log('Successfully generated config.ts!');\n return configOutputPath;\n}\n\nasync function generateHandleFile(\n monoriseConfig: { customRoutes?: string; configDir: string },\n projectRoot: string,\n monoriseOutputDir: string,\n): Promise<string> {\n const handleOutputPath = path.join(monoriseOutputDir, 'handle.ts');\n const customRoutesPath = monoriseConfig.customRoutes;\n\n let routesImportLine = '';\n let appHandlerPayload = '{}'; // Default to an empty object for appHandler if no custom routes\n\n if (customRoutesPath) {\n const absoluteCustomRoutesPath = path.resolve(\n projectRoot,\n customRoutesPath,\n );\n\n if (\n !fs.existsSync(absoluteCustomRoutesPath) &&\n !fs.existsSync(`${absoluteCustomRoutesPath}.ts`) &&\n !fs.existsSync(`${absoluteCustomRoutesPath}.js`)\n ) {\n throw new Error(\n `Custom routes file not found: '${absoluteCustomRoutesPath}'. Please ensure 'customRoutes' in monorise.config.ts points to a valid file.`,\n );\n }\n\n let routesModule;\n try {\n routesModule = await import(absoluteCustomRoutesPath);\n } catch (e: any) {\n throw new Error(\n `Failed to load custom routes file at '${absoluteCustomRoutesPath}'. Ensure it's a valid JavaScript/TypeScript module. Error: ${e.message}`,\n );\n }\n\n const routesExport = routesModule.default;\n\n if (\n !routesExport ||\n routesExport === null ||\n (typeof routesExport === 'object' &&\n !(\n 'get' in routesExport &&\n 'post' in routesExport &&\n 'use' in routesExport\n ))\n ) {\n throw new Error(\n `Custom routes file at '${absoluteCustomRoutesPath}' must default export an instance of Hono (or an object with .get, .post, .use methods). Or a function that consume the dependency container provided by route handler.`,\n );\n }\n\n let relativePathToRoutes = path.relative(\n monoriseOutputDir,\n absoluteCustomRoutesPath,\n );\n relativePathToRoutes = relativePathToRoutes.replace(\n /\\.(ts|js|mjs|cjs)$/,\n '',\n );\n\n // If custom routes are provided, include the import statement and pass 'routes' to appHandler\n routesImportLine = `import routes from '${relativePathToRoutes}';`;\n appHandlerPayload = '{ routes }';\n }\n // If customRoutesPath is not provided, routesImportLine remains empty and appHandlerPayload remains `{}`\n\n const combinedContent = `\nimport CoreFactory from 'monorise/core';\nimport config from './config';\n${routesImportLine ? `${routesImportLine}\\n` : ''}const coreFactory = new CoreFactory(config);\n\nexport const replicationHandler = coreFactory.replicationProcessor;\nexport const mutualHandler = coreFactory.mutualProcessor;\nexport const tagHandler = coreFactory.tagProcessor;\nexport const treeHandler = coreFactory.prejoinProcessor;\nexport const appHandler = coreFactory.appHandler(${appHandlerPayload});\n`;\n fs.writeFileSync(handleOutputPath, combinedContent);\n console.log('Successfully generated handle.ts!');\n\n return handleOutputPath;\n}\n\nasync function generateFiles(rootPath?: string): Promise<string> {\n const baseDir = rootPath ? path.resolve(rootPath) : process.cwd();\n const configFilePathTS = path.join(baseDir, 'monorise.config.ts');\n const configFilePathJS = path.join(baseDir, 'monorise.config.js');\n\n let configFilePath: string;\n if (fs.existsSync(configFilePathTS)) {\n configFilePath = configFilePathTS;\n } else if (fs.existsSync(configFilePathJS)) {\n configFilePath = configFilePathJS;\n } else {\n throw new Error(\n 'Neither monorise.config.ts nor monorise.config.js found in the root of the project.',\n );\n }\n\n const projectRoot = path.dirname(configFilePath);\n const monoriseConfigModule = await import(configFilePath);\n const monoriseConfig = monoriseConfigModule.default;\n\n const configDir = path.resolve(projectRoot, monoriseConfig.configDir);\n const monoriseOutputDir = path.join(projectRoot, '.monorise');\n\n fs.mkdirSync(monoriseOutputDir, { recursive: true });\n\n await generateConfigFile(configDir, monoriseOutputDir);\n await generateHandleFile(monoriseConfig, projectRoot, monoriseOutputDir);\n\n return configDir;\n}\n\nconst MONORISE_LOGO = `\n\n\n\n ░░░░░░░\n ░░▒▒▒░░░░░░▒▒▒░\n ░▒▒░ ░▒▒░\n ░▒▒░ ░▒▒░\n ░▒░ ░▒▒░\n ░▒▒░ ▒▒▒░\n ░▒░░░▒░ ░▒░░▒▒░\n ░▒▒░ ░▒▒▒░ ░▒▒░ ░▒░░\n ░▒▒ ░▒▒░ ░▒▒░ ░▒░ ░▒░ ░▒░\n ░▒▒░ ░▒░ ░▒░░▒▒░░░ ░░▒▒░░▒░ ░▒▒ ░▒░\n ░░▒░ ░▒░ ░▒░ ░▒▒░░▒▒▒▒▒▒░░▒░ ░▒░░ ░▒░ ░▒░\n ░▒░ ░░▒░ ░▒░ ░░░ ░▒░ ░░ ░▒░ ░▒░ ░▒░░ ░░▒░\n ░▒░ ░▒░ ░▒░ ░▒ ░░ ░▒░ ░▒░ ░▒░ ░▒░ ░░░░\n ░░░ ░░░░ ░░░ ░░ ▒░ ░░░ ░░░ ░░░ ░░░ ░░░░\n ░░░ ░░░░ ░░░ ░░░ ░░░ ░░ ░░░ ░░░ ░░░ ░░░░\n ░░░ ░░░ ░░░ ░░░ ░░ ░░ ░░░ ░░░ ░░░ ░░░\n ░░░ ░░░░ ░░░ ░░░ ░░ ░░░ ░░ ░░░ ░░░ ░░░\n ░░ ░░░ ░░░ ░░░ ░░░ ░░ ░░░ ░░░ ░░░ ░░░\n ░░ ░░ ░░ ░░ ░░ ░░░ ░░░ ░░░ ░░░░ ░░░\n ░░░ ░░ ░░░ ░░░ ░░░\n ░░░░░▒░░░░░░░░░▒░░░░░░░░░ ░ ░░ ░░░ ░░░ ░░\n ░░░ ░░░░░░░░░ ░░░ ░░░\n ░░░ ░░░░░░ ░░ ░░░░░▒░░░░░░▒░░░░\n ░░░░░░░░░░░░░░░░░ ░░░░░ ░░░░░░░░ ░░\n ░░░░░░░ ░░░░░░░░░░░░░░ ░░░░ ░░░░░ ░▒░\n ░░░ ░░░░░░░ ░░░░░░ ░░░░░░░░\n ░░░░░░░░░░░░ ░░░░░░ ░░░░ ░░░░░░░░░░░░░\n ░▒▒░░░░░░░░░░░▒▒░░ ░░▒▒▒░░ ░▒▒░░ ░░░░\n ░▒░ ░░▒▒░ ░▒░ ░▒▒░ ░░▒░\n ░▒░ ░░░░▒▒▒▒▒▒▒▒▒▒░░ ░▒░ ▒▒░ ░░▒▒▒░\n ░▒▒▒▒▒░░░ ░░░▒▒▒▒▒░ ▒▒░ ░▒▒▒▒▒▒░\n ░▒▒░ ░▒▒▒▒ ▒▒▒ ▒▒▒\n ░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░ ░▒▒▒▒▒░ ░▒▒\n ▒▒▒ ░░▒▒▒▒▒▒░ ▒▒▒ ░▒▒\n ▒▒▒ ░▒▒▒▒ ░▒▒▒░\n ▒▓▓▓▒▒▒▓▓▒▒▒░ ▒▒▒░░▒▒░\n ▒▓░ ░▒▒▓▓▒░ ▒▓▓░\n ░▒▓░ ░▒▓▒░▒▓▒\n ░▒▓▒░ ░▒▓▓▒\n ░▒▒▓▓▓▓▓▓▒▒░\n\n\n\n`;\n\nasync function runInitCommand(rootPath?: string) {\n const projectRoot = rootPath ? path.resolve(rootPath) : process.cwd();\n console.log(MONORISE_LOGO);\n console.log(`Initializing Monorise project in ${projectRoot}...`);\n\n // 1. Create monorise.config.ts\n const monoriseConfigTsPath = path.join(projectRoot, 'monorise.config.ts');\n const monoriseConfigContent = `\nconst config = {\n configDir: './monorise/entities',\n // custom route file should export default an Hono object.\n // customRoutes: './path/to/custom/routes.ts'\n};\n\nexport default config;\n`;\n if (!fs.existsSync(monoriseConfigTsPath)) {\n fs.writeFileSync(monoriseConfigTsPath, monoriseConfigContent.trimStart());\n console.log(`Created ${path.relative(projectRoot, monoriseConfigTsPath)}`);\n } else {\n console.log(\n `${path.relative(projectRoot, monoriseConfigTsPath)} already exists. Skipping.`,\n );\n }\n\n // 2. Create ./monorise/entities/user.ts\n const monoriseEntitiesDir = path.join(projectRoot, 'monorise', 'entities');\n fs.mkdirSync(monoriseEntitiesDir, { recursive: true });\n\n const userEntityTsPath = path.join(monoriseEntitiesDir, 'user.ts');\n const userEntityContent = `\nimport { createEntityConfig } from 'monorise/base';\nimport { z } from 'zod';\n\nconst baseSchema = z\n .object({\n displayName: z\n .string()\n .min(1, 'Please provide a name for this user account'),\n firstName: z.string().min(1, 'Please provide first name'),\n lastName: z.string().min(1, 'Please provide last name'),\n jobTitle: z.string(),\n })\n .partial();\n\nconst config = createEntityConfig({\n name: 'user',\n baseSchema,\n});\n\nexport default config;\n`;\n if (!fs.existsSync(userEntityTsPath)) {\n fs.writeFileSync(userEntityTsPath, userEntityContent.trimStart());\n console.log(`Created ${path.relative(projectRoot, userEntityTsPath)}`);\n } else {\n console.log(\n `${path.relative(projectRoot, userEntityTsPath)} already exists. Skipping.`,\n );\n }\n\n // 3. Update package.json\n const packageJsonPath = path.join(projectRoot, 'package.json');\n if (fs.existsSync(packageJsonPath)) {\n try {\n const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8');\n const packageJson = JSON.parse(packageJsonContent);\n\n if (packageJson.type !== 'module') {\n packageJson.type = 'module';\n fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));\n console.log(\n `Updated 'type' to 'module' in ${path.relative(projectRoot, packageJsonPath)}`,\n );\n } else {\n console.log(\n `'type: \"module\"' already set in ${path.relative(projectRoot, packageJsonPath)}. Skipping.`,\n );\n }\n } catch (error) {\n console.error(\n `Error reading or parsing ${path.relative(projectRoot, packageJsonPath)}:`,\n error,\n );\n }\n } else {\n console.warn(\n `Warning: ${path.relative(projectRoot, packageJsonPath)} not found. Cannot update 'type'.`,\n );\n }\n\n // 4. Add tsconfig path alias for .monorise directory\n const tsconfigPath = path.join(projectRoot, 'tsconfig.json');\n if (fs.existsSync(tsconfigPath)) {\n try {\n const tsconfigContent = fs.readFileSync(tsconfigPath, 'utf8');\n const tsconfig = JSON.parse(tsconfigContent);\n\n if (!tsconfig.compilerOptions) {\n tsconfig.compilerOptions = {};\n }\n if (!tsconfig.compilerOptions.paths) {\n tsconfig.compilerOptions.paths = {};\n }\n\n const pathKey = '#/monorise/*';\n const pathValue = ['./.monorise/*'];\n\n if (!tsconfig.compilerOptions.paths[pathKey]) {\n tsconfig.compilerOptions.paths[pathKey] = pathValue;\n fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2));\n console.log(\n `Added '${pathKey}' path alias in ${path.relative(projectRoot, tsconfigPath)}`,\n );\n } else {\n console.log(\n `'${pathKey}' path alias already set in ${path.relative(projectRoot, tsconfigPath)}. Skipping.`,\n );\n }\n } catch (error) {\n console.error(\n `Error updating ${path.relative(projectRoot, tsconfigPath)}:`,\n error,\n );\n }\n } else {\n console.warn(\n `Warning: ${path.relative(projectRoot, tsconfigPath)} not found. Cannot add path alias.`,\n );\n }\n\n console.log('Monorise initialization complete!');\n}\n\nasync function runDevCommand(configDir: string, rootPath?: string) {\n console.log(MONORISE_LOGO);\n console.log(`Watching for changes in ${configDir}...`);\n const watcher = chokidar.watch(configDir, {\n ignored: (watchedPath: string) => {\n const fileName = path.basename(watchedPath);\n return (\n fileName === 'index.ts' || // Old name, still ignore in case it exists\n fileName === 'config.ts' || // Generated config file\n fileName === 'processors.ts' || // Generated processors file\n fileName === 'app.ts' || // Generated app file\n fileName.startsWith('.') ||\n watchedPath.endsWith('.js') ||\n watchedPath.endsWith('.jsx') ||\n watchedPath.endsWith('.d.ts')\n );\n },\n persistent: true,\n ignoreInitial: true,\n });\n\n watcher.on('add', async (filePath) => {\n console.log(`File ${filePath} has been added. Regenerating...`);\n try {\n await generateFiles(rootPath);\n } catch (err) {\n console.error('Regeneration failed:', err);\n }\n });\n\n watcher.on('change', async (filePath) => {\n console.log(`File ${filePath} has been changed. Regenerating...`);\n try {\n await generateFiles(rootPath);\n } catch (err) {\n console.error('Regeneration failed:', err);\n }\n });\n\n watcher.on('unlink', async (filePath) => {\n console.log(`File ${filePath} has been removed. Regenerating...`);\n try {\n await generateFiles(rootPath);\n } catch (err) {\n console.error('Regeneration failed:', err);\n }\n });\n\n process.on('SIGINT', () => {\n console.log('Monorise dev terminated. Closing watcher and sst dev...');\n watcher.close();\n process.exit(0);\n });\n process.on('SIGTERM', () => {\n console.log('Monorise dev terminated. Closing watcher and sst dev...');\n watcher.close();\n process.exit(0);\n });\n}\n\nasync function runBuildCommand(rootPath?: string) {\n console.log('Starting sst build...');\n await generateFiles(rootPath);\n}\n\nasync function main() {\n const args = process.argv.slice(2);\n const command = args[0];\n\n let rootPath: string | undefined;\n const rootFlagIndex = args.indexOf('--config-root');\n if (rootFlagIndex > -1 && args[rootFlagIndex + 1]) {\n rootPath = args[rootFlagIndex + 1];\n }\n\n try {\n if (command === 'dev') {\n const configDir = await generateFiles(rootPath);\n await runDevCommand(configDir, rootPath);\n } else if (command === 'build') {\n await runBuildCommand(rootPath);\n } else if (command === 'init') {\n await runInitCommand(rootPath);\n } else {\n console.error(\n 'Unknown command. Usage: monorise [dev|build|init] [--config-root <path>]',\n );\n process.exit(1);\n }\n } catch (err) {\n console.error('Monorise process failed:', err);\n process.exit(1);\n }\n}\n\nmain().catch((err) => {\n console.error('Monorise encountered an unhandled error:', err);\n process.exit(1);\n});\n"],"mappings":";;;AAEA,OAAO;AACP,OAAO;AACP,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,cAAc;AAErB,SAAS,aAAa,KAAqB;AACzC,SAAO,IAAI,QAAQ,aAAa,CAAC,GAAG,WAAW,OAAO,YAAY,CAAC;AACrE;AAEA,SAAS,cAAc,OAAuB;AAC5C,SAAO,MACJ,MAAM,GAAG,EACT,IAAI,CAAC,SAAS,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC,CAAC,EAC1D,KAAK,EAAE;AACZ;AAEA,eAAe,mBACb,WACA,mBACiB;AACjB,QAAM,mBAAmB,KAAK,KAAK,mBAAmB,WAAW;AACjE,QAAM,uBAAuB;AAAA;AAAA;AAG7B,KAAG,cAAc,kBAAkB,oBAAoB;AAEvD,QAAM,QAAQ,GACX,YAAY,SAAS,EACrB,OAAO,CAAC,SAAS,KAAK,SAAS,KAAK,KAAK,SAAS,UAAU;AAE/D,QAAM,QAAQ,oBAAI,IAAY;AAC9B,QAAM,YAAY;AAClB,QAAM,UAAoB,CAAC;AAE3B,QAAM,cAAwB,CAAC;AAC/B,QAAM,cAAwB,CAAC;AAC/B,QAAM,mBAA6B,CAAC;AACpC,QAAM,gBAA0B,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AK,gBAAgB,CAAC,GAAG;AACjD,eAAW,KAAK,gBAAgB,CAAC;AAAA,EACnC;AAEA,MAAI;AACF,QAAI,YAAY,OAAO;AACrB,YAAM,YAAY,MAAM,cAAc,QAAQ;AAC9C,YAAM,cAAc,WAAW,QAAQ;AAAA,IACzC,WAAW,YAAY,SAAS;AAC9B,YAAM,gBAAgB,QAAQ;AAAA,IAChC,WAAW,YAAY,QAAQ;AAC7B,YAAM,eAAe,QAAQ;AAAA,IAC/B,OAAO;AACL,cAAQ;AAAA,QACN;AAAA,MACF;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF,SAAS,KAAK;AACZ,YAAQ,MAAM,4BAA4B,GAAG;AAC7C,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;AAEA,KAAK,EAAE,MAAM,CAAC,QAAQ;AACpB,UAAQ,MAAM,4CAA4C,GAAG;AAC7D,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monorise/cli",
3
- "version": "1.0.5",
3
+ "version": "3.0.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -9,14 +9,18 @@
9
9
  "monorise": "dist/cli.js"
10
10
  },
11
11
  "scripts": {
12
- "build": "tsc"
12
+ "build": "tsup && chmod +x dist/cli.js",
13
+ "dev": "tsup --watch"
13
14
  },
14
15
  "keywords": [],
15
16
  "author": "",
16
17
  "license": "ISC",
17
18
  "dependencies": {
19
+ "chokidar": "^4.0.3",
18
20
  "tsconfig-paths": "^4.2.0",
19
- "tsx": "^4.19.3",
20
- "zod": "^3.24.2"
21
- }
21
+ "tsx": "^4.19.3"
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ]
22
26
  }
package/cli.ts DELETED
@@ -1,167 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import 'tsx';
4
- import 'tsconfig-paths/register.js';
5
- import fs from 'node:fs';
6
- import path from 'node:path';
7
-
8
- async function main() {
9
- // Check for monorise.config.ts or monorise.config.js
10
- const configFilePathTS = path.resolve('./monorise.config.ts');
11
- const configFilePathJS = path.resolve('./monorise.config.js');
12
-
13
- let configFilePath: string;
14
- if (fs.existsSync(configFilePathTS)) {
15
- configFilePath = configFilePathTS;
16
- } else if (fs.existsSync(configFilePathJS)) {
17
- configFilePath = configFilePathJS;
18
- } else {
19
- throw new Error(
20
- 'Neither monorise.config.ts nor monorise.config.js found in the root of the project.',
21
- );
22
- }
23
-
24
- // Dynamically import the config file
25
- const monoriseConfig = await import(configFilePath);
26
- const configDir = path.resolve(monoriseConfig.default.configDir);
27
-
28
- const configOutputPath = path.join(configDir, 'index.ts');
29
- const initialOutputContent = `
30
- export enum Entity {}
31
- `;
32
-
33
- // Clean up and initialize index.ts file, so that tsconfig resolves import correctly
34
- fs.writeFileSync(configOutputPath, initialOutputContent);
35
-
36
- const files = fs
37
- .readdirSync(configDir)
38
- .filter((file) => file.endsWith('.ts') && file !== 'index.ts');
39
-
40
- const names = new Set<string>();
41
- const nameRegex = /^[a-z]+(-[a-z]+)*$/;
42
- const imports: string[] = [];
43
- const importTypes: string[] = [];
44
- const arrayElements: string[] = [];
45
-
46
- const enumEntries: string[] = [];
47
- const typeEntries: string[] = [];
48
- const schemaMapEntries: string[] = [];
49
- const configEntries: string[] = [];
50
- const schemaEntries: string[] = [];
51
- const allowedEntityEntries: string[] = [];
52
- const entityWithEmailAuthEntries: string[] = [];
53
-
54
- for (const file of files) {
55
- const fullPath = path.join(configDir, file);
56
- const module = await import(fullPath);
57
- const config = module.default;
58
-
59
- // Validate name
60
- if (!nameRegex.test(config.name)) {
61
- throw new Error(
62
- `Invalid name format: ${config.name} in ${file}. Must be kebab-case.`,
63
- );
64
- }
65
-
66
- if (names.has(config.name)) {
67
- throw new Error(`Duplicate name found: ${config.name} in ${file}`);
68
- }
69
- names.add(config.name);
70
-
71
- // Generate import and array element
72
- const fileName = file.replace(/\.ts$/, '');
73
- const variableName = kebabToCamel(fileName);
74
- imports.push(`import ${variableName} from './${fileName}';`);
75
- importTypes.push(`import type ${variableName} from './${fileName}';`);
76
- arrayElements.push(variableName);
77
-
78
- // Generate enum entry
79
- const enumKey = config.name.toUpperCase().replace(/-/g, '_');
80
- enumEntries.push(`${enumKey} = '${config.name}'`);
81
- typeEntries.push(
82
- `export type ${kebabToPascal(config.name)}Type = z.infer<(typeof ${variableName})['finalSchema']>;`,
83
- );
84
- schemaMapEntries.push(
85
- `${kebabToCamel(config.name)}: ${kebabToPascal(config.name)}Type;`,
86
- );
87
-
88
- // Generate config entry
89
- configEntries.push(`[Entity.${enumKey}]: ${kebabToCamel(config.name)},`);
90
- schemaEntries.push(
91
- `[Entity.${enumKey}]: ${kebabToCamel(config.name)}.finalSchema,`,
92
- );
93
-
94
- allowedEntityEntries.push(`Entity.${enumKey}`);
95
-
96
- if (config.authMethod?.email) {
97
- entityWithEmailAuthEntries.push(`Entity.${enumKey}`);
98
- }
99
- }
100
-
101
- const outputContent = `
102
- import type { z } from 'zod';
103
- ${imports.join('\n')}
104
-
105
- export enum Entity {
106
- ${enumEntries.join(',\n ')}
107
- }
108
-
109
- ${typeEntries.join('\n')}
110
-
111
- export interface EntitySchemaMap {
112
- ${schemaMapEntries.join('\n ')}
113
- }
114
-
115
- const EntityConfig = {
116
- ${configEntries.join('\n ')}
117
- };
118
-
119
- const FormSchema = {
120
- ${schemaEntries.join('\n ')}
121
- };
122
-
123
- const AllowedEntityTypes = [
124
- ${allowedEntityEntries.join(',\n ')}
125
- ];
126
-
127
- const EmailAuthEnabledEntities = [${entityWithEmailAuthEntries.join(', ')}];
128
-
129
- export {
130
- EntityConfig,
131
- FormSchema,
132
- AllowedEntityTypes,
133
- EmailAuthEnabledEntities,
134
- };
135
-
136
- declare module '@monorise/base' {
137
- export enum Entity {
138
- ${enumEntries.join(',\n ')}
139
- }
140
-
141
- ${typeEntries.join('\n ')}
142
-
143
- export interface EntitySchemaMap {
144
- ${schemaMapEntries.join('\n ')}
145
- }
146
- }
147
- `;
148
-
149
- fs.writeFileSync(configOutputPath, outputContent);
150
- console.log('Successfully generated entity configurations and enum!');
151
- }
152
-
153
- function kebabToCamel(str: string): string {
154
- return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
155
- }
156
-
157
- function kebabToPascal(kebab: string): string {
158
- return kebab
159
- .split('-')
160
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
161
- .join('');
162
- }
163
-
164
- main().catch((err) => {
165
- console.error('Generation failed:', err);
166
- process.exit(1);
167
- });
package/dist/cli.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../cli.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,CAAC;AACb,OAAO,4BAA4B,CAAC"}
package/dist/index.d.ts DELETED
@@ -1,47 +0,0 @@
1
- import type { Entity, MonoriseEntityConfig } from '@monorise/base';
2
- import { z } from 'zod';
3
- declare const createEntityConfig: <T extends Entity, B extends z.ZodRawShape, C extends z.ZodRawShape, M extends z.ZodRawShape, CO extends z.ZodObject<C> | undefined = undefined, MO extends z.ZodObject<M> | undefined = undefined>(config: MonoriseEntityConfig<T, B, C, M, CO, MO>) => {
4
- finalSchema: (CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any>[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<MO["shape"] & CO["shape"]>[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_3 ? { [k_2 in keyof T_3]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any>[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_4 ? { [k_3 in keyof T_4]: z.baseObjectInputType<MO["shape"] & B>[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_5 ? { [k_4 in keyof T_5]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_6 ? { [k_5 in keyof T_6]: z.baseObjectInputType<B>[k_5]; } : never>) | z.ZodEffects<CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_7 ? { [k in keyof T_7]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any>[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_8 ? { [k_1 in keyof T_8]: z.baseObjectInputType<MO["shape"] & CO["shape"]>[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_9 ? { [k_2 in keyof T_9]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any>[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_10 ? { [k_3 in keyof T_10]: z.baseObjectInputType<MO["shape"] & B>[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_11 ? { [k_4 in keyof T_11]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_12 ? { [k_5 in keyof T_12]: z.baseObjectInputType<B>[k_5]; } : never>, z.output<CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_13 ? { [k in keyof T_13]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any>[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_14 ? { [k_1 in keyof T_14]: z.baseObjectInputType<MO["shape"] & CO["shape"]>[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_15 ? { [k_2 in keyof T_15]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any>[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_16 ? { [k_3 in keyof T_16]: z.baseObjectInputType<MO["shape"] & B>[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_17 ? { [k_4 in keyof T_17]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_18 ? { [k_5 in keyof T_18]: z.baseObjectInputType<B>[k_5]; } : never>>, z.input<CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_19 ? { [k in keyof T_19]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any>[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_20 ? { [k_1 in keyof T_20]: z.baseObjectInputType<MO["shape"] & CO["shape"]>[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_21 ? { [k_2 in keyof T_21]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any>[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_22 ? { [k_3 in keyof T_22]: z.baseObjectInputType<MO["shape"] & B>[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_23 ? { [k_4 in keyof T_23]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_24 ? { [k_5 in keyof T_24]: z.baseObjectInputType<B>[k_5]; } : never>>>;
5
- name: string | T;
6
- displayName: string;
7
- authMethod?: {
8
- email: {
9
- tokenExpiresIn: number;
10
- };
11
- };
12
- baseSchema: z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_25 ? { [k_4 in keyof T_25]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_26 ? { [k_5 in keyof T_26]: z.baseObjectInputType<B>[k_5]; } : never>;
13
- createSchema?: CO | undefined;
14
- searchableFields?: (keyof B)[] | undefined;
15
- mutual?: {
16
- subscribes?: {
17
- entityType: Entity;
18
- }[];
19
- mutualSchema: MO;
20
- mutualFields: {
21
- [key: string]: {
22
- entityType: Entity;
23
- toMutualIds?: (context: any) => string[];
24
- mutualDataProcessor?: (mutualIds: string[], currentMutual: any, customContext?: Record<string, any>) => Record<string, any>;
25
- };
26
- };
27
- prejoins?: {
28
- mutualField: string;
29
- targetEntityType: Entity;
30
- entityPaths: {
31
- skipCache?: boolean;
32
- entityType: Entity;
33
- processor?: (items: any[], context: Record<string, any>) => any;
34
- }[];
35
- }[];
36
- } | undefined;
37
- effect?: ((schema: CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_27 ? { [k in keyof T_27]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any>[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_28 ? { [k_1 in keyof T_28]: z.baseObjectInputType<MO["shape"] & CO["shape"]>[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_29 ? { [k_2 in keyof T_29]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any>[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_30 ? { [k_3 in keyof T_30]: z.baseObjectInputType<MO["shape"] & B>[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_31 ? { [k_4 in keyof T_31]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_32 ? { [k_5 in keyof T_32]: z.baseObjectInputType<B>[k_5]; } : never>) => z.ZodEffects<CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_33 ? { [k in keyof T_33]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any>[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_34 ? { [k_1 in keyof T_34]: z.baseObjectInputType<MO["shape"] & CO["shape"]>[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_35 ? { [k_2 in keyof T_35]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any>[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_36 ? { [k_3 in keyof T_36]: z.baseObjectInputType<MO["shape"] & B>[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_37 ? { [k_4 in keyof T_37]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_38 ? { [k_5 in keyof T_38]: z.baseObjectInputType<B>[k_5]; } : never>, z.output<CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_39 ? { [k in keyof T_39]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any>[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_40 ? { [k_1 in keyof T_40]: z.baseObjectInputType<MO["shape"] & CO["shape"]>[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_41 ? { [k_2 in keyof T_41]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any>[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_42 ? { [k_3 in keyof T_42]: z.baseObjectInputType<MO["shape"] & B>[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_43 ? { [k_4 in keyof T_43]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_44 ? { [k_5 in keyof T_44]: z.baseObjectInputType<B>[k_5]; } : never>>, z.input<CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_45 ? { [k in keyof T_45]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any>[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_46 ? { [k_1 in keyof T_46]: z.baseObjectInputType<MO["shape"] & CO["shape"]>[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_47 ? { [k_2 in keyof T_47]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any>[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_48 ? { [k_3 in keyof T_48]: z.baseObjectInputType<MO["shape"] & B>[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_49 ? { [k_4 in keyof T_49]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_50 ? { [k_5 in keyof T_50]: z.baseObjectInputType<B>[k_5]; } : never>>>) | undefined;
38
- tags?: {
39
- name: string;
40
- processor: (entity: import("@monorise/base").CreatedEntity<T>) => {
41
- group?: string;
42
- sortValue?: string;
43
- }[];
44
- }[] | undefined;
45
- };
46
- export { createEntityConfig };
47
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgCxB,QAAA,MAAM,kBAAkB,GACtB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,CAAC,CAAC,WAAW,EACvB,CAAC,SAAS,CAAC,CAAC,WAAW,EACvB,CAAC,SAAS,CAAC,CAAC,WAAW,EACvB,EAAE,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,SAAS,EACjD,EAAE,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,SAAS,EAEjD,QAAQ,oBAAoB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;2BAO2oE,CAAC;mCAA+W,CAAC,yDAAyD,CAAC;;;;;;;yBAAq5B,CAAC;;yBAAwE,CAAC;;;;;;;;iBAAg4E,CAAC;qBAA+B,CAAC;;;CAHt+L,CAAC;AAEH,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
package/dist/index.js DELETED
@@ -1,20 +0,0 @@
1
- import { z } from 'zod';
2
- function makeSchema(config) {
3
- const { baseSchema, createSchema, mutual, effect } = config;
4
- const { mutualSchema } = mutual || {};
5
- const finalSchema = z.object({
6
- ...baseSchema.shape,
7
- ...createSchema?.shape,
8
- ...mutualSchema?.shape,
9
- });
10
- if (effect) {
11
- return effect(finalSchema);
12
- }
13
- return finalSchema;
14
- }
15
- const createEntityConfig = (config) => ({
16
- ...config,
17
- finalSchema: makeSchema(config),
18
- });
19
- export { createEntityConfig };
20
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,SAAS,UAAU,CAOjB,MAAgD;IAChD,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC5D,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,IAAI,EAAE,CAAC;IAEtC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;QAC3B,GAAG,UAAU,CAAC,KAAK;QACnB,GAAG,YAAY,EAAE,KAAK;QACtB,GAAG,YAAY,EAAE,KAAK;KACvB,CAMmB,CAAC;IAErB,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,MAAM,kBAAkB,GAAG,CAQzB,MAAgD,EAChD,EAAE,CAAC,CAAC;IACJ,GAAG,MAAM;IACT,WAAW,EAAE,UAAU,CAAC,MAAM,CAAC;CAChC,CAAC,CAAC;AAEH,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
package/index.ts DELETED
@@ -1,48 +0,0 @@
1
- import type { Entity, MonoriseEntityConfig } from '@monorise/base';
2
- import { z } from 'zod';
3
-
4
- function makeSchema<
5
- T extends Entity,
6
- B extends z.ZodRawShape,
7
- C extends z.ZodRawShape,
8
- M extends z.ZodRawShape,
9
- CO extends z.ZodObject<C> | undefined = undefined,
10
- MO extends z.ZodObject<M> | undefined = undefined,
11
- >(config: MonoriseEntityConfig<T, B, C, M, CO, MO>) {
12
- const { baseSchema, createSchema, mutual, effect } = config;
13
- const { mutualSchema } = mutual || {};
14
-
15
- const finalSchema = z.object({
16
- ...baseSchema.shape,
17
- ...createSchema?.shape,
18
- ...mutualSchema?.shape,
19
- }) as CO extends z.AnyZodObject
20
- ? MO extends z.AnyZodObject
21
- ? z.ZodObject<MO['shape'] & CO['shape']>
22
- : CO
23
- : MO extends z.AnyZodObject
24
- ? z.ZodObject<MO['shape'] & B>
25
- : z.ZodObject<B>;
26
-
27
- if (effect) {
28
- return effect(finalSchema);
29
- }
30
-
31
- return finalSchema;
32
- }
33
-
34
- const createEntityConfig = <
35
- T extends Entity,
36
- B extends z.ZodRawShape,
37
- C extends z.ZodRawShape,
38
- M extends z.ZodRawShape,
39
- CO extends z.ZodObject<C> | undefined = undefined,
40
- MO extends z.ZodObject<M> | undefined = undefined,
41
- >(
42
- config: MonoriseEntityConfig<T, B, C, M, CO, MO>,
43
- ) => ({
44
- ...config,
45
- finalSchema: makeSchema(config),
46
- });
47
-
48
- export { createEntityConfig };
package/tsconfig.json DELETED
@@ -1,114 +0,0 @@
1
- {
2
- "extends": "@tsconfig/node20/tsconfig.json",
3
- "compilerOptions": {
4
- /* Visit https://aka.ms/tsconfig to read more about this file */
5
-
6
- /* Projects */
7
- // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
8
- // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
9
- // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
10
- // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
11
- // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
12
- // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
13
-
14
- /* Language and Environment */
15
- "target": "esnext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
16
- // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
17
- // "jsx": "preserve", /* Specify what JSX code is generated. */
18
- // "libReplacement": true, /* Enable lib replacement. */
19
- // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
20
- // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
21
- // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
22
- // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
23
- // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
24
- // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
25
- // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
26
- // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
27
- // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
28
-
29
- /* Modules */
30
- "module": "esnext" /* Specify what module code is generated. */,
31
- // "rootDir": "./", /* Specify the root folder within your source files. */
32
- "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
33
- // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
34
- // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
35
- // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
36
- // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
37
- // "types": [], /* Specify type package names to be included without being referenced in a source file. */
38
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
39
- // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
40
- // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
41
- // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
42
- // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
43
- // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
44
- // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
45
- // "noUncheckedSideEffectImports": true, /* Check side effect imports. */
46
- // "resolveJsonModule": true, /* Enable importing .json files. */
47
- // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
48
- // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
49
-
50
- /* JavaScript Support */
51
- // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
52
- // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
53
- // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
54
-
55
- /* Emit */
56
- "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
57
- "declarationMap": true /* Create sourcemaps for d.ts files. */,
58
- // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
59
- "sourceMap": true /* Create source map files for emitted JavaScript files. */,
60
- // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
61
- // "noEmit": true, /* Disable emitting files from a compilation. */
62
- // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
63
- "outDir": "./dist" /* Specify an output folder for all emitted files. */,
64
- // "removeComments": true, /* Disable emitting comments. */
65
- // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
66
- // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
67
- // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
68
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
69
- // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
70
- // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
71
- // "newLine": "crlf", /* Set the newline character for emitting files. */
72
- // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
73
- // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
74
- // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
75
- // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
76
- // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
77
-
78
- /* Interop Constraints */
79
- // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
80
- // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
81
- // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
82
- // "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */
83
- // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
84
- "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
85
- // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
86
- "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
87
-
88
- /* Type Checking */
89
- "strict": true /* Enable all strict type-checking options. */,
90
- // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
91
- // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
92
- // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
93
- // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
94
- // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
95
- // "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
96
- // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
97
- // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
98
- // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
99
- // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
100
- // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
101
- // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
102
- // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
103
- // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
104
- // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
105
- // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
106
- // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
107
- // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
108
- // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
109
-
110
- /* Completeness */
111
- // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
112
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
113
- }
114
- }