Skip to content

Commit e50bbd8

Browse files
committed
feat: use namespaces to export "internal" types that are used in exported signatures
1 parent a39d538 commit e50bbd8

File tree

17 files changed

+627
-515
lines changed

17 files changed

+627
-515
lines changed

library/eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export default tseslint.config(
8383
'@typescript-eslint/no-non-null-assertion': 'off',
8484
'@typescript-eslint/consistent-indexed-object-style': 'off',
8585
'@typescript-eslint/no-inferrable-types': 'off',
86+
'@typescript-eslint/no-namespace': 'off',
8687

8788
// Imports
8889
'no-duplicate-imports': 'off',

library/src/actions/args/args.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,28 @@ import type {
1818
} from '../../types/index.ts';
1919
import { ValiError } from '../../utils/index.ts';
2020

21-
/**
22-
* Schema type.
23-
*/
24-
type Schema =
25-
| LooseTupleSchema<TupleItems, ErrorMessage<LooseTupleIssue> | undefined>
26-
| StrictTupleSchema<TupleItems, ErrorMessage<StrictTupleIssue> | undefined>
27-
| TupleSchema<TupleItems, ErrorMessage<TupleIssue> | undefined>
28-
| TupleWithRestSchema<
29-
TupleItems,
30-
BaseSchema<unknown, unknown, BaseIssue<unknown>>,
31-
ErrorMessage<TupleWithRestIssue> | undefined
32-
>;
21+
export namespace args {
22+
/**
23+
* Schema type.
24+
*/
25+
export type Schema =
26+
| LooseTupleSchema<TupleItems, ErrorMessage<LooseTupleIssue> | undefined>
27+
| StrictTupleSchema<TupleItems, ErrorMessage<StrictTupleIssue> | undefined>
28+
| TupleSchema<TupleItems, ErrorMessage<TupleIssue> | undefined>
29+
| TupleWithRestSchema<
30+
TupleItems,
31+
BaseSchema<unknown, unknown, BaseIssue<unknown>>,
32+
ErrorMessage<TupleWithRestIssue> | undefined
33+
>;
34+
}
3335

3436
/**
3537
* Args action type.
3638
*/
3739
export interface ArgsAction<
3840
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3941
TInput extends (...args: any[]) => unknown,
40-
TSchema extends Schema,
42+
TSchema extends args.Schema,
4143
> extends BaseTransformation<
4244
TInput,
4345
(...args: InferInput<TSchema>) => ReturnType<TInput>,
@@ -67,13 +69,13 @@ export interface ArgsAction<
6769
export function args<
6870
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6971
TInput extends (...args: any[]) => unknown,
70-
TSchema extends Schema,
72+
TSchema extends args.Schema,
7173
>(schema: TSchema): ArgsAction<TInput, TSchema>;
7274

7375
// @__NO_SIDE_EFFECTS__
7476
export function args(
75-
schema: Schema
76-
): ArgsAction<(...args: unknown[]) => unknown, Schema> {
77+
schema: args.Schema
78+
): ArgsAction<(...args: unknown[]) => unknown, args.Schema> {
7779
return {
7880
kind: 'transformation',
7981
type: 'args',

library/src/actions/args/argsAsync.ts

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,43 @@ import type {
2525
} from '../../types/index.ts';
2626
import { ValiError } from '../../utils/index.ts';
2727

28-
/**
29-
* Schema type.
30-
*/
31-
type Schema =
32-
| LooseTupleSchema<TupleItems, ErrorMessage<LooseTupleIssue> | undefined>
33-
| LooseTupleSchemaAsync<
34-
TupleItemsAsync,
35-
ErrorMessage<LooseTupleIssue> | undefined
36-
>
37-
| StrictTupleSchema<TupleItems, ErrorMessage<StrictTupleIssue> | undefined>
38-
| StrictTupleSchemaAsync<
39-
TupleItemsAsync,
40-
ErrorMessage<StrictTupleIssue> | undefined
41-
>
42-
| TupleSchema<TupleItems, ErrorMessage<TupleIssue> | undefined>
43-
| TupleSchemaAsync<TupleItemsAsync, ErrorMessage<TupleIssue> | undefined>
44-
| TupleWithRestSchema<
45-
TupleItems,
46-
BaseSchema<unknown, unknown, BaseIssue<unknown>>,
47-
ErrorMessage<TupleWithRestIssue> | undefined
48-
>
49-
| TupleWithRestSchemaAsync<
50-
TupleItemsAsync,
51-
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
52-
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>,
53-
ErrorMessage<TupleWithRestIssue> | undefined
54-
>;
28+
export namespace argsAsync {
29+
/**
30+
* Schema type.
31+
*/
32+
export type Schema =
33+
| LooseTupleSchema<TupleItems, ErrorMessage<LooseTupleIssue> | undefined>
34+
| LooseTupleSchemaAsync<
35+
TupleItemsAsync,
36+
ErrorMessage<LooseTupleIssue> | undefined
37+
>
38+
| StrictTupleSchema<TupleItems, ErrorMessage<StrictTupleIssue> | undefined>
39+
| StrictTupleSchemaAsync<
40+
TupleItemsAsync,
41+
ErrorMessage<StrictTupleIssue> | undefined
42+
>
43+
| TupleSchema<TupleItems, ErrorMessage<TupleIssue> | undefined>
44+
| TupleSchemaAsync<TupleItemsAsync, ErrorMessage<TupleIssue> | undefined>
45+
| TupleWithRestSchema<
46+
TupleItems,
47+
BaseSchema<unknown, unknown, BaseIssue<unknown>>,
48+
ErrorMessage<TupleWithRestIssue> | undefined
49+
>
50+
| TupleWithRestSchemaAsync<
51+
TupleItemsAsync,
52+
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
53+
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>,
54+
ErrorMessage<TupleWithRestIssue> | undefined
55+
>;
56+
}
5557

5658
/**
5759
* Args action async type.
5860
*/
5961
export interface ArgsActionAsync<
6062
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6163
TInput extends (...args: any[]) => unknown,
62-
TSchema extends Schema,
64+
TSchema extends argsAsync.Schema,
6365
> extends BaseTransformation<
6466
TInput,
6567
(...args: InferInput<TSchema>) => Promise<Awaited<ReturnType<TInput>>>,
@@ -89,13 +91,13 @@ export interface ArgsActionAsync<
8991
export function argsAsync<
9092
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9193
TInput extends (...args: any[]) => unknown,
92-
TSchema extends Schema,
94+
TSchema extends argsAsync.Schema,
9395
>(schema: TSchema): ArgsActionAsync<TInput, TSchema>;
9496

9597
// @__NO_SIDE_EFFECTS__
9698
export function argsAsync(
97-
schema: Schema
98-
): ArgsActionAsync<(...args: unknown[]) => unknown, Schema> {
99+
schema: argsAsync.Schema
100+
): ArgsActionAsync<(...args: unknown[]) => unknown, argsAsync.Schema> {
99101
return {
100102
kind: 'transformation',
101103
type: 'args',

library/src/methods/getDescription/getDescription.ts

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,36 @@ import type {
99
import { _getLastMetadata } from '../../utils/index.ts';
1010
import type { SchemaWithPipe, SchemaWithPipeAsync } from '../index.ts';
1111

12-
/**
13-
* Schema type.
14-
*/
15-
type Schema =
16-
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
17-
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
18-
| SchemaWithPipe<
19-
readonly [
20-
BaseSchema<unknown, unknown, BaseIssue<unknown>>,
21-
...(
22-
| PipeItem<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
23-
| DescriptionAction<unknown, string>
24-
)[],
25-
]
26-
>
27-
| SchemaWithPipeAsync<
28-
readonly [
29-
(
30-
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
31-
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
32-
),
33-
...(
34-
| PipeItem<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
35-
| PipeItemAsync<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
36-
| DescriptionAction<unknown, string>
37-
)[],
38-
]
39-
>;
12+
export namespace getDescription {
13+
/**
14+
* Schema type.
15+
*/
16+
export type Schema =
17+
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
18+
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
19+
| SchemaWithPipe<
20+
readonly [
21+
BaseSchema<unknown, unknown, BaseIssue<unknown>>,
22+
...(
23+
| PipeItem<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
24+
| DescriptionAction<unknown, string>
25+
)[],
26+
]
27+
>
28+
| SchemaWithPipeAsync<
29+
readonly [
30+
(
31+
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
32+
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
33+
),
34+
...(
35+
| PipeItem<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
36+
| PipeItemAsync<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
37+
| DescriptionAction<unknown, string>
38+
)[],
39+
]
40+
>;
41+
}
4042

4143
/**
4244
* Returns the description of the schema.
@@ -52,6 +54,8 @@ type Schema =
5254
*/
5355
// TODO: Investigate if return type can be strongly typed
5456
// @__NO_SIDE_EFFECTS__
55-
export function getDescription(schema: Schema): string | undefined {
57+
export function getDescription(
58+
schema: getDescription.Schema
59+
): string | undefined {
5660
return _getLastMetadata(schema, 'description');
5761
}

library/src/methods/getMetadata/getMetadata.ts

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,36 @@ import type {
1010
} from '../../types/index.ts';
1111
import type { SchemaWithPipe, SchemaWithPipeAsync } from '../pipe/index.ts';
1212

13-
/**
14-
* Schema type.
15-
*/
16-
type Schema =
17-
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
18-
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
19-
| SchemaWithPipe<
20-
readonly [
21-
BaseSchema<unknown, unknown, BaseIssue<unknown>>,
22-
...(
23-
| PipeItem<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
24-
| MetadataAction<unknown, Record<string, unknown>>
25-
)[],
26-
]
27-
>
28-
| SchemaWithPipeAsync<
29-
readonly [
30-
(
31-
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
32-
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
33-
),
34-
...(
35-
| PipeItem<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
36-
| PipeItemAsync<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
37-
| MetadataAction<unknown, Record<string, unknown>>
38-
)[],
39-
]
40-
>;
13+
export namespace getMetadata {
14+
/**
15+
* Schema type.
16+
*/
17+
export type Schema =
18+
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
19+
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
20+
| SchemaWithPipe<
21+
readonly [
22+
BaseSchema<unknown, unknown, BaseIssue<unknown>>,
23+
...(
24+
| PipeItem<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
25+
| MetadataAction<unknown, Record<string, unknown>>
26+
)[],
27+
]
28+
>
29+
| SchemaWithPipeAsync<
30+
readonly [
31+
(
32+
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
33+
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
34+
),
35+
...(
36+
| PipeItem<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
37+
| PipeItemAsync<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
38+
| MetadataAction<unknown, Record<string, unknown>>
39+
)[],
40+
]
41+
>;
42+
}
4143

4244
/**
4345
* Basic pipe item type.
@@ -74,7 +76,7 @@ type RecursiveMerge<
7476
*
7577
* @beta
7678
*/
77-
export type InferMetadata<TSchema extends Schema> =
79+
export type InferMetadata<TSchema extends getMetadata.Schema> =
7880
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7981
BaseSchema<any, any, any> extends TSchema
8082
? Record<string, unknown>
@@ -101,11 +103,11 @@ export type InferMetadata<TSchema extends Schema> =
101103
* @beta
102104
*/
103105
// @__NO_SIDE_EFFECTS__
104-
export function getMetadata<const TSchema extends Schema>(
106+
export function getMetadata<const TSchema extends getMetadata.Schema>(
105107
schema: TSchema
106108
): InferMetadata<TSchema> {
107109
const result = {};
108-
function depthFirstMerge(schema: Schema): void {
110+
function depthFirstMerge(schema: getMetadata.Schema): void {
109111
if ('pipe' in schema) {
110112
for (const item of schema.pipe) {
111113
if (item.kind === 'schema' && 'pipe' in item) {

library/src/methods/getTitle/getTitle.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,36 @@ import type {
99
import { _getLastMetadata } from '../../utils/index.ts';
1010
import type { SchemaWithPipe, SchemaWithPipeAsync } from '../index.ts';
1111

12-
/**
13-
* Schema type.
14-
*/
15-
type Schema =
16-
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
17-
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
18-
| SchemaWithPipe<
19-
readonly [
20-
BaseSchema<unknown, unknown, BaseIssue<unknown>>,
21-
...(
22-
| PipeItem<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
23-
| TitleAction<unknown, string>
24-
)[],
25-
]
26-
>
27-
| SchemaWithPipeAsync<
28-
readonly [
29-
(
30-
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
31-
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
32-
),
33-
...(
34-
| PipeItem<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
35-
| PipeItemAsync<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
36-
| TitleAction<unknown, string>
37-
)[],
38-
]
39-
>;
40-
12+
export namespace getTitle {
13+
/**
14+
* Schema type.
15+
*/
16+
export type Schema =
17+
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
18+
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
19+
| SchemaWithPipe<
20+
readonly [
21+
BaseSchema<unknown, unknown, BaseIssue<unknown>>,
22+
...(
23+
| PipeItem<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
24+
| TitleAction<unknown, string>
25+
)[],
26+
]
27+
>
28+
| SchemaWithPipeAsync<
29+
readonly [
30+
(
31+
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
32+
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
33+
),
34+
...(
35+
| PipeItem<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
36+
| PipeItemAsync<any, unknown, BaseIssue<unknown>> // eslint-disable-line @typescript-eslint/no-explicit-any
37+
| TitleAction<unknown, string>
38+
)[],
39+
]
40+
>;
41+
}
4142
/**
4243
* Returns the title of the schema.
4344
*
@@ -52,6 +53,6 @@ type Schema =
5253
*/
5354
// TODO: Investigate if return type can be strongly typed
5455
// @__NO_SIDE_EFFECTS__
55-
export function getTitle(schema: Schema): string | undefined {
56+
export function getTitle(schema: getTitle.Schema): string | undefined {
5657
return _getLastMetadata(schema, 'title');
5758
}

0 commit comments

Comments
 (0)