mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 12:21:57 +00:00
feat: Save uses dependencies, which ensure the id is from manifest
This commit is contained in:
@@ -1,15 +1,25 @@
|
|||||||
|
import { GenericManifest } from "../manifest/ManifestTypes";
|
||||||
import { Dependency, PackageId } from "../types";
|
import { Dependency, PackageId } from "../types";
|
||||||
|
|
||||||
export function exists(id: PackageId) {
|
export type Dependencies<T extends GenericManifest> = {
|
||||||
return {
|
exists(id: keyof T["dependencies"]): Dependency;
|
||||||
id,
|
running(id: keyof T["dependencies"]): Dependency;
|
||||||
kind: "exists",
|
};
|
||||||
} as Dependency;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function running(id: PackageId) {
|
export const dependenciesSet = <
|
||||||
return {
|
T extends GenericManifest,
|
||||||
id,
|
>(): Dependencies<T> => ({
|
||||||
kind: "running",
|
exists(id: keyof T["dependencies"]) {
|
||||||
} as Dependency;
|
return {
|
||||||
}
|
id,
|
||||||
|
kind: "exists",
|
||||||
|
} as Dependency;
|
||||||
|
},
|
||||||
|
|
||||||
|
running(id: keyof T["dependencies"]) {
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
kind: "running",
|
||||||
|
} as Dependency;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|||||||
@@ -3,16 +3,19 @@ import { DeepPartial, Dependencies, Effects, ExpectedExports } from "../types";
|
|||||||
import { InputSpec } from "./configTypes";
|
import { InputSpec } from "./configTypes";
|
||||||
import { Utils, nullIfEmpty, once, utils } from "../util";
|
import { Utils, nullIfEmpty, once, utils } from "../util";
|
||||||
import { TypeFromProps } from "../util/propertiesMatcher";
|
import { TypeFromProps } from "../util/propertiesMatcher";
|
||||||
|
import { GenericManifest } from "../manifest/ManifestTypes";
|
||||||
|
import * as D from "./dependencies";
|
||||||
|
|
||||||
declare const dependencyProof: unique symbol;
|
declare const dependencyProof: unique symbol;
|
||||||
export type DependenciesReceipt = void & {
|
export type DependenciesReceipt = void & {
|
||||||
[dependencyProof]: never;
|
[dependencyProof]: never;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Save<WD, A> = (options: {
|
export type Save<WD, A, Manifest extends GenericManifest> = (options: {
|
||||||
effects: Effects;
|
effects: Effects;
|
||||||
input: A;
|
input: A;
|
||||||
utils: Utils<WD>;
|
utils: Utils<WD>;
|
||||||
|
dependencies: D.Dependencies<Manifest>;
|
||||||
}) => Promise<DependenciesReceipt>;
|
}) => Promise<DependenciesReceipt>;
|
||||||
export type Read<WD, A> = (options: {
|
export type Read<WD, A> = (options: {
|
||||||
effects: Effects;
|
effects: Effects;
|
||||||
@@ -25,9 +28,13 @@ export type Read<WD, A> = (options: {
|
|||||||
* @param options
|
* @param options
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function setupConfig<WD, A extends Config<InputSpec>>(
|
export function setupConfig<
|
||||||
|
WD,
|
||||||
|
A extends Config<InputSpec>,
|
||||||
|
Manifest extends GenericManifest,
|
||||||
|
>(
|
||||||
spec: A,
|
spec: A,
|
||||||
write: Save<WD, TypeFromProps<A>>,
|
write: Save<WD, TypeFromProps<A>, Manifest>,
|
||||||
read: Read<WD, TypeFromProps<A>>,
|
read: Read<WD, TypeFromProps<A>>,
|
||||||
) {
|
) {
|
||||||
const validator = once(() => spec.validator());
|
const validator = once(() => spec.validator());
|
||||||
@@ -41,6 +48,7 @@ export function setupConfig<WD, A extends Config<InputSpec>>(
|
|||||||
input: JSON.parse(JSON.stringify(input)),
|
input: JSON.parse(JSON.stringify(input)),
|
||||||
effects,
|
effects,
|
||||||
utils: utils<WD>(effects),
|
utils: utils<WD>(effects),
|
||||||
|
dependencies: D.dependenciesSet<Manifest>(),
|
||||||
});
|
});
|
||||||
}) as ExpectedExports.setConfig,
|
}) as ExpectedExports.setConfig,
|
||||||
getConfig: (async ({ effects, config }) => {
|
getConfig: (async ({ effects, config }) => {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export class WrapperData<WrapperData, Path extends string> {
|
|||||||
callback: () => {},
|
callback: () => {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async *overTime() {
|
async *watch() {
|
||||||
while (true) {
|
while (true) {
|
||||||
let callback: () => void;
|
let callback: () => void;
|
||||||
const waitForNext = new Promise<void>((resolve) => {
|
const waitForNext = new Promise<void>((resolve) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user