chore: Add the wrapperData, bound effects, and sdk

This commit is contained in:
BluJ
2023-04-13 14:44:17 -06:00
parent cff86718f8
commit c9a1c45930
11 changed files with 134 additions and 25 deletions

View 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;
}
},
};
}