Skip to content

Commit

Permalink
added: autoResolveDeps param
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Pasynok committed Nov 8, 2024
1 parent f66d14d commit 28546c0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
31 changes: 31 additions & 0 deletions src/compose/up/__tests__/index.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,35 @@ describe('upFn', () => {

expectTypeOf<UpResult>().toEqualTypeOf<typeof upResult>();
});

test('config', () => {
const a = createContainer({
id: 'a',
start: () => ({ api: { t: () => true } }),
});

test('empty', async () => {
const upResult = await upFn([a]);

expectTypeOf<keyof typeof upResult>().toEqualTypeOf<'hasErrors' | 'statuses'>();
});

test('only debug', async () => {
const upResult = await upFn([a], { debug: true });

expectTypeOf<keyof typeof upResult>().toEqualTypeOf<'hasErrors' | 'statuses'>();
});

test('only apis', async () => {
const upResult = await upFn([a], { apis: true });

expectTypeOf<keyof typeof upResult>().toEqualTypeOf<'hasErrors' | 'statuses' | 'apis'>();
});

test('debug + apis', async () => {
const upResult = await upFn([a], { debug: true, apis: true });

expectTypeOf<keyof typeof upResult>().toEqualTypeOf<'hasErrors' | 'statuses' | 'apis'>();
});
});
});
21 changes: 15 additions & 6 deletions src/compose/up/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,29 @@ type APIs<T extends AnyContainer[]> = {
};

type Config = {
apis?: true;
apis?: boolean;
debug?: boolean;
autoResolveDeps?: {
strict: boolean;
optional: boolean;
};
};

type UpResult<T extends AnyContainer[], C extends Config | undefined> = undefined extends C
? {
hasErrors: boolean;
statuses: Statuses<T>;
}
: {
apis: APIs<T>;
hasErrors: boolean;
statuses: Statuses<T>;
};
: NonNullable<C>['apis'] extends true
? {
apis: APIs<T>;
hasErrors: boolean;
statuses: Statuses<T>;
}
: {
hasErrors: boolean;
statuses: Statuses<T>;
};

const upFn = async <T extends AnyContainer[], C extends Config | undefined>(
containers: T,
Expand Down

0 comments on commit 28546c0

Please sign in to comment.