@reventlessdev/reventless-core 3.0.0-alpha.334 → 3.0.0-alpha.336

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 (38) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/package.json +6 -6
  3. package/src/CommandSent.res +10 -0
  4. package/src/CommandSent.res.mjs +8 -0
  5. package/src/admin/Platform_I18n.res +112 -0
  6. package/src/admin/Platform_I18n.res.mjs +115 -0
  7. package/src/components/Aggregate/Aggregate_Callback.res +3 -0
  8. package/src/components/Aggregate/Aggregate_Callback.res.mjs +3 -3
  9. package/src/components/AutomationSlice/AutomationSlice.res +3 -0
  10. package/src/components/AutomationSlice/AutomationSlice_Builder.res +24 -8
  11. package/src/components/AutomationSlice/AutomationSlice_Builder.res.mjs +109 -102
  12. package/src/components/AutomationSlice/AutomationSlice_Callback.res +75 -8
  13. package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +58 -7
  14. package/src/components/CommandGenerator/CommandGenerator_Callback.res.mjs +1 -1
  15. package/src/components/CommandTopic/CommandTopic.res.mjs +9 -0
  16. package/src/components/CommandTopic/CommandTopic_Helpers.res +118 -33
  17. package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +137 -22
  18. package/src/components/Dcb/Dcb_Builder.res +16 -0
  19. package/src/components/Dcb/Dcb_Builder.res.mjs +6 -3
  20. package/src/components/InboundTranslationSlice/InboundTranslationSlice.res +3 -0
  21. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res +17 -6
  22. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res.mjs +46 -41
  23. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res +37 -8
  24. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +33 -13
  25. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res +3 -0
  26. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res.mjs +14 -2
  27. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice.res +3 -0
  28. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res +30 -9
  29. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +10 -5
  30. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +40 -2
  31. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +57 -11
  32. package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +4 -0
  33. package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +4 -4
  34. package/tests/commandtopic/CommandOutcomeLineTest.res.mjs +3 -3
  35. package/tests/commandtopic/CommandTopicHelpersRejectionTest.res +102 -0
  36. package/tests/commandtopic/CommandTopicHelpersRejectionTest.res.mjs +101 -3
  37. package/tests/plugin/PluginStructureAccessTest.res +6 -1
  38. package/tests/plugin/PluginStructureAccessTest.res.mjs +1 -1
@@ -18,18 +18,11 @@ is the JSON-stringified error payload (or empty string for payload-less variants
18
18
  */
19
19
  type rejectedResult = {errorCode: string, errorDetail: string}
20
20
 
21
- /**
22
- Why a command was refused.
23
-
24
- `DomainRejection` is `Decision.decide` returning `Error` — the model declining the command,
25
- which is the model working. `InfrastructureFailure` is the decision never landing: an event-log
26
- append that failed outright or exhausted its conflict retries. Both arrive on `reportRejected`,
27
- so without this a consumer would read a broken event log as a business rejection.
28
-
29
- `AccessRefusal` is the handler refusing before `decide` runs, because the caller does not
30
- own what the command acts on (`OwnerScope.decideActing`).
31
- */
32
- type refusalCause = DomainRejection | InfrastructureFailure | AccessRefusal
21
+ /** Why a command was refused; see `ReventlessInfra.CommandTopic.refusalCause`. */
22
+ type refusalCause = ReventlessInfra.CommandTopic.refusalCause =
23
+ | DomainRejection
24
+ | InfrastructureFailure
25
+ | AccessRefusal
33
26
 
34
27
  /** The `CommandRejectionCause` enum value a client sees for a cause. */
35
28
  let refusalCauseToGraphQL = (cause: refusalCause): string =>
@@ -58,6 +51,9 @@ type commandOutcomeReport = {
58
51
  when it sent the command. */
59
52
  causationId?: string,
60
53
  outcome: observedOutcome,
54
+ /** A refusal of a command the platform sent itself, which nobody waited on: no
55
+ person and no work item hears it. */
56
+ unheard?: bool,
61
57
  }
62
58
 
63
59
  type commandOutcomeHook = commandOutcomeReport => unit
@@ -110,15 +106,25 @@ let logOutcome = (r: commandOutcomeReport) => {
110
106
  ],
111
107
  )
112
108
  }
