@feathersjs/typebox 5.0.0-pre.34 → 5.0.0-pre.35
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 +7 -0
- package/lib/index.d.ts +49 -40
- package/lib/index.js +12 -8
- package/lib/index.js.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +30 -15
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
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.0-pre.35](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.34...v5.0.0-pre.35) (2023-01-12)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **generators:** Move core code generators to shared generators package ([#2982](https://github.com/feathersjs/feathers/issues/2982)) ([0328d22](https://github.com/feathersjs/feathers/commit/0328d2292153870bc43958f73d2c6f288a8cec17))
|
|
11
|
+
- **schema:** Allow to add additional operators to the query syntax ([#2941](https://github.com/feathersjs/feathers/issues/2941)) ([f324940](https://github.com/feathersjs/feathers/commit/f324940d5795b41e8c6fc113defb0beb7ab03a0a))
|
|
12
|
+
|
|
6
13
|
# [5.0.0-pre.34](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.33...v5.0.0-pre.34) (2022-12-14)
|
|
7
14
|
|
|
8
15
|
### Bug Fixes
|
package/lib/index.d.ts
CHANGED
|
@@ -44,9 +44,12 @@ export declare function sortDefinition<T extends TObject>(schema: T): TObject<T[
|
|
|
44
44
|
* including operators like `$gt`, `$lt` etc. for a single property
|
|
45
45
|
*
|
|
46
46
|
* @param def The property definition
|
|
47
|
+
* @param extension Additional properties to add to the property query
|
|
47
48
|
* @returns The Feathers query syntax schema
|
|
48
49
|
*/
|
|
49
|
-
export declare const queryProperty: <T extends TSchema
|
|
50
|
+
export declare const queryProperty: <T extends TSchema, X extends {
|
|
51
|
+
[key: string]: TSchema;
|
|
52
|
+
}>(def: T, extension?: X) => TOptional<import("@sinclair/typebox").TUnion<[T, import("@sinclair/typebox").TPartial<TObject<{
|
|
50
53
|
$gt: T;
|
|
51
54
|
$gte: T;
|
|
52
55
|
$lt: T;
|
|
@@ -54,59 +57,65 @@ export declare const queryProperty: <T extends TSchema>(def: T) => TOptional<imp
|
|
|
54
57
|
$ne: T;
|
|
55
58
|
$in: import("@sinclair/typebox").TArray<T>;
|
|
56
59
|
$nin: import("@sinclair/typebox").TArray<T>;
|
|
57
|
-
}>>]>>;
|
|
60
|
+
} & X>>]>>;
|
|
58
61
|
/**
|
|
59
62
|
* Creates a Feathers query syntax schema for the properties defined in `definition`.
|
|
60
63
|
*
|
|
61
64
|
* @param definition The properties to create the Feathers query syntax schema for
|
|
65
|
+
* @param extensions Additional properties to add to a property query
|
|
62
66
|
* @returns The Feathers query syntax schema
|
|
63
67
|
*/
|
|
64
|
-
export declare const queryProperties: <T extends TObject<import("@sinclair/typebox").TProperties
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
$
|
|
68
|
-
$
|
|
69
|
-
$
|
|
70
|
-
$
|
|
71
|
-
$
|
|
72
|
-
|
|
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]?: {
|
|
69
|
+
[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").TPartial<TObject<{
|
|
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
|
+
} & X[K_1]>>]>>; } : never>>;
|
|
73
79
|
/**
|
|
74
80
|
* Creates a TypeBox schema for the complete Feathers query syntax including `$limit`, $skip`, `$or`
|
|
75
81
|
* and `$sort` and `$select` for the allowed properties.
|
|
76
82
|
*
|
|
77
83
|
* @param type The properties to create the query syntax for
|
|
84
|
+
* @param extensions Additional properties to add to the query syntax
|
|
78
85
|
* @param options Options for the TypeBox object schema
|
|
79
86
|
* @returns A TypeBox object representing the complete Feathers query syntax for the given properties
|
|
80
87
|
*/
|
|
81
|
-
export declare const querySyntax: <T extends TObject<import("@sinclair/typebox").TProperties> | TIntersect<TObject<import("@sinclair/typebox").TProperties>[]
|
|
88
|
+
export declare const querySyntax: <T extends TObject<import("@sinclair/typebox").TProperties> | TIntersect<TObject<import("@sinclair/typebox").TProperties>[]>, X extends T["properties"] extends infer T_1 ? { [K in keyof T_1]?: {
|
|
89
|
+
[key: string]: TSchema;
|
|
90
|
+
}; } : never>(type: T, extensions?: X, options?: ObjectOptions) => TIntersect<[import("@sinclair/typebox").TPartial<TObject<{
|
|
82
91
|
$limit: import("@sinclair/typebox").TNumber;
|
|
83
92
|
$skip: import("@sinclair/typebox").TNumber;
|
|
84
|
-
$sort: TObject<T["properties"] extends infer
|
|
93
|
+
$sort: TObject<T["properties"] extends infer T_2 ? { [K_1 in keyof T_2]: TOptional<TInteger>; } : never>;
|
|
85
94
|
$select: import("@sinclair/typebox").TUnsafe<(keyof T["properties"])[]>;
|
|
86
|
-
$or: import("@sinclair/typebox").TArray<TOptional<TObject<T["properties"] extends infer
|
|
87
|
-
$gt: T["properties"][
|
|
88
|
-
$gte: T["properties"][
|
|
89
|
-
$lt: T["properties"][
|
|
90
|
-
$lte: T["properties"][
|
|
91
|
-
$ne: T["properties"][
|
|
92
|
-
$in: import("@sinclair/typebox").TArray<T["properties"][
|
|
93
|
-
$nin: import("@sinclair/typebox").TArray<T["properties"][
|
|
94
|
-
}>>]>>; } : never>>>;
|
|
95
|
-
$and: import("@sinclair/typebox").TArray<TOptional<TObject<T["properties"] extends infer
|
|
96
|
-
$gt: T["properties"][
|
|
97
|
-
$gte: T["properties"][
|
|
98
|
-
$lt: T["properties"][
|
|
99
|
-
$lte: T["properties"][
|
|
100
|
-
$ne: T["properties"][
|
|
101
|
-
$in: import("@sinclair/typebox").TArray<T["properties"][
|
|
102
|
-
$nin: import("@sinclair/typebox").TArray<T["properties"][
|
|
103
|
-
}>>]>>; } : never>>>;
|
|
104
|
-
}>>, TOptional<TObject<T["properties"] extends infer
|
|
105
|
-
$gt: T["properties"][
|
|
106
|
-
$gte: T["properties"][
|
|
107
|
-
$lt: T["properties"][
|
|
108
|
-
$lte: T["properties"][
|
|
109
|
-
$ne: T["properties"][
|
|
110
|
-
$in: import("@sinclair/typebox").TArray<T["properties"][
|
|
111
|
-
$nin: import("@sinclair/typebox").TArray<T["properties"][
|
|
112
|
-
}>>]>>; } : never>>]>;
|
|
95
|
+
$or: import("@sinclair/typebox").TArray<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").TPartial<TObject<{
|
|
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
|
+
} & X[K_2]>>]>>; } : never>>>;
|
|
104
|
+
$and: import("@sinclair/typebox").TArray<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").TPartial<TObject<{
|
|
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
|
+
} & X[K_2]>>]>>; } : never>>>;
|
|
113
|
+
}>>, TOptional<TObject<T["properties"] extends infer T_4 ? { [K_2 in keyof T_4]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_2], import("@sinclair/typebox").TPartial<TObject<{
|
|
114
|
+
$gt: T["properties"][K_2];
|
|
115
|
+
$gte: T["properties"][K_2];
|
|
116
|
+
$lt: T["properties"][K_2];
|
|
117
|
+
$lte: T["properties"][K_2];
|
|
118
|
+
$ne: T["properties"][K_2];
|
|
119
|
+
$in: import("@sinclair/typebox").TArray<T["properties"][K_2]>;
|
|
120
|
+
$nin: import("@sinclair/typebox").TArray<T["properties"][K_2]>;
|
|
121
|
+
} & X[K_2]>>]>>; } : never>>]>;
|
package/lib/index.js
CHANGED
|
@@ -80,9 +80,10 @@ exports.sortDefinition = sortDefinition;
|
|
|
80
80
|
* including operators like `$gt`, `$lt` etc. for a single property
|
|
81
81
|
*
|
|
82
82
|
* @param def The property definition
|
|
83
|
+
* @param extension Additional properties to add to the property query
|
|
83
84
|
* @returns The Feathers query syntax schema
|
|
84
85
|
*/
|
|
85
|
-
const queryProperty = (def) => typebox_1.Type.Optional(typebox_1.Type.Union([
|
|
86
|
+
const queryProperty = (def, extension = {}) => typebox_1.Type.Optional(typebox_1.Type.Union([
|
|
86
87
|
def,
|
|
87
88
|
typebox_1.Type.Partial(typebox_1.Type.Object({
|
|
88
89
|
$gt: def,
|
|
@@ -91,7 +92,8 @@ const queryProperty = (def) => typebox_1.Type.Optional(typebox_1.Type.Union([
|
|
|
91
92
|
$lte: def,
|
|
92
93
|
$ne: def,
|
|
93
94
|
$in: typebox_1.Type.Array(def),
|
|
94
|
-
$nin: typebox_1.Type.Array(def)
|
|
95
|
+
$nin: typebox_1.Type.Array(def),
|
|
96
|
+
...extension
|
|
95
97
|
}), { additionalProperties: false })
|
|
96
98
|
]));
|
|
97
99
|
exports.queryProperty = queryProperty;
|
|
@@ -99,16 +101,17 @@ exports.queryProperty = queryProperty;
|
|
|
99
101
|
* Creates a Feathers query syntax schema for the properties defined in `definition`.
|
|
100
102
|
*
|
|
101
103
|
* @param definition The properties to create the Feathers query syntax schema for
|
|
104
|
+
* @param extensions Additional properties to add to a property query
|
|
102
105
|
* @returns The Feathers query syntax schema
|
|
103
106
|
*/
|
|
104
|
-
const queryProperties = (definition) => {
|
|
107
|
+
const queryProperties = (definition, extensions = {}) => {
|
|
105
108
|
const properties = Object.keys(definition.properties).reduce((res, key) => {
|
|
106
109
|
const result = res;
|
|
107
110
|
const value = definition.properties[key];
|
|
108
|
-
if (value.$ref
|
|
109
|
-
throw new Error(`Can not create query syntax schema for property '${key}'
|
|
111
|
+
if (value.$ref) {
|
|
112
|
+
throw new Error(`Can not create query syntax schema for reference property '${key}'`);
|
|
110
113
|
}
|
|
111
|
-
result[key] = (0, exports.queryProperty)(value);
|
|
114
|
+
result[key] = (0, exports.queryProperty)(value, extensions[key]);
|
|
112
115
|
return result;
|
|
113
116
|
}, {});
|
|
114
117
|
return typebox_1.Type.Optional(typebox_1.Type.Object(properties, { additionalProperties: false }));
|
|
@@ -119,11 +122,12 @@ exports.queryProperties = queryProperties;
|
|
|
119
122
|
* and `$sort` and `$select` for the allowed properties.
|
|
120
123
|
*
|
|
121
124
|
* @param type The properties to create the query syntax for
|
|
125
|
+
* @param extensions Additional properties to add to the query syntax
|
|
122
126
|
* @param options Options for the TypeBox object schema
|
|
123
127
|
* @returns A TypeBox object representing the complete Feathers query syntax for the given properties
|
|
124
128
|
*/
|
|
125
|
-
const querySyntax = (type, options = { additionalProperties: false }) => {
|
|
126
|
-
const propertySchema = (0, exports.queryProperties)(type);
|
|
129
|
+
const querySyntax = (type, extensions = {}, options = { additionalProperties: false }) => {
|
|
130
|
+
const propertySchema = (0, exports.queryProperties)(type, extensions);
|
|
127
131
|
return typebox_1.Type.Intersect([
|
|
128
132
|
typebox_1.Type.Partial(typebox_1.Type.Object({
|
|
129
133
|
$limit: typebox_1.Type.Number({ minimum: 0 }),
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAA0G;AAC1G,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAA0G;AAC1G,+CAAiF;AAEjF,oDAAiC;AACjC,oDAAiC;AAQjC;;;;;;GAMG;AACI,MAAM,YAAY,GAAG,CAAiB,MAAe,EAAE,SAAc,EAAmB,EAAE,CAC/F,mBAAU,CAAC,YAAY,CAAC,MAAa,EAAE,SAAS,CAAC,CAAA;AADtC,QAAA,YAAY,gBAC0B;AAEnD;;;;;;;;;GASG;AACI,MAAM,gBAAgB,GAAG,CAAC,GAA6B,EAAE,SAAc,EAAoB,EAAE,CAClG,mBAAU,CAAC,gBAAgB,CAAC,GAAU,EAAE,SAAS,CAAC,CAAA;AADvC,QAAA,gBAAgB,oBACuB;AAEpD;;;;GAIG;AACH,SAAgB,UAAU,CAAqB,aAAqB;IAClE,OAAO,cAAI,CAAC,MAAM,CAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAA;AACxE,CAAC;AAFD,gCAEC;AAED,MAAM,WAAW,GAAG,CAAoB,IAAO,EAAE,EAAE;IACjD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACzC,OAAO,cAAI,CAAC,MAAM,CAA4B;QAC5C,IAAI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,CAAC;YACnC,KAAK,EAAE,cAAI,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;YAClC,KAAK,EAAE,cAAc,CAAC,IAAI,CAAC;YAC3B,OAAO,EAAE,WAAW,CAAC,IAAI,CAAC;YAC1B,GAAG,EAAE,cAAI,CAAC,KAAK,CAAC,cAAc,CAAC;YAC/B,IAAI,EAAE,cAAI,CAAC,KAAK,CAAC,cAAc,CAAC;SACjC,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAChC,CACF;QACD,cAAc;KACf,EACD,OAAO,CACR,CAAA;AACH,CAAC,CAAA;AA7BY,QAAA,WAAW,eA6BvB"}
|
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.0-pre.
|
|
4
|
+
"version": "5.0.0-pre.35",
|
|
5
5
|
"homepage": "https://feathersjs.com",
|
|
6
6
|
"main": "lib/",
|
|
7
7
|
"types": "lib/",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
],
|
|
43
43
|
"scripts": {
|
|
44
44
|
"prepublish": "npm run compile",
|
|
45
|
-
"pack": "npm pack --pack-destination ../
|
|
45
|
+
"pack": "npm pack --pack-destination ../generators/test/build",
|
|
46
46
|
"compile": "shx rm -rf lib/ && tsc && npm run pack",
|
|
47
47
|
"mocha": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts",
|
|
48
48
|
"test": "npm run compile && npm run mocha"
|
|
@@ -54,15 +54,15 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@feathersjs/schema": "^5.0.0-pre.
|
|
58
|
-
"@sinclair/typebox": "^0.25.
|
|
57
|
+
"@feathersjs/schema": "^5.0.0-pre.35",
|
|
58
|
+
"@sinclair/typebox": "^0.25.16"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/mocha": "^10.0.1",
|
|
62
|
-
"@types/node": "^18.11.
|
|
63
|
-
"mocha": "^10.
|
|
62
|
+
"@types/node": "^18.11.18",
|
|
63
|
+
"mocha": "^10.2.0",
|
|
64
64
|
"shx": "^0.3.4",
|
|
65
|
-
"typescript": "^4.9.
|
|
65
|
+
"typescript": "^4.9.4"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "c641598d9a4de3ceda10f56cf2af288a4236b15e"
|
|
68
68
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Type, TObject, TInteger, TOptional, TSchema, TIntersect, ObjectOptions } from '@sinclair/typebox'
|
|
2
|
-
import { jsonSchema, Validator, DataValidatorMap, Ajv
|
|
2
|
+
import { jsonSchema, Validator, DataValidatorMap, Ajv } from '@feathersjs/schema'
|
|
3
3
|
|
|
4
4
|
export * from '@sinclair/typebox'
|
|
5
5
|
export * from './default-schemas'
|
|
@@ -77,9 +77,13 @@ export function sortDefinition<T extends TObject>(schema: T) {
|
|
|
77
77
|
* including operators like `$gt`, `$lt` etc. for a single property
|
|
78
78
|
*
|
|
79
79
|
* @param def The property definition
|
|
80
|
+
* @param extension Additional properties to add to the property query
|
|
80
81
|
* @returns The Feathers query syntax schema
|
|
81
82
|
*/
|
|
82
|
-
export const queryProperty = <T extends TSchema
|
|
83
|
+
export const queryProperty = <T extends TSchema, X extends { [key: string]: TSchema }>(
|
|
84
|
+
def: T,
|
|
85
|
+
extension: X = {} as X
|
|
86
|
+
) =>
|
|
83
87
|
Type.Optional(
|
|
84
88
|
Type.Union([
|
|
85
89
|
def,
|
|
@@ -91,38 +95,44 @@ export const queryProperty = <T extends TSchema>(def: T) =>
|
|
|
91
95
|
$lte: def,
|
|
92
96
|
$ne: def,
|
|
93
97
|
$in: Type.Array(def),
|
|
94
|
-
$nin: Type.Array(def)
|
|
98
|
+
$nin: Type.Array(def),
|
|
99
|
+
...extension
|
|
95
100
|
}),
|
|
96
101
|
{ additionalProperties: false }
|
|
97
102
|
)
|
|
98
103
|
])
|
|
99
104
|
)
|
|
100
105
|
|
|
101
|
-
type QueryProperty<T extends TSchema> = ReturnType<
|
|
106
|
+
type QueryProperty<T extends TSchema, X extends { [key: string]: TSchema }> = ReturnType<
|
|
107
|
+
typeof queryProperty<T, X>
|
|
108
|
+
>
|
|
102
109
|
|
|
103
110
|
/**
|
|
104
111
|
* Creates a Feathers query syntax schema for the properties defined in `definition`.
|
|
105
112
|
*
|
|
106
113
|
* @param definition The properties to create the Feathers query syntax schema for
|
|
114
|
+
* @param extensions Additional properties to add to a property query
|
|
107
115
|
* @returns The Feathers query syntax schema
|
|
108
116
|
*/
|
|
109
|
-
export const queryProperties = <
|
|
117
|
+
export const queryProperties = <
|
|
118
|
+
T extends TObject,
|
|
119
|
+
X extends { [K in keyof T['properties']]?: { [key: string]: TSchema } }
|
|
120
|
+
>(
|
|
121
|
+
definition: T,
|
|
122
|
+
extensions: X = {} as X
|
|
123
|
+
) => {
|
|
110
124
|
const properties = Object.keys(definition.properties).reduce((res, key) => {
|
|
111
125
|
const result = res as any
|
|
112
126
|
const value = definition.properties[key]
|
|
113
127
|
|
|
114
|
-
if (value.$ref
|
|
115
|
-
throw new Error(
|
|
116
|
-
`Can not create query syntax schema for property '${key}'. Only types ${SUPPORTED_TYPES.join(
|
|
117
|
-
', '
|
|
118
|
-
)} are allowed.`
|
|
119
|
-
)
|
|
128
|
+
if (value.$ref) {
|
|
129
|
+
throw new Error(`Can not create query syntax schema for reference property '${key}'`)
|
|
120
130
|
}
|
|
121
131
|
|
|
122
|
-
result[key] = queryProperty(value)
|
|
132
|
+
result[key] = queryProperty(value, extensions[key])
|
|
123
133
|
|
|
124
134
|
return result
|
|
125
|
-
}, {} as { [K in keyof T['properties']]: QueryProperty<T['properties'][K]> })
|
|
135
|
+
}, {} as { [K in keyof T['properties']]: QueryProperty<T['properties'][K], X[K]> })
|
|
126
136
|
|
|
127
137
|
return Type.Optional(Type.Object(properties, { additionalProperties: false }))
|
|
128
138
|
}
|
|
@@ -132,14 +142,19 @@ export const queryProperties = <T extends TObject>(definition: T) => {
|
|
|
132
142
|
* and `$sort` and `$select` for the allowed properties.
|
|
133
143
|
*
|
|
134
144
|
* @param type The properties to create the query syntax for
|
|
145
|
+
* @param extensions Additional properties to add to the query syntax
|
|
135
146
|
* @param options Options for the TypeBox object schema
|
|
136
147
|
* @returns A TypeBox object representing the complete Feathers query syntax for the given properties
|
|
137
148
|
*/
|
|
138
|
-
export const querySyntax = <
|
|
149
|
+
export const querySyntax = <
|
|
150
|
+
T extends TObject | TIntersect,
|
|
151
|
+
X extends { [K in keyof T['properties']]?: { [key: string]: TSchema } }
|
|
152
|
+
>(
|
|
139
153
|
type: T,
|
|
154
|
+
extensions: X = {} as X,
|
|
140
155
|
options: ObjectOptions = { additionalProperties: false }
|
|
141
156
|
) => {
|
|
142
|
-
const propertySchema = queryProperties(type)
|
|
157
|
+
const propertySchema = queryProperties(type, extensions)
|
|
143
158
|
|
|
144
159
|
return Type.Intersect(
|
|
145
160
|
[
|