Skip to content

Commit 0f185e2

Browse files
committed
Release 0.13.30
1 parent cbc7c8b commit 0f185e2

13 files changed

Lines changed: 135 additions & 134 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "pave",
33
"type": "module",
4-
"version": "0.13.29",
4+
"version": "0.13.30",
55
"author": "Casey Foster <c@sey.me>",
66
"license": "MIT",
77
"repository": {

src/execute.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ const { Promise } = globalThis;
1010
const { isArray } = Array;
1111

1212
/**
13-
* @template {Schema<any>} S
1413
* @param {{
1514
* context?: any;
1615
* object?: any;
1716
* path?: string[];
1817
* query: Query;
19-
* schema: S;
20-
* type: Type<S, any>;
18+
* schema: Schema<any>;
19+
* type: Type<any>;
2120
* value?: any;
2221
* }} options
2322
*/

src/get-query-cost.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import { isObject } from '#src/is-object.js';
55
const { isArray } = Array;
66

77
/**
8-
* @template {Schema<any>} S
98
* @param {{
10-
* context?: SchemaContext<S>;
9+
* context?: any;
1110
* path?: string[];
1211
* query: Query;
13-
* schema: S;
14-
* type: Type<S, any>;
12+
* schema: Schema<any>;
13+
* type: Type<any>;
1514
* }} options
1615
*/
1716
export const getQueryCost = ({ context, path = [], query, schema, type }) => {

src/index.js

Lines changed: 64 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -12,76 +12,72 @@
1212
* @typedef {{
1313
* context?: any;
1414
* extensions?: { [K: string]: any };
15-
* typeName?: string;
16-
* }} SchemaOptions
15+
* input?: any;
16+
* object?: any;
17+
* resolvedValue?: {};
18+
* typeName?: string | unknown;
19+
* value?: any;
20+
* }} TypeOptions
1721
*/
1822

1923
/**
20-
* @template {SchemaOptions} [O={}] Default is `{}`
21-
* @template [_Context=O['context'] extends undefined ? unknown: O['context']]
22-
* Default is `O['context'] extends undefined ? unknown: O['context']`
23-
* @template [_Extensions=O['extensions'] extends undefined ? {} : O['extensions']]
24-
* Default is `O['extensions'] extends undefined ? {} : O['extensions']`
25-
* @template {string} [TypeName=O['typeName'] extends string ? O['typeName'] : never]
26-
* Default is `O['typeName'] extends string ? O['typeName'] : never`
27-
* @typedef {{ [K in TypeName]: Type<Schema<O>, any> }} Schema
28-
*/
29-
30-
/**
31-
* @template {Schema<any>} S
32-
* @typedef {S extends Schema<infer _, infer Context> ? Context : never} SchemaContext
24+
* @typedef {{
25+
* context: unknown;
26+
* extensions: {};
27+
* input: unknown;
28+
* object: unknown;
29+
* resolvedValue: {};
30+
* typeName: unknown;
31+
* value: unknown;
32+
* }} DefaultTypeOptions
3333
*/
3434

3535
/**
36-
* @template {Schema<any>} S
37-
* @typedef {S extends Schema<infer _, infer __, infer Extensions> ? Extensions : never} SchemaExtensions
36+
* @template {TypeOptions} Obj
37+
* @template {keyof TypeOptions} Key
38+
* @typedef {undefined extends Obj[Key] ? DefaultTypeOptions[Key] : Obj[Key]} GetTypeOption
3839
*/
3940

4041
/**
41-
* @template {Schema<any>} S
42-
* @typedef {S extends Schema<infer _, infer __, infer ___, infer TypeName>
43-
* ? TypeName
44-
* : never} SchemaTypeName
42+
* @template {TypeOptions} O
43+
* @typedef {Pick<O, 'context' | 'extensions' | 'typeName'>} SharedTypeOptions
4544
*/
4645