113
- EffectLogger.logInfo(
114
- ~comp=`CommandTopic(${r.component})`,
115
- ~ids={
116
- msgId: r.reference,
117
- correlationId: ?r.correlationId,
118
- causationId: ?r.causationId,
119
- },
120
- ~detail=JSON.Object(Dict.fromArray([("component", str(r.component))]->Array.concat(fields))),
121
- message,
109
+ let unheard = r.unheard->Option.getOr(false)
110
+ let ids: EffectLogger.ids = {
111
+ msgId: r.reference,
112
+ correlationId: ?r.correlationId,
113
+ causationId: ?r.causationId,
114
+ }
115
+ let detail = JSON.Object(
116
+ Dict.fromArray(
117
+ [("component", str(r.component))]
118
+ ->Array.concat(fields)
119
+ ->Array.concat(unheard ? [("unheard", JSON.Encode.bool(true))] : []),
120
+ ),
121
+ )
122
+ let comp = `CommandTopic(${r.component})`
123
+
124
+ (
125
+ unheard
126
+ ? EffectLogger.logWarn(~comp, ~ids, ~detail, `${message}, and nobody is told`)
127
+ : EffectLogger.logInfo(~comp, ~ids, ~detail, message)
122
128
  )->Effect.runSync
123
129
  }
124
130
 
