@monorise/core 5.0.0-dev.0 → 5.0.0-dev.2

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/index.d.ts CHANGED
@@ -4608,12 +4608,14 @@ declare class UpsertEntityController {
4608
4608
  }
4609
4609
 
4610
4610
  declare class MutualService {
4611
+ private EntityConfig;
4611
4612
  private entityRepository;
4612
4613
  private mutualRepository;
4613
4614
  private publishEvent;
4614
4615
  private ddbUtils;
4615
4616
  private entityServiceLifeCycle;
4616
- constructor(entityRepository: EntityRepository, mutualRepository: MutualRepository, publishEvent: typeof publishEvent, ddbUtils: DbUtils, entityServiceLifeCycle: EntityServiceLifeCycle);
4617
+ constructor(EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>, entityRepository: EntityRepository, mutualRepository: MutualRepository, publishEvent: typeof publishEvent, ddbUtils: DbUtils, entityServiceLifeCycle: EntityServiceLifeCycle);
4618
+ private getMutualDataSchema;
4617
4619
  createMutual: <B extends Entity$2, T extends Entity$2, A extends Entity$2>({ byEntityType, byEntityId, entityType, entityId, mutualPayload, accountId, options, }: {
4618
4620
  byEntityType: B;
4619
4621
  byEntityId: string;
@@ -4632,13 +4634,17 @@ declare class MutualService {
4632
4634
  ExpressionAttributeValues?: Record<string, AttributeValue>;
4633
4635
  };
4634
4636
  }) => Promise<{
4635
- mutual: Mutual<B, T, Record<string, any>>;
4637
+ mutual: Mutual<B, T, {
4638
+ [x: string]: any;
4639
+ }>;
4636
4640
  eventPayload: {
4637
4641
  byEntityType: B;
4638
4642
  byEntityId: string;
4639
4643
  entityType: T;
4640
4644
  entityId: string;
4641
- parsedMutualPayload: Record<string, any>;
4645
+ parsedMutualPayload: {
4646
+ [x: string]: any;
4647
+ };
4642
4648
  accountId: string | string[] | undefined;
4643
4649
  publishedAt: string;
4644
4650
  };
package/dist/index.js CHANGED
@@ -2315,7 +2315,7 @@ var handler2 = (container) => (ev) => __async(null, null, function* () {
2315
2315
  const { entityRepository, mutualRepository, publishEvent: publishEvent2 } = container;
2316
2316
  yield Promise.allSettled(
2317
2317
  ev.Records.map((record) => __async(null, null, function* () {
2318
- var _a, _b, _c, _d;
2318
+ var _a, _b, _c, _d, _e;
2319
2319
  const errorContext = {};
2320
2320
  const body = parseSQSBusEvent(record.body);
2321
2321
  const { detail } = body;
@@ -2338,6 +2338,7 @@ var handler2 = (container) => (ev) => __async(null, null, function* () {
2338
2338
  );
2339
2339
  }
2340
2340
  const mutualDataProcessor = (_d = config.mutualDataProcessor) != null ? _d : (() => ({}));
2341
+ const mutualDataSchema = (_e = config.mutual) == null ? void 0 : _e.mutualDataSchema;
2341
2342
  yield mutualRepository.createMutualLock({
2342
2343
  byEntityType,
2343
2344
  byEntityId,
@@ -2373,6 +2374,20 @@ var handler2 = (container) => (ev) => __async(null, null, function* () {
2373
2374
  addedEntityIds,
2374
2375
  (id) => __async(null, null, function* () {
2375
2376
  const entity = yield entityRepository.getEntity(entityType, id);
2377
+ const processedMutualData = mutualDataProcessor(
2378
+ mutualIds,
2379
+ new Mutual(
2380
+ byEntityType,
2381
+ byEntityId,
2382
+ byEntity.data,
2383
+ entityType,
2384
+ id,
2385
+ entity.data,
2386
+ {}
2387
+ ),
2388
+ customContext
2389
+ );
2390
+ const parsedMutualData = mutualDataSchema ? mutualDataSchema.parse(processedMutualData) : processedMutualData;
2376
2391
  yield mutualRepository.createMutual(
2377
2392
  byEntityType,
2378
2393
  byEntityId,
@@ -2380,19 +2395,7 @@ var handler2 = (container) => (ev) => __async(null, null, function* () {
2380
2395
  entityType,
2381
2396
  id,
2382
2397
  entity.data,
2383
- mutualDataProcessor(
2384
- mutualIds,
2385
- new Mutual(
2386
- byEntityType,
2387
- byEntityId,
2388
- byEntity.data,
2389
- entityType,
2390
- id,
2391
- entity.data,
2392
- {}
2393
- ),
2394
- customContext
2395
- ),
2398
+ parsedMutualData,
2396
2399
  {
2397
2400
  ConditionExpression: "attribute_not_exists(#mutualUpdatedAt) OR #mutualUpdatedAt < :publishedAt",
2398
2401
  ExpressionAttributeNames: {
@@ -2429,25 +2432,27 @@ var handler2 = (container) => (ev) => __async(null, null, function* () {
2429
2432
  const updateEntities = yield processEntities(
2430
2433
  toUpdateEntityIds,
2431
2434
  (id) => __async(null, null, function* () {
2435
+ const processedMutualData = mutualDataProcessor(
2436
+ mutualIds,
2437
+ new Mutual(
2438
+ byEntityType,
2439
+ byEntityId,
2440
+ byEntity.data,
2441
+ entityType,
2442
+ id,
2443
+ {},
2444
+ {}
2445
+ ),
2446
+ customContext
2447
+ );
2448
+ const parsedMutualData = mutualDataSchema ? mutualDataSchema.parse(processedMutualData) : processedMutualData;
2432
2449
  yield mutualRepository.updateMutual(
2433
2450
  byEntityType,
2434
2451
  byEntityId,
2435
2452
  entityType,
2436
2453
  id,
2437
2454
  {
2438
- mutualData: mutualDataProcessor(
2439
- mutualIds,
2440
- new Mutual(
2441
- byEntityType,
2442
- byEntityId,
2443
- byEntity.data,
2444
- entityType,
2445
- id,
2446
- {},
2447
- {}
2448
- ),
2449
- customContext
2450
- ),
2455
+ mutualData: parsedMutualData,
2451
2456
  mutualUpdatedAt: publishedAt
2452
2457
  },
2453
2458
  {
@@ -8510,7 +8515,8 @@ var EntityService = class {
8510
8515
  // services/mutual.service.ts
8511
8516
  import { ulid as ulid4 } from "ulid";
8512
8517
  var MutualService = class {
8513
- constructor(entityRepository, mutualRepository, publishEvent2, ddbUtils, entityServiceLifeCycle) {
8518
+ constructor(EntityConfig, entityRepository, mutualRepository, publishEvent2, ddbUtils, entityServiceLifeCycle) {
8519
+ this.EntityConfig = EntityConfig;
8514
8520
  this.entityRepository = entityRepository;
8515
8521
  this.mutualRepository = mutualRepository;
8516
8522
  this.publishEvent = publishEvent2;
@@ -8525,6 +8531,7 @@ var MutualService = class {
8525
8531
  accountId,
8526
8532
  options = {}
8527
8533
  }) {
8534
+ var _a;
8528
8535
  const {
8529
8536
  ensureEntityStrongConsistentWrite = false,
8530
8537
  asEntity,
@@ -8545,7 +8552,7 @@ var MutualService = class {
8545
8552
  options
8546
8553
  }
8547
8554
  };
8548
- const schema = external_exports.record(external_exports.string(), external_exports.any());
8555
+ const schema = (_a = this.getMutualDataSchema(byEntityType, entityType)) != null ? _a : external_exports.record(external_exports.string(), external_exports.any());
8549
8556
  const parsedMutualPayload = schema.parse(mutualPayload);
8550
8557
  const [{ data: byEntityData }, { data: entityData }] = yield Promise.all([
8551
8558
  this.entityRepository.getEntity(byEntityType, byEntityId),
@@ -8648,7 +8655,8 @@ var MutualService = class {
8648
8655
  accountId,
8649
8656
  options
8650
8657
  }) {
8651
- const schema = external_exports.record(external_exports.string(), external_exports.any());
8658
+ var _a;
8659
+ const schema = (_a = this.getMutualDataSchema(byEntityType, entityType)) != null ? _a : external_exports.record(external_exports.string(), external_exports.any());
8652
8660
  const parsedMutualPayload = schema.parse(mutualPayload);
8653
8661
  const mutual = yield this.mutualRepository.updateMutual(
8654
8662
  byEntityType,
@@ -8697,6 +8705,22 @@ var MutualService = class {
8697
8705
  return mutual;
8698
8706
  });
8699
8707
  }
8708
+ getMutualDataSchema(byEntityType, entityType) {
8709
+ var _a, _b, _c;
8710
+ for (const [from, to] of [
8711
+ [byEntityType, entityType],
8712
+ [entityType, byEntityType]
8713
+ ]) {
8714
+ const mutualFields = (_b = (_a = this.EntityConfig[from]) == null ? void 0 : _a.mutual) == null ? void 0 : _b.mutualFields;
8715
+ if (!mutualFields) continue;
8716
+ for (const config of Object.values(mutualFields)) {
8717
+ if (config.entityType === to && ((_c = config.mutual) == null ? void 0 : _c.mutualDataSchema)) {
8718
+ return config.mutual.mutualDataSchema;
8719
+ }
8720
+ }
8721
+ }
8722
+ return void 0;
8723
+ }
8700
8724
  };
8701
8725
 
8702
8726
  // controllers/tag/list-tags.controller.ts
@@ -9395,6 +9419,7 @@ var DependencyContainer = class {
9395
9419
  get mutualService() {
9396
9420
  return this.createCachedInstance(
9397
9421
  MutualService,
9422
+ this.config.EntityConfig,
9398
9423
  this.entityRepository,
9399
9424
  this.mutualRepository,
9400
9425
  this.publishEvent,