mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 10:21:55 +00:00
chore: add types
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
import { Config } from "./builder";
|
||||
import {
|
||||
DeepPartial,
|
||||
Dependencies,
|
||||
DependsOn,
|
||||
Effects,
|
||||
ExpectedExports,
|
||||
} from "../types";
|
||||
import { DeepPartial, Dependencies, DependsOn, Effects, ExpectedExports } from "../types";
|
||||
import { InputSpec } from "./configTypes";
|
||||
import { nullIfEmpty } from "../util";
|
||||
import { TypeFromProps } from "../util/propertiesMatcher";
|
||||
|
||||
export type Write<A, ConfigType> = (options: { effects: Effects; input: TypeFromProps<A> }) => Promise<ConfigType>;
|
||||
export type Read<A, ConfigType> = (options: {
|
||||
effects: Effects;
|
||||
config: ConfigType;
|
||||
}) => Promise<null | DeepPartial<TypeFromProps<A>>>;
|
||||
export type DependenciesFn<A, ConfigType> = (options: {
|
||||
effects: Effects;
|
||||
input: TypeFromProps<A>;
|
||||
config: ConfigType;
|
||||
}) => Promise<Dependencies | void>;
|
||||
/**
|
||||
* We want to setup a config export with a get and set, this
|
||||
* is going to be the default helper to setup config, because it will help
|
||||
@@ -19,20 +23,9 @@ import { TypeFromProps } from "../util/propertiesMatcher";
|
||||
*/
|
||||
export function setupConfigExports<A extends InputSpec, ConfigType>(options: {
|
||||
spec: Config<A>;
|
||||
write(options: {
|
||||
effects: Effects;
|
||||
input: TypeFromProps<A>;
|
||||
}): Promise<ConfigType>;
|
||||
read(options: {
|
||||
effects: Effects;
|
||||
config: ConfigType;
|
||||
}): Promise<null | DeepPartial<TypeFromProps<A>>>;
|
||||
|
||||
dependencies(options: {
|
||||
effects: Effects;
|
||||
input: TypeFromProps<A>;
|
||||
config: ConfigType;
|
||||
}): Promise<Dependencies | void>;
|
||||
write: Write<A, ConfigType>;
|
||||
read: Read<A, ConfigType>;
|
||||
dependencies: DependenciesFn<A, ConfigType>;
|
||||
}) {
|
||||
const validator = options.spec.validator();
|
||||
return {
|
||||
@@ -45,17 +38,14 @@ export function setupConfigExports<A extends InputSpec, ConfigType>(options: {
|
||||
input: JSON.parse(JSON.stringify(input)),
|
||||
effects,
|
||||
});
|
||||
const dependencies =
|
||||
(await options.dependencies({ effects, input, config })) || [];
|
||||
const dependencies = (await options.dependencies({ effects, input, config })) || [];
|
||||
await effects.setDependencies(dependencies);
|
||||
await effects.setWrapperData({ path: "config", value: config || null });
|
||||
}) as ExpectedExports.setConfig,
|
||||
getConfig: (async ({ effects, config }) => {
|
||||
return {
|
||||
spec: options.spec.build(),
|
||||
config: nullIfEmpty(
|
||||
await options.read({ effects, config: config as ConfigType })
|
||||
),
|
||||
config: nullIfEmpty(await options.read({ effects, config: config as ConfigType })),
|
||||
};
|
||||
}) as ExpectedExports.getConfig,
|
||||
};
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "start-sdk",
|
||||
"version": "0.4.0-lib0.charlie29",
|
||||
"version": "0.4.0-lib0.charlie30",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "start-sdk",
|
||||
"version": "0.4.0-lib0.charlie29",
|
||||
"version": "0.4.0-lib0.charlie30",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@iarna/toml": "^2.2.5",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "start-sdk",
|
||||
"version": "0.4.0-lib0.charlie29",
|
||||
"version": "0.4.0-lib0.charlie30",
|
||||
"description": "For making the patterns that are wanted in making services for the startOS.",
|
||||
"main": "./lib/index.js",
|
||||
"types": "./lib/index.d.ts",
|
||||
|
||||
Reference in New Issue
Block a user