@@ -135,9 +141,10 @@ let fireCommandOutcome = (
135
141
  ~reference: string,
136
142
  ~correlationId: option<string>=?,
137
143
  ~causationId: option<string>=?,
144
+ ~unheard: option<bool>=?,
138
145
  outcome: observedOutcome,
139
146
  ) => {
140
- let report = {component, reference, ?correlationId, ?causationId, outcome}
147
+ let report = {component, reference, ?correlationId, ?causationId, outcome, ?unheard}
141
148
  if outcomeLines.contents {
142
149
  try logOutcome(report) catch {
143
150
  | _ => ()
@@ -171,6 +178,15 @@ let acceptedResultChannel: ref<option<(string, acceptedResult) => unit>> = ref(N
171
178
  // to build `Rejected` outcomes that carry the real error code, detail and cause.
172
179
  let rejectedResultChannel: ref<option<(string, rejectedResult, refusalCause) => unit>> = ref(None)
173
180
 
181
+ /** Who is waiting inline for one command's outcome, keyed by its message id. Keyed
182
+ rather than one slot so two inline runs in one process, overlapping or nested,
183
+ each hear only their own commands. */
184
+ type inlineWaiter = {
185
+ onAccepted: acceptedResult => unit,
186
+ onRejected: (rejectedResult, refusalCause) => unit,
187
+ }
188
+ let inlineWaiters: dict<inlineWaiter> = Dict.make()
189
+
174
190
  /**
175
191
  Turn an `acting` verdict into the refusal a command handler reports, or `None` to let
176
192
  `decide` run.
@@ -219,6 +235,7 @@ let reportAccepted = (
219
235
  result: acceptedResult,
220
236
  ) => {
221
237
  acceptedResultChannel.contents->Option.forEach(cb => cb(reference, result))
238
+ inlineWaiters->Dict.get(reference)->Option.forEach(w => w.onAccepted(result))
222
239
  fireCommandOutcome(
223
240
  ~component,
224
241
  ~reference,
@@ -228,27 +245,40 @@ let reportAccepted = (
228
245
  )
229
246
  }
230
247
 
248
+ /** `~claimed` is whether the command carries a caller claim, as every command the
249
+ API generates does. A business or permission refusal of one without a claim that
250
+ nobody waits on inline is a refusal nobody hears: it is logged as a warning and
251
+ counted as `UnheardRefusal`. */
231
252
  let reportRejected = (
232
253
  ~component: string,
233
254
  ~cause: refusalCause,
234
255
  ~correlationId: option<string>=?,
235
256
  ~causationId: option<string>=?,
257
+ ~claimed: bool=true,
236
258
  reference: string,
237
259
  result: rejectedResult,
238
260
  ) => {
239
261
  rejectedResultChannel.contents->Option.forEach(cb => cb(reference, result, cause))
262
+ let waiter = inlineWaiters->Dict.get(reference)
263
+ waiter->Option.forEach(w => w.onRejected(result, cause))
264
+ // An infrastructure failure is not final: the queue delivers the command again.
265
+ let unheard = !claimed && waiter->Option.isNone && cause != InfrastructureFailure
266
+ if unheard {
267
+ Metrics.emitCount(~metric="UnheardRefusal", ~slice=component)
268
+ }
240
269
  fireCommandOutcome(
241
270
  ~component,
242
271
  ~reference,
243
272
  ~correlationId?,
244
273
  ~causationId?,
274
+ ~unheard,
245
275
  OutcomeRejected({errorCode: result.errorCode, errorDetail: result.errorDetail, cause}),
246
276
  )
247
277
  }
248
278
 
249
279
  // Placed here (rather than CommandTopic.res) so runInlineAndCollect can use commandOutcome
250
280
  // without importing Adapter.res → @pulumi/pulumi. Re-exported by CommandTopic via include.
251
- type commandOutcome =
281
+ type commandOutcome = ReventlessInfra.CommandTopic.commandOutcome =
252
282
  | Accepted({msgId: string, entityId?: string, eventCount: int})
253
283
  | Rejected({msgId: string, errorCode: string, errorDetail: option<string>, cause: refusalCause})
254
284
  | Pending({msgId: string})
@@ -288,7 +318,50 @@ let commandOutcomeToJson = (outcome: commandOutcome): JSON.t =>
288
318
  )
289
319
  }
290
320
 
291
- type publishJsonsAndWait = array<Reventless.Message.commandJson> => promise<array<commandOutcome>>
321
+ /** `commandOutcomeToJson` read back, for a caller that got the outcome over the wire.
322
+ `None` for a shape it does not write. */
323
+ let commandOutcomeOfJson = (json: JSON.t): option<commandOutcome> => {
324
+ let fields = json->JSON.Decode.object->Option.getOr(Dict.make())
325
+ let str = key => fields->Dict.get(key)->Option.flatMap(JSON.Decode.string)
326
+ switch (str("__typename"), str("msgId")) {
327
+ | (Some("CommandAccepted"), Some(msgId)) =>
328
+ Some(
329
+ Accepted({
330
+ msgId,
331
+ entityId: ?str("entityId"),
332
+ eventCount: fields
333
+ ->Dict.get("eventCount")
334
+ ->Option.flatMap(JSON.Decode.float)
335
+ ->Option.mapOr(0, Float.toInt),
336
+ }),
337
+ )
338
+ | (Some("CommandRejected"), Some(msgId)) =>
339
+ let cause = switch str("cause") {
340
+ | Some("DOMAIN") => DomainRejection
341
+ | Some("ACCESS") => AccessRefusal
342
+ | _ => InfrastructureFailure
343
+ }
344
+ Some(
345
+ Rejected({
346
+ msgId,
347
+ errorCode: str("errorCode")->Option.getOr(""),
348
+ errorDetail: str("errorDetail"),
349
+ cause,
350
+ }),
351
+ )
352
+ | (Some("CommandPending"), Some(msgId)) => Some(Pending({msgId: msgId}))
353
+ | _ => None
354
+ }
355
+ }
356
+
357
+ type publishJsonsAndWait = ReventlessInfra.CommandTopic.publishJsonsAndWait
358
+
359
+ /** A refusal as one line for a work item's `lastError`: the code, then the detail. */
360
+ let describeRefusal = (~errorCode: string, ~errorDetail: option<string>) =>
361
+ switch errorDetail {
362
+ | Some(detail) if detail != "" => `${errorCode}: ${detail}`
363
+ | _ => errorCode
364
+ }
292
365
 
293
366
  // Encode the full message body expected by CommandTopic_Callback: {id, meta, command}.
294
367
  // Shared by LocalCommandTopicChannel and CommandTopicChannel_SQS_Sync.
@@ -301,7 +374,7 @@ let encodeCommandJson = (cmdJson: Reventless.Message.commandJson): JSON.t =>
301
374
  ]),
302
375
  )
303
376
 
304
- // Runs handleCmds inline, manages the acceptedResultChannel side-channel, and maps
377
+ // Runs handleCmds inline, waits on each command's outcome by its message id, and maps
305
378
  // results to commandOutcome. Shared by LocalCommandTopicChannel and CommandTopicChannel_SQS_Sync.
