@liminalfunctions/framework 1.0.43 → 1.0.46

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.
Files changed (38) hide show
  1. package/README.md +315 -4
  2. package/dist/F_Collection.js +6 -0
  3. package/dist/F_Collection.js.map +1 -1
  4. package/dist/F_Collection_Registry.js +1 -1
  5. package/dist/F_Collection_Registry.js.map +1 -1
  6. package/dist/F_Compile.d.ts +2 -1
  7. package/dist/F_Compile.js +18 -1
  8. package/dist/F_Compile.js.map +1 -1
  9. package/dist/code_generation/templates/collection.mustache +72 -56
  10. package/dist/code_generation/templates/main.mustache +23 -12
  11. package/package.json +1 -1
  12. package/src/F_Collection.ts +7 -0
  13. package/src/F_Collection_Registry.ts +1 -1
  14. package/src/F_Compile.ts +32 -1
  15. package/src/code_generation/templates/collection.mustache +72 -56
  16. package/src/code_generation/templates/main.mustache +23 -12
  17. package/test/2_0_client_library_basic_type_generation.test.ts +48 -2
  18. package/test/2_0_client_library_query_type_generation.test.ts +63 -38
  19. package/test/tmp/dist/Brief_News_Category.d.ts +13 -10
  20. package/test/tmp/dist/Brief_News_Category.js +55 -47
  21. package/test/tmp/dist/Brief_News_Category.js.map +1 -1
  22. package/test/tmp/dist/Client.d.ts +15 -11
  23. package/test/tmp/dist/Client.js +65 -57
  24. package/test/tmp/dist/Client.js.map +1 -1
  25. package/test/tmp/dist/Institution.d.ts +14 -11
  26. package/test/tmp/dist/Institution.js +63 -55
  27. package/test/tmp/dist/Institution.js.map +1 -1
  28. package/test/tmp/dist/Project.d.ts +13 -10
  29. package/test/tmp/dist/Project.js +55 -47
  30. package/test/tmp/dist/Project.js.map +1 -1
  31. package/test/tmp/dist/index.d.ts +7 -2
  32. package/test/tmp/dist/index.js +16 -9
  33. package/test/tmp/dist/index.js.map +1 -1
  34. package/test/tmp/src/Brief_News_Category.ts +57 -44
  35. package/test/tmp/src/Client.ts +69 -54
  36. package/test/tmp/src/Institution.ts +66 -52
  37. package/test/tmp/src/Project.ts +57 -44
  38. package/test/tmp/src/index.ts +19 -10
@@ -7,18 +7,29 @@ import { Collection_{{built_collection}} } from "{{ built_collection_path }}"
7
7
 
8
8
 
