@feathersjs/typebox 5.0.1 → 5.0.4
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 +16 -0
- package/README.md +1 -1
- package/lib/default-schemas.d.ts +37 -37
- package/lib/default-schemas.js +4 -1
- package/lib/default-schemas.js.map +1 -1
- package/lib/index.d.ts +80 -65
- package/lib/index.js +60 -19
- package/lib/index.js.map +1 -1
- package/package.json +6 -6
- package/src/default-schemas.ts +6 -1
- package/src/index.ts +65 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
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.4](https://github.com/feathersjs/feathers/compare/v5.0.3...v5.0.4) (2023-04-12)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- Make sure all Readme files are up to date ([#3154](https://github.com/feathersjs/feathers/issues/3154)) ([a5f0b38](https://github.com/feathersjs/feathers/commit/a5f0b38bbf2a11486415a39533bcc6c67fb51e3e))
|
|
11
|
+
- **typebox:** Implement custom TypeBuilder for backwards compatibility ([#3150](https://github.com/feathersjs/feathers/issues/3150)) ([962bd87](https://github.com/feathersjs/feathers/commit/962bd87217212320b1a68f6556a16b8a6b8f757c))
|
|
12
|
+
|
|
13
|
+
## [5.0.3](https://github.com/feathersjs/feathers/compare/v5.0.2...v5.0.3) (2023-04-05)
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
- **authentication:** Ensure authentication.entity configuration can be null ([#3136](https://github.com/feathersjs/feathers/issues/3136)) ([c47349b](https://github.com/feathersjs/feathers/commit/c47349b9dcf2067b7b572c5463b15b2a8fbda972))
|
|
18
|
+
- **dependencies:** Update all dependencies ([#3139](https://github.com/feathersjs/feathers/issues/3139)) ([f24276e](https://github.com/feathersjs/feathers/commit/f24276e9a909e2e58a0730c730258ce1f70f4028))
|
|
19
|
+
- **knex:** Get by id and transactions should work with params.knex ([#3146](https://github.com/feathersjs/feathers/issues/3146)) ([b172b5e](https://github.com/feathersjs/feathers/commit/b172b5ea9b461642874eb7d2ba01dc4cfc275155))
|
|
20
|
+
- **typebox:** Upgrade to TypeBox 0.26.0 ([#3113](https://github.com/feathersjs/feathers/issues/3113)) ([d1d9598](https://github.com/feathersjs/feathers/commit/d1d95984dd94d2b9305e7338421f84f9c4f733fd))
|
|
21
|
+
|
|
6
22
|
## [5.0.1](https://github.com/feathersjs/feathers/compare/v5.0.0...v5.0.1) (2023-03-15)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package @feathersjs/typebox
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ npm install @feathersjs/typebox --save
|
|
|
14
14
|
|
|
15
15
|
## Documentation
|
|
16
16
|
|
|
17
|
-
Refer to the [Feathers documentation](https://
|
|
17
|
+
Refer to the [Feathers TypeBox documentation](https://feathersjs.com/api/schema/typebox.html) for more details.
|
|
18
18
|
|
|
19
19
|
## License
|
|
20
20
|
|
package/lib/default-schemas.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Static } from '@sinclair/typebox';
|
|
2
2
|
export declare const authenticationSettingsSchema: import("@sinclair/typebox").TObject<{
|
|
3
3
|
secret: import("@sinclair/typebox").TString<string>;
|
|
4
|
-
entity: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
4
|
+
entity: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString<string>, import("@sinclair/typebox").TNull]>>;
|
|
5
5
|
entityId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
6
6
|
service: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
7
7
|
authStrategies: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString<string>>;
|
|
@@ -30,13 +30,13 @@ export declare const authenticationSettingsSchema: import("@sinclair/typebox").T
|
|
|
30
30
|
}>;
|
|
31
31
|
export declare const sqlSettingsSchema: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
32
32
|
client: import("@sinclair/typebox").TString<string>;
|
|
33
|
-
connection: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString<string>, import("@sinclair/typebox").
|
|
34
|
-
host: import("@sinclair/typebox").TString<string
|
|
35
|
-
port: import("@sinclair/typebox").TNumber
|
|
36
|
-
user: import("@sinclair/typebox").TString<string
|
|
37
|
-
password: import("@sinclair/typebox").TString<string
|
|
38
|
-
database: import("@sinclair/typebox").TString<string
|
|
39
|
-
}
|
|
33
|
+
connection: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString<string>, import("@sinclair/typebox").TObject<{
|
|
34
|
+
host: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
35
|
+
port: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
36
|
+
user: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
37
|
+
password: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
38
|
+
database: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
39
|
+
}>]>;
|
|
40
40
|
pool: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
41
41
|
min: import("@sinclair/typebox").TNumber;
|
|
42
42
|
max: import("@sinclair/typebox").TNumber;
|
|
@@ -45,7 +45,7 @@ export declare const sqlSettingsSchema: import("@sinclair/typebox").TOptional<im
|
|
|
45
45
|
export declare const defaultAppConfiguration: import("@sinclair/typebox").TObject<{
|
|
46
46
|
authentication: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
47
47
|
secret: import("@sinclair/typebox").TString<string>;
|
|
48
|
-
entity: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
48
|
+
entity: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString<string>, import("@sinclair/typebox").TNull]>>;
|
|
49
49
|
entityId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
50
50
|
service: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
51
51
|
authStrategies: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString<string>>;
|
|
@@ -80,13 +80,13 @@ export declare const defaultAppConfiguration: import("@sinclair/typebox").TObjec
|
|
|
80
80
|
mongodb: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
81
81
|
mysql: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
82
82
|
client: import("@sinclair/typebox").TString<string>;
|
|
83
|
-
connection: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString<string>, import("@sinclair/typebox").
|
|
84
|
-
host: import("@sinclair/typebox").TString<string
|
|
85
|
-
port: import("@sinclair/typebox").TNumber
|
|
86
|
-
user: import("@sinclair/typebox").TString<string
|
|
87
|
-
password: import("@sinclair/typebox").TString<string
|
|
88
|
-
database: import("@sinclair/typebox").TString<string
|
|
89
|
-
}
|
|
83
|
+
connection: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString<string>, import("@sinclair/typebox").TObject<{
|
|
84
|
+
host: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
85
|
+
port: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
86
|
+
user: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
87
|
+
password: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
88
|
+
database: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
89
|
+
}>]>;
|
|
90
90
|
pool: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
91
91
|
min: import("@sinclair/typebox").TNumber;
|
|
92
92
|
max: import("@sinclair/typebox").TNumber;
|
|
@@ -94,13 +94,13 @@ export declare const defaultAppConfiguration: import("@sinclair/typebox").TObjec
|
|
|
94
94
|
}>>;
|
|
95
95
|
postgresql: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
96
96
|
client: import("@sinclair/typebox").TString<string>;
|
|
97
|
-
connection: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString<string>, import("@sinclair/typebox").
|
|
98
|
-
host: import("@sinclair/typebox").TString<string
|
|
99
|
-
port: import("@sinclair/typebox").TNumber
|
|
100
|
-
user: import("@sinclair/typebox").TString<string
|
|
101
|
-
password: import("@sinclair/typebox").TString<string
|
|
102
|
-
database: import("@sinclair/typebox").TString<string
|
|
103
|
-
}
|
|
97
|
+
connection: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString<string>, import("@sinclair/typebox").TObject<{
|
|
98
|
+
host: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
99
|
+
port: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
100
|
+
user: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
101
|
+
password: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
102
|
+
database: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
103
|
+
}>]>;
|
|
104
104
|
pool: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
105
105
|
min: import("@sinclair/typebox").TNumber;
|
|
106
106
|
max: import("@sinclair/typebox").TNumber;
|
|
@@ -108,13 +108,13 @@ export declare const defaultAppConfiguration: import("@sinclair/typebox").TObjec
|
|
|
108
108
|
}>>;
|
|
109
109
|
sqlite: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
110
110
|
client: import("@sinclair/typebox").TString<string>;
|
|
111
|
-
connection: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString<string>, import("@sinclair/typebox").
|
|
112
|
-
host: import("@sinclair/typebox").TString<string
|
|
113
|
-
port: import("@sinclair/typebox").TNumber
|
|
114
|
-
user: import("@sinclair/typebox").TString<string
|
|
115
|
-
password: import("@sinclair/typebox").TString<string
|
|
116
|
-
database: import("@sinclair/typebox").TString<string
|
|
117
|
-
}
|
|
111
|
+
connection: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString<string>, import("@sinclair/typebox").TObject<{
|
|
112
|
+
host: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
113
|
+
port: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
114
|
+
user: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
115
|
+
password: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
116
|
+
database: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
117
|
+
}>]>;
|
|
118
118
|
pool: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
119
119
|
min: import("@sinclair/typebox").TNumber;
|
|
120
120
|
max: import("@sinclair/typebox").TNumber;
|
|
@@ -122,13 +122,13 @@ export declare const defaultAppConfiguration: import("@sinclair/typebox").TObjec
|
|
|
122
122
|
}>>;
|
|
123
123
|
mssql: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
124
124
|
client: import("@sinclair/typebox").TString<string>;
|
|
125
|
-
connection: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString<string>, import("@sinclair/typebox").
|
|
126
|
-
host: import("@sinclair/typebox").TString<string
|
|
127
|
-
port: import("@sinclair/typebox").TNumber
|
|
128
|
-
user: import("@sinclair/typebox").TString<string
|
|
129
|
-
password: import("@sinclair/typebox").TString<string
|
|
130
|
-
database: import("@sinclair/typebox").TString<string
|
|
131
|
-
}
|
|
125
|
+
connection: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString<string>, import("@sinclair/typebox").TObject<{
|
|
126
|
+
host: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
127
|
+
port: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
128
|
+
user: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
129
|
+
password: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
130
|
+
database: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
|
|
131
|
+
}>]>;
|
|
132
132
|
pool: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
133
133
|
min: import("@sinclair/typebox").TNumber;
|
|
134
134
|
max: import("@sinclair/typebox").TNumber;
|
package/lib/default-schemas.js
CHANGED
|
@@ -4,7 +4,10 @@ exports.defaultAppConfiguration = exports.sqlSettingsSchema = exports.authentica
|
|
|
4
4
|
const typebox_1 = require("@sinclair/typebox");
|
|
5
5
|
exports.authenticationSettingsSchema = typebox_1.Type.Object({
|
|
6
6
|
secret: typebox_1.Type.String({ description: 'The JWT signing secret' }),
|
|
7
|
-
entity: typebox_1.Type.Optional(typebox_1.Type.
|
|
7
|
+
entity: typebox_1.Type.Optional(typebox_1.Type.Union([
|
|
8
|
+
typebox_1.Type.String({ description: 'The name of the authentication entity (e.g. user)' }),
|
|
9
|
+
typebox_1.Type.Null()
|
|
10
|
+
])),
|
|
8
11
|
entityId: typebox_1.Type.Optional(typebox_1.Type.String({ description: 'The name of the authentication entity id property' })),
|
|
9
12
|
service: typebox_1.Type.Optional(typebox_1.Type.String({ description: 'The path of the entity service' })),
|
|
10
13
|
authStrategies: typebox_1.Type.Array(typebox_1.Type.String(), {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-schemas.js","sourceRoot":"","sources":["../src/default-schemas.ts"],"names":[],"mappings":";;;AAAA,+CAAgD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AQ,CAAC,cAAI,CAAC,KAAK,CAAC,cAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACjD,OAAO,EAAE,cAAI,CAAC,QAAQ,CAAC,cAAI,CAAC,MAAM,EAAE,CAAC;IACrC,KAAK,EAAE,yBAAiB;IACxB,UAAU,EAAE,yBAAiB;IAC7B,MAAM,EAAE,yBAAiB;IACzB,KAAK,EAAE,yBAAiB;CACzB,EACD,EAAE,GAAG,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,KAAK,EAAE,CACjE,CAAA"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
import { TObject, TInteger, TOptional, TSchema, TIntersect, ObjectOptions } from '@sinclair/typebox';
|
|
1
|
+
import { TObject, TInteger, TOptional, TSchema, TIntersect, ObjectOptions, ExtendedTypeBuilder, SchemaOptions, TNever, IntersectOptions } from '@sinclair/typebox';
|
|
2
2
|
import { Validator, DataValidatorMap, Ajv } from '@feathersjs/schema';
|
|
3
3
|
export * from '@sinclair/typebox';
|
|
4
4
|
export * from './default-schemas';
|
|
5
|
+
/**
|
|
6
|
+
* Feathers TypeBox customisations. Implements the 0.25.0 fallback for Intersect types.
|
|
7
|
+
* @see https://github.com/sinclairzx81/typebox/issues/373
|
|
8
|
+
*/
|
|
9
|
+
export declare class FeathersTypeBuilder extends ExtendedTypeBuilder {
|
|
10
|
+
/** `[Standard]` Creates a Intersect type */
|
|
11
|
+
Intersect(allOf: [], options?: SchemaOptions): TNever;
|
|
12
|
+
/** `[Standard]` Creates a Intersect type */
|
|
13
|
+
Intersect<T extends [TObject]>(allOf: [...T], options?: SchemaOptions): T[0];
|
|
14
|
+
Intersect<T extends TObject[]>(allOf: [...T], options?: IntersectOptions): TIntersect<T>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Exports our own type builder
|
|
18
|
+
*/
|
|
19
|
+
export declare const Type: FeathersTypeBuilder;
|
|
5
20
|
export type TDataSchemaMap = {
|
|
6
21
|
create: TObject;
|
|
7
22
|
update?: TObject;
|
|
@@ -14,7 +29,7 @@ export type TDataSchemaMap = {
|
|
|
14
29
|
* @param validator The AJV validation instance
|
|
15
30
|
* @returns A compiled validation function
|
|
16
31
|
*/
|
|
17
|
-
export declare const getValidator: <T = any, R = T>(schema: TObject, validator: Ajv) => Validator<T, R>;
|
|
32
|
+
export declare const getValidator: <T = any, R = T>(schema: TObject | TIntersect, validator: Ajv) => Validator<T, R>;
|
|
18
33
|
/**
|
|
19
34
|
* Returns compiled validation functions to validate data for the `create`, `update` and `patch`
|
|
20
35
|
* service methods. If not passed explicitly, the `update` validator will be the same as the `create`
|
|
@@ -38,7 +53,7 @@ export declare function StringEnum<T extends string[]>(allowedValues: [...T]): i
|
|
|
38
53
|
* @param schema The TypeBox object schema
|
|
39
54
|
* @returns The `$sort` syntax schema
|
|
40
55
|
*/
|
|
41
|
-
export declare function sortDefinition<T extends TObject>(schema: T): TObject<T["properties"] extends infer T_1 ? { [K in keyof T_1]: TOptional<TInteger>; } : never>;
|
|
56
|
+
export declare function sortDefinition<T extends TObject | TIntersect>(schema: T): TObject<T["properties"] extends infer T_1 ? { [K in keyof T_1]: TOptional<TInteger>; } : never>;
|
|
42
57
|
/**
|
|
43
58
|
* Returns the standard Feathers query syntax for a property schema,
|
|
44
59
|
* including operators like `$gt`, `$lt` etc. for a single property
|
|
@@ -49,15 +64,15 @@ export declare function sortDefinition<T extends TObject>(schema: T): TObject<T[
|
|
|
49
64
|
*/
|
|
50
65
|
export declare const queryProperty: <T extends TSchema, X extends {
|
|
51
66
|
[key: string]: TSchema;
|
|
52
|
-
}>(def: T, extension?: X) => TOptional<import("@sinclair/typebox").TUnion<[T, import("@sinclair/typebox").
|
|
53
|
-
$gt: T
|
|
54
|
-
$gte: T
|
|
55
|
-
$lt: T
|
|
56
|
-
$lte: T
|
|
57
|
-
$ne: T
|
|
58
|
-
$in: import("@sinclair/typebox").TArray<T
|
|
59
|
-
$nin: import("@sinclair/typebox").TArray<T
|
|
60
|
-
}
|
|
67
|
+
}>(def: T, extension?: X) => TOptional<import("@sinclair/typebox").TUnion<[T, import("@sinclair/typebox").TComposite<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
|
|
68
|
+
$gt: T extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T>;
|
|
69
|
+
$gte: T extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T>;
|
|
70
|
+
$lt: T extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T>;
|
|
71
|
+
$lte: T extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T>;
|
|
72
|
+
$ne: T extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T>;
|
|
73
|
+
$in: TOptional<import("@sinclair/typebox").TArray<T>>;
|
|
74
|
+
$nin: TOptional<import("@sinclair/typebox").TArray<T>>;
|
|
75
|
+
}, import("@sinclair/typebox").TProperties>>>, TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{ [K in keyof X]: X[K] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : X[K] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : X[K] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<X[K]>; }, import("@sinclair/typebox").TProperties>>>]>]>>;
|
|
61
76
|
/**
|
|
62
77
|
* Creates a Feathers query syntax schema for the properties defined in `definition`.
|
|
63
78
|
*
|
|
@@ -65,17 +80,17 @@ export declare const queryProperty: <T extends TSchema, X extends {
|
|
|
65
80
|
* @param extensions Additional properties to add to a property query
|
|
66
81
|
* @returns The Feathers query syntax schema
|
|
67
82
|
*/
|
|
68
|
-
export declare const queryProperties: <T extends TObject<import("@sinclair/typebox").TProperties>, X extends T["properties"] extends infer T_1 ? { [K in keyof T_1]?: {
|
|
83
|
+
export declare const queryProperties: <T extends TObject<import("@sinclair/typebox").TProperties> | TIntersect<TSchema[]>, X extends T["properties"] extends infer T_1 ? { [K in keyof T_1]?: {
|
|
69
84
|
[key: string]: TSchema;
|
|
70
|
-
}; } : never>(definition: T, extensions?: X) => TOptional<TObject<T["properties"] extends infer T_2 ? { [K_1 in keyof T_2]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_1], import("@sinclair/typebox").
|
|
71
|
-
$gt: T["properties"][K_1]
|
|
72
|
-
$gte: T["properties"][K_1]
|
|
73
|
-
$lt: T["properties"][K_1]
|
|
74
|
-
$lte: T["properties"][K_1]
|
|
75
|
-
$ne: T["properties"][K_1]
|
|
76
|
-
$in: import("@sinclair/typebox").TArray<T["properties"][K_1]
|
|
77
|
-
$nin: import("@sinclair/typebox").TArray<T["properties"][K_1]
|
|
78
|
-
}
|
|
85
|
+
}; } : never>(definition: T, extensions?: X) => TOptional<TObject<T["properties"] extends infer T_2 ? { [K_1 in keyof T_2]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_1], import("@sinclair/typebox").TComposite<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
|
|
86
|
+
$gt: T["properties"][K_1] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_1] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_1] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_1]>;
|
|
87
|
+
$gte: T["properties"][K_1] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_1] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_1] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_1]>;
|
|
88
|
+
$lt: T["properties"][K_1] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_1] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_1] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_1]>;
|
|
89
|
+
$lte: T["properties"][K_1] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_1] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_1] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_1]>;
|
|
90
|
+
$ne: T["properties"][K_1] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_1] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_1] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_1]>;
|
|
91
|
+
$in: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_1]>>;
|
|
92
|
+
$nin: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_1]>>;
|
|
93
|
+
}, import("@sinclair/typebox").TProperties>>>, TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<X[K_1] extends infer T_3 extends import("@sinclair/typebox").TProperties ? { [K_2 in keyof T_3]: X[K_1][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : X[K_1][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : X[K_1][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<X[K_1][K_2]>; } : never, import("@sinclair/typebox").TProperties>>>]>]>>; } : never>>;
|
|
79
94
|
/**
|
|
80
95
|
* Creates a TypeBox schema for the complete Feathers query syntax including `$limit`, $skip`, `$or`
|
|
81
96
|
* and `$sort` and `$select` for the allowed properties.
|
|
@@ -85,48 +100,48 @@ export declare const queryProperties: <T extends TObject<import("@sinclair/typeb
|
|
|
85
100
|
* @param options Options for the TypeBox object schema
|
|
86
101
|
* @returns A TypeBox object representing the complete Feathers query syntax for the given properties
|
|
87
102
|
*/
|
|
88
|
-
export declare const querySyntax: <T extends TObject<import("@sinclair/typebox").TProperties> | TIntersect<
|
|
103
|
+
export declare const querySyntax: <T extends TObject<import("@sinclair/typebox").TProperties> | TIntersect<TSchema[]>, X extends T["properties"] extends infer T_1 ? { [K in keyof T_1]?: {
|
|
89
104
|
[key: string]: TSchema;
|
|
90
|
-
}; } : never>(type: T, extensions?: X, options?: ObjectOptions) =>
|
|
91
|
-
$limit: import("@sinclair/typebox").TNumber
|
|
92
|
-
$skip: import("@sinclair/typebox").TNumber
|
|
93
|
-
$sort: TObject<T["properties"] extends infer T_2 ? { [K_1 in keyof T_2]: TOptional<TInteger>; } : never
|
|
94
|
-
$select: import("@sinclair/typebox").TUnsafe<(keyof T["properties"])[]
|
|
95
|
-
$and: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<[TOptional<TObject<T["properties"] extends infer T_3 ? { [K_2 in keyof T_3]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_2], import("@sinclair/typebox").
|
|
96
|
-
$gt: T["properties"][K_2]
|
|
97
|
-
$gte: T["properties"][K_2]
|
|
98
|
-
$lt: T["properties"][K_2]
|
|
99
|
-
$lte: T["properties"][K_2]
|
|
100
|
-
$ne: T["properties"][K_2]
|
|
101
|
-
$in: import("@sinclair/typebox").TArray<T["properties"][K_2]
|
|
102
|
-
$nin: import("@sinclair/typebox").TArray<T["properties"][K_2]
|
|
103
|
-
}
|
|
104
|
-
$or: import("@sinclair/typebox").TArray<TOptional<TObject<T["properties"] extends infer
|
|
105
|
-
$gt: T["properties"][K_2]
|
|
106
|
-
$gte: T["properties"][K_2]
|
|
107
|
-
$lt: T["properties"][K_2]
|
|
108
|
-
$lte: T["properties"][K_2]
|
|
109
|
-
$ne: T["properties"][K_2]
|
|
110
|
-
$in: import("@sinclair/typebox").TArray<T["properties"][K_2]
|
|
111
|
-
$nin: import("@sinclair/typebox").TArray<T["properties"][K_2]
|
|
112
|
-
}
|
|
113
|
-
}>]
|
|
114
|
-
$or: import("@sinclair/typebox").TArray<TOptional<TObject<T["properties"] extends infer
|
|
115
|
-
$gt: T["properties"][K_2]
|
|
116
|
-
$gte: T["properties"][K_2]
|
|
117
|
-
$lt: T["properties"][K_2]
|
|
118
|
-
$lte: T["properties"][K_2]
|
|
119
|
-
$ne: T["properties"][K_2]
|
|
120
|
-
$in: import("@sinclair/typebox").TArray<T["properties"][K_2]
|
|
121
|
-
$nin: import("@sinclair/typebox").TArray<T["properties"][K_2]
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
$gt: T["properties"][K_2]
|
|
125
|
-
$gte: T["properties"][K_2]
|
|
126
|
-
$lt: T["properties"][K_2]
|
|
127
|
-
$lte: T["properties"][K_2]
|
|
128
|
-
$ne: T["properties"][K_2]
|
|
129
|
-
$in: import("@sinclair/typebox").TArray<T["properties"][K_2]
|
|
130
|
-
$nin: import("@sinclair/typebox").TArray<T["properties"][K_2]
|
|
131
|
-
}
|
|
105
|
+
}; } : never>(type: T, extensions?: X, options?: ObjectOptions) => import("@sinclair/typebox").TComposite<[TObject<{
|
|
106
|
+
$limit: TOptional<import("@sinclair/typebox").TNumber>;
|
|
107
|
+
$skip: TOptional<import("@sinclair/typebox").TNumber>;
|
|
108
|
+
$sort: TOptional<TObject<T["properties"] extends infer T_2 ? { [K_1 in keyof T_2]: TOptional<TInteger>; } : never>>;
|
|
109
|
+
$select: TOptional<import("@sinclair/typebox").TUnsafe<(keyof T["properties"])[]>>;
|
|
110
|
+
$and: TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<[TOptional<TObject<T["properties"] extends infer T_3 ? { [K_2 in keyof T_3]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_2], import("@sinclair/typebox").TComposite<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
|
|
111
|
+
$gt: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
112
|
+
$gte: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
113
|
+
$lt: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
114
|
+
$lte: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
115
|
+
$ne: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
116
|
+
$in: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_2]>>;
|
|
117
|
+
$nin: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_2]>>;
|
|
118
|
+
}, import("@sinclair/typebox").TProperties>>>, TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<X[K_2] extends infer T_4 extends import("@sinclair/typebox").TProperties ? { [K_3 in keyof T_4]: X[K_2][K_3] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : X[K_2][K_3] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : X[K_2][K_3] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<X[K_2][K_3]>; } : never, import("@sinclair/typebox").TProperties>>>]>]>>; } : never>>, TObject<{
|
|
119
|
+
$or: import("@sinclair/typebox").TArray<TOptional<TObject<T["properties"] extends infer T_5 ? { [K_2 in keyof T_5]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_2], import("@sinclair/typebox").TComposite<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
|
|
120
|
+
$gt: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
121
|
+
$gte: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
122
|
+
$lt: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
123
|
+
$lte: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
124
|
+
$ne: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
125
|
+
$in: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_2]>>;
|
|
126
|
+
$nin: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_2]>>;
|
|
127
|
+
}, import("@sinclair/typebox").TProperties>>>, TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<X[K_2] extends infer T_6 extends import("@sinclair/typebox").TProperties ? { [K_3 in keyof T_6]: X[K_2][K_3] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : X[K_2][K_3] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : X[K_2][K_3] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<X[K_2][K_3]>; } : never, import("@sinclair/typebox").TProperties>>>]>]>>; } : never>>>;
|
|
128
|
+
}>]>>>;
|
|
129
|
+
$or: TOptional<import("@sinclair/typebox").TArray<TOptional<TObject<T["properties"] extends infer T_7 ? { [K_2 in keyof T_7]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_2], import("@sinclair/typebox").TComposite<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
|
|
130
|
+
$gt: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
131
|
+
$gte: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
132
|
+
$lt: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
133
|
+
$lte: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
134
|
+
$ne: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
135
|
+
$in: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_2]>>;
|
|
136
|
+
$nin: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_2]>>;
|
|
137
|
+
}, import("@sinclair/typebox").TProperties>>>, TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<X[K_2] extends infer T_8 extends import("@sinclair/typebox").TProperties ? { [K_3 in keyof T_8]: X[K_2][K_3] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : X[K_2][K_3] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : X[K_2][K_3] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<X[K_2][K_3]>; } : never, import("@sinclair/typebox").TProperties>>>]>]>>; } : never>>>>;
|
|
138
|
+
}>, TOptional<TObject<T["properties"] extends infer T_9 ? { [K_2 in keyof T_9]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_2], import("@sinclair/typebox").TComposite<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
|
|
139
|
+
$gt: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
140
|
+
$gte: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
141
|
+
$lt: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
142
|
+
$lte: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
143
|
+
$ne: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
|
|
144
|
+
$in: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_2]>>;
|
|
145
|
+
$nin: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_2]>>;
|
|
146
|
+
}, import("@sinclair/typebox").TProperties>>>, TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<X[K_2] extends infer T_10 extends import("@sinclair/typebox").TProperties ? { [K_3 in keyof T_10]: X[K_2][K_3] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : X[K_2][K_3] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : X[K_2][K_3] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<X[K_2][K_3]>; } : never, import("@sinclair/typebox").TProperties>>>]>]>>; } : never>>]>;
|
|
132
147
|
export declare const ObjectIdSchema: () => import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString<string>, TObject<{}>]>;
|
package/lib/index.js
CHANGED
|
@@ -14,11 +14,52 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.ObjectIdSchema = exports.querySyntax = exports.queryProperties = exports.queryProperty = exports.sortDefinition = exports.StringEnum = exports.getDataValidator = exports.getValidator = void 0;
|
|
17
|
+
exports.ObjectIdSchema = exports.querySyntax = exports.queryProperties = exports.queryProperty = exports.sortDefinition = exports.StringEnum = exports.getDataValidator = exports.getValidator = exports.Type = exports.FeathersTypeBuilder = void 0;
|
|
18
18
|
const typebox_1 = require("@sinclair/typebox");
|
|
19
19
|
const schema_1 = require("@feathersjs/schema");
|
|
20
20
|
__exportStar(require("@sinclair/typebox"), exports);
|
|
21
21
|
__exportStar(require("./default-schemas"), exports);
|
|
22
|
+
/**
|
|
23
|
+
* Feathers TypeBox customisations. Implements the 0.25.0 fallback for Intersect types.
|
|
24
|
+
* @see https://github.com/sinclairzx81/typebox/issues/373
|
|
25
|
+
*/
|
|
26
|
+
class FeathersTypeBuilder extends typebox_1.ExtendedTypeBuilder {
|
|
27
|
+
Intersect(allOf, options = {}) {
|
|
28
|
+
const [required, optional] = [new Set(), new Set()];
|
|
29
|
+
for (const object of allOf) {
|
|
30
|
+
for (const [key, property] of Object.entries(object.properties)) {
|
|
31
|
+
if (typebox_1.TypeGuard.TOptional(property) || typebox_1.TypeGuard.TReadonlyOptional(property))
|
|
32
|
+
optional.add(key);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
for (const object of allOf) {
|
|
36
|
+
for (const key of Object.keys(object.properties)) {
|
|
37
|
+
if (!optional.has(key))
|
|
38
|
+
required.add(key);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const properties = {};
|
|
42
|
+
for (const object of allOf) {
|
|
43
|
+
for (const [key, schema] of Object.entries(object.properties)) {
|
|
44
|
+
properties[key] =
|
|
45
|
+
properties[key] === undefined
|
|
46
|
+
? schema
|
|
47
|
+
: { [typebox_1.Kind]: 'Union', anyOf: [properties[key], { ...schema }] };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (required.size > 0) {
|
|
51
|
+
return { ...options, [typebox_1.Kind]: 'Object', type: 'object', properties, required: [...required] };
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return { ...options, [typebox_1.Kind]: 'Object', type: 'object', properties };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.FeathersTypeBuilder = FeathersTypeBuilder;
|
|
59
|
+
/**
|
|
60
|
+
* Exports our own type builder
|
|
61
|
+
*/
|
|
62
|
+
exports.Type = new FeathersTypeBuilder();
|
|
22
63
|
/**
|
|
23
64
|
* Returns a compiled validation function for a TypeBox object and AJV validator instance.
|
|
24
65
|
*
|
|
@@ -46,12 +87,12 @@ exports.getDataValidator = getDataValidator;
|
|
|
46
87
|
* @returns TypeBox.Type
|
|
47
88
|
*/
|
|
48
89
|
function StringEnum(allowedValues) {
|
|
49
|
-
return
|
|
90
|
+
return exports.Type.Unsafe({ type: 'string', enum: allowedValues });
|
|
50
91
|
}
|
|
51
92
|
exports.StringEnum = StringEnum;
|
|
52
93
|
const arrayOfKeys = (type) => {
|
|
53
94
|
const keys = Object.keys(type.properties);
|
|
54
|
-
return
|
|
95
|
+
return exports.Type.Unsafe({
|
|
55
96
|
type: 'array',
|
|
56
97
|
maxItems: keys.length,
|
|
57
98
|
items: {
|
|
@@ -69,10 +110,10 @@ const arrayOfKeys = (type) => {
|
|
|
69
110
|
function sortDefinition(schema) {
|
|
70
111
|
const properties = Object.keys(schema.properties).reduce((res, key) => {
|
|
71
112
|
const result = res;
|
|
72
|
-
result[key] =
|
|
113
|
+
result[key] = exports.Type.Optional(exports.Type.Integer({ minimum: -1, maximum: 1 }));
|
|
73
114
|
return result;
|
|
74
115
|
}, {});
|
|
75
|
-
return
|
|
116
|
+
return exports.Type.Object(properties, { additionalProperties: false });
|
|
76
117
|
}
|
|
77
118
|
exports.sortDefinition = sortDefinition;
|
|
78
119
|
/**
|
|
@@ -83,19 +124,19 @@ exports.sortDefinition = sortDefinition;
|
|
|
83
124
|
* @param extension Additional properties to add to the property query
|
|
84
125
|
* @returns The Feathers query syntax schema
|
|
85
126
|
*/
|
|
86
|
-
const queryProperty = (def, extension = {}) =>
|
|
127
|
+
const queryProperty = (def, extension = {}) => exports.Type.Optional(exports.Type.Union([
|
|
87
128
|
def,
|
|
88
|
-
|
|
89
|
-
|
|
129
|
+
exports.Type.Partial(exports.Type.Composite([
|
|
130
|
+
exports.Type.Object({
|
|
90
131
|
$gt: def,
|
|
91
132
|
$gte: def,
|
|
92
133
|
$lt: def,
|
|
93
134
|
$lte: def,
|
|
94
135
|
$ne: def,
|
|
95
|
-
$in:
|
|
96
|
-
$nin:
|
|
136
|
+
$in: exports.Type.Array(def),
|
|
137
|
+
$nin: exports.Type.Array(def)
|
|
97
138
|
}),
|
|
98
|
-
|
|
139
|
+
exports.Type.Object(extension)
|
|
99
140
|
], { additionalProperties: false }))
|
|
100
141
|
]));
|
|
101
142
|
exports.queryProperty = queryProperty;
|
|
@@ -113,7 +154,7 @@ const queryProperties = (definition, extensions = {}) => {
|
|
|
113
154
|
result[key] = (0, exports.queryProperty)(value, extensions[key]);
|
|
114
155
|
return result;
|
|
115
156
|
}, {});
|
|
116
|
-
return
|
|
157
|
+
return exports.Type.Optional(exports.Type.Object(properties, { additionalProperties: false }));
|
|
117
158
|
};
|
|
118
159
|
exports.queryProperties = queryProperties;
|
|
119
160
|
/**
|
|
@@ -127,12 +168,12 @@ exports.queryProperties = queryProperties;
|
|
|
127
168
|
*/
|
|
128
169
|
const querySyntax = (type, extensions = {}, options = { additionalProperties: false }) => {
|
|
129
170
|
const propertySchema = (0, exports.queryProperties)(type, extensions);
|
|
130
|
-
const $or =
|
|
131
|
-
const $and =
|
|
132
|
-
return
|
|
133
|
-
|
|
134
|
-
$limit:
|
|
135
|
-
$skip:
|
|
171
|
+
const $or = exports.Type.Array(propertySchema);
|
|
172
|
+
const $and = exports.Type.Array(exports.Type.Union([propertySchema, exports.Type.Object({ $or })]));
|
|
173
|
+
return exports.Type.Composite([
|
|
174
|
+
exports.Type.Partial(exports.Type.Object({
|
|
175
|
+
$limit: exports.Type.Number({ minimum: 0 }),
|
|
176
|
+
$skip: exports.Type.Number({ minimum: 0 }),
|
|
136
177
|
$sort: sortDefinition(type),
|
|
137
178
|
$select: arrayOfKeys(type),
|
|
138
179
|
$and,
|
|
@@ -142,6 +183,6 @@ const querySyntax = (type, extensions = {}, options = { additionalProperties: fa
|
|
|
142
183
|
], options);
|
|
143
184
|
};
|
|
144
185
|
exports.querySyntax = querySyntax;
|
|
145
|
-
const ObjectIdSchema = () =>
|
|
186
|
+
const ObjectIdSchema = () => exports.Type.Union([exports.Type.String({ objectid: true }), exports.Type.Object({}, { additionalProperties: false })]);
|
|
146
187
|
exports.ObjectIdSchema = ObjectIdSchema;
|
|
147
188
|
//# sourceMappingURL=index.js.map
|
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,+CAa0B;AAC1B,+CAAiF;AAEjF,oDAAiC;AACjC,oDAAiC;AAEjC;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,6BAAmB;IAOnD,SAAS,CAAC,KAAgB,EAAE,UAA4B,EAAE;QAC/D,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,EAAU,EAAE,IAAI,GAAG,EAAU,CAAC,CAAA;QACnE,KAAK,MAAM,MAAM,IAAI,KAAK,EAAE;YAC1B,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;gBAC/D,IAAI,mBAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,mBAAS,CAAC,iBAAiB,CAAC,QAAQ,CAAC;oBAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;aAC9F;SACF;QACD,KAAK,MAAM,MAAM,IAAI,KAAK,EAAE;YAC1B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;gBAChD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;oBAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;aAC1C;SACF;QACD,MAAM,UAAU,GAAG,EAAyB,CAAA;QAC5C,KAAK,MAAM,MAAM,IAAI,KAAK,EAAE;YAC1B,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CA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GAAG,GAAG,YAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;IACtC,MAAM,IAAI,GAAG,YAAI,CAAC,KAAK,CAAC,YAAI,CAAC,KAAK,CAAC,CAAC,cAAc,EAAE,YAAI,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IAE3E,OAAO,YAAI,CAAC,SAAS,CACnB;QACE,YAAI,CAAC,OAAO,CACV,YAAI,CAAC,MAAM,CACT;YACE,MAAM,EAAE,YAAI,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;YACnC,KAAK,EAAE,YAAI,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;YAClC,KAAK,EAAE,cAAc,CAAC,IAAI,CAAC;YAC3B,OAAO,EAAE,WAAW,CAAC,IAAI,CAAC;YAC1B,IAAI;YACJ,GAAG;SACJ,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAChC,CACF;QACD,cAAc;KACf,EACD,OAAO,CACR,CAAA;AACH,CAAC,CAAA;AA/BY,QAAA,WAAW,eA+BvB;AAEM,MAAM,cAAc,GAAG,GAAG,EAAE,CACjC,YAAI,CAAC,KAAK,CAAC,CAAC,YAAI,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,YAAI,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.4",
|
|
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.
|
|
58
|
-
"@sinclair/typebox": "^0.
|
|
57
|
+
"@feathersjs/schema": "^5.0.4",
|
|
58
|
+
"@sinclair/typebox": "^0.26.8"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/mocha": "^10.0.1",
|
|
62
|
-
"@types/node": "^18.
|
|
62
|
+
"@types/node": "^18.15.11",
|
|
63
63
|
"mocha": "^10.2.0",
|
|
64
64
|
"shx": "^0.3.4",
|
|
65
|
-
"typescript": "^
|
|
65
|
+
"typescript": "^5.0.3"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "376e89040991db500f1f327aa699322543315039"
|
|
68
68
|
}
|
package/src/default-schemas.ts
CHANGED
|
@@ -2,7 +2,12 @@ import { Type, Static } from '@sinclair/typebox'
|
|
|
2
2
|
|
|
3
3
|
export const authenticationSettingsSchema = Type.Object({
|
|
4
4
|
secret: Type.String({ description: 'The JWT signing secret' }),
|
|
5
|
-
entity: Type.Optional(
|
|
5
|
+
entity: Type.Optional(
|
|
6
|
+
Type.Union([
|
|
7
|
+
Type.String({ description: 'The name of the authentication entity (e.g. user)' }),
|
|
8
|
+
Type.Null()
|
|
9
|
+
])
|
|
10
|
+
),
|
|
6
11
|
entityId: Type.Optional(Type.String({ description: 'The name of the authentication entity id property' })),
|
|
7
12
|
service: Type.Optional(Type.String({ description: 'The path of the entity service' })),
|
|
8
13
|
authStrategies: Type.Array(Type.String(), {
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,67 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
TObject,
|
|
3
|
+
TInteger,
|
|
4
|
+
TOptional,
|
|
5
|
+
TSchema,
|
|
6
|
+
TIntersect,
|
|
7
|
+
ObjectOptions,
|
|
8
|
+
ExtendedTypeBuilder,
|
|
9
|
+
SchemaOptions,
|
|
10
|
+
TNever,
|
|
11
|
+
IntersectOptions,
|
|
12
|
+
TypeGuard,
|
|
13
|
+
Kind
|
|
14
|
+
} from '@sinclair/typebox'
|
|
2
15
|
import { jsonSchema, Validator, DataValidatorMap, Ajv } from '@feathersjs/schema'
|
|
3
16
|
|
|
4
17
|
export * from '@sinclair/typebox'
|
|
5
18
|
export * from './default-schemas'
|
|
6
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Feathers TypeBox customisations. Implements the 0.25.0 fallback for Intersect types.
|
|
22
|
+
* @see https://github.com/sinclairzx81/typebox/issues/373
|
|
23
|
+
*/
|
|
24
|
+
export class FeathersTypeBuilder extends ExtendedTypeBuilder {
|
|
25
|
+
/** `[Standard]` Creates a Intersect type */
|
|
26
|
+
public Intersect(allOf: [], options?: SchemaOptions): TNever
|
|
27
|
+
/** `[Standard]` Creates a Intersect type */
|
|
28
|
+
public Intersect<T extends [TObject]>(allOf: [...T], options?: SchemaOptions): T[0]
|
|
29
|
+
// /** `[Standard]` Creates a Intersect type */
|
|
30
|
+
public Intersect<T extends TObject[]>(allOf: [...T], options?: IntersectOptions): TIntersect<T>
|
|
31
|
+
public Intersect(allOf: TObject[], options: IntersectOptions = {}) {
|
|
32
|
+
const [required, optional] = [new Set<string>(), new Set<string>()]
|
|
33
|
+
for (const object of allOf) {
|
|
34
|
+
for (const [key, property] of Object.entries(object.properties)) {
|
|
35
|
+
if (TypeGuard.TOptional(property) || TypeGuard.TReadonlyOptional(property)) optional.add(key)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
for (const object of allOf) {
|
|
39
|
+
for (const key of Object.keys(object.properties)) {
|
|
40
|
+
if (!optional.has(key)) required.add(key)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const properties = {} as Record<string, any>
|
|
44
|
+
for (const object of allOf) {
|
|
45
|
+
for (const [key, schema] of Object.entries(object.properties)) {
|
|
46
|
+
properties[key] =
|
|
47
|
+
properties[key] === undefined
|
|
48
|
+
? schema
|
|
49
|
+
: { [Kind]: 'Union', anyOf: [properties[key], { ...schema }] }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (required.size > 0) {
|
|
53
|
+
return { ...options, [Kind]: 'Object', type: 'object', properties, required: [...required] } as any
|
|
54
|
+
} else {
|
|
55
|
+
return { ...options, [Kind]: 'Object', type: 'object', properties } as any
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Exports our own type builder
|
|
62
|
+
*/
|
|
63
|
+
export const Type = new FeathersTypeBuilder()
|
|
64
|
+
|
|
7
65
|
export type TDataSchemaMap = {
|
|
8
66
|
create: TObject
|
|
9
67
|
update?: TObject
|
|
@@ -17,7 +75,7 @@ export type TDataSchemaMap = {
|
|
|
17
75
|
* @param validator The AJV validation instance
|
|
18
76
|
* @returns A compiled validation function
|
|
19
77
|
*/
|
|
20
|
-
export const getValidator = <T = any, R = T>(schema: TObject, validator: Ajv): Validator<T, R> =>
|
|
78
|
+
export const getValidator = <T = any, R = T>(schema: TObject | TIntersect, validator: Ajv): Validator<T, R> =>
|
|
21
79
|
jsonSchema.getValidator(schema as any, validator)
|
|
22
80
|
|
|
23
81
|
/**
|
|
@@ -42,7 +100,7 @@ export function StringEnum<T extends string[]>(allowedValues: [...T]) {
|
|
|
42
100
|
return Type.Unsafe<T[number]>({ type: 'string', enum: allowedValues })
|
|
43
101
|
}
|
|
44
102
|
|
|
45
|
-
const arrayOfKeys = <T extends TObject>(type: T) => {
|
|
103
|
+
const arrayOfKeys = <T extends TObject | TIntersect>(type: T) => {
|
|
46
104
|
const keys = Object.keys(type.properties)
|
|
47
105
|
return Type.Unsafe<(keyof T['properties'])[]>({
|
|
48
106
|
type: 'array',
|
|
@@ -60,7 +118,7 @@ const arrayOfKeys = <T extends TObject>(type: T) => {
|
|
|
60
118
|
* @param schema The TypeBox object schema
|
|
61
119
|
* @returns The `$sort` syntax schema
|
|
62
120
|
*/
|
|
63
|
-
export function sortDefinition<T extends TObject>(schema: T) {
|
|
121
|
+
export function sortDefinition<T extends TObject | TIntersect>(schema: T) {
|
|
64
122
|
const properties = Object.keys(schema.properties).reduce((res, key) => {
|
|
65
123
|
const result = res as any
|
|
66
124
|
|
|
@@ -88,7 +146,7 @@ export const queryProperty = <T extends TSchema, X extends { [key: string]: TSch
|
|
|
88
146
|
Type.Union([
|
|
89
147
|
def,
|
|
90
148
|
Type.Partial(
|
|
91
|
-
Type.
|
|
149
|
+
Type.Composite(
|
|
92
150
|
[
|
|
93
151
|
Type.Object({
|
|
94
152
|
$gt: def,
|
|
@@ -119,7 +177,7 @@ type QueryProperty<T extends TSchema, X extends { [key: string]: TSchema }> = Re
|
|
|
119
177
|
* @returns The Feathers query syntax schema
|
|
120
178
|
*/
|
|
121
179
|
export const queryProperties = <
|
|
122
|
-
T extends TObject,
|
|
180
|
+
T extends TObject | TIntersect,
|
|
123
181
|
X extends { [K in keyof T['properties']]?: { [key: string]: TSchema } }
|
|
124
182
|
>(
|
|
125
183
|
definition: T,
|
|
@@ -158,7 +216,7 @@ export const querySyntax = <
|
|
|
158
216
|
const $or = Type.Array(propertySchema)
|
|
159
217
|
const $and = Type.Array(Type.Union([propertySchema, Type.Object({ $or })]))
|
|
160
218
|
|
|
161
|
-
return Type.
|
|
219
|
+
return Type.Composite(
|
|
162
220
|
[
|
|
163
221
|
Type.Partial(
|
|
164
222
|
Type.Object(
|