monorise 0.0.2-dev.5 → 0.0.3-dev.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.
@@ -202,7 +202,7 @@ interface MonoriseEntityConfig<T extends Entity = Entity, B extends z.ZodRawShap
202
202
  processor: (entity: {
203
203
  entityId: string;
204
204
  entityType: string;
205
- data: z.infer<z.ZodObject<B>>;
205
+ data: Record<string, any>;
206
206
  createdAt: string;
207
207
  updatedAt: string;
208
208
  }) => {
@@ -213,7 +213,7 @@ interface MonoriseEntityConfig<T extends Entity = Entity, B extends z.ZodRawShap
213
213
  }
214
214
 
215
215
  declare const createEntityConfig: <T extends Entity, B extends z.ZodRawShape, C extends z.ZodRawShape, M extends z.ZodRawShape, CO extends z.ZodObject<C> | undefined = undefined, MO extends z.ZodObject<M> | undefined = undefined>(config: MonoriseEntityConfig<T, B, C, M, CO, MO>) => {
216
- finalSchema: (CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any>[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<MO["shape"] & CO["shape"]>[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_3 ? { [k_2 in keyof T_3]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any>[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_4 ? { [k_3 in keyof T_4]: z.baseObjectInputType<MO["shape"] & B>[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_5 ? { [k_4 in keyof T_5]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_6 ? { [k_5 in keyof T_6]: z.baseObjectInputType<B>[k_5]; } : never>) | z.ZodEffects<CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_7 ? { [k in keyof T_7]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any>[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_8 ? { [k_1 in keyof T_8]: z.baseObjectInputType<MO["shape"] & CO["shape"]>[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_9 ? { [k_2 in keyof T_9]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any>[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_10 ? { [k_3 in keyof T_10]: z.baseObjectInputType<MO["shape"] & B>[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_11 ? { [k_4 in keyof T_11]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_12 ? { [k_5 in keyof T_12]: z.baseObjectInputType<B>[k_5]; } : never>, z.output<CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_13 ? { [k in keyof T_13]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any>[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_14 ? { [k_1 in keyof T_14]: z.baseObjectInputType<MO["shape"] & CO["shape"]>[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_15 ? { [k_2 in keyof T_15]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any>[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_16 ? { [k_3 in keyof T_16]: z.baseObjectInputType<MO["shape"] & B>[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_17 ? { [k_4 in keyof T_17]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_18 ? { [k_5 in keyof T_18]: z.baseObjectInputType<B>[k_5]; } : never>>, z.input<CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_19 ? { [k in keyof T_19]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any>[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_20 ? { [k_1 in keyof T_20]: z.baseObjectInputType<MO["shape"] & CO["shape"]>[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_21 ? { [k_2 in keyof T_21]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any>[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_22 ? { [k_3 in keyof T_22]: z.baseObjectInputType<MO["shape"] & B>[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_23 ? { [k_4 in keyof T_23]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_24 ? { [k_5 in keyof T_24]: z.baseObjectInputType<B>[k_5]; } : never>>>;
216
+ finalSchema: (CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_3 ? { [k_2 in keyof T_3]: T_3[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_4 ? { [k_3 in keyof T_4]: T_4[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_5 ? { [k_4 in keyof T_5]: T_5[k_4]; } : never, z.baseObjectInputType<B> extends infer T_6 ? { [k_5 in keyof T_6]: T_6[k_5]; } : never>) | z.ZodEffects<CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_7 ? { [k in keyof T_7]: T_7[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_8 ? { [k_1 in keyof T_8]: T_8[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_9 ? { [k_2 in keyof T_9]: T_9[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_10 ? { [k_3 in keyof T_10]: T_10[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_11 ? { [k_4 in keyof T_11]: T_11[k_4]; } : never, z.baseObjectInputType<B> extends infer T_12 ? { [k_5 in keyof T_12]: T_12[k_5]; } : never>, z.output<CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_13 ? { [k in keyof T_13]: T_13[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_14 ? { [k_1 in keyof T_14]: T_14[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_15 ? { [k_2 in keyof T_15]: T_15[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_16 ? { [k_3 in keyof T_16]: T_16[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_17 ? { [k_4 in keyof T_17]: T_17[k_4]; } : never, z.baseObjectInputType<B> extends infer T_18 ? { [k_5 in keyof T_18]: T_18[k_5]; } : never>>, z.input<CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_19 ? { [k in keyof T_19]: T_19[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_20 ? { [k_1 in keyof T_20]: T_20[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_21 ? { [k_2 in keyof T_21]: T_21[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_22 ? { [k_3 in keyof T_22]: T_22[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_23 ? { [k_4 in keyof T_23]: T_23[k_4]; } : never, z.baseObjectInputType<B> extends infer T_24 ? { [k_5 in keyof T_24]: T_24[k_5]; } : never>>>;
217
217
  name: string | T;
218
218
  displayName: string;
219
219
  authMethod?: {
@@ -221,7 +221,7 @@ declare const createEntityConfig: <T extends Entity, B extends z.ZodRawShape, C
221
221
  tokenExpiresIn: number;
222
222
  };
223
223
  };
224
- baseSchema: z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_25 ? { [k_4 in keyof T_25]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_26 ? { [k_5 in keyof T_26]: z.baseObjectInputType<B>[k_5]; } : never>;
224
+ baseSchema: z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_25 ? { [k_4 in keyof T_25]: T_25[k_4]; } : never, z.baseObjectInputType<B> extends infer T_26 ? { [k_5 in keyof T_26]: T_26[k_5]; } : never>;
225
225
  createSchema?: CO | undefined;
226
226
  searchableFields?: (keyof B)[] | undefined;
227
227
  uniqueFields?: (keyof B)[] | undefined;
@@ -253,14 +253,14 @@ declare const createEntityConfig: <T extends Entity, B extends z.ZodRawShape, C
253
253
  processor: (entity: {
254
254
  entityId: string;
255
255
  entityType: string;
256
- data: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_27 ? { [k_4 in keyof T_27]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never;
256
+ data: Record<string, any>;
257
257
  createdAt: string;
258
258
  updatedAt: string;
259
259
  }) => {
260
260
  group?: string;
261
261
  sortValue?: string;
262
262
  }[];
263
- }[] | undefined;
263
+ }[];
264
264
  };
265
265
 
266
266
  export { type CreatedEntity, type DraftEntity, Entity, type EntitySchemaMap, type MonoriseEntityConfig, createEntityConfig };
@@ -1 +1 @@
1
- {"version":3,"sources":["../types/monorise.type.ts","../utils/index.ts"],"sourcesContent":["import type { z } from 'zod';\n\nexport enum Entity {}\n\nexport interface EntitySchemaMap {\n [key: string]: Record<string, any>;\n}\n\nexport type DraftEntity<T extends Entity = Entity> =\n T extends keyof EntitySchemaMap ? EntitySchemaMap[T] : never;\n\nexport type CreatedEntity<T extends Entity = Entity> = {\n entityId: string;\n entityType: string;\n data: T extends keyof EntitySchemaMap ? EntitySchemaMap[T] : never;\n createdAt: string;\n updatedAt: string;\n};\n\n/**\n * @description Configuration for a monorise entity, a shared configuration that is used across frontend and backend.\n * This can be served as a single source of truth for the entity configuration.\n * It is used to define the schema, and mutual relationships between this entity and other entities.\n *\n * @example\n * ```ts\n * const baseSchema = z.object({\n * title: z.string(),\n * }).partial();\n *\n * const createSchema = baseSchema.extend({\n * title: z.string(),\n * })\n *\n * const config = createEntityConfig({\n * name: 'learner',\n * displayName: 'Learner',\n * baseSchema,\n * createSchema,\n * });\n * ```\n */\nexport interface MonoriseEntityConfig<\n T extends Entity = Entity,\n B extends z.ZodRawShape = z.ZodRawShape,\n C extends z.ZodRawShape = z.ZodRawShape,\n M extends z.ZodRawShape = z.ZodRawShape,\n CO extends z.ZodObject<C> | undefined = undefined,\n MO extends z.ZodObject<M> | undefined = undefined,\n> {\n /**\n * @description Name of the entity. Must be in **lower-kebab-case** and **unique** across all entities\n *\n * @example `learner`, `learning-activity`\n */\n name: string | T;\n\n /**\n * @description Display name of the entity. It is not required to be unique\n */\n displayName: string;\n\n /**\n * @description (DEPRECATED) Use `uniqueFields` instead, Monorise should not handle auth mechanism\n * @description (Optional) Specify the authentication method to be used for the entity\n */\n authMethod?: {\n /**\n * @description Authentication method using email\n *\n * Note: The email used for authentication is unique per entity.\n * For example, if `johndoe@mail.com` is used for `learner` entity,\n * it can be reused again on `admin` entity. However, the same email\n * address cannot be repeated for the same entity.\n */\n email: {\n /**\n * @description Number of milliseconds before the token expires\n */\n tokenExpiresIn: number;\n };\n };\n\n /**\n * @description Base schema for the entity\n */\n baseSchema: z.ZodObject<B>;\n\n /**\n * @description Minimal schema required to create an entity\n */\n createSchema?: CO;\n searchableFields?: (keyof B)[];\n uniqueFields?: (keyof B)[];\n\n /**\n * @description Define mutual relationship of this entity with other entities\n */\n mutual?: {\n /**\n * @description Subscribes to update events from specified entities in the array.\n * These events will be used to run prejoin processor.\n */\n subscribes?: { entityType: Entity }[];\n /**\n * @description Virtual schema for mutual relationship. The schema is only used for validation purpose, but these fields are not stored in the database\n */\n mutualSchema: MO;\n\n /**\n * @description Keys of `mutualFields` are fields defined in `mutualSchema`.\n * Each field is a mutual relationship between this entity and another entity.\n */\n mutualFields: {\n [key: string]: {\n entityType: Entity;\n toMutualIds?: (context: any) => string[];\n /**\n * @description (Optional) Custom function to process `mutualData`. If not provided, `mutualData` will be empty.\n *\n * @returns the final state of `mutualData` to be stored in the mutual record. Must be an object.\n */\n mutualDataProcessor?: (\n mutualIds: string[],\n currentMutual: any,\n customContext?: Record<string, any>,\n ) => Record<string, any>;\n };\n };\n\n /**\n * @description (Optional) Better known as tree processor\n * This is used to prejoin entities that are not directly related as mutual.\n * For example, if `learner` entity is related to `course` entity, and `course` entity is related to `module` entity,\n * prejoins can be used to join `learner` and `module` entities.\n * With this, the `learner` entity can access the `module` entity without having to go through the `course` entity,\n * hence reducing the number of queries.\n *\n * DynamoDB best practices: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-general-normalization.html\n *\n */\n prejoins?: {\n mutualField: string;\n targetEntityType: Entity;\n entityPaths: {\n skipCache?: boolean;\n entityType: Entity;\n processor?: (items: any[], context: Record<string, any>) => any;\n }[];\n }[];\n };\n /**\n * Use this function to perform side effects on the final schema for example refine/superRefine the schema\n *\n * @param schema The final schema of the entity (the combination of `baseSchema`/`createSchema` and `mutualSchema` if specified)\n * @returns void\n *\n * @example\n * ```ts\n * effect: (schema) => {\n * schema.refine(\n * // refinement logic here\n * )\n * }\n */\n effect?: (\n schema: z.ZodObject<z.ZodRawShape>,\n ) => z.ZodEffects<z.ZodObject<z.ZodRawShape>>;\n\n /**\n * @description (Optional) Use tags to create additional access patterns for the entity.\n * Time complexity for retrieving tagged entities is O(1).\n *\n * The following configuration will create a tag named `region` for the `organization` entity grouped by `region`.\n * You would then be able to retrieve all organizations in a specific region by:\n * GET `/core/tag/organization/region?group={region_name}`\n *\n * @example\n *\n * ```ts\n * {\n * name: 'organization',\n * tags: [\n * {\n * name: 'region',\n * processor: (entity) => {\n * return [\n * {\n * group: entity.data.region\n * }\n * ]\n * },\n * }\n * ]\n * }\n * ```\n *\n * @description\n *\n * The following configuration will create a tag named `dob` for the `user` entity sorted by `dob`.\n * You would then be able to retrieve all users sorted by `dob` by:\n * GET `/core/tag/user/dob?start=2000-01-01&end=2020-12-31`\n *\n * @example\n * ```ts\n * {\n * name: 'user',\n * tags: [\n * {\n * name: 'dob',\n * processor: (entity) => {\n * return [\n * {\n * sortValue: entity.data.dob\n * }\n * ]\n * },\n * }\n * ]\n * }\n * ```\n */\n tags?: {\n name: string;\n processor: (entity: {\n entityId: string;\n entityType: string;\n data: z.infer<z.ZodObject<B>>;\n createdAt: string;\n updatedAt: string;\n }) => {\n group?: string;\n sortValue?: string;\n }[];\n }[];\n}\n","import type { Entity, MonoriseEntityConfig } from '../types/monorise.type';\nimport { z } from 'zod';\n\nfunction makeSchema<\n T extends Entity,\n B extends z.ZodRawShape,\n C extends z.ZodRawShape,\n M extends z.ZodRawShape,\n CO extends z.ZodObject<C> | undefined = undefined,\n MO extends z.ZodObject<M> | undefined = undefined,\n>(config: MonoriseEntityConfig<T, B, C, M, CO, MO>) {\n const { baseSchema, createSchema, mutual, effect } = config;\n const { mutualSchema } = mutual || {};\n\n type FinalSchemaType = CO extends z.AnyZodObject\n ? MO extends z.AnyZodObject\n ? z.ZodObject<MO['shape'] & CO['shape']>\n : CO\n : MO extends z.AnyZodObject\n ? z.ZodObject<MO['shape'] & B>\n : z.ZodObject<B>;\n\n const finalSchema = z.object({\n ...baseSchema.shape,\n ...createSchema?.shape,\n ...mutualSchema?.shape,\n }) as FinalSchemaType;\n\n if (effect) {\n return effect(finalSchema) as z.ZodEffects<FinalSchemaType>;\n }\n\n return finalSchema;\n}\n\nconst createEntityConfig = <\n T extends Entity,\n B extends z.ZodRawShape,\n C extends z.ZodRawShape,\n M extends z.ZodRawShape,\n CO extends z.ZodObject<C> | undefined = undefined,\n MO extends z.ZodObject<M> | undefined = undefined,\n>(\n config: MonoriseEntityConfig<T, B, C, M, CO, MO>,\n) => ({\n ...config,\n finalSchema: makeSchema(config),\n});\n\nexport { createEntityConfig };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAEO,IAAK,SAAL,kBAAKA,YAAL;AAAK,SAAAA;AAAA,GAAA;;;ACDZ,SAAS,SAAS;AAElB,SAAS,WAOP,QAAkD;AAClD,QAAM,EAAE,YAAY,cAAc,QAAQ,OAAO,IAAI;AACrD,QAAM,EAAE,aAAa,IAAI,UAAU,CAAC;AAUpC,QAAM,cAAc,EAAE,OAAO,iDACxB,WAAW,QACX,6CAAc,QACd,6CAAc,MAClB;AAED,MAAI,QAAQ;AACV,WAAO,OAAO,WAAW;AAAA,EAC3B;AAEA,SAAO;AACT;AAEA,IAAM,qBAAqB,CAQzB,WACI,iCACD,SADC;AAAA,EAEJ,aAAa,WAAW,MAAM;AAChC;","names":["Entity"]}
1
+ {"version":3,"sources":["../types/monorise.type.ts","../utils/index.ts"],"sourcesContent":["import type { z } from 'zod';\n\nexport enum Entity {}\n\nexport interface EntitySchemaMap {\n [key: string]: Record<string, any>;\n}\n\nexport type DraftEntity<T extends Entity = Entity> =\n T extends keyof EntitySchemaMap ? EntitySchemaMap[T] : never;\n\nexport type CreatedEntity<T extends Entity = Entity> = {\n entityId: string;\n entityType: string;\n data: T extends keyof EntitySchemaMap ? EntitySchemaMap[T] : never;\n createdAt: string;\n updatedAt: string;\n};\n\n/**\n * @description Configuration for a monorise entity, a shared configuration that is used across frontend and backend.\n * This can be served as a single source of truth for the entity configuration.\n * It is used to define the schema, and mutual relationships between this entity and other entities.\n *\n * @example\n * ```ts\n * const baseSchema = z.object({\n * title: z.string(),\n * }).partial();\n *\n * const createSchema = baseSchema.extend({\n * title: z.string(),\n * })\n *\n * const config = createEntityConfig({\n * name: 'learner',\n * displayName: 'Learner',\n * baseSchema,\n * createSchema,\n * });\n * ```\n */\nexport interface MonoriseEntityConfig<\n T extends Entity = Entity,\n B extends z.ZodRawShape = z.ZodRawShape,\n C extends z.ZodRawShape = z.ZodRawShape,\n M extends z.ZodRawShape = z.ZodRawShape,\n CO extends z.ZodObject<C> | undefined = undefined,\n MO extends z.ZodObject<M> | undefined = undefined,\n> {\n /**\n * @description Name of the entity. Must be in **lower-kebab-case** and **unique** across all entities\n *\n * @example `learner`, `learning-activity`\n */\n name: string | T;\n\n /**\n * @description Display name of the entity. It is not required to be unique\n */\n displayName: string;\n\n /**\n * @description (DEPRECATED) Use `uniqueFields` instead, Monorise should not handle auth mechanism\n * @description (Optional) Specify the authentication method to be used for the entity\n */\n authMethod?: {\n /**\n * @description Authentication method using email\n *\n * Note: The email used for authentication is unique per entity.\n * For example, if `johndoe@mail.com` is used for `learner` entity,\n * it can be reused again on `admin` entity. However, the same email\n * address cannot be repeated for the same entity.\n */\n email: {\n /**\n * @description Number of milliseconds before the token expires\n */\n tokenExpiresIn: number;\n };\n };\n\n /**\n * @description Base schema for the entity\n */\n baseSchema: z.ZodObject<B>;\n\n /**\n * @description Minimal schema required to create an entity\n */\n createSchema?: CO;\n searchableFields?: (keyof B)[];\n uniqueFields?: (keyof B)[];\n\n /**\n * @description Define mutual relationship of this entity with other entities\n */\n mutual?: {\n /**\n * @description Subscribes to update events from specified entities in the array.\n * These events will be used to run prejoin processor.\n */\n subscribes?: { entityType: Entity }[];\n /**\n * @description Virtual schema for mutual relationship. The schema is only used for validation purpose, but these fields are not stored in the database\n */\n mutualSchema: MO;\n\n /**\n * @description Keys of `mutualFields` are fields defined in `mutualSchema`.\n * Each field is a mutual relationship between this entity and another entity.\n */\n mutualFields: {\n [key: string]: {\n entityType: Entity;\n toMutualIds?: (context: any) => string[];\n /**\n * @description (Optional) Custom function to process `mutualData`. If not provided, `mutualData` will be empty.\n *\n * @returns the final state of `mutualData` to be stored in the mutual record. Must be an object.\n */\n mutualDataProcessor?: (\n mutualIds: string[],\n currentMutual: any,\n customContext?: Record<string, any>,\n ) => Record<string, any>;\n };\n };\n\n /**\n * @description (Optional) Better known as tree processor\n * This is used to prejoin entities that are not directly related as mutual.\n * For example, if `learner` entity is related to `course` entity, and `course` entity is related to `module` entity,\n * prejoins can be used to join `learner` and `module` entities.\n * With this, the `learner` entity can access the `module` entity without having to go through the `course` entity,\n * hence reducing the number of queries.\n *\n * DynamoDB best practices: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-general-normalization.html\n *\n */\n prejoins?: {\n mutualField: string;\n targetEntityType: Entity;\n entityPaths: {\n skipCache?: boolean;\n entityType: Entity;\n processor?: (items: any[], context: Record<string, any>) => any;\n }[];\n }[];\n };\n /**\n * Use this function to perform side effects on the final schema for example refine/superRefine the schema\n *\n * @param schema The final schema of the entity (the combination of `baseSchema`/`createSchema` and `mutualSchema` if specified)\n * @returns void\n *\n * @example\n * ```ts\n * effect: (schema) => {\n * schema.refine(\n * // refinement logic here\n * )\n * }\n */\n effect?: (\n schema: z.ZodObject<z.ZodRawShape>,\n ) => z.ZodEffects<z.ZodObject<z.ZodRawShape>>;\n\n /**\n * @description (Optional) Use tags to create additional access patterns for the entity.\n * Time complexity for retrieving tagged entities is O(1).\n *\n * The following configuration will create a tag named `region` for the `organization` entity grouped by `region`.\n * You would then be able to retrieve all organizations in a specific region by:\n * GET `/core/tag/organization/region?group={region_name}`\n *\n * @example\n *\n * ```ts\n * {\n * name: 'organization',\n * tags: [\n * {\n * name: 'region',\n * processor: (entity) => {\n * return [\n * {\n * group: entity.data.region\n * }\n * ]\n * },\n * }\n * ]\n * }\n * ```\n *\n * @description\n *\n * The following configuration will create a tag named `dob` for the `user` entity sorted by `dob`.\n * You would then be able to retrieve all users sorted by `dob` by:\n * GET `/core/tag/user/dob?start=2000-01-01&end=2020-12-31`\n *\n * @example\n * ```ts\n * {\n * name: 'user',\n * tags: [\n * {\n * name: 'dob',\n * processor: (entity) => {\n * return [\n * {\n * sortValue: entity.data.dob\n * }\n * ]\n * },\n * }\n * ]\n * }\n * ```\n */\n tags?: {\n name: string;\n processor: (entity: { entityId: string; entityType: string; data: Record<string, any>; createdAt: string; updatedAt: string }) => {\n group?: string;\n sortValue?: string;\n }[];\n }[];\n}\n","import type { Entity, MonoriseEntityConfig } from '../types/monorise.type';\nimport { z } from 'zod';\n\nfunction makeSchema<\n T extends Entity,\n B extends z.ZodRawShape,\n C extends z.ZodRawShape,\n M extends z.ZodRawShape,\n CO extends z.ZodObject<C> | undefined = undefined,\n MO extends z.ZodObject<M> | undefined = undefined,\n>(config: MonoriseEntityConfig<T, B, C, M, CO, MO>) {\n const { baseSchema, createSchema, mutual, effect } = config;\n const { mutualSchema } = mutual || {};\n\n type FinalSchemaType = CO extends z.AnyZodObject\n ? MO extends z.AnyZodObject\n ? z.ZodObject<MO['shape'] & CO['shape']>\n : CO\n : MO extends z.AnyZodObject\n ? z.ZodObject<MO['shape'] & B>\n : z.ZodObject<B>;\n\n const finalSchema = z.object({\n ...baseSchema.shape,\n ...createSchema?.shape,\n ...mutualSchema?.shape,\n }) as FinalSchemaType;\n\n if (effect) {\n return effect(finalSchema) as z.ZodEffects<FinalSchemaType>;\n }\n\n return finalSchema;\n}\n\nconst createEntityConfig = <\n T extends Entity,\n B extends z.ZodRawShape,\n C extends z.ZodRawShape,\n M extends z.ZodRawShape,\n CO extends z.ZodObject<C> | undefined = undefined,\n MO extends z.ZodObject<M> | undefined = undefined,\n>(\n config: MonoriseEntityConfig<T, B, C, M, CO, MO>,\n) => ({\n ...config,\n finalSchema: makeSchema(config),\n});\n\nexport { createEntityConfig };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAEO,IAAK,SAAL,kBAAKA,YAAL;AAAK,SAAAA;AAAA,GAAA;;;ACDZ,SAAS,SAAS;AAElB,SAAS,WAOP,QAAkD;AAClD,QAAM,EAAE,YAAY,cAAc,QAAQ,OAAO,IAAI;AACrD,QAAM,EAAE,aAAa,IAAI,UAAU,CAAC;AAUpC,QAAM,cAAc,EAAE,OAAO,iDACxB,WAAW,QACX,6CAAc,QACd,6CAAc,MAClB;AAED,MAAI,QAAQ;AACV,WAAO,OAAO,WAAW;AAAA,EAC3B;AAEA,SAAO;AACT;AAEA,IAAM,qBAAqB,CAQzB,WACI,iCACD,SADC;AAAA,EAEJ,aAAa,WAAW,MAAM;AAChC;","names":["Entity"]}
package/dist/cli/cli.js CHANGED
@@ -3,22 +3,40 @@
3
3
  // cli.ts
4
4
  import "tsx";
5
5
  import "tsconfig-paths/register.js";
6
+ import fs2 from "fs";
7
+ import path2 from "path";
8
+ import chokidar from "chokidar";
9
+
10
+ // commands/utils/detect-package.ts
6
11
  import fs from "fs";
7
12
  import path from "path";
8
- import chokidar from "chokidar";
13
+ function detectCombinedPackage(startDir) {
14
+ let dir = startDir;
15
+ while (true) {
16
+ if (fs.existsSync(path.join(dir, "node_modules", "monorise"))) {
17
+ return true;
18
+ }
19
+ const parent = path.dirname(dir);
20
+ if (parent === dir) break;
21
+ dir = parent;
22
+ }
23
+ return false;
24
+ }
25
+
26
+ // cli.ts
9
27
  function kebabToCamel(str) {
10
28
  return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
11
29
  }
12
30
  function kebabToPascal(kebab) {
13
31
  return kebab.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
14
32
  }
15
- async function generateConfigFile(configDir, monoriseOutputDir) {
16
- const configOutputPath = path.join(monoriseOutputDir, "config.ts");
33
+ async function generateConfigFile(configDir, monoriseOutputDir, projectRoot) {
34
+ const configOutputPath = path2.join(monoriseOutputDir, "config.ts");
17
35
  const initialConfigContent = `
18
36
  export enum Entity {}
19
37
  `;
20
- fs.writeFileSync(configOutputPath, initialConfigContent);
21
- const files = fs.readdirSync(configDir).filter((file) => file.endsWith(".ts") && file !== "index.ts");
38
+ fs2.writeFileSync(configOutputPath, initialConfigContent);
39
+ const files = fs2.readdirSync(configDir).filter((file) => file.endsWith(".ts") && file !== "index.ts");
22
40
  const names = /* @__PURE__ */ new Set();
23
41
  const nameRegex = /^[a-z]+(-[a-z]+)*$/;
24
42
  const imports = [];
@@ -29,10 +47,10 @@ export enum Entity {}
29
47
  const schemaEntries = [];
30
48
  const allowedEntityEntries = [];
31
49
  const entityWithEmailAuthEntries = [];
32
- const relativePathToConfigDir = path.relative(monoriseOutputDir, configDir);
50
+ const relativePathToConfigDir = path2.relative(monoriseOutputDir, configDir);
33
51
  const importPathPrefix = relativePathToConfigDir ? `${relativePathToConfigDir}/` : "./";
34
52
  for (const file of files) {
35
- const fullPath = path.join(configDir, file);
53
+ const fullPath = path2.join(configDir, file);
36
54
  const module = await import(fullPath);
37
55
  const config = module.default;
38
56
  if (!nameRegex.test(config.name)) {
@@ -66,6 +84,20 @@ export enum Entity {}
66
84
  entityWithEmailAuthEntries.push(`Entity.${enumKey}`);
67
85
  }
68
86
  }
87
+ const usesCombinedPackage = detectCombinedPackage(projectRoot);
88
+ const augmentationBlock = (moduleName) => `
89
+ declare module '${moduleName}' {
90
+ export enum Entity {
91
+ ${enumEntries.join(",\n ")}
92
+ }
93
+
94
+ ${typeEntries.join("\n ")}
95
+
96
+ export interface EntitySchemaMap {
97
+ ${schemaMapEntries.join("\n ")}
98
+ }
99
+ }`;
100
+ const moduleAugmentations = usesCombinedPackage ? augmentationBlock("monorise/base") : augmentationBlock("@monorise/base");
69
101
  const configOutputContent = `
70
102
  import type { z } from 'zod';
71
103
  ${imports.join("\n")}
@@ -109,46 +141,23 @@ const config = {
109
141
  };
110
142
 
111
143
  export default config;
112
-
113
- declare module '@monorise/base' {
114
- export enum Entity {
115
- ${enumEntries.join(",\n ")}
116
- }
117
-
118
- ${typeEntries.join("\n ")}
119
-
120
- export interface EntitySchemaMap {
121
- ${schemaMapEntries.join("\n ")}
122
- }
123
- }
124
-
125
- declare module 'monorise/base' {
126
- export enum Entity {
127
- ${enumEntries.join(",\n ")}
128
- }
129
-
130
- ${typeEntries.join("\n ")}
131
-
132
- export interface EntitySchemaMap {
133
- ${schemaMapEntries.join("\n ")}
134
- }
135
- }
144
+ ${moduleAugmentations}
136
145
  `;
137
- fs.writeFileSync(configOutputPath, configOutputContent);
146
+ fs2.writeFileSync(configOutputPath, configOutputContent);
138
147
  console.log("Successfully generated config.ts!");
139
148
  return configOutputPath;
140
149
  }
141
150
  async function generateHandleFile(monoriseConfig, projectRoot, monoriseOutputDir) {
142
- const handleOutputPath = path.join(monoriseOutputDir, "handle.ts");
151
+ const handleOutputPath = path2.join(monoriseOutputDir, "handle.ts");
143
152
  const customRoutesPath = monoriseConfig.customRoutes;
144
153
  let routesImportLine = "";
145
154
  let appHandlerPayload = "{}";
146
155
  if (customRoutesPath) {
147
- const absoluteCustomRoutesPath = path.resolve(
156
+ const absoluteCustomRoutesPath = path2.resolve(
148
157
  projectRoot,
149
158
  customRoutesPath
150
159
  );
151
- if (!fs.existsSync(absoluteCustomRoutesPath) && !fs.existsSync(`${absoluteCustomRoutesPath}.ts`) && !fs.existsSync(`${absoluteCustomRoutesPath}.js`)) {
160
+ if (!fs2.existsSync(absoluteCustomRoutesPath) && !fs2.existsSync(`${absoluteCustomRoutesPath}.ts`) && !fs2.existsSync(`${absoluteCustomRoutesPath}.js`)) {
152
161
  throw new Error(
153
162
  `Custom routes file not found: '${absoluteCustomRoutesPath}'. Please ensure 'customRoutes' in monorise.config.ts points to a valid file.`
154
163
  );
@@ -167,7 +176,7 @@ async function generateHandleFile(monoriseConfig, projectRoot, monoriseOutputDir
167
176
  `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.`
168
177
  );
169
178
  }
170
- let relativePathToRoutes = path.relative(
179
+ let relativePathToRoutes = path2.relative(
171
180
  monoriseOutputDir,
172
181
  absoluteCustomRoutesPath
173
182
  );
@@ -178,8 +187,10 @@ async function generateHandleFile(monoriseConfig, projectRoot, monoriseOutputDir
178
187
  routesImportLine = `import routes from '${relativePathToRoutes}';`;
179
188
  appHandlerPayload = "{ routes }";
180
189
  }
190
+ const usesCombinedPackage = detectCombinedPackage(projectRoot);
191
+ const coreImportPath = usesCombinedPackage ? "monorise/core" : "@monorise/core";
181
192
  const combinedContent = `
182
- import CoreFactory from 'monorise/core';
193
+ import CoreFactory from '${coreImportPath}';
183
194
  import config from './config';
184
195
  ${routesImportLine ? `${routesImportLine}
185
196
  ` : ""}const coreFactory = new CoreFactory(config);
@@ -190,31 +201,31 @@ export const tagHandler = coreFactory.tagProcessor;
190
201
  export const treeHandler = coreFactory.prejoinProcessor;
191
202
  export const appHandler = coreFactory.appHandler(${appHandlerPayload});
192
203
  `;
193
- fs.writeFileSync(handleOutputPath, combinedContent);
204
+ fs2.writeFileSync(handleOutputPath, combinedContent);
194
205
  console.log("Successfully generated handle.ts!");
195
206
  return handleOutputPath;
196
207
  }
197
208
  async function generateFiles(rootPath) {
198
- const baseDir = rootPath ? path.resolve(rootPath) : process.cwd();
199
- const configFilePathTS = path.join(baseDir, "monorise.config.ts");
200
- const configFilePathJS = path.join(baseDir, "monorise.config.js");
209
+ const baseDir = rootPath ? path2.resolve(rootPath) : process.cwd();
210
+ const configFilePathTS = path2.join(baseDir, "monorise.config.ts");
211
+ const configFilePathJS = path2.join(baseDir, "monorise.config.js");
201
212
  let configFilePath;
202
- if (fs.existsSync(configFilePathTS)) {
213
+ if (fs2.existsSync(configFilePathTS)) {
203
214
  configFilePath = configFilePathTS;
204
- } else if (fs.existsSync(configFilePathJS)) {
215
+ } else if (fs2.existsSync(configFilePathJS)) {
205
216
  configFilePath = configFilePathJS;
206
217
  } else {
207
218
  throw new Error(
208
219
  "Neither monorise.config.ts nor monorise.config.js found in the root of the project."
209
220
  );
210
221
  }
211
- const projectRoot = path.dirname(configFilePath);
222
+ const projectRoot = path2.dirname(configFilePath);
212
223
  const monoriseConfigModule = await import(configFilePath);
213
224
  const monoriseConfig = monoriseConfigModule.default;
214
- const configDir = path.resolve(projectRoot, monoriseConfig.configDir);
215
- const monoriseOutputDir = path.join(projectRoot, ".monorise");
216
- fs.mkdirSync(monoriseOutputDir, { recursive: true });
217
- await generateConfigFile(configDir, monoriseOutputDir);
225
+ const configDir = path2.resolve(projectRoot, monoriseConfig.configDir);
226
+ const monoriseOutputDir = path2.join(projectRoot, ".monorise");
227
+ fs2.mkdirSync(monoriseOutputDir, { recursive: true });
228
+ await generateConfigFile(configDir, monoriseOutputDir, projectRoot);
218
229
  await generateHandleFile(monoriseConfig, projectRoot, monoriseOutputDir);
219
230
  return configDir;
220
231
  }
@@ -267,10 +278,10 @@ var MONORISE_LOGO = `
267
278
 
268
279
  `;
269
280
  async function runInitCommand(rootPath) {
270
- const projectRoot = rootPath ? path.resolve(rootPath) : process.cwd();
281
+ const projectRoot = rootPath ? path2.resolve(rootPath) : process.cwd();
271
282
  console.log(MONORISE_LOGO);
272
283
  console.log(`Initializing Monorise project in ${projectRoot}...`);
273
- const monoriseConfigTsPath = path.join(projectRoot, "monorise.config.ts");
284
+ const monoriseConfigTsPath = path2.join(projectRoot, "monorise.config.ts");
274
285
  const monoriseConfigContent = `
275
286
  const config = {
276
287
  configDir: './monorise/entities',
@@ -280,17 +291,17 @@ const config = {
280
291
 
281
292
  export default config;
282
293
  `;
283
- if (!fs.existsSync(monoriseConfigTsPath)) {
284
- fs.writeFileSync(monoriseConfigTsPath, monoriseConfigContent.trimStart());
285
- console.log(`Created ${path.relative(projectRoot, monoriseConfigTsPath)}`);
294
+ if (!fs2.existsSync(monoriseConfigTsPath)) {
295
+ fs2.writeFileSync(monoriseConfigTsPath, monoriseConfigContent.trimStart());
296
+ console.log(`Created ${path2.relative(projectRoot, monoriseConfigTsPath)}`);
286
297
  } else {
287
298
  console.log(
288
- `${path.relative(projectRoot, monoriseConfigTsPath)} already exists. Skipping.`
299
+ `${path2.relative(projectRoot, monoriseConfigTsPath)} already exists. Skipping.`
289
300
  );
290
301
  }
291
- const monoriseEntitiesDir = path.join(projectRoot, "monorise", "entities");
292
- fs.mkdirSync(monoriseEntitiesDir, { recursive: true });
293
- const userEntityTsPath = path.join(monoriseEntitiesDir, "user.ts");
302
+ const monoriseEntitiesDir = path2.join(projectRoot, "monorise", "entities");
303
+ fs2.mkdirSync(monoriseEntitiesDir, { recursive: true });
304
+ const userEntityTsPath = path2.join(monoriseEntitiesDir, "user.ts");
294
305
  const userEntityContent = `
295
306
  import { createEntityConfig } from 'monorise/base';
296
307
  import { z } from 'zod';
@@ -313,45 +324,45 @@ const config = createEntityConfig({
313
324
 
314
325
  export default config;
315
326
  `;
316
- if (!fs.existsSync(userEntityTsPath)) {
317
- fs.writeFileSync(userEntityTsPath, userEntityContent.trimStart());
318
- console.log(`Created ${path.relative(projectRoot, userEntityTsPath)}`);
327
+ if (!fs2.existsSync(userEntityTsPath)) {
328
+ fs2.writeFileSync(userEntityTsPath, userEntityContent.trimStart());
329
+ console.log(`Created ${path2.relative(projectRoot, userEntityTsPath)}`);
319
330
  } else {
320
331
  console.log(
321
- `${path.relative(projectRoot, userEntityTsPath)} already exists. Skipping.`
332
+ `${path2.relative(projectRoot, userEntityTsPath)} already exists. Skipping.`
322
333
  );
323
334
  }
324
- const packageJsonPath = path.join(projectRoot, "package.json");
325
- if (fs.existsSync(packageJsonPath)) {
335
+ const packageJsonPath = path2.join(projectRoot, "package.json");
336
+ if (fs2.existsSync(packageJsonPath)) {
326
337
  try {
327
- const packageJsonContent = fs.readFileSync(packageJsonPath, "utf8");
338
+ const packageJsonContent = fs2.readFileSync(packageJsonPath, "utf8");
328
339
  const packageJson = JSON.parse(packageJsonContent);
329
340
  if (packageJson.type !== "module") {
330
341
  packageJson.type = "module";
331
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
342
+ fs2.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
332
343
  console.log(
333
- `Updated 'type' to 'module' in ${path.relative(projectRoot, packageJsonPath)}`
344
+ `Updated 'type' to 'module' in ${path2.relative(projectRoot, packageJsonPath)}`
334
345
  );
335
346
  } else {
336
347
  console.log(
337
- `'type: "module"' already set in ${path.relative(projectRoot, packageJsonPath)}. Skipping.`
348
+ `'type: "module"' already set in ${path2.relative(projectRoot, packageJsonPath)}. Skipping.`
338
349
  );
339
350
  }
340
351
  } catch (error) {
341
352
  console.error(
342
- `Error reading or parsing ${path.relative(projectRoot, packageJsonPath)}:`,
353
+ `Error reading or parsing ${path2.relative(projectRoot, packageJsonPath)}:`,
343
354
  error
344
355
  );
345
356
  }
346
357
  } else {
347
358
  console.warn(
348
- `Warning: ${path.relative(projectRoot, packageJsonPath)} not found. Cannot update 'type'.`
359
+ `Warning: ${path2.relative(projectRoot, packageJsonPath)} not found. Cannot update 'type'.`
349
360
  );
350
361
  }
351
- const tsconfigPath = path.join(projectRoot, "tsconfig.json");
352
- if (fs.existsSync(tsconfigPath)) {
362
+ const tsconfigPath = path2.join(projectRoot, "tsconfig.json");
363
+ if (fs2.existsSync(tsconfigPath)) {
353
364
  try {
354
- const tsconfigContent = fs.readFileSync(tsconfigPath, "utf8");
365
+ const tsconfigContent = fs2.readFileSync(tsconfigPath, "utf8");
355
366
  const tsconfig = JSON.parse(tsconfigContent);
356
367
  if (!tsconfig.compilerOptions) {
357
368
  tsconfig.compilerOptions = {};
@@ -363,24 +374,24 @@ export default config;
363
374
  const pathValue = ["./.monorise/*"];
364
375
  if (!tsconfig.compilerOptions.paths[pathKey]) {
365
376
  tsconfig.compilerOptions.paths[pathKey] = pathValue;
366
- fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2));
377
+ fs2.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2));
367
378
  console.log(
368
- `Added '${pathKey}' path alias in ${path.relative(projectRoot, tsconfigPath)}`
379
+ `Added '${pathKey}' path alias in ${path2.relative(projectRoot, tsconfigPath)}`
369
380
  );
370
381
  } else {
371
382
  console.log(
372
- `'${pathKey}' path alias already set in ${path.relative(projectRoot, tsconfigPath)}. Skipping.`
383
+ `'${pathKey}' path alias already set in ${path2.relative(projectRoot, tsconfigPath)}. Skipping.`
373
384
  );
374
385
  }
375
386
  } catch (error) {
376
387
  console.error(
377
- `Error updating ${path.relative(projectRoot, tsconfigPath)}:`,
388
+ `Error updating ${path2.relative(projectRoot, tsconfigPath)}:`,
378
389
  error
379
390
  );
380
391
  }
381
392
  } else {
382
393
  console.warn(
383
- `Warning: ${path.relative(projectRoot, tsconfigPath)} not found. Cannot add path alias.`
394
+ `Warning: ${path2.relative(projectRoot, tsconfigPath)} not found. Cannot add path alias.`
384
395
  );
385
396
  }
386
397
  console.log("Monorise initialization complete!");
@@ -390,7 +401,7 @@ async function runDevCommand(configDir, rootPath) {
390
401
  console.log(`Watching for changes in ${configDir}...`);
391
402
  const watcher = chokidar.watch(configDir, {
392
403
  ignored: (watchedPath) => {
393
- const fileName = path.basename(watchedPath);
404
+ const fileName = path2.basename(watchedPath);
394
405
  return fileName === "index.ts" || // Old name, still ignore in case it exists
395
406
  fileName === "config.ts" || // Generated config file
396
407
  fileName === "processors.ts" || // Generated processors file
@@ -1 +1 @@
1
- {"version":3,"sources":["../cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport 'tsx';\nimport 'tsconfig-paths/register.js';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport chokidar from 'chokidar';\n\nfunction kebabToCamel(str: string): string {\n return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());\n}\n\nfunction kebabToPascal(kebab: string): string {\n return kebab\n .split('-')\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\n .join('');\n}\n\nasync function generateConfigFile(\n configDir: string,\n monoriseOutputDir: string,\n): Promise<string> {\n const configOutputPath = path.join(monoriseOutputDir, 'config.ts');\n const initialConfigContent = `\nexport enum Entity {}\n`;\n fs.writeFileSync(configOutputPath, initialConfigContent);\n\n const files = fs\n .readdirSync(configDir)\n .filter((file) => file.endsWith('.ts') && file !== 'index.ts');\n\n const names = new Set<string>();\n const nameRegex = /^[a-z]+(-[a-z]+)*$/;\n const imports: string[] = [];\n\n const enumEntries: string[] = [];\n const typeEntries: string[] = [];\n const schemaMapEntries: string[] = [];\n const configEntries: string[] = [];\n const schemaEntries: string[] = [];\n const allowedEntityEntries: string[] = [];\n const entityWithEmailAuthEntries: string[] = [];\n\n const relativePathToConfigDir = path.relative(monoriseOutputDir, configDir);\n const importPathPrefix = relativePathToConfigDir\n ? `${relativePathToConfigDir}/`\n : './';\n\n for (const file of files) {\n const fullPath = path.join(configDir, file);\n const module = await import(fullPath);\n const config = module.default;\n\n if (!nameRegex.test(config.name)) {\n throw new Error(\n `Invalid name format: ${config.name} in ${file}. Must be kebab-case.`,\n );\n }\n\n if (names.has(config.name)) {\n throw new Error(`Duplicate name found: ${config.name} in ${file}`);\n }\n names.add(config.name);\n\n const fileName = file.replace(/\\.ts$/, '');\n const variableName = kebabToCamel(fileName);\n imports.push(\n `import ${variableName} from '${importPathPrefix}${fileName}';`,\n );\n\n const enumKey = config.name.toUpperCase().replace(/-/g, '_');\n enumEntries.push(`${enumKey} = '${config.name}'`);\n typeEntries.push(\n `export type ${kebabToPascal(config.name)}Type = z.infer<(typeof ${variableName})['finalSchema']>;`,\n );\n schemaMapEntries.push(\n `[Entity.${enumKey}]: ${kebabToPascal(config.name)}Type;`,\n );\n\n configEntries.push(`[Entity.${enumKey}]: ${kebabToCamel(config.name)},`);\n schemaEntries.push(\n `[Entity.${enumKey}]: ${kebabToCamel(config.name)}.finalSchema,`,\n );\n\n allowedEntityEntries.push(`Entity.${enumKey}`);\n\n if (config.authMethod?.email) {\n entityWithEmailAuthEntries.push(`Entity.${enumKey}`);\n }\n }\n\n const configOutputContent = `\nimport type { z } from 'zod';\n${imports.join('\\n')}\n\nexport enum Entity {\n ${enumEntries.join(',\\n ')}\n}\n\n${typeEntries.join('\\n')}\n\nexport interface EntitySchemaMap {\n ${schemaMapEntries.join('\\n ')}\n}\n\nconst EntityConfig = {\n ${configEntries.join('\\n ')}\n};\n\nconst FormSchema = {\n ${schemaEntries.join('\\n ')}\n};\n\nconst AllowedEntityTypes = [\n ${allowedEntityEntries.join(',\\n ')}\n];\n\nconst EmailAuthEnabledEntities: Entity[] = [${entityWithEmailAuthEntries.join(', ')}];\n\nexport {\n EntityConfig,\n FormSchema,\n AllowedEntityTypes,\n EmailAuthEnabledEntities,\n};\n\nconst config = {\n EntityConfig,\n FormSchema,\n AllowedEntityTypes,\n EmailAuthEnabledEntities,\n};\n\nexport default config;\n\ndeclare module '@monorise/base' {\n export enum Entity {\n ${enumEntries.join(',\\n ')}\n }\n\n ${typeEntries.join('\\n ')}\n\n export interface EntitySchemaMap {\n ${schemaMapEntries.join('\\n ')}\n }\n}\n\ndeclare module 'monorise/base' {\n export enum Entity {\n ${enumEntries.join(',\\n ')}\n }\n\n ${typeEntries.join('\\n ')}\n\n export interface EntitySchemaMap {\n ${schemaMapEntries.join('\\n ')}\n }\n}\n`;\n\n fs.writeFileSync(configOutputPath, configOutputContent);\n console.log('Successfully generated config.ts!');\n return configOutputPath;\n}\n\nasync function generateHandleFile(\n monoriseConfig: { customRoutes?: string; configDir: string },\n projectRoot: string,\n monoriseOutputDir: string,\n): Promise<string> {\n const handleOutputPath = path.join(monoriseOutputDir, 'handle.ts');\n const customRoutesPath = monoriseConfig.customRoutes;\n\n let routesImportLine = '';\n let appHandlerPayload = '{}'; // Default to an empty object for appHandler if no custom routes\n\n if (customRoutesPath) {\n const absoluteCustomRoutesPath = path.resolve(\n projectRoot,\n customRoutesPath,\n );\n\n if (\n !fs.existsSync(absoluteCustomRoutesPath) &&\n !fs.existsSync(`${absoluteCustomRoutesPath}.ts`) &&\n !fs.existsSync(`${absoluteCustomRoutesPath}.js`)\n ) {\n throw new Error(\n `Custom routes file not found: '${absoluteCustomRoutesPath}'. Please ensure 'customRoutes' in monorise.config.ts points to a valid file.`,\n );\n }\n\n let routesModule;\n try {\n routesModule = await import(absoluteCustomRoutesPath);\n } catch (e: any) {\n throw new Error(\n `Failed to load custom routes file at '${absoluteCustomRoutesPath}'. Ensure it's a valid JavaScript/TypeScript module. Error: ${e.message}`,\n );\n }\n\n const routesExport = routesModule.default;\n\n if (\n !routesExport ||\n routesExport === null ||\n (typeof routesExport === 'object' &&\n !(\n 'get' in routesExport &&\n 'post' in routesExport &&\n 'use' in routesExport\n ))\n ) {\n throw new Error(\n `Custom routes file at '${absoluteCustomRoutesPath}' must default export an instance of Hono (or an object with .get, .post, .use methods). Or a function that consume the dependency container provided by route handler.`,\n );\n }\n\n let relativePathToRoutes = path.relative(\n monoriseOutputDir,\n absoluteCustomRoutesPath,\n );\n relativePathToRoutes = relativePathToRoutes.replace(\n /\\.(ts|js|mjs|cjs)$/,\n '',\n );\n\n // If custom routes are provided, include the import statement and pass 'routes' to appHandler\n routesImportLine = `import routes from '${relativePathToRoutes}';`;\n appHandlerPayload = '{ routes }';\n }\n // If customRoutesPath is not provided, routesImportLine remains empty and appHandlerPayload remains `{}`\n\n const combinedContent = `\nimport CoreFactory from 'monorise/core';\nimport config from './config';\n${routesImportLine ? `${routesImportLine}\\n` : ''}const coreFactory = new CoreFactory(config);\n\nexport const replicationHandler = coreFactory.replicationProcessor;\nexport const mutualHandler = coreFactory.mutualProcessor;\nexport const tagHandler = coreFactory.tagProcessor;\nexport const treeHandler = coreFactory.prejoinProcessor;\nexport const appHandler = coreFactory.appHandler(${appHandlerPayload});\n`;\n fs.writeFileSync(handleOutputPath, combinedContent);\n console.log('Successfully generated handle.ts!');\n\n return handleOutputPath;\n}\n\nasync function generateFiles(rootPath?: string): Promise<string> {\n const baseDir = rootPath ? path.resolve(rootPath) : process.cwd();\n const configFilePathTS = path.join(baseDir, 'monorise.config.ts');\n const configFilePathJS = path.join(baseDir, 'monorise.config.js');\n\n let configFilePath: string;\n if (fs.existsSync(configFilePathTS)) {\n configFilePath = configFilePathTS;\n } else if (fs.existsSync(configFilePathJS)) {\n configFilePath = configFilePathJS;\n } else {\n throw new Error(\n 'Neither monorise.config.ts nor monorise.config.js found in the root of the project.',\n );\n }\n\n const projectRoot = path.dirname(configFilePath);\n const monoriseConfigModule = await import(configFilePath);\n const monoriseConfig = monoriseConfigModule.default;\n\n const configDir = path.resolve(projectRoot, monoriseConfig.configDir);\n const monoriseOutputDir = path.join(projectRoot, '.monorise');\n\n fs.mkdirSync(monoriseOutputDir, { recursive: true });\n\n await generateConfigFile(configDir, monoriseOutputDir);\n await generateHandleFile(monoriseConfig, projectRoot, monoriseOutputDir);\n\n return configDir;\n}\n\nconst MONORISE_LOGO = `\n\n\n\n ░░░░░░░\n ░░▒▒▒░░░░░░▒▒▒░\n ░▒▒░ ░▒▒░\n ░▒▒░ ░▒▒░\n ░▒░ ░▒▒░\n ░▒▒░ ▒▒▒░\n ░▒░░░▒░ ░▒░░▒▒░\n ░▒▒░ ░▒▒▒░ ░▒▒░ ░▒░░\n ░▒▒ ░▒▒░ ░▒▒░ ░▒░ ░▒░ ░▒░\n ░▒▒░ ░▒░ ░▒░░▒▒░░░ ░░▒▒░░▒░ ░▒▒ ░▒░\n ░░▒░ ░▒░ ░▒░ ░▒▒░░▒▒▒▒▒▒░░▒░ ░▒░░ ░▒░ ░▒░\n ░▒░ ░░▒░ ░▒░ ░░░ ░▒░ ░░ ░▒░ ░▒░ ░▒░░ ░░▒░\n ░▒░ ░▒░ ░▒░ ░▒ ░░ ░▒░ ░▒░ ░▒░ ░▒░ ░░░░\n ░░░ ░░░░ ░░░ ░░ ▒░ ░░░ ░░░ ░░░ ░░░ ░░░░\n ░░░ ░░░░ ░░░ ░░░ ░░░ ░░ ░░░ ░░░ ░░░ ░░░░\n ░░░ ░░░ ░░░ ░░░ ░░ ░░ ░░░ ░░░ ░░░ ░░░\n ░░░ ░░░░ ░░░ ░░░ ░░ ░░░ ░░ ░░░ ░░░ ░░░\n ░░ ░░░ ░░░ ░░░ ░░░ ░░ ░░░ ░░░ ░░░ ░░░\n ░░ ░░ ░░ ░░ ░░ ░░░ ░░░ ░░░ ░░░░ ░░░\n ░░░ ░░ ░░░ ░░░ ░░░\n ░░░░░▒░░░░░░░░░▒░░░░░░░░░ ░ ░░ ░░░ ░░░ ░░\n ░░░ ░░░░░░░░░ ░░░ ░░░\n ░░░ ░░░░░░ ░░ ░░░░░▒░░░░░░▒░░░░\n ░░░░░░░░░░░░░░░░░ ░░░░░ ░░░░░░░░ ░░\n ░░░░░░░ ░░░░░░░░░░░░░░ ░░░░ ░░░░░ ░▒░\n ░░░ ░░░░░░░ ░░░░░░ ░░░░░░░░\n ░░░░░░░░░░░░ ░░░░░░ ░░░░ ░░░░░░░░░░░░░\n ░▒▒░░░░░░░░░░░▒▒░░ ░░▒▒▒░░ ░▒▒░░ ░░░░\n ░▒░ ░░▒▒░ ░▒░ ░▒▒░ ░░▒░\n ░▒░ ░░░░▒▒▒▒▒▒▒▒▒▒░░ ░▒░ ▒▒░ ░░▒▒▒░\n ░▒▒▒▒▒░░░ ░░░▒▒▒▒▒░ ▒▒░ ░▒▒▒▒▒▒░\n ░▒▒░ ░▒▒▒▒ ▒▒▒ ▒▒▒\n ░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░ ░▒▒▒▒▒░ ░▒▒\n ▒▒▒ ░░▒▒▒▒▒▒░ ▒▒▒ ░▒▒\n ▒▒▒ ░▒▒▒▒ ░▒▒▒░\n ▒▓▓▓▒▒▒▓▓▒▒▒░ ▒▒▒░░▒▒░\n ▒▓░ ░▒▒▓▓▒░ ▒▓▓░\n ░▒▓░ ░▒▓▒░▒▓▒\n ░▒▓▒░ ░▒▓▓▒\n ░▒▒▓▓▓▓▓▓▒▒░\n\n\n\n`;\n\nasync function runInitCommand(rootPath?: string) {\n const projectRoot = rootPath ? path.resolve(rootPath) : process.cwd();\n console.log(MONORISE_LOGO);\n console.log(`Initializing Monorise project in ${projectRoot}...`);\n\n // 1. Create monorise.config.ts\n const monoriseConfigTsPath = path.join(projectRoot, 'monorise.config.ts');\n const monoriseConfigContent = `\nconst config = {\n configDir: './monorise/entities',\n // custom route file should export default an Hono object.\n // customRoutes: './path/to/custom/routes.ts'\n};\n\nexport default config;\n`;\n if (!fs.existsSync(monoriseConfigTsPath)) {\n fs.writeFileSync(monoriseConfigTsPath, monoriseConfigContent.trimStart());\n console.log(`Created ${path.relative(projectRoot, monoriseConfigTsPath)}`);\n } else {\n console.log(\n `${path.relative(projectRoot, monoriseConfigTsPath)} already exists. Skipping.`,\n );\n }\n\n // 2. Create ./monorise/entities/user.ts\n const monoriseEntitiesDir = path.join(projectRoot, 'monorise', 'entities');\n fs.mkdirSync(monoriseEntitiesDir, { recursive: true });\n\n const userEntityTsPath = path.join(monoriseEntitiesDir, 'user.ts');\n const userEntityContent = `\nimport { createEntityConfig } from 'monorise/base';\nimport { z } from 'zod';\n\nconst baseSchema = z\n .object({\n displayName: z\n .string()\n .min(1, 'Please provide a name for this user account'),\n firstName: z.string().min(1, 'Please provide first name'),\n lastName: z.string().min(1, 'Please provide last name'),\n jobTitle: z.string(),\n })\n .partial();\n\nconst config = createEntityConfig({\n name: 'user',\n baseSchema,\n});\n\nexport default config;\n`;\n if (!fs.existsSync(userEntityTsPath)) {\n fs.writeFileSync(userEntityTsPath, userEntityContent.trimStart());\n console.log(`Created ${path.relative(projectRoot, userEntityTsPath)}`);\n } else {\n console.log(\n `${path.relative(projectRoot, userEntityTsPath)} already exists. Skipping.`,\n );\n }\n\n // 3. Update package.json\n const packageJsonPath = path.join(projectRoot, 'package.json');\n if (fs.existsSync(packageJsonPath)) {\n try {\n const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8');\n const packageJson = JSON.parse(packageJsonContent);\n\n if (packageJson.type !== 'module') {\n packageJson.type = 'module';\n fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));\n console.log(\n `Updated 'type' to 'module' in ${path.relative(projectRoot, packageJsonPath)}`,\n );\n } else {\n console.log(\n `'type: \"module\"' already set in ${path.relative(projectRoot, packageJsonPath)}. Skipping.`,\n );\n }\n } catch (error) {\n console.error(\n `Error reading or parsing ${path.relative(projectRoot, packageJsonPath)}:`,\n error,\n );\n }\n } else {\n console.warn(\n `Warning: ${path.relative(projectRoot, packageJsonPath)} not found. Cannot update 'type'.`,\n );\n }\n\n // 4. Add tsconfig path alias for .monorise directory\n const tsconfigPath = path.join(projectRoot, 'tsconfig.json');\n if (fs.existsSync(tsconfigPath)) {\n try {\n const tsconfigContent = fs.readFileSync(tsconfigPath, 'utf8');\n const tsconfig = JSON.parse(tsconfigContent);\n\n if (!tsconfig.compilerOptions) {\n tsconfig.compilerOptions = {};\n }\n if (!tsconfig.compilerOptions.paths) {\n tsconfig.compilerOptions.paths = {};\n }\n\n const pathKey = '#/monorise/*';\n const pathValue = ['./.monorise/*'];\n\n if (!tsconfig.compilerOptions.paths[pathKey]) {\n tsconfig.compilerOptions.paths[pathKey] = pathValue;\n fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2));\n console.log(\n `Added '${pathKey}' path alias in ${path.relative(projectRoot, tsconfigPath)}`,\n );\n } else {\n console.log(\n `'${pathKey}' path alias already set in ${path.relative(projectRoot, tsconfigPath)}. Skipping.`,\n );\n }\n } catch (error) {\n console.error(\n `Error updating ${path.relative(projectRoot, tsconfigPath)}:`,\n error,\n );\n }\n } else {\n console.warn(\n `Warning: ${path.relative(projectRoot, tsconfigPath)} not found. Cannot add path alias.`,\n );\n }\n\n console.log('Monorise initialization complete!');\n}\n\nasync function runDevCommand(configDir: string, rootPath?: string) {\n console.log(MONORISE_LOGO);\n console.log(`Watching for changes in ${configDir}...`);\n const watcher = chokidar.watch(configDir, {\n ignored: (watchedPath: string) => {\n const fileName = path.basename(watchedPath);\n return (\n fileName === 'index.ts' || // Old name, still ignore in case it exists\n fileName === 'config.ts' || // Generated config file\n fileName === 'processors.ts' || // Generated processors file\n fileName === 'app.ts' || // Generated app file\n fileName.startsWith('.') ||\n watchedPath.endsWith('.js') ||\n watchedPath.endsWith('.jsx') ||\n watchedPath.endsWith('.d.ts')\n );\n },\n persistent: true,\n ignoreInitial: true,\n });\n\n watcher.on('add', async (filePath) => {\n console.log(`File ${filePath} has been added. Regenerating...`);\n try {\n await generateFiles(rootPath);\n } catch (err) {\n console.error('Regeneration failed:', err);\n }\n });\n\n watcher.on('change', async (filePath) => {\n console.log(`File ${filePath} has been changed. Regenerating...`);\n try {\n await generateFiles(rootPath);\n } catch (err) {\n console.error('Regeneration failed:', err);\n }\n });\n\n watcher.on('unlink', async (filePath) => {\n console.log(`File ${filePath} has been removed. Regenerating...`);\n try {\n await generateFiles(rootPath);\n } catch (err) {\n console.error('Regeneration failed:', err);\n }\n });\n\n process.on('SIGINT', () => {\n console.log('Monorise dev terminated. Closing watcher and sst dev...');\n watcher.close();\n process.exit(0);\n });\n process.on('SIGTERM', () => {\n console.log('Monorise dev terminated. Closing watcher and sst dev...');\n watcher.close();\n process.exit(0);\n });\n}\n\nasync function runBuildCommand(rootPath?: string) {\n console.log('Starting sst build...');\n await generateFiles(rootPath);\n}\n\nasync function main() {\n const args = process.argv.slice(2);\n const command = args[0];\n\n let rootPath: string | undefined;\n const rootFlagIndex = args.indexOf('--config-root');\n if (rootFlagIndex > -1 && args[rootFlagIndex + 1]) {\n rootPath = args[rootFlagIndex + 1];\n }\n\n try {\n if (command === 'dev') {\n const configDir = await generateFiles(rootPath);\n await runDevCommand(configDir, rootPath);\n } else if (command === 'build') {\n await runBuildCommand(rootPath);\n } else if (command === 'init') {\n await runInitCommand(rootPath);\n } else {\n console.error(\n 'Unknown command. Usage: monorise [dev|build|init] [--config-root <path>]',\n );\n process.exit(1);\n }\n } catch (err) {\n console.error('Monorise process failed:', err);\n process.exit(1);\n }\n}\n\nmain().catch((err) => {\n console.error('Monorise encountered an unhandled error:', err);\n process.exit(1);\n});\n"],"mappings":";;;AAEA,OAAO;AACP,OAAO;AACP,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,cAAc;AAErB,SAAS,aAAa,KAAqB;AACzC,SAAO,IAAI,QAAQ,aAAa,CAAC,GAAG,WAAW,OAAO,YAAY,CAAC;AACrE;AAEA,SAAS,cAAc,OAAuB;AAC5C,SAAO,MACJ,MAAM,GAAG,EACT,IAAI,CAAC,SAAS,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC,CAAC,EAC1D,KAAK,EAAE;AACZ;AAEA,eAAe,mBACb,WACA,mBACiB;AACjB,QAAM,mBAAmB,KAAK,KAAK,mBAAmB,WAAW;AACjE,QAAM,uBAAuB;AAAA;AAAA;AAG7B,KAAG,cAAc,kBAAkB,oBAAoB;AAE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,YAAQ,MAAM;AACd,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AACD,UAAQ,GAAG,WAAW,MAAM;AAC1B,YAAQ,IAAI,yDAAyD;AACrE,YAAQ,MAAM;AACd,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AACH;AAEA,eAAe,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;AAC7B,YAAM,eAAe,QAAQ;AAAA,IAC/B,OAAO;AACL,cAAQ;AAAA,QACN;AAAA,MACF;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF,SAAS,KAAK;AACZ,YAAQ,MAAM,4BAA4B,GAAG;AAC7C,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;AAEA,KAAK,EAAE,MAAM,CAAC,QAAQ;AACpB,UAAQ,MAAM,4CAA4C,GAAG;AAC7D,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
1
+ {"version":3,"sources":["../cli.ts","../commands/utils/detect-package.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport 'tsx';\nimport 'tsconfig-paths/register.js';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport chokidar from 'chokidar';\nimport { detectCombinedPackage } from './commands/utils/detect-package';\n\nfunction kebabToCamel(str: string): string {\n return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());\n}\n\nfunction kebabToPascal(kebab: string): string {\n return kebab\n .split('-')\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\n .join('');\n}\n\nasync function generateConfigFile(\n configDir: string,\n monoriseOutputDir: string,\n 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 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 const projectRoot = rootPath ? path.resolve(rootPath) : process.cwd();\n console.log(MONORISE_LOGO);\n console.log(`Initializing Monorise project in ${projectRoot}...`);\n\n // 1. Create monorise.config.ts\n const monoriseConfigTsPath = path.join(projectRoot, 'monorise.config.ts');\n const monoriseConfigContent = `\nconst config = {\n configDir: './monorise/entities',\n // custom route file should export default an Hono object.\n // customRoutes: './path/to/custom/routes.ts'\n};\n\nexport default config;\n`;\n if (!fs.existsSync(monoriseConfigTsPath)) {\n fs.writeFileSync(monoriseConfigTsPath, monoriseConfigContent.trimStart());\n console.log(`Created ${path.relative(projectRoot, monoriseConfigTsPath)}`);\n } else {\n console.log(\n `${path.relative(projectRoot, monoriseConfigTsPath)} already exists. Skipping.`,\n );\n }\n\n // 2. Create ./monorise/entities/user.ts\n const monoriseEntitiesDir = path.join(projectRoot, 'monorise', 'entities');\n fs.mkdirSync(monoriseEntitiesDir, { recursive: true });\n\n const userEntityTsPath = path.join(monoriseEntitiesDir, 'user.ts');\n const userEntityContent = `\nimport { createEntityConfig } from 'monorise/base';\nimport { z } from 'zod';\n\nconst baseSchema = z\n .object({\n displayName: z\n .string()\n .min(1, 'Please provide a name for this user account'),\n firstName: z.string().min(1, 'Please provide first name'),\n lastName: z.string().min(1, 'Please provide last name'),\n jobTitle: z.string(),\n })\n .partial();\n\nconst config = createEntityConfig({\n name: 'user',\n baseSchema,\n});\n\nexport default config;\n`;\n if (!fs.existsSync(userEntityTsPath)) {\n fs.writeFileSync(userEntityTsPath, userEntityContent.trimStart());\n console.log(`Created ${path.relative(projectRoot, userEntityTsPath)}`);\n } else {\n console.log(\n `${path.relative(projectRoot, userEntityTsPath)} already exists. Skipping.`,\n );\n }\n\n // 3. Update package.json\n const packageJsonPath = path.join(projectRoot, 'package.json');\n if (fs.existsSync(packageJsonPath)) {\n try {\n const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8');\n const packageJson = JSON.parse(packageJsonContent);\n\n if (packageJson.type !== 'module') {\n packageJson.type = 'module';\n fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));\n console.log(\n `Updated 'type' to 'module' in ${path.relative(projectRoot, packageJsonPath)}`,\n );\n } else {\n console.log(\n `'type: \"module\"' already set in ${path.relative(projectRoot, packageJsonPath)}. Skipping.`,\n );\n }\n } catch (error) {\n console.error(\n `Error reading or parsing ${path.relative(projectRoot, packageJsonPath)}:`,\n error,\n );\n }\n } else {\n console.warn(\n `Warning: ${path.relative(projectRoot, packageJsonPath)} not found. Cannot update 'type'.`,\n );\n }\n\n // 4. Add tsconfig path alias for .monorise directory\n const tsconfigPath = path.join(projectRoot, 'tsconfig.json');\n if (fs.existsSync(tsconfigPath)) {\n try {\n const tsconfigContent = fs.readFileSync(tsconfigPath, 'utf8');\n const tsconfig = JSON.parse(tsconfigContent);\n\n if (!tsconfig.compilerOptions) {\n tsconfig.compilerOptions = {};\n }\n if (!tsconfig.compilerOptions.paths) {\n tsconfig.compilerOptions.paths = {};\n }\n\n const pathKey = '#/monorise/*';\n const pathValue = ['./.monorise/*'];\n\n if (!tsconfig.compilerOptions.paths[pathKey]) {\n tsconfig.compilerOptions.paths[pathKey] = pathValue;\n fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2));\n console.log(\n `Added '${pathKey}' path alias in ${path.relative(projectRoot, tsconfigPath)}`,\n );\n } else {\n console.log(\n `'${pathKey}' path alias already set in ${path.relative(projectRoot, tsconfigPath)}. Skipping.`,\n );\n }\n } catch (error) {\n console.error(\n `Error updating ${path.relative(projectRoot, tsconfigPath)}:`,\n error,\n );\n }\n } else {\n console.warn(\n `Warning: ${path.relative(projectRoot, tsconfigPath)} not found. Cannot add path alias.`,\n );\n }\n\n console.log('Monorise initialization complete!');\n}\n\nasync function runDevCommand(configDir: string, rootPath?: string) {\n console.log(MONORISE_LOGO);\n console.log(`Watching for changes in ${configDir}...`);\n const watcher = chokidar.watch(configDir, {\n ignored: (watchedPath: string) => {\n const fileName = path.basename(watchedPath);\n return (\n fileName === 'index.ts' || // Old name, still ignore in case it exists\n fileName === 'config.ts' || // Generated config file\n fileName === 'processors.ts' || // Generated processors file\n fileName === 'app.ts' || // Generated app file\n fileName.startsWith('.') ||\n watchedPath.endsWith('.js') ||\n watchedPath.endsWith('.jsx') ||\n watchedPath.endsWith('.d.ts')\n );\n },\n persistent: true,\n ignoreInitial: true,\n });\n\n watcher.on('add', async (filePath) => {\n console.log(`File ${filePath} has been added. Regenerating...`);\n try {\n await generateFiles(rootPath);\n } catch (err) {\n console.error('Regeneration failed:', err);\n }\n });\n\n watcher.on('change', async (filePath) => {\n console.log(`File ${filePath} has been changed. Regenerating...`);\n try {\n await generateFiles(rootPath);\n } catch (err) {\n console.error('Regeneration failed:', err);\n }\n });\n\n watcher.on('unlink', async (filePath) => {\n console.log(`File ${filePath} has been removed. Regenerating...`);\n try {\n await generateFiles(rootPath);\n } catch (err) {\n console.error('Regeneration failed:', err);\n }\n });\n\n process.on('SIGINT', () => {\n console.log('Monorise dev terminated. Closing watcher and sst dev...');\n watcher.close();\n process.exit(0);\n });\n process.on('SIGTERM', () => {\n console.log('Monorise dev terminated. Closing watcher and sst dev...');\n watcher.close();\n process.exit(0);\n });\n}\n\nasync function runBuildCommand(rootPath?: string) {\n console.log('Starting sst build...');\n await generateFiles(rootPath);\n}\n\nasync function main() {\n const args = process.argv.slice(2);\n const command = args[0];\n\n let rootPath: string | undefined;\n const rootFlagIndex = args.indexOf('--config-root');\n if (rootFlagIndex > -1 && args[rootFlagIndex + 1]) {\n rootPath = args[rootFlagIndex + 1];\n }\n\n try {\n if (command === 'dev') {\n const configDir = await generateFiles(rootPath);\n await runDevCommand(configDir, rootPath);\n } else if (command === 'build') {\n await runBuildCommand(rootPath);\n } else if (command === 'init') {\n await runInitCommand(rootPath);\n } else {\n console.error(\n 'Unknown command. Usage: monorise [dev|build|init] [--config-root <path>]',\n );\n process.exit(1);\n }\n } catch (err) {\n console.error('Monorise process failed:', err);\n process.exit(1);\n }\n}\n\nmain().catch((err) => {\n console.error('Monorise encountered an unhandled error:', err);\n process.exit(1);\n});\n","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"],"mappings":";;;AAEA,OAAO;AACP,OAAO;AACP,OAAOA,SAAQ;AACf,OAAOC,WAAU;AACjB,OAAO,cAAc;;;ACNrB,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;;;ADVA,SAAS,aAAa,KAAqB;AACzC,SAAO,IAAI,QAAQ,aAAa,CAAC,GAAG,WAAW,OAAO,YAAY,CA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