@restatedev/restate-sdk-gen 1.18.4 → 1.19.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 +31 -22
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -23
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __export } from "./chunk-Bp6m_JJh.js";
|
|
2
2
|
import * as restate from "@restatedev/restate-sdk";
|
|
3
3
|
import { Opts, SendOpts, isRestatePromise } from "@restatedev/restate-sdk";
|
|
4
|
-
import { iface as iface$1,
|
|
4
|
+
import { iface as iface$1, serde, serde as serde$1 } from "@restatedev/restate-sdk-core";
|
|
5
5
|
import { HttpCallError, Opts as Opts$1, SendOpts as SendOpts$1, connect, defaultShouldRetry } from "@restatedev/restate-sdk-clients";
|
|
6
6
|
|
|
7
7
|
//#region src/current.ts
|
|
@@ -946,15 +946,14 @@ var Scheduler = class {
|
|
|
946
946
|
}
|
|
947
947
|
return this.spawnFuture(gen(function* () {
|
|
948
948
|
const out = new Array(fs.length);
|
|
949
|
-
for (let i = 0; i < fs.length; i++)
|
|
950
|
-
|
|
949
|
+
for (let i = 0; i < fs.length; i++) {
|
|
950
|
+
const { settled } = yield* awaitRace([fs[i]]);
|
|
951
|
+
out[i] = settled.ok ? {
|
|
951
952
|
status: "fulfilled",
|
|
952
|
-
value:
|
|
953
|
-
}
|
|
954
|
-
} catch (reason) {
|
|
955
|
-
out[i] = {
|
|
953
|
+
value: settled.v
|
|
954
|
+
} : {
|
|
956
955
|
status: "rejected",
|
|
957
|
-
reason
|
|
956
|
+
reason: settled.e
|
|
958
957
|
};
|
|
959
958
|
}
|
|
960
959
|
return out;
|
|
@@ -999,7 +998,13 @@ var Scheduler = class {
|
|
|
999
998
|
this.drainReady();
|
|
1000
999
|
while (!this.mainExited() && this.fibers.size > 0) {
|
|
1001
1000
|
const items = [];
|
|
1002
|
-
|
|
1001
|
+
const parked = [];
|
|
1002
|
+
for (const f of this.fibers) {
|
|
1003
|
+
const sources = f.parkedSources();
|
|
1004
|
+
if (sources.length === 0) continue;
|
|
1005
|
+
parked.push(f);
|
|
1006
|
+
for (const src of sources) items.push(src);
|
|
1007
|
+
}
|
|
1003
1008
|
if (items.length === 0) throw new Error("scheduler stuck: live fibers but nothing pending on a journal promise");
|
|
1004
1009
|
const tagged = items.map(({ promise }, i$1) => promise.map((v, e) => e !== void 0 ? {
|
|
1005
1010
|
i: i$1,
|
|
@@ -1022,7 +1027,7 @@ var Scheduler = class {
|
|
|
1022
1027
|
ok: false,
|
|
1023
1028
|
e
|
|
1024
1029
|
};
|
|
1025
|
-
for (const
|
|
1030
|
+
for (const f of parked) f.wake(errSettled);
|
|
1026
1031
|
this.drainReady();
|
|
1027
1032
|
continue;
|
|
1028
1033
|
}
|
|
@@ -1596,6 +1601,15 @@ function extractEntry(entry) {
|
|
|
1596
1601
|
outputSerde: void 0
|
|
1597
1602
|
};
|
|
1598
1603
|
}
|
|
1604
|
+
/**
|
|
1605
|
+
* The per-handler serde descriptors computed by the core SDK factory. They hold
|
|
1606
|
+
* the effective serde of each handler (explicit `input`/`output`, else the
|
|
1607
|
+
* handler-level `serde`, else the service-level `serde`), matching what the
|
|
1608
|
+
* endpoint uses at runtime, so clients built from the definition agree with it.
|
|
1609
|
+
*/
|
|
1610
|
+
function effectiveDescriptors(coreDef) {
|
|
1611
|
+
return coreDef._handlers;
|
|
1612
|
+
}
|
|
1599
1613
|
/** serdes(opts, fn) — explicit Serde per field */
|
|
1600
1614
|
function serdes(opts, fn) {
|
|
1601
1615
|
return {
|
|
@@ -1616,7 +1630,6 @@ function service(config) {
|
|
|
1616
1630
|
const { name, description, metadata, handlers, options } = config;
|
|
1617
1631
|
const { handlers: perHandlerOpts,...serviceOpts } = options ?? {};
|
|
1618
1632
|
const coreHandlers = {};
|
|
1619
|
-
const descriptors = {};
|
|
1620
1633
|
for (const [handlerName, entry] of Object.entries(handlers)) {
|
|
1621
1634
|
const { genFn, inputSerde, outputSerde } = extractEntry(entry);
|
|
1622
1635
|
const handlerOpts = perHandlerOpts?.[handlerName] ?? {};
|
|
@@ -1625,7 +1638,6 @@ function service(config) {
|
|
|
1625
1638
|
output: outputSerde,
|
|
1626
1639
|
...handlerOpts
|
|
1627
1640
|
}, async (ctx, input) => execute(ctx, genFn(input)));
|
|
1628
|
-
descriptors[handlerName] = makeHandlerDescriptor(inputSerde, outputSerde);
|
|
1629
1641
|
}
|
|
1630
1642
|
const coreDef = restate.service({
|
|
1631
1643
|
name,
|
|
@@ -1636,14 +1648,13 @@ function service(config) {
|
|
|
1636
1648
|
});
|
|
1637
1649
|
return Object.assign(coreDef, {
|
|
1638
1650
|
_kind: "service",
|
|
1639
|
-
_handlers:
|
|
1651
|
+
_handlers: effectiveDescriptors(coreDef)
|
|
1640
1652
|
});
|
|
1641
1653
|
}
|
|
1642
1654
|
function object(config) {
|
|
1643
1655
|
const { name, description, metadata, handlers, options } = config;
|
|
1644
1656
|
const { handlers: perHandlerOpts,...objectOpts } = options ?? {};
|
|
1645
1657
|
const coreHandlers = {};
|
|
1646
|
-
const descriptors = {};
|
|
1647
1658
|
for (const [handlerName, entry] of Object.entries(handlers)) {
|
|
1648
1659
|
const { genFn, inputSerde, outputSerde } = extractEntry(entry);
|
|
1649
1660
|
const { shared,...restOpts } = perHandlerOpts?.[handlerName] ?? {};
|
|
@@ -1654,7 +1665,6 @@ function object(config) {
|
|
|
1654
1665
|
};
|
|
1655
1666
|
const fn = async (ctx, input) => execute(ctx, genFn(input));
|
|
1656
1667
|
coreHandlers[handlerName] = shared ? restate.handlers.object.shared(sdkOpts, fn) : restate.handlers.object.exclusive(sdkOpts, fn);
|
|
1657
|
-
descriptors[handlerName] = makeHandlerDescriptor(inputSerde, outputSerde);
|
|
1658
1668
|
}
|
|
1659
1669
|
const coreDef = restate.object({
|
|
1660
1670
|
name,
|
|
@@ -1665,14 +1675,13 @@ function object(config) {
|
|
|
1665
1675
|
});
|
|
1666
1676
|
return Object.assign(coreDef, {
|
|
1667
1677
|
_kind: "object",
|
|
1668
|
-
_handlers:
|
|
1678
|
+
_handlers: effectiveDescriptors(coreDef)
|
|
1669
1679
|
});
|
|
1670
1680
|
}
|
|
1671
1681
|
function workflow(config) {
|
|
1672
1682
|
const { name, description, metadata, handlers, options } = config;
|
|
1673
1683
|
const { handlers: perHandlerOpts,...workflowOpts } = options ?? {};
|
|
1674
1684
|
const coreHandlers = {};
|
|
1675
|
-
const descriptors = {};
|
|
1676
1685
|
for (const [handlerName, entry] of Object.entries(handlers)) {
|
|
1677
1686
|
const { genFn, inputSerde, outputSerde } = extractEntry(entry);
|
|
1678
1687
|
const sdkOpts = {
|
|
@@ -1682,7 +1691,6 @@ function workflow(config) {
|
|
|
1682
1691
|
};
|
|
1683
1692
|
const fn = async (ctx, input) => execute(ctx, genFn(input));
|
|
1684
1693
|
coreHandlers[handlerName] = handlerName === "run" ? restate.handlers.workflow.workflow(sdkOpts, fn) : restate.handlers.workflow.shared(sdkOpts, fn);
|
|
1685
|
-
descriptors[handlerName] = makeHandlerDescriptor(inputSerde, outputSerde);
|
|
1686
1694
|
}
|
|
1687
1695
|
const coreDef = restate.workflow({
|
|
1688
1696
|
name,
|
|
@@ -1693,7 +1701,7 @@ function workflow(config) {
|
|
|
1693
1701
|
});
|
|
1694
1702
|
return Object.assign(coreDef, {
|
|
1695
1703
|
_kind: "workflow",
|
|
1696
|
-
_handlers:
|
|
1704
|
+
_handlers: effectiveDescriptors(coreDef)
|
|
1697
1705
|
});
|
|
1698
1706
|
}
|
|
1699
1707
|
|
|
@@ -1710,10 +1718,11 @@ function implement(iface$2, config) {
|
|
|
1710
1718
|
_inputSerde: desc._inputSerde,
|
|
1711
1719
|
_outputSerde: desc._outputSerde
|
|
1712
1720
|
};
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1721
|
+
const contractOpts = {};
|
|
1722
|
+
if (desc._description !== void 0) contractOpts.description = desc._description;
|
|
1723
|
+
if (desc._metadata !== void 0) contractOpts.metadata = desc._metadata;
|
|
1724
|
+
if (iface$2._kind === "object" && desc._shared) contractOpts.shared = true;
|
|
1725
|
+
if (Object.keys(contractOpts).length > 0) contractHandlerOpts[name] = contractOpts;
|
|
1717
1726
|
}
|
|
1718
1727
|
const { handlers: userHandlerOpts,...restOptions } = config.options ?? {};
|
|
1719
1728
|
const mergedHandlerOpts = {};
|