monorise 1.5.0 → 1.6.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.
Files changed (70) hide show
  1. package/dist/cli/cli.js +9 -16
  2. package/dist/cli/cli.js.map +1 -1
  3. package/dist/core/index.d.ts +83 -2
  4. package/dist/core/index.js +580 -1
  5. package/dist/core/index.js.map +1 -1
  6. package/dist/react/chunk-5XIRNUBL.js +43 -0
  7. package/dist/react/chunk-5XIRNUBL.js.map +1 -0
  8. package/dist/react/chunk-7JDOKZGQ.js +172 -0
  9. package/dist/react/chunk-7JDOKZGQ.js.map +1 -0
  10. package/dist/react/chunk-A5TI2FW3.js +13 -0
  11. package/dist/react/chunk-A5TI2FW3.js.map +1 -0
  12. package/dist/react/chunk-AYQDOLYF.js +628 -0
  13. package/dist/react/chunk-AYQDOLYF.js.map +1 -0
  14. package/dist/react/chunk-BUTF5RJU.js +29 -0
  15. package/dist/react/chunk-BUTF5RJU.js.map +1 -0
  16. package/dist/react/chunk-EYG2DL3D.js +893 -0
  17. package/dist/react/chunk-EYG2DL3D.js.map +1 -0
  18. package/dist/react/chunk-GEN4TSCQ.js +5179 -0
  19. package/dist/react/chunk-GEN4TSCQ.js.map +1 -0
  20. package/dist/react/chunk-GFVCNWVT.js +54 -0
  21. package/dist/react/chunk-GFVCNWVT.js.map +1 -0
  22. package/dist/react/chunk-KJX5LOMN.js +43 -0
  23. package/dist/react/chunk-KJX5LOMN.js.map +1 -0
  24. package/dist/react/chunk-KLXK4V6G.js +65 -0
  25. package/dist/react/chunk-KLXK4V6G.js.map +1 -0
  26. package/dist/react/chunk-L6MAS3AX.js +482 -0
  27. package/dist/react/chunk-L6MAS3AX.js.map +1 -0
  28. package/dist/react/chunk-LPXR5V4J.js +582 -0
  29. package/dist/react/chunk-LPXR5V4J.js.map +1 -0
  30. package/dist/react/chunk-MIXAYX55.js +147 -0
  31. package/dist/react/chunk-MIXAYX55.js.map +1 -0
  32. package/dist/react/chunk-OEHQ546W.js +182 -0
  33. package/dist/react/chunk-OEHQ546W.js.map +1 -0
  34. package/dist/react/chunk-RPNCWADG.js +248 -0
  35. package/dist/react/chunk-RPNCWADG.js.map +1 -0
  36. package/dist/react/chunk-S6RDMHHH.js +47 -0
  37. package/dist/react/chunk-S6RDMHHH.js.map +1 -0
  38. package/dist/react/chunk-VVCM7N22.js +101 -0
  39. package/dist/react/chunk-VVCM7N22.js.map +1 -0
  40. package/dist/react/dist-es-5WYA7CWK.js +379 -0
  41. package/dist/react/dist-es-5WYA7CWK.js.map +1 -0
  42. package/dist/react/dist-es-DLWQXBOR.js +333 -0
  43. package/dist/react/dist-es-DLWQXBOR.js.map +1 -0
  44. package/dist/react/dist-es-EMJCB37T.js +71 -0
  45. package/dist/react/dist-es-EMJCB37T.js.map +1 -0
  46. package/dist/react/dist-es-Q7IAXWRB.js +494 -0
  47. package/dist/react/dist-es-Q7IAXWRB.js.map +1 -0
  48. package/dist/react/dist-es-QF65HH5Y.js +169 -0
  49. package/dist/react/dist-es-QF65HH5Y.js.map +1 -0
  50. package/dist/react/dist-es-R4TRTT45.js +22 -0
  51. package/dist/react/dist-es-R4TRTT45.js.map +1 -0
  52. package/dist/react/dist-es-XNAC47MK.js +90 -0
  53. package/dist/react/dist-es-XNAC47MK.js.map +1 -0
  54. package/dist/react/event-streams-6APKUBMC.js +270 -0
  55. package/dist/react/event-streams-6APKUBMC.js.map +1 -0
  56. package/dist/react/index.d.ts +17 -0
  57. package/dist/react/index.d.ts.map +1 -1
  58. package/dist/react/index.js +8722 -159
  59. package/dist/react/index.js.map +1 -1
  60. package/dist/react/loadSso-WMS367NT.js +595 -0
  61. package/dist/react/loadSso-WMS367NT.js.map +1 -0
  62. package/dist/react/services/core.service.d.ts +8 -0
  63. package/dist/react/services/core.service.d.ts.map +1 -1
  64. package/dist/react/signin-2I7AG6XI.js +707 -0
  65. package/dist/react/signin-2I7AG6XI.js.map +1 -0
  66. package/dist/react/sso-oidc-OAJ7SALL.js +825 -0
  67. package/dist/react/sso-oidc-OAJ7SALL.js.map +1 -0
  68. package/dist/react/sts-LKM23TRV.js +3866 -0
  69. package/dist/react/sts-LKM23TRV.js.map +1 -0
  70. package/package.json +1 -1
package/dist/cli/cli.js CHANGED
@@ -65,8 +65,15 @@ async function generateConfigFile(configDir, monoriseOutputDir, projectRoot) {
65
65
  const configOutputPath = path2.join(monoriseOutputDir, "config.ts");
66
66
  const initialConfigContent = `
67
67
  export enum Entity {}
68
+ export default {};
68
69
  `;
69
70
  fs2.writeFileSync(configOutputPath, initialConfigContent);
71
+ fs2.writeFileSync(
72
+ path2.join(monoriseOutputDir, "index.ts"),
73
+ `export * from './config';
74
+ export { default } from './config';
75
+ `
76
+ );
70
77
  const files = fs2.readdirSync(configDir).filter((file) => file.endsWith(".ts") && file !== "index.ts");
71
78
  const names = /* @__PURE__ */ new Set();
72
79
  const nameRegex = /^[a-z]+(-[a-z]+)*$/;
@@ -128,7 +135,7 @@ declare module '${moduleName}' {
128
135
  ${schemaMapEntries.join("\n ")}
129
136
  }
130
137
  }`;
131
- const moduleAugmentations = usesCombinedPackage ? augmentationBlock("monorise/base") : augmentationBlock("@monorise/base");
138
+ const moduleAugmentations = usesCombinedPackage ? augmentationBlock("monorise/base") : augmentationBlock("../base/index.js");
132
139
  const configOutputContent = `
133
140
  import type { z } from 'zod';
134
141
  ${imports.join("\n")}
@@ -201,20 +208,6 @@ async function generateHandleFile(monoriseConfig, projectRoot, monoriseOutputDir
201
208
  `Custom routes file not found: '${absoluteCustomRoutesPath}'. Please ensure 'customRoutes' in monorise.config.ts points to a valid file.`
202
209
  );
203
210
  }
