monorise 1.4.0 → 1.6.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 (71) hide show
  1. package/dist/base/index.d.ts +95 -1
  2. package/dist/base/index.js.map +1 -1
  3. package/dist/cli/cli.js +2 -2
  4. package/dist/core/index.d.ts +96 -30
  5. package/dist/core/index.js +785 -27
  6. package/dist/core/index.js.map +1 -1
  7. package/dist/react/chunk-5XIRNUBL.js +43 -0
  8. package/dist/react/chunk-5XIRNUBL.js.map +1 -0
  9. package/dist/react/chunk-7JDOKZGQ.js +172 -0
  10. package/dist/react/chunk-7JDOKZGQ.js.map +1 -0
  11. package/dist/react/chunk-A5TI2FW3.js +13 -0
  12. package/dist/react/chunk-A5TI2FW3.js.map +1 -0
  13. package/dist/react/chunk-AYQDOLYF.js +628 -0
  14. package/dist/react/chunk-AYQDOLYF.js.map +1 -0
  15. package/dist/react/chunk-BUTF5RJU.js +29 -0
  16. package/dist/react/chunk-BUTF5RJU.js.map +1 -0
  17. package/dist/react/chunk-EYG2DL3D.js +893 -0
  18. package/dist/react/chunk-EYG2DL3D.js.map +1 -0
  19. package/dist/react/chunk-GEN4TSCQ.js +5179 -0
  20. package/dist/react/chunk-GEN4TSCQ.js.map +1 -0
  21. package/dist/react/chunk-GFVCNWVT.js +54 -0
  22. package/dist/react/chunk-GFVCNWVT.js.map +1 -0
  23. package/dist/react/chunk-KJX5LOMN.js +43 -0
  24. package/dist/react/chunk-KJX5LOMN.js.map +1 -0
  25. package/dist/react/chunk-KLXK4V6G.js +65 -0
  26. package/dist/react/chunk-KLXK4V6G.js.map +1 -0
  27. package/dist/react/chunk-L6MAS3AX.js +482 -0
  28. package/dist/react/chunk-L6MAS3AX.js.map +1 -0
  29. package/dist/react/chunk-LPXR5V4J.js +582 -0
  30. package/dist/react/chunk-LPXR5V4J.js.map +1 -0
  31. package/dist/react/chunk-MIXAYX55.js +147 -0
  32. package/dist/react/chunk-MIXAYX55.js.map +1 -0
  33. package/dist/react/chunk-OEHQ546W.js +182 -0
  34. package/dist/react/chunk-OEHQ546W.js.map +1 -0
  35. package/dist/react/chunk-RPNCWADG.js +248 -0
  36. package/dist/react/chunk-RPNCWADG.js.map +1 -0
  37. package/dist/react/chunk-S6RDMHHH.js +47 -0
  38. package/dist/react/chunk-S6RDMHHH.js.map +1 -0
  39. package/dist/react/chunk-VVCM7N22.js +101 -0
  40. package/dist/react/chunk-VVCM7N22.js.map +1 -0
  41. package/dist/react/dist-es-5WYA7CWK.js +379 -0
  42. package/dist/react/dist-es-5WYA7CWK.js.map +1 -0
  43. package/dist/react/dist-es-DLWQXBOR.js +333 -0
  44. package/dist/react/dist-es-DLWQXBOR.js.map +1 -0
  45. package/dist/react/dist-es-EMJCB37T.js +71 -0
  46. package/dist/react/dist-es-EMJCB37T.js.map +1 -0
  47. package/dist/react/dist-es-Q7IAXWRB.js +494 -0
  48. package/dist/react/dist-es-Q7IAXWRB.js.map +1 -0
  49. package/dist/react/dist-es-QF65HH5Y.js +169 -0
  50. package/dist/react/dist-es-QF65HH5Y.js.map +1 -0
  51. package/dist/react/dist-es-R4TRTT45.js +22 -0
  52. package/dist/react/dist-es-R4TRTT45.js.map +1 -0
  53. package/dist/react/dist-es-XNAC47MK.js +90 -0
  54. package/dist/react/dist-es-XNAC47MK.js.map +1 -0
  55. package/dist/react/event-streams-6APKUBMC.js +270 -0
  56. package/dist/react/event-streams-6APKUBMC.js.map +1 -0
  57. package/dist/react/index.d.ts +23 -2
  58. package/dist/react/index.d.ts.map +1 -1
  59. package/dist/react/index.js +8724 -160
  60. package/dist/react/index.js.map +1 -1
  61. package/dist/react/loadSso-WMS367NT.js +595 -0
  62. package/dist/react/loadSso-WMS367NT.js.map +1 -0
  63. package/dist/react/services/core.service.d.ts +11 -1
  64. package/dist/react/services/core.service.d.ts.map +1 -1
  65. package/dist/react/signin-2I7AG6XI.js +707 -0
  66. package/dist/react/signin-2I7AG6XI.js.map +1 -0
  67. package/dist/react/sso-oidc-OAJ7SALL.js +825 -0
  68. package/dist/react/sso-oidc-OAJ7SALL.js.map +1 -0
  69. package/dist/react/sts-LKM23TRV.js +3866 -0
  70. package/dist/react/sts-LKM23TRV.js.map +1 -0
  71. package/package.json +1 -1
