monorise 0.1.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base/index.d.ts +6 -2
- package/dist/base/index.js.map +1 -1
- package/dist/core/index.d.ts +26 -5
- package/dist/core/index.js +112 -6
- package/dist/core/index.js.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/alb.d.ts +280 -0
- package/dist/sst/.sst/platform/src/components/aws/alb.d.ts.map +1 -0
- package/dist/sst/.sst/platform/src/components/aws/apigateway-websocket-route.d.ts +1 -1
- package/dist/sst/.sst/platform/src/components/aws/apigateway-websocket-route.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/apigateway-websocket.d.ts +13 -2
- package/dist/sst/.sst/platform/src/components/aws/apigateway-websocket.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/apigatewayv1-authorizer.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/apigatewayv1-lambda-route.d.ts +1 -1
- package/dist/sst/.sst/platform/src/components/aws/apigatewayv1-lambda-route.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/apigatewayv1.d.ts +93 -83
- package/dist/sst/.sst/platform/src/components/aws/apigatewayv1.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/apigatewayv2-authorizer.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/apigatewayv2-lambda-route.d.ts +1 -1
- package/dist/sst/.sst/platform/src/components/aws/apigatewayv2-lambda-route.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/apigatewayv2.d.ts +8 -2
- package/dist/sst/.sst/platform/src/components/aws/apigatewayv2.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/app-sync-data-source.d.ts +1 -1
- package/dist/sst/.sst/platform/src/components/aws/app-sync-data-source.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/app-sync.d.ts +1 -1
- package/dist/sst/.sst/platform/src/components/aws/app-sync.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/aurora.d.ts +18 -0
- package/dist/sst/.sst/platform/src/components/aws/aurora.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/auth-v1.d.ts +1 -1
- package/dist/sst/.sst/platform/src/components/aws/auth-v1.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/auth.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/bucket-lambda-subscriber.d.ts +1 -1
- package/dist/sst/.sst/platform/src/components/aws/bucket-lambda-subscriber.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/bucket-notification.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/bucket.d.ts +13 -8
- package/dist/sst/.sst/platform/src/components/aws/bucket.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/bus-lambda-subscriber.d.ts +3 -2
- package/dist/sst/.sst/platform/src/components/aws/bus-lambda-subscriber.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/bus.d.ts +34 -3
- package/dist/sst/.sst/platform/src/components/aws/bus.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/cdn.d.ts +11 -0
- package/dist/sst/.sst/platform/src/components/aws/cdn.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/cluster.d.ts +59 -1
- package/dist/sst/.sst/platform/src/components/aws/cluster.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/cognito-identity-pool.d.ts +5 -0
- package/dist/sst/.sst/platform/src/components/aws/cognito-identity-pool.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/cognito-user-pool.d.ts +100 -0
- package/dist/sst/.sst/platform/src/components/aws/cognito-user-pool.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/cron-v2.d.ts +325 -0
- package/dist/sst/.sst/platform/src/components/aws/cron-v2.d.ts.map +1 -0
- package/dist/sst/.sst/platform/src/components/aws/cron.d.ts +15 -6
- package/dist/sst/.sst/platform/src/components/aws/cron.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/dsql.d.ts +369 -0
- package/dist/sst/.sst/platform/src/components/aws/dsql.d.ts.map +1 -0
- package/dist/sst/.sst/platform/src/components/aws/dynamo-lambda-subscriber.d.ts +1 -1
- package/dist/sst/.sst/platform/src/components/aws/dynamo-lambda-subscriber.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/dynamo.d.ts +63 -3
- package/dist/sst/.sst/platform/src/components/aws/dynamo.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/email.d.ts +5 -0
- package/dist/sst/.sst/platform/src/components/aws/email.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/fargate.d.ts +95 -4
- package/dist/sst/.sst/platform/src/components/aws/fargate.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/function.d.ts +121 -21
- package/dist/sst/.sst/platform/src/components/aws/function.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/helpers/arn.d.ts +11 -0
- package/dist/sst/.sst/platform/src/components/aws/helpers/arn.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/helpers/container-builder.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/helpers/function-builder.d.ts +7 -3
- package/dist/sst/.sst/platform/src/components/aws/helpers/function-builder.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/helpers/load-balancer.d.ts +9 -0
- package/dist/sst/.sst/platform/src/components/aws/helpers/load-balancer.d.ts.map +1 -0
- package/dist/sst/.sst/platform/src/components/aws/helpers/provider.d.ts +2 -2
- package/dist/sst/.sst/platform/src/components/aws/helpers/provider.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/helpers/site-builder.d.ts +1 -1
- package/dist/sst/.sst/platform/src/components/aws/helpers/site-builder.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/helpers/subscriber.d.ts +1 -1
- package/dist/sst/.sst/platform/src/components/aws/helpers/subscriber.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/https-redirect.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/index.d.ts +4 -0
- package/dist/sst/.sst/platform/src/components/aws/index.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/kinesis-stream-lambda-subscriber.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/kinesis-stream.d.ts +8 -3
- package/dist/sst/.sst/platform/src/components/aws/kinesis-stream.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/linkable.d.ts +1 -1
- package/dist/sst/.sst/platform/src/components/aws/linkable.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/mysql.d.ts +34 -5
- package/dist/sst/.sst/platform/src/components/aws/mysql.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/nextjs.d.ts +39 -5
- package/dist/sst/.sst/platform/src/components/aws/nextjs.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/nuxt.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/open-search.d.ts +12 -1
- package/dist/sst/.sst/platform/src/components/aws/open-search.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/opencontrol.d.ts +7 -3
- package/dist/sst/.sst/platform/src/components/aws/opencontrol.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/permission.d.ts +5 -0
- package/dist/sst/.sst/platform/src/components/aws/permission.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/postgres-v1.d.ts +13 -2
- package/dist/sst/.sst/platform/src/components/aws/postgres-v1.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/postgres.d.ts +34 -5
- package/dist/sst/.sst/platform/src/components/aws/postgres.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/queue-lambda-subscriber.d.ts +6 -1
- package/dist/sst/.sst/platform/src/components/aws/queue-lambda-subscriber.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/queue.d.ts +10 -1
- package/dist/sst/.sst/platform/src/components/aws/queue.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/realtime-lambda-subscriber.d.ts +1 -1
- package/dist/sst/.sst/platform/src/components/aws/realtime-lambda-subscriber.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/realtime.d.ts +6 -1
- package/dist/sst/.sst/platform/src/components/aws/realtime.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/redis-v1.d.ts +10 -0
- package/dist/sst/.sst/platform/src/components/aws/redis-v1.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/redis.d.ts +14 -0
- package/dist/sst/.sst/platform/src/components/aws/redis.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/router.d.ts +482 -2
- package/dist/sst/.sst/platform/src/components/aws/router.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/service-v1.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/service.d.ts +125 -0
- package/dist/sst/.sst/platform/src/components/aws/service.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/sns-topic-lambda-subscriber.d.ts +1 -1
- package/dist/sst/.sst/platform/src/components/aws/sns-topic-lambda-subscriber.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/sns-topic.d.ts +6 -1
- package/dist/sst/.sst/platform/src/components/aws/sns-topic.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/ssr-site.d.ts +7 -7
- package/dist/sst/.sst/platform/src/components/aws/ssr-site.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/static-site.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/step-functions/state.d.ts +1 -1
- package/dist/sst/.sst/platform/src/components/aws/step-functions/state.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/step-functions/task.d.ts +10 -2
- package/dist/sst/.sst/platform/src/components/aws/step-functions/task.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/step-functions.d.ts +5 -0
- package/dist/sst/.sst/platform/src/components/aws/step-functions.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/tan-stack-start.d.ts +20 -6
- package/dist/sst/.sst/platform/src/components/aws/tan-stack-start.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/task.d.ts +35 -15
- package/dist/sst/.sst/platform/src/components/aws/task.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/vector.d.ts +5 -0
- package/dist/sst/.sst/platform/src/components/aws/vector.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/vpc.d.ts +51 -4
- package/dist/sst/.sst/platform/src/components/aws/vpc.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/aws/workflow.d.ts +331 -0
- package/dist/sst/.sst/platform/src/components/aws/workflow.d.ts.map +1 -0
- package/dist/sst/.sst/platform/src/components/cloudflare/ai.d.ts +82 -0
- package/dist/sst/.sst/platform/src/components/cloudflare/ai.d.ts.map +1 -0
- package/dist/sst/.sst/platform/src/components/cloudflare/binding.d.ts +15 -1
- package/dist/sst/.sst/platform/src/components/cloudflare/binding.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/cloudflare/bucket.d.ts +4 -2
- package/dist/sst/.sst/platform/src/components/cloudflare/bucket.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/cloudflare/cron.d.ts +29 -5
- package/dist/sst/.sst/platform/src/components/cloudflare/cron.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/cloudflare/d1.d.ts +37 -2
- package/dist/sst/.sst/platform/src/components/cloudflare/d1.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/cloudflare/index.d.ts +1 -0
- package/dist/sst/.sst/platform/src/components/cloudflare/index.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/cloudflare/kv.d.ts +36 -2
- package/dist/sst/.sst/platform/src/components/cloudflare/kv.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/cloudflare/providers/worker-placement.d.ts +27 -0
- package/dist/sst/.sst/platform/src/components/cloudflare/providers/worker-placement.d.ts.map +1 -0
- package/dist/sst/.sst/platform/src/components/cloudflare/providers/zone-lookup.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/cloudflare/queue-worker-subscriber.d.ts +116 -0
- package/dist/sst/.sst/platform/src/components/cloudflare/queue-worker-subscriber.d.ts.map +1 -0
- package/dist/sst/.sst/platform/src/components/cloudflare/queue.d.ts +186 -3
- package/dist/sst/.sst/platform/src/components/cloudflare/queue.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/cloudflare/static-site.d.ts +2 -2
- package/dist/sst/.sst/platform/src/components/cloudflare/static-site.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/cloudflare/worker.d.ts +39 -5
- package/dist/sst/.sst/platform/src/components/cloudflare/worker.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/component.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/duration.d.ts +2 -0
- package/dist/sst/.sst/platform/src/components/duration.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/esbuild.d.ts +3 -0
- package/dist/sst/.sst/platform/src/components/esbuild.d.ts.map +1 -0
- package/dist/sst/.sst/platform/src/components/link.d.ts +2 -2
- package/dist/sst/.sst/platform/src/components/link.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/linkable.d.ts +32 -2
- package/dist/sst/.sst/platform/src/components/linkable.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/rpc/rpc.d.ts.map +1 -1
- package/dist/sst/.sst/platform/src/components/vercel/dns.d.ts +2 -2
- package/dist/sst/.sst/platform/src/util/minify.d.ts +2 -0
- package/dist/sst/.sst/platform/src/util/minify.d.ts.map +1 -0
- package/dist/sst/components/q-function.d.ts +2 -3
- package/dist/sst/components/q-function.d.ts.map +1 -1
- package/dist/sst/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/sst/.sst/platform/src/components/aws/helpers/quota.d.ts +0 -7
- package/dist/sst/.sst/platform/src/components/aws/helpers/quota.d.ts.map +0 -1
package/dist/base/index.d.ts
CHANGED
|
@@ -242,10 +242,14 @@ interface MonoriseEntityConfig<T extends Entity = Entity, B extends z.ZodRawShap
|
|
|
242
242
|
/** Field name on the entity whose value is used as the minimum (must be a numeric field) */
|
|
243
243
|
minField?: keyof {
|
|
244
244
|
[K in keyof B as B[K] extends z.ZodNumber | z.ZodOptional<z.ZodNumber> ? K : never]: K;
|
|
245
|
+
} extends never ? string : keyof {
|
|
246
|
+
[K in keyof B as B[K] extends z.ZodNumber | z.ZodOptional<z.ZodNumber> ? K : never]: K;
|
|
245
247
|
};
|
|
246
248
|
/** Field name on the entity whose value is used as the maximum (must be a numeric field) */
|
|
247
249
|
maxField?: keyof {
|
|
248
250
|
[K in keyof B as B[K] extends z.ZodNumber | z.ZodOptional<z.ZodNumber> ? K : never]: K;
|
|
251
|
+
} extends never ? string : keyof {
|
|
252
|
+
[K in keyof B as B[K] extends z.ZodNumber | z.ZodOptional<z.ZodNumber> ? K : never]: K;
|
|
249
253
|
};
|
|
250
254
|
};
|
|
251
255
|
};
|
|
@@ -304,8 +308,8 @@ declare const createEntityConfig: <T extends Entity, B extends z.ZodRawShape, C
|
|
|
304
308
|
[fieldName: string]: {
|
|
305
309
|
min?: number;
|
|
306
310
|
max?: number;
|
|
307
|
-
minField?: keyof { [K in keyof B as B[K] extends z.ZodNumber | z.ZodOptional<z.ZodNumber> ? K : never]: K; } | undefined;
|
|
308
|
-
maxField?: keyof { [
|
|
311
|
+
minField?: (keyof { [K in keyof B as B[K] extends z.ZodNumber | z.ZodOptional<z.ZodNumber> ? K : never]: K; } extends never ? string : keyof { [K_1 in keyof B as B[K_1] extends z.ZodNumber | z.ZodOptional<z.ZodNumber> ? K_1 : never]: K_1; }) | undefined;
|
|
312
|
+
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;
|
|
309
313
|
};
|
|
310
314
|
} | undefined;
|
|
311
315
|
};
|
package/dist/base/index.js.map
CHANGED
|
@@ -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 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 };\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) 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 };\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 };\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 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 };\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) 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 } 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/core/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { DynamoDB, TransactWriteItemsInput, AttributeValue, TransactWriteItem, U
|
|
|
5
5
|
import * as hono_utils_http_status from 'hono/utils/http-status';
|
|
6
6
|
import * as hono_utils_types from 'hono/utils/types';
|
|
7
7
|
import { createFactory } from 'hono/factory';
|
|
8
|
-
import
|
|
8
|
+
import httpStatus8 from 'http-status';
|
|
9
9
|
import { unmarshall, marshall } from '@aws-sdk/util-dynamodb';
|
|
10
10
|
import { EventBridgeClient } from '@aws-sdk/client-eventbridge';
|
|
11
11
|
import * as hono_aws_lambda from 'hono/aws-lambda';
|
|
@@ -465,10 +465,10 @@ factory.createMiddleware((c, next) => __async(null, null, function* () {
|
|
|
465
465
|
return yield next();
|
|
466
466
|
}
|
|
467
467
|
if (!xApiKey || Array.isArray(xApiKey) || !API_KEYS.includes(xApiKey)) {
|
|
468
|
-
c.status(
|
|
468
|
+
c.status(httpStatus8.UNAUTHORIZED);
|
|
469
469
|
return c.json({
|
|
470
|
-
status:
|
|
471
|
-
message:
|
|
470
|
+
status: httpStatus8.UNAUTHORIZED,
|
|
471
|
+
message: httpStatus8["401_MESSAGE"]
|
|
472
472
|
});
|
|
473
473
|
}
|
|
474
474
|
return yield next();
|
|
@@ -4446,6 +4446,26 @@ external_exports.object({
|
|
|
4446
4446
|
lastKey: external_exports.string().optional()
|
|
4447
4447
|
});
|
|
4448
4448
|
|
|
4449
|
+
type WhereOperator = {
|
|
4450
|
+
$eq: string | number | boolean;
|
|
4451
|
+
} | {
|
|
4452
|
+
$ne: string | number | boolean;
|
|
4453
|
+
} | {
|
|
4454
|
+
$gt: number;
|
|
4455
|
+
} | {
|
|
4456
|
+
$lt: number;
|
|
4457
|
+
} | {
|
|
4458
|
+
$gte: number;
|
|
4459
|
+
} | {
|
|
4460
|
+
$lte: number;
|
|
4461
|
+
} | {
|
|
4462
|
+
$exists: boolean;
|
|
4463
|
+
} | {
|
|
4464
|
+
$beginsWith: string;
|
|
4465
|
+
};
|
|
4466
|
+
type WhereClause = WhereOperator | string | number | boolean;
|
|
4467
|
+
type WhereConditions = Record<string, WhereClause>;
|
|
4468
|
+
|
|
4449
4469
|
declare class EntityServiceLifeCycle {
|
|
4450
4470
|
private EntityConfig;
|
|
4451
4471
|
private publishEvent;
|
|
@@ -4477,11 +4497,12 @@ declare class EntityService {
|
|
|
4477
4497
|
adjustments: Record<string, number>;
|
|
4478
4498
|
accountId?: string;
|
|
4479
4499
|
}) => Promise<Entity<T>>;
|
|
4480
|
-
updateEntity: <T extends Entity$2>({ entityType, entityId, entityPayload, accountId, }: {
|
|
4500
|
+
updateEntity: <T extends Entity$2>({ entityType, entityId, entityPayload, accountId, where, }: {
|
|
4481
4501
|
entityType: T;
|
|
4482
4502
|
entityId: string;
|
|
4483
4503
|
entityPayload: Partial<EntitySchemaMap[T]>;
|
|
4484
4504
|
accountId?: string | string[];
|
|
4505
|
+
where?: WhereConditions;
|
|
4485
4506
|
}) => Promise<Entity<T>>;
|
|
4486
4507
|
deleteEntity: <T extends Entity$2>({ entityType, entityId, accountId, }: {
|
|
4487
4508
|
entityType: T;
|
package/dist/core/index.js
CHANGED
|
@@ -17,6 +17,18 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
20
32
|
var __export = (target, all) => {
|
|
21
33
|
for (var name in all)
|
|
22
34
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -762,6 +774,22 @@ var EntityRepository = class extends Repository {
|
|
|
762
774
|
} catch (err) {
|
|
763
775
|
if (err instanceof TransactionCanceledException) {
|
|
764
776
|
const [updateErr, ...uniqueFieldErr] = err.CancellationReasons || [];
|
|
777
|
+
if ((updateErr == null ? void 0 : updateErr.Code) === BatchStatementErrorCodeEnum.ConditionalCheckFailed) {
|
|
778
|
+
if (opts == null ? void 0 : opts.ConditionExpression) {
|
|
779
|
+
throw new StandardError(
|
|
780
|
+
StandardErrorCode.CONDITIONAL_CHECK_FAILED,
|
|
781
|
+
"Conditional check failed",
|
|
782
|
+
err,
|
|
783
|
+
{ entityId, toUpdate }
|
|
784
|
+
);
|
|
785
|
+
}
|
|
786
|
+
throw new StandardError(
|
|
787
|
+
StandardErrorCode.ENTITY_NOT_FOUND,
|
|
788
|
+
"Entity not found",
|
|
789
|
+
err,
|
|
790
|
+
{ entityId, toUpdate }
|
|
791
|
+
);
|
|
792
|
+
}
|
|
765
793
|
for (let i = 0; i < uniqueFieldErr.length; i++) {
|
|
766
794
|
if (i % 2 === 1 && uniqueFieldErr[i].Code === BatchStatementErrorCodeEnum.ConditionalCheckFailed) {
|
|
767
795
|
const field = updatedUniqueFields[Math.floor(i / 2)];
|
|
@@ -782,6 +810,14 @@ var EntityRepository = class extends Repository {
|
|
|
782
810
|
return updatedEntity;
|
|
783
811
|
} catch (err) {
|
|
784
812
|
if (err instanceof ConditionalCheckFailedException) {
|
|
813
|
+
if (opts == null ? void 0 : opts.ConditionExpression) {
|
|
814
|
+
throw new StandardError(
|
|
815
|
+
StandardErrorCode.CONDITIONAL_CHECK_FAILED,
|
|
816
|
+
"Conditional check failed",
|
|
817
|
+
err,
|
|
818
|
+
{ entityId, toUpdate }
|
|
819
|
+
);
|
|
820
|
+
}
|
|
785
821
|
throw new StandardError(
|
|
786
822
|
StandardErrorCode.ENTITY_NOT_FOUND,
|
|
787
823
|
"Entity not found",
|
|
@@ -7051,10 +7087,11 @@ var UpdateEntityController = class {
|
|
|
7051
7087
|
constructor(entityService) {
|
|
7052
7088
|
this.entityService = entityService;
|
|
7053
7089
|
this.controller = createMiddleware8((c) => __async(this, null, function* () {
|
|
7054
|
-
var
|
|
7090
|
+
var _b;
|
|
7055
7091
|
const accountId = c.req.header("account-id");
|
|
7056
7092
|
const { entityType, entityId } = c.req.param();
|
|
7057
7093
|
const body = yield c.req.json();
|
|
7094
|
+
const _a = body, { $where: where } = _a, entityPayload = __objRest(_a, ["$where"]);
|
|
7058
7095
|
const errorContext = {
|
|
7059
7096
|
accountId,
|
|
7060
7097
|
"req.params": c.req.param(),
|
|
@@ -7064,14 +7101,15 @@ var UpdateEntityController = class {
|
|
|
7064
7101
|
const entity = yield this.entityService.updateEntity({
|
|
7065
7102
|
entityType,
|
|
7066
7103
|
entityId,
|
|
7067
|
-
entityPayload
|
|
7068
|
-
accountId
|
|
7104
|
+
entityPayload,
|
|
7105
|
+
accountId,
|
|
7106
|
+
where
|
|
7069
7107
|
});
|
|
7070
7108
|
errorContext.entity = entity;
|
|
7071
7109
|
c.status(httpStatus8.OK);
|
|
7072
7110
|
return c.json(entity);
|
|
7073
7111
|
} catch (err) {
|
|
7074
|
-
if (((
|
|
7112
|
+
if (((_b = err.constructor) == null ? void 0 : _b.name) === "ZodError") {
|
|
7075
7113
|
c.status(httpStatus8.BAD_REQUEST);
|
|
7076
7114
|
return c.json({
|
|
7077
7115
|
code: "API_VALIDATION_ERROR",
|
|
@@ -7087,6 +7125,10 @@ var UpdateEntityController = class {
|
|
|
7087
7125
|
c.status(httpStatus8.BAD_REQUEST);
|
|
7088
7126
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
7089
7127
|
}
|
|
7128
|
+
if (err instanceof StandardError && err.code === StandardErrorCode.CONDITIONAL_CHECK_FAILED) {
|
|
7129
|
+
c.status(httpStatus8.CONFLICT);
|
|
7130
|
+
return c.json(__spreadValues({}, err.toJSON()));
|
|
7131
|
+
}
|
|
7090
7132
|
console.log(
|
|
7091
7133
|
"====UPDATE_ENTITY_CONTROLLER_ERROR",
|
|
7092
7134
|
err,
|
|
@@ -7437,6 +7479,67 @@ var UpdateMutualController = class {
|
|
|
7437
7479
|
}
|
|
7438
7480
|
};
|
|
7439
7481
|
|
|
7482
|
+
// data/utils/build-condition-expression.ts
|
|
7483
|
+
import { marshall as marshall5 } from "@aws-sdk/util-dynamodb";
|
|
7484
|
+
function buildConditionExpression(where) {
|
|
7485
|
+
const conditions = ["attribute_exists(PK)"];
|
|
7486
|
+
const expressionAttributeNames = { "#data": "data" };
|
|
7487
|
+
const expressionAttributeValues = {};
|
|
7488
|
+
for (const [field, clause] of Object.entries(where)) {
|
|
7489
|
+
const namePlaceholder = `#where_${field}`;
|
|
7490
|
+
expressionAttributeNames[namePlaceholder] = field;
|
|
7491
|
+
const fieldRef = `#data.${namePlaceholder}`;
|
|
7492
|
+
if (clause === null || clause === void 0) continue;
|
|
7493
|
+
if (typeof clause !== "object") {
|
|
7494
|
+
const valPlaceholder = `:where_${field}`;
|
|
7495
|
+
expressionAttributeValues[valPlaceholder] = clause;
|
|
7496
|
+
conditions.push(`${fieldRef} = ${valPlaceholder}`);
|
|
7497
|
+
continue;
|
|
7498
|
+
}
|
|
7499
|
+
const op = clause;
|
|
7500
|
+
if ("$eq" in op) {
|
|
7501
|
+
const valPlaceholder = `:where_${field}_eq`;
|
|
7502
|
+
expressionAttributeValues[valPlaceholder] = op.$eq;
|
|
7503
|
+
conditions.push(`${fieldRef} = ${valPlaceholder}`);
|
|
7504
|
+
} else if ("$ne" in op) {
|
|
7505
|
+
const valPlaceholder = `:where_${field}_ne`;
|
|
7506
|
+
expressionAttributeValues[valPlaceholder] = op.$ne;
|
|
7507
|
+
conditions.push(`${fieldRef} <> ${valPlaceholder}`);
|
|
7508
|
+
} else if ("$gt" in op) {
|
|
7509
|
+
const valPlaceholder = `:where_${field}_gt`;
|
|
7510
|
+
expressionAttributeValues[valPlaceholder] = op.$gt;
|
|
7511
|
+
conditions.push(`${fieldRef} > ${valPlaceholder}`);
|
|
7512
|
+
} else if ("$lt" in op) {
|
|
7513
|
+
const valPlaceholder = `:where_${field}_lt`;
|
|
7514
|
+
expressionAttributeValues[valPlaceholder] = op.$lt;
|
|
7515
|
+
conditions.push(`${fieldRef} < ${valPlaceholder}`);
|
|
7516
|
+
} else if ("$gte" in op) {
|
|
7517
|
+
const valPlaceholder = `:where_${field}_gte`;
|
|
7518
|
+
expressionAttributeValues[valPlaceholder] = op.$gte;
|
|
7519
|
+
conditions.push(`${fieldRef} >= ${valPlaceholder}`);
|
|
7520
|
+
} else if ("$lte" in op) {
|
|
7521
|
+
const valPlaceholder = `:where_${field}_lte`;
|
|
7522
|
+
expressionAttributeValues[valPlaceholder] = op.$lte;
|
|
7523
|
+
conditions.push(`${fieldRef} <= ${valPlaceholder}`);
|
|
7524
|
+
} else if ("$exists" in op) {
|
|
7525
|
+
if (op.$exists) {
|
|
7526
|
+
conditions.push(`attribute_exists(${fieldRef})`);
|
|
7527
|
+
} else {
|
|
7528
|
+
conditions.push(`attribute_not_exists(${fieldRef})`);
|
|
7529
|
+
}
|
|
7530
|
+
} else if ("$beginsWith" in op) {
|
|
7531
|
+
const valPlaceholder = `:where_${field}_beginsWith`;
|
|
7532
|
+
expressionAttributeValues[valPlaceholder] = op.$beginsWith;
|
|
7533
|
+
conditions.push(`begins_with(${fieldRef}, ${valPlaceholder})`);
|
|
7534
|
+
}
|
|
7535
|
+
}
|
|
7536
|
+
return {
|
|
7537
|
+
ConditionExpression: conditions.join(" AND "),
|
|
7538
|
+
ExpressionAttributeNames: expressionAttributeNames,
|
|
7539
|
+
ExpressionAttributeValues: marshall5(expressionAttributeValues)
|
|
7540
|
+
};
|
|
7541
|
+
}
|
|
7542
|
+
|
|
7440
7543
|
// services/entity.service.ts
|
|
7441
7544
|
var EntityService = class {
|
|
7442
7545
|
constructor(EntityConfig, EmailAuthEnabledEntities, entityRepository, publishEvent2, entityServiceLifeCycle) {
|
|
@@ -7537,7 +7640,8 @@ var EntityService = class {
|
|
|
7537
7640
|
entityType,
|
|
7538
7641
|
entityId,
|
|
7539
7642
|
entityPayload,
|
|
7540
|
-
accountId
|
|
7643
|
+
accountId,
|
|
7644
|
+
where
|
|
7541
7645
|
}) {
|
|
7542
7646
|
var _a, _b;
|
|
7543
7647
|
const errorContext = {};
|
|
@@ -7553,10 +7657,12 @@ var EntityService = class {
|
|
|
7553
7657
|
const parsedEntityPayload = entitySchema.parse(entityPayload);
|
|
7554
7658
|
const parsedMutualPayload = mutualSchema == null ? void 0 : mutualSchema.parse(entityPayload);
|
|
7555
7659
|
errorContext.parsedMutualPayload = parsedMutualPayload;
|
|
7660
|
+
const opts = where && Object.keys(where).length > 0 ? buildConditionExpression(where) : void 0;
|
|
7556
7661
|
const entity = yield this.entityRepository.updateEntity(
|
|
7557
7662
|
entityType,
|
|
7558
7663
|
entityId,
|
|
7559
|
-
{ data: parsedEntityPayload }
|
|
7664
|
+
{ data: parsedEntityPayload },
|
|
7665
|
+
opts
|
|
7560
7666
|
);
|
|
7561
7667
|
errorContext.entity = entity;
|
|
7562
7668
|
if (parsedMutualPayload) {
|