306
379
  let runInlineAndCollect = async (
307
380
  jsons: array<Reventless.Message.commandJson>,
@@ -314,15 +387,27 @@ let runInlineAndCollect = async (
314
387
  })
315
388
  let acceptedResults: dict<acceptedResult> = Dict.make()
316
389
  let rejectedResults: dict<(rejectedResult, refusalCause)> = Dict.make()
317
- acceptedResultChannel.contents = Some(
318
- (reference, result) => acceptedResults->Dict.set(reference, result),
319
- )
320
- rejectedResultChannel.contents = Some(
321
- (reference, result, cause) => rejectedResults->Dict.set(reference, (result, cause)),
390
+ let references = items->Array.map(item => item.reference)
391
+ references->Array.forEach(reference =>
392
+ inlineWaiters->Dict.set(
393
+ reference,
394
+ {
395
+ onAccepted: result => acceptedResults->Dict.set(reference, result),
396
+ onRejected: (result, cause) => rejectedResults->Dict.set(reference, (result, cause)),
397
+ },
398
+ )
322
399
  )
323
- let results = await handleCmds(Stream.fromIterable(items))->Effect.runPromise
324
- acceptedResultChannel.contents = None
325
- rejectedResultChannel.contents = None
400
+ let stopWaiting = () =>
401
+ references->Array.forEach(reference => inlineWaiters->Dict.delete(reference))
402
+ let results = try await handleCmds(Stream.fromIterable(items))->Effect.runPromise catch {
403
+ | JsExn(e) =>
404
+ stopWaiting()
405
+ JsExn.throw(e)
406
+ | exn =>
407
+ stopWaiting()
408
+ throw(exn)
409
+ }
410
+ stopWaiting()
326
411
  jsons->Array.mapWithIndex((cmdJson, i) => {
327
412
  let msgId = cmdJson.meta.msgId
328
413
  // A reported rejection takes precedence over both Accepted and the
@@ -1,6 +1,8 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
3
  import * as Effect from "@reventlessdev/rescript-effect/src/Effect.res.mjs";
4
+ import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
5
+ import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
4
6
  import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
5
7
  import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
6
8
  import * as Stream from "effect/Stream";
@@ -8,6 +10,7 @@ import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/component
8
10
  import * as Message$Reventless from "@reventlessdev/reventless-spec/src/types/Message.res.mjs";
9
11
  import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
10
12
  import * as Util_Sury$Reventless from "@reventlessdev/reventless-spec/src/util/Util_Sury.res.mjs";
13
+ import * as Metrics$ReventlessCore from "../../util/Metrics.res.mjs";
11
14
  import * as CommandOutcome$Reventless from "@reventlessdev/reventless-spec/src/components/CommandOutcome.res.mjs";
12
15
  import * as EffectLogger$ReventlessCore from "../../util/EffectLogger.res.mjs";
13
16
 
@@ -85,23 +88,35 @@ function logOutcome(r) {
85
88
  ]
86
89
  ]
87
90
  ];
88
- Effect.runSync(EffectLogger$ReventlessCore.logInfo(`CommandTopic(` + r.component + `)`, Object.fromEntries([[
91
+ let message = match$1[0];
92
+ let unheard = Stdlib_Option.getOr(r.unheard, false);
93
+ let ids_msgId = r.reference;
94
+ let ids_correlationId = r.correlationId;
95
+ let ids_causationId = r.causationId;
96
+ let ids = {
97
+ msgId: ids_msgId,
98
+ correlationId: ids_correlationId,
99
+ causationId: ids_causationId
100
+ };
101
+ let detail = Object.fromEntries([[
89
102
  "component",
90
103
  r.component
91
- ]].concat(match$1[1])), {
92
- msgId: r.reference,
93
- correlationId: r.correlationId,
94
- causationId: r.causationId
95
- }, match$1[0]));
104
+ ]].concat(match$1[1]).concat(unheard ? [[
105
+ "unheard",
106
+ true
107
+ ]] : []));
108
+ let comp = `CommandTopic(` + r.component + `)`;
109
+ Effect.runSync(unheard ? EffectLogger$ReventlessCore.logWarn(comp, detail, ids, message + `, and nobody is told`) : EffectLogger$ReventlessCore.logInfo(comp, detail, ids, message));
96
110
  }
