@empyria/restate 0.1.12 → 0.1.14

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/lib/Admin.js CHANGED
@@ -193,9 +193,19 @@ export async function listHandlers({ restateAdminURL, name }) {
193
193
  */
194
194
 
195
195
  /**
196
- * Starts a sub-workflow and returns a handle to the invocation.
196
+ * Starts a sub-workflow and returns a handle to the invocation. Submitting against a
197
+ * `workflowKey` that already has a running or completed workflow is a safe no-op on
198
+ * Restate's side (see the SDK's own workflow-submission semantics) — this is the
199
+ * idiomatic "start if absent, otherwise leave it alone" primitive for a long-running,
200
+ * once-per-key workflow, not just a plain fire-and-forget call.
197
201
  * @template P
198
- * @param {import('@restatedev/restate-sdk').WorkflowContext} ctx Existing workflow context
202
+ * @param {import('@restatedev/restate-sdk').Context} ctx Restate context of the CALLING
203
+ * handler — any handler type works here (plain service, virtual object, or another
204
+ * workflow), not just a workflow's own context. This only needs `ctx.genericSend`,
205
+ * which every Context exposes (declared on the base `Context` interface, not
206
+ * `WorkflowContext` — verified against the SDK's own type declarations); the earlier
207
+ * `WorkflowContext` annotation here reflected this repo's own usages so far
208
+ * (workflow-starts-sub-workflow), not an actual restriction.
199
209
  * @param {string} workflowName name of the workflow to start
200
210
  * @param {string} workflowKey key of the workflow instance to start
201
211
  * @param {P} payload payload to pass to the workflow
@@ -215,7 +225,10 @@ export function startSubWorkflow(ctx, workflowName, workflowKey, payload) {
215
225
  * Executes a sub-workflow and returns a promise resolving to the result.
216
226
  * @template P
217
227
  * @template [R=unknown]
218
- * @param {import('@restatedev/restate-sdk').WorkflowContext} ctx Existing workflow context
228
+ * @param {import('@restatedev/restate-sdk').Context} ctx Restate context of the CALLING
229
+ * handler — any handler type works here (plain service, virtual object, or another
230
+ * workflow); see {@link startSubWorkflow}'s own doc for why `Context`, not
231
+ * `WorkflowContext`, is the accurate type.
219
232
  * @param {string} workflowName name of the workflow to execute
220
233
  * @param {string} workflowKey key of the workflow instance to execute
221
234
  * @param {P} payload payload to pass to the workflow
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empyria/restate",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "Restate.dev helpers for the Empyria nanoservice framework",
5
5
  "license": "MIT",
6
6
  "author": "Imre Fazekas <imre.fazekas@icloud.com>",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@empyria/classification": "0.1.6",
28
- "@empyria/common": "0.3.0",
28
+ "@empyria/common": "0.3.1",
29
29
  "@restatedev/pubsub": "0.3.2",
30
30
  "@restatedev/pubsub-client": "0.3.2",
31
31
  "@restatedev/restate-sdk": "1.17.0",
@@ -34,9 +34,9 @@
34
34
  "croner": "10.0.1"
35
35
  },
36
36
  "devDependencies": {
37
- "@restatedev/restate-server": "1.7.9",
38
- "oxfmt": "0.67.0",
39
- "oxlint": "1.82.0"
37
+ "@restatedev/restate-server": "1.7.10",
38
+ "oxfmt": "0.68.0",
39
+ "oxlint": "1.83.0"
40
40
  },
41
41
  "engines": {
42
42
  "bun": ">=1.4.2",
@@ -136,6 +136,25 @@ describe('startSubWorkflow / callSubWorkflow', () => {
136
136
  expect(calledArgs.key).toBe('wf-key-2')
137
137
  expect(result).toEqual({ done: true })
138
138
  })
139
+
140
+ // Both functions only need `ctx.genericSend`/`ctx.genericCall`, which the SDK declares on
141
+ // the base Context interface — every handler type has it, not just a workflow's own
142
+ // context. Named explicitly (not just "a ctx mock", like the two tests above already are)
143
+ // to document that calling these from a plain, unkeyed `restate.service` handler — e.g. to
144
+ // idempotently start a long-running workflow the moment that service first learns the
145
+ // workflow's key exists — is a supported, intended use, not an incidental side effect of
146
+ // duck typing.
147
+ test('startSubWorkflow works from a plain (non-workflow) service context', () => {
148
+ let sentArgs
149
+ /** @type {import('@restatedev/restate-sdk').Context} */
150
+ const plainServiceCtx = { genericSend: (args) => (sentArgs = args) ?? 'handle' }
151
+ startSubWorkflow(plainServiceCtx, 'CorporateActionWorkflow', 'CA08841DVCA26', {
152
+ triggeredBy: 'swift-upstream-sort',
153
+ })
154
+ expect(sentArgs.service).toBe('CorporateActionWorkflow')
155
+ expect(sentArgs.method).toBe('run')
156
+ expect(sentArgs.key).toBe('CA08841DVCA26')
157
+ })
139
158
  })
140
159
 
141
160
  describe('listServices', () => {