@liminalfunctions/framework 1.0.10 → 1.0.12

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 (101) hide show
  1. package/dist/code_generation/utils/type_from_zod.js +2 -0
  2. package/dist/code_generation/utils/type_from_zod.js.map +1 -1
  3. package/dist/utils/mongoose_from_zod.js +16 -16
  4. package/dist/utils/mongoose_from_zod.js.map +1 -1
  5. package/package.json +1 -1
  6. package/src/code_generation/utils/type_from_zod.ts +2 -3
  7. package/src/utils/mongoose_from_zod.ts +16 -16
  8. package/test/0_0_mongoose_from_zod.test.ts +30 -30
  9. package/test/2_0_client_library_basic_type_generation.test.ts +20 -0
  10. package/test/tmp/src/index.ts +1 -4
  11. package/test/tmp/src/types/test_collection.ts +3 -0
  12. package/test/tmp/src/types/test_collection_post.ts +3 -0
  13. package/test/tmp/src/types/test_collection_put.ts +3 -0
  14. package/test/tmp/src/types/test_collection_query.ts +6 -0
  15. package/test/tmp/dist/Brief_News_Category.d.ts +0 -16
  16. package/test/tmp/dist/Brief_News_Category.js +0 -85
  17. package/test/tmp/dist/Brief_News_Category.js.map +0 -1
  18. package/test/tmp/dist/Client.d.ts +0 -19
  19. package/test/tmp/dist/Client.js +0 -97
  20. package/test/tmp/dist/Client.js.map +0 -1
  21. package/test/tmp/dist/Institution.d.ts +0 -18
  22. package/test/tmp/dist/Institution.js +0 -94
  23. package/test/tmp/dist/Institution.js.map +0 -1
  24. package/test/tmp/dist/Project.d.ts +0 -16
  25. package/test/tmp/dist/Project.js +0 -85
  26. package/test/tmp/dist/Project.js.map +0 -1
  27. package/test/tmp/dist/index.d.ts +0 -4
  28. package/test/tmp/dist/index.js +0 -14
  29. package/test/tmp/dist/index.js.map +0 -1
  30. package/test/tmp/dist/types/brief_news_category.d.ts +0 -7
  31. package/test/tmp/dist/types/brief_news_category.js +0 -2
  32. package/test/tmp/dist/types/brief_news_category.js.map +0 -1
  33. package/test/tmp/dist/types/brief_news_category_post.d.ts +0 -7
  34. package/test/tmp/dist/types/brief_news_category_post.js +0 -2
  35. package/test/tmp/dist/types/brief_news_category_post.js.map +0 -1
  36. package/test/tmp/dist/types/brief_news_category_put.d.ts +0 -7
  37. package/test/tmp/dist/types/brief_news_category_put.js +0 -2
  38. package/test/tmp/dist/types/brief_news_category_put.js.map +0 -1
  39. package/test/tmp/dist/types/brief_news_category_query.d.ts +0 -26
  40. package/test/tmp/dist/types/brief_news_category_query.js +0 -2
  41. package/test/tmp/dist/types/brief_news_category_query.js.map +0 -1
  42. package/test/tmp/dist/types/client.d.ts +0 -5
  43. package/test/tmp/dist/types/client.js +0 -2
  44. package/test/tmp/dist/types/client.js.map +0 -1
  45. package/test/tmp/dist/types/client_post.d.ts +0 -5
  46. package/test/tmp/dist/types/client_post.js +0 -2
  47. package/test/tmp/dist/types/client_post.js.map +0 -1
  48. package/test/tmp/dist/types/client_put.d.ts +0 -5
  49. package/test/tmp/dist/types/client_put.js +0 -2
  50. package/test/tmp/dist/types/client_put.js.map +0 -1
  51. package/test/tmp/dist/types/client_query.d.ts +0 -18
  52. package/test/tmp/dist/types/client_query.js +0 -2
  53. package/test/tmp/dist/types/client_query.js.map +0 -1
  54. package/test/tmp/dist/types/institution.d.ts +0 -4
  55. package/test/tmp/dist/types/institution.js +0 -2
  56. package/test/tmp/dist/types/institution.js.map +0 -1
  57. package/test/tmp/dist/types/institution_post.d.ts +0 -4
  58. package/test/tmp/dist/types/institution_post.js +0 -2
  59. package/test/tmp/dist/types/institution_post.js.map +0 -1
  60. package/test/tmp/dist/types/institution_put.d.ts +0 -4
  61. package/test/tmp/dist/types/institution_put.js +0 -2
  62. package/test/tmp/dist/types/institution_put.js.map +0 -1
  63. package/test/tmp/dist/types/institution_query.d.ts +0 -14
  64. package/test/tmp/dist/types/institution_query.js +0 -2
  65. package/test/tmp/dist/types/institution_query.js.map +0 -1
  66. package/test/tmp/dist/types/project.d.ts +0 -7
  67. package/test/tmp/dist/types/project.js +0 -2
  68. package/test/tmp/dist/types/project.js.map +0 -1
  69. package/test/tmp/dist/types/project_post.d.ts +0 -7
  70. package/test/tmp/dist/types/project_post.js +0 -2
  71. package/test/tmp/dist/types/project_post.js.map +0 -1
  72. package/test/tmp/dist/types/project_put.d.ts +0 -7
  73. package/test/tmp/dist/types/project_put.js +0 -2
  74. package/test/tmp/dist/types/project_put.js.map +0 -1
  75. package/test/tmp/dist/types/project_query.d.ts +0 -27
  76. package/test/tmp/dist/types/project_query.js +0 -2
  77. package/test/tmp/dist/types/project_query.js.map +0 -1
  78. package/test/tmp/dist/utils/utils.d.ts +0 -11
  79. package/test/tmp/dist/utils/utils.js +0 -13
  80. package/test/tmp/dist/utils/utils.js.map +0 -1
  81. package/test/tmp/package-lock.json +0 -573
  82. package/test/tmp/src/Brief_News_Category.ts +0 -94
  83. package/test/tmp/src/Client.ts +0 -106
  84. package/test/tmp/src/Institution.ts +0 -103
  85. package/test/tmp/src/Project.ts +0 -94
  86. package/test/tmp/src/types/brief_news_category.ts +0 -7
  87. package/test/tmp/src/types/brief_news_category_post.ts +0 -7
  88. package/test/tmp/src/types/brief_news_category_put.ts +0 -7
  89. package/test/tmp/src/types/brief_news_category_query.ts +0 -26
  90. package/test/tmp/src/types/client.ts +0 -5
  91. package/test/tmp/src/types/client_post.ts +0 -5
  92. package/test/tmp/src/types/client_put.ts +0 -5
  93. package/test/tmp/src/types/client_query.ts +0 -18
  94. package/test/tmp/src/types/institution.ts +0 -4
  95. package/test/tmp/src/types/institution_post.ts +0 -4
  96. package/test/tmp/src/types/institution_put.ts +0 -4
  97. package/test/tmp/src/types/institution_query.ts +0 -14
  98. package/test/tmp/src/types/project.ts +0 -7
  99. package/test/tmp/src/types/project_post.ts +0 -7
  100. package/test/tmp/src/types/project_put.ts +0 -7
  101. package/test/tmp/src/types/project_query.ts +0 -27
