@liminalfunctions/framework 1.0.67 → 1.0.69
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/dist/F_Collection.d.ts +2 -0
- package/dist/F_Collection.js +5 -0
- package/dist/F_Collection.js.map +1 -1
- package/dist/F_Compile.js +19 -0
- package/dist/F_Compile.js.map +1 -1
- package/dist/code_generation/templates/utils.ts.mustache +1 -0
- package/dist/utils/complex_query_validator_from_zod.d.ts +20 -0
- package/dist/utils/complex_query_validator_from_zod.js +223 -0
- package/dist/utils/complex_query_validator_from_zod.js.map +1 -0
- package/dist/utils/query_object_to_mongodb_query.d.ts +8 -1
- package/dist/utils/query_object_to_mongodb_query.js +12 -2
- package/dist/utils/query_object_to_mongodb_query.js.map +1 -1
- package/dist/utils/query_validator_from_zod.js +7 -1
- package/dist/utils/query_validator_from_zod.js.map +1 -1
- package/dist/utils/zod_loop_seperator.js +4 -0
- package/dist/utils/zod_loop_seperator.js.map +1 -1
- package/package.json +4 -3
- package/src/F_Collection.ts +5 -0
- package/src/F_Compile.ts +18 -0
- package/src/code_generation/templates/utils.ts.mustache +1 -0
- package/src/utils/complex_query_validator_from_zod.ts +252 -0
- package/src/utils/query_object_to_mongodb_query.ts +11 -3
- package/src/utils/query_validator_from_zod.ts +8 -1
- package/src/utils/zod_loop_seperator.ts +5 -0
- package/test/0_3_query_validator_to_mongodb_query.test.ts +18 -0
- package/test/0_4_query_validator_to_advanced_query.test.ts +402 -0
- package/test/1_0_basic_server.test.ts +30 -0
- package/test/1_4_advanced_queries.test.ts +400 -0
- package/test/2_0_client_library_basic_type_generation.test.ts +2 -2
- package/test/2_0_client_library_query_type_generation.test.ts +12 -0
- package/test/tmp/dist/types/brief_news_category_query.d.ts +3 -0
- package/test/tmp/dist/types/client_query.d.ts +2 -0
- package/test/tmp/dist/types/institution_query.d.ts +2 -0
- package/test/tmp/dist/types/project_query.d.ts +2 -0
- package/test/tmp/dist/utils/utils.js +4 -0
- package/test/tmp/dist/utils/utils.js.map +1 -1
- package/test/tmp/package-lock.json +3 -3
- package/test/tmp/src/types/brief_news_category_query.ts +3 -0
- package/test/tmp/src/types/client_query.ts +2 -0
- package/test/tmp/src/types/institution_query.ts +2 -0
- package/test/tmp/src/types/project_query.ts +2 -0
- package/test/tmp/src/utils/utils.ts +1 -0
- /package/test/{0_4_cache.test.ts → 0_5_cache.test.ts} +0 -0
- /package/test/{0_5_malicious_keys.test.ts → 0_6_malicious_keys.test.ts} +0 -0
- /package/test/{0_6_array_children.test.ts → 0_7_array_children.test.ts} +0 -0
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
import { z_mongodb_id } from '../dist/utils/mongoose_from_zod.js';
|
|
5
|
+
import { complex_query_validator_from_zod } from '../dist/utils/complex_query_validator_from_zod.js';
|
|
6
|
+
|
|
7
|
+
describe('query validator to advanced query', function () {
|
|
8
|
+
|
|
9
|
+
it('advanced queries should fail if they get bad data', async function () {
|
|
10
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
11
|
+
enum: z.enum(['one', 'two']),
|
|
12
|
+
}))
|
|
13
|
+
|
|
14
|
+
assert.throws(() => {
|
|
15
|
+
query_validator.parse({
|
|
16
|
+
test: 'bad'
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('advanced queries should be able to parse ands', async function () {
|
|
22
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
23
|
+
}))
|
|
24
|
+
|
|
25
|
+
query_validator.parse({
|
|
26
|
+
$and:[]
|
|
27
|
+
})
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('advanced queries should be able to parse ors', async function () {
|
|
31
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
32
|
+
}))
|
|
33
|
+
|
|
34
|
+
query_validator.parse({
|
|
35
|
+
$or:[]
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('advanced queries should be able to parse enum $eq', async function () {
|
|
40
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
41
|
+
enum: z.enum(['one', 'two']),
|
|
42
|
+
}))
|
|
43
|
+
|
|
44
|
+
query_validator.parse({
|
|
45
|
+
$and:[{
|
|
46
|
+
enum: {
|
|
47
|
+
$eq: 'one'
|
|
48
|
+
}
|
|
49
|
+
}]
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('advanced queries should be able to parse enum $in', async function () {
|
|
54
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
55
|
+
enum: z.enum(['one', 'two']),
|
|
56
|
+
}))
|
|
57
|
+
|
|
58
|
+
query_validator.parse({
|
|
59
|
+
$and:[{
|
|
60
|
+
enum: {
|
|
61
|
+
$in: ['one', 'two']
|
|
62
|
+
}
|
|
63
|
+
}]
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('advanced queries should be able to parse boolean $eq', async function () {
|
|
68
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
69
|
+
bool: z.boolean(),
|
|
70
|
+
}))
|
|
71
|
+
|
|
72
|
+
query_validator.parse({
|
|
73
|
+
$and:[{
|
|
74
|
+
bool: {
|
|
75
|
+
$eq: true
|
|
76
|
+
}
|
|
77
|
+
}]
|
|
78
|
+
})
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('advanced queries should be able to parse number $eq', async function () {
|
|
82
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
83
|
+
num: z.number(),
|
|
84
|
+
}))
|
|
85
|
+
|
|
86
|
+
query_validator.parse({
|
|
87
|
+
$and:[{
|
|
88
|
+
num: {
|
|
89
|
+
$eq: 5
|
|
90
|
+
}
|
|
91
|
+
}]
|
|
92
|
+
})
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('advanced queries should be able to parse number $lt', async function () {
|
|
96
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
97
|
+
num: z.number(),
|
|
98
|
+
}))
|
|
99
|
+
|
|
100
|
+
query_validator.parse({
|
|
101
|
+
$and:[{
|
|
102
|
+
num: {
|
|
103
|
+
$lt: 5
|
|
104
|
+
}
|
|
105
|
+
}]
|
|
106
|
+
})
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('advanced queries should be able to parse number $gt', async function () {
|
|
110
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
111
|
+
num: z.number(),
|
|
112
|
+
}))
|
|
113
|
+
|
|
114
|
+
query_validator.parse({
|
|
115
|
+
$and:[{
|
|
116
|
+
num: {
|
|
117
|
+
$gt: 5
|
|
118
|
+
}
|
|
119
|
+
}]
|
|
120
|
+
})
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('advanced queries should be able to parse number $lte', async function () {
|
|
124
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
125
|
+
num: z.number(),
|
|
126
|
+
}))
|
|
127
|
+
|
|
128
|
+
query_validator.parse({
|
|
129
|
+
$and:[{
|
|
130
|
+
num: {
|
|
131
|
+
$lte: 5
|
|
132
|
+
}
|
|
133
|
+
}]
|
|
134
|
+
})
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('advanced queries should be able to parse number $gte', async function () {
|
|
138
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
139
|
+
num: z.number(),
|
|
140
|
+
}))
|
|
141
|
+
|
|
142
|
+
query_validator.parse({
|
|
143
|
+
$and:[{
|
|
144
|
+
num: {
|
|
145
|
+
$gte: 5
|
|
146
|
+
}
|
|
147
|
+
}]
|
|
148
|
+
})
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('advanced queries should be able to parse date $eq', async function () {
|
|
152
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
153
|
+
date: z.date(),
|
|
154
|
+
}))
|
|
155
|
+
|
|
156
|
+
query_validator.parse({
|
|
157
|
+
$and:[{
|
|
158
|
+
date: {
|
|
159
|
+
$eq: new Date()
|
|
160
|
+
}
|
|
161
|
+
}]
|
|
162
|
+
})
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('advanced queries should be able to parse date $gt', async function () {
|
|
166
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
167
|
+
date: z.date(),
|
|
168
|
+
}))
|
|
169
|
+
|
|
170
|
+
query_validator.parse({
|
|
171
|
+
$and:[{
|
|
172
|
+
date: {
|
|
173
|
+
$gt: new Date()
|
|
174
|
+
}
|
|
175
|
+
}]
|
|
176
|
+
})
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('advanced queries should be able to parse date $lt', async function () {
|
|
180
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
181
|
+
date: z.date(),
|
|
182
|
+
}))
|
|
183
|
+
|
|
184
|
+
query_validator.parse({
|
|
185
|
+
$and:[{
|
|
186
|
+
date: {
|
|
187
|
+
$lt: new Date()
|
|
188
|
+
}
|
|
189
|
+
}]
|
|
190
|
+
})
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('advanced queries should be able to parse date $gte', async function () {
|
|
194
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
195
|
+
date: z.date(),
|
|
196
|
+
}))
|
|
197
|
+
|
|
198
|
+
query_validator.parse({
|
|
199
|
+
$and:[{
|
|
200
|
+
date: {
|
|
201
|
+
$gte: new Date()
|
|
202
|
+
}
|
|
203
|
+
}]
|
|
204
|
+
})
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('advanced queries should be able to parse date $lte', async function () {
|
|
208
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
209
|
+
date: z.date(),
|
|
210
|
+
}))
|
|
211
|
+
|
|
212
|
+
query_validator.parse({
|
|
213
|
+
$and:[{
|
|
214
|
+
date: {
|
|
215
|
+
$lte: new Date()
|
|
216
|
+
}
|
|
217
|
+
}]
|
|
218
|
+
})
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('advanced queries should be able to parse coerce date $eq', async function () {
|
|
222
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
223
|
+
date: z.coerce.date()
|
|
224
|
+
}))
|
|
225
|
+
|
|
226
|
+
query_validator.parse({
|
|
227
|
+
$and:[{
|
|
228
|
+
date: {
|
|
229
|
+
$eq: new Date().toISOString()
|
|
230
|
+
}
|
|
231
|
+
}]
|
|
232
|
+
})
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('advanced queries should be able to parse coerce date $gt', async function () {
|
|
236
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
237
|
+
date: z.coerce.date()
|
|
238
|
+
}))
|
|
239
|
+
|
|
240
|
+
query_validator.parse({
|
|
241
|
+
$and:[{
|
|
242
|
+
date: {
|
|
243
|
+
$gt: new Date().toISOString()
|
|
244
|
+
}
|
|
245
|
+
}]
|
|
246
|
+
})
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('advanced queries should be able to parse coerce date $lt', async function () {
|
|
250
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
251
|
+
date: z.coerce.date()
|
|
252
|
+
}))
|
|
253
|
+
|
|
254
|
+
query_validator.parse({
|
|
255
|
+
$and:[{
|
|
256
|
+
date: {
|
|
257
|
+
$lt: new Date().toISOString()
|
|
258
|
+
}
|
|
259
|
+
}]
|
|
260
|
+
})
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('advanced queries should be able to parse coerce date $gte', async function () {
|
|
264
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
265
|
+
date: z.coerce.date()
|
|
266
|
+
}))
|
|
267
|
+
|
|
268
|
+
query_validator.parse({
|
|
269
|
+
$and:[{
|
|
270
|
+
date: {
|
|
271
|
+
$gte: new Date().toISOString()
|
|
272
|
+
}
|
|
273
|
+
}]
|
|
274
|
+
})
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('advanced queries should be able to parse coerce date $lte', async function () {
|
|
278
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
279
|
+
date: z.coerce.date()
|
|
280
|
+
}))
|
|
281
|
+
|
|
282
|
+
query_validator.parse({
|
|
283
|
+
$and:[{
|
|
284
|
+
date: {
|
|
285
|
+
$lte: new Date().toISOString()
|
|
286
|
+
}
|
|
287
|
+
}]
|
|
288
|
+
})
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('advanced queries should be able to parse mongodb id $eq', async function () {
|
|
292
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
293
|
+
_id: z_mongodb_id
|
|
294
|
+
}))
|
|
295
|
+
|
|
296
|
+
query_validator.parse({
|
|
297
|
+
$and:[{
|
|
298
|
+
_id: {
|
|
299
|
+
$eq: '697b80da5a78eb5b841ad72f'
|
|
300
|
+
}
|
|
301
|
+
}]
|
|
302
|
+
})
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it('advanced queries should be able to parse mongodb id $gt', async function () {
|
|
306
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
307
|
+
_id: z_mongodb_id
|
|
308
|
+
}))
|
|
309
|
+
|
|
310
|
+
query_validator.parse({
|
|
311
|
+
$and:[{
|
|
312
|
+
_id: {
|
|
313
|
+
$gt: '697b80da5a78eb5b841ad72f'
|
|
314
|
+
}
|
|
315
|
+
}]
|
|
316
|
+
})
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it('advanced queries should be able to parse mongodb id $lt', async function () {
|
|
320
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
321
|
+
_id: z_mongodb_id
|
|
322
|
+
}))
|
|
323
|
+
|
|
324
|
+
query_validator.parse({
|
|
325
|
+
$and:[{
|
|
326
|
+
_id: {
|
|
327
|
+
$lt: '697b80da5a78eb5b841ad72f'
|
|
328
|
+
}
|
|
329
|
+
}]
|
|
330
|
+
})
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('advanced queries should be able to parse mongodb id $gte', async function () {
|
|
334
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
335
|
+
_id: z_mongodb_id
|
|
336
|
+
}))
|
|
337
|
+
|
|
338
|
+
query_validator.parse({
|
|
339
|
+
$and:[{
|
|
340
|
+
_id: {
|
|
341
|
+
$gte: '697b80da5a78eb5b841ad72f'
|
|
342
|
+
}
|
|
343
|
+
}]
|
|
344
|
+
})
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it('advanced queries should be able to parse mongodb id $lte', async function () {
|
|
348
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
349
|
+
_id: z_mongodb_id
|
|
350
|
+
}))
|
|
351
|
+
|
|
352
|
+
query_validator.parse({
|
|
353
|
+
$and:[{
|
|
354
|
+
_id: {
|
|
355
|
+
$lte: '697b80da5a78eb5b841ad72f'
|
|
356
|
+
}
|
|
357
|
+
}]
|
|
358
|
+
})
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it('advanced queries should be able to parse mongodb id $in', async function () {
|
|
362
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
363
|
+
_id: z_mongodb_id
|
|
364
|
+
}))
|
|
365
|
+
|
|
366
|
+
query_validator.parse({
|
|
367
|
+
$and:[{
|
|
368
|
+
_id: {
|
|
369
|
+
$in: ['697b80da5a78eb5b841ad72f']
|
|
370
|
+
}
|
|
371
|
+
}]
|
|
372
|
+
})
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it('advanced queries should be able to parse mongodb id $nin', async function () {
|
|
376
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
377
|
+
_id: z_mongodb_id
|
|
378
|
+
}))
|
|
379
|
+
|
|
380
|
+
query_validator.parse({
|
|
381
|
+
$and:[{
|
|
382
|
+
_id: {
|
|
383
|
+
$nin: ['697b80da5a78eb5b841ad72f']
|
|
384
|
+
}
|
|
385
|
+
}]
|
|
386
|
+
})
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it('advanced quey fields should be optional', async function () {
|
|
390
|
+
let query_validator = complex_query_validator_from_zod(z.object({
|
|
391
|
+
_id: z_mongodb_id,
|
|
392
|
+
enum: z.enum(['one', 'two']),
|
|
393
|
+
bool: z.boolean(),
|
|
394
|
+
num: z.number(),
|
|
395
|
+
date: z.date(),
|
|
396
|
+
}))
|
|
397
|
+
|
|
398
|
+
query_validator.parse({
|
|
399
|
+
$and:[]
|
|
400
|
+
})
|
|
401
|
+
});
|
|
402
|
+
});
|
|
@@ -61,6 +61,7 @@ describe('Basic Server', function () {
|
|
|
61
61
|
|
|
62
62
|
// before any tests run, set up the server and the db connection
|
|
63
63
|
before(async function() {
|
|
64
|
+
this.timeout(10000)
|
|
64
65
|
express_app = express();
|
|
65
66
|
express_app.use(express.json());
|
|
66
67
|
db_connection = await mongoose.connect('mongodb://127.0.0.1:27017/');
|
|
@@ -471,6 +472,35 @@ describe('Basic Server', function () {
|
|
|
471
472
|
})
|
|
472
473
|
});
|
|
473
474
|
|
|
475
|
+
|
|
476
|
+
it(`should be able to perform a basic GET multiple with a regex search`, async function () {
|
|
477
|
+
let test_institutions = []
|
|
478
|
+
for(let q = 0; q < 5; q++){
|
|
479
|
+
let test_institution = await institution.mongoose_model.create({
|
|
480
|
+
name: ['spandex co',
|
|
481
|
+
'the ordinary institute',
|
|
482
|
+
'saliva branding collective',
|
|
483
|
+
'united league of billionare communitsts',
|
|
484
|
+
'geriatric co',
|
|
485
|
+
'jousing club of omaha, nebraska',
|
|
486
|
+
'dental hygenist paratrooper union',
|
|
487
|
+
'martha stewart\'s cannibal fan club',
|
|
488
|
+
'wrecking ball operator crochet club',
|
|
489
|
+
'accidental co'
|
|
490
|
+
][q]
|
|
491
|
+
});
|
|
492
|
+
//@ts-ignore
|
|
493
|
+
test_institutions.push(test_institution);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
let results = await got.get(`http://localhost:${port}/api/institution?name_search=li`).json();
|
|
497
|
+
|
|
498
|
+
//@ts-ignore
|
|
499
|
+
assert.equal(results.data.length, 2)
|
|
500
|
+
//@ts-ignore
|
|
501
|
+
assert.deepEqual(JSON.parse(JSON.stringify(test_institutions.filter(ele => ele.name.match(/li/i)))), results.data);
|
|
502
|
+
});
|
|
503
|
+
|
|
474
504
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
475
505
|
///////////////////////////////////////////////////////////// PUT ////////////////////////////////////////////////////////////////////////////////////
|
|
476
506
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|