monorise 1.8.0-dev.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dist/cli/cli.js +239 -153
  2. package/dist/cli/cli.js.map +1 -1
  3. package/dist/cli/templates/files/proxy-request.ts +2 -1
  4. package/dist/cli/templates/files/sst.config.ts +5 -4
  5. package/dist/core/index.d.ts +54 -12
  6. package/dist/core/index.js +484 -135
  7. package/dist/core/index.js.map +1 -1
  8. package/dist/index.d.ts +106 -4
  9. package/dist/react/actions/core.action.d.ts.map +1 -1
  10. package/dist/react/helpers/transactional.d.ts +40 -0
  11. package/dist/react/helpers/transactional.d.ts.map +1 -0
  12. package/dist/react/index.d.ts +4 -17
  13. package/dist/react/index.d.ts.map +1 -1
  14. package/dist/react/index.js +390 -25645
  15. package/dist/react/index.js.map +1 -1
  16. package/dist/react/lib/utils.d.ts +7 -0
  17. package/dist/react/lib/utils.d.ts.map +1 -1
  18. package/dist/react/services/core.service.d.ts +2 -8
  19. package/dist/react/services/core.service.d.ts.map +1 -1
  20. package/dist/sst/components/analytics.d.ts +26 -6
  21. package/dist/sst/components/analytics.d.ts.map +1 -1
  22. package/dist/sst/components/monorise-core.d.ts +1 -0
  23. package/dist/sst/components/monorise-core.d.ts.map +1 -1
  24. package/dist/sst/components/single-table.d.ts +1 -0
  25. package/dist/sst/components/single-table.d.ts.map +1 -1
  26. package/dist/sst/index.js +173 -67
  27. package/dist/sst/index.js.map +1 -1
  28. package/package.json +3 -3
  29. package/dist/react/bowser-RUCNDTEX.js +0 -2822
  30. package/dist/react/bowser-RUCNDTEX.js.map +0 -1
  31. package/dist/react/chunk-2U2REJF4.js +0 -138
  32. package/dist/react/chunk-2U2REJF4.js.map +0 -1
  33. package/dist/react/chunk-5CPIG7AN.js +0 -449
  34. package/dist/react/chunk-5CPIG7AN.js.map +0 -1
  35. package/dist/react/chunk-7BSJSLIL.js +0 -528
  36. package/dist/react/chunk-7BSJSLIL.js.map +0 -1
  37. package/dist/react/chunk-7MNBSDJI.js +0 -3362
  38. package/dist/react/chunk-7MNBSDJI.js.map +0 -1
  39. package/dist/react/chunk-JXBFOCBM.js +0 -2929
  40. package/dist/react/chunk-JXBFOCBM.js.map +0 -1
  41. package/dist/react/chunk-MIXAYX55.js +0 -147
  42. package/dist/react/chunk-MIXAYX55.js.map +0 -1
  43. package/dist/react/chunk-Q26JGAFF.js +0 -47
  44. package/dist/react/chunk-Q26JGAFF.js.map +0 -1
  45. package/dist/react/chunk-QZSEUOCY.js +0 -2298
  46. package/dist/react/chunk-QZSEUOCY.js.map +0 -1
  47. package/dist/react/chunk-W6S3JWZV.js +0 -1045
  48. package/dist/react/chunk-W6S3JWZV.js.map +0 -1
  49. package/dist/react/chunk-WUOPYF3V.js +0 -127
  50. package/dist/react/chunk-WUOPYF3V.js.map +0 -1
  51. package/dist/react/chunk-Z45ECZFO.js +0 -995
  52. package/dist/react/chunk-Z45ECZFO.js.map +0 -1
  53. package/dist/react/dist-es-2P6AKQM3.js +0 -325
  54. package/dist/react/dist-es-2P6AKQM3.js.map +0 -1
  55. package/dist/react/dist-es-CEMZ6HT6.js +0 -294
  56. package/dist/react/dist-es-CEMZ6HT6.js.map +0 -1
  57. package/dist/react/dist-es-NZWWHEBR.js +0 -89
  58. package/dist/react/dist-es-NZWWHEBR.js.map +0 -1
  59. package/dist/react/dist-es-QVQ2CPIM.js +0 -376
  60. package/dist/react/dist-es-QVQ2CPIM.js.map +0 -1
  61. package/dist/react/dist-es-VBWII54H.js +0 -70
  62. package/dist/react/dist-es-VBWII54H.js.map +0 -1
  63. package/dist/react/dist-es-VXN7IC3J.js +0 -23
  64. package/dist/react/dist-es-VXN7IC3J.js.map +0 -1
  65. package/dist/react/dist-es-YKVDPOOB.js +0 -221
  66. package/dist/react/dist-es-YKVDPOOB.js.map +0 -1
  67. package/dist/react/dist-es-ZPOY2Z6R.js +0 -178
  68. package/dist/react/dist-es-ZPOY2Z6R.js.map +0 -1
  69. package/dist/react/event-streams-NBH35WQC.js +0 -44
  70. package/dist/react/event-streams-NBH35WQC.js.map +0 -1
  71. package/dist/react/loadSso-2GPAQE3H.js +0 -583
  72. package/dist/react/loadSso-2GPAQE3H.js.map +0 -1
  73. package/dist/react/signin-HT4EDHQE.js +0 -821
  74. package/dist/react/signin-HT4EDHQE.js.map +0 -1
  75. package/dist/react/sso-oidc-WA3BK6FI.js +0 -830
  76. package/dist/react/sso-oidc-WA3BK6FI.js.map +0 -1
  77. package/dist/react/sts-V7PNNQ2L.js +0 -1114
  78. package/dist/react/sts-V7PNNQ2L.js.map +0 -1
package/dist/cli/cli.js CHANGED
@@ -2,24 +2,41 @@
2
2
 
