diff --git a/server/core/src/storage.ts b/server/core/src/storage.ts index d849c2c96e..bcfe672aae 100644 --- a/server/core/src/storage.ts +++ b/server/core/src/storage.ts @@ -69,6 +69,7 @@ import { FullTextPipelineStage } from './indexer/types' import serverCore from './plugin' import { Triggers } from './triggers' import type { + BroadcastFunc, ContentTextAdapter, ContentTextAdapterConfiguration, FullTextAdapter, @@ -626,11 +627,11 @@ class TServerStorage implements ServerStorage { findAllCtx: findAll, modelDb: this.modelDb, hierarchy: this.hierarchy, - apply: async (tx, broadcast) => { - return await this.apply(ctx, tx, broadcast) + apply: async (tx, broadcast, target) => { + return await this.apply(ctx, tx, broadcast, target) }, - applyCtx: async (ctx, tx, broadcast) => { - return await this.apply(ctx, tx, broadcast) + applyCtx: async (ctx, tx, broadcast, target) => { + return await this.apply(ctx, tx, broadcast, target) }, // Will create a live query if missing and return values immediately if already asked. queryFind: async (_class, query, options) => { @@ -719,14 +720,14 @@ class TServerStorage implements ServerStorage { return { passed, onEnd } } - async apply (ctx: MeasureContext, txes: Tx[], broadcast: boolean): Promise { + async apply (ctx: MeasureContext, txes: Tx[], broadcast: boolean, target?: string[]): Promise { const result = await this.processTxes(ctx, txes) let derived: Tx[] = [] derived = result[1] if (broadcast) { - this.options?.broadcast?.([...txes, ...derived]) + this.options?.broadcast?.([...txes, ...derived], target) } return result[0] @@ -867,7 +868,7 @@ export interface ServerStorageOptions { // Indexing is not required to be started for upgrade mode. upgrade: boolean - broadcast?: (tx: Tx[]) => void + broadcast?: BroadcastFunc } /** * @public diff --git a/server/core/src/triggers.ts b/server/core/src/triggers.ts index 04e643bdea..5df48bbc60 100644 --- a/server/core/src/triggers.ts +++ b/server/core/src/triggers.ts @@ -76,8 +76,8 @@ export class Triggers { ctx, txFactory: new TxFactory(tx.modifiedBy, true), findAll: async (clazz, query, options) => await ctrl.findAllCtx(ctx, clazz, query, options), - apply: async (tx, broadcast) => { - return await ctrl.applyCtx(ctx, tx, broadcast) + apply: async (tx, broadcast, target) => { + return await ctrl.applyCtx(ctx, tx, broadcast, target) } })) ) diff --git a/server/core/src/types.ts b/server/core/src/types.ts index 1dd4007da6..da8a640cf6 100644 --- a/server/core/src/types.ts +++ b/server/core/src/types.ts @@ -135,8 +135,8 @@ export interface TriggerControl { fx: (f: () => Promise) => void // Bulk operations in case trigger require some - apply: (tx: Tx[], broadcast: boolean) => Promise - applyCtx: (ctx: MeasureContext, tx: Tx[], broadcast: boolean) => Promise + apply: (tx: Tx[], broadcast: boolean, target?: string[]) => Promise + applyCtx: (ctx: MeasureContext, tx: Tx[], broadcast: boolean, target?: string[]) => Promise // Will create a live query if missing and return values immediately if already asked. queryFind: (