@feathersjs/schema 5.0.0-pre.29 → 5.0.0-pre.31
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 +43 -127
- package/lib/default-schemas.d.ts +505 -0
- package/lib/default-schemas.js +149 -0
- package/lib/default-schemas.js.map +1 -0
- package/lib/hooks/resolve.d.ts +1 -0
- package/lib/hooks/resolve.js +2 -1
- package/lib/hooks/resolve.js.map +1 -1
- package/lib/hooks/validate.d.ts +4 -3
- package/lib/hooks/validate.js +40 -30
- package/lib/hooks/validate.js.map +1 -1
- package/lib/index.d.ts +6 -1
- package/lib/index.js +22 -1
- package/lib/index.js.map +1 -1
- package/lib/json-schema.d.ts +124 -0
- package/lib/json-schema.js +127 -0
- package/lib/json-schema.js.map +1 -0
- package/lib/resolver.d.ts +25 -0
- package/lib/resolver.js +15 -0
- package/lib/resolver.js.map +1 -1
- package/lib/schema.d.ts +6 -1
- package/lib/schema.js.map +1 -1
- package/package.json +11 -11
- package/src/default-schemas.ts +157 -0
- package/src/hooks/resolve.ts +2 -0
- package/src/hooks/validate.ts +25 -16
- package/src/index.ts +8 -1
- package/src/json-schema.ts +179 -0
- package/src/resolver.ts +25 -0
- package/src/schema.ts +7 -1
- package/lib/query.d.ts +0 -75
- package/lib/query.js +0 -69
- package/lib/query.js.map +0 -1
- package/src/query.ts +0 -97
package/src/query.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { _ } from '@feathersjs/commons'
|
|
2
|
-
import { JSONSchema } from 'json-schema-to-ts'
|
|
3
|
-
|
|
4
|
-
export type PropertyQuery<D extends JSONSchema> = {
|
|
5
|
-
anyOf: [
|
|
6
|
-
D,
|
|
7
|
-
{
|
|
8
|
-
type: 'object'
|
|
9
|
-
additionalProperties: false
|
|
10
|
-
properties: {
|
|
11
|
-
$gt: D
|
|
12
|
-
$gte: D
|
|
13
|
-
$lt: D
|
|
14
|
-
$lte: D
|
|
15
|
-
$ne: D
|
|
16
|
-
$in: {
|
|
17
|
-
type: 'array'
|
|
18
|
-
items: D
|
|
19
|
-
}
|
|
20
|
-
$nin: {
|
|
21
|
-
type: 'array'
|
|
22
|
-
items: D
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
]
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const queryProperty = <T extends JSONSchema>(def: T) => {
|
|
30
|
-
const definition = _.omit(def, 'default')
|
|
31
|
-
return {
|
|
32
|
-
anyOf: [
|
|
33
|
-
definition,
|
|
34
|
-
{
|
|
35
|
-
type: 'object',
|
|
36
|
-
additionalProperties: false,
|
|
37
|
-
properties: {
|
|
38
|
-
$gt: definition,
|
|
39
|
-
$gte: definition,
|
|
40
|
-
$lt: definition,
|
|
41
|
-
$lte: definition,
|
|
42
|
-
$ne: definition,
|
|
43
|
-
$in: {
|
|
44
|
-
type: 'array',
|
|
45
|
-
items: definition
|
|
46
|
-
},
|
|
47
|
-
$nin: {
|
|
48
|
-
type: 'array',
|
|
49
|
-
items: definition
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
]
|
|
54
|
-
} as const
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export const queryProperties = <T extends { [key: string]: JSONSchema }>(definition: T) =>
|
|
58
|
-
Object.keys(definition).reduce((res, key) => {
|
|
59
|
-
const result = res as any
|
|
60
|
-
|
|
61
|
-
result[key] = queryProperty(definition[key])
|
|
62
|
-
|
|
63
|
-
return result
|
|
64
|
-
}, {} as { [K in keyof T]: PropertyQuery<T[K]> })
|
|
65
|
-
|
|
66
|
-
export const querySyntax = <T extends { [key: string]: any }>(definition: T) =>
|
|
67
|
-
({
|
|
68
|
-
$limit: {
|
|
69
|
-
type: 'number',
|
|
70
|
-
minimum: 0
|
|
71
|
-
},
|
|
72
|
-
$skip: {
|
|
73
|
-
type: 'number',
|
|
74
|
-
minimum: 0
|
|
75
|
-
},
|
|
76
|
-
$sort: {
|
|
77
|
-
type: 'object',
|
|
78
|
-
properties: Object.keys(definition).reduce((res, key) => {
|
|
79
|
-
const result = res as any
|
|
80
|
-
|
|
81
|
-
result[key] = {
|
|
82
|
-
type: 'number',
|
|
83
|
-
enum: [1, -1]
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return result
|
|
87
|
-
}, {} as { [K in keyof T]: { readonly type: 'number'; readonly enum: [1, -1] } })
|
|
88
|
-
},
|
|
89
|
-
$select: {
|
|
90
|
-
type: 'array',
|
|
91
|
-
items: {
|
|
92
|
-
type: 'string',
|
|
93
|
-
enum: Object.keys(definition) as any as (keyof T)[]
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
...queryProperties(definition)
|
|
97
|
-
} as const)
|