@@ -1,5 +1,29 @@
1
1
  import { z } from 'zod';
2
2
 
3
+ type WhereOperator = {
4
+ $eq: string | number | boolean;
5
+ } | {
6
+ $ne: string | number | boolean;
7
+ } | {
8
+ $gt: number;
9
+ } | {
10
+ $lt: number;
11
+ } | {
12
+ $gte: number;
13
+ } | {
14
+ $lte: number;
15
+ } | {
16
+ $exists: boolean;
17
+ } | {
18
+ $beginsWith: string;
19
+ };
20
+ type WhereClause = WhereOperator | string | number | boolean;
21
+ type WhereConditions = Record<string, WhereClause>;
22
+ type AdjustmentConditionFn<B extends z.ZodRawShape = z.ZodRawShape> = (data: Partial<z.infer<z.ZodObject<B>>>, adjustments: Record<string, number>) => WhereConditions;
23
+ type AdjustmentCondition<B extends z.ZodRawShape = z.ZodRawShape> = WhereConditions | AdjustmentConditionFn<B>;
24
+ type UpdateConditionFn<B extends z.ZodRawShape = z.ZodRawShape> = (data: Partial<z.infer<z.ZodObject<B>>>) => WhereConditions;
25
+ type UpdateCondition<B extends z.ZodRawShape = z.ZodRawShape> = WhereConditions | UpdateConditionFn<B>;
26
+
3
27
  declare enum Entity {
4
28
  }