3
3
  // cli.ts
4
4
  import "tsx";
5
- import fs2 from "fs";
6
- import path2 from "path";
5
+ import fs3 from "fs";
6
+ import path3 from "path";
7
7
  import { execSync } from "child_process";
8
8
  import chokidar from "chokidar";
9
9
 
10
10
  // commands/utils/analytics-manifest.ts
11
11
  import { createHash } from "crypto";
12
+ import fs from "fs";
13
+ import path from "path";
12
14
  var lowerKebabCase = /^[a-z]+(?:-[a-z]+)*$/;
13
15
  function normalizeSqlIdentifier(name) {
14
16
  const normalized = name.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[^a-zA-Z0-9]+/g, "_").replace(/^_+|_+$/g, "").toLowerCase();
15
17
  return /^[a-z_]/.test(normalized) ? normalized : `_${normalized}`;
16
18
  }
17
- function athenaType(schema, path3) {
19
+ function athenaType(schema, path4) {
18
20
  let current = schema;
19
- while (current._def?.typeName === "ZodOptional" || current._def?.typeName === "ZodNullable" || current._def?.typeName === "ZodDefault") {
20
- const innerType = current._def?.innerType;
21
- if (!innerType) break;
22
- current = innerType;
21
+ for (; ; ) {
22
+ const typeName = current._def?.typeName;
23
+ if (typeName === "ZodEffects") {
24
+ if (current._def?.effect?.type !== "refinement") return "json";
25
+ if (!current._def.schema) return "json";
26
+ current = current._def.schema;
27
+ continue;
28
+ }
29
+ if (typeName === "ZodOptional" || typeName === "ZodNullable" || typeName === "ZodDefault" || typeName === "ZodCatch" || typeName === "ZodReadonly") {
30
+ if (!current._def?.innerType) return "json";
31
+ current = current._def.innerType;
32
+ continue;
33
+ }
34
+ if (typeName === "ZodBranded") {
35
+ if (!current._def?.type) return "json";
36
+ current = current._def.type;
37
+ continue;
38
+ }
39
+ break;
23
40
  }
24
41
  switch (current._def?.typeName) {
25
42
  case "ZodString":
@@ -30,36 +47,63 @@ function athenaType(schema, path3) {
30
47
  return "boolean";
31
48
  case "ZodDate":
32
49
  return "timestamp";
50
+ case "ZodEnum":
51
+ return "string";
52
+ case "ZodNativeEnum": {
53
+ const values = current._def.values ?? {};
54
+ const validValues = Object.keys(values).filter((key) => typeof values[String(values[key])] !== "number").map((key) => values[key]);
55
+ if (validValues.every((value) => typeof value === "string")) return "string";
56
+ if (validValues.every((value) => typeof value === "number")) return "double";
57
+ return "json";
58
+ }
59
+ case "ZodLiteral":
60
+ return typeof current._def.value === "string" ? "string" : typeof current._def.value === "number" ? "double" : typeof current._def.value === "boolean" ? "boolean" : "json";
33
61
  case "ZodArray":
34
62
  case "ZodObject":
35
63
  return "json";
36
64
  default:
37
- throw new Error(
38
- `Unsupported analytics schema field ${path3}. Supported types are string, number, boolean, datetime, arrays, and objects.`
39
- );
65
+ return "json";
40
66
  }
41
67
  }
42
- function columns(schema, path3) {
43
- if (!schema.shape) {
44
- throw new Error(`Analytics schema ${path3} must be a Zod object.`);
68
+ function columns(schema, path4) {
69
+ let objectSchema = schema;
70
+ while (!objectSchema.shape && objectSchema._def?.typeName === "ZodEffects") {
71
+ const innerSchema = objectSchema._def.schema;
72
+ if (!innerSchema) break;
73
+ objectSchema = innerSchema;
45
74
  }
75
+ if (!objectSchema.shape) return [];
46
76
  const names = /* @__PURE__ */ new Map();
47
- return Object.entries(schema.shape).map(([sourceName, field]) => {
77
+ return Object.entries(objectSchema.shape).map(([sourceName, field]) => {
48
78
  const name = normalizeSqlIdentifier(sourceName);
49
79
  const existing = names.get(name);
50
80
  if (existing) {
51
81
  throw new Error(
52
- `Analytics column identifier collision in ${path3}: ${existing} and ${sourceName} both normalize to ${name}.`
82
+ `Analytics column identifier collision in ${path4}: ${existing} and ${sourceName} both normalize to ${name}.`
53
83
  );
54
84
  }
55
85
  names.set(name, sourceName);
56
86
  return {
57
87
  name,
58
88
  sourceName,
59
- type: athenaType(field, `${path3}.${sourceName}`)
89
+ type: athenaType(field, `${path4}.${sourceName}`)
60
90
  };
61
91
  });
62
92
  }
93
+ function endpoints(entities) {
94
+ const [first, second] = entities;
95
+ if (first === second) {
96
+ const identifier = normalizeSqlIdentifier(first);
97
+ return [
98
+ { entityName: first, column: `${identifier}_source_id`, role: "source" },
99
+ { entityName: second, column: `${identifier}_target_id`, role: "target" }
100
+ ];
101
+ }
102
+ return [first, second].sort().map((entityName) => ({
103
+ entityName,
104
+ column: `${normalizeSqlIdentifier(entityName)}_id`
105
+ }));
106
+ }
63
107
  function fingerprint(datasets) {
64
108
  return createHash("sha256").update(JSON.stringify(datasets)).digest("hex");
65
109
  }
@@ -92,12 +136,30 @@ function validateSchemaEvolution(previous, next) {
92
136
  }
93
137
  }
94
138
  }
139
+ function writeAnalyticsManifest(monoriseOutputDir, configs) {
140
+ const analyticsManifestPath = path.join(monoriseOutputDir, "analytics-manifest.json");
141
+ const manifest = createAnalyticsManifest(configs);
142
+ if (manifest.unnamedMutuals.length) {
143
+ console.warn(
144
+ `Skipping unnamed mutual analytics datasets: ${manifest.unnamedMutuals.join(", ")}.`
145
+ );
146
+ }
147
+ if (fs.existsSync(analyticsManifestPath)) {
148
+ validateSchemaEvolution(
149
+ JSON.parse(fs.readFileSync(analyticsManifestPath, "utf8")),
150
+ manifest
151
+ );
152
+ }
153
+ fs.writeFileSync(analyticsManifestPath, `${JSON.stringify(manifest, null, 2)}
154
+ `);
155
+ }
95
156
  function createAnalyticsManifest(configs) {
96
157
  const datasets = [];
97
158
  const unnamedMutuals = /* @__PURE__ */ new Set();
98
159
  const identifiers = /* @__PURE__ */ new Map();
99
160
  const mutuals = /* @__PURE__ */ new Set();
100
- const addDataset = (kind, name, schema) => {
161
+ const mutualPairs = /* @__PURE__ */ new Map();
162
+ const addDataset = (kind, name, schema, mutualEntities) => {
101
163
  if (!lowerKebabCase.test(name)) {
102
164
  throw new Error(
103
165
  `Invalid analytics ${kind} name: ${name}. Must be lower-kebab-case.`
@@ -111,13 +173,38 @@ function createAnalyticsManifest(configs) {
111
173
  );
112
174
  }
113
175
  identifiers.set(identifier, name);
176
+ const idColumn = `${identifier}_id`;
177
+ const datasetEndpoints = kind === "mutual" && mutualEntities ? endpoints(mutualEntities) : [];
178
+ const datasetColumns = columns(schema, `${kind} ${name}`);
179
+ const reservedNames = /* @__PURE__ */ new Set([
180
+ idColumn,
181
+ ...datasetEndpoints.map((endpoint) => endpoint.column),
182
+ "event_id",
183
+ "idempotency_key",
184
+ "ordering_key",
185
+ "sequence_number",
186
+ "operation",
187
+ "occurred_at",
188
+ "before_json",
189
+ "after_json"
190
+ ]);
191
+ const collision = datasetColumns.find(
192
+ (column) => reservedNames.has(column.name)
193
+ );
194
+ if (collision) {
195
+ throw new Error(
196
+ `Analytics field ${kind} ${name}.${collision.sourceName} conflicts with generated column ${collision.name}.`
197
+ );
198
+ }
114
199
  datasets.push({
115
200
  kind,
116
201
  name,
117
202
  identifier,
203
+ idColumn,
204
+ endpoints: datasetEndpoints,
118
205
  currentTable: `${identifier}_${kind === "entity" ? "entities" : "mutuals"}`,
119
206
  historyTable: `${identifier}_${kind === "entity" ? "entity_changes" : "mutual_changes"}`,
120
- columns: columns(schema, `${kind} ${name}`),
207
+ columns: datasetColumns,
121
208
  partition: { granularity: "day" }
122
209
  });
123
210
  };
@@ -131,11 +218,25 @@ function createAnalyticsManifest(configs) {
131
218
  }
132
219
  if (mutuals.has(mutual)) continue;
133
220
  mutuals.add(mutual);
134
- addDataset("mutual", mutual.name, mutual.mutualDataSchema);
221
+ const entities = mutual.entities ?? [config.name, field.entityType];
222
+ const pair = [...entities].sort().join("::");
223
+ const existing = mutualPairs.get(pair);
224
+ if (existing) {
225
+ throw new Error(
226
+ `Analytics mutual ${mutual.name} conflicts with ${existing}: both use the ${pair} entity pair.`
227
+ );
228
+ }
229
+ mutualPairs.set(pair, mutual.name);
230
+ addDataset(
231
+ "mutual",
232
+ mutual.name,
233
+ mutual.mutualDataSchema,
234
+ entities
235
+ );
135
236
  }
136
237
  }
137
238
  return {
138
- version: 1,
239
+ version: 2,
139
240
  datasets,
140
241
  unnamedMutuals: [...unnamedMutuals].sort(),
141
242
  schemaFingerprint: fingerprint(datasets)
@@ -146,15 +247,15 @@ function createAnalyticsManifest(configs) {
146
247
  import { fileURLToPath } from "url";
147
248
 
148
249
  // commands/utils/detect-package.ts
149
- import fs from "fs";
150
- import path from "path";
250
+ import fs2 from "fs";
251
+ import path2 from "path";
151
252
  function detectCombinedPackage(startDir) {
152
253
  let dir = startDir;
153
254
  while (true) {
154
- if (fs.existsSync(path.join(dir, "node_modules", "monorise"))) {
255
+ if (fs2.existsSync(path2.join(dir, "node_modules", "monorise"))) {
155
256
  return true;
156
257
  }
157
- const parent = path.dirname(dir);
258
+ const parent = path2.dirname(dir);
158
259
  if (parent === dir) break;
159
260
  dir = parent;
160
261
  }
@@ -183,10 +284,10 @@ var ROOT_TSCONFIG_TEMPLATE = {
183
284
 
184
285
  // cli.ts
185
286
  var __filename = fileURLToPath(import.meta.url);
186
- var __dirname = path2.dirname(__filename);
187
- var TEMPLATES_DIR = path2.join(__dirname, "templates", "files");
287
+ var __dirname = path3.dirname(__filename);
288
+ var TEMPLATES_DIR = path3.join(__dirname, "templates", "files");
188
289
  function readTemplate(filename) {
189
- return fs2.readFileSync(path2.join(TEMPLATES_DIR, filename), "utf-8");
290
+ return fs3.readFileSync(path3.join(TEMPLATES_DIR, filename), "utf-8");
190
291
  }
191
292
  function kebabToCamel(str) {
192
293
  return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
@@ -199,12 +300,19 @@ function execCommand(command, cwd, stdio = "inherit") {
199
300
  execSync(command, { cwd, stdio });
200
301
  }
201
302
  async function generateConfigFile(configDir, monoriseOutputDir, projectRoot) {
202
- const configOutputPath = path2.join(monoriseOutputDir, "config.ts");
303
+ const configOutputPath = path3.join(monoriseOutputDir, "config.ts");
203
304
  const initialConfigContent = `
204
305
  export enum Entity {}
306
+ export default {};
205
307
  `;
206
- fs2.writeFileSync(configOutputPath, initialConfigContent);
207
- const files = fs2.readdirSync(configDir).filter((file) => file.endsWith(".ts") && file !== "index.ts");
308
+ fs3.writeFileSync(configOutputPath, initialConfigContent);
309
+ fs3.writeFileSync(
310
+ path3.join(monoriseOutputDir, "index.ts"),
311
+ `export * from './config';
312
+ export { default } from './config';
313
+ `
314
+ );
315
+ const files = fs3.readdirSync(configDir).filter((file) => file.endsWith(".ts") && file !== "index.ts");
208
316
  const names = /* @__PURE__ */ new Set();
209
317
  const nameRegex = /^[a-z]+(-[a-z]+)*$/;
210
318
  const imports = [];
@@ -216,10 +324,10 @@ export enum Entity {}
216
324
  const allowedEntityEntries = [];
217
325
  const entityWithEmailAuthEntries = [];
218
326
  const analyticsConfigs = [];
219
- const relativePathToConfigDir = path2.relative(monoriseOutputDir, configDir);
327
+ const relativePathToConfigDir = path3.relative(monoriseOutputDir, configDir);
220
328
  const importPathPrefix = relativePathToConfigDir ? `${relativePathToConfigDir}/` : "./";
221
329
  for (const file of files) {
222
- const fullPath = path2.join(configDir, file);
330
+ const fullPath = path3.join(configDir, file);
223
331
  const module = await import(fullPath);
224
332
  const config = module.default;
225
333
  if (!nameRegex.test(config.name)) {
@@ -313,23 +421,11 @@ const config = {
313
421
  export default config;
314
422
  ${moduleAugmentations}
315
423
  `;
316
- fs2.writeFileSync(configOutputPath, configOutputContent);
317
- const analyticsManifestPath = path2.join(
318
- monoriseOutputDir,
319
- "analytics-manifest.json"
320
- );
321
- const manifest = createAnalyticsManifest(analyticsConfigs);
322
- if (fs2.existsSync(analyticsManifestPath)) {
323
- validateSchemaEvolution(
324
- JSON.parse(fs2.readFileSync(analyticsManifestPath, "utf8")),
325
- manifest
326
- );
327
- }
328
- fs2.writeFileSync(analyticsManifestPath, `${JSON.stringify(manifest, null, 2)}
329
- `);
424
+ fs3.writeFileSync(configOutputPath, configOutputContent);
425
+ writeAnalyticsManifest(monoriseOutputDir, analyticsConfigs);
330
426
  console.log("Successfully generated config.ts!");
331
- const indexOutputPath = path2.join(monoriseOutputDir, "index.ts");
332
- fs2.writeFileSync(
427
+ const indexOutputPath = path3.join(monoriseOutputDir, "index.ts");
428
+ fs3.writeFileSync(
333
429
  indexOutputPath,
334
430
  `export * from './config';
335
431
  export { default } from './config';
@@ -339,35 +435,21 @@ export { default } from './config';
339
435
  return configOutputPath;
340
436
  }
341
437
  async function generateHandleFile(monoriseConfig, projectRoot, monoriseOutputDir) {
342
- const handleOutputPath = path2.join(monoriseOutputDir, "handle.ts");
438
+ const handleOutputPath = path3.join(monoriseOutputDir, "handle.ts");
343
439
  const customRoutesPath = monoriseConfig.customRoutes;
344
440
  let routesImportLine = "";
345
441
  let appHandlerPayload = "{}";
346
442
  if (customRoutesPath) {
347
- const absoluteCustomRoutesPath = path2.resolve(
443
+ const absoluteCustomRoutesPath = path3.resolve(
348
444
  projectRoot,
349
445
  customRoutesPath
350
446
  );
351
- if (!fs2.existsSync(absoluteCustomRoutesPath) && !fs2.existsSync(`${absoluteCustomRoutesPath}.ts`) && !fs2.existsSync(`${absoluteCustomRoutesPath}.js`)) {
447
+ if (!fs3.existsSync(absoluteCustomRoutesPath) && !fs3.existsSync(`${absoluteCustomRoutesPath}.ts`) && !fs3.existsSync(`${absoluteCustomRoutesPath}.js`)) {
352
448
  throw new Error(
353
449
  `Custom routes file not found: '${absoluteCustomRoutesPath}'. Please ensure 'customRoutes' in monorise.config.ts points to a valid file.`
354
450
  );
355
451
  }
356
- let routesModule;
357
- try {
358
- routesModule = await import(absoluteCustomRoutesPath);
359
- } catch (e) {
360
- throw new Error(
361
- `Failed to load custom routes file at '${absoluteCustomRoutesPath}'. Ensure it's a valid JavaScript/TypeScript module. Error: ${e.message}`
362
- );
363
- }
364
- const routesExport = routesModule.default;
365
- if (!routesExport || routesExport === null || typeof routesExport === "object" && !("get" in routesExport && "post" in routesExport && "use" in routesExport)) {
366
- throw new Error(
367
- `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.`
368
- );
369
- }
370
- let relativePathToRoutes = path2.relative(
452
+ let relativePathToRoutes = path3.relative(
371
453
  monoriseOutputDir,
372
454
  absoluteCustomRoutesPath
373
455
  );
@@ -381,44 +463,48 @@ async function generateHandleFile(monoriseConfig, projectRoot, monoriseOutputDir
381
463
  const usesCombinedPackage = detectCombinedPackage(projectRoot);
382
464
  const coreImportPath = usesCombinedPackage ? "monorise/core" : "../core/index.js";
383
465
  const combinedContent = `
384
- import CoreFactory from '${coreImportPath}';
466
+ import CoreFactory, { analyticsMaterializationProcessor, analyticsModelProcessor, analyticsQueryHandler as createAnalyticsQueryHandler, analyticsViewProcessor } from '${coreImportPath}';
385
467
  import config from './config';
468
+ import analyticsManifest from './analytics-manifest.json';
386
469
  ${routesImportLine ? `${routesImportLine}
387
470
  ` : ""}const coreFactory = new CoreFactory(config);
388
471
 
389
472
  export const replicationHandler = coreFactory.replicationProcessor;
390
473
  export const analyticsHandler = coreFactory.analyticsProcessor;
391
474
  export const analyticsBackfillHandler = coreFactory.analyticsBackfillProcessor;
392
- export { analyticsMaterializationProcessor as analyticsMaterializationHandler } from '${coreImportPath}';
475
+ export const analyticsMaterializationHandler = analyticsMaterializationProcessor(analyticsManifest);
476
+ export const analyticsQueryHandler = createAnalyticsQueryHandler();
477
+ export const analyticsModelHandler = analyticsModelProcessor;
478
+ export const analyticsViewHandler = analyticsViewProcessor;
393
479
  export const mutualHandler = coreFactory.mutualProcessor;
394
480
  export const tagHandler = coreFactory.tagProcessor;
395
481
  export const treeHandler = coreFactory.prejoinProcessor;
396
482
  export const appHandler = coreFactory.appHandler(${appHandlerPayload});
397
483
  `;
398
- fs2.writeFileSync(handleOutputPath, combinedContent);
484
+ fs3.writeFileSync(handleOutputPath, combinedContent);
399
485
  console.log("Successfully generated handle.ts!");
400
486
  return handleOutputPath;
401
487
  }
402
488
  async function generateFiles(rootPath) {
403
- const baseDir = rootPath ? path2.resolve(rootPath) : process.cwd();
404
- const configFilePathTS = path2.join(baseDir, "monorise.config.ts");
405
- const configFilePathJS = path2.join(baseDir, "monorise.config.js");
489
+ const baseDir = rootPath ? path3.resolve(rootPath) : process.cwd();
490
+ const configFilePathTS = path3.join(baseDir, "monorise.config.ts");
491
+ const configFilePathJS = path3.join(baseDir, "monorise.config.js");
406
492
  let configFilePath;
407
- if (fs2.existsSync(configFilePathTS)) {
493
+ if (fs3.existsSync(configFilePathTS)) {
408
494
  configFilePath = configFilePathTS;
409
- } else if (fs2.existsSync(configFilePathJS)) {
495
+ } else if (fs3.existsSync(configFilePathJS)) {
410
496
  configFilePath = configFilePathJS;
411
497
  } else {
412
498
  throw new Error(
413
499
  "Neither monorise.config.ts nor monorise.config.js found in the root of the project."
414
500
  );
415
501
  }
416
- const projectRoot = path2.dirname(configFilePath);
502
+ const projectRoot = path3.dirname(configFilePath);
417
503
  const monoriseConfigModule = await import(configFilePath);
418
504
  const monoriseConfig = monoriseConfigModule.default;
419
- const configDir = path2.resolve(projectRoot, monoriseConfig.configDir);
420
- const monoriseOutputDir = path2.join(projectRoot, ".monorise");
421
- fs2.mkdirSync(monoriseOutputDir, { recursive: true });
505
+ const configDir = path3.resolve(projectRoot, monoriseConfig.configDir);
506
+ const monoriseOutputDir = path3.join(projectRoot, ".monorise");
507
+ fs3.mkdirSync(monoriseOutputDir, { recursive: true });
422
508
  await generateConfigFile(configDir, monoriseOutputDir, projectRoot);
423
509
  await generateHandleFile(monoriseConfig, projectRoot, monoriseOutputDir);
424
510
  return configDir;
@@ -476,29 +562,29 @@ async function runInitCommand(rootPath) {
476
562
  let projectName = "my-app";
477
563
  let projectRoot;
478
564
  if (rootPath) {
479
- projectRoot = path2.resolve(rootPath);
480
- projectName = path2.basename(projectRoot);
565
+ projectRoot = path3.resolve(rootPath);
566
+ projectName = path3.basename(projectRoot);
481
567
  } else {
482
568
  const args = process.argv.slice(2);
483
569
  const nameIndex = args.indexOf("--name");
484
570
  if (nameIndex > -1 && args[nameIndex + 1]) {
485
571
  projectName = args[nameIndex + 1];
486
572
  }
487
- projectRoot = path2.resolve(projectName);
573
+ projectRoot = path3.resolve(projectName);
488
574
  }
489
575
  console.log(`
490
576
  \u{1F680} Creating Monorise project: ${projectName}
491
577
  `);
492
- if (fs2.existsSync(projectRoot)) {
578
+ if (fs3.existsSync(projectRoot)) {
493
579
  console.error(`Error: Directory ${projectName} already exists.`);
494
580
  process.exit(1);
495
581
  }
496
582
  console.log("\u{1F4C1} Creating project structure...");
497
- fs2.mkdirSync(projectRoot, { recursive: true });
498
- fs2.mkdirSync(path2.join(projectRoot, "apps"), { recursive: true });
499
- fs2.mkdirSync(path2.join(projectRoot, "services", "core"), { recursive: true });
500
- fs2.mkdirSync(path2.join(projectRoot, "monorise", "configs"), { recursive: true });
501
- fs2.mkdirSync(path2.join(projectRoot, "monorise", "mutuals"), { recursive: true });
583
+ fs3.mkdirSync(projectRoot, { recursive: true });
584
+ fs3.mkdirSync(path3.join(projectRoot, "apps"), { recursive: true });
585
+ fs3.mkdirSync(path3.join(projectRoot, "services", "core"), { recursive: true });
586
+ fs3.mkdirSync(path3.join(projectRoot, "monorise", "configs"), { recursive: true });
587
+ fs3.mkdirSync(path3.join(projectRoot, "monorise", "mutuals"), { recursive: true });
502
588
  console.log("\u{1F4E6} Initializing root package.json...");
503
589
  const rootPackageJson = {
504
590
  name: projectName,
@@ -507,21 +593,21 @@ async function runInitCommand(rootPath) {
507
593
  private: true,
508
594
  workspaces: ["apps/*", "services/*"]
509
595
  };
510
- fs2.writeFileSync(
511
- path2.join(projectRoot, "package.json"),
596
+ fs3.writeFileSync(
597
+ path3.join(projectRoot, "package.json"),
512
598
  JSON.stringify(rootPackageJson, null, 2)
513
599
  );
514
600
  console.log("\u2699\uFE0F Creating root tsconfig.json...");
515
- fs2.writeFileSync(
516
- path2.join(projectRoot, "tsconfig.json"),
601
+ fs3.writeFileSync(
602
+ path3.join(projectRoot, "tsconfig.json"),
517
603
  JSON.stringify(ROOT_TSCONFIG_TEMPLATE, null, 2)
518
604
  );
519
605
  console.log("\n\u{1F4F1} Creating Next.js app in apps/web...");
520
- const nextAppDir = path2.join(projectRoot, "apps", "web");
606
+ const nextAppDir = path3.join(projectRoot, "apps", "web");
521
607
  try {
522
608
  execCommand(
523
609
  `npx create-next-app@latest web --typescript --tailwind --eslint --app --no-src-dir --import-alias "#/*" --no-turbopack --yes`,
524
- path2.join(projectRoot, "apps")
610
+ path3.join(projectRoot, "apps")
525
611
  );
526
612
  } catch (error) {
527
613
  console.error("Failed to create Next.js app:", error);
@@ -542,28 +628,28 @@ async function runInitCommand(rootPath) {
542
628
  process.exit(1);
543
629
  }
544
630
  console.log("\u2699\uFE0F Creating monorise.config.ts...");
545
- fs2.writeFileSync(
546
- path2.join(projectRoot, "monorise.config.ts"),
631
+ fs3.writeFileSync(
632
+ path3.join(projectRoot, "monorise.config.ts"),
547
633
  readTemplate("monorise.config.ts")
548
634
  );
549
635
  console.log("\u{1F517} Creating team-membership mutual config...");
550
- fs2.writeFileSync(
551
- path2.join(projectRoot, "monorise", "mutuals", "team-membership.ts"),
636
+ fs3.writeFileSync(
637
+ path3.join(projectRoot, "monorise", "mutuals", "team-membership.ts"),
552
638
  readTemplate("team-membership.mutual.ts")
553
639
  );
554
640
  console.log("\u{1F464} Creating starter User entity...");
555
- fs2.writeFileSync(
556
- path2.join(projectRoot, "monorise", "configs", "user.ts"),
641
+ fs3.writeFileSync(
642
+ path3.join(projectRoot, "monorise", "configs", "user.ts"),
557
643
  readTemplate("user-entity.ts")
558
644
  );
559
645
  console.log("\u{1F465} Creating starter Team entity...");
560
- fs2.writeFileSync(
561
- path2.join(projectRoot, "monorise", "configs", "team.ts"),
646
+ fs3.writeFileSync(
647
+ path3.join(projectRoot, "monorise", "configs", "team.ts"),
562
648
  readTemplate("team-entity.ts")
563
649
  );
564
650
  console.log("\u{1F527} Creating services/core/routes.ts...");
565
- fs2.writeFileSync(
566
- path2.join(projectRoot, "services", "core", "routes.ts"),
651
+ fs3.writeFileSync(
652
+ path3.join(projectRoot, "services", "core", "routes.ts"),
567
653
  readTemplate("core-routes.ts")
568
654
  );
569
655
  const servicesPackageJson = {
@@ -571,13 +657,13 @@ async function runInitCommand(rootPath) {
571
657
  version: "0.0.0",
572
658
  type: "module"
573
659
  };
574
- fs2.writeFileSync(
575
- path2.join(projectRoot, "services", "core", "package.json"),
660
+ fs3.writeFileSync(
661
+ path3.join(projectRoot, "services", "core", "package.json"),
576
662
  JSON.stringify(servicesPackageJson, null, 2)
577
663
  );
578
664
  console.log("\u2699\uFE0F Creating sst.config.ts with Monorise...");
579
- const sstConfigPath = path2.join(projectRoot, "sst.config.ts");
580
- fs2.writeFileSync(sstConfigPath, readTemplate("sst.config.ts").replace("{{PROJECT_NAME}}", projectName));
665
+ const sstConfigPath = path3.join(projectRoot, "sst.config.ts");
666
+ fs3.writeFileSync(sstConfigPath, readTemplate("sst.config.ts").replace("{{PROJECT_NAME}}", projectName));
581
667
  console.log("\n\u2601\uFE0F Installing SST providers...");
582
668
  try {
583
669
  execCommand("npx sst install", projectRoot);
@@ -585,63 +671,63 @@ async function runInitCommand(rootPath) {
585
671
  console.warn("Warning: SST install failed, continuing anyway...");
586
672
  }
587
673
  console.log("\u{1F4C4} Creating example page in apps/web...");
588
- const webSrcAppDir = path2.join(projectRoot, "apps", "web", "src", "app");
589
- const webAppDir = path2.join(projectRoot, "apps", "web", "app");
590
- const pagePath = fs2.existsSync(webSrcAppDir) ? path2.join(webSrcAppDir, "page.tsx") : fs2.existsSync(webAppDir) ? path2.join(webAppDir, "page.tsx") : null;
674
+ const webSrcAppDir = path3.join(projectRoot, "apps", "web", "src", "app");
675
+ const webAppDir = path3.join(projectRoot, "apps", "web", "app");
676
+ const pagePath = fs3.existsSync(webSrcAppDir) ? path3.join(webSrcAppDir, "page.tsx") : fs3.existsSync(webAppDir) ? path3.join(webAppDir, "page.tsx") : null;
591
677
  if (pagePath) {
592
678
  try {
593
- fs2.writeFileSync(pagePath, readTemplate("example-page.tsx"));
594
- console.log(`Created example page at ${path2.relative(projectRoot, pagePath)}`);
679
+ fs3.writeFileSync(pagePath, readTemplate("example-page.tsx"));
680
+ console.log(`Created example page at ${path3.relative(projectRoot, pagePath)}`);
595
681
  } catch (error) {
596
682
  console.warn("Warning: Could not create example page:", error);
597
683
  }
598
684
  } else {
599
685
  console.warn("Warning: Could not find apps/web/src/app or apps/web/app directory");
600
686
  }
601
- const webRoot = fs2.existsSync(webSrcAppDir) ? path2.join(projectRoot, "apps", "web", "src") : fs2.existsSync(webAppDir) ? path2.join(projectRoot, "apps", "web") : null;
687
+ const webRoot = fs3.existsSync(webSrcAppDir) ? path3.join(projectRoot, "apps", "web", "src") : fs3.existsSync(webAppDir) ? path3.join(projectRoot, "apps", "web") : null;
602
688
  if (webRoot) {
603
- const appDir = fs2.existsSync(webSrcAppDir) ? webSrcAppDir : webAppDir;
604
- fs2.mkdirSync(path2.join(webRoot, "components", "ui"), { recursive: true });
605
- fs2.mkdirSync(path2.join(webRoot, "lib"), { recursive: true });
689
+ const appDir = fs3.existsSync(webSrcAppDir) ? webSrcAppDir : webAppDir;
690
+ fs3.mkdirSync(path3.join(webRoot, "components", "ui"), { recursive: true });
691
+ fs3.mkdirSync(path3.join(webRoot, "lib"), { recursive: true });
606
692
  console.log("\u{1F310} Creating global components...");
607
- fs2.writeFileSync(
608
- path2.join(webRoot, "components", "global-initializer.tsx"),
693
+ fs3.writeFileSync(
694
+ path3.join(webRoot, "components", "global-initializer.tsx"),
609
695
  readTemplate("global-initializer.tsx")
610
696
  );
611
- fs2.writeFileSync(
612
- path2.join(webRoot, "components", "global-loader.tsx"),
697
+ fs3.writeFileSync(
698
+ path3.join(webRoot, "components", "global-loader.tsx"),
613
699
  readTemplate("global-loader.tsx")
614
700
  );
615
701
  console.log("\u{1F527} Creating lib/utils.ts...");
616
- fs2.writeFileSync(
617
- path2.join(webRoot, "lib", "utils.ts"),
702
+ fs3.writeFileSync(
703
+ path3.join(webRoot, "lib", "utils.ts"),
618
704
  readTemplate("lib-utils.ts")
619
705
  );
620
706
  console.log("\u{1F3A8} Creating shadcn UI components...");
621
- fs2.writeFileSync(
622
- path2.join(webRoot, "components", "ui", "button.tsx"),
707
+ fs3.writeFileSync(
708
+ path3.join(webRoot, "components", "ui", "button.tsx"),
623
709
  readTemplate("ui-button.tsx")
624
710
  );
625
- fs2.writeFileSync(
626
- path2.join(webRoot, "components", "ui", "card.tsx"),
711
+ fs3.writeFileSync(
712
+ path3.join(webRoot, "components", "ui", "card.tsx"),
627
713
  readTemplate("ui-card.tsx")
628
714
  );
629
- fs2.writeFileSync(
630
- path2.join(webRoot, "components", "ui", "input.tsx"),
715
+ fs3.writeFileSync(
716
+ path3.join(webRoot, "components", "ui", "input.tsx"),
631
717
  readTemplate("ui-input.tsx")
632
718
  );
633
- fs2.writeFileSync(
634
- path2.join(webRoot, "components", "ui", "label.tsx"),
719
+ fs3.writeFileSync(
720
+ path3.join(webRoot, "components", "ui", "label.tsx"),
635
721
  readTemplate("ui-label.tsx")
636
722
  );
637
723
  console.log("\u{1F3A8} Setting up shadcn globals.css...");
638
- const globalsCssPath = path2.join(appDir, "globals.css");
639
- fs2.writeFileSync(globalsCssPath, readTemplate("globals.css"));
724
+ const globalsCssPath = path3.join(appDir, "globals.css");
725
+ fs3.writeFileSync(globalsCssPath, readTemplate("globals.css"));
640
726
  console.log("\u{1F4D0} Updating layout.tsx with global components...");
641
- const layoutPath = path2.join(appDir, "layout.tsx");
642
- if (fs2.existsSync(layoutPath)) {
727
+ const layoutPath = path3.join(appDir, "layout.tsx");
728
+ if (fs3.existsSync(layoutPath)) {
643
729
  try {
644
- let layoutContent = fs2.readFileSync(layoutPath, "utf8");
730
+ let layoutContent = fs3.readFileSync(layoutPath, "utf8");
645
731
  const globalImports = `import GlobalInitializer from '#/components/global-initializer';
646
732
  import GlobalLoader from '#/components/global-loader';`;
647
733
  const lastImportIndex = layoutContent.lastIndexOf("import ");
@@ -654,14 +740,14 @@ import GlobalLoader from '#/components/global-loader';`;
654
740
  <GlobalInitializer />
655
741
  <GlobalLoader />`
656
742
  );
657
- fs2.writeFileSync(layoutPath, layoutContent);
743
+ fs3.writeFileSync(layoutPath, layoutContent);
658
744
  } catch (error) {
659
745
  console.warn("Warning: Could not update layout.tsx:", error);
660
746
  }
661
747
  }
662
- const postcssPath = path2.join(projectRoot, "apps", "web", "postcss.config.mjs");
663
- if (fs2.existsSync(postcssPath)) {
664
- fs2.writeFileSync(
748
+ const postcssPath = path3.join(projectRoot, "apps", "web", "postcss.config.mjs");
749
+ if (fs3.existsSync(postcssPath)) {
750
+ fs3.writeFileSync(
665
751
  postcssPath,
666
752
  `const config = {
667
753
  plugins: {
@@ -674,23 +760,23 @@ export default config;
674
760
  );
675
761
  }
676
762
  console.log("\u{1F500} Creating API proxy routes...");
677
- const apiDir = path2.join(appDir, "api");
678
- const catchAllDir = path2.join(apiDir, "[...proxy]");
679
- fs2.mkdirSync(catchAllDir, { recursive: true });
680
- fs2.writeFileSync(
681
- path2.join(apiDir, "proxy-request.ts"),
763
+ const apiDir = path3.join(appDir, "api");
764
+ const catchAllDir = path3.join(apiDir, "[...proxy]");
765
+ fs3.mkdirSync(catchAllDir, { recursive: true });
766
+ fs3.writeFileSync(
767
+ path3.join(apiDir, "proxy-request.ts"),
682
768
  readTemplate("proxy-request.ts")
683
769
  );
684
- fs2.writeFileSync(
685
- path2.join(catchAllDir, "route.ts"),
770
+ fs3.writeFileSync(
771
+ path3.join(catchAllDir, "route.ts"),
686
772
  readTemplate("proxy-route.ts")
687
773
  );
688
774
  }
689
775
  console.log("\u2699\uFE0F Updating apps/web tsconfig.json...");
690
- const webTsconfigPath = path2.join(projectRoot, "apps", "web", "tsconfig.json");
691
- if (fs2.existsSync(webTsconfigPath)) {
776
+ const webTsconfigPath = path3.join(projectRoot, "apps", "web", "tsconfig.json");
777
+ if (fs3.existsSync(webTsconfigPath)) {
692
778
  try {
693
- const webTsconfigContent = fs2.readFileSync(webTsconfigPath, "utf8");
779
+ const webTsconfigContent = fs3.readFileSync(webTsconfigPath, "utf8");
694
780
  const webTsconfig = JSON.parse(webTsconfigContent);
695
781
  if (!webTsconfig.compilerOptions) {
696
782
  webTsconfig.compilerOptions = {};
@@ -701,9 +787,9 @@ export default config;
701
787
  webTsconfig.compilerOptions.paths["#/shared/*"] = ["../../shared/*"];
702
788
  webTsconfig.compilerOptions.paths["#/monorise/*"] = ["../../.monorise/*"];
703
789
  webTsconfig.compilerOptions.paths["#/monorise"] = ["../../.monorise/index"];
704
- const hasSrcDir = fs2.existsSync(path2.join(projectRoot, "apps", "web", "src"));
790
+ const hasSrcDir = fs3.existsSync(path3.join(projectRoot, "apps", "web", "src"));
705
791
  webTsconfig.compilerOptions.paths["#/*"] = [hasSrcDir ? "./src/*" : "./*"];
706
- fs2.writeFileSync(webTsconfigPath, JSON.stringify(webTsconfig, null, 2));
792
+ fs3.writeFileSync(webTsconfigPath, JSON.stringify(webTsconfig, null, 2));
707
793
  } catch (error) {
708
794
  console.warn("Warning: Could not update apps/web tsconfig.json:", error);
709
795
  }
@@ -730,7 +816,7 @@ export default config;
730
816
  console.log(` \u2022 Edit your data model \u2192 monorise/configs/user.ts`);
731
817
  console.log(` (Add fields like phone, role, status to the User entity)`);
732
818
  console.log(
733
- ` \u2022 Build your UI \u2192 ${pagePath ? path2.relative(projectRoot, pagePath) : "apps/web/app/page.tsx"}`
819
+ ` \u2022 Build your UI \u2192 ${pagePath ? path3.relative(projectRoot, pagePath) : "apps/web/app/page.tsx"}`
734
820
  );
735
821
  console.log(` (React components using useEntities and createEntity)`);
736
822
  console.log(` \u2022 Add backend logic \u2192 services/core/routes.ts`);
@@ -749,7 +835,7 @@ async function runDevCommand(configDir, rootPath) {
749
835
  console.log(`Watching for changes in ${configDir}...`);
750
836
  const watcher = chokidar.watch(configDir, {
751
837
  ignored: (watchedPath) => {
752
- const fileName = path2.basename(watchedPath);
838
+ const fileName = path3.basename(watchedPath);
753
839
  return fileName === "index.ts" || // Old name, still ignore in case it exists
754
840
  fileName === "config.ts" || // Generated config file
755
841
  fileName === "processors.ts" || // Generated processors file