@restatedev/restate-sdk-gen 1.16.8 → 1.17.0

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.cjs CHANGED
@@ -31,10 +31,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
31
31
  //#endregion
32
32
  let __restatedev_restate_sdk = require("@restatedev/restate-sdk");
33
33
  __restatedev_restate_sdk = __toESM(__restatedev_restate_sdk);
34
- let __restatedev_restate_sdk_clients = require("@restatedev/restate-sdk-clients");
35
- __restatedev_restate_sdk_clients = __toESM(__restatedev_restate_sdk_clients);
36
34
  let __restatedev_restate_sdk_core = require("@restatedev/restate-sdk-core");
37
35
  __restatedev_restate_sdk_core = __toESM(__restatedev_restate_sdk_core);
36
+ let __restatedev_restate_sdk_clients = require("@restatedev/restate-sdk-clients");
37
+ __restatedev_restate_sdk_clients = __toESM(__restatedev_restate_sdk_clients);
38
38
 
39
39
  //#region src/current.ts
40
40
  let CURRENT = null;
@@ -79,11 +79,11 @@ var InvocationReferenceImpl = class {
79
79
  this.id = id;
80
80
  this._outputSerde = _outputSerde;
81
81
  }
82
- attach(serde$1) {
83
- return getCurrent().attach(this.id, serde$1 ?? this._outputSerde);
82
+ attach(serde$2) {
83
+ return getCurrent().attach(this.id, serde$2 ?? this._outputSerde);
84
84
  }
85
- signal(name, serde$1) {
86
- return getCurrent().invocationSignal(this.id, name, serde$1);
85
+ signal(name, serde$2) {
86
+ return getCurrent().invocationSignal(this.id, name, serde$2);
87
87
  }
88
88
  cancel() {
89
89
  getCurrent().cancel(this.id);
@@ -120,11 +120,11 @@ const handlerRequest = () => currentOps().handlerRequest();
120
120
  */
121
121
  const run = (action, opts) => currentOps().run(action, opts);
122
122
  const sleep = (duration, name) => currentOps().sleep(duration, name);
123
- const awakeable = (serde$1) => currentOps().awakeable(serde$1);
124
- const resolveAwakeable = (id, payload, serde$1) => currentOps().resolveAwakeable(id, payload, serde$1);
123
+ const awakeable = (serde$2) => currentOps().awakeable(serde$2);
124
+ const resolveAwakeable = (id, payload, serde$2) => currentOps().resolveAwakeable(id, payload, serde$2);
125
125
  const rejectAwakeable = (id, reason) => currentOps().rejectAwakeable(id, reason);
126
- const signal = (name, serde$1) => currentOps().signal(name, serde$1);
127
- const attach = (invocationId, serde$1) => currentOps().attach(invocationId, serde$1);
126
+ const signal = (name, serde$2) => currentOps().signal(name, serde$2);
127
+ const attach = (invocationId, serde$2) => currentOps().attach(invocationId, serde$2);
128
128
  function client(def, key) {
129
129
  return currentOps().client(def, key);
130
130
  }
@@ -155,7 +155,7 @@ const cancel = (invocationId) => currentOps().cancel(invocationId);
155
155
  const channel = () => currentOps().channel();
156
156
  const state = () => currentOps().state();
157
157
  const sharedState = () => currentOps().sharedState();
158
- const workflowPromise = (name, serde$1) => currentOps().workflowPromise(name, serde$1);
158
+ const workflowPromise = (name, serde$2) => currentOps().workflowPromise(name, serde$2);
159
159
  /**
160
160
  * Wait for every future to settle; return their values in input order.
161
161
  * Heterogeneous-tuple typing — `all([fA, fB])` where `fA: Future<A>`
@@ -1091,14 +1091,14 @@ var Scheduler = class {
1091
1091
  function makeState(ctx, sched, adapt$1) {
1092
1092
  const writeCtx = ctx;
1093
1093
  return {
1094
- get(name, serde$1) {
1095
- return sched.makeJournalFuture(adapt$1(ctx.get(name, serde$1)));
1094
+ get(name, serde$2) {
1095
+ return sched.makeJournalFuture(adapt$1(ctx.get(name, serde$2)));
1096
1096
  },
1097
1097
  keys() {
1098
1098
  return sched.makeJournalFuture(adapt$1(ctx.stateKeys()));
1099
1099
  },
1100
- set(name, value, serde$1) {
1101
- writeCtx.set(name, value, serde$1);
1100
+ set(name, value, serde$2) {
1101
+ writeCtx.set(name, value, serde$2);
1102
1102
  },
1103
1103
  clear(name) {
1104
1104
  writeCtx.clear(name);
@@ -1114,7 +1114,7 @@ function makeState(ctx, sched, adapt$1) {
1114
1114
  function makeClient(def, key, call$1, scope$2) {
1115
1115
  return new Proxy({}, { get(_target, methodName) {
1116
1116
  return (...args) => {
1117
- const { parameter, opts } = optsFromArgs$1(args);
1117
+ const { parameter, opts } = optsFromArgs(args);
1118
1118
  const callOpts = opts;
1119
1119
  const desc = def._handlers[methodName];
1120
1120
  const outputSerde = callOpts?.output ?? desc?._outputSerde;
@@ -1137,7 +1137,7 @@ function makeClient(def, key, call$1, scope$2) {
1137
1137
  function makeSendClient(def, key, send$1, scope$2) {
1138
1138
  return new Proxy({}, { get(_target, methodName) {
1139
1139
  return (...args) => {
1140
- const { parameter, opts } = optsFromArgs$1(args);
1140
+ const { parameter, opts } = optsFromArgs(args);
1141
1141
  const sendOpts = opts;
1142
1142
  const desc = def._handlers[methodName];
1143
1143
  return send$1({
@@ -1156,7 +1156,7 @@ function makeSendClient(def, key, send$1, scope$2) {
1156
1156
  };
1157
1157
  } });
1158
1158
  }
1159
- function optsFromArgs$1(args) {
1159
+ function optsFromArgs(args) {
1160
1160
  let parameter;
1161
1161
  let opts;
1162
1162
  switch (args.length) {
@@ -1355,24 +1355,24 @@ var RestateOperations = class {
1355
1355
  sleep(duration, name) {
1356
1356
  return this.sched.makeJournalFuture(adapt(this.ctx.sleep(duration, name)));
1357
1357
  }
1358
- awakeable(serde$1) {
1359
- const { id, promise } = this.ctx.awakeable(serde$1);
1358
+ awakeable(serde$2) {
1359
+ const { id, promise } = this.ctx.awakeable(serde$2);
1360
1360
  return {
1361
1361
  id,
1362
1362
  promise: this.sched.makeJournalFuture(adapt(promise))
1363
1363
  };
1364
1364
  }
1365
- resolveAwakeable(id, payload, serde$1) {
1366
- this.ctx.resolveAwakeable(id, payload, serde$1);
1365
+ resolveAwakeable(id, payload, serde$2) {
1366
+ this.ctx.resolveAwakeable(id, payload, serde$2);
1367
1367
  }
1368
1368
  rejectAwakeable(id, reason) {
1369
1369
  this.ctx.rejectAwakeable(id, reason);
1370
1370
  }
1371
- signal(name, serde$1) {
1372
- return this.sched.makeJournalFuture(adapt(this.ctx.signal(name, serde$1)));
1371
+ signal(name, serde$2) {
1372
+ return this.sched.makeJournalFuture(adapt(this.ctx.signal(name, serde$2)));
1373
1373
  }
1374
- attach(invocationId, serde$1) {
1375
- return this.sched.makeJournalFuture(adapt(this.ctx.attach(invocationId, serde$1)));
1374
+ attach(invocationId, serde$2) {
1375
+ return this.sched.makeJournalFuture(adapt(this.ctx.attach(invocationId, serde$2)));
1376
1376
  }
1377
1377
  /**
1378
1378
  * Returns the current invocation's request metadata plus the optional
@@ -1401,7 +1401,7 @@ var RestateOperations = class {
1401
1401
  return makeClient(def, key, (o) => this.call(o));
1402
1402
  }
1403
1403
  sendClient(def, key) {
1404
- return makeSendClient(def, key, (o, serde$1) => this.send(o, serde$1));
1404
+ return makeSendClient(def, key, (o, serde$2) => this.send(o, serde$2));
1405
1405
  }
1406
1406
  /**
1407
1407
  * Route all outgoing calls/sends through a named scope.
@@ -1423,7 +1423,7 @@ var RestateOperations = class {
1423
1423
  scope(scopeKey) {
1424
1424
  return {
1425
1425
  client: (def, key) => makeClient(def, key, (o) => this.call(o), scopeKey),
1426
- sendClient: (def, key) => makeSendClient(def, key, (o, serde$1) => this.send(o, serde$1), scopeKey)
1426
+ sendClient: (def, key) => makeSendClient(def, key, (o, serde$2) => this.send(o, serde$2), scopeKey)
1427
1427
  };
1428
1428
  }
1429
1429
  call(opts) {
@@ -1442,8 +1442,8 @@ var RestateOperations = class {
1442
1442
  return new InvocationReferenceImpl(yield* idFuture, outputSerde);
1443
1443
  }));
1444
1444
  }
1445
- invocationSignal(invocationId, name, serde$1) {
1446
- return this.ctx.invocation(invocationId).signal(name, serde$1);
1445
+ invocationSignal(invocationId, name, serde$2) {
1446
+ return this.ctx.invocation(invocationId).signal(name, serde$2);
1447
1447
  }
1448
1448
  /**
1449
1449
  * Cancel another invocation by its id. To observe cancellation
@@ -1460,9 +1460,9 @@ var RestateOperations = class {
1460
1460
  * `WorkflowSharedContext`). Returns a wrapper whose `peek`/`get`/
1461
1461
  * `resolve`/`reject` methods return Futures.
1462
1462
  */
1463
- workflowPromise(name, serde$1) {
1463
+ workflowPromise(name, serde$2) {
1464
1464
  const wfCtx = this.ctx;
1465
- return wrapDurablePromise(wfCtx.promise(name, serde$1), (p) => this.toFuture(p));
1465
+ return wrapDurablePromise(wfCtx.promise(name, serde$2), (p) => this.toFuture(p));
1466
1466
  }
1467
1467
  /**
1468
1468
  * Register `op` as a fresh routine and return a `Future<T>` for its
@@ -1612,20 +1612,10 @@ async function execute(context, op, options) {
1612
1612
 
1613
1613
  //#endregion
1614
1614
  //#region src/define.ts
1615
- function makeDescriptor(inputSerde, outputSerde) {
1616
- return {
1617
- _inputSerde: inputSerde,
1618
- _outputSerde: outputSerde
1619
- };
1620
- }
1621
1615
  /** HandlerDef has _genFn as an object property; bare gen fns are plain functions */
1622
1616
  function isHandlerDef(entry) {
1623
1617
  return typeof entry === "object" && entry !== null && typeof entry._genFn === "function";
1624
1618
  }
1625
- /** Convert a Standard Schema to a Serde via restate.serde.schema() */
1626
- function toSerde(schema) {
1627
- return __restatedev_restate_sdk.serde.schema(schema);
1628
- }
1629
1619
  function extractEntry(entry) {
1630
1620
  if (isHandlerDef(entry)) return {
1631
1621
  genFn: entry._genFn,
@@ -1650,8 +1640,8 @@ function serdes(opts, fn) {
1650
1640
  function schemas(opts, fn) {
1651
1641
  return {
1652
1642
  _genFn: fn,
1653
- _inputSerde: toSerde(opts.input),
1654
- _outputSerde: toSerde(opts.output)
1643
+ _inputSerde: __restatedev_restate_sdk_core.serde.schema(opts.input),
1644
+ _outputSerde: __restatedev_restate_sdk_core.serde.schema(opts.output)
1655
1645
  };
1656
1646
  }
1657
1647
  function service(config) {
@@ -1667,7 +1657,7 @@ function service(config) {
1667
1657
  output: outputSerde,
1668
1658
  ...handlerOpts
1669
1659
  }, async (ctx, input) => execute(ctx, genFn(input)));
1670
- descriptors[handlerName] = makeDescriptor(inputSerde, outputSerde);
1660
+ descriptors[handlerName] = (0, __restatedev_restate_sdk_core.makeHandlerDescriptor)(inputSerde, outputSerde);
1671
1661
  }
1672
1662
  const coreDef = __restatedev_restate_sdk.service({
1673
1663
  name,
@@ -1696,7 +1686,7 @@ function object(config) {
1696
1686
  };
1697
1687
  const fn = async (ctx, input) => execute(ctx, genFn(input));
1698
1688
  coreHandlers[handlerName] = shared ? __restatedev_restate_sdk.handlers.object.shared(sdkOpts, fn) : __restatedev_restate_sdk.handlers.object.exclusive(sdkOpts, fn);
1699
- descriptors[handlerName] = makeDescriptor(inputSerde, outputSerde);
1689
+ descriptors[handlerName] = (0, __restatedev_restate_sdk_core.makeHandlerDescriptor)(inputSerde, outputSerde);
1700
1690
  }
1701
1691
  const coreDef = __restatedev_restate_sdk.object({
1702
1692
  name,
@@ -1724,7 +1714,7 @@ function workflow(config) {
1724
1714
  };
1725
1715
  const fn = async (ctx, input) => execute(ctx, genFn(input));
1726
1716
  coreHandlers[handlerName] = handlerName === "run" ? __restatedev_restate_sdk.handlers.workflow.workflow(sdkOpts, fn) : __restatedev_restate_sdk.handlers.workflow.shared(sdkOpts, fn);
1727
- descriptors[handlerName] = makeDescriptor(inputSerde, outputSerde);
1717
+ descriptors[handlerName] = (0, __restatedev_restate_sdk_core.makeHandlerDescriptor)(inputSerde, outputSerde);
1728
1718
  }
1729
1719
  const coreDef = __restatedev_restate_sdk.workflow({
1730
1720
  name,
@@ -1741,51 +1731,9 @@ function workflow(config) {
1741
1731
 
1742
1732
  //#endregion
1743
1733
  //#region src/interface.ts
1744
- var interface_exports = /* @__PURE__ */ __export({
1745
- implement: () => implement,
1746
- json: () => json,
1747
- object: () => object$1,
1748
- schemas: () => schemas$1,
1749
- serdes: () => serdes$1,
1750
- service: () => service$1,
1751
- workflow: () => workflow$1
1752
- });
1753
- /** json<I, O>() — type params, default JSON serde */
1754
- function json() {
1755
- return makeDescriptor(void 0, void 0);
1756
- }
1757
- /** serdes(opts) — explicit Serde per field */
1758
- function serdes$1(opts) {
1759
- return makeDescriptor(opts.input, opts.output);
1760
- }
1761
- /** schemas(opts) — Standard Schema (Zod, TypeBox, Valibot, …) per field */
1762
- function schemas$1(opts) {
1763
- return makeDescriptor(opts.input ? toSerde(opts.input) : void 0, opts.output ? toSerde(opts.output) : void 0);
1764
- }
1765
- function service$1(name, handlers) {
1766
- return {
1767
- name,
1768
- _kind: "service",
1769
- _handlers: handlers
1770
- };
1771
- }
1772
- function object$1(name, handlers) {
1773
- return {
1774
- name,
1775
- _kind: "object",
1776
- _handlers: handlers
1777
- };
1778
- }
1779
- function workflow$1(name, handlers) {
1780
- return {
1781
- name,
1782
- _kind: "workflow",
1783
- _handlers: handlers
1784
- };
1785
- }
1786
- function implement(iface, config) {
1734
+ function implement(iface$1, config) {
1787
1735
  const handlerEntries = {};
1788
- for (const [name, desc] of Object.entries(iface._handlers)) {
1736
+ for (const [name, desc] of Object.entries(iface$1._handlers)) {
1789
1737
  const genFn = config.handlers[name];
1790
1738
  if (!genFn) throw new Error(`implement(): missing handler "${name}"`);
1791
1739
  handlerEntries[name] = {
@@ -1794,18 +1742,18 @@ function implement(iface, config) {
1794
1742
  _outputSerde: desc._outputSerde
1795
1743
  };
1796
1744
  }
1797
- if (iface._kind === "service") return service({
1798
- name: iface.name,
1745
+ if (iface$1._kind === "service") return service({
1746
+ name: iface$1.name,
1799
1747
  handlers: handlerEntries,
1800
1748
  options: config.options
1801
1749
  });
1802
- else if (iface._kind === "object") return object({
1803
- name: iface.name,
1750
+ else if (iface$1._kind === "object") return object({
1751
+ name: iface$1.name,
1804
1752
  handlers: handlerEntries,
1805
1753
  options: config.options
1806
1754
  });
1807
1755
  else return workflow({
1808
- name: iface.name,
1756
+ name: iface$1.name,
1809
1757
  handlers: handlerEntries,
1810
1758
  options: config.options
1811
1759
  });
@@ -1824,98 +1772,28 @@ var ingress_exports = /* @__PURE__ */ __export({
1824
1772
  sendClient: () => sendClient$1
1825
1773
  });
1826
1774
  /**
1827
- * Connect to the Restate Ingress.
1828
- *
1829
- * @param opts connection options
1830
- * @returns a connection the the restate ingress
1775
+ * @deprecated Use `connect` from `@restatedev/restate-sdk-clients` and its typed
1776
+ * client methods, e.g. `connect({ url }).serviceClient(def)`
1831
1777
  */
1832
1778
  function connect(opts) {
1833
1779
  return (0, __restatedev_restate_sdk_clients.connect)(opts);
1834
1780
  }
1835
1781
  function client$1(ingress, def, key) {
1836
- return makeIngressClient(ingress, def, key);
1782
+ return key === void 0 ? ingress.client(def) : ingress.client(def, key);
1837
1783
  }
1838
1784
  function sendClient$1(ingress, def, key) {
1839
- return makeIngressSendClient(ingress, def, key);
1785
+ return key === void 0 ? ingress.sendClient(def) : ingress.sendClient(def, key);
1840
1786
  }
1841
1787
  /**
1842
- * Route all ingress calls/sends through a named scope. The in-handler
1843
- * `scope(scopeKey)` and this `scope(ingress, scopeKey)` produce the same
1844
- * `.client(def)` / `.sendClient(def)` shape, so handler and ingress code
1845
- * read identically (modulo the explicit `ingress`).
1846
- *
1847
- * @example
1848
- * await clients.scope(ingress, "tenant-123").client(Greeter).greet(name);
1849
- * await clients.scope(ingress, "tenant-123").client(Cart, "cart-42").add(item);
1788
+ * @deprecated Use `ingress.scope(scopeKey)` from
1789
+ * `@restatedev/restate-sdk-clients`, then `.client(def)` / `.sendClient(def)`
1790
+ * on the returned scoped ingress.
1850
1791
  */
1851
1792
  function scope$1(ingress, scopeKey) {
1793
+ const scoped = ingress.scope(scopeKey);
1852
1794
  return {
1853
- client: (def, key) => makeIngressClient(ingress, def, key, scopeKey),
1854
- sendClient: (def, key) => makeIngressSendClient(ingress, def, key, scopeKey)
1855
- };
1856
- }
1857
- function makeIngressClient(ingress, def, key, scope$2) {
1858
- return new Proxy({}, { get(_target, methodName) {
1859
- return (...args) => {
1860
- const { parameter, opts } = optsFromArgs(args);
1861
- const desc = def._handlers[methodName];
1862
- const mergedOpts = __restatedev_restate_sdk_clients.Opts.from({
1863
- ...opts?.opts,
1864
- input: opts?.opts?.input ?? desc?._inputSerde,
1865
- output: opts?.opts?.output ?? desc?._outputSerde
1866
- });
1867
- return ingress.call({
1868
- service: def.name,
1869
- handler: methodName,
1870
- parameter,
1871
- key,
1872
- scope: scope$2,
1873
- opts: mergedOpts
1874
- });
1875
- };
1876
- } });
1877
- }
1878
- function makeIngressSendClient(ingress, def, key, scope$2) {
1879
- return new Proxy({}, { get(_target, methodName) {
1880
- return (...args) => {
1881
- const { parameter, opts } = optsFromArgs(args);
1882
- const desc = def._handlers[methodName];
1883
- const mergedOpts = __restatedev_restate_sdk_clients.SendOpts.from({
1884
- ...opts?.opts,
1885
- input: opts?.opts?.input ?? desc?._inputSerde
1886
- });
1887
- return ingress.send({
1888
- service: def.name,
1889
- handler: methodName,
1890
- parameter,
1891
- key,
1892
- scope: scope$2,
1893
- opts: mergedOpts
1894
- });
1895
- };
1896
- } });
1897
- }
1898
- function optsFromArgs(args) {
1899
- let parameter;
1900
- let opts;
1901
- switch (args.length) {
1902
- case 0: break;
1903
- case 1:
1904
- if (args[0] instanceof __restatedev_restate_sdk_clients.Opts) opts = args[0];
1905
- else if (args[0] instanceof __restatedev_restate_sdk_clients.SendOpts) opts = args[0];
1906
- else parameter = args[0];
1907
- break;
1908
- case 2:
1909
- parameter = args[0];
1910
- if (args[1] instanceof __restatedev_restate_sdk_clients.Opts) opts = args[1];
1911
- else if (args[1] instanceof __restatedev_restate_sdk_clients.SendOpts) opts = args[1];
1912
- else throw new TypeError("The second argument must be either Opts or SendOpts");
1913
- break;
1914
- default: throw new TypeError("unexpected number of arguments");
1915
- }
1916
- return {
1917
- parameter,
1918
- opts
1795
+ client: (def, key) => key === void 0 ? scoped.client(def) : scoped.client(def, key),
1796
+ sendClient: (def, key) => key === void 0 ? scoped.sendClient(def) : scoped.sendClient(def, key)
1919
1797
  };
1920
1798
  }
1921
1799
 
@@ -1943,6 +1821,13 @@ function isProcessing() {
1943
1821
  return current instanceof RestateOperations ? current.isProcessing() : void 0;
1944
1822
  }
1945
1823
 
1824
+ //#endregion
1825
+ //#region src/index.ts
1826
+ const iface = {
1827
+ ...__restatedev_restate_sdk_core.iface,
1828
+ implement
1829
+ };
1830
+
1946
1831
  //#endregion
1947
1832
  exports.InterruptedError = InterruptedError;
1948
1833
  exports.all = all;
@@ -1965,12 +1850,7 @@ exports.date = date;
1965
1850
  exports.execute = execute;
1966
1851
  exports.gen = gen;
1967
1852
  exports.handlerRequest = handlerRequest;
1968
- Object.defineProperty(exports, 'iface', {
1969
- enumerable: true,
1970
- get: function () {
1971
- return interface_exports;
1972
- }
1973
- });
1853
+ exports.iface = iface;
1974
1854
  exports.implement = implement;
1975
1855
  Object.defineProperty(exports, 'internal', {
1976
1856
  enumerable: true,