@liminalfunctions/framework 1.0.44 → 1.0.47
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/README.md +315 -4
- package/dist/F_Collection.js +6 -0
- package/dist/F_Collection.js.map +1 -1
- package/dist/F_Collection_Registry.js +1 -1
- package/dist/F_Collection_Registry.js.map +1 -1
- package/dist/F_Compile.d.ts +2 -1
- package/dist/F_Compile.js +18 -1
- package/dist/F_Compile.js.map +1 -1
- package/dist/utils/mongoose_from_zod.js +19 -0
- package/dist/utils/mongoose_from_zod.js.map +1 -1
- package/dist/utils/query_object_to_mongodb_query.d.ts +13 -0
- package/dist/utils/query_object_to_mongodb_query.js +2 -2
- package/dist/utils/query_object_to_mongodb_query.js.map +1 -1
- package/package.json +1 -1
- package/src/F_Collection.ts +7 -0
- package/src/F_Collection_Registry.ts +1 -1
- package/src/F_Compile.ts +32 -1
- package/src/utils/mongoose_from_zod.ts +22 -3
- package/src/utils/query_object_to_mongodb_query.ts +2 -2
- package/test/0_1_mongoose_from_zod.test.ts +37 -0
- package/test/2_0_client_library_basic_type_generation.test.ts +48 -2
- package/test/2_0_client_library_query_type_generation.test.ts +63 -38
|
@@ -45,7 +45,9 @@ describe('Client Library Generation: Query Types', function () {
|
|
|
45
45
|
})
|
|
46
46
|
|
|
47
47
|
it(`should be able to generate a query for a plain object`, async function () {
|
|
48
|
-
const validate_test_collection = z.object({
|
|
48
|
+
const validate_test_collection = z.object({
|
|
49
|
+
_id: z_mongodb_id,
|
|
50
|
+
});
|
|
49
51
|
|
|
50
52
|
let test_collection = new F_Collection('test_collection', 'test_collection', validate_test_collection);
|
|
51
53
|
|
|
@@ -60,13 +62,18 @@ describe('Client Library Generation: Query Types', function () {
|
|
|
60
62
|
"limit"?: number
|
|
61
63
|
"cursor"?: string
|
|
62
64
|
"sort_order"?: ("ascending" | "descending")
|
|
63
|
-
"
|
|
65
|
+
"_id"?: string
|
|
66
|
+
"_id_gt"?: string
|
|
67
|
+
"_id_lt"?: string
|
|
68
|
+
"_id_in"?: string[]
|
|
69
|
+
"sort"?: ("_id")
|
|
64
70
|
}`)
|
|
65
71
|
)
|
|
66
72
|
});
|
|
67
73
|
|
|
68
74
|
it(`should be able to generate a plain object containing a string`, async function () {
|
|
69
75
|
const validate_test_collection = z.object({
|
|
76
|
+
_id: z_mongodb_id,
|
|
70
77
|
test: z.string(),
|
|
71
78
|
});
|
|
72
79
|
|
|
@@ -83,17 +90,22 @@ describe('Client Library Generation: Query Types', function () {
|
|
|
83
90
|
"limit"?: number
|
|
84
91
|
"cursor"?: string
|
|
85
92
|
"sort_order"?: ("ascending" | "descending")
|
|
93
|
+
"_id"?: string
|
|
94
|
+
"_id_gt"?: string
|
|
95
|
+
"_id_lt"?: string
|
|
96
|
+
"_id_in"?: string[]
|
|
86
97
|
"test"?: string
|
|
87
98
|
"test_gt"?: string
|
|
88
99
|
"test_lt"?: string
|
|
89
100
|
"test_in"?: string[]
|
|
90
|
-
"sort"?: ("test")
|
|
101
|
+
"sort"?: ("_id" | "test")
|
|
91
102
|
}`)
|
|
92
103
|
)
|
|
93
104
|
});
|
|
94
105
|
|
|
95
106
|
it(`should be able to generate a plain object containing a number`, async function () {
|
|
96
107
|
const validate_test_collection = z.object({
|
|
108
|
+
_id: z_mongodb_id,
|
|
97
109
|
test: z.number(),
|
|
98
110
|
});
|
|
99
111
|
|
|
@@ -110,18 +122,23 @@ describe('Client Library Generation: Query Types', function () {
|
|
|
110
122
|
"limit"?: number
|
|
111
123
|
"cursor"?: string
|
|
112
124
|
"sort_order"?: ("ascending" | "descending")
|
|
125
|
+
"_id"?: string
|
|
126
|
+
"_id_gt"?: string
|
|
127
|
+
"_id_lt"?: string
|
|
128
|
+
"_id_in"?: string[]
|
|
113
129
|
"test"?: number
|
|
114
130
|
"test_gt"?: number
|
|
115
131
|
"test_gte"?: number
|
|
116
132
|
"test_lt"?: number
|
|
117
133
|
"test_lte"?: number
|
|
118
|
-
"sort"?: ("test")
|
|
134
|
+
"sort"?: ("_id" | "test")
|
|
119
135
|
}`)
|
|
120
136
|
)
|
|
121
137
|
});
|
|
122
138
|
|
|
123
139
|
it(`should be able to generate a plain object containing a boolean`, async function () {
|
|
124
140
|
const validate_test_collection = z.object({
|
|
141
|
+
_id: z_mongodb_id,
|
|
125
142
|
test: z.boolean(),
|
|
126
143
|
});
|
|
127
144
|
|
|
@@ -138,14 +155,19 @@ describe('Client Library Generation: Query Types', function () {
|
|
|
138
155
|
"limit"?: number
|
|
139
156
|
"cursor"?: string
|
|
140
157
|
"sort_order"?: ("ascending" | "descending")
|
|
158
|
+
"_id"?: string
|
|
159
|
+
"_id_gt"?: string
|
|
160
|
+
"_id_lt"?: string
|
|
161
|
+
"_id_in"?: string[]
|
|
141
162
|
"test"?: boolean
|
|
142
|
-
"sort"?: ("test")
|
|
163
|
+
"sort"?: ("_id" | "test")
|
|
143
164
|
}`)
|
|
144
165
|
)
|
|
145
166
|
});
|
|
146
167
|
|
|
147
168
|
it(`should be able to generate a plain object containing a date`, async function () {
|
|
148
169
|
const validate_test_collection = z.object({
|
|
170
|
+
_id: z_mongodb_id,
|
|
149
171
|
test: z.date(),
|
|
150
172
|
});
|
|
151
173
|
|
|
@@ -162,43 +184,21 @@ describe('Client Library Generation: Query Types', function () {
|
|
|
162
184
|
"limit"?: number
|
|
163
185
|
"cursor"?: string
|
|
164
186
|
"sort_order"?: ("ascending" | "descending")
|
|
187
|
+
"_id"?: string
|
|
188
|
+
"_id_gt"?: string
|
|
189
|
+
"_id_lt"?: string
|
|
190
|
+
"_id_in"?: string[]
|
|
165
191
|
"test"?: Date
|
|
166
192
|
"test_gt"?: Date
|
|
167
193
|
"test_lt"?: Date
|
|
168
|
-
"sort"?: ("test")
|
|
169
|
-
}`)
|
|
170
|
-
)
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it(`should be able to generate a plain object containing an objectID`, async function () {
|
|
174
|
-
const validate_test_collection = z.object({
|
|
175
|
-
test: z_mongodb_id,
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
let test_collection = new F_Collection('test_collection', 'test_collection', validate_test_collection);
|
|
179
|
-
|
|
180
|
-
let proto_registry = new F_Collection_Registry();
|
|
181
|
-
let registry = proto_registry.register(test_collection);
|
|
182
|
-
|
|
183
|
-
await generate_client_library('./test/tmp', registry);
|
|
184
|
-
|
|
185
|
-
assert.equal(
|
|
186
|
-
remove_whitespace(await readFile('./test/tmp/src/types/test_collection_query.ts', { encoding: 'utf-8' })),
|
|
187
|
-
remove_whitespace(`export type test_collection_query = {
|
|
188
|
-
"limit"?: number
|
|
189
|
-
"cursor"?: string
|
|
190
|
-
"sort_order"?: ("ascending" | "descending")
|
|
191
|
-
"test"?: string
|
|
192
|
-
"test_gt"?: string
|
|
193
|
-
"test_lt"?: string
|
|
194
|
-
"test_in"?: string[]
|
|
195
|
-
"sort"?: ("test")
|
|
194
|
+
"sort"?: ("_id" | "test")
|
|
196
195
|
}`)
|
|
197
196
|
)
|
|
198
197
|
});
|
|
199
198
|
|
|
200
199
|
it(`should be able to generate an enum`, async function () {
|
|
201
200
|
const validate_test_collection = z.object({
|
|
201
|
+
_id: z_mongodb_id,
|
|
202
202
|
test: z.enum(["red", "green", "blue"]),
|
|
203
203
|
});
|
|
204
204
|
|
|
@@ -215,9 +215,13 @@ describe('Client Library Generation: Query Types', function () {
|
|
|
215
215
|
"limit"?: number
|
|
216
216
|
"cursor"?: string
|
|
217
217
|
"sort_order"?: ("ascending" | "descending")
|
|
218
|
+
"_id"?: string
|
|
219
|
+
"_id_gt"?: string
|
|
220
|
+
"_id_lt"?: string
|
|
221
|
+
"_id_in"?: string[]
|
|
218
222
|
"test"?: ("red" | "green" | "blue")
|
|
219
223
|
"test_in"?: ("red" | "green" | "blue")[]
|
|
220
|
-
"sort"?: ("test")
|
|
224
|
+
"sort"?: ("_id" | "test")
|
|
221
225
|
}`)
|
|
222
226
|
)
|
|
223
227
|
});
|
|
@@ -226,6 +230,7 @@ describe('Client Library Generation: Query Types', function () {
|
|
|
226
230
|
|
|
227
231
|
it(`should be able to generate a plain nested object`, async function () {
|
|
228
232
|
const validate_test_collection = z.object({
|
|
233
|
+
_id: z_mongodb_id,
|
|
229
234
|
test: z.object({
|
|
230
235
|
}),
|
|
231
236
|
});
|
|
@@ -243,13 +248,18 @@ describe('Client Library Generation: Query Types', function () {
|
|
|
243
248
|
"limit"?: number
|
|
244
249
|
"cursor"?: string
|
|
245
250
|
"sort_order"?: ("ascending" | "descending")
|
|
246
|
-
"
|
|
251
|
+
"_id"?: string
|
|
252
|
+
"_id_gt"?: string
|
|
253
|
+
"_id_lt"?: string
|
|
254
|
+
"_id_in"?: string[]
|
|
255
|
+
"sort"?: ("_id")
|
|
247
256
|
}`)
|
|
248
257
|
)
|
|
249
258
|
});
|
|
250
259
|
|
|
251
260
|
it(`should be able to generate a plain nested with basic fields`, async function () {
|
|
252
261
|
const validate_test_collection = z.object({
|
|
262
|
+
_id: z_mongodb_id,
|
|
253
263
|
test: z.object({
|
|
254
264
|
field_string: z.string(),
|
|
255
265
|
field_number: z.number(),
|
|
@@ -275,6 +285,11 @@ describe('Client Library Generation: Query Types', function () {
|
|
|
275
285
|
"cursor"?: string
|
|
276
286
|
"sort_order"?: ("ascending" | "descending")
|
|
277
287
|
|
|
288
|
+
"_id"?: string
|
|
289
|
+
"_id_gt"?: string
|
|
290
|
+
"_id_lt"?: string
|
|
291
|
+
"_id_in"?: string[]
|
|
292
|
+
|
|
278
293
|
"test.field_string"?: string
|
|
279
294
|
"test.field_string_gt"?: string
|
|
280
295
|
"test.field_string_lt"?: string
|
|
@@ -293,13 +308,14 @@ describe('Client Library Generation: Query Types', function () {
|
|
|
293
308
|
"test.field_date_lt"?: Date
|
|
294
309
|
|
|
295
310
|
"test.test_2.field_doublenested"?: boolean
|
|
296
|
-
"sort"?: ("test.field_string" | "test.field_number" | "test.field_boolean" | "test.field_date" | "test.test_2.field_doublenested")
|
|
311
|
+
"sort"?: ("_id" | "test.field_string" | "test.field_number" | "test.field_boolean" | "test.field_date" | "test.test_2.field_doublenested")
|
|
297
312
|
}`)
|
|
298
313
|
)
|
|
299
314
|
});
|
|
300
315
|
|
|
301
316
|
it(`should be able to generate arrays of primitive fields`, async function () {
|
|
302
317
|
const validate_test_collection = z.object({
|
|
318
|
+
_id: z_mongodb_id,
|
|
303
319
|
field_string: z.array(z.string()),
|
|
304
320
|
field_number: z.array(z.number()),
|
|
305
321
|
field_boolean: z.array(z.boolean()),
|
|
@@ -318,16 +334,21 @@ describe('Client Library Generation: Query Types', function () {
|
|
|
318
334
|
"limit"?: number
|
|
319
335
|
"cursor"?: string
|
|
320
336
|
"sort_order"?: ("ascending" | "descending")
|
|
337
|
+
"_id"?: string
|
|
338
|
+
"_id_gt"?: string
|
|
339
|
+
"_id_lt"?: string
|
|
340
|
+
"_id_in"?: string[]
|
|
321
341
|
"field_string"?: string
|
|
322
342
|
"field_number"?: number
|
|
323
343
|
"field_boolean"?: boolean
|
|
324
|
-
"sort"?: ("field_string" | "field_number" | "field_boolean")
|
|
344
|
+
"sort"?: ("_id" | "field_string" | "field_number" | "field_boolean")
|
|
325
345
|
}`)
|
|
326
346
|
)
|
|
327
347
|
});
|
|
328
348
|
|
|
329
349
|
it(`should be able to generate a plain object containing a primitive with a default`, async function () {
|
|
330
350
|
const validate_test_collection = z.object({
|
|
351
|
+
_id: z_mongodb_id,
|
|
331
352
|
test: z.boolean().default(true),
|
|
332
353
|
});
|
|
333
354
|
|
|
@@ -344,8 +365,12 @@ describe('Client Library Generation: Query Types', function () {
|
|
|
344
365
|
"limit"?: number
|
|
345
366
|
"cursor"?: string
|
|
346
367
|
"sort_order"?: ("ascending" | "descending")
|
|
368
|
+
"_id"?: string
|
|
369
|
+
"_id_gt"?: string
|
|
370
|
+
"_id_lt"?: string
|
|
371
|
+
"_id_in"?: string[]
|
|
347
372
|
"test"?: boolean
|
|
348
|
-
"sort"?: ("test")
|
|
373
|
+
"sort"?: ("_id" | "test")
|
|
349
374
|
}`)
|
|
350
375
|
)
|
|
351
376
|
});
|