@@ -23,6 +23,8 @@ export function type_from_zod(zod_definition, indent_level) {
23
23
  return ['null'];
24
24
  case "array":
25
25
  return parse_array(zod_definition._zod.def, indent_level);
26
+ case "nullable":
27
+ return [`${type_from_zod(zod_definition._zod.def.innerType, indent_level)} | null`];
26
28
  case "record":
27
29
  return parse_record(zod_definition._zod.def, indent_level);
28
30
  case "enum":
@@ -1 +1 @@
1
- {"version":3,"file":"type_from_zod.js","sourceRoot":"","sources":["../../../src/code_generation/utils/type_from_zod.ts"],"names":[],"mappings":"AACA,OAAiB,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAcxC,MAAM,UAAU,aAAa,CAAC,cAAyB,EAAE,YAAoB;IACzE,IAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACrB,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAChC,CAAC;IAED,QAAQ,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QACnC,KAAK,QAAQ;YACT,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtB,KAAK,QAAQ,CAAC;QACd,KAAK,KAAK;YACN,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtB,KAAK,QAAQ;YACT,OAAO,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC,GAA2B,EAAE,YAAY,CAAC,CAAC;QACvF,KAAK,SAAS;YACV,OAAO,CAAC,SAAS,CAAC,CAAC;QACvB,KAAK,MAAM;YACP,OAAO,CAAC,MAAM,CAAC,CAAC;QACpB,KAAK,WAAW;YACZ,OAAO,CAAC,WAAW,CAAC,CAAA;QACxB,KAAK,MAAM;YACP,OAAO,CAAC,MAAM,CAAC,CAAA;QACnB,KAAK,OAAO;YACR,OAAO,WAAW,CAAC,cAAc,CAAC,IAAI,CAAC,GAA0B,EAAE,YAAY,CAAC,CAAA;QAQpF,KAAK,QAAQ;YACT,OAAQ,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC,GAA2B,EAAE,YAAY,CA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Q,GAAG,KAAK,CAAC;IACjC,OAAO,eAAe,CAAC;AAC3B,CAAC;AAED,SAAS,gBAAgB,CAAC,GAAyB;IAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;AAC3C,CAAC"}
@@ -31,13 +31,13 @@ export const z_mongodb_id_optional = z.custom((val) => {
31
31
  }).meta({ framework_override_type: 'mongodb_id' });
32
32
  export function mongoose_from_zod(schema_name, zod_definition) {
33
33
  let mongoose_schema = schema_from_zod(zod_definition);
34
- return mongoose.model(schema_name, mongoose_schema);
34
+ return mongoose.model(schema_name, new Schema(mongoose_schema, { typeKey: 'mongoose_type' }));
35
35
  }
36
36
  export function schema_from_zod(zod_definition) {
37
37
  let mongoose_schema = schema_entry_from_zod(zod_definition);
38
- delete mongoose_schema.type.required;
39
- delete mongoose_schema.type._id;
40
- return mongoose_schema.type;
38
+ delete mongoose_schema.mongoose_type.required;
39
+ delete mongoose_schema.mongoose_type._id;
40
+ return mongoose_schema.mongoose_type;
41
41
  }
42
42
  export function schema_entry_from_zod(zod_definition, loop_detector = new Set()) {
43
43
  if (!zod_definition) {
@@ -84,7 +84,7 @@ export function schema_entry_from_zod(zod_definition, loop_detector = new Set())
84
84
  result.required = !zod_definition.safeParse(undefined).success;
85
85
  return result;
86
86
  case "any":
87
- result = { type: Schema.Types.Mixed, required: false };
87
+ result = { mongoose_type: Schema.Types.Mixed, required: false };
88
88
  return result;
89
89
  case "default":
90
90
  result = parse_default(zod_definition._zod.def, loop_detector);
@@ -119,27 +119,27 @@ export function schema_entry_from_zod(zod_definition, loop_detector = new Set())
119
119
  }
120
120
  function parse_object(def, loop_detector) {
121
121
  if (loop_detector.has(def)) {
122
- return { type: Schema.Types.Mixed, required: true };
122
+ return { mongoose_type: Schema.Types.Mixed, required: true };
123
123
  }
124
124
  loop_detector.add(def);
125
125
  let retval = {};
126
126
  for (let [key, value] of Object.entries(def.shape)) {
127
127
  retval[key] = schema_entry_from_zod(value, loop_detector);
128
128
  }
129
- return { type: retval, required: true };
129
+ return { mongoose_type: retval, required: true };
130
130
  }
131
131
  function parse_array(def, loop_detector) {
132
- let retval = { type: [schema_entry_from_zod(def.element, loop_detector)] };
132
+ let retval = { mongoose_type: [schema_entry_from_zod(def.element, loop_detector)] };
133
133
  retval.required = true;
134
134
  return retval;
135
135
  }
136
136
  function parse_enum(def) {
137
- let retval = { type: String };
137
+ let retval = { mongoose_type: String };
138
138
  retval.required = true;
139
139
  return retval;
140
140
  }
141
141
  function parse_union(def) {
142
- let retval = { type: Schema.Types.Mixed };
142
+ let retval = { mongoose_type: Schema.Types.Mixed };
143
143
  retval.required = true;
144
144
  return retval;
145
145
  }
@@ -147,24 +147,24 @@ function parse_record(def, loop_detector) {
147
147
  if (def.keyType._zod.def.type !== 'string') {
148
148
  throw new Error('mongoDB only supports maps where the key is a string.');
149
149
  }
150
- let retval = { type: Schema.Types.Map, of: schema_entry_from_zod(def.valueType, loop_detector), required: true };
150
+ let retval = { mongoose_type: Schema.Types.Map, of: schema_entry_from_zod(def.valueType, loop_detector), required: true };
151
151
  retval.required = true;
152
152
  return retval;
153
153
  }
154
154
  function parse_string(def) {
155
- let retval = { type: String };
155
+ let retval = { mongoose_type: String };
156
156
  return retval;
157
157
  }
158
158
  function parse_number(def) {
159
- let retval = { type: Number };
159
+ let retval = { mongoose_type: Number };
160
160
  return retval;
161
161
  }
162
162
  function parse_boolean(def) {
163
- let retval = { type: Boolean };
163
+ let retval = { mongoose_type: Boolean };
164
164
  return retval;
165
165
  }
166
166
  function parse_date(def) {
167
- let retval = { type: Date };
167
+ let retval = { mongoose_type: Date };
168
168
  return retval;
169
169
  }
170
170
  function parse_default(def, loop_detector) {
@@ -178,6 +178,6 @@ function parse_optional(def, loop_detector) {
178
178
  return type_definition;
179
179
  }
180
180
  function parse_mongodb_id(def) {
181
- return { type: Schema.Types.ObjectId };
181
+ return { mongoose_type: Schema.Types.ObjectId };
182
182
  }
183
183
  //# sourceMappingUR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;AAED,SAAS,aAAa,CAAC,GAA0B,EAAE,aAAuB;IAEtE,IAAI,eAAe,GAAG,qBAAqB,CAAC,GAAG,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IAC1E,eAAe,CAAC,OAAO,GAAG,GAAG,CAAC,YAAY,CAAC;IAC3C,OAAO,eAAe,CAAC;AAC3B,CAAC;AAED,SAAS,cAAc,CAAC,GAA2B,EAAE,aAAuB;IAExE,IAAI,eAAe,GAAG,qBAAqB,CAAC,GAAG,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IAC1E,eAAe,CAAC,QAAQ,GAAG,KAAK,CAAC;IACjC,OAAO,eAAe,CAAC;AAC3B,CAAC;AAED,SAAS,gBAAgB,CAAC,GAAyB;IAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;AACpD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liminalfunctions/framework",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "main": "./dist/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -40,11 +40,10 @@ export function type_from_zod(zod_definition: z.ZodType, indent_level: number):
40
40
  return parse_array(zod_definition._zod.def as z.core.$ZodArrayDef, indent_level)
41
41
  /*
42
42
  case "any":
43
- return ["any"]
43
+ return ["any"]*/
44
44
  case "nullable":
45
- //stuff is nullable in mongodb by default, so just return the ordinary results of the parse
46
45
  //@ts-expect-error
47
- return type_from_zod((zod_definition as z.core.$ZodNullable)._zod.def.innerType)*/
46
+ return [`${type_from_zod((zod_definition._zod.def as z.core.$ZodNullable).innerType as ZodType, indent_level)} | null`]
48
47
  case "record":
49
48
  return parse_record(zod_definition._zod.def as z.core.$ZodRecordDef, indent_level);
50
49
  case "enum":
@@ -33,14 +33,14 @@ export const z_mongodb_id_optional = z.custom<string>((val) => {
33
33
 
34
34
  export function mongoose_from_zod<T>(schema_name: string, zod_definition: z.core.$ZodType) {
35
35
  let mongoose_schema = schema_from_zod(zod_definition);
36
- return mongoose.model<T>(schema_name, mongoose_schema);
36
+ return mongoose.model<T>(schema_name, new Schema(mongoose_schema, {typeKey: 'mongoose_type'}));
37
37
  }
38
38
 
39
39
  export function schema_from_zod(zod_definition: z.core.$ZodType): any {
40
40
  let mongoose_schema = schema_entry_from_zod(zod_definition as z.ZodType);
41
- delete mongoose_schema.type.required;
42
- delete mongoose_schema.type._id;
43
- return mongoose_schema.type;
41
+ delete mongoose_schema.mongoose_type.required;
42
+ delete mongoose_schema.mongoose_type._id;
43
+ return mongoose_schema.mongoose_type;
44
44
  }
45
45
 
46
46
  export function schema_entry_from_zod(zod_definition: z.ZodType, loop_detector: Set<any> = new Set()): any {
@@ -91,7 +91,7 @@ export function schema_entry_from_zod(zod_definition: z.ZodType, loop_detector:
91
91
  result.required = !zod_definition.safeParse(undefined).success
92
92
  return result;
93
93
  case "any" :
94
- result = { type: Schema.Types.Mixed, required: false };
94
+ result = { mongoose_type: Schema.Types.Mixed, required: false };
95
95
  return result;
96
96
  case "default":
97
97
  result = parse_default(zod_definition._zod.def as z.core.$ZodDefaultDef, loop_detector);
@@ -128,7 +128,7 @@ export function schema_entry_from_zod(zod_definition: z.ZodType, loop_detector:
128
128
 
129
129
  function parse_object(def: z.core.$ZodObjectDef, loop_detector: Set<any>): any {
130
130
  if(loop_detector.has(def)) {
131
- return {type: Schema.Types.Mixed, required: true}
131
+ return {mongoose_type: Schema.Types.Mixed, required: true}
132
132
  }
133
133
  loop_detector.add(def);
134
134
 
@@ -137,24 +137,24 @@ function parse_object(def: z.core.$ZodObjectDef, loop_detector: Set<any>): any {
137
137
  //@ts-ignore
138
138
  retval[key] = schema_entry_from_zod(value, loop_detector);
139
139
  }
140
- return {type: retval, required: true};
140
+ return {mongoose_type: retval, required: true};
141
141
  }
142
142
 
143
143
  function parse_array(def: z.core.$ZodArrayDef, loop_detector: Set<any>): any {
144
144
  //@ts-ignore
145
- let retval = { type: [schema_entry_from_zod(def.element, loop_detector)] } as any;
145
+ let retval = { mongoose_type: [schema_entry_from_zod(def.element, loop_detector)] } as any;
146
146
  retval.required = true;
147
147
  return retval;
148
148
  }
149
149
 
150
150
  function parse_enum(def: z.core.$ZodEnumDef): any {
151
- let retval = { type: String } as any;
151
+ let retval = { mongoose_type: String } as any;
152
152
  retval.required = true;
153
153
  return retval;
154
154
  }
155
155
 
156
156
  function parse_union(def: z.core.$ZodUnionDef): any {
157
- let retval = { type: Schema.Types.Mixed } as any;
157
+ let retval = { mongoose_type: Schema.Types.Mixed } as any;
158
158
  retval.required = true;
159
159
  return retval;
160
160
  }
@@ -162,30 +162,30 @@ function parse_union(def: z.core.$ZodUnionDef): any {
162
162
  function parse_record(def: z.core.$ZodRecordDef, loop_detector: Set<any>): any {
163
163
  if(def.keyType._zod.def.type !== 'string') { throw new Error('mongoDB only supports maps where the key is a string.'); }
164
164
  //@ts-ignore
165
- let retval = { type: Schema.Types.Map, of: schema_entry_from_zod(def.valueType, loop_detector), required: true}
165
+ let retval = { mongoose_type: Schema.Types.Map, of: schema_entry_from_zod(def.valueType, loop_detector), required: true}
166
166
  retval.required = true;
167
167
  return retval;
168
168
  }
169
169
 
170
170
  function parse_string(def: z.core.$ZodStringDef): any {
171
- let retval = { type: String } as any;
171
+ let retval = { mongoose_type: String } as any;
172
172
  // for fixing the optional issue
173
173
  // https://github.com/colinhacks/zod/issues/4824
174
174
  return retval;
175
175
  }
176
176
 
177
177
  function parse_number(def: z.core.$ZodNumberDef): any {
178
- let retval = { type: Number } as any;
178
+ let retval = { mongoose_type: Number } as any;
179
179
  return retval;
180
180
  }
181
181
 
182
182
  function parse_boolean(def: z.core.$ZodBooleanDef): any {
183
- let retval = { type: Boolean } as any;
183
+ let retval = { mongoose_type: Boolean } as any;
184
184
  return retval;
185
185
  }
186
186
 
187
187
  function parse_date(def: z.core.$ZodDateDef): any {
188
- let retval = { type: Date } as any;
188
+ let retval = { mongoose_type: Date } as any;
189
189
  return retval;
190
190
  }
191
191
 
@@ -204,5 +204,5 @@ function parse_optional(def: z.core.$ZodOptionalDef, loop_detector: Set<any>): a
204
204
  }
205
205
 
206
206
  function parse_mongodb_id(def: z.core.$ZodCustomDef): any {
207
- return { type: Schema.Types.ObjectId };
207
+ return { mongoose_type: Schema.Types.ObjectId };
208
208
  }
@@ -50,33 +50,33 @@ describe('Mongoose from Zod', function () {
50
50
  it(`should convert ${basic_type.label} to mongoose type`, function () {
51
51
  let zodSchema = z.object({ test_value: basic_type.zod_function() })
52
52
  let mongooseSchema = schema_from_zod(zodSchema)
53
- assert.deepEqual({ test_value: { type: basic_type.mongoose_type, required: true } }, mongooseSchema)
53
+ assert.deepEqual({ test_value: { mongoose_type: basic_type.mongoose_type, required: true } }, mongooseSchema)
54
54
  });
55
55
 
56
56
  it(`should convert ${basic_type.label} to mongoose type with optional`, function () {
57
57
  let zodSchema = z.object({ test_value: basic_type.zod_function().optional() })
58
58
  let mongooseSchema = schema_from_zod(zodSchema)
59
- assert.deepEqual({ test_value: { type: basic_type.mongoose_type, required: false } }, mongooseSchema)
59
+ assert.deepEqual({ test_value: { mongoose_type: basic_type.mongoose_type, required: false } }, mongooseSchema)
60
60
  });
61
61
 
62
62
  it(`should convert ${basic_type.label} to mongoose type with default values`, function () {
63
63
  //@ts-ignore
64
64
  let zodSchema = z.object({ test_value: basic_type.zod_function().default(basic_type.default_val) })
65
65
  let mongooseSchema = schema_from_zod(zodSchema)
66
- assert.deepEqual({ test_value: { type: basic_type.mongoose_type, required: true, default: basic_type.default_val } }, mongooseSchema)
66
+ assert.deepEqual({ test_value: { mongoose_type: basic_type.mongoose_type, required: true, default: basic_type.default_val } }, mongooseSchema)
67
67
  });
68
68
 
69
69
  it(`should convert ${basic_type.label} to mongoose type with nullable`, function () {
70
70
  let zodSchema = z.object({ test_value: basic_type.zod_function().nullable() })
71
71
  let mongooseSchema = schema_from_zod(zodSchema)
72
- assert.deepEqual({ test_value: { type: basic_type.mongoose_type, required: true } }, mongooseSchema)
72
+ assert.deepEqual({ test_value: { mongoose_type: basic_type.mongoose_type, required: true } }, mongooseSchema)
73
73
  });
74
74
 
75
75
  it(`should convert ${basic_type.label} to mongoose type with optional AND default values`, function () {
76
76
  //@ts-ignore
77
77
  let zodSchema = z.object({ test_value: basic_type.zod_function().default(basic_type.default_val).optional() })
78
78
  let mongooseSchema = schema_from_zod(zodSchema)
79
- assert.deepEqual({ test_value: { type: basic_type.mongoose_type, required: false, default: basic_type.default_val } }, mongooseSchema)
79
+ assert.deepEqual({ test_value: { mongoose_type: basic_type.mongoose_type, required: false, default: basic_type.default_val } }, mongooseSchema)
80
80
  });
81
81
  }
82
82
 
@@ -87,20 +87,20 @@ describe('Mongoose from Zod', function () {
87
87
  it(`should convert a nested object containing a ${basic_type.label} property to mongoose type`, function () {
88
88
  let zodSchema = z.object({ test_value: z.object({test_value: basic_type.zod_function() }) })
89
89
  let mongooseSchema = schema_from_zod(zodSchema)
90
- assert.deepEqual({ test_value: { type: {test_value: { type: basic_type.mongoose_type, required: true }}, required: true} }, mongooseSchema)
90
+ assert.deepEqual({ test_value: { mongoose_type: {test_value: { mongoose_type: basic_type.mongoose_type, required: true }}, required: true} }, mongooseSchema)
91
91
  });
92
92
 
93
93
  it(`should convert a nested object containing a ${basic_type.label} property to mongoose type with optional`, function () {
94
94
  let zodSchema = z.object({ test_value: z.object({test_value: basic_type.zod_function().optional() }) })
95
95
  let mongooseSchema = schema_from_zod(zodSchema)
96
- assert.deepEqual({ test_value: { type: {test_value: { type: basic_type.mongoose_type, required: false }}, required: true } }, mongooseSchema)
96
+ assert.deepEqual({ test_value: { mongoose_type: {test_value: { mongoose_type: basic_type.mongoose_type, required: false }}, required: true } }, mongooseSchema)
97
97
  });
98
98
 
99
99
  it(`should convert a nested object containing a ${basic_type.label} property to mongoose type with default values`, function () {
100
100
  //@ts-ignore
101
101
  let zodSchema = z.object({ test_value: z.object({test_value: basic_type.zod_function().default(basic_type.default_val) }) })
102
102
  let mongooseSchema = schema_from_zod(zodSchema)
103
- assert.deepEqual({ test_value: { type: {test_value: { type: basic_type.mongoose_type, required: true, default: basic_type.default_val }}, required: true } }, mongooseSchema)
103
+ assert.deepEqual({ test_value: { mongoose_type: {test_value: { mongoose_type: basic_type.mongoose_type, required: true, default: basic_type.default_val }}, required: true } }, mongooseSchema)
104
104
  });
105
105
  }
106
106
 
@@ -111,19 +111,19 @@ describe('Mongoose from Zod', function () {
111
111
  it(`should convert ${basic_type.label} array to mongoose type`, function () {
112
112
  let zodSchema = z.object({ test_value: z.array(basic_type.zod_function()) })
113
113
  let mongooseSchema = schema_from_zod(zodSchema)
114
- assert.deepEqual({ test_value: {type: [{ type: basic_type.mongoose_type, required: true }], required: true} }, mongooseSchema)
114
+ assert.deepEqual({ test_value: {mongoose_type: [{ mongoose_type: basic_type.mongoose_type, required: true }], required: true} }, mongooseSchema)
115
115
  });
116
116
 
117
117
  it(`should convert ${basic_type.label} array to mongoose type with optional`, function () {
118
118
  let zodSchema = z.object({ test_value: z.array(basic_type.zod_function()).optional() })
119
119
  let mongooseSchema = schema_from_zod(zodSchema)
120
- assert.deepEqual({ test_value: {type: [{ type: basic_type.mongoose_type, required: true }], required: false} }, mongooseSchema)
120
+ assert.deepEqual({ test_value: {mongoose_type: [{ mongoose_type: basic_type.mongoose_type, required: true }], required: false} }, mongooseSchema)
121
121
  });
122
122
 
123
123
  it(`should convert ${basic_type.label} array to mongoose type with default values`, function () {
124
124
  let zodSchema = z.object({ test_value: z.array(basic_type.zod_function()).default([]) })
125
125
  let mongooseSchema = schema_from_zod(zodSchema)
126
- assert.deepEqual({ test_value: {type: [{ type: basic_type.mongoose_type, required: true }], required: true, default: []} }, mongooseSchema)
126
+ assert.deepEqual({ test_value: {mongoose_type: [{ mongoose_type: basic_type.mongoose_type, required: true }], required: true, default: []} }, mongooseSchema)
127
127
  });
128
128
  }
129
129
 
@@ -134,19 +134,19 @@ describe('Mongoose from Zod', function () {
134
134
  it(`should convert ${basic_type.label} array to mongoose type`, function () {
135
135
  let zodSchema = z.object({ test_value: z.array(basic_type.zod_function()) })
136
136
  let mongooseSchema = schema_from_zod(zodSchema)
137
- assert.deepEqual({ test_value: {type: [{ type: basic_type.mongoose_type, required: true }], required: true} }, mongooseSchema)
137
+ assert.deepEqual({ test_value: {mongoose_type: [{ mongoose_type: basic_type.mongoose_type, required: true }], required: true} }, mongooseSchema)
138
138
  });
139
139
 
140
140
  it(`should convert ${basic_type.label} array to mongoose type with optional`, function () {
141
141
  let zodSchema = z.object({ test_value: z.array(basic_type.zod_function()).optional() })
142
142
  let mongooseSchema = schema_from_zod(zodSchema)
143
- assert.deepEqual({ test_value: {type: [{ type: basic_type.mongoose_type, required: true }], required: false} }, mongooseSchema)
143
+ assert.deepEqual({ test_value: {mongoose_type: [{ mongoose_type: basic_type.mongoose_type, required: true }], required: false} }, mongooseSchema)
144
144
  });
145
145
 
146
146
  it(`should convert ${basic_type.label} array to mongoose type with default values`, function () {
147
147
  let zodSchema = z.object({ test_value: z.array(basic_type.zod_function()).default([]) })
148
148
  let mongooseSchema = schema_from_zod(zodSchema)
149
- assert.deepEqual({ test_value: {type: [{ type: basic_type.mongoose_type, required: true }], required: true, default: []} }, mongooseSchema)
149
+ assert.deepEqual({ test_value: {mongoose_type: [{ mongoose_type: basic_type.mongoose_type, required: true }], required: true, default: []} }, mongooseSchema)
150
150
  });
151
151
  }
152
152
 
@@ -157,20 +157,20 @@ describe('Mongoose from Zod', function () {
157
157
  it(`should convert record of ${basic_type.label} to mongoose type`, function () {
158
158
  let zodSchema = z.object({ test_value: z.record(z.string(), basic_type.zod_function()) })
159
159
  let mongooseSchema = schema_from_zod(zodSchema)
160
- assert.deepEqual({ test_value: {type: Schema.Types.Map, of: { type: basic_type.mongoose_type, required: true }, required: true} }, mongooseSchema)
160
+ assert.deepEqual({ test_value: {mongoose_type: Schema.Types.Map, of: { mongoose_type: basic_type.mongoose_type, required: true }, required: true} }, mongooseSchema)
161
161
  });
162
162
 
163
163
  it(`should convert record of ${basic_type.label} to mongoose type with optional`, function () {
164
164
  let zodSchema = z.object({ test_value: z.record(z.string(), basic_type.zod_function()).optional() })
165
165
  let mongooseSchema = schema_from_zod(zodSchema)
166
- assert.deepEqual({ test_value: {type: Schema.Types.Map, of: { type: basic_type.mongoose_type, required: true }, required: false} }, mongooseSchema)
166
+ assert.deepEqual({ test_value: {mongoose_type: Schema.Types.Map, of: { mongoose_type: basic_type.mongoose_type, required: true }, required: false} }, mongooseSchema)
167
167
  });
168
168
 
169
169
  it(`should convert record of ${basic_type.label} to mongoose type with default values`, function () {
170
170
  //@ts-ignore
171
171
  let zodSchema = z.object({ test_value: z.record(z.string(), basic_type.zod_function()).default({}) })
172
172
  let mongooseSchema = schema_from_zod(zodSchema)
173
- assert.deepEqual({ test_value: {type: Schema.Types.Map, of: { type: basic_type.mongoose_type, required: true }, required: true, default: {}} }, mongooseSchema)
173
+ assert.deepEqual({ test_value: {mongoose_type: Schema.Types.Map, of: { mongoose_type: basic_type.mongoose_type, required: true }, required: true, default: {}} }, mongooseSchema)
174
174
  });
175
175
  }
176
176
 
@@ -181,19 +181,19 @@ describe('Mongoose from Zod', function () {
181
181
  it(`should convert enums to mongoose type`, function () {
182
182
  let zodSchema = z.object({ test_value: z.enum(['chunky', 'funky', 'monkey']) })
183
183
  let mongooseSchema = schema_from_zod(zodSchema)
184
- assert.deepEqual({ test_value: {type: String, required: true} }, mongooseSchema)
184
+ assert.deepEqual({ test_value: {mongoose_type: String, required: true} }, mongooseSchema)
185
185
  });
186
186
 
187
187
  it(`should convert enums to mongoose type with optional`, function () {
188
188
  let zodSchema = z.object({ test_value: z.enum(['chunky', 'funky', 'monkey']).optional() })
189
189
  let mongooseSchema = schema_from_zod(zodSchema)
190
- assert.deepEqual({ test_value: {type: String, required: false} }, mongooseSchema)
190
+ assert.deepEqual({ test_value: {mongoose_type: String, required: false} }, mongooseSchema)
191
191
  });
192
192
 
193
193
  it(`should convert enums to mongoose type with default values`, function () {
194
194
  let zodSchema = z.object({ test_value: z.enum(['chunky', 'funky', 'monkey']).default('chunky') })
195
195
  let mongooseSchema = schema_from_zod(zodSchema)
196
- assert.deepEqual({ test_value: {type: String, required: true, default: 'chunky'} }, mongooseSchema)
196
+ assert.deepEqual({ test_value: {mongoose_type: String, required: true, default: 'chunky'} }, mongooseSchema)
197
197
  });
198
198
 
199
199
  it(`should convert union types to a mixed schema`, function () {
@@ -201,7 +201,7 @@ describe('Mongoose from Zod', function () {
201
201
  test_value: z.number().or(z.string())
202
202
  })
203
203
  let mongooseSchema = schema_from_zod(zodSchema)
204
- assert.deepEqual({ test_value: {type: Schema.Types.Mixed, required: true} }, mongooseSchema)
204
+ assert.deepEqual({ test_value: {mongoose_type: Schema.Types.Mixed, required: true} }, mongooseSchema)
205
205
  });
206
206
 
207
207
  it(`should convert union types to a mixed schema with default values`, function () {
@@ -209,7 +209,7 @@ describe('Mongoose from Zod', function () {
209
209
  test_value: z.number().or(z.string()).default(2)
210
210
  })
211
211
  let mongooseSchema = schema_from_zod(zodSchema)
212
- assert.deepEqual({ test_value: {type: Schema.Types.Mixed, required: true, default: 2} }, mongooseSchema)
212
+ assert.deepEqual({ test_value: {mongoose_type: Schema.Types.Mixed, required: true, default: 2} }, mongooseSchema)
213
213
  });
214
214
 
215
215
  it(`should convert union types to a mixed schema with optional`, function () {
@@ -217,7 +217,7 @@ describe('Mongoose from Zod', function () {
217
217
  test_value: z.number().or(z.string()).optional()
218
218
  })
219
219
  let mongooseSchema = schema_from_zod(zodSchema)
220
- assert.deepEqual({ test_value: {type: Schema.Types.Mixed, required: false} }, mongooseSchema)
220
+ assert.deepEqual({ test_value: {mongoose_type: Schema.Types.Mixed, required: false} }, mongooseSchema)
221
221
  });
222
222
 
223
223
  it(`should convert recursive schemas`, function () {
@@ -232,10 +232,10 @@ describe('Mongoose from Zod', function () {
232
232
  let mongooseSchema = schema_from_zod(zodSchema)
233
233
 
234
234
  assert.deepEqual({
235
- type: {type: String, required: true },
236
- operator: {type: String, required: true },
237
- children: {type: [{ type: Schema.Types.Mixed, required: true }], required: true },
238
- locked: {type: Boolean, required: false },
235
+ type: {mongoose_type: String, required: true },
236
+ operator: {mongoose_type: String, required: true },
237
+ children: {mongoose_type: [{ mongoose_type: Schema.Types.Mixed, required: true }], required: true },
238
+ locked: {mongoose_type: Boolean, required: false },
239
239
  }, mongooseSchema)
240
240
  })
241
241
 
@@ -254,9 +254,9 @@ describe('Mongoose from Zod', function () {
254
254
  let mongooseSchema = schema_from_zod(zodSchema)
255
255
 
256
256
  assert.deepEqual({
257
- a: { type: { name: { type: String, required: true } }, required: true },
258
- b: { type: { name: { type: String, required: true } }, required: true },
259
- c: { type: { name: { type: String, required: true } }, required: true },
257
+ a: { mongoose_type: { name: { mongoose_type: String, required: true } }, required: true },
258
+ b: { mongoose_type: { name: { mongoose_type: String, required: true } }, required: true },
259
+ c: { mongoose_type: { name: { mongoose_type: String, required: true } }, required: true },
260
260
  }, mongooseSchema)
261
261
  })
262
262
  });
@@ -153,6 +153,26 @@ describe('Client Library Generation: Basic Types', function () {
153
153
  )
154
154
  });
155
155
 
156
+ it(`should be able to generate a plain object containing a nullable string`, async function () {
157
+ const validate_test_collection = z.object({
158
+ test: z.nullable(z.string()),
159
+ });
160
+
161
+ let test_collection = new F_Collection('test_collection', validate_test_collection);
162
+
163
+ let proto_registry = new F_Collection_Registry();
164
+ let registry = proto_registry.register(test_collection);
165
+
166
+ await generate_client_library('./test/tmp', registry);
167
+
168
+ assert.equal(
169
+ remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
170
+ remove_whitespace(`export type test_collection = {
171
+ "test": string | null
172
+ }`)
173
+ )
174
+ });
175
+
156
176
  it(`should be able to generate an enum`, async function () {
157
177
  const validate_test_collection = z.object({
158
178
  test: z.enum(["red", "green", "blue"]),
@@ -1,15 +1,12 @@
1
1
  import ky from 'ky';
2
2
 
3
3
 
4
- import { Collection_Institution } from "./Institution.js"
5
4
 
6
5
 
7
6
  export function api(base_url: string, get_auth: () => Promise<any>) {
8
7
  return {
9
- collection(collection_id: "institution") {
8
+ collection(collection_id: "") {
10
9
  switch(collection_id) {
11
- case "institution":
12
- return new Collection_Institution([base_url, "institution"], get_auth);
13
10
  default:
14
11
  throw new Error(`Api does not have the collection ${collection_id}`)
15
12
  }
@@ -0,0 +1,3 @@
1
+ export type test_collection = {
2
+ "test": string | null
3
+ }
@@ -0,0 +1,3 @@
1
+ export type test_collection_post = {
2
+ "test": string | null
3
+ }
@@ -0,0 +1,3 @@
1
+ export type test_collection_put = {
2
+ "test"?: string | null
3
+ }
@@ -0,0 +1,6 @@
1
+ export type test_collection_query = {
2
+ "limit"?: number
3
+ "cursor"?: string
4
+ "sort_order"?: ("ascending" | "descending")
5
+ "sort"?: ("")
6
+ }
@@ -1,16 +0,0 @@
1
- import { brief_news_category } from "./types/brief_news_category.js";
2
- import { brief_news_category_query } from "./types/brief_news_category_query.js";
3
- import { brief_news_category_put } from "./types/brief_news_category_put.js";
4
- import { brief_news_category_post } from "./types/brief_news_category_post.js";
5
- export declare class Collection_Brief_News_Category {
6
- path: string[];
7
- get_auth: () => Promise<any>;
8
- constructor(path: string[], get_auth: () => Promise<any>);
9
- query(query: brief_news_category_query): Promise<brief_news_category[]>;
10
- post(document: brief_news_category_post): Promise<brief_news_category>;
11
- document(document_id: string): {
12
- get(): Promise<brief_news_category>;
13
- put(update: brief_news_category_put): Promise<brief_news_category>;
14
- remove(): Promise<brief_news_category>;
15
- };
16
- }