47-
/** @typedef {{ input?: any; object?: any; resolvedValue?: {}; value?: any }} TypeOptions */
48-
4946
/**
50-
* @template {Schema<any>} [S=Schema] Default is `Schema`
51-
* @template {TypeOptions} [O={}] Default is `{}`
52-
* @template [Input=O['input'] extends undefined ? unknown : O['input']]
53-
* Default is `O['input'] extends undefined ? unknown : O['input']`
54-
* @template [Object=O['object'] extends undefined ? unknown : O['object']]
55-
* Default is `O['object'] extends undefined ? unknown : O['object']`
56-
* @template [ResolvedValue=O['resolvedValue'] extends undefined ? {} : O['resolvedValue']]
57-
* Default is `O['resolvedValue'] extends undefined ? {} : O['resolvedValue']`
58-
* @template [Value=O['value'] extends undefined ? undefined : O['value']]
59-
* Default is `O['value'] extends undefined ? undefined : O['value']`
47+
* @template {TypeOptions} [O=DefaultTypeOptions] Default is
48+
* `DefaultTypeOptions`
6049
* @typedef {Recursive<
61-
* | SchemaTypeName<S>
50+
* | GetTypeOption<O, 'typeName'>
6251
* | ((
63-
* | { optional: Type<S, any> }
64-
* | { nullable: Type<S, any> }
65-
* | { arrayOf: Type<S, any>; minLength?: number; maxLength?: number }
52+
* | { optional: Type<SharedTypeOptions<O>> }
53+
* | { nullable: Type<SharedTypeOptions<O>> }
54+
* | {
55+
* arrayOf: Type<SharedTypeOptions<O>>;
56+
* minLength?: number;
57+
* maxLength?: number;
58+
* }
6659
* | {
67-
* oneOf: { [K: string]: Type<S, any> };
60+
* oneOf: { [K: string]: Type<SharedTypeOptions<O>> };
6861
* resolveType: (value: {}) => string;
6962
* }
70-
* | { object: { [K: string]: Type<S, any> }; defaultType?: Type<S, any> }
7163
* | {
72-
* input?: Type<S, any>;
73-
* type?: Type<S, any>;
64+
* object: { [K: string]: Type<SharedTypeOptions<O>> };
65+
* defaultType?: Type<SharedTypeOptions<O>>;
66+
* }
67+
* | {
68+
* input?: Type<SharedTypeOptions<O>>;
69+
* type?: Type<SharedTypeOptions<O>>;
7470
* typeInput?: any;
7571
* resolve?:
7672
* | ((options: {
77-
* context: SchemaContext<S>;
78-
* input: Input;
79-
* object: Object;
73+
* context: GetTypeOption<O, 'context'>;
74+
* input: GetTypeOption<O, 'input'>;
75+
* object: GetTypeOption<O, 'object'>;
8076
* path: string[];
8177
* query: Query;
82-
* schema: S;
83-
* type: Type<S, any>;
84-
* value: Value;
78+
* schema: Schema<SharedTypeOptions<O>>;
79+
* type: Type<SharedTypeOptions<O>>;
80+
* value: GetTypeOption<O, 'typeName'>;
8581
* }) => any)
8682
* | {}
8783
* | null;
@@ -90,31 +86,39 @@
9086
* cost?:
9187
* | number
9288
* | ((options: {
93-
* context: SchemaContext<S>;
89+
* context: GetTypeOption<O, 'context'>;
9490
* cost: number;
95-
* input: Input;
96-
* object: Object;
91+
* input: GetTypeOption<O, 'input'>;
92+
* object: GetTypeOption<O, 'object'>;
9793
* path: string[];
9894
* query: Query;
99-
* schema: S;
100-
* type: Type<S, any>;
101-
* value: Value;
95+
* schema: Schema<SharedTypeOptions<O>>;
96+
* type: Type<SharedTypeOptions<O>>;
97+
* value: GetTypeOption<O, 'typeName'>;
10298
* }) => number);
10399
* defaultValue?: any;
104100
* validate?: (options: {
105-
* context: SchemaContext<S>;
106-
* input: Input;
107-
* object: Object;
101+
* context: GetTypeOption<O, 'context'>;
102+
* input: GetTypeOption<O, 'input'>;
103+
* object: GetTypeOption<O, 'object'>;
108104
* path: string[];
109105
* query: Query;
110-
* schema: S;
111-
* type: Type<S, any>;
112-
* value: ResolvedValue;
106+
* schema: Schema<SharedTypeOptions<O>>;
107+
* type: Type<SharedTypeOptions<O>>;
108+
* value: GetTypeOption<O, 'resolvedValue'>;
113109
* }) => any;
114-
* } & SchemaExtensions<S>)
110+
* } & GetTypeOption<O, 'extensions'>)
115111
* >} Type
116112
*/
117113