5
29
  interface EntitySchemaMap {
@@ -284,6 +308,8 @@ interface MonoriseEntityConfig<T extends Entity = Entity, B extends z.ZodRawShap
284
308
  * When adjusting numeric fields, these constraints are enforced at the database level.
285
309
  * If an adjustment would violate a constraint, the operation is rejected.
286
310
  *
311
+ * @deprecated Use `conditions` instead. Will be removed in a future version.
312
+ *
287
313
  * @example
288
314
  * ```ts
289
315
  * {
@@ -319,6 +345,67 @@ interface MonoriseEntityConfig<T extends Entity = Entity, B extends z.ZodRawShap
319
345
  };
320
346
  };
321
347
  };
348
+ /**
349
+ * @description Named conditions for adjustEntity operations.
350
+ * Each condition is either a static `WhereConditions` object or a function
351
+ * `(data, adjustments) => WhereConditions` that receives the entity's current data
352
+ * and the adjustment deltas.
353
+ *
354
+ * When defined, `$condition` is **required** in the adjustEntity request body.
355
+ * The client sends a condition name (string), the server resolves it to a
356
+ * DynamoDB ConditionExpression.
357
+ *
358
+ * @example
359
+ * ```ts
360
+ * {
361
+ * adjustmentConditions: {
362
+ * withdraw: (data, adjustments) => ({
363
+ * balance: { $gte: (data.minBalance ?? 0) + Math.abs(adjustments?.balance ?? 0) },
364
+ * }),
365
+ * deposit: (data, adjustments) => ({
366
+ * balance: { $lte: 1000000 - (adjustments.balance ?? 0) },
367
+ * }),
368
+ * }
369
+ * }
370
+ * ```
371
+ */
372
+ adjustmentConditions?: {
373
+ [conditionName: string]: WhereConditions | ((data: Partial<z.infer<z.ZodObject<B>>>, adjustments: Record<string, number>) => WhereConditions);
374
+ };
375
+ /**
376
+ * @description Named conditions for updateEntity operations.
377
+ * Each condition is either a static `WhereConditions` object or a function
378
+ * `(data) => WhereConditions` that receives the entity's current data.
379
+ *
380
+ * `$condition` is always **optional** for updateEntity.
381
+ * The client sends a condition name (string), the server resolves it to a
382
+ * DynamoDB ConditionExpression. Replaces raw `$where` (deprecated).
383
+ *
384
+ * @example
385
+ * ```ts
386
+ * {
387
+ * updateConditions: {
388
+ * publish: { status: { $eq: 'draft' } },
389
+ * archive: (data) => ({ status: { $ne: 'archived' } }),
390
+ * }
391
+ * }
392
+ * ```
393
+ */
394
+ updateConditions?: {
395
+ [conditionName: string]: WhereConditions | ((data: Partial<z.infer<z.ZodObject<B>>>) => WhereConditions);
396
+ };
397
+ /**
398
+ * @description (Optional) Opt in to accepting legacy raw `$where` on updateEntity.
399
+ * Disabled by default: raw DynamoDB condition operators must never be
400
+ * client-facing — an authenticated client could otherwise probe field
401
+ * existence or guess values via the 200-vs-409 response status.
402
+ *
403
+ * Only enable this if you trust the caller (e.g. server-to-server) or have
404
+ * your own validation in front of it. Prefer `updateConditions` instead.
405
+ *
406
+ * @default false
407
+ */
408
+ allowLegacyWhere?: boolean;
322
409
  }
323
410
 
324
411
  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>) => {
@@ -388,7 +475,14 @@ declare const createEntityConfig: <T extends Entity, B extends z.ZodRawShape, C
388
475
  maxField?: (keyof { [K_2 in keyof B as B[K_2] extends z.ZodNumber | z.ZodOptional<z.ZodNumber> ? K_2 : never]: K_2; } extends never ? string : keyof { [K_3 in keyof B as B[K_3] extends z.ZodNumber | z.ZodOptional<z.ZodNumber> ? K_3 : never]: K_3; }) | undefined;
389
476
  };
390
477
  } | undefined;
478
+ adjustmentConditions?: {
479
+ [conditionName: string]: undefined | ((data: Partial<z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_27 ? { [k_4 in keyof T_27]: T_27[k_4]; } : never>, adjustments: Record<string, number>) => undefined);
480
+ } | undefined;
481
+ updateConditions?: {
482
+ [conditionName: string]: undefined | ((data: Partial<z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_27 ? { [k_4 in keyof T_27]: T_27[k_4]; } : never>) => undefined);
483
+ } | undefined;
484
+ allowLegacyWhere?: boolean;
391
485
  };
392
486
  declare const createMutualConfig: <MD extends z.ZodRawShape>(config: MutualConfig<MD>) => MutualConfig<MD>;
393
487
 
394
- export { type CreatedEntity, type DraftEntity, Entity, type EntitySchemaMap, type MonoriseEntityConfig, type MutualConfig, type NumericFields, createEntityConfig, createMutualConfig };
488
+ export { type AdjustmentCondition, type AdjustmentConditionFn, type CreatedEntity, type DraftEntity, Entity, type EntitySchemaMap, type MonoriseEntityConfig, type MutualConfig, type NumericFields, type UpdateCondition, type UpdateConditionFn, type WhereClause, type WhereConditions, type WhereOperator, createEntityConfig, createMutualConfig };
@@ -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\n/**\n * @description Configuration for a mutual relationship between two entities.\n * Defines the schema for mutualData validation. Define once, reference from both entity configs.\n *\n * @example\n * ```ts\n * const enrollmentMutual = createMutualConfig({\n * entities: [Entity.STUDENT, Entity.COURSE],\n * mutualDataSchema: z.object({\n * role: z.enum(['student', 'auditor']),\n * enrolledAt: z.string().datetime(),\n * }),\n * });\n * ```\n */\nexport interface MutualConfig<\n MD extends z.ZodRawShape = z.ZodRawShape,\n> {\n entities: [Entity, Entity];\n mutualDataSchema: z.ZodObject<MD>;\n}\n\nexport type DraftEntity<T extends Entity = Entity> =\n T extends keyof EntitySchemaMap ? EntitySchemaMap[T] : never;\n\nexport type NumericFields<T> = {\n [K in keyof T as T[K] extends number ? K : never]?: number;\n};\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 * @description (Optional) Reference to a mutual config created by `createMutualConfig`.\n * Provides mutualData schema validation for create/update operations on this mutual relationship.\n */\n mutual?: MutualConfig;\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 /**\n * @description (Optional) Configure a DynamoDB TTL for this entity. When set, `expiresAt`\n * is computed via `processor` on create, and recomputed on every update/upsert. Once past,\n * DynamoDB automatically deletes the item (and its derived index rows, since they all carry\n * the same `expiresAt`).\n *\n * `processor` returning `undefined` means \"no TTL\" for that record. On updates, an `undefined`\n * result leaves any existing `expiresAt` untouched rather than clearing it.\n *\n * @example\n * ```ts\n * // fixed 30-day TTL from creation/each update\n * ttl: {\n * processor: () => Math.floor(Date.now() / 1000) + 30 * 24 * 60 * 60,\n * }\n * ```\n *\n * @example\n * ```ts\n * // data-driven TTL, eg. expire when a subscription ends\n * ttl: {\n * processor: (entity) => {\n * return entity.data.subscriptionEndsAt\n * ? new Date(entity.data.subscriptionEndsAt)\n * : undefined;\n * },\n * }\n * ```\n */\n ttl?: {\n /**\n * @description Returns the expiry as epoch seconds (absolute) or a `Date`.\n * Return `undefined` for no expiry.\n */\n processor: (entity: {\n entityId: string;\n entityType: string;\n data: Record<string, any>;\n createdAt: string;\n updatedAt: string;\n }) => number | Date | undefined;\n };\n\n /**\n * @description (Optional) Constraints for `adjustEntity` operations.\n * When adjusting numeric fields, these constraints are enforced at the database level.\n * If an adjustment would violate a constraint, the operation is rejected.\n *\n * @example\n * ```ts\n * {\n * adjustmentConstraints: {\n * // Static: same for all entities of this type\n * balance: { min: 0 },\n * credits: { min: 0, max: 10000 },\n *\n * // Dynamic: reads constraint value from entity's own data\n * balance: { minField: 'minBalance' },\n * credits: { min: 0, maxField: 'creditLimit' },\n * }\n * }\n * ```\n */\n adjustmentConstraints?: {\n [fieldName: string]: {\n /** Static minimum value */\n min?: number;\n /** Static maximum value */\n max?: number;\n /** Field name on the entity whose value is used as the minimum (must be a numeric field) */\n minField?: keyof {\n [K in keyof B as B[K] extends z.ZodNumber | z.ZodOptional<z.ZodNumber> ? K : never]: K;\n } extends never ? string : keyof {\n [K in keyof B as B[K] extends z.ZodNumber | z.ZodOptional<z.ZodNumber> ? K : never]: K;\n };\n /** Field name on the entity whose value is used as the maximum (must be a numeric field) */\n maxField?: keyof {\n [K in keyof B as B[K] extends z.ZodNumber | z.ZodOptional<z.ZodNumber> ? K : never]: K;\n } extends never ? string : keyof {\n [K in keyof B as B[K] extends z.ZodNumber | z.ZodOptional<z.ZodNumber> ? K : never]: K;\n };\n };\n };\n}\n","import type { Entity, MonoriseEntityConfig, MutualConfig } 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\nconst createMutualConfig = <MD extends z.ZodRawShape>(\n config: MutualConfig<MD>,\n) => config;\n\nexport { createEntityConfig, createMutualConfig };\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;AAEA,IAAM,qBAAqB,CACzB,WACG;","names":["Entity"]}
1
+ {"version":3,"sources":["../types/monorise.type.ts","../utils/index.ts"],"sourcesContent":["import type { z } from 'zod';\nimport type { WhereConditions } from './conditions.type';\n\nexport enum Entity {}\n\nexport interface EntitySchemaMap {\n [key: string]: Record<string, any>;\n}\n\n/**\n * @description Configuration for a mutual relationship between two entities.\n * Defines the schema for mutualData validation. Define once, reference from both entity configs.\n *\n * @example\n * ```ts\n * const enrollmentMutual = createMutualConfig({\n * entities: [Entity.STUDENT, Entity.COURSE],\n * mutualDataSchema: z.object({\n * role: z.enum(['student', 'auditor']),\n * enrolledAt: z.string().datetime(),\n * }),\n * });\n * ```\n */\nexport interface MutualConfig<\n MD extends z.ZodRawShape = z.ZodRawShape,\n> {\n entities: [Entity, Entity];\n mutualDataSchema: z.ZodObject<MD>;\n}\n\nexport type DraftEntity<T extends Entity = Entity> =\n T extends keyof EntitySchemaMap ? EntitySchemaMap[T] : never;\n\nexport type NumericFields<T> = {\n [K in keyof T as T[K] extends number ? K : never]?: number;\n};\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 * @description (Optional) Reference to a mutual config created by `createMutualConfig`.\n * Provides mutualData schema validation for create/update operations on this mutual relationship.\n */\n mutual?: MutualConfig;\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 /**\n * @description (Optional) Configure a DynamoDB TTL for this entity. When set, `expiresAt`\n * is computed via `processor` on create, and recomputed on every update/upsert. Once past,\n * DynamoDB automatically deletes the item (and its derived index rows, since they all carry\n * the same `expiresAt`).\n *\n * `processor` returning `undefined` means \"no TTL\" for that record. On updates, an `undefined`\n * result leaves any existing `expiresAt` untouched rather than clearing it.\n *\n * @example\n * ```ts\n * // fixed 30-day TTL from creation/each update\n * ttl: {\n * processor: () => Math.floor(Date.now() / 1000) + 30 * 24 * 60 * 60,\n * }\n * ```\n *\n * @example\n * ```ts\n * // data-driven TTL, eg. expire when a subscription ends\n * ttl: {\n * processor: (entity) => {\n * return entity.data.subscriptionEndsAt\n * ? new Date(entity.data.subscriptionEndsAt)\n * : undefined;\n * },\n * }\n * ```\n */\n ttl?: {\n /**\n * @description Returns the expiry as epoch seconds (absolute) or a `Date`.\n * Return `undefined` for no expiry.\n */\n processor: (entity: {\n entityId: string;\n entityType: string;\n data: Record<string, any>;\n createdAt: string;\n updatedAt: string;\n }) => number | Date | undefined;\n };\n\n /**\n * @description (Optional) Constraints for `adjustEntity` operations.\n * When adjusting numeric fields, these constraints are enforced at the database level.\n * If an adjustment would violate a constraint, the operation is rejected.\n *\n * @deprecated Use `conditions` instead. Will be removed in a future version.\n *\n * @example\n * ```ts\n * {\n * adjustmentConstraints: {\n * // Static: same for all entities of this type\n * balance: { min: 0 },\n * credits: { min: 0, max: 10000 },\n *\n * // Dynamic: reads constraint value from entity's own data\n * balance: { minField: 'minBalance' },\n * credits: { min: 0, maxField: 'creditLimit' },\n * }\n * }\n * ```\n */\n adjustmentConstraints?: {\n [fieldName: string]: {\n /** Static minimum value */\n min?: number;\n /** Static maximum value */\n max?: number;\n /** Field name on the entity whose value is used as the minimum (must be a numeric field) */\n minField?: keyof {\n [K in keyof B as B[K] extends z.ZodNumber | z.ZodOptional<z.ZodNumber> ? K : never]: K;\n } extends never ? string : keyof {\n [K in keyof B as B[K] extends z.ZodNumber | z.ZodOptional<z.ZodNumber> ? K : never]: K;\n };\n /** Field name on the entity whose value is used as the maximum (must be a numeric field) */\n maxField?: keyof {\n [K in keyof B as B[K] extends z.ZodNumber | z.ZodOptional<z.ZodNumber> ? K : never]: K;\n } extends never ? string : keyof {\n [K in keyof B as B[K] extends z.ZodNumber | z.ZodOptional<z.ZodNumber> ? K : never]: K;\n };\n };\n };\n\n /**\n * @description Named conditions for adjustEntity operations.\n * Each condition is either a static `WhereConditions` object or a function\n * `(data, adjustments) => WhereConditions` that receives the entity's current data\n * and the adjustment deltas.\n *\n * When defined, `$condition` is **required** in the adjustEntity request body.\n * The client sends a condition name (string), the server resolves it to a\n * DynamoDB ConditionExpression.\n *\n * @example\n * ```ts\n * {\n * adjustmentConditions: {\n * withdraw: (data, adjustments) => ({\n * balance: { $gte: (data.minBalance ?? 0) + Math.abs(adjustments?.balance ?? 0) },\n * }),\n * deposit: (data, adjustments) => ({\n * balance: { $lte: 1000000 - (adjustments.balance ?? 0) },\n * }),\n * }\n * }\n * ```\n */\n adjustmentConditions?: {\n [conditionName: string]:\n | WhereConditions\n | ((\n data: Partial<z.infer<z.ZodObject<B>>>,\n adjustments: Record<string, number>,\n ) => WhereConditions);\n };\n\n /**\n * @description Named conditions for updateEntity operations.\n * Each condition is either a static `WhereConditions` object or a function\n * `(data) => WhereConditions` that receives the entity's current data.\n *\n * `$condition` is always **optional** for updateEntity.\n * The client sends a condition name (string), the server resolves it to a\n * DynamoDB ConditionExpression. Replaces raw `$where` (deprecated).\n *\n * @example\n * ```ts\n * {\n * updateConditions: {\n * publish: { status: { $eq: 'draft' } },\n * archive: (data) => ({ status: { $ne: 'archived' } }),\n * }\n * }\n * ```\n */\n updateConditions?: {\n [conditionName: string]:\n | WhereConditions\n | ((data: Partial<z.infer<z.ZodObject<B>>>) => WhereConditions);\n };\n\n /**\n * @description (Optional) Opt in to accepting legacy raw `$where` on updateEntity.\n * Disabled by default: raw DynamoDB condition operators must never be\n * client-facing — an authenticated client could otherwise probe field\n * existence or guess values via the 200-vs-409 response status.\n *\n * Only enable this if you trust the caller (e.g. server-to-server) or have\n * your own validation in front of it. Prefer `updateConditions` instead.\n *\n * @default false\n */\n allowLegacyWhere?: boolean;\n}\n","import type { Entity, MonoriseEntityConfig, MutualConfig } 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\nconst createMutualConfig = <MD extends z.ZodRawShape>(\n config: MutualConfig<MD>,\n) => config;\n\nexport { createEntityConfig, createMutualConfig };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAGO,IAAK,SAAL,kBAAKA,YAAL;AAAK,SAAAA;AAAA,GAAA;;;ACFZ,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;AAEA,IAAM,qBAAqB,CACzB,WACG;","names":["Entity"]}
package/dist/cli/cli.js CHANGED
@@ -128,7 +128,7 @@ declare module '${moduleName}' {
128
128
  ${schemaMapEntries.join("\n ")}
129
129
  }
130
130
  }`;
131
- const moduleAugmentations = usesCombinedPackage ? augmentationBlock("monorise/base") : augmentationBlock("@monorise/base");
131
+ const moduleAugmentations = usesCombinedPackage ? augmentationBlock("monorise/base") : augmentationBlock("../base/index.js");
132
132
  const configOutputContent = `
133
133
  import type { z } from 'zod';
134
134
  ${imports.join("\n")}
@@ -227,7 +227,7 @@ async function generateHandleFile(monoriseConfig, projectRoot, monoriseOutputDir
227
227
  appHandlerPayload = "{ routes }";
228
228
  }
229
229
  const usesCombinedPackage = detectCombinedPackage(projectRoot);
230
- const coreImportPath = usesCombinedPackage ? "monorise/core" : "@monorise/core";
230
+ const coreImportPath = usesCombinedPackage ? "monorise/core" : "../core/index.js";
231
231
  const combinedContent = `
232
232
  import CoreFactory from '${coreImportPath}';
233
233
  import config from './config';
@@ -1,4 +1,4 @@
1
- import { Entity as Entity$2, EntitySchemaMap, createEntityConfig } from '../base/index';
1
+ import { Entity as Entity$2, EntitySchemaMap, createEntityConfig, WhereConditions } from '../base/index';
2
2
  import * as hono from 'hono';
3
3
  import { Hono } from 'hono';
4
4
  import { DynamoDB, TransactWriteItemsInput, AttributeValue, TransactWriteItem, UpdateItemCommandInput } from '@aws-sdk/client-dynamodb';
@@ -90,7 +90,7 @@ declare class Entity$1<T extends Entity$2> extends Item$1 {
90
90
  }
91
91
  declare class EntityRepository extends Repository {
92
92
  private EntityConfig;
93
- private readonly TABLE_NAME;
93
+ readonly TABLE_NAME: string;
94
94
  private readonly dynamodbClient;
95
95
  private readonly EmailAuthEnabledEntities;
96
96
  constructor(EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>, TABLE_NAME: string, dynamodbClient: DynamoDB, EmailAuthEnabledEntities: Entity$2[]);
@@ -141,11 +141,10 @@ declare class EntityRepository extends Repository {
141
141
  ExpressionAttributeNames?: Record<string, string>;
142
142
  ExpressionAttributeValues?: Record<string, AttributeValue>;
143
143
  }): Promise<Entity$1<T>>;
144
- adjustEntity<T extends Entity$2>(entityType: T, entityId: string, adjustments: Record<string, number>, constraints?: {
145
- [field: string]: {
146
- min?: number;
147
- max?: number;
148
- };
144
+ adjustEntity<T extends Entity$2>(entityType: T, entityId: string, adjustments: Record<string, number>, opts?: {
145
+ ConditionExpression?: string;
146
+ ExpressionAttributeNames?: Record<string, string>;
147
+ ExpressionAttributeValues?: Record<string, AttributeValue>;
149
148
  }): Promise<Entity$1<T>>;
150
149
  deleteEntity<T extends Entity$2>(entityType: T, entityId: string): Promise<void>;
151
150
  queryEntities<T extends Entity$2>(entityType: T, query: string): Promise<{
@@ -4462,26 +4461,6 @@ external_exports.object({
4462
4461
  lastKey: external_exports.string().optional()
4463
4462
  });
4464
4463
 
4465
- type WhereOperator = {
4466
- $eq: string | number | boolean;
4467
- } | {
4468
- $ne: string | number | boolean;
4469
- } | {
4470
- $gt: number;
4471
- } | {
4472
- $lt: number;
4473
- } | {
4474
- $gte: number;
4475
- } | {
4476
- $lte: number;
4477
- } | {
4478
- $exists: boolean;
4479
- } | {
4480
- $beginsWith: string;
4481
- };
4482
- type WhereClause = WhereOperator | string | number | boolean;
4483
- type WhereConditions = Record<string, WhereClause>;
4484
-
4485
4464
  declare class EntityServiceLifeCycle {
4486
4465
  private EntityConfig;
4487
4466
  private publishEvent;
@@ -4507,19 +4486,24 @@ declare class EntityService {
4507
4486
  mutualId?: string;
4508
4487
  };
4509
4488
  }) => Promise<Entity<T>>;
4510
- adjustEntity: <T extends Entity$2>({ entityType, entityId, adjustments, accountId, }: {
4489
+ adjustEntity: <T extends Entity$2>({ entityType, entityId, adjustments, accountId, condition, }: {
4511
4490
  entityType: T;
4512
4491
  entityId: string;
4513
4492
  adjustments: Record<string, number>;
4514
4493
  accountId?: string;
4494
+ condition?: string;
4515
4495
  }) => Promise<Entity<T>>;
4516
- updateEntity: <T extends Entity$2>({ entityType, entityId, entityPayload, accountId, where, }: {
4496
+ updateEntity: <T extends Entity$2>({ entityType, entityId, entityPayload, accountId, condition, where, }: {
4517
4497
  entityType: T;
4518
4498
  entityId: string;
4519
4499
  entityPayload: Partial<EntitySchemaMap[T]>;
4520
4500
  accountId?: string | string[];
4501
+ condition?: string;
4502
+ /** @deprecated Use `condition` (named condition) instead of raw `where`. */
4521
4503
  where?: WhereConditions;
4522
4504
  }) => Promise<Entity<T>>;
4505
+ /** @deprecated Converts legacy adjustmentConstraints to condition expression opts. */
4506
+ private buildLegacyAdjustCondition;
4523
4507
  deleteEntity: <T extends Entity$2>({ entityType, entityId, accountId, }: {
4524
4508
  entityType: T;
4525
4509
  entityId: string;
@@ -4715,6 +4699,67 @@ declare class ListTagsController {
4715
4699
  }, hono_utils_http_status.ContentfulStatusCode, "json">>;
4716
4700
  }
4717
4701
 
4702
+ type TransactionCreateEntity<T extends Entity$2 = Entity$2> = {
4703
+ operation: 'createEntity';
4704
+ entityType: T;
4705
+ entityId?: string;
4706
+ payload: EntitySchemaMap[T];
4707
+ };
4708
+ type TransactionUpdateEntity<T extends Entity$2 = Entity$2> = {
4709
+ operation: 'updateEntity';
4710
+ entityType: T;
4711
+ entityId: string;
4712
+ payload: Partial<EntitySchemaMap[T]>;
4713
+ condition?: string;
4714
+ };
4715
+ type TransactionAdjustEntity<T extends Entity$2 = Entity$2> = {
4716
+ operation: 'adjustEntity';
4717
+ entityType: T;
4718
+ entityId: string;
4719
+ adjustments: Record<string, number>;
4720
+ condition?: string;
4721
+ };
4722
+ type TransactionDeleteEntity<T extends Entity$2 = Entity$2> = {
4723
+ operation: 'deleteEntity';
4724
+ entityType: T;
4725
+ entityId: string;
4726
+ };
4727
+ type TransactionOperation = TransactionCreateEntity | TransactionUpdateEntity | TransactionAdjustEntity | TransactionDeleteEntity;
4728
+ type TransactionResultEntry = {
4729
+ operation: string;
4730
+ entityType: Entity$2;
4731
+ entityId: string;
4732
+ data?: Record<string, unknown>;
4733
+ };
4734
+ type TransactionResult = {
4735
+ results: TransactionResultEntry[];
4736
+ };
4737
+
4738
+ declare class TransactionService {
4739
+ private EntityConfig;
4740
+ private EmailAuthEnabledEntities;
4741
+ private entityRepository;
4742
+ private dynamodbClient;
4743
+ private publishEvent;
4744
+ private entityServiceLifeCycle;
4745
+ private eventUtils;
4746
+ constructor(EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>, EmailAuthEnabledEntities: Entity$2[], entityRepository: EntityRepository, dynamodbClient: DynamoDB, publishEvent: typeof publishEvent, entityServiceLifeCycle: EntityServiceLifeCycle, eventUtils: EventUtils);
4747
+ executeTransaction: (operations: TransactionOperation[], accountId?: string) => Promise<TransactionResult>;
4748
+ private processOperation;
4749
+ private buildCreateItems;
4750
+ private buildUpdateItem;
4751
+ private buildAdjustItem;
4752
+ private buildDeleteItem;
4753
+ private collectCreateEvents;
4754
+ private collectUpdateEvents;
4755
+ }
4756
+
4757
+ declare class ExecuteTransactionController {
4758
+ private transactionService;
4759
+ constructor(transactionService: TransactionService);
4760
+ controller: hono.MiddlewareHandler<any, string, {}, any>;
4761
+ }
4762
+
4718
4763
  declare class DependencyContainer {
4719
4764
  config: {
4720
4765
  EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>;
@@ -4757,6 +4802,8 @@ declare class DependencyContainer {
4757
4802
  get updateMutualController(): UpdateMutualController;
4758
4803
  get deleteMutualController(): DeleteMutualController;
4759
4804
  get listTagsController(): ListTagsController;
4805
+ get transactionService(): TransactionService;
4806
+ get executeTransactionController(): ExecuteTransactionController;
4760
4807
  }
4761
4808
 
4762
4809
  declare const setupCommonRoutes: (container: DependencyContainer) => Hono;
@@ -4777,6 +4824,7 @@ declare const StandardErrorCode: {
4777
4824
  readonly ENTITY_ID_IS_UNDEFINED: "ENTITY_ID_IS_UNDEFINED";
4778
4825
  readonly ENTITY_IS_UNDEFINED: "ENTITY_IS_UNDEFINED";
4779
4826
  readonly ENTITY_NOT_FOUND: "ENTITY_NOT_FOUND";
4827
+ readonly INVALID_CONDITION: "INVALID_CONDITION";
4780
4828
  readonly INVALID_ENTITY_TYPE: "INVALID_ENTITY_TYPE";
4781
4829
  readonly INVALID_MUTUAL: "INVALID_MUTUAL";
4782
4830
  readonly INVALID_QUERY: "INVALID_QUERY";
@@ -4789,7 +4837,12 @@ declare const StandardErrorCode: {
4789
4837
  readonly REPLICATION_ERROR: "REPLICATION_ERROR";
4790
4838
  readonly RETRYABLE_MUTUAL_LOCK_CONFLICT: "RETRYABLE_MUTUAL_LOCK_CONFLICT";
4791
4839
  readonly TAG_IS_UNDEFINED: "TAG_IS_UNDEFINED";
4840
+ readonly TRANSACTION_EMPTY: "TRANSACTION_EMPTY";
4792
4841
  readonly TRANSACTION_FAILED: "TRANSACTION_FAILED";
4842
+ readonly TRANSACTION_INVALID_OPERATION: "TRANSACTION_INVALID_OPERATION";
4843
+ readonly TRANSACTION_ITEM_LIMIT_EXCEEDED: "TRANSACTION_ITEM_LIMIT_EXCEEDED";
4844
+ readonly TRANSACTION_UNIQUE_FIELD_UPDATE: "TRANSACTION_UNIQUE_FIELD_UPDATE";
4845
+ readonly TRANSACTION_VALIDATION_ERROR: "TRANSACTION_VALIDATION_ERROR";
4793
4846
  readonly UNIQUE_VALUE_EXISTS: "UNIQUE_VALUE_EXISTS";
4794
4847
  };
4795
4848
  type StandardErrorCode = typeof StandardErrorCode[keyof typeof StandardErrorCode];
@@ -4829,6 +4882,19 @@ declare const handler: (container: DependencyContainer) => (ev: SQSEvent) => Pro
4829
4882
  batchItemFailures: SQSBatchItemFailure[];
4830
4883
  }>;
4831
4884
 
4885
+ declare const transactional: {
4886
+ createEntity: <T extends Entity$2>(entityType: T, payload: EntitySchemaMap[T] & {
4887
+ entityId?: string;
4888
+ }) => TransactionCreateEntity<T>;
4889
+ updateEntity: <T extends Entity$2>(entityType: T, entityId: string, payload: Partial<EntitySchemaMap[T]> & {
4890
+ $condition?: string;
4891
+ }) => TransactionUpdateEntity<T>;
4892
+ adjustEntity: <T extends Entity$2>(entityType: T, entityId: string, adjustments: Record<string, number> & {
4893
+ $condition?: string;
4894
+ }) => TransactionAdjustEntity<T>;
4895
+ deleteEntity: <T extends Entity$2>(entityType: T, entityId: string) => TransactionDeleteEntity<T>;
4896
+ };
4897
+
4832
4898
  declare class CoreFactory {
4833
4899
  private config;
4834
4900
  setupCommonRoutes: ReturnType<typeof setupCommonRoutes>;
@@ -4846,4 +4912,4 @@ declare class CoreFactory {
4846
4912
  });
4847
4913
  }
4848
4914
 
4849
- export { DependencyContainer, Entity$1 as Entity, EntityRepository, EntityService, Mutual, MutualRepository, MutualService, PROJECTION_EXPRESSION, StandardError, StandardErrorCode, TagRepository, appHandler, handler$4 as createEntityProcessor, CoreFactory as default, handler$3 as mutualProcessor, handler$2 as prejoinProcessor, handler$1 as replicationProcessor, setupCommonRoutes, handler as tagProcessor };
4915
+ export { DependencyContainer, Entity$1 as Entity, EntityRepository, EntityService, Mutual, MutualRepository, MutualService, PROJECTION_EXPRESSION, StandardError, StandardErrorCode, TagRepository, TransactionService, appHandler, handler$4 as createEntityProcessor, CoreFactory as default, handler$3 as mutualProcessor, handler$2 as prejoinProcessor, handler$1 as replicationProcessor, setupCommonRoutes, handler as tagProcessor, transactional };