@liminalfunctions/framework 1.0.0
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/.mocharc.json +5 -0
- package/dist/F_Client_Collection_Registry.d.ts +18 -0
- package/dist/F_Client_Collection_Registry.js +36 -0
- package/dist/F_Client_Collection_Registry.js.map +1 -0
- package/dist/F_Collection.d.ts +21 -0
- package/dist/F_Collection.js +36 -0
- package/dist/F_Collection.js.map +1 -0
- package/dist/F_Collection_Registry.d.ts +11 -0
- package/dist/F_Collection_Registry.js +18 -0
- package/dist/F_Collection_Registry.js.map +1 -0
- package/dist/F_Compile.d.ts +4 -0
- package/dist/F_Compile.js +298 -0
- package/dist/F_Compile.js.map +1 -0
- package/dist/F_Security_Models/F_SM_Open_Access.d.ts +11 -0
- package/dist/F_Security_Models/F_SM_Open_Access.js +14 -0
- package/dist/F_Security_Models/F_SM_Open_Access.js.map +1 -0
- package/dist/F_Security_Models/F_SM_Ownership.d.ts +12 -0
- package/dist/F_Security_Models/F_SM_Ownership.js +46 -0
- package/dist/F_Security_Models/F_SM_Ownership.js.map +1 -0
- package/dist/F_Security_Models/F_SM_Role_Membership.d.ts +19 -0
- package/dist/F_Security_Models/F_SM_Role_Membership.js +73 -0
- package/dist/F_Security_Models/F_SM_Role_Membership.js.map +1 -0
- package/dist/F_Security_Models/F_Security_Model.d.ts +41 -0
- package/dist/F_Security_Models/F_Security_Model.js +29 -0
- package/dist/F_Security_Models/F_Security_Model.js.map +1 -0
- package/dist/code_generation/generate_client_library.d.ts +4 -0
- package/dist/code_generation/generate_client_library.js +158 -0
- package/dist/code_generation/generate_client_library.js.map +1 -0
- package/dist/code_generation/templates/.gitignore.mustache +383 -0
- package/dist/code_generation/templates/collection.mustache +106 -0
- package/dist/code_generation/templates/main.mustache +24 -0
- package/dist/code_generation/templates/package.json.mustache +18 -0
- package/dist/code_generation/templates/tsconfig.json.mustache +14 -0
- package/dist/code_generation/templates/types.mustache +4 -0
- package/dist/code_generation/templates/utils.ts.mustache +17 -0
- package/dist/code_generation/utils/tab_indent.d.ts +1 -0
- package/dist/code_generation/utils/tab_indent.js +4 -0
- package/dist/code_generation/utils/tab_indent.js.map +1 -0
- package/dist/code_generation/utils/type_from_zod.d.ts +2 -0
- package/dist/code_generation/utils/type_from_zod.js +102 -0
- package/dist/code_generation/utils/type_from_zod.js.map +1 -0
- package/dist/utils/cache.d.ts +13 -0
- package/dist/utils/cache.js +101 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/mongoose_from_zod.d.ts +13 -0
- package/dist/utils/mongoose_from_zod.js +164 -0
- package/dist/utils/mongoose_from_zod.js.map +1 -0
- package/dist/utils/pretty_print_zod.d.ts +2 -0
- package/dist/utils/pretty_print_zod.js +63 -0
- package/dist/utils/pretty_print_zod.js.map +1 -0
- package/dist/utils/query_object_to_mongodb_query.d.ts +3 -0
- package/dist/utils/query_object_to_mongodb_query.js +61 -0
- package/dist/utils/query_object_to_mongodb_query.js.map +1 -0
- package/dist/utils/query_validator_from_zod.d.ts +6 -0
- package/dist/utils/query_validator_from_zod.js +216 -0
- package/dist/utils/query_validator_from_zod.js.map +1 -0
- package/package.json +36 -0
- package/src/F_Collection.ts +50 -0
- package/src/F_Collection_Registry.ts +29 -0
- package/src/F_Compile.ts +368 -0
- package/src/F_Security_Models/F_SM_Open_Access.ts +21 -0
- package/src/F_Security_Models/F_SM_Ownership.ts +72 -0
- package/src/F_Security_Models/F_SM_Role_Membership.ts +87 -0
- package/src/F_Security_Models/F_Security_Model.ts +85 -0
- package/src/code_generation/generate_client_library.ts +197 -0
- package/src/code_generation/templates/.gitignore.mustache +383 -0
- package/src/code_generation/templates/collection.mustache +106 -0
- package/src/code_generation/templates/main.mustache +24 -0
- package/src/code_generation/templates/package.json.mustache +18 -0
- package/src/code_generation/templates/tsconfig.json.mustache +14 -0
- package/src/code_generation/templates/types.mustache +4 -0
- package/src/code_generation/templates/utils.ts.mustache +17 -0
- package/src/code_generation/utils/tab_indent.ts +3 -0
- package/src/code_generation/utils/type_from_zod.ts +140 -0
- package/src/utils/cache.ts +149 -0
- package/src/utils/mongoose_from_zod.ts +191 -0
- package/src/utils/pretty_print_zod.ts +75 -0
- package/src/utils/query_object_to_mongodb_query.ts +73 -0
- package/src/utils/query_validator_from_zod.ts +246 -0
- package/test/0_0_mongoose_from_zod.test.ts +260 -0
- package/test/0_1_query_validator_from_zod.test.ts +518 -0
- package/test/0_2_query_validator_to_mongodb_query.test.ts +365 -0
- package/test/0_3_cache.test.ts +204 -0
- package/test/1_0_basic_server.test.ts +530 -0
- package/test/1_1_security_ownership.test.ts +328 -0
- package/test/1_2_role_membership.test.ts +731 -0
- package/test/2_0_client_library_basic_type_generation.test.ts +444 -0
- package/test/2_0_client_library_query_type_generation.test.ts +352 -0
- package/test/2_1_client_library_generation.test.ts +255 -0
- package/test/tmp/dist/Brief_News_Category.d.ts +16 -0
- package/test/tmp/dist/Brief_News_Category.js +85 -0
- package/test/tmp/dist/Brief_News_Category.js.map +1 -0
- package/test/tmp/dist/Client.d.ts +19 -0
- package/test/tmp/dist/Client.js +97 -0
- package/test/tmp/dist/Client.js.map +1 -0
- package/test/tmp/dist/Institution.d.ts +18 -0
- package/test/tmp/dist/Institution.js +94 -0
- package/test/tmp/dist/Institution.js.map +1 -0
- package/test/tmp/dist/Project.d.ts +16 -0
- package/test/tmp/dist/Project.js +85 -0
- package/test/tmp/dist/Project.js.map +1 -0
- package/test/tmp/dist/index.d.ts +4 -0
- package/test/tmp/dist/index.js +14 -0
- package/test/tmp/dist/index.js.map +1 -0
- package/test/tmp/dist/types/brief_news_category.d.ts +7 -0
- package/test/tmp/dist/types/brief_news_category.js +2 -0
- package/test/tmp/dist/types/brief_news_category.js.map +1 -0
- package/test/tmp/dist/types/brief_news_category_post.d.ts +7 -0
- package/test/tmp/dist/types/brief_news_category_post.js +2 -0
- package/test/tmp/dist/types/brief_news_category_post.js.map +1 -0
- package/test/tmp/dist/types/brief_news_category_put.d.ts +7 -0
- package/test/tmp/dist/types/brief_news_category_put.js +2 -0
- package/test/tmp/dist/types/brief_news_category_put.js.map +1 -0
- package/test/tmp/dist/types/brief_news_category_query.d.ts +26 -0
- package/test/tmp/dist/types/brief_news_category_query.js +2 -0
- package/test/tmp/dist/types/brief_news_category_query.js.map +1 -0
- package/test/tmp/dist/types/client.d.ts +5 -0
- package/test/tmp/dist/types/client.js +2 -0
- package/test/tmp/dist/types/client.js.map +1 -0
- package/test/tmp/dist/types/client_post.d.ts +5 -0
- package/test/tmp/dist/types/client_post.js +2 -0
- package/test/tmp/dist/types/client_post.js.map +1 -0
- package/test/tmp/dist/types/client_put.d.ts +5 -0
- package/test/tmp/dist/types/client_put.js +2 -0
- package/test/tmp/dist/types/client_put.js.map +1 -0
- package/test/tmp/dist/types/client_query.d.ts +18 -0
- package/test/tmp/dist/types/client_query.js +2 -0
- package/test/tmp/dist/types/client_query.js.map +1 -0
- package/test/tmp/dist/types/institution.d.ts +4 -0
- package/test/tmp/dist/types/institution.js +2 -0
- package/test/tmp/dist/types/institution.js.map +1 -0
- package/test/tmp/dist/types/institution_post.d.ts +4 -0
- package/test/tmp/dist/types/institution_post.js +2 -0
- package/test/tmp/dist/types/institution_post.js.map +1 -0
- package/test/tmp/dist/types/institution_put.d.ts +4 -0
- package/test/tmp/dist/types/institution_put.js +2 -0
- package/test/tmp/dist/types/institution_put.js.map +1 -0
- package/test/tmp/dist/types/institution_query.d.ts +14 -0
- package/test/tmp/dist/types/institution_query.js +2 -0
- package/test/tmp/dist/types/institution_query.js.map +1 -0
- package/test/tmp/dist/types/project.d.ts +7 -0
- package/test/tmp/dist/types/project.js +2 -0
- package/test/tmp/dist/types/project.js.map +1 -0
- package/test/tmp/dist/types/project_post.d.ts +7 -0
- package/test/tmp/dist/types/project_post.js +2 -0
- package/test/tmp/dist/types/project_post.js.map +1 -0
- package/test/tmp/dist/types/project_put.d.ts +7 -0
- package/test/tmp/dist/types/project_put.js +2 -0
- package/test/tmp/dist/types/project_put.js.map +1 -0
- package/test/tmp/dist/types/project_query.d.ts +27 -0
- package/test/tmp/dist/types/project_query.js +2 -0
- package/test/tmp/dist/types/project_query.js.map +1 -0
- package/test/tmp/dist/utils/utils.d.ts +11 -0
- package/test/tmp/dist/utils/utils.js +13 -0
- package/test/tmp/dist/utils/utils.js.map +1 -0
- package/test/tmp/package-lock.json +573 -0
- package/test/tmp/package.json +18 -0
- package/test/tmp/src/Brief_News_Category.ts +94 -0
- package/test/tmp/src/Client.ts +106 -0
- package/test/tmp/src/Institution.ts +103 -0
- package/test/tmp/src/Project.ts +94 -0
- package/test/tmp/src/index.ts +20 -0
- package/test/tmp/src/types/brief_news_category.ts +7 -0
- package/test/tmp/src/types/brief_news_category_post.ts +7 -0
- package/test/tmp/src/types/brief_news_category_put.ts +7 -0
- package/test/tmp/src/types/brief_news_category_query.ts +26 -0
- package/test/tmp/src/types/client.ts +5 -0
- package/test/tmp/src/types/client_post.ts +5 -0
- package/test/tmp/src/types/client_put.ts +5 -0
- package/test/tmp/src/types/client_query.ts +18 -0
- package/test/tmp/src/types/institution.ts +4 -0
- package/test/tmp/src/types/institution_post.ts +4 -0
- package/test/tmp/src/types/institution_put.ts +4 -0
- package/test/tmp/src/types/institution_query.ts +14 -0
- package/test/tmp/src/types/project.ts +7 -0
- package/test/tmp/src/types/project_post.ts +7 -0
- package/test/tmp/src/types/project_put.ts +7 -0
- package/test/tmp/src/types/project_query.ts +27 -0
- package/test/tmp/src/utils/utils.ts +17 -0
- package/test/tmp/tsconfig.json +14 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import { boolean, z, ZodBoolean, ZodDate, ZodNumber, ZodString } from 'zod'
|
|
3
|
+
|
|
4
|
+
import { z_mongodb_id } from '../dist/utils/mongoose_from_zod.js';
|
|
5
|
+
import { query_validator_from_zod } from '../dist/utils/query_validator_from_zod.js';
|
|
6
|
+
import { Schema } from 'mongoose'
|
|
7
|
+
|
|
8
|
+
import { Cache } from '../dist/utils/cache.js'
|
|
9
|
+
|
|
10
|
+
describe('query validator from zod', function () {
|
|
11
|
+
it('should be able to turn an empty zod object into an empty validator', async function () {
|
|
12
|
+
let query_validator = query_validator_from_zod(z.object({}))
|
|
13
|
+
assert.deepEqual(
|
|
14
|
+
query_validator.parse({}),
|
|
15
|
+
{}
|
|
16
|
+
)
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should be able to process all the default arguments', async function () {
|
|
20
|
+
let query_validator = query_validator_from_zod(z.object({}))
|
|
21
|
+
assert.deepEqual(
|
|
22
|
+
query_validator.parse({
|
|
23
|
+
limit: 5,
|
|
24
|
+
cursor: '6894cba684185cb03275d511',
|
|
25
|
+
sort_order: 'ascending',
|
|
26
|
+
}),
|
|
27
|
+
{
|
|
28
|
+
limit: 5,
|
|
29
|
+
cursor: '6894cba684185cb03275d511',
|
|
30
|
+
sort_order: 'ascending',
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should throw an error on uncalled-for inputs', async function () {
|
|
36
|
+
let query_validator = query_validator_from_zod(z.object({}))
|
|
37
|
+
assert.throws(() => {
|
|
38
|
+
query_validator.parse({
|
|
39
|
+
bad_input: 'bad input',
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should be able to process a mongodb_id with greater than and less than', async function () {
|
|
45
|
+
let query_validator = query_validator_from_zod(
|
|
46
|
+
z.object({
|
|
47
|
+
parameter: z_mongodb_id
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
assert.deepEqual(
|
|
52
|
+
query_validator.parse({
|
|
53
|
+
parameter: '6894cba684185cb03275d511',
|
|
54
|
+
parameter_gt: '6894cba684185cb03275d511',
|
|
55
|
+
parameter_lt: '6894cba684185cb03275d511',
|
|
56
|
+
}),
|
|
57
|
+
{
|
|
58
|
+
parameter: '6894cba684185cb03275d511',
|
|
59
|
+
parameter_gt: '6894cba684185cb03275d511',
|
|
60
|
+
parameter_lt: '6894cba684185cb03275d511',
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should be able to process a mongodb_id as a member of an array', async function () {
|
|
66
|
+
let query_validator = query_validator_from_zod(
|
|
67
|
+
z.object({
|
|
68
|
+
parameter: z_mongodb_id
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
assert.deepEqual(
|
|
73
|
+
query_validator.parse({
|
|
74
|
+
parameter_in: '6894cba684185cb03275d511,689510e2c345ab6dd1075266,689510e2c345ab6dd1075268',
|
|
75
|
+
}),
|
|
76
|
+
{
|
|
77
|
+
parameter_in: ['6894cba684185cb03275d511', '689510e2c345ab6dd1075266', '689510e2c345ab6dd1075268'],
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
it('should error out if passed an invalid mongodb id', async function () {
|
|
84
|
+
let query_validator = query_validator_from_zod(z.object({}))
|
|
85
|
+
assert.throws(() => {
|
|
86
|
+
query_validator.parse({
|
|
87
|
+
cursor: 'bad id',
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should be able to process a string, string greater than, and string less than', async function () {
|
|
93
|
+
let query_validator = query_validator_from_zod(
|
|
94
|
+
z.object({
|
|
95
|
+
parameter: z.string()
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
assert.deepEqual(
|
|
100
|
+
query_validator.parse({
|
|
101
|
+
parameter: 'fungus',
|
|
102
|
+
parameter_gt: 'fungus',
|
|
103
|
+
parameter_lt: 'fungus',
|
|
104
|
+
}),
|
|
105
|
+
{
|
|
106
|
+
parameter: 'fungus',
|
|
107
|
+
parameter_gt: 'fungus',
|
|
108
|
+
parameter_lt: 'fungus',
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should be able to process a union', async function () {
|
|
114
|
+
let query_validator = query_validator_from_zod(
|
|
115
|
+
z.object({
|
|
116
|
+
parameter: z.string().or(z.number())
|
|
117
|
+
})
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
assert.deepEqual(
|
|
121
|
+
query_validator.parse({
|
|
122
|
+
parameter: 'fungus',
|
|
123
|
+
}),
|
|
124
|
+
{
|
|
125
|
+
parameter: 'fungus',
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
assert.deepEqual(
|
|
130
|
+
query_validator.parse({
|
|
131
|
+
parameter: '5',
|
|
132
|
+
}),
|
|
133
|
+
{
|
|
134
|
+
parameter: 5,
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('should be able to discard a recursive schema', async function () {
|
|
140
|
+
let zod_validator = z.object({
|
|
141
|
+
name: z.string(),
|
|
142
|
+
get recurse() {
|
|
143
|
+
return zod_validator;
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
let query_validator = query_validator_from_zod(zod_validator);
|
|
148
|
+
|
|
149
|
+
assert.deepEqual(
|
|
150
|
+
query_validator.parse({
|
|
151
|
+
name: 'fungus',
|
|
152
|
+
}),
|
|
153
|
+
{
|
|
154
|
+
name: 'fungus',
|
|
155
|
+
}
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
assert.throws(() => {
|
|
159
|
+
assert.deepEqual(
|
|
160
|
+
query_validator.parse({
|
|
161
|
+
'recurse.name': 'fungus',
|
|
162
|
+
}),
|
|
163
|
+
{}
|
|
164
|
+
);
|
|
165
|
+
})
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('should be able to process string membership in an array', async function () {
|
|
169
|
+
let query_validator = query_validator_from_zod(
|
|
170
|
+
z.object({
|
|
171
|
+
parameter: z.string()
|
|
172
|
+
})
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
assert.deepEqual(
|
|
176
|
+
query_validator.parse({
|
|
177
|
+
parameter_in: 'fungus,yeast,mold',
|
|
178
|
+
}),
|
|
179
|
+
{
|
|
180
|
+
parameter_in: ['fungus', 'yeast', 'mold'],
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('should be able to process a boolean', async function () {
|
|
186
|
+
let query_validator = query_validator_from_zod(
|
|
187
|
+
z.object({
|
|
188
|
+
parameter: z.boolean()
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
assert.deepEqual(
|
|
193
|
+
query_validator.parse({
|
|
194
|
+
parameter: 'false',
|
|
195
|
+
}),
|
|
196
|
+
{
|
|
197
|
+
parameter: false,
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('should be able to process a number with greater than, greater than or equal to, less than, less than or equal to', async function () {
|
|
203
|
+
let query_validator = query_validator_from_zod(
|
|
204
|
+
z.object({
|
|
205
|
+
parameter: z.number()
|
|
206
|
+
})
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
assert.deepEqual(
|
|
210
|
+
query_validator.parse({
|
|
211
|
+
parameter: '42',
|
|
212
|
+
parameter_gt: '42',
|
|
213
|
+
parameter_gte: '42',
|
|
214
|
+
parameter_lt: '42',
|
|
215
|
+
parameter_lte: '42',
|
|
216
|
+
}),
|
|
217
|
+
{
|
|
218
|
+
parameter: 42,
|
|
219
|
+
parameter_gt: 42,
|
|
220
|
+
parameter_gte: 42,
|
|
221
|
+
parameter_lt: 42,
|
|
222
|
+
parameter_lte: 42,
|
|
223
|
+
}
|
|
224
|
+
);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('should be able to process a date with greater than and less than', async function () {
|
|
228
|
+
let query_validator = query_validator_from_zod(
|
|
229
|
+
z.object({
|
|
230
|
+
parameter: z.date()
|
|
231
|
+
})
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
let date = new Date().toISOString();
|
|
235
|
+
|
|
236
|
+
assert.deepEqual(
|
|
237
|
+
query_validator.parse({
|
|
238
|
+
parameter: date,
|
|
239
|
+
parameter_gt: date,
|
|
240
|
+
parameter_lt: date,
|
|
241
|
+
}),
|
|
242
|
+
{
|
|
243
|
+
parameter: new Date(date),
|
|
244
|
+
parameter_gt: new Date(date),
|
|
245
|
+
parameter_lt: new Date(date),
|
|
246
|
+
}
|
|
247
|
+
);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it('should be able to process a number in an array', async function () {
|
|
251
|
+
let query_validator = query_validator_from_zod(
|
|
252
|
+
z.object({
|
|
253
|
+
parameter: z.array(z.number())
|
|
254
|
+
})
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
assert.deepEqual(
|
|
258
|
+
query_validator.parse({
|
|
259
|
+
parameter: '42',
|
|
260
|
+
}),
|
|
261
|
+
{
|
|
262
|
+
parameter: 42,
|
|
263
|
+
}
|
|
264
|
+
);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('should be able to process a string in an array', async function () {
|
|
268
|
+
let query_validator = query_validator_from_zod(
|
|
269
|
+
z.object({
|
|
270
|
+
parameter: z.array(z.string())
|
|
271
|
+
})
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
assert.deepEqual(
|
|
275
|
+
query_validator.parse({
|
|
276
|
+
parameter: 'algebra',
|
|
277
|
+
}),
|
|
278
|
+
{
|
|
279
|
+
parameter: 'algebra',
|
|
280
|
+
}
|
|
281
|
+
);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('should be able to process an enum in an array', async function () {
|
|
285
|
+
let query_validator = query_validator_from_zod(
|
|
286
|
+
z.object({
|
|
287
|
+
parameter: z.array(z.enum(['red', 'blue']))
|
|
288
|
+
})
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
assert.deepEqual(
|
|
292
|
+
query_validator.parse({
|
|
293
|
+
parameter: 'red',
|
|
294
|
+
}),
|
|
295
|
+
{
|
|
296
|
+
parameter: 'red',
|
|
297
|
+
}
|
|
298
|
+
);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it('should be able to process a boolean in an array', async function () {
|
|
302
|
+
let query_validator = query_validator_from_zod(
|
|
303
|
+
z.object({
|
|
304
|
+
parameter: z.array(z.boolean())
|
|
305
|
+
})
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
assert.deepEqual(
|
|
309
|
+
query_validator.parse({
|
|
310
|
+
parameter: 'true',
|
|
311
|
+
}),
|
|
312
|
+
{
|
|
313
|
+
parameter: true,
|
|
314
|
+
}
|
|
315
|
+
);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('should be able to process a mongodb in an array', async function () {
|
|
319
|
+
let query_validator = query_validator_from_zod(
|
|
320
|
+
z.object({
|
|
321
|
+
parameter: z.array(z_mongodb_id)
|
|
322
|
+
})
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
assert.deepEqual(
|
|
326
|
+
query_validator.parse({
|
|
327
|
+
parameter: '6894cba684185cb03275d511',
|
|
328
|
+
}),
|
|
329
|
+
{
|
|
330
|
+
parameter: '6894cba684185cb03275d511',
|
|
331
|
+
}
|
|
332
|
+
);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it('should be able to process a nested value', async function () {
|
|
336
|
+
let query_validator = query_validator_from_zod(
|
|
337
|
+
z.object({
|
|
338
|
+
nest: z.object({
|
|
339
|
+
parameter: z.string()
|
|
340
|
+
})
|
|
341
|
+
|
|
342
|
+
})
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
assert.deepEqual(
|
|
346
|
+
query_validator.parse({
|
|
347
|
+
'nest.parameter': 'fungus'
|
|
348
|
+
}),
|
|
349
|
+
{
|
|
350
|
+
'nest.parameter': 'fungus'
|
|
351
|
+
}
|
|
352
|
+
);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it('should be able to process a deeply nested value', async function () {
|
|
356
|
+
let query_validator = query_validator_from_zod(
|
|
357
|
+
z.object({
|
|
358
|
+
nest: z.object({
|
|
359
|
+
egg: z.object({
|
|
360
|
+
parameter: z.string()
|
|
361
|
+
})
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
})
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
assert.deepEqual(
|
|
368
|
+
query_validator.parse({
|
|
369
|
+
'nest.egg.parameter': 'fungus'
|
|
370
|
+
}),
|
|
371
|
+
{
|
|
372
|
+
'nest.egg.parameter': 'fungus'
|
|
373
|
+
}
|
|
374
|
+
);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('should be able to process a deeply nested array value', async function () {
|
|
378
|
+
let query_validator = query_validator_from_zod(
|
|
379
|
+
z.object({
|
|
380
|
+
nest: z.object({
|
|
381
|
+
egg: z.object({
|
|
382
|
+
parameter: z.array(z.string())
|
|
383
|
+
})
|
|
384
|
+
})
|
|
385
|
+
|
|
386
|
+
})
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
assert.deepEqual(
|
|
390
|
+
query_validator.parse({
|
|
391
|
+
'nest.egg.parameter': 'fungus'
|
|
392
|
+
}),
|
|
393
|
+
{
|
|
394
|
+
'nest.egg.parameter': 'fungus'
|
|
395
|
+
}
|
|
396
|
+
);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it('should allow for sorting any sortable field', async function () {
|
|
400
|
+
let query_validator = query_validator_from_zod(
|
|
401
|
+
z.object({
|
|
402
|
+
mongodb_parameter: z_mongodb_id,
|
|
403
|
+
date_parameter: z.date(),
|
|
404
|
+
number_parameter: z.number(),
|
|
405
|
+
boolean_parameter: z.boolean(),
|
|
406
|
+
string_parameter: z.string(),
|
|
407
|
+
})
|
|
408
|
+
);
|
|
409
|
+
|
|
410
|
+
assert.deepEqual(
|
|
411
|
+
query_validator.parse({
|
|
412
|
+
sort: 'mongodb_parameter',
|
|
413
|
+
}),
|
|
414
|
+
{
|
|
415
|
+
sort: 'mongodb_parameter',
|
|
416
|
+
}
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
assert.deepEqual(
|
|
420
|
+
query_validator.parse({
|
|
421
|
+
sort: 'mongodb_parameter',
|
|
422
|
+
}),
|
|
423
|
+
{
|
|
424
|
+
sort: 'mongodb_parameter',
|
|
425
|
+
}
|
|
426
|
+
);
|
|
427
|
+
|
|
428
|
+
assert.deepEqual(
|
|
429
|
+
query_validator.parse({
|
|
430
|
+
sort: 'date_parameter',
|
|
431
|
+
}),
|
|
432
|
+
{
|
|
433
|
+
sort: 'date_parameter',
|
|
434
|
+
}
|
|
435
|
+
);
|
|
436
|
+
|
|
437
|
+
assert.deepEqual(
|
|
438
|
+
query_validator.parse({
|
|
439
|
+
sort: 'boolean_parameter',
|
|
440
|
+
}),
|
|
441
|
+
{
|
|
442
|
+
sort: 'boolean_parameter',
|
|
443
|
+
}
|
|
444
|
+
);
|
|
445
|
+
|
|
446
|
+
assert.deepEqual(
|
|
447
|
+
query_validator.parse({
|
|
448
|
+
sort: 'string_parameter',
|
|
449
|
+
}),
|
|
450
|
+
{
|
|
451
|
+
sort: 'string_parameter',
|
|
452
|
+
}
|
|
453
|
+
);
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
it('should allow for sorting any nested sortable field', async function () {
|
|
457
|
+
let query_validator = query_validator_from_zod(
|
|
458
|
+
z.object({
|
|
459
|
+
nested: z.object({
|
|
460
|
+
mongodb_parameter: z_mongodb_id,
|
|
461
|
+
date_parameter: z.date(),
|
|
462
|
+
number_parameter: z.number(),
|
|
463
|
+
boolean_parameter: z.boolean(),
|
|
464
|
+
string_parameter: z.string(),
|
|
465
|
+
})
|
|
466
|
+
})
|
|
467
|
+
);
|
|
468
|
+
|
|
469
|
+
assert.deepEqual(
|
|
470
|
+
query_validator.parse({
|
|
471
|
+
sort: 'nested.mongodb_parameter',
|
|
472
|
+
}),
|
|
473
|
+
{
|
|
474
|
+
sort: 'nested.mongodb_parameter',
|
|
475
|
+
}
|
|
476
|
+
);
|
|
477
|
+
|
|
478
|
+
assert.deepEqual(
|
|
479
|
+
query_validator.parse({
|
|
480
|
+
sort: 'nested.mongodb_parameter',
|
|
481
|
+
}),
|
|
482
|
+
{
|
|
483
|
+
sort: 'nested.mongodb_parameter',
|
|
484
|
+
}
|
|
485
|
+
);
|
|
486
|
+
|
|
487
|
+
assert.deepEqual(
|
|
488
|
+
query_validator.parse({
|
|
489
|
+
sort: 'nested.date_parameter',
|
|
490
|
+
}),
|
|
491
|
+
{
|
|
492
|
+
sort: 'nested.date_parameter',
|
|
493
|
+
}
|
|
494
|
+
);
|
|
495
|
+
|
|
496
|
+
assert.deepEqual(
|
|
497
|
+
query_validator.parse({
|
|
498
|
+
sort: 'nested.boolean_parameter',
|
|
499
|
+
}),
|
|
500
|
+
{
|
|
501
|
+
sort: 'nested.boolean_parameter',
|
|
502
|
+
}
|
|
503
|
+
);
|
|
504
|
+
|
|
505
|
+
assert.deepEqual(
|
|
506
|
+
query_validator.parse({
|
|
507
|
+
sort: 'nested.string_parameter',
|
|
508
|
+
}),
|
|
509
|
+
{
|
|
510
|
+
sort: 'nested.string_parameter',
|
|
511
|
+
}
|
|
512
|
+
);
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
});
|