@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/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)