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