mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-04-01 21:13:11 +00:00
chore: Add the wrapperData, bound effects, and sdk
This commit is contained in:
45
lib/util/getWrapperData.ts
Normal file
45
lib/util/getWrapperData.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { Parser } from "ts-matches";
|
||||
import { Effects } from "../types";
|
||||
|
||||
export function getWrapperData<A>(
|
||||
effects: Effects,
|
||||
validator: Parser<unknown, A>,
|
||||
options: {
|
||||
/** Defaults to what ever the package currently in */
|
||||
packageId?: string | undefined;
|
||||
/** JsonPath */
|
||||
path?: string | undefined;
|
||||
} = {}
|
||||
) {
|
||||
return {
|
||||
const: () =>
|
||||
effects
|
||||
.getWrapperData({
|
||||
...options,
|
||||
callback: effects.restart,
|
||||
})
|
||||
.then(validator.unsafeCast),
|
||||
first: () =>
|
||||
effects
|
||||
.getWrapperData({
|
||||
...options,
|
||||
callback: () => {},
|
||||
})
|
||||
.then(validator.unsafeCast),
|
||||
overTime: async function* <A>() {
|
||||
while (true) {
|
||||
let callback: () => void;
|
||||
const waitForNext = new Promise<void>((resolve) => {
|
||||
callback = resolve;
|
||||
});
|
||||
yield await effects
|
||||
.getWrapperData({
|
||||
...options,
|
||||
callback: () => callback(),
|
||||
})
|
||||
.then(validator.unsafeCast);
|
||||
await waitForNext;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user