@open-mercato/shared 0.7.1-develop.7148.1.3076e5ccf7 → 0.7.1-develop.7150.1.c1941e0c22

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.
@@ -671,6 +671,31 @@ function makeCrudRoute(opts) {
671
671
  const listCustomFieldDecorator = opts.list?.decorateCustomFields;
672
672
  const indexerConfig = opts.indexer;
673
673
  const eventsConfig = opts.events;
674
+ const withRouteIndexerDeclaration = async (ctx, operation, commandId, run) => {
675
+ if (!indexerConfig || !ormCfg.entity) return run();
676
+ let de = null;
677
+ try {
678
+ de = ctx.container.resolve("dataEngine");
679
+ } catch {
680
+ de = null;
681
+ }
682
+ if (!de || typeof de.setDefaultIndexerConfig !== "function") return run();
683
+ de.setDefaultIndexerConfig({ indexer: indexerConfig, entityClass: ormCfg.entity });
684
+ try {
685
+ const result = await run();
686
+ if (de.hasIndexedDefaultEntityClass?.() === false) {
687
+ logger.warn("CRUD route declares an indexer that its command handler did not discharge; the query index was not updated for this write", {
688
+ resourceKind,
689
+ operation,
690
+ commandId,
691
+ entityType: indexerConfig.entityType
692
+ });
693
+ }
694
+ return result;
695
+ } finally {
696
+ de.setDefaultIndexerConfig(null);
697
+ }
698
+ };
674
699
  const inferFieldValue = (item, keys) => {
675
700
  for (const key of keys) {
676
701
  const value = item[key];
@@ -1675,7 +1700,12 @@ function makeCrudRoute(opts) {
1675
1700
  context: { cacheAliases: resourceTargets }
1676
1701
  };
1677
1702
  const metadataToSend = mergeCommandMetadata(baseMetadata, userMetadata);
1678
- const { result, logEntry } = await commandBus.execute(action.commandId, { input: input2, ctx, metadata: metadataToSend });
1703
+ const { result, logEntry } = await withRouteIndexerDeclaration(
1704
+ ctx,
1705
+ "created",
1706
+ action.commandId,
1707
+ () => commandBus.execute(action.commandId, { input: input2, ctx, metadata: metadataToSend })
1708
+ );
1679
1709
  if (createLifecycleCmd.afterEventId && ctx.auth.tenantId) {
1680
1710
  const syncAfterSubs = collectSyncSubscribers(getAllSyncSubscribers(), createLifecycleCmd.afterEventId);
1681
1711
  if (syncAfterSubs.length) {
@@ -1968,7 +1998,12 @@ function makeCrudRoute(opts) {
1968
1998
  };
1969
1999
  if (candidateId) baseMetadata.resourceId = candidateId;
1970
2000
  const metadataToSend = mergeCommandMetadata(baseMetadata, userMetadata);
1971
- const { result, logEntry } = await commandBus.execute(action.commandId, { input: input2, ctx, metadata: metadataToSend });
2001
+ const { result, logEntry } = await withRouteIndexerDeclaration(
2002
+ ctx,
2003
+ "updated",
2004
+ action.commandId,
2005
+ () => commandBus.execute(action.commandId, { input: input2, ctx, metadata: metadataToSend })
2006
+ );
1972
2007
  const payload2 = action.response ? action.response({ result, logEntry, ctx }) : result;
1973
2008
  let resolvedPayload = await Promise.resolve(payload2);
1974
2009
  if (interceptorRequestPayload && resolvedPayload && typeof resolvedPayload === "object" && !Array.isArray(resolvedPayload)) {
@@ -2269,7 +2304,12 @@ function makeCrudRoute(opts) {
2269
2304
  };
2270
2305
  if (candidateId) baseMetadata.resourceId = candidateId;
2271
2306
  const metadataToSend = mergeCommandMetadata(baseMetadata, userMetadata);
2272
- const { result, logEntry } = await commandBus.execute(action.commandId, { input, ctx, metadata: metadataToSend });
2307
+ const { result, logEntry } = await withRouteIndexerDeclaration(
2308
+ ctx,
2309
+ "deleted",
2310
+ action.commandId,
2311
+ () => commandBus.execute(action.commandId, { input, ctx, metadata: metadataToSend })
2312
+ );
2273
2313
  const payload2 = action.response ? action.response({ result, logEntry, ctx }) : result;
2274
2314
  let resolvedPayload = await Promise.resolve(payload2);
2275
2315
  if (interceptorRequestPayload && resolvedPayload && typeof resolvedPayload === "object" && !Array.isArray(resolvedPayload)) {