9
9
  export function api(base_url: string, get_auth: () => Promise<any>) {
10
- return {
11
- collection(collection_id: {{child_collection_id_types}}) {
12
- switch(collection_id) {
13
- {{#child_collections}}
14
- case "{{collection_id}}":
15
- return new Collection_{{built_collection}}([base_url, "{{collection_id}}"], get_auth);
16
- {{/child_collections}}
17
- default:
18
- throw new Error(`Api does not have the collection ${collection_id}`)
19
- }
20
- }
21
- }
10
+ return new Api(base_url, get_auth)
22
11
  }
23
12
 
13
+ class Api {
14
+ base_url: string;
15
+ get_auth: () => Promise<any>
16
+
17
+ constructor(base_url: string, get_auth: () => Promise<any>) {
18
+ this.base_url = base_url;
19
+ this.get_auth = get_auth
20
+ }
24
21
 
22
+ {{#child_collections}}
23
+ collection(collection_id: "{{collection_id}}"): Collection_{{built_collection}};
24
+ {{/child_collections}}
25
+ collection(collection_id: string) {
26
+ switch(collection_id) {
27
+ {{#child_collections}}
28
+ case "{{collection_id}}":
29
+ return new Collection_{{built_collection}}([this.base_url, "{{collection_id}}"], this.get_auth);
30
+ {{/child_collections}}
31
+ default:
32
+ throw new Error(`Api does not have the collection ${collection_id}`)
33
+ }
34
+ }
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liminalfunctions/framework",
3
- "version": "1.0.43",
3
+ "version": "1.0.46",
4
4
  "main": "./dist/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -48,6 +48,13 @@ export class F_Collection<Collection_ID extends string, ZodSchema extends z.ZodO
48
48
  this.query_validator_server = query_validator_from_zod(validator, 'server');
49
49
  this.query_validator_client = query_validator_from_zod(validator, 'client');
50
50
  // TODO: we can make this more closely match the mongoDB PUT operation and allow updates to eg array.3.element fields
51
+
52
+ if(!Object.hasOwn(this.validator._zod.def.shape, '_id')){
53
+ throw new Error(`_id is a required field, because each collection is a mongoDB object.`)
54
+ }
55
+ if(this.validator._zod.def.shape._id.meta()?.framework_override_type !== 'mongodb_id'){
56
+ throw new Error(`_id must be a mongoDB ID. Use the z_mongodb_id special field.`)
57
+ }
51
58
 
52
59
  // TODO: find a more elegant way to do this so that the types don't have a cow
53
60
  //@ts-ignore
@@ -23,7 +23,7 @@ export class F_Collection_Registry<Collections = {}> {
23
23
 
24
24
  compile(app: Router, api_prefix: string) {
25
25
  for(let collection of Object.values(this.collections)){
26
- compile(app, collection, api_prefix)
26
+ compile(app, collection, api_prefix, this)
27
27
  }
28
28
  }
29
29
  }
package/src/F_Compile.ts CHANGED
@@ -6,20 +6,51 @@ import { F_Collection } from "./F_Collection.js";
6
6
  import { F_Security_Model, Authenticated_Request } from "./F_Security_Models/F_Security_Model.js";
7
7
  import { convert_null, query_object_to_mongodb_limits, query_object_to_mongodb_query } from "./utils/query_object_to_mongodb_query.js";
8
8
  import { z_mongodb_id } from "./utils/mongoose_from_zod.js";
9
+ import { F_Collection_Registry } from "./F_Collection_Registry.js";
9
10
 
10
11
  /*process.on('unhandledRejection', (reason, promise) => {
11
12
  console.log(`CAUGHT UNHANDLED REJECTION`)
12
13
  console.log(reason)
13
14
  })*/
14
15
 
15
- export function compile<Collection_ID extends string, ZodSchema extends z.ZodObject>(app: Router, collection: F_Collection<Collection_ID, ZodSchema>, api_prefix: string){
16
+ export function compile<Collection_ID extends string, ZodSchema extends z.ZodObject>(
17
+ app: Router,
18
+ collection: F_Collection<Collection_ID, ZodSchema>,
19
+ api_prefix: string,
20
+ collection_registry: F_Collection_Registry<any>){
16
21
  /*app.use((req, res, next) => {
17
22
  console.log(`${req.method} ${req.originalUrl}`)
18
23
  next();
19
24
  })*/
25
+
26
+
27
+ for(let access_layers of collection.access_layers){
28
+ for(let layer of access_layers.layers){
29
+ // verify that the collection is not in its own layers
30
+ if(layer === collection.collection_id){
31
+ throw new Error(`Error compiling collection ${collection.collection_id}: a collection cannot be a member of it's own layer. Remove "${collection.collection_id}" from the collection's layers.`)
32
+ }
33
+
34
+ // verify that each layer has a corresponding collection
35
+ if(!collection_registry.collections[layer]){
36
+ throw new Error(`Error compiling collection ${collection.collection_id}: collection registry does not have a collection with the ID "${layer}". Each layer must be a valid collection ID.`)
37
+ }
38
+
39
+ if(!Object.hasOwn(collection.validator._zod.def.shape, `${layer}_id`)) {
40
+ throw new Error(`Error compiling collection ${collection.collection_id}: collection does not have a field "${layer}_id. Either remove ${layer} from the collection's layers, or add a field ${layer}_id`)
41
+ }
42
+
43
+ let layer_id_is_mongodb_id = collection.validator._zod.def.shape[`${layer}_id`].meta()?.framework_override_type === 'mongodb_id';
44
+ if(!layer_id_is_mongodb_id){
45
+ throw new Error(`Error compiling collection ${collection.collection_id}: ${layer}_id must be a mongodb ID. use the z_mongodb_id, z_mongodb_id_nullable, or z_mongodb_id_optional special fields.`)
46
+ }
47
+ }
48
+ }
20
49
 
50
+ // set up the Express endpoints
21
51
  for(let access_layers of collection.access_layers){
22
52
  let base_layers_path_components = access_layers.layers.flatMap(ele => [ele, ':' + ele]);
53
+
23
54
 
24
55
  let get_one_path = [
25
56
  api_prefix,
@@ -54,64 +54,80 @@ export class Collection_{{my_built_collection}} {
54
54
  let get_auth = this.get_auth;
55
55
  let collection_id = this.collection_id;
56
56
  let collection_name_plural = this.collection_name_plural;
57
- return {
58
- path: [...path, document_id],
59
- collection_id: collection_id,
60
- document_id: document_id,
61
- collection_name_plural: collection_name_plural,
62
- get_auth: get_auth,
63
- async get(): Promise<{{type_return}}>{
64
- try {
65
- let result = await ky.get([...path, document_id].join('/'), {
66
- headers: {
67
- authorization: await get_auth()
68
- },
69
- }).json() as Response<{{type_return}}>;
70
- return result.data;
71
- } catch(err){
72
- return Promise.reject(err)
73
- }
74
- },
57
+ return new Document(path, collection_id, document_id, collection_name_plural, get_auth);
58
+ }
59
+ }
60
+
61
+
62
+
63
+ class Document {
64
+ path: string[];
65
+ collection_id: string;
66
+ document_id: string;
67
+ collection_name_plural: string;
68
+ get_auth: () => Promise<any>;
69
+
70
+ constructor(path: string[], collection_id: string, document_id: string, collection_name_plural: string, get_auth: () => Promise<any>) {
71
+ this.path = path;
72
+ this.collection_id = collection_id;
73
+ this.document_id = document_id;
74
+ this.collection_name_plural = collection_name_plural;
75
+ this.get_auth = get_auth;
76
+ }
77
+
78
+ async get(): Promise<{{type_return}}>{
79
+ try {
80
+ let result = await ky.get([...this.path, this.document_id].join('/'), {
81
+ headers: {
82
+ authorization: await this.get_auth()
83
+ },
84
+ }).json() as Response<{{type_return}}>;
85
+ return result.data;
86
+ } catch(err){
87
+ return Promise.reject(err)
88
+ }
89
+ }
75
90
 
76
- async put(update: {{type_put}}): Promise<{{type_return}}>{
77
- try {
78
- let result = await ky.put([...path, document_id].join('/'), {
79
- headers: {
80
- authorization: await get_auth()
81
- },
82
- json: update
83
- }).json() as Response<{{type_return}}>;
84
- return result.data;
85
- } catch(err){
86
- return Promise.reject(err)
87
- }
88
- },
89
-
90
- async remove(): Promise<{{type_return}}>{
91
- try {
92
- let result = await ky.delete([...path, document_id].join('/'), {
93
- headers: {
94
- authorization: await get_auth()
95
- },
96
- }).json() as Response<{{type_return}}>;
97
- return result.data;
98
- } catch(err){
99
- return Promise.reject(err)
100
- }
101
- },
91
+ async put(update: {{type_put}}): Promise<{{type_return}}>{
92
+ try {
93
+ let result = await ky.put([...this.path, this.document_id].join('/'), {
94
+ headers: {
95
+ authorization: await this.get_auth()
96
+ },
97
+ json: update
98
+ }).json() as Response<{{type_return}}>;
99
+ return result.data;
100
+ } catch(err){
101
+ return Promise.reject(err)
102
+ }
103
+ }
104
+
105
+ async remove(): Promise<{{type_return}}>{
106
+ try {
107
+ let result = await ky.delete([...this.path, this.document_id].join('/'), {
108
+ headers: {
109
+ authorization: await this.get_auth()
110
+ },
111
+ }).json() as Response<{{type_return}}>;
112
+ return result.data;
113
+ } catch(err){
114
+ return Promise.reject(err)
115
+ }
116
+ }
102
117
 
103
- {{#has_subcollections}}
104
- collection(collection_id: {{child_collection_id_types}}) {
105
- switch(collection_id) {
106
- {{#child_collections}}
107
- case "{{collection_id}}":
108
- return new Collection_{{built_collection}}([...path, document_id, "{{collection_id}}"], get_auth);
109
- {{/child_collections}}
110
- default:
111
- throw new Error(`Api does not have the collection ${collection_id}`)
112
- }
113
- }
114
- {{/has_subcollections}}
118
+ {{#has_subcollections}}
119
+ {{#child_collections}}
120
+ collection(collection_id: "{{collection_id}}"): Collection_{{built_collection}};
121
+ {{/child_collections}}
122
+ collection(collection_id: string) {
123
+ switch(collection_id) {
124
+ {{#child_collections}}
125
+ case "{{collection_id}}":
126
+ return new Collection_{{built_collection}}([...this.path, this.document_id, "{{collection_id}}"], this.get_auth);
127
+ {{/child_collections}}
128
+ default:
129
+ throw new Error(`Api does not have the collection ${collection_id}`)
115
130
  }
116
131
  }
132
+ {{/has_subcollections}}
117
133
  }
@@ -7,18 +7,29 @@ import { Collection_{{built_collection}} } from "{{ built_collection_path }}"
7
7
 
8
8
 
9
9
  export function api(base_url: string, get_auth: () => Promise<any>) {
10
- return {
11
- collection(collection_id: {{child_collection_id_types}}) {
12
- switch(collection_id) {
13
- {{#child_collections}}
14
- case "{{collection_id}}":
15
- return new Collection_{{built_collection}}([base_url, "{{collection_id}}"], get_auth);
16
- {{/child_collections}}
17
- default:
18
- throw new Error(`Api does not have the collection ${collection_id}`)
19
- }
20
- }
21
- }
10
+ return new Api(base_url, get_auth)
22
11
  }
23
12
 
13
+ class Api {
14
+ base_url: string;
15
+ get_auth: () => Promise<any>
16
+
17
+ constructor(base_url: string, get_auth: () => Promise<any>) {
18
+ this.base_url = base_url;
19
+ this.get_auth = get_auth
20
+ }
24
21
 
22
+ {{#child_collections}}
23
+ collection(collection_id: "{{collection_id}}"): Collection_{{built_collection}};
24
+ {{/child_collections}}
25
+ collection(collection_id: string) {
26
+ switch(collection_id) {
27
+ {{#child_collections}}
28
+ case "{{collection_id}}":
29
+ return new Collection_{{built_collection}}([this.base_url, "{{collection_id}}"], this.get_auth);
30
+ {{/child_collections}}
31
+ default:
32
+ throw new Error(`Api does not have the collection ${collection_id}`)
33
+ }
34
+ }
35
+ }
@@ -38,7 +38,9 @@ describe('Client Library Generation: Basic Types', function () {
38
38
  })
39
39
 
40
40
  it(`should be able to generate a plain object`, async function () {
41
- const validate_test_collection = z.object({});
41
+ const validate_test_collection = z.object({
42
+ _id: z_mongodb_id
43
+ });
42
44
 
43
45
  let test_collection = new F_Collection('test_collection', 'test_collection', validate_test_collection);
44
46
 
@@ -49,12 +51,13 @@ describe('Client Library Generation: Basic Types', function () {
49
51
 
50
52
  assert.equal(
51
53
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
52
- remove_whitespace(`export type test_collection = {}`)
54
+ remove_whitespace(`export type test_collection = {"_id": string}`)
53
55
  )
54
56
  });
55
57
 
56
58
  it(`should be able to generate a plain object containing a string`, async function () {
57
59
  const validate_test_collection = z.object({
60
+ _id: z_mongodb_id,
58
61
  test: z.string(),
59
62
  });
60
63
 
@@ -68,6 +71,7 @@ describe('Client Library Generation: Basic Types', function () {
68
71
  assert.equal(
69
72
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
70
73
  remove_whitespace(`export type test_collection = {
74
+ "_id": string
71
75
  "test": string
72
76
  }`)
73
77
  )
@@ -75,6 +79,7 @@ describe('Client Library Generation: Basic Types', function () {
75
79
 
76
80
  it(`should be able to generate a plain object containing a number`, async function () {
77
81
  const validate_test_collection = z.object({
82
+ _id: z_mongodb_id,
78
83
  test: z.number(),
79
84
  });
80
85
 
@@ -88,6 +93,7 @@ describe('Client Library Generation: Basic Types', function () {
88
93
  assert.equal(
89
94
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
90
95
  remove_whitespace(`export type test_collection = {
96
+ "_id": string
91
97
  "test": number
92
98
  }`)
93
99
  )
@@ -95,6 +101,7 @@ describe('Client Library Generation: Basic Types', function () {
95
101
 
96
102
  it(`should be able to generate a plain object containing a boolean`, async function () {
97
103
  const validate_test_collection = z.object({
104
+ _id: z_mongodb_id,
98
105
  test: z.boolean(),
99
106
  });
100
107
 
@@ -108,6 +115,7 @@ describe('Client Library Generation: Basic Types', function () {
108
115
  assert.equal(
109
116
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
110
117
  remove_whitespace(`export type test_collection = {
118
+ "_id": string
111
119
  "test": boolean
112
120
  }`)
113
121
  )
@@ -115,6 +123,7 @@ describe('Client Library Generation: Basic Types', function () {
115
123
 
116
124
  it(`should be able to generate a plain object containing a date`, async function () {
117
125
  const validate_test_collection = z.object({
126
+ _id: z_mongodb_id,
118
127
  test: z.date(),
119
128
  });
120
129
 
@@ -128,6 +137,7 @@ describe('Client Library Generation: Basic Types', function () {
128
137
  assert.equal(
129
138
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
130
139
  remove_whitespace(`export type test_collection = {
140
+ "_id": string
131
141
  "test": Date
132
142
  }`)
133
143
  )
@@ -135,6 +145,7 @@ describe('Client Library Generation: Basic Types', function () {
135
145
 
136
146
  it(`should be able to generate a plain object containing an objectID`, async function () {
137
147
  const validate_test_collection = z.object({
148
+ _id: z_mongodb_id,
138
149
  test: z_mongodb_id,
139
150
  });
140
151
 
@@ -148,6 +159,7 @@ describe('Client Library Generation: Basic Types', function () {
148
159
  assert.equal(
149
160
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
150
161
  remove_whitespace(`export type test_collection = {
162
+ "_id": string
151
163
  "test": string
152
164
  }`)
153
165
  )
@@ -155,6 +167,7 @@ describe('Client Library Generation: Basic Types', function () {
155
167
 
156
168
  it(`should be able to generate a plain object containing a nullable string`, async function () {
157
169
  const validate_test_collection = z.object({
170
+ _id: z_mongodb_id,
158
171
  test: z.nullable(z.string()),
159
172
  });
160
173
 
@@ -168,6 +181,7 @@ describe('Client Library Generation: Basic Types', function () {
168
181
  assert.equal(
169
182
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
170
183
  remove_whitespace(`export type test_collection = {
184
+ "_id": string
171
185
  "test": string | null
172
186
  }`)
173
187
  )
@@ -175,6 +189,7 @@ describe('Client Library Generation: Basic Types', function () {
175
189
 
176
190
  it(`should be able to generate a plain object containing union types`, async function () {
177
191
  const validate_test_collection = z.object({
192
+ _id: z_mongodb_id,
178
193
  test: z.string().or(z.number()),
179
194
  });
180
195
 
@@ -188,6 +203,7 @@ describe('Client Library Generation: Basic Types', function () {
188
203
  assert.equal(
189
204
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
190
205
  remove_whitespace(`export type test_collection = {
206
+ "_id": string
191
207
  "test": string | number
192
208
  }`)
193
209
  )
@@ -195,6 +211,7 @@ describe('Client Library Generation: Basic Types', function () {
195
211
 
196
212
  it(`should be able to generate a plain object containing union types wrapped in nullable`, async function () {
197
213
  const validate_test_collection = z.object({
214
+ _id: z_mongodb_id,
198
215
  test: z.nullable(z.string().or(z.number())),
199
216
  });
200
217
 
@@ -208,6 +225,7 @@ describe('Client Library Generation: Basic Types', function () {
208
225
  assert.equal(
209
226
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
210
227
  remove_whitespace(`export type test_collection = {
228
+ "_id": string
211
229
  "test": string | number | null
212
230
  }`)
213
231
  )
@@ -215,6 +233,7 @@ describe('Client Library Generation: Basic Types', function () {
215
233
 
216
234
  it(`should be able to generate a plain object containing union of object types`, async function () {
217
235
  const validate_test_collection = z.object({
236
+ _id: z_mongodb_id,
218
237
  test: z.object({
219
238
  sub: z.string()
220
239
  }).or(z.object({
@@ -232,6 +251,7 @@ describe('Client Library Generation: Basic Types', function () {
232
251
  assert.equal(
233
252
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
234
253
  remove_whitespace(`export type test_collection = {
254
+ "_id": string
235
255
  "test": {"sub": string} | {"sub2": number}
236
256
  }`)
237
257
  )
@@ -239,6 +259,7 @@ describe('Client Library Generation: Basic Types', function () {
239
259
 
240
260
  it(`should be able to generate an enum`, async function () {
241
261
  const validate_test_collection = z.object({
262
+ _id: z_mongodb_id,
242
263
  test: z.enum(["red", "green", "blue"]),
243
264
  });
244
265
 
@@ -252,6 +273,7 @@ describe('Client Library Generation: Basic Types', function () {
252
273
  assert.equal(
253
274
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
254
275
  remove_whitespace(`export type test_collection = {
276
+ "_id": string
255
277
  "test": ("red" | "green" | "blue")
256
278
  }`)
257
279
  )
@@ -259,6 +281,7 @@ describe('Client Library Generation: Basic Types', function () {
259
281
 
260
282
  it(`should be able to generate an array of enum`, async function () {
261
283
  const validate_test_collection = z.object({
284
+ _id: z_mongodb_id,
262
285
  test: z.array(z.enum(["red", "green", "blue"])),
263
286
  });
264
287
 
@@ -272,6 +295,7 @@ describe('Client Library Generation: Basic Types', function () {
272
295
  assert.equal(
273
296
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
274
297
  remove_whitespace(`export type test_collection = {
298
+ "_id": string
275
299
  "test": ("red" | "green" | "blue")[]
276
300
  }`)
277
301
  )
@@ -279,6 +303,7 @@ describe('Client Library Generation: Basic Types', function () {
279
303
 
280
304
  it(`should be able to generate a plain nested object`, async function () {
281
305
  const validate_test_collection = z.object({
306
+ _id: z_mongodb_id,
282
307
  test: z.object({
283
308
  }),
284
309
  });
@@ -293,6 +318,7 @@ describe('Client Library Generation: Basic Types', function () {
293
318
  assert.equal(
294
319
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
295
320
  remove_whitespace(`export type test_collection = {
321
+ "_id": string
296
322
  "test": {}
297
323
  }`)
298
324
  )
@@ -300,6 +326,7 @@ describe('Client Library Generation: Basic Types', function () {
300
326
 
301
327
  it(`should be able to generate a plain nested with basic fields`, async function () {
302
328
  const validate_test_collection = z.object({
329
+ _id: z_mongodb_id,
303
330
  test: z.object({
304
331
  field_string: z.string(),
305
332
  field_number: z.number(),
@@ -321,6 +348,7 @@ describe('Client Library Generation: Basic Types', function () {
321
348
  assert.equal(
322
349
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
323
350
  remove_whitespace(`export type test_collection = {
351
+ "_id": string
324
352
  "test": {
325
353
  "field_string": string
326
354
  "field_number": number
@@ -336,6 +364,7 @@ describe('Client Library Generation: Basic Types', function () {
336
364
 
337
365
  it(`should be able to generate arrays of primitive fields`, async function () {
338
366
  const validate_test_collection = z.object({
367
+ _id: z_mongodb_id,
339
368
  field_string: z.array(z.string()),
340
369
  field_number: z.array(z.number()),
341
370
  field_boolean: z.array(z.boolean()),
@@ -352,6 +381,7 @@ describe('Client Library Generation: Basic Types', function () {
352
381
  assert.equal(
353
382
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
354
383
  remove_whitespace(`export type test_collection = {
384
+ "_id": string
355
385
  "field_string": string[]
356
386
  "field_number": number[]
357
387
  "field_boolean": boolean[]
@@ -362,6 +392,7 @@ describe('Client Library Generation: Basic Types', function () {
362
392
 
363
393
  it(`should be able to generate arrays of objects containing primitive fields`, async function () {
364
394
  const validate_test_collection = z.object({
395
+ _id: z_mongodb_id,
365
396
  field_array: z.array(z.object({
366
397
  field_string: z.array(z.string()),
367
398
  field_number: z.array(z.number()),
@@ -381,6 +412,7 @@ describe('Client Library Generation: Basic Types', function () {
381
412
  assert.equal(
382
413
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
383
414
  remove_whitespace(`export type test_collection = {
415
+ "_id": string
384
416
  "field_array": {
385
417
  "field_string": string[]
386
418
  "field_number": number[]
@@ -393,6 +425,7 @@ describe('Client Library Generation: Basic Types', function () {
393
425
 
394
426
  it(`should be able to generate nested arrays`, async function () {
395
427
  const validate_test_collection = z.object({
428
+ _id: z_mongodb_id,
396
429
  field_array: z.array(
397
430
  z.array(z.object({
398
431
  field_string: z.array(z.string()),
@@ -413,6 +446,7 @@ describe('Client Library Generation: Basic Types', function () {
413
446
  assert.equal(
414
447
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
415
448
  remove_whitespace(`export type test_collection = {
449
+ "_id": string
416
450
  "field_array": {
417
451
  "field_string": string[]
418
452
  "field_number": number[]
@@ -425,6 +459,7 @@ describe('Client Library Generation: Basic Types', function () {
425
459
 
426
460
  it(`should be able to generate a plain object containing a primitive with a default`, async function () {
427
461
  const validate_test_collection = z.object({
462
+ _id: z_mongodb_id,
428
463
  test: z.string().default('ezikiel snograss'),
429
464
  });
430
465
 
@@ -438,6 +473,7 @@ describe('Client Library Generation: Basic Types', function () {
438
473
  assert.equal(
439
474
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
440
475
  remove_whitespace(`export type test_collection = {
476
+ "_id": string
441
477
  "test"?: string
442
478
  }`)
443
479
  )
@@ -445,6 +481,7 @@ describe('Client Library Generation: Basic Types', function () {
445
481
 
446
482
  it(`should be able to generate a plain object containing an optional primitive`, async function () {
447
483
  const validate_test_collection = z.object({
484
+ _id: z_mongodb_id,
448
485
  test: z.string().optional(),
449
486
  });
450
487
 
@@ -458,6 +495,7 @@ describe('Client Library Generation: Basic Types', function () {
458
495
  assert.equal(
459
496
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
460
497
  remove_whitespace(`export type test_collection = {
498
+ "_id": string
461
499
  "test"?: string
462
500
  }`)
463
501
  )
@@ -465,6 +503,7 @@ describe('Client Library Generation: Basic Types', function () {
465
503
 
466
504
  it(`should be able to generate a plain object containing a record`, async function () {
467
505
  const validate_test_collection = z.object({
506
+ _id: z_mongodb_id,
468
507
  test: z.record(z.string(), z.string())
469
508
  });
470
509
 
@@ -478,6 +517,7 @@ describe('Client Library Generation: Basic Types', function () {
478
517
  assert.equal(
479
518
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
480
519
  remove_whitespace(`export type test_collection = {
520
+ "_id": string
481
521
  "test": {[key: string]: string}
482
522
  }`)
483
523
  )
@@ -486,6 +526,7 @@ describe('Client Library Generation: Basic Types', function () {
486
526
 
487
527
  it(`should be able to generate a plain object containing an object record`, async function () {
488
528
  const validate_test_collection = z.object({
529
+ _id: z_mongodb_id,
489
530
  test: z.record(z.string(), z.object({
490
531
  test_2: z.string()
491
532
  }))
@@ -501,6 +542,7 @@ describe('Client Library Generation: Basic Types', function () {
501
542
  assert.equal(
502
543
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
503
544
  remove_whitespace(`export type test_collection = {
545
+ "_id": string
504
546
  "test": {[key: string]: { "test_2": string }}
505
547
  }`)
506
548
  )
@@ -508,6 +550,7 @@ describe('Client Library Generation: Basic Types', function () {
508
550
 
509
551
  it(`should be able to generate a plain object containing an array record`, async function () {
510
552
  const validate_test_collection = z.object({
553
+ _id: z_mongodb_id,
511
554
  test: z.record(z.string(), z.array(z.string()))
512
555
  });
513
556
 
@@ -521,6 +564,7 @@ describe('Client Library Generation: Basic Types', function () {
521
564
  assert.equal(
522
565
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
523
566
  remove_whitespace(`export type test_collection = {
567
+ "_id": string
524
568
  "test": {[key: string]: string[]}
525
569
  }`)
526
570
  )
@@ -535,6 +579,7 @@ describe('Client Library Generation: Basic Types', function () {
535
579
  }).meta({id: 'test_recursive_object'})
536
580
 
537
581
  const validate_test_collection = z.object({
582
+ _id: z_mongodb_id,
538
583
  test: recursive
539
584
  });
540
585
 
@@ -548,6 +593,7 @@ describe('Client Library Generation: Basic Types', function () {
548
593
  assert.equal(
549
594
  remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
550
595
  remove_whitespace(`export type test_collection = {
596
+ "_id": string
551
597
  "test": type_test_recursive_object
552
598
  }
553
599
  type type_test_recursive_object = {