97
111
 
98
- function fireCommandOutcome(component, reference, correlationId, causationId, outcome) {
112
+ function fireCommandOutcome(component, reference, correlationId, causationId, unheard, outcome) {
99
113
  let report = {
100
114
  component: component,
101
115
  reference: reference,
102
116
  correlationId: correlationId,
103
117
  causationId: causationId,
104
- outcome: outcome
118
+ outcome: outcome,
119
+ unheard: unheard
105
120
  };
106
121
  if (outcomeLines.contents) {
107
122
  try {
@@ -133,6 +148,8 @@ let rejectedResultChannel = {
133
148
  contents: undefined
134
149
  };
135
150
 
151
+ let inlineWaiters = {};
152
+
136
153
  function ownershipRefusal(verdict, component, command) {
137
154
  let refuse = (isDefectOpt, why) => {
138
155
  let isDefect = isDefectOpt !== undefined ? isDefectOpt : false;
@@ -163,16 +180,24 @@ function ownershipRefusal(verdict, component, command) {
163
180
 
164
181
  function reportAccepted(component, correlationId, causationId, reference, result) {
165
182
  Stdlib_Option.forEach(acceptedResultChannel.contents, cb => cb(reference, result));
166
- fireCommandOutcome(component, reference, correlationId, causationId, {
183
+ Stdlib_Option.forEach(inlineWaiters[reference], w => w.onAccepted(result));
184
+ fireCommandOutcome(component, reference, correlationId, causationId, undefined, {
167
185
  TAG: "OutcomeAccepted",
168
186
  entityId: result.entityId,
169
187
  eventCount: result.eventCount
170
188
  });
171
189
  }
172
190
 
173
- function reportRejected(component, cause, correlationId, causationId, reference, result) {
191
+ function reportRejected(component, cause, correlationId, causationId, claimedOpt, reference, result) {
192
+ let claimed = claimedOpt !== undefined ? claimedOpt : true;
174
193
  Stdlib_Option.forEach(rejectedResultChannel.contents, cb => cb(reference, result, cause));
175
- fireCommandOutcome(component, reference, correlationId, causationId, {
194
+ let waiter = inlineWaiters[reference];
195
+ Stdlib_Option.forEach(waiter, w => w.onRejected(result, cause));
196
+ let unheard = !claimed && Stdlib_Option.isNone(waiter) && cause !== "InfrastructureFailure";
197
+ if (unheard) {
198
+ Metrics$ReventlessCore.emitCount("UnheardRefusal", component, undefined);
199
+ }
200
+ fireCommandOutcome(component, reference, correlationId, causationId, unheard, {
176
201
  TAG: "OutcomeRejected",
177
202
  errorCode: result.errorCode,
178
203
  errorDetail: result.errorDetail,
@@ -238,6 +263,75 @@ function commandOutcomeToJson(outcome) {
238
263
  }
239
264
  }
240
265
 
266
+ function commandOutcomeOfJson(json) {
267
+ let fields = Stdlib_Option.getOr(Stdlib_JSON.Decode.object(json), {});
268
+ let str = key => Stdlib_Option.flatMap(fields[key], Stdlib_JSON.Decode.string);
269
+ let match = str("__typename");
270
+ let match$1 = str("msgId");
271
+ if (match === undefined) {
272
+ return;
273
+ }
274
+ switch (match) {
275
+ case "CommandAccepted" :
276
+ if (match$1 !== undefined) {
277
+ return {
278
+ TAG: "Accepted",
279
+ msgId: match$1,
280
+ entityId: str("entityId"),
281
+ eventCount: Stdlib_Option.mapOr(Stdlib_Option.flatMap(fields["eventCount"], Stdlib_JSON.Decode.float), 0, prim => prim | 0)
282
+ };
283
+ } else {
284
+ return;
285
+ }
286
+ case "CommandPending" :
287
+ if (match$1 !== undefined) {
288
+ return {
289
+ TAG: "Pending",
290
+ msgId: match$1
291
+ };
292
+ } else {
293
+ return;
294
+ }
295
+ case "CommandRejected" :
296
+ if (match$1 === undefined) {
297
+ return;
298
+ }
299
+ let match$2 = str("cause");
300
+ let cause;
301
+ if (match$2 !== undefined) {
302
+ switch (match$2) {
303
+ case "ACCESS" :
304
+ cause = "AccessRefusal";
305
+ break;
306
+ case "DOMAIN" :
307
+ cause = "DomainRejection";
308
+ break;
309
+ default:
310
+ cause = "InfrastructureFailure";
311
+ }
312
+ } else {
313
+ cause = "InfrastructureFailure";
314
+ }
315
+ return {
316
+ TAG: "Rejected",
317
+ msgId: match$1,
318
+ errorCode: Stdlib_Option.getOr(str("errorCode"), ""),
319
+ errorDetail: str("errorDetail"),
320
+ cause: cause
321
+ };
322
+ default:
323
+ return;
324
+ }
325
+ }
326
+
327
+ function describeRefusal(errorCode, errorDetail) {
328
+ if (errorDetail !== undefined && errorDetail !== "") {
329
+ return errorCode + `: ` + errorDetail;
330
+ } else {
331
+ return errorCode;
332
+ }
333
+ }
334
+
241
335
  function encodeCommandJson(cmdJson) {
242
336
  return Object.fromEntries([
243
337
  [
@@ -265,18 +359,36 @@ async function runInlineAndCollect(jsons, handleCmds) {
265
359
  });
266
360
  let acceptedResults = {};
267
361
  let rejectedResults = {};
268
- acceptedResultChannel.contents = (reference, result) => {
269
- acceptedResults[reference] = result;
270
- };
271
- rejectedResultChannel.contents = (reference, result, cause) => {
272
- rejectedResults[reference] = [
273
- result,
274
- cause
275
- ];
362
+ let references = items.map(item => item.reference);
363
+ references.forEach(reference => {
364
+ inlineWaiters[reference] = {
365
+ onAccepted: result => {
366
+ acceptedResults[reference] = result;
367
+ },
368
+ onRejected: (result, cause) => {
369
+ rejectedResults[reference] = [
370
+ result,
371
+ cause
372
+ ];
373
+ }
374
+ };
375
+ });
376
+ let stopWaiting = () => {
377
+ references.forEach(reference => Stdlib_Dict.$$delete(inlineWaiters, reference));
276
378
  };
277
- let results = await Effect.runPromise(handleCmds(Stream.fromIterable(items)));
278
- acceptedResultChannel.contents = undefined;
279
- rejectedResultChannel.contents = undefined;
379
+ let results;
380
+ try {
381
+ results = await Effect.runPromise(handleCmds(Stream.fromIterable(items)));
382
+ } catch (raw_e) {
383
+ let e = Primitive_exceptions.internalToException(raw_e);
384
+ if (e.RE_EXN_ID === "JsExn") {
385
+ stopWaiting();
386
+ throw e._1;
387
+ }
388
+ stopWaiting();
389
+ throw e;
390
+ }
391
+ stopWaiting();
280
392
  return jsons.map((cmdJson, i) => {
281
393
  let msgId = cmdJson.meta.msgId;
282
394
  let match = rejectedResults[msgId];
@@ -356,10 +468,13 @@ export {
356
468
  fireCommandOutcome,
357
469
  acceptedResultChannel,
358
470
  rejectedResultChannel,
471
+ inlineWaiters,
359
472
  ownershipRefusal,
360
473
  reportAccepted,
361
474
  reportRejected,
362
475
  commandOutcomeToJson,
476
+ commandOutcomeOfJson,
477
+ describeRefusal,
363
478
  encodeCommandJson,
364
479
  runInlineAndCollect,
365
480
  callHandlerWithArray,
@@ -467,6 +467,11 @@ module Make = (
467
467
  dcbCommandTopic
468
468
  ->Component.operations
469
469
  ->Pulumi.Output.apply(ops => ops.publishJsons)
470
+ // Lets an automation or a translation hear a sync slice's refusal.
471
+ let publishJsonsAndWait =
472
+ dcbCommandTopic
473
+ ->Component.operations
474
+ ->Pulumi.Output.apply(ops => ops.publishJsonsAndWait)
470
475
 
471
476
  // Create FIFO CommandTopic for async StateChangeSlices (only if any are configured)
472
477
  module DcbCommandTopicSpecAsync = {
@@ -713,6 +718,7 @@ module Make = (
713
718
  let as_ = AutoSlice.make(
714
719
  ~allEventTopics,
715
720
  ~publishJsons,
721
+ ~publishJsonsAndWait,
716
722
  ~context,
717
723
  ~runtime=?componentRuntime->Dict.get(AutoSlice.Spec.name),
718
724
  ~opts,
@@ -733,6 +739,14 @@ module Make = (
733
739
  OTS.Spec.targetName
734
740
  ->Option.flatMap(target => publishToAggregates->Dict.get(target))
735
741
  ->Option.getOr(publishJsons)
742
+ // An aggregate's topic offers no waiting publish here, so only the DCB
743
+ // topic's outcomes are heard.
744
+ let targetPublishJsonsAndWait = switch OTS.Spec.targetName->Option.flatMap(target =>
745
+ publishToAggregates->Dict.get(target)
746
+ ) {
747
+ | Some(_) => Pulumi.Output.make(None)
748
+ | None => publishJsonsAndWait
749
+ }
736
750
 
737
751
  let ots = OTS.make(
738
752
  ~dcbEventLog,
@@ -740,6 +754,7 @@ module Make = (
740
754
  // name an Aggregate source by its Spec.name.
741
755
  ~allEventTopics,
742
756
  ~publishJsons=targetPublishJsons,
757
+ ~publishJsonsAndWait=targetPublishJsonsAndWait,
743
758
  ~runtime=?componentRuntime->Dict.get(OTS.Spec.name),
744
759
  ~opts,
745
760
  )
@@ -752,6 +767,7 @@ module Make = (
752
767
  inboundTranslationSlices->Array.map((module(ITS: InboundTranslationSlice.T)) => {
753
768
  let its = ITS.make(
754
769
  ~publishJsons,
770
+ ~publishJsonsAndWait,
755
771
  ~runtime=?componentRuntime->Dict.get(ITS.Spec.name),
756
772
  ~opts,
757
773
  )
@@ -258,6 +258,7 @@ function Make(DcbEventLogStorage) {
258
258
  }, opts);
259
259
  Stdlib_Option.forEach(HooksConfig.hooks.onDcbCommandTopicCreated, hook => hook(dcbCommandTopic));
260
260
  let publishJsons = Component$ReventlessCore.operations(dcbCommandTopic).apply(ops => ops.publishJsons);
261
+ let publishJsonsAndWait = Component$ReventlessCore.operations(dcbCommandTopic).apply(ops => ops.publishJsonsAndWait);
261
262
  let name$1 = childName + "Async";
262
263
  let commandSchema$1 = Sury.json;
263
264
  let DcbAsyncCommandTopic = CommandTopic_Builder$ReventlessCore.Make({
@@ -387,7 +388,7 @@ function Make(DcbEventLogStorage) {
387
388
  pluginName: name,
388
389
  sliceName: context_sliceName
389
390
  };
390
- let as_ = AutoSlice.make(allEventTopics, publishJsons, context, componentRuntime[AutoSlice.Spec.name], opts);
391
+ let as_ = AutoSlice.make(allEventTopics, publishJsons, publishJsonsAndWait, context, componentRuntime[AutoSlice.Spec.name], opts);
391
392
  return [
392
393
  AutoSlice.Spec.name,
393
394
  Component$ReventlessCore.outputs(as_)
@@ -395,14 +396,16 @@ function Make(DcbEventLogStorage) {
395
396
  }));
396
397
  let outboundTranslationSlicesOutputs = Object.fromEntries(outboundTranslationSlices.map(OTS => {
397
398
  let targetPublishJsons = Stdlib_Option.getOr(Stdlib_Option.flatMap(OTS.Spec.targetName, target => publishToAggregates[target]), publishJsons);
398
- let ots = OTS.make(dcbEventLog, allEventTopics, targetPublishJsons, componentRuntime[OTS.Spec.name], opts);
399
+ let match = Stdlib_Option.flatMap(OTS.Spec.targetName, target => publishToAggregates[target]);
400
+ let targetPublishJsonsAndWait = match !== undefined ? Pulumi.output(undefined) : publishJsonsAndWait;
401
+ let ots = OTS.make(dcbEventLog, allEventTopics, targetPublishJsons, targetPublishJsonsAndWait, componentRuntime[OTS.Spec.name], opts);
399
402
  return [
400
403
  OTS.Spec.name,
401
404
  Component$ReventlessCore.outputs(ots)
402
405
  ];
403
406
  }));
404
407
  let inboundTranslationSliceData = inboundTranslationSlices.map(ITS => {
405
- let its = ITS.make(publishJsons, componentRuntime[ITS.Spec.name], opts);
408
+ let its = ITS.make(publishJsons, publishJsonsAndWait, componentRuntime[ITS.Spec.name], opts);
406
409
  let fieldName = Api_Naming$ReventlessCore.sliceMutationField(name, ITS.Spec.name);
407
410
  let exposed = InboundTranslationSlice_Callback$ReventlessCore.exposesMutation(ITS.Spec.externalInputSchema);
408
411
  InboundTranslationSlice_Callback$ReventlessCore.checkReachable(name, ITS.Spec.name, exposed, Stdlib_Option.isSome(ITS.Spec.endpoint));
@@ -31,6 +31,9 @@ module type T = {
31
31
 
32
32
  let make: (
33
33
  ~publishJsons: Pulumi.Output.t<CommandTopic.publishJsons>,
34
+ /** The target's publish that waits for each command's outcome, where its topic
35
+ offers one; the caller then hears the target's refusal. */
36
+ ~publishJsonsAndWait: Pulumi.Output.t<option<CommandTopic.publishJsonsAndWait>>=?,
34
37
  ~runtime: ReventlessInfra.RuntimeHints.t=?,
35
38
  ~opts: Pulumi.ComponentResource.options=?,
36
39
  ) => component
@@ -67,7 +67,12 @@ module Make = (
67
67
  | None => ()
68
68
  }
69
69
 
70
- let construct = (~publishJsons, self, _name) => {
70
+ let construct = (
71
+ ~publishJsons,
72
+ ~publishJsonsAndWait: Pulumi.Output.t<option<CommandTopic.publishJsonsAndWait>>,
73
+ self,
74
+ _name,
75
+ ) => {
71
76
  let opts = {Pulumi.ComponentResource.parent: self->Component.toPulumiResource}
72
77
 
73
78
  let queryDb = SpecificQueryDb.make(
@@ -84,15 +89,16 @@ module Make = (
84
89
  })
85
90
 
86
91
  self->Component.setOperations(
87
- (queryDb->Component.operations, publishJsons)
88
- ->Pulumi.Output.all2
89
- ->Pulumi.Output.apply(((queryDbOps, publishJsonsFn)) => {
92
+ (queryDb->Component.operations, publishJsons, publishJsonsAndWait)
93
+ ->Pulumi.Output.all3
94
+ ->Pulumi.Output.apply(((queryDbOps, publishJsonsFn, publishJsonsAndWait)) => {
90
95
  let ops: InboundTranslationSlice.operations = {
91
96
  receive: async (inputJson, ~caller=?, ~door=?) => {
92
97
  let result = await Callback.receive(
93
98
  publishJsonsFn,
94
99
  inputJson,
95
100
  ~capabilities=Capabilities.capabilities(),
101
+ ~publishJsonsAndWait?,
96
102
  ~caller?,
97
103
  ~door?,
98
104
  )
@@ -119,11 +125,16 @@ module Make = (
119
125
  // InboundTranslationSlice publishes commands + syncs its QueryDb inline; it
120
126
  // provisions no per-slice runtime environment, so the runtime hint is accepted
121
127
  // (for composition-surface parity) and discarded.
122
- let make = (~publishJsons, ~runtime as _=?, ~opts=?): InboundTranslationSlice.component =>
128
+ let make = (
129
+ ~publishJsons,
130
+ ~publishJsonsAndWait=Pulumi.Output.make(None),
131
+ ~runtime as _=?,
132
+ ~opts=?,
133
+ ): InboundTranslationSlice.component =>
123
134
  Component.make(
124
135
  ~componentType=InboundTranslationSlice.componentType->ComponentType.toString,
125
136
  ~name=Spec.name,
126
- ~construct=construct(~publishJsons, ...),
137
+ ~construct=construct(~publishJsons, ~publishJsonsAndWait, ...),
127
138
  ~opts,
128
139
  )
129
140
  }