114+
/**
115+
* @template {TypeOptions} [O=DefaultTypeOptions] Default is
116+
* `DefaultTypeOptions`
117+
* @typedef {GetTypeOption<O, 'typeName'> extends string
118+
* ? { [K in GetTypeOption<O, 'typeName'>]: Type<SharedTypeOptions<O>> }
119+
* : { [K in keyof any]: never }} Schema
120+
*/
121+
118122
/**
119123
* @template [T=any] Default is `any`
120124
* @typedef {{ _?: string; $?: any; _type?: { [K in keyof any]: never } }

src/validate-query.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ const { isArray } = Array;
99
const skipInput = {};
1010

1111
/**
12-
* @template {Schema<any>} S
1312
* @param {{
1413
* context?: any;
1514
* path?: string[];
1615
* query: Query;
17-
* schema: S;
18-
* type: Type<S, any>;
16+
* schema: Schema<any>;
17+
* type: Type<any>;
1918
* }} options
2019
* @returns {Query}
2120
*/

src/validate-schema.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ const { Set } = globalThis;
77

88
const { isArray } = Array;
99

10-
/**
11-
* @template {Schema<any>} S
12-
* @param {{ extensions?: { [K: string]: any }; schema: S }} options
13-
*/
10+
/** @param {{ extensions?: { [K: string]: any }; schema: S }} options */
1411
export const validateSchema = ({ extensions, schema }) => {
1512
const positiveNumber = {
1613
resolve: ({ value }) => {

src/validate-value.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ import { throwPaveError } from '#src/throw-pave-error.js';
77
const { isArray } = Array;
88

99
/**
10-
* @template {Schema<any>} S
1110
* @param {{
1211
* context?: any;
1312
* object?: any;
1413
* path?: string[];
1514
* query?: Query;
16-
* schema: S;
17-
* type: Type<S, any>;
15+
* schema: Schema<any>;
16+
* type: Type<any>;
1817
* value?: any;
1918
* }} options
2019
*/

types/execute.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
export function execute<S extends Schema<any>>({ context, object, path, query, schema, type, value }: {
1+
export function execute({ context, object, path, query, schema, type, value }: {
22
context?: any;
33
object?: any;
44
path?: string[];
55
query: Query;
6-
schema: S;
7-
type: Type<S, any>;
6+
schema: Schema<any>;
7+
type: Type<any>;
88
value?: any;
99
}): Promise<any>;
10-
import type { Schema } from '#types/index.js';
1110
import type { Query } from '#types/index.js';
11+
import type { Schema } from '#types/index.js';
1212
import type { Type } from '#types/index.js';

types/get-query-cost.d.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
export function getQueryCost<S extends Schema<any>>({ context, path, query, schema, type }: {
2-
context?: SchemaContext<S>;
1+
export function getQueryCost({ context, path, query, schema, type }: {
2+
context?: any;
33
path?: string[];
44
query: Query;
5-
schema: S;
6-
type: Type<S, any>;
5+
schema: Schema<any>;
6+
type: Type<any>;
77
}): any;
8-
import type { Schema } from '#types/index.js';
9-
import type { SchemaContext } from '#types/index.js';
108
import type { Query } from '#types/index.js';
9+
import type { Schema } from '#types/index.js';
1110
import type { Type } from '#types/index.js';

0 commit comments

Comments
 (0)