@feathersjs/typebox 5.0.8 → 5.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -5
- package/lib/index.d.ts +12 -10
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +16 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,21 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [5.0.
|
|
6
|
+
## [5.0.10](https://github.com/feathersjs/feathers/compare/v5.0.9...v5.0.10) (2023-10-03)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
### Bug Fixes
|
|
9
9
|
|
|
10
|
+
- **typebox:** Allow default value in StringEnum ([#3281](https://github.com/feathersjs/feathers/issues/3281)) ([25af09a](https://github.com/feathersjs/feathers/commit/25af09ad065e72768bf88bc8b529b68f2ca4da17))
|
|
10
11
|
|
|
12
|
+
## [5.0.9](https://github.com/feathersjs/feathers/compare/v5.0.8...v5.0.9) (2023-09-27)
|
|
11
13
|
|
|
14
|
+
### Bug Fixes
|
|
12
15
|
|
|
16
|
+
- **typebox:** allow TUnion<TObject[]> inside getValidator ([#3262](https://github.com/feathersjs/feathers/issues/3262)) ([cf9df96](https://github.com/feathersjs/feathers/commit/cf9df96c1011fcf13e9c6d652b06036bb0aac1c3))
|
|
13
17
|
|
|
14
|
-
## [5.0.
|
|
18
|
+
## [5.0.8](https://github.com/feathersjs/feathers/compare/v5.0.7...v5.0.8) (2023-07-19)
|
|
15
19
|
|
|
16
20
|
**Note:** Version bump only for package @feathersjs/typebox
|
|
17
21
|
|
|
22
|
+
## [5.0.7](https://github.com/feathersjs/feathers/compare/v5.0.6...v5.0.7) (2023-07-14)
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
**Note:** Version bump only for package @feathersjs/typebox
|
|
21
25
|
|
|
22
26
|
## [5.0.6](https://github.com/feathersjs/feathers/compare/v5.0.5...v5.0.6) (2023-06-15)
|
|
23
27
|
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TObject, TInteger, TOptional, TSchema, ObjectOptions, TIntersect } from '@sinclair/typebox';
|
|
1
|
+
import { TObject, TInteger, TOptional, TSchema, ObjectOptions, TIntersect, TUnion } from '@sinclair/typebox';
|
|
2
2
|
import { Validator, DataValidatorMap, Ajv } from '@feathersjs/schema';
|
|
3
3
|
export * from '@sinclair/typebox';
|
|
4
4
|
export * from './default-schemas';
|
|
@@ -14,7 +14,7 @@ export type TDataSchemaMap = {
|
|
|
14
14
|
* @param validator The AJV validation instance
|
|
15
15
|
* @returns A compiled validation function
|
|
16
16
|
*/
|
|
17
|
-
export declare const getValidator: <T = any, R = T>(schema: TObject | TIntersect
|
|
17
|
+
export declare const getValidator: <T = any, R = T>(schema: TObject | TIntersect | TUnion<TObject[]>, validator: Ajv) => Validator<T, R>;
|
|
18
18
|
/**
|
|
19
19
|
* Returns compiled validation functions to validate data for the `create`, `update` and `patch`
|
|
20
20
|
* service methods. If not passed explicitly, the `update` validator will be the same as the `create`
|
|
@@ -31,7 +31,9 @@ export declare const getDataValidator: (def: TObject | TDataSchemaMap, validator
|
|
|
31
31
|
* @param allowedValues array of strings for the enum
|
|
32
32
|
* @returns TypeBox.Type
|
|
33
33
|
*/
|
|
34
|
-
export declare function StringEnum<T extends string[]>(allowedValues: [...T]
|
|
34
|
+
export declare function StringEnum<T extends string[]>(allowedValues: [...T], options?: {
|
|
35
|
+
default: T[number];
|
|
36
|
+
}): import("@sinclair/typebox").TUnsafe<T[number]>;
|
|
35
37
|
/**
|
|
36
38
|
* Creates the `$sort` Feathers query syntax schema for an object schema
|
|
37
39
|
*
|
|
@@ -49,7 +51,7 @@ export declare function sortDefinition<T extends TObject>(schema: T): TObject<{
|
|
|
49
51
|
*/
|
|
50
52
|
export declare const queryProperty: <T extends TSchema, X extends {
|
|
51
53
|
[key: string]: TSchema;
|
|
52
|
-
}>(def: T, extension?: X) => TOptional<
|
|
54
|
+
}>(def: T, extension?: X) => TOptional<TUnion<[T, import("@sinclair/typebox").TPartial<TIntersect<[TObject<{
|
|
53
55
|
$gt: T;
|
|
54
56
|
$gte: T;
|
|
55
57
|
$lt: T;
|
|
@@ -67,7 +69,7 @@ export declare const queryProperty: <T extends TSchema, X extends {
|
|
|
67
69
|
*/
|
|
68
70
|
export declare const queryProperties: <T extends TObject<import("@sinclair/typebox").TProperties>, X extends { [K in keyof T["properties"]]?: {
|
|
69
71
|
[key: string]: TSchema;
|
|
70
|
-
}; }>(definition: T, extensions?: X) => TOptional<TObject<{ [K_1 in keyof T["properties"]]: TOptional<
|
|
72
|
+
}; }>(definition: T, extensions?: X) => TOptional<TObject<{ [K_1 in keyof T["properties"]]: TOptional<TUnion<[T["properties"][K_1], import("@sinclair/typebox").TPartial<TIntersect<[TObject<{
|
|
71
73
|
$gt: T["properties"][K_1];
|
|
72
74
|
$gte: T["properties"][K_1];
|
|
73
75
|
$lt: T["properties"][K_1];
|
|
@@ -92,7 +94,7 @@ export declare const querySyntax: <T extends TObject<import("@sinclair/typebox")
|
|
|
92
94
|
$skip: import("@sinclair/typebox").TNumber;
|
|
93
95
|
$sort: TObject<{ [K_1 in keyof T["properties"]]: TOptional<TInteger>; }>;
|
|
94
96
|
$select: import("@sinclair/typebox").TUnsafe<(keyof T["properties"])[]>;
|
|
95
|
-
$and: import("@sinclair/typebox").TArray<
|
|
97
|
+
$and: import("@sinclair/typebox").TArray<TUnion<[TOptional<TObject<{ [K_2 in keyof T["properties"]]: TOptional<TUnion<[T["properties"][K_2], import("@sinclair/typebox").TPartial<TIntersect<[TObject<{
|
|
96
98
|
$gt: T["properties"][K_2];
|
|
97
99
|
$gte: T["properties"][K_2];
|
|
98
100
|
$lt: T["properties"][K_2];
|
|
@@ -101,7 +103,7 @@ export declare const querySyntax: <T extends TObject<import("@sinclair/typebox")
|
|
|
101
103
|
$in: import("@sinclair/typebox").TArray<T["properties"][K_2]>;
|
|
102
104
|
$nin: import("@sinclair/typebox").TArray<T["properties"][K_2]>;
|
|
103
105
|
}>, TObject<X[K_2]>]>>]>>; }>>, TObject<{
|
|
104
|
-
$or: import("@sinclair/typebox").TArray<TOptional<TObject<{ [K_2 in keyof T["properties"]]: TOptional<
|
|
106
|
+
$or: import("@sinclair/typebox").TArray<TOptional<TObject<{ [K_2 in keyof T["properties"]]: TOptional<TUnion<[T["properties"][K_2], import("@sinclair/typebox").TPartial<TIntersect<[TObject<{
|
|
105
107
|
$gt: T["properties"][K_2];
|
|
106
108
|
$gte: T["properties"][K_2];
|
|
107
109
|
$lt: T["properties"][K_2];
|
|
@@ -111,7 +113,7 @@ export declare const querySyntax: <T extends TObject<import("@sinclair/typebox")
|
|
|
111
113
|
$nin: import("@sinclair/typebox").TArray<T["properties"][K_2]>;
|
|
112
114
|
}>, TObject<X[K_2]>]>>]>>; }>>>;
|
|
113
115
|
}>]>>;
|
|
114
|
-
$or: import("@sinclair/typebox").TArray<TOptional<TObject<{ [K_2 in keyof T["properties"]]: TOptional<
|
|
116
|
+
$or: import("@sinclair/typebox").TArray<TOptional<TObject<{ [K_2 in keyof T["properties"]]: TOptional<TUnion<[T["properties"][K_2], import("@sinclair/typebox").TPartial<TIntersect<[TObject<{
|
|
115
117
|
$gt: T["properties"][K_2];
|
|
116
118
|
$gte: T["properties"][K_2];
|
|
117
119
|
$lt: T["properties"][K_2];
|
|
@@ -120,7 +122,7 @@ export declare const querySyntax: <T extends TObject<import("@sinclair/typebox")
|
|
|
120
122
|
$in: import("@sinclair/typebox").TArray<T["properties"][K_2]>;
|
|
121
123
|
$nin: import("@sinclair/typebox").TArray<T["properties"][K_2]>;
|
|
122
124
|
}>, TObject<X[K_2]>]>>]>>; }>>>;
|
|
123
|
-
}>>, TOptional<TObject<{ [K_2 in keyof T["properties"]]: TOptional<
|
|
125
|
+
}>>, TOptional<TObject<{ [K_2 in keyof T["properties"]]: TOptional<TUnion<[T["properties"][K_2], import("@sinclair/typebox").TPartial<TIntersect<[TObject<{
|
|
124
126
|
$gt: T["properties"][K_2];
|
|
125
127
|
$gte: T["properties"][K_2];
|
|
126
128
|
$lt: T["properties"][K_2];
|
|
@@ -129,4 +131,4 @@ export declare const querySyntax: <T extends TObject<import("@sinclair/typebox")
|
|
|
129
131
|
$in: import("@sinclair/typebox").TArray<T["properties"][K_2]>;
|
|
130
132
|
$nin: import("@sinclair/typebox").TArray<T["properties"][K_2]>;
|
|
131
133
|
}>, TObject<X[K_2]>]>>]>>; }>>]>;
|
|
132
|
-
export declare const ObjectIdSchema: () =>
|
|
134
|
+
export declare const ObjectIdSchema: () => TUnion<[import("@sinclair/typebox").TString<string>, TObject<{}>]>;
|
package/lib/index.js
CHANGED
|
@@ -45,8 +45,8 @@ exports.getDataValidator = getDataValidator;
|
|
|
45
45
|
* @param allowedValues array of strings for the enum
|
|
46
46
|
* @returns TypeBox.Type
|
|
47
47
|
*/
|
|
48
|
-
function StringEnum(allowedValues) {
|
|
49
|
-
return typebox_1.Type.Unsafe({ type: 'string', enum: allowedValues });
|
|
48
|
+
function StringEnum(allowedValues, options) {
|
|
49
|
+
return typebox_1.Type.Unsafe({ type: 'string', enum: allowedValues, ...options });
|
|
50
50
|
}
|
|
51
51
|
exports.StringEnum = StringEnum;
|
|
52
52
|
const arrayOfKeys = (type) => {
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAS0B;AAC1B,+CAAiF;AAEjF,oDAAiC;AACjC,oDAAiC;AAQjC;;;;;;GAMG;AACI,MAAM,YAAY,GAA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GAAG,EAAE,CACjC,cAAI,CAAC,KAAK,CAAC,CAAC,cAAI,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,cAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;AADpF,QAAA,cAAc,kBACsE"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@feathersjs/typebox",
|
|
3
3
|
"description": "TypeBox integration for @feathersjs/schema",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.10",
|
|
5
5
|
"homepage": "https://feathersjs.com",
|
|
6
6
|
"main": "lib/",
|
|
7
7
|
"types": "lib/",
|
|
@@ -54,15 +54,15 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@feathersjs/schema": "^5.0.
|
|
57
|
+
"@feathersjs/schema": "^5.0.10",
|
|
58
58
|
"@sinclair/typebox": "^0.25.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@types/mocha": "^10.0.
|
|
62
|
-
"@types/node": "^20.
|
|
61
|
+
"@types/mocha": "^10.0.2",
|
|
62
|
+
"@types/node": "^20.8.2",
|
|
63
63
|
"mocha": "^10.2.0",
|
|
64
64
|
"shx": "^0.3.4",
|
|
65
|
-
"typescript": "^5.
|
|
65
|
+
"typescript": "^5.2.2"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "463dedcd35b16e43bc55e04df877ca82ed38dcea"
|
|
68
68
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Type,
|
|
3
|
+
TObject,
|
|
4
|
+
TInteger,
|
|
5
|
+
TOptional,
|
|
6
|
+
TSchema,
|
|
7
|
+
ObjectOptions,
|
|
8
|
+
TIntersect,
|
|
9
|
+
TUnion
|
|
10
|
+
} from '@sinclair/typebox'
|
|
2
11
|
import { jsonSchema, Validator, DataValidatorMap, Ajv } from '@feathersjs/schema'
|
|
3
12
|
|
|
4
13
|
export * from '@sinclair/typebox'
|
|
@@ -17,8 +26,10 @@ export type TDataSchemaMap = {
|
|
|
17
26
|
* @param validator The AJV validation instance
|
|
18
27
|
* @returns A compiled validation function
|
|
19
28
|
*/
|
|
20
|
-
export const getValidator = <T = any, R = T>(
|
|
21
|
-
|
|
29
|
+
export const getValidator = <T = any, R = T>(
|
|
30
|
+
schema: TObject | TIntersect | TUnion<TObject[]>,
|
|
31
|
+
validator: Ajv
|
|
32
|
+
): Validator<T, R> => jsonSchema.getValidator(schema as any, validator)
|
|
22
33
|
|
|
23
34
|
/**
|
|
24
35
|
* Returns compiled validation functions to validate data for the `create`, `update` and `patch`
|
|
@@ -38,8 +49,8 @@ export const getDataValidator = (def: TObject | TDataSchemaMap, validator: Ajv):
|
|
|
38
49
|
* @param allowedValues array of strings for the enum
|
|
39
50
|
* @returns TypeBox.Type
|
|
40
51
|
*/
|
|
41
|
-
export function StringEnum<T extends string[]>(allowedValues: [...T]) {
|
|
42
|
-
return Type.Unsafe<T[number]>({ type: 'string', enum: allowedValues })
|
|
52
|
+
export function StringEnum<T extends string[]>(allowedValues: [...T], options?: { default: T[number] }) {
|
|
53
|
+
return Type.Unsafe<T[number]>({ type: 'string', enum: allowedValues, ...options })
|
|
43
54
|
}
|
|
44
55
|
|
|
45
56
|
const arrayOfKeys = <T extends TObject>(type: T) => {
|