204
- let routesModule;
205
- try {
206
- routesModule = await import(absoluteCustomRoutesPath);
207
- } catch (e) {
208
- throw new Error(
209
- `Failed to load custom routes file at '${absoluteCustomRoutesPath}'. Ensure it's a valid JavaScript/TypeScript module. Error: ${e.message}`
210
- );
211
- }
212
- const routesExport = routesModule.default;
213
- if (!routesExport || routesExport === null || typeof routesExport === "object" && !("get" in routesExport && "post" in routesExport && "use" in routesExport)) {
214
- throw new Error(
215
- `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.`
216
- );
217
- }
218
211
  let relativePathToRoutes = path2.relative(
219
212
  monoriseOutputDir,
220
213
  absoluteCustomRoutesPath
@@ -227,7 +220,7 @@ async function generateHandleFile(monoriseConfig, projectRoot, monoriseOutputDir
227
220
  appHandlerPayload = "{ routes }";
228
221
  }
229
222
  const usesCombinedPackage = detectCombinedPackage(projectRoot);
230
- const coreImportPath = usesCombinedPackage ? "monorise/core" : "@monorise/core";
223
+ const coreImportPath = usesCombinedPackage ? "monorise/core" : "../core/index.js";
231
224
  const combinedContent = `
232
225
  import CoreFactory from '${coreImportPath}';
233
226
  import config from './config';
@@ -1 +1 @@
1
- {"version":3,"sources":["../cli.ts","../commands/utils/detect-package.ts","../templates/root-tsconfig.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport 'tsx';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { execSync, spawn } from 'node:child_process';\nimport chokidar from 'chokidar';\nimport { fileURLToPath } from 'node:url';\nimport { detectCombinedPackage } from './commands/utils/detect-package';\nimport { ROOT_TSCONFIG_TEMPLATE } from './templates/root-tsconfig';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\nconst TEMPLATES_DIR = path.join(__dirname, 'templates', 'files');\n\nfunction readTemplate(filename: string): string {\n return fs.readFileSync(path.join(TEMPLATES_DIR, filename), 'utf-8');\n}\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\nfunction execCommand(\n command: string,\n cwd?: string,\n stdio: 'inherit' | 'pipe' = 'inherit',\n): void {\n console.log(`Running: ${command}`);\n execSync(command, { cwd, stdio });\n}\n\nasync function generateConfigFile(\n configDir: string,\n monoriseOutputDir: string,\n projectRoot: 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 // Detect whether the consumer uses the combined 'monorise' package or scoped '@monorise/*' packages\n const usesCombinedPackage = detectCombinedPackage(projectRoot);\n\n // Build module augmentation block\n const augmentationBlock = (moduleName: string) => `\ndeclare module '${moduleName}' {\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 // Augment the correct module based on which package is installed\n const moduleAugmentations = usesCombinedPackage\n ? augmentationBlock('monorise/base')\n : augmentationBlock('@monorise/base');\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${moduleAugmentations}\n`;\n\n fs.writeFileSync(configOutputPath, configOutputContent);\n console.log('Successfully generated config.ts!');\n\n // Also generate index.ts re-exporting everything from config.ts, so consumers\n // can import from '#/monorise' directly instead of '#/monorise/config'.\n // config.ts keeps being generated for backward compatibility.\n const indexOutputPath = path.join(monoriseOutputDir, 'index.ts');\n fs.writeFileSync(\n indexOutputPath,\n `export * from './config';\\nexport { default } from './config';\\n`,\n );\n console.log('Successfully generated index.ts!');\n\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 // Detect whether the consumer uses the combined 'monorise' package or scoped '@monorise/*' packages\n const usesCombinedPackage = detectCombinedPackage(projectRoot);\n const coreImportPath = usesCombinedPackage ? 'monorise/core' : '@monorise/core';\n\n const combinedContent = `\nimport CoreFactory from '${coreImportPath}';\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, projectRoot);\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 console.log(MONORISE_LOGO);\n\n // Determine project name and root\n let projectName = 'my-app';\n let projectRoot: string;\n\n if (rootPath) {\n projectRoot = path.resolve(rootPath);\n projectName = path.basename(projectRoot);\n } else {\n // Prompt for project name (simple approach for now)\n const args = process.argv.slice(2);\n const nameIndex = args.indexOf('--name');\n if (nameIndex > -1 && args[nameIndex + 1]) {\n projectName = args[nameIndex + 1];\n }\n projectRoot = path.resolve(projectName);\n }\n\n console.log(`\\n🚀 Creating Monorise project: ${projectName}\\n`);\n\n // Check if directory exists\n if (fs.existsSync(projectRoot)) {\n console.error(`Error: Directory ${projectName} already exists.`);\n process.exit(1);\n }\n\n // Step 1: Create project directory structure\n console.log('📁 Creating project structure...');\n fs.mkdirSync(projectRoot, { recursive: true });\n fs.mkdirSync(path.join(projectRoot, 'apps'), { recursive: true });\n fs.mkdirSync(path.join(projectRoot, 'services', 'core'), { recursive: true });\n fs.mkdirSync(path.join(projectRoot, 'monorise', 'configs'), { recursive: true });\n fs.mkdirSync(path.join(projectRoot, 'monorise', 'mutuals'), { recursive: true });\n\n // Step 2: Create root package.json\n console.log('📦 Initializing root package.json...');\n const rootPackageJson = {\n name: projectName,\n version: '0.0.0',\n type: 'module',\n private: true,\n workspaces: ['apps/*', 'services/*'],\n };\n fs.writeFileSync(\n path.join(projectRoot, 'package.json'),\n JSON.stringify(rootPackageJson, null, 2),\n );\n\n // Step 3: Create root tsconfig.json\n console.log('⚙️ Creating root tsconfig.json...');\n fs.writeFileSync(\n path.join(projectRoot, 'tsconfig.json'),\n JSON.stringify(ROOT_TSCONFIG_TEMPLATE, null, 2),\n );\n\n // Step 4: Create Next.js app in apps/web\n console.log('\\n📱 Creating Next.js app in apps/web...');\n const nextAppDir = path.join(projectRoot, 'apps', 'web');\n try {\n execCommand(\n `npx create-next-app@latest web --typescript --tailwind --eslint --app --no-src-dir --import-alias \"#/*\" --no-turbopack --yes`,\n path.join(projectRoot, 'apps'),\n );\n } catch (error) {\n console.error('Failed to create Next.js app:', error);\n process.exit(1);\n }\n\n // Step 5: Install SST v4\n console.log('\\n☁️ Installing SST v4...');\n try {\n execCommand('npm install sst@^4 --save-dev', projectRoot);\n } catch (error) {\n console.error('Failed to install SST:', error);\n process.exit(1);\n }\n\n // Step 6: Install dependencies\n console.log('\\n📦 Installing dependencies (monorise, hono, zod, shadcn utilities)...');\n try {\n execCommand('npm install monorise hono zod clsx class-variance-authority radix-ui lucide-react tailwind-merge react-hook-form @hookform/resolvers', projectRoot);\n } catch (error) {\n console.error('Failed to install dependencies:', error);\n process.exit(1);\n }\n\n // Step 7: Create monorise.config.ts\n console.log('⚙️ Creating monorise.config.ts...');\n fs.writeFileSync(\n path.join(projectRoot, 'monorise.config.ts'),\n readTemplate('monorise.config.ts'),\n );\n\n // Step 8: Create shared mutual config (referenced by both User and Team)\n console.log('🔗 Creating team-membership mutual config...');\n fs.writeFileSync(\n path.join(projectRoot, 'monorise', 'mutuals', 'team-membership.ts'),\n readTemplate('team-membership.mutual.ts'),\n );\n\n // Step 9: Create starter entities (User <-> Team mutual relationship)\n console.log('👤 Creating starter User entity...');\n fs.writeFileSync(\n path.join(projectRoot, 'monorise', 'configs', 'user.ts'),\n readTemplate('user-entity.ts'),\n );\n console.log('👥 Creating starter Team entity...');\n fs.writeFileSync(\n path.join(projectRoot, 'monorise', 'configs', 'team.ts'),\n readTemplate('team-entity.ts'),\n );\n\n // Step 10: Create services/core/routes.ts\n console.log('🔧 Creating services/core/routes.ts...');\n fs.writeFileSync(\n path.join(projectRoot, 'services', 'core', 'routes.ts'),\n readTemplate('core-routes.ts'),\n );\n\n // Step 11: Create services package.json\n const servicesPackageJson = {\n name: '@my-app/services',\n version: '0.0.0',\n type: 'module',\n };\n fs.writeFileSync(\n path.join(projectRoot, 'services', 'core', 'package.json'),\n JSON.stringify(servicesPackageJson, null, 2),\n );\n\n // Step 12: Create sst.config.ts with monorise\n console.log('⚙️ Creating sst.config.ts with Monorise...');\n const sstConfigPath = path.join(projectRoot, 'sst.config.ts');\n fs.writeFileSync(sstConfigPath, readTemplate('sst.config.ts').replace('{{PROJECT_NAME}}', projectName));\n\n // Step 13: Install SST providers (after sst.config.ts exists)\n console.log('\\n☁️ Installing SST providers...');\n try {\n execCommand('npx sst install', projectRoot);\n } catch (error) {\n console.warn('Warning: SST install failed, continuing anyway...');\n }\n\n // Step 14: Create example page in apps/web\n console.log('📄 Creating example page in apps/web...');\n const webSrcAppDir = path.join(projectRoot, 'apps', 'web', 'src', 'app');\n const webAppDir = path.join(projectRoot, 'apps', 'web', 'app');\n const pagePath = fs.existsSync(webSrcAppDir)\n ? path.join(webSrcAppDir, 'page.tsx')\n : fs.existsSync(webAppDir)\n ? path.join(webAppDir, 'page.tsx')\n : null;\n\n if (pagePath) {\n try {\n fs.writeFileSync(pagePath, readTemplate('example-page.tsx'));\n console.log(`Created example page at ${path.relative(projectRoot, pagePath)}`);\n } catch (error) {\n console.warn('Warning: Could not create example page:', error);\n }\n } else {\n console.warn('Warning: Could not find apps/web/src/app or apps/web/app directory');\n }\n\n // Step 15: Create global components, lib/utils, UI components, and globals.css\n const webRoot = fs.existsSync(webSrcAppDir)\n ? path.join(projectRoot, 'apps', 'web', 'src')\n : fs.existsSync(webAppDir)\n ? path.join(projectRoot, 'apps', 'web')\n : null;\n\n if (webRoot) {\n const appDir = fs.existsSync(webSrcAppDir) ? webSrcAppDir : webAppDir;\n\n // Create directories\n fs.mkdirSync(path.join(webRoot, 'components', 'ui'), { recursive: true });\n fs.mkdirSync(path.join(webRoot, 'lib'), { recursive: true });\n\n // Global components\n console.log('🌐 Creating global components...');\n fs.writeFileSync(\n path.join(webRoot, 'components', 'global-initializer.tsx'),\n readTemplate('global-initializer.tsx'),\n );\n fs.writeFileSync(\n path.join(webRoot, 'components', 'global-loader.tsx'),\n readTemplate('global-loader.tsx'),\n );\n\n // lib/utils.ts\n console.log('🔧 Creating lib/utils.ts...');\n fs.writeFileSync(\n path.join(webRoot, 'lib', 'utils.ts'),\n readTemplate('lib-utils.ts'),\n );\n\n // Shadcn UI components\n console.log('🎨 Creating shadcn UI components...');\n fs.writeFileSync(\n path.join(webRoot, 'components', 'ui', 'button.tsx'),\n readTemplate('ui-button.tsx'),\n );\n fs.writeFileSync(\n path.join(webRoot, 'components', 'ui', 'card.tsx'),\n readTemplate('ui-card.tsx'),\n );\n fs.writeFileSync(\n path.join(webRoot, 'components', 'ui', 'input.tsx'),\n readTemplate('ui-input.tsx'),\n );\n fs.writeFileSync(\n path.join(webRoot, 'components', 'ui', 'label.tsx'),\n readTemplate('ui-label.tsx'),\n );\n\n // Replace globals.css with shadcn theme\n console.log('🎨 Setting up shadcn globals.css...');\n const globalsCssPath = path.join(appDir, 'globals.css');\n fs.writeFileSync(globalsCssPath, readTemplate('globals.css'));\n\n // Update layout.tsx with GlobalInitializer, GlobalLoader, and loader-portal\n console.log('📐 Updating layout.tsx with global components...');\n const layoutPath = path.join(appDir, 'layout.tsx');\n if (fs.existsSync(layoutPath)) {\n try {\n let layoutContent = fs.readFileSync(layoutPath, 'utf8');\n\n // Add imports after existing imports\n const globalImports = `import GlobalInitializer from '#/components/global-initializer';\\nimport GlobalLoader from '#/components/global-loader';`;\n // Insert after the last import statement\n const lastImportIndex = layoutContent.lastIndexOf('import ');\n const lineEnd = layoutContent.indexOf('\\n', lastImportIndex);\n layoutContent =\n layoutContent.slice(0, lineEnd + 1) +\n globalImports +\n '\\n' +\n layoutContent.slice(lineEnd + 1);\n\n // Add loader-portal div and global components inside <body>\n layoutContent = layoutContent.replace(\n /(<body[^>]*>)/,\n `$1\\n <div id=\"loader-portal\" />\\n <GlobalInitializer />\\n <GlobalLoader />`,\n );\n\n fs.writeFileSync(layoutPath, layoutContent);\n } catch (error) {\n console.warn('Warning: Could not update layout.tsx:', error);\n }\n }\n\n // Replace postcss.config.mjs with @tailwindcss/postcss\n const postcssPath = path.join(projectRoot, 'apps', 'web', 'postcss.config.mjs');\n if (fs.existsSync(postcssPath)) {\n fs.writeFileSync(\n postcssPath,\n `const config = {\\n plugins: {\\n '@tailwindcss/postcss': {},\\n },\\n};\\n\\nexport default config;\\n`,\n );\n }\n\n // Create API proxy routes\n console.log('🔀 Creating API proxy routes...');\n const apiDir = path.join(appDir, 'api');\n const catchAllDir = path.join(apiDir, '[...proxy]');\n fs.mkdirSync(catchAllDir, { recursive: true });\n fs.writeFileSync(\n path.join(apiDir, 'proxy-request.ts'),\n readTemplate('proxy-request.ts'),\n );\n fs.writeFileSync(\n path.join(catchAllDir, 'route.ts'),\n readTemplate('proxy-route.ts'),\n );\n }\n\n // Step 16: Update apps/web tsconfig.json with monorise path alias\n console.log('⚙️ Updating apps/web tsconfig.json...');\n const webTsconfigPath = path.join(projectRoot, 'apps', 'web', 'tsconfig.json');\n if (fs.existsSync(webTsconfigPath)) {\n try {\n const webTsconfigContent = fs.readFileSync(webTsconfigPath, 'utf8');\n const webTsconfig = JSON.parse(webTsconfigContent);\n\n if (!webTsconfig.compilerOptions) {\n webTsconfig.compilerOptions = {};\n }\n if (!webTsconfig.compilerOptions.paths) {\n webTsconfig.compilerOptions.paths = {};\n }\n\n // Add path aliases\n webTsconfig.compilerOptions.paths['#/shared/*'] = ['../../shared/*'];\n webTsconfig.compilerOptions.paths['#/monorise/*'] = ['../../.monorise/*'];\n // Exact-match alias so `import { Entity } from '#/monorise'` resolves to\n // the generated index.ts (re-exports config.ts, kept for backward compat).\n webTsconfig.compilerOptions.paths['#/monorise'] = ['../../.monorise/index'];\n const hasSrcDir = fs.existsSync(path.join(projectRoot, 'apps', 'web', 'src'));\n webTsconfig.compilerOptions.paths['#/*'] = [hasSrcDir ? './src/*' : './*'];\n\n fs.writeFileSync(webTsconfigPath, JSON.stringify(webTsconfig, null, 2));\n } catch (error) {\n console.warn('Warning: Could not update apps/web tsconfig.json:', error);\n }\n }\n\n // Step 16: Run initial monorise build to generate .monorise files\n console.log('\\n🔨 Running initial Monorise build...');\n try {\n execCommand('npx monorise build', projectRoot);\n } catch (error) {\n console.warn('Warning: Initial monorise build failed. You can run it manually later.');\n }\n\n console.log('\\n' + '='.repeat(60));\n console.log('✅ Monorise project created successfully!');\n console.log('='.repeat(60));\n console.log(`\\n📁 Project structure:`);\n console.log(` ${projectName}/`);\n console.log(` ├── apps/web/ # Next.js frontend`);\n console.log(` ├── services/core/ # Backend routes (Hono)`);\n console.log(` ├── monorise/configs/ # Entity definitions (User, Team)`);\n console.log(` ├── monorise/mutuals/ # Shared mutual relationship configs`);\n console.log(` └── .monorise/ # Generated files`);\n console.log(`\\n📂 Where to start coding:`);\n console.log(` • Edit your data model → monorise/configs/user.ts`);\n console.log(` (Add fields like phone, role, status to the User entity)`);\n console.log(\n ` • Build your UI → ${pagePath ? path.relative(projectRoot, pagePath) : 'apps/web/app/page.tsx'}`,\n );\n console.log(` (React components using useEntities and createEntity)`);\n console.log(` • Add backend logic → services/core/routes.ts`);\n console.log(` (Custom API endpoints with Hono)`);\n console.log(` • See the User <-> Team relationship → monorise/mutuals/team-membership.ts`);\n console.log(` (createMutualConfig — shared schema, referenced from both entity configs)`);\n console.log(`\\n🚀 Next steps:`);\n console.log(` cd ${projectName}`);\n console.log(` npx sst dev`);\n console.log('\\n📚 Documentation: https://monorise.dev');\n console.log('');\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 // init is greenfield-only — it always creates a fresh directory named via\n // --name, never an existing path. --config-root doesn't apply here.\n await runInitCommand();\n } else {\n console.error(\n 'Unknown command. Usage:\\n' +\n ' monorise dev [--config-root <path>]\\n' +\n ' monorise build [--config-root <path>]\\n' +\n ' monorise init [--name <project-name>]',\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","import fs from 'node:fs';\nimport path from 'node:path';\n\n/**\n * Detects whether the combined 'monorise' package is installed by walking up\n * the directory tree. This handles monorepo setups where dependencies are\n * hoisted to the root node_modules.\n */\nexport function detectCombinedPackage(startDir: string): boolean {\n let dir = startDir;\n while (true) {\n if (fs.existsSync(path.join(dir, 'node_modules', 'monorise'))) {\n return true;\n }\n const parent = path.dirname(dir);\n if (parent === dir) break; // reached filesystem root\n dir = parent;\n }\n return false;\n}\n","export const ROOT_TSCONFIG_TEMPLATE = {\n compilerOptions: {\n target: 'ES2022',\n module: 'ESNext',\n moduleResolution: 'bundler',\n esModuleInterop: true,\n strict: true,\n skipLibCheck: true,\n jsx: 'preserve',\n paths: {\n '#/shared/*': ['./shared/*'],\n '#/monorise/*': ['./.monorise/*'],\n '#/monorise': ['./.monorise/index'],\n },\n },\n include: ['**/*.ts', '.monorise/**/*.ts'],\n exclude: ['node_modules', 'apps'],\n};\n"],"mappings":";;;AAEA,OAAO;AACP,OAAOA,SAAQ;AACf,OAAOC,WAAU;AACjB,SAAS,gBAAuB;AAChC,OAAO,cAAc;AACrB,SAAS,qBAAqB;;;ACP9B,OAAO,QAAQ;AACf,OAAO,UAAU;AAOV,SAAS,sBAAsB,UAA2B;AAC/D,MAAI,MAAM;AACV,SAAO,MAAM;AACX,QAAI,GAAG,WAAW,KAAK,KAAK,KAAK,gBAAgB,UAAU,CAAC,GAAG;AAC7D,aAAO;AAAA,IACT;AACA,UAAM,SAA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W,YAAY,QAAQ;AAG7B,YAAM,eAAe;AAAA,IACvB,OAAO;AACL,cAAQ;AAAA,QACN;AAAA,MAIF;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":["fs","path","path","fs"]}
1
+ {"version":3,"sources":["../cli.ts","../commands/utils/detect-package.ts","../templates/root-tsconfig.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport 'tsx';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { execSync, spawn } from 'node:child_process';\nimport chokidar from 'chokidar';\nimport { fileURLToPath } from 'node:url';\nimport { detectCombinedPackage } from './commands/utils/detect-package';\nimport { ROOT_TSCONFIG_TEMPLATE } from './templates/root-tsconfig';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\nconst TEMPLATES_DIR = path.join(__dirname, 'templates', 'files');\n\nfunction readTemplate(filename: string): string {\n return fs.readFileSync(path.join(TEMPLATES_DIR, filename), 'utf-8');\n}\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\nfunction execCommand(\n command: string,\n cwd?: string,\n stdio: 'inherit' | 'pipe' = 'inherit',\n): void {\n console.log(`Running: ${command}`);\n execSync(command, { cwd, stdio });\n}\n\nasync function generateConfigFile(\n configDir: string,\n monoriseOutputDir: string,\n projectRoot: string,\n): Promise<string> {\n const configOutputPath = path.join(monoriseOutputDir, 'config.ts');\n const initialConfigContent = `\nexport enum Entity {}\nexport default {};\n`;\n fs.writeFileSync(configOutputPath, initialConfigContent);\n fs.writeFileSync(\n path.join(monoriseOutputDir, 'index.ts'),\n `export * from './config';\\nexport { default } from './config';\\n`,\n );\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 // Detect whether the consumer uses the combined 'monorise' package or scoped '@monorise/*' packages\n const usesCombinedPackage = detectCombinedPackage(projectRoot);\n\n // Build module augmentation block\n const augmentationBlock = (moduleName: string) => `\ndeclare module '${moduleName}' {\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 // Augment the correct module based on which package is installed\n const moduleAugmentations = usesCombinedPackage\n ? augmentationBlock('monorise/base')\n : augmentationBlock('@monorise/base');\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${moduleAugmentations}\n`;\n\n fs.writeFileSync(configOutputPath, configOutputContent);\n console.log('Successfully generated config.ts!');\n\n // Also generate index.ts re-exporting everything from config.ts, so consumers\n // can import from '#/monorise' directly instead of '#/monorise/config'.\n // config.ts keeps being generated for backward compatibility.\n const indexOutputPath = path.join(monoriseOutputDir, 'index.ts');\n fs.writeFileSync(\n indexOutputPath,\n `export * from './config';\\nexport { default } from './config';\\n`,\n );\n console.log('Successfully generated index.ts!');\n\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 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 // Detect whether the consumer uses the combined 'monorise' package or scoped '@monorise/*' packages\n const usesCombinedPackage = detectCombinedPackage(projectRoot);\n const coreImportPath = usesCombinedPackage ? 'monorise/core' : '@monorise/core';\n\n const combinedContent = `\nimport CoreFactory from '${coreImportPath}';\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, projectRoot);\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 console.log(MONORISE_LOGO);\n\n // Determine project name and root\n let projectName = 'my-app';\n let projectRoot: string;\n\n if (rootPath) {\n projectRoot = path.resolve(rootPath);\n projectName = path.basename(projectRoot);\n } else {\n // Prompt for project name (simple approach for now)\n const args = process.argv.slice(2);\n const nameIndex = args.indexOf('--name');\n if (nameIndex > -1 && args[nameIndex + 1]) {\n projectName = args[nameIndex + 1];\n }\n projectRoot = path.resolve(projectName);\n }\n\n console.log(`\\n🚀 Creating Monorise project: ${projectName}\\n`);\n\n // Check if directory exists\n if (fs.existsSync(projectRoot)) {\n console.error(`Error: Directory ${projectName} already exists.`);\n process.exit(1);\n }\n\n // Step 1: Create project directory structure\n console.log('📁 Creating project structure...');\n fs.mkdirSync(projectRoot, { recursive: true });\n fs.mkdirSync(path.join(projectRoot, 'apps'), { recursive: true });\n fs.mkdirSync(path.join(projectRoot, 'services', 'core'), { recursive: true });\n fs.mkdirSync(path.join(projectRoot, 'monorise', 'configs'), { recursive: true });\n fs.mkdirSync(path.join(projectRoot, 'monorise', 'mutuals'), { recursive: true });\n\n // Step 2: Create root package.json\n console.log('📦 Initializing root package.json...');\n const rootPackageJson = {\n name: projectName,\n version: '0.0.0',\n type: 'module',\n private: true,\n workspaces: ['apps/*', 'services/*'],\n };\n fs.writeFileSync(\n path.join(projectRoot, 'package.json'),\n JSON.stringify(rootPackageJson, null, 2),\n );\n\n // Step 3: Create root tsconfig.json\n console.log('⚙️ Creating root tsconfig.json...');\n fs.writeFileSync(\n path.join(projectRoot, 'tsconfig.json'),\n JSON.stringify(ROOT_TSCONFIG_TEMPLATE, null, 2),\n );\n\n // Step 4: Create Next.js app in apps/web\n console.log('\\n📱 Creating Next.js app in apps/web...');\n const nextAppDir = path.join(projectRoot, 'apps', 'web');\n try {\n execCommand(\n `npx create-next-app@latest web --typescript --tailwind --eslint --app --no-src-dir --import-alias \"#/*\" --no-turbopack --yes`,\n path.join(projectRoot, 'apps'),\n );\n } catch (error) {\n console.error('Failed to create Next.js app:', error);\n process.exit(1);\n }\n\n // Step 5: Install SST v4\n console.log('\\n☁️ Installing SST v4...');\n try {\n execCommand('npm install sst@^4 --save-dev', projectRoot);\n } catch (error) {\n console.error('Failed to install SST:', error);\n process.exit(1);\n }\n\n // Step 6: Install dependencies\n console.log('\\n📦 Installing dependencies (monorise, hono, zod, shadcn utilities)...');\n try {\n execCommand('npm install monorise hono zod clsx class-variance-authority radix-ui lucide-react tailwind-merge react-hook-form @hookform/resolvers', projectRoot);\n } catch (error) {\n console.error('Failed to install dependencies:', error);\n process.exit(1);\n }\n\n // Step 7: Create monorise.config.ts\n console.log('⚙️ Creating monorise.config.ts...');\n fs.writeFileSync(\n path.join(projectRoot, 'monorise.config.ts'),\n readTemplate('monorise.config.ts'),\n );\n\n // Step 8: Create shared mutual config (referenced by both User and Team)\n console.log('🔗 Creating team-membership mutual config...');\n fs.writeFileSync(\n path.join(projectRoot, 'monorise', 'mutuals', 'team-membership.ts'),\n readTemplate('team-membership.mutual.ts'),\n );\n\n // Step 9: Create starter entities (User <-> Team mutual relationship)\n console.log('👤 Creating starter User entity...');\n fs.writeFileSync(\n path.join(projectRoot, 'monorise', 'configs', 'user.ts'),\n readTemplate('user-entity.ts'),\n );\n console.log('👥 Creating starter Team entity...');\n fs.writeFileSync(\n path.join(projectRoot, 'monorise', 'configs', 'team.ts'),\n readTemplate('team-entity.ts'),\n );\n\n // Step 10: Create services/core/routes.ts\n console.log('🔧 Creating services/core/routes.ts...');\n fs.writeFileSync(\n path.join(projectRoot, 'services', 'core', 'routes.ts'),\n readTemplate('core-routes.ts'),\n );\n\n // Step 11: Create services package.json\n const servicesPackageJson = {\n name: '@my-app/services',\n version: '0.0.0',\n type: 'module',\n };\n fs.writeFileSync(\n path.join(projectRoot, 'services', 'core', 'package.json'),\n JSON.stringify(servicesPackageJson, null, 2),\n );\n\n // Step 12: Create sst.config.ts with monorise\n console.log('⚙️ Creating sst.config.ts with Monorise...');\n const sstConfigPath = path.join(projectRoot, 'sst.config.ts');\n fs.writeFileSync(sstConfigPath, readTemplate('sst.config.ts').replace('{{PROJECT_NAME}}', projectName));\n\n // Step 13: Install SST providers (after sst.config.ts exists)\n console.log('\\n☁️ Installing SST providers...');\n try {\n execCommand('npx sst install', projectRoot);\n } catch (error) {\n console.warn('Warning: SST install failed, continuing anyway...');\n }\n\n // Step 14: Create example page in apps/web\n console.log('📄 Creating example page in apps/web...');\n const webSrcAppDir = path.join(projectRoot, 'apps', 'web', 'src', 'app');\n const webAppDir = path.join(projectRoot, 'apps', 'web', 'app');\n const pagePath = fs.existsSync(webSrcAppDir)\n ? path.join(webSrcAppDir, 'page.tsx')\n : fs.existsSync(webAppDir)\n ? path.join(webAppDir, 'page.tsx')\n : null;\n\n if (pagePath) {\n try {\n fs.writeFileSync(pagePath, readTemplate('example-page.tsx'));\n console.log(`Created example page at ${path.relative(projectRoot, pagePath)}`);\n } catch (error) {\n console.warn('Warning: Could not create example page:', error);\n }\n } else {\n console.warn('Warning: Could not find apps/web/src/app or apps/web/app directory');\n }\n\n // Step 15: Create global components, lib/utils, UI components, and globals.css\n const webRoot = fs.existsSync(webSrcAppDir)\n ? path.join(projectRoot, 'apps', 'web', 'src')\n : fs.existsSync(webAppDir)\n ? path.join(projectRoot, 'apps', 'web')\n : null;\n\n if (webRoot) {\n const appDir = fs.existsSync(webSrcAppDir) ? webSrcAppDir : webAppDir;\n\n // Create directories\n fs.mkdirSync(path.join(webRoot, 'components', 'ui'), { recursive: true });\n fs.mkdirSync(path.join(webRoot, 'lib'), { recursive: true });\n\n // Global components\n console.log('🌐 Creating global components...');\n fs.writeFileSync(\n path.join(webRoot, 'components', 'global-initializer.tsx'),\n readTemplate('global-initializer.tsx'),\n );\n fs.writeFileSync(\n path.join(webRoot, 'components', 'global-loader.tsx'),\n readTemplate('global-loader.tsx'),\n );\n\n // lib/utils.ts\n console.log('🔧 Creating lib/utils.ts...');\n fs.writeFileSync(\n path.join(webRoot, 'lib', 'utils.ts'),\n readTemplate('lib-utils.ts'),\n );\n\n // Shadcn UI components\n console.log('🎨 Creating shadcn UI components...');\n fs.writeFileSync(\n path.join(webRoot, 'components', 'ui', 'button.tsx'),\n readTemplate('ui-button.tsx'),\n );\n fs.writeFileSync(\n path.join(webRoot, 'components', 'ui', 'card.tsx'),\n readTemplate('ui-card.tsx'),\n );\n fs.writeFileSync(\n path.join(webRoot, 'components', 'ui', 'input.tsx'),\n readTemplate('ui-input.tsx'),\n );\n fs.writeFileSync(\n path.join(webRoot, 'components', 'ui', 'label.tsx'),\n readTemplate('ui-label.tsx'),\n );\n\n // Replace globals.css with shadcn theme\n console.log('🎨 Setting up shadcn globals.css...');\n const globalsCssPath = path.join(appDir, 'globals.css');\n fs.writeFileSync(globalsCssPath, readTemplate('globals.css'));\n\n // Update layout.tsx with GlobalInitializer, GlobalLoader, and loader-portal\n console.log('📐 Updating layout.tsx with global components...');\n const layoutPath = path.join(appDir, 'layout.tsx');\n if (fs.existsSync(layoutPath)) {\n try {\n let layoutContent = fs.readFileSync(layoutPath, 'utf8');\n\n // Add imports after existing imports\n const globalImports = `import GlobalInitializer from '#/components/global-initializer';\\nimport GlobalLoader from '#/components/global-loader';`;\n // Insert after the last import statement\n const lastImportIndex = layoutContent.lastIndexOf('import ');\n const lineEnd = layoutContent.indexOf('\\n', lastImportIndex);\n layoutContent =\n layoutContent.slice(0, lineEnd + 1) +\n globalImports +\n '\\n' +\n layoutContent.slice(lineEnd + 1);\n\n // Add loader-portal div and global components inside <body>\n layoutContent = layoutContent.replace(\n /(<body[^>]*>)/,\n `$1\\n <div id=\"loader-portal\" />\\n <GlobalInitializer />\\n <GlobalLoader />`,\n );\n\n fs.writeFileSync(layoutPath, layoutContent);\n } catch (error) {\n console.warn('Warning: Could not update layout.tsx:', error);\n }\n }\n\n // Replace postcss.config.mjs with @tailwindcss/postcss\n const postcssPath = path.join(projectRoot, 'apps', 'web', 'postcss.config.mjs');\n if (fs.existsSync(postcssPath)) {\n fs.writeFileSync(\n postcssPath,\n `const config = {\\n plugins: {\\n '@tailwindcss/postcss': {},\\n },\\n};\\n\\nexport default config;\\n`,\n );\n }\n\n // Create API proxy routes\n console.log('🔀 Creating API proxy routes...');\n const apiDir = path.join(appDir, 'api');\n const catchAllDir = path.join(apiDir, '[...proxy]');\n fs.mkdirSync(catchAllDir, { recursive: true });\n fs.writeFileSync(\n path.join(apiDir, 'proxy-request.ts'),\n readTemplate('proxy-request.ts'),\n );\n fs.writeFileSync(\n path.join(catchAllDir, 'route.ts'),\n readTemplate('proxy-route.ts'),\n );\n }\n\n // Step 16: Update apps/web tsconfig.json with monorise path alias\n console.log('⚙️ Updating apps/web tsconfig.json...');\n const webTsconfigPath = path.join(projectRoot, 'apps', 'web', 'tsconfig.json');\n if (fs.existsSync(webTsconfigPath)) {\n try {\n const webTsconfigContent = fs.readFileSync(webTsconfigPath, 'utf8');\n const webTsconfig = JSON.parse(webTsconfigContent);\n\n if (!webTsconfig.compilerOptions) {\n webTsconfig.compilerOptions = {};\n }\n if (!webTsconfig.compilerOptions.paths) {\n webTsconfig.compilerOptions.paths = {};\n }\n\n // Add path aliases\n webTsconfig.compilerOptions.paths['#/shared/*'] = ['../../shared/*'];\n webTsconfig.compilerOptions.paths['#/monorise/*'] = ['../../.monorise/*'];\n // Exact-match alias so `import { Entity } from '#/monorise'` resolves to\n // the generated index.ts (re-exports config.ts, kept for backward compat).\n webTsconfig.compilerOptions.paths['#/monorise'] = ['../../.monorise/index'];\n const hasSrcDir = fs.existsSync(path.join(projectRoot, 'apps', 'web', 'src'));\n webTsconfig.compilerOptions.paths['#/*'] = [hasSrcDir ? './src/*' : './*'];\n\n fs.writeFileSync(webTsconfigPath, JSON.stringify(webTsconfig, null, 2));\n } catch (error) {\n console.warn('Warning: Could not update apps/web tsconfig.json:', error);\n }\n }\n\n // Step 16: Run initial monorise build to generate .monorise files\n console.log('\\n🔨 Running initial Monorise build...');\n try {\n execCommand('npx monorise build', projectRoot);\n } catch (error) {\n console.warn('Warning: Initial monorise build failed. You can run it manually later.');\n }\n\n console.log('\\n' + '='.repeat(60));\n console.log('✅ Monorise project created successfully!');\n console.log('='.repeat(60));\n console.log(`\\n📁 Project structure:`);\n console.log(` ${projectName}/`);\n console.log(` ├── apps/web/ # Next.js frontend`);\n console.log(` ├── services/core/ # Backend routes (Hono)`);\n console.log(` ├── monorise/configs/ # Entity definitions (User, Team)`);\n console.log(` ├── monorise/mutuals/ # Shared mutual relationship configs`);\n console.log(` └── .monorise/ # Generated files`);\n console.log(`\\n📂 Where to start coding:`);\n console.log(` • Edit your data model → monorise/configs/user.ts`);\n console.log(` (Add fields like phone, role, status to the User entity)`);\n console.log(\n ` • Build your UI → ${pagePath ? path.relative(projectRoot, pagePath) : 'apps/web/app/page.tsx'}`,\n );\n console.log(` (React components using useEntities and createEntity)`);\n console.log(` • Add backend logic → services/core/routes.ts`);\n console.log(` (Custom API endpoints with Hono)`);\n console.log(` • See the User <-> Team relationship → monorise/mutuals/team-membership.ts`);\n console.log(` (createMutualConfig — shared schema, referenced from both entity configs)`);\n console.log(`\\n🚀 Next steps:`);\n console.log(` cd ${projectName}`);\n console.log(` npx sst dev`);\n console.log('\\n📚 Documentation: https://monorise.dev');\n console.log('');\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 // init is greenfield-only — it always creates a fresh directory named via\n // --name, never an existing path. --config-root doesn't apply here.\n await runInitCommand();\n } else {\n console.error(\n 'Unknown command. Usage:\\n' +\n ' monorise dev [--config-root <path>]\\n' +\n ' monorise build [--config-root <path>]\\n' +\n ' monorise init [--name <project-name>]',\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","import fs from 'node:fs';\nimport path from 'node:path';\n\n/**\n * Detects whether the combined 'monorise' package is installed by walking up\n * the directory tree. This handles monorepo setups where dependencies are\n * hoisted to the root node_modules.\n */\nexport function detectCombinedPackage(startDir: string): boolean {\n let dir = startDir;\n while (true) {\n if (fs.existsSync(path.join(dir, 'node_modules', 'monorise'))) {\n return true;\n }\n const parent = path.dirname(dir);\n if (parent === dir) break; // reached filesystem root\n dir = parent;\n }\n return false;\n}\n","export const ROOT_TSCONFIG_TEMPLATE = {\n compilerOptions: {\n target: 'ES2022',\n module: 'ESNext',\n moduleResolution: 'bundler',\n esModuleInterop: true,\n strict: true,\n skipLibCheck: true,\n jsx: 'preserve',\n paths: {\n '#/shared/*': ['./shared/*'],\n '#/monorise/*': ['./.monorise/*'],\n '#/monorise': ['./.monorise/index'],\n },\n },\n include: ['**/*.ts', '.monorise/**/*.ts'],\n exclude: ['node_modules', 'apps'],\n};\n"],"mappings":";;;AAEA,OAAO;AACP,OAAOA,SAAQ;AACf,OAAOC,WAAU;AACjB,SAAS,gBAAuB;AAChC,OAAO,cAAc;AACrB,SAAS,qBAAqB;;;ACP9B,OAAO,QAAQ;AACf,OAAO,UAAU;AAOV,SAAS,sBAAsB,UAA2B;AAC/D,MAAI,MAAM;AACV,SAAO,MAAM;AACX,QAAI,GAAG,WAAW,KAAK,KAAK,KAAK,gBAAgB,UAAU,CAAC,GAAG;AAC7D,aAAO;AAAA,IACT;AACA,UAAM,SAAS,KAAK,QAAQ,GAAG;AAC/B,QAAI,WAAW,IAAK;AACpB,UAAM;AAAA,EACR;AACA,SAAO;AACT;;;ACnBO,IAAM,yBAAyB;AAAA,EACpC,iBAAiB;AAAA,IACf,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,kBAAkB;AAAA,IAClB,iBAAiB;AAAA,IACjB,QAAQ;AAAA,IACR,cAAc;AAAA,IACd,KAAK;AAAA,IACL,OAAO;AAAA,MACL,cAAc,CAAC,YAAY;AAAA,MAC3B,gBAAgB,CAAC,eAAe;AAAA,MAChC,cAAc,CAAC,mBAAmB;AAAA,IACpC;AAAA,EACF;AAAA,EACA,SAAS,CAAC,WAAW,mBAAmB;AAAA,EACxC,SAAS,CAAC,gBAAgB,MAAM;AAClC;;;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,gBAAgB,UAAmB;AAChD,UAAQ,IAAI,uBAAuB;AACnC,QAAM,cAAc,QAAQ;AAC9B;AAEA,eAAe,OAAO;AACpB,QAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,QAAM,UAAU,KAAK,CAAC;AAEtB,MAAI;AACJ,QAAM,gBAAgB,KAAK,QAAQ,eAAe;AAClD,MAAI,gBAAgB,MAAM,KAAK,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;AAG7B,YAAM,eAAe;AAAA,IACvB,OAAO;AACL,cAAQ;AAAA,QACN;AAAA,MAIF;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":["fs","path","path","fs"]}
@@ -90,7 +90,7 @@ declare class Entity$1<T extends Entity$2> extends Item$1 {
90
90
  }
91
91
  declare class EntityRepository extends Repository {
92
92
  private EntityConfig;
93
- private readonly TABLE_NAME;
93
+ readonly TABLE_NAME: string;
94
94
  private readonly dynamodbClient;
95
95
  private readonly EmailAuthEnabledEntities;
96
96
  constructor(EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>, TABLE_NAME: string, dynamodbClient: DynamoDB, EmailAuthEnabledEntities: Entity$2[]);
@@ -4699,6 +4699,67 @@ declare class ListTagsController {
4699
4699
  }, hono_utils_http_status.ContentfulStatusCode, "json">>;
4700
4700
  }
4701
4701
 
4702
+ type TransactionCreateEntity<T extends Entity$2 = Entity$2> = {
4703
+ operation: 'createEntity';
4704
+ entityType: T;
4705
+ entityId?: string;
4706
+ payload: EntitySchemaMap[T];
4707
+ };
4708
+ type TransactionUpdateEntity<T extends Entity$2 = Entity$2> = {
4709
+ operation: 'updateEntity';
4710
+ entityType: T;
4711
+ entityId: string;
4712
+ payload: Partial<EntitySchemaMap[T]>;
4713
+ condition?: string;
4714
+ };
4715
+ type TransactionAdjustEntity<T extends Entity$2 = Entity$2> = {
4716
+ operation: 'adjustEntity';
4717
+ entityType: T;
4718
+ entityId: string;
4719
+ adjustments: Record<string, number>;
4720
+ condition?: string;
4721
+ };
4722
+ type TransactionDeleteEntity<T extends Entity$2 = Entity$2> = {
4723
+ operation: 'deleteEntity';
4724
+ entityType: T;
4725
+ entityId: string;
4726
+ };
4727
+ type TransactionOperation = TransactionCreateEntity | TransactionUpdateEntity | TransactionAdjustEntity | TransactionDeleteEntity;
4728
+ type TransactionResultEntry = {
4729
+ operation: string;
4730
+ entityType: Entity$2;
4731
+ entityId: string;
4732
+ data?: Record<string, unknown>;
4733
+ };
4734
+ type TransactionResult = {
4735
+ results: TransactionResultEntry[];
4736
+ };
4737
+
4738
+ declare class TransactionService {
4739
+ private EntityConfig;
4740
+ private EmailAuthEnabledEntities;
4741
+ private entityRepository;
4742
+ private dynamodbClient;
4743
+ private publishEvent;
4744
+ private entityServiceLifeCycle;
4745
+ private eventUtils;
4746
+ constructor(EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>, EmailAuthEnabledEntities: Entity$2[], entityRepository: EntityRepository, dynamodbClient: DynamoDB, publishEvent: typeof publishEvent, entityServiceLifeCycle: EntityServiceLifeCycle, eventUtils: EventUtils);
4747
+ executeTransaction: (operations: TransactionOperation[], accountId?: string) => Promise<TransactionResult>;
4748
+ private processOperation;
4749
+ private buildCreateItems;
4750
+ private buildUpdateItem;
4751
+ private buildAdjustItem;
4752
+ private buildDeleteItem;
4753
+ private collectCreateEvents;
4754
+ private collectUpdateEvents;
4755
+ }
4756
+
4757
+ declare class ExecuteTransactionController {
4758
+ private transactionService;
4759
+ constructor(transactionService: TransactionService);
4760
+ controller: hono.MiddlewareHandler<any, string, {}, any>;
4761
+ }
4762
+
4702
4763
  declare class DependencyContainer {
4703
4764
  config: {
4704
4765
  EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>;
@@ -4741,6 +4802,8 @@ declare class DependencyContainer {
4741
4802
  get updateMutualController(): UpdateMutualController;
4742
4803
  get deleteMutualController(): DeleteMutualController;
4743
4804
  get listTagsController(): ListTagsController;
4805
+ get transactionService(): TransactionService;
4806
+ get executeTransactionController(): ExecuteTransactionController;
4744
4807
  }
4745
4808
 
4746
4809
  declare const setupCommonRoutes: (container: DependencyContainer) => Hono;
@@ -4774,7 +4837,12 @@ declare const StandardErrorCode: {
4774
4837
  readonly REPLICATION_ERROR: "REPLICATION_ERROR";
4775
4838
  readonly RETRYABLE_MUTUAL_LOCK_CONFLICT: "RETRYABLE_MUTUAL_LOCK_CONFLICT";
4776
4839
  readonly TAG_IS_UNDEFINED: "TAG_IS_UNDEFINED";
4840
+ readonly TRANSACTION_EMPTY: "TRANSACTION_EMPTY";
4777
4841
  readonly TRANSACTION_FAILED: "TRANSACTION_FAILED";
4842
+ readonly TRANSACTION_INVALID_OPERATION: "TRANSACTION_INVALID_OPERATION";
4843
+ readonly TRANSACTION_ITEM_LIMIT_EXCEEDED: "TRANSACTION_ITEM_LIMIT_EXCEEDED";
4844
+ readonly TRANSACTION_UNIQUE_FIELD_UPDATE: "TRANSACTION_UNIQUE_FIELD_UPDATE";
4845
+ readonly TRANSACTION_VALIDATION_ERROR: "TRANSACTION_VALIDATION_ERROR";
4778
4846
  readonly UNIQUE_VALUE_EXISTS: "UNIQUE_VALUE_EXISTS";
4779
4847
  };
4780
4848
  type StandardErrorCode = typeof StandardErrorCode[keyof typeof StandardErrorCode];
@@ -4814,6 +4882,19 @@ declare const handler: (container: DependencyContainer) => (ev: SQSEvent) => Pro
4814
4882
  batchItemFailures: SQSBatchItemFailure[];
4815
4883
  }>;
4816
4884
 
4885
+ declare const transactional: {
4886
+ createEntity: <T extends Entity$2>(entityType: T, payload: EntitySchemaMap[T] & {
4887
+ entityId?: string;
4888
+ }) => TransactionCreateEntity<T>;
4889
+ updateEntity: <T extends Entity$2>(entityType: T, entityId: string, payload: Partial<EntitySchemaMap[T]> & {
4890
+ $condition?: string;
4891
+ }) => TransactionUpdateEntity<T>;
4892
+ adjustEntity: <T extends Entity$2>(entityType: T, entityId: string, adjustments: Record<string, number> & {
4893
+ $condition?: string;
4894
+ }) => TransactionAdjustEntity<T>;
4895
+ deleteEntity: <T extends Entity$2>(entityType: T, entityId: string) => TransactionDeleteEntity<T>;
4896
+ };
4897
+
4817
4898
  declare class CoreFactory {
4818
4899
  private config;
4819
4900
  setupCommonRoutes: ReturnType<typeof setupCommonRoutes>;
@@ -4831,4 +4912,4 @@ declare class CoreFactory {
4831
4912
  });
4832
4913
  }
4833
4914
 
4834
- export { DependencyContainer, Entity$1 as Entity, EntityRepository, EntityService, Mutual, MutualRepository, MutualService, PROJECTION_EXPRESSION, StandardError, StandardErrorCode, TagRepository, appHandler, handler$4 as createEntityProcessor, CoreFactory as default, handler$3 as mutualProcessor, handler$2 as prejoinProcessor, handler$1 as replicationProcessor, setupCommonRoutes, handler as tagProcessor };
4915
+ export { DependencyContainer, Entity$1 as Entity, EntityRepository, EntityService, Mutual, MutualRepository, MutualService, PROJECTION_EXPRESSION, StandardError, StandardErrorCode, TagRepository, TransactionService, appHandler, handler$4 as createEntityProcessor, CoreFactory as default, handler$3 as mutualProcessor, handler$2 as prejoinProcessor, handler$1 as replicationProcessor, setupCommonRoutes, handler as tagProcessor, transactional };