mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-04-04 14:29:47 +00:00
chore: Get config takes in the config
This commit is contained in:
@@ -18,7 +18,8 @@ const matchConfig = dictionary([string, any]);
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const getConfig =
|
export const getConfig =
|
||||||
(spec: ConfigSpec): ExpectedExports.getConfig => async (effects) => {
|
<A extends ConfigSpec>(spec: Config<A>): ExpectedExports.getConfig =>
|
||||||
|
async (effects) => {
|
||||||
const config = await effects
|
const config = await effects
|
||||||
.readFile({
|
.readFile({
|
||||||
path: "start9/config.yaml",
|
path: "start9/config.yaml",
|
||||||
@@ -34,7 +35,7 @@ export const getConfig =
|
|||||||
return {
|
return {
|
||||||
result: {
|
result: {
|
||||||
config,
|
config,
|
||||||
spec,
|
spec: spec.build(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -48,12 +49,12 @@ export const getConfig =
|
|||||||
* @returns A funnction for getConfig and the matcher for the spec sent in
|
* @returns A funnction for getConfig and the matcher for the spec sent in
|
||||||
*/
|
*/
|
||||||
export const getConfigAndMatcher = <Spec extends ConfigSpec>(
|
export const getConfigAndMatcher = <Spec extends ConfigSpec>(
|
||||||
spec: Config<Spec> | Spec,
|
spec: Config<Spec>,
|
||||||
): [
|
): [
|
||||||
ExpectedExports.getConfig,
|
ExpectedExports.getConfig,
|
||||||
matches.Parser<unknown, TypeFromProps<Spec>>,
|
matches.Parser<unknown, TypeFromProps<Spec>>,
|
||||||
] => {
|
] => {
|
||||||
const specBuilt: Spec = spec instanceof Config ? spec.build() : spec;
|
const specBuilt: Spec = spec.build();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
async (effects) => {
|
async (effects) => {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import * as M from "../migrations.ts";
|
|||||||
import * as util from "../util.ts";
|
import * as util from "../util.ts";
|
||||||
import { EmVer } from "../emver-lite/mod.ts";
|
import { EmVer } from "../emver-lite/mod.ts";
|
||||||
import { ConfigSpec } from "../types/config-types.ts";
|
import { ConfigSpec } from "../types/config-types.ts";
|
||||||
|
import { Config } from "../config/mod.ts";
|
||||||
|
|
||||||
export interface NoRepeat<version extends string, type extends "up" | "down"> {
|
export interface NoRepeat<version extends string, type extends "up" | "down"> {
|
||||||
version: version;
|
version: version;
|
||||||
@@ -31,7 +32,8 @@ export function updateConfig<
|
|||||||
): M.MigrationFn<version, type> {
|
): M.MigrationFn<version, type> {
|
||||||
return M.migrationFn(async (effects: T.Effects) => {
|
return M.migrationFn(async (effects: T.Effects) => {
|
||||||
await noRepeatGuard(effects, noRepeat, async () => {
|
await noRepeatGuard(effects, noRepeat, async () => {
|
||||||
let config = util.unwrapResultType(await getConfig({})(effects)).config;
|
let config =
|
||||||
|
util.unwrapResultType(await getConfig(Config.of({}))(effects)).config;
|
||||||
if (config) {
|
if (config) {
|
||||||
try {
|
try {
|
||||||
config = await fn(config, effects);
|
config = await fn(config, effects);
|
||||||
|
|||||||
Reference in New Issue
Block a user