@drax/crud-back 0.51.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,8 @@
1
1
  import z from 'zod';
2
- import { zodToJsonSchema } from 'zod-to-json-schema';
3
2
  import { IdParamSchema, DeleteBodyResponseSchema, PaginateQuerySchema, PaginateBodyResponseSchema, FindQuerySchema, SearchQuerySchema, FindByParamSchema, ErrorBodyResponseSchema, ValidationErrorBodyResponseSchema, ExportBodyResponseSchema, GroupByQuerySchema } from '../index.js';
4
3
  export class CrudSchemaBuilder {
5
- constructor(entitySchema, entityCreateSchema, entityUpdateSchema, entityName, target = 'openApi3', tags = []) {
6
- this.target = 'openApi3'; //"jsonSchema7" | "jsonSchema2019-09" | "openApi3" | "openAi"
4
+ constructor(entitySchema, entityCreateSchema, entityUpdateSchema, entityName, target = 'openapi-3.0', tags = []) {
5
+ this.target = 'openapi-3.0'; //"jsonSchema7" | "jsonSchema2019-09" | "openapi-3.0" | "openAi"
7
6
  this.entitySchema = entitySchema;
8
7
  this.entityCreateSchema = entityCreateSchema;
9
8
  this.entityUpdateSchema = entityUpdateSchema;
@@ -18,56 +17,56 @@ export class CrudSchemaBuilder {
18
17
  return [];
19
18
  }
20
19
  get jsonEntityCreateSchema() {
21
- return zodToJsonSchema(this.entityCreateSchema, { target: this.target });
20
+ return z.toJSONSchema(this.entityCreateSchema, { target: this.target });
22
21
  }
23
22
  get jsonEntityUpdateSchema() {
24
- return zodToJsonSchema(this.entityUpdateSchema, { target: this.target });
23
+ return z.toJSONSchema(this.entityUpdateSchema, { target: this.target });
25
24
  }
26
25
  get jsonEntitySchema() {
27
- return zodToJsonSchema(this.entitySchema, { target: this.target });
26
+ return z.toJSONSchema(this.entitySchema, { target: this.target });
28
27
  }
29
28
  get jsonEntityArraySchema() {
30
- return zodToJsonSchema(z.array(this.entitySchema), { target: this.target });
29
+ return z.toJSONSchema(z.array(this.entitySchema), { target: this.target });
31
30
  }
32
31
  get jsonEntityGroupBySchema() {
33
- return zodToJsonSchema(z.array(z.object({
32
+ return z.toJSONSchema(z.array(z.object({
34
33
  count: z.number()
35
34
  }).catchall(z.any())), { target: this.target });
36
35
  }
37
36
  get jsonExportBodyResponse() {
38
- return zodToJsonSchema(ExportBodyResponseSchema, { target: this.target });
37
+ return z.toJSONSchema(ExportBodyResponseSchema, { target: this.target });
39
38
  }
40
39
  get jsonErrorBodyResponse() {
41
- return zodToJsonSchema(ErrorBodyResponseSchema, { target: this.target });
40
+ return z.toJSONSchema(ErrorBodyResponseSchema, { target: this.target });
42
41
  }
43
42
  get jsonValidationErrorBodyResponse() {
44
- return zodToJsonSchema(ValidationErrorBodyResponseSchema, { target: this.target });
43
+ return z.toJSONSchema(ValidationErrorBodyResponseSchema, { target: this.target });
45
44
  }
46
45
  get jsonFindQuerySchema() {
47
- return zodToJsonSchema(FindQuerySchema, { target: this.target });
46
+ return z.toJSONSchema(FindQuerySchema, { target: this.target });
48
47
  }
49
48
  get jsonGroupByQuerySchema() {
50
- return zodToJsonSchema(GroupByQuerySchema, { target: this.target });
49
+ return z.toJSONSchema(GroupByQuerySchema, { target: this.target });
51
50
  }
52
51
  get jsonSearchQuerySchema() {
53
- return zodToJsonSchema(SearchQuerySchema, { target: this.target });
52
+ return z.toJSONSchema(SearchQuerySchema, { target: this.target });
54
53
  }
55
54
  get jsonPaginateQuerySchema() {
56
- return zodToJsonSchema(PaginateQuerySchema, { target: this.target });
55
+ return z.toJSONSchema(PaginateQuerySchema, { target: this.target });
57
56
  }
58
57
  get jsonDeleteBodyResponseSchema() {
59
- return zodToJsonSchema(DeleteBodyResponseSchema, { target: this.target });
58
+ return z.toJSONSchema(DeleteBodyResponseSchema, { target: this.target });
60
59
  }
61
60
  get jsonFindByParamSchema() {
62
- return zodToJsonSchema(FindByParamSchema, { target: this.target });
61
+ return z.toJSONSchema(FindByParamSchema, { target: this.target });
63
62
  }
64
63
  get jsonPaginateBodyResponseSchema() {
65
- return zodToJsonSchema(PaginateBodyResponseSchema.extend({
64
+ return z.toJSONSchema(PaginateBodyResponseSchema.extend({
66
65
  items: z.array(this.entitySchema)
67
66
  }), { target: this.target });
68
67
  }
69
68
  get jsonIdParamSchema() {
70
- return zodToJsonSchema(IdParamSchema, { target: this.target });
69
+ return z.toJSONSchema(IdParamSchema, { target: this.target });
71
70
  }
72
71
  /**
73
72
  * Get JSON schema for export
@@ -107,7 +106,7 @@ export class CrudSchemaBuilder {
107
106
  get findByIdsSchema() {
108
107
  return {
109
108
  ...(this.getTags),
110
- params: zodToJsonSchema(z.object({
109
+ params: z.toJSONSchema(z.object({
111
110
  ids: z.string().regex(/^[^,]+(,[^,]+)*$/, "Debe ser una lista de valores separados por coma sin comas consecutivas")
112
111
  }), { target: this.target }),
113
112
  response: {
@@ -283,7 +282,7 @@ export class CrudSchemaBuilder {
283
282
  return {
284
283
  ...(this.getTags),
285
284
  params: this.jsonIdParamSchema,
286
- body: zodToJsonSchema(this.entityUpdateSchema.partial(), { target: this.target }),
285
+ body: z.toJSONSchema(this.entityUpdateSchema.partial(), { target: this.target }),
287
286
  response: {
288
287
  200: this.jsonEntitySchema,
289
288
  401: this.jsonErrorBodyResponse,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.51.0",
6
+ "version": "1.0.0",
7
7
  "description": "Crud utils across modules",
8
8
  "main": "dist/index.js",
9
9
  "types": "types/index.d.ts",
@@ -22,10 +22,10 @@
22
22
  "author": "Cristian Incarnato & Drax Team",
23
23
  "license": "ISC",
24
24
  "dependencies": {
25
- "@drax/common-back": "^0.51.0",
26
- "@drax/common-share": "^0.51.0",
27
- "@drax/identity-share": "^0.51.0",
28
- "@drax/media-back": "^0.51.0",
25
+ "@drax/common-back": "^1.0.0",
26
+ "@drax/common-share": "^1.0.0",
27
+ "@drax/identity-share": "^1.0.0",
28
+ "@drax/media-back": "^1.0.0",
29
29
  "@graphql-tools/load-files": "^7.0.0",
30
30
  "@graphql-tools/merge": "^9.0.4",
31
31
  "mongoose": "^8.21.0",
@@ -35,8 +35,7 @@
35
35
  "peerDependencies": {
36
36
  "dayjs": "^1.11.19",
37
37
  "mongoose-paginate-v2": "^1.8.3",
38
- "zod": "^3.25.76",
39
- "zod-to-json-schema": "3.24.6"
38
+ "zod": "^4.3.6"
40
39
  },
41
40
  "devDependencies": {
42
41
  "@types/node": "^20.12.10",
@@ -47,5 +46,5 @@
47
46
  "tsc-alias": "^1.8.10",
48
47
  "typescript": "^5.6.2"
49
48
  },
50
- "gitHead": "a8fe4fe11637e3b899686b8dd8d658d62933ea5a"
49
+ "gitHead": "8e60f7548448f339e7e9bb665ceacd3e051ef32e"
51
50
  }
@@ -1,6 +1,5 @@
1
1
  import z from 'zod';
2
- import { zodToJsonSchema } from 'zod-to-json-schema';
3
- import type { Targets } from 'zod-to-json-schema';
2
+
4
3
  import {
5
4
  IdParamSchema,
6
5
  DeleteBodyResponseSchema,
@@ -21,9 +20,9 @@ export class CrudSchemaBuilder<T extends z.ZodObject<z.ZodRawShape>, TCreate ext
21
20
  private entityUpdateSchema: TUpdate;
22
21
  private entityName: string;
23
22
  private tags: string[];
24
- private target: Targets = 'openApi3'; //"jsonSchema7" | "jsonSchema2019-09" | "openApi3" | "openAi"
23
+ private target: string = 'openapi-3.0'; //"jsonSchema7" | "jsonSchema2019-09" | "openapi-3.0" | "openAi"
25
24
 
26
- constructor(entitySchema: T, entityCreateSchema: TCreate, entityUpdateSchema: TUpdate, entityName: string, target:Targets = 'openApi3', tags: string[] = []) {
25
+ constructor(entitySchema: T, entityCreateSchema: TCreate, entityUpdateSchema: TUpdate, entityName: string, target:string = 'openapi-3.0', tags: string[] = []) {
27
26
  this.entitySchema = entitySchema;
28
27
  this.entityCreateSchema = entityCreateSchema;
29
28
  this.entityUpdateSchema = entityUpdateSchema;
@@ -40,23 +39,23 @@ export class CrudSchemaBuilder<T extends z.ZodObject<z.ZodRawShape>, TCreate ext
40
39
  }
41
40
 
42
41
  get jsonEntityCreateSchema(){
43
- return zodToJsonSchema(this.entityCreateSchema, {target: this.target})
42
+ return z.toJSONSchema(this.entityCreateSchema, {target: this.target})
44
43
  }
45
44
 
46
45
  get jsonEntityUpdateSchema(){
47
- return zodToJsonSchema(this.entityUpdateSchema, {target: this.target})
46
+ return z.toJSONSchema(this.entityUpdateSchema, {target: this.target})
48
47
  }
49
48
 
50
49
  get jsonEntitySchema() {
51
- return zodToJsonSchema(this.entitySchema, {target: this.target})
50
+ return z.toJSONSchema(this.entitySchema, {target: this.target})
52
51
  }
53
52
 
54
53
  get jsonEntityArraySchema() {
55
- return zodToJsonSchema(z.array(this.entitySchema), {target: this.target})
54
+ return z.toJSONSchema(z.array(this.entitySchema), {target: this.target})
56
55
  }
57
56
 
58
57
  get jsonEntityGroupBySchema() {
59
- return zodToJsonSchema(
58
+ return z.toJSONSchema(
60
59
  z.array(
61
60
  z.object({
62
61
  count: z.number()
@@ -67,49 +66,49 @@ export class CrudSchemaBuilder<T extends z.ZodObject<z.ZodRawShape>, TCreate ext
67
66
  }
68
67
 
69
68
  get jsonExportBodyResponse() {
70
- return zodToJsonSchema(ExportBodyResponseSchema, {target: this.target})
69
+ return z.toJSONSchema(ExportBodyResponseSchema, {target: this.target})
71
70
  }
72
71
 
73
72
  get jsonErrorBodyResponse() {
74
- return zodToJsonSchema(ErrorBodyResponseSchema, {target: this.target})
73
+ return z.toJSONSchema(ErrorBodyResponseSchema, {target: this.target})
75
74
  }
76
75
 
77
76
  get jsonValidationErrorBodyResponse() {
78
- return zodToJsonSchema(ValidationErrorBodyResponseSchema, {target: this.target})
77
+ return z.toJSONSchema(ValidationErrorBodyResponseSchema, {target: this.target})
79
78
  }
80
79
 
81
80
  get jsonFindQuerySchema(){
82
- return zodToJsonSchema(FindQuerySchema, {target: this.target})
81
+ return z.toJSONSchema(FindQuerySchema, {target: this.target})
83
82
  }
84
83
 
85
84
  get jsonGroupByQuerySchema(){
86
- return zodToJsonSchema(GroupByQuerySchema, {target: this.target})
85
+ return z.toJSONSchema(GroupByQuerySchema, {target: this.target})
87
86
  }
88
87
 
89
88
  get jsonSearchQuerySchema(){
90
- return zodToJsonSchema(SearchQuerySchema, {target: this.target})
89
+ return z.toJSONSchema(SearchQuerySchema, {target: this.target})
91
90
  }
92
91
 
93
92
  get jsonPaginateQuerySchema(){
94
- return zodToJsonSchema(PaginateQuerySchema, {target: this.target})
93
+ return z.toJSONSchema(PaginateQuerySchema, {target: this.target})
95
94
  }
96
95
 
97
96
  get jsonDeleteBodyResponseSchema(){
98
- return zodToJsonSchema(DeleteBodyResponseSchema, {target: this.target})
97
+ return z.toJSONSchema(DeleteBodyResponseSchema, {target: this.target})
99
98
  }
100
99
 
101
100
  get jsonFindByParamSchema(){
102
- return zodToJsonSchema(FindByParamSchema, {target: this.target})
101
+ return z.toJSONSchema(FindByParamSchema, {target: this.target})
103
102
  }
104
103
 
105
104
  get jsonPaginateBodyResponseSchema(){
106
- return zodToJsonSchema(PaginateBodyResponseSchema.extend({
105
+ return z.toJSONSchema(PaginateBodyResponseSchema.extend({
107
106
  items: z.array(this.entitySchema)
108
107
  }), {target: this.target})
109
108
  }
110
109
 
111
110
  get jsonIdParamSchema(){
112
- return zodToJsonSchema(IdParamSchema, {target: this.target})
111
+ return z.toJSONSchema(IdParamSchema, {target: this.target})
113
112
  }
114
113
 
115
114
  /**
@@ -152,7 +151,7 @@ export class CrudSchemaBuilder<T extends z.ZodObject<z.ZodRawShape>, TCreate ext
152
151
  get findByIdsSchema() {
153
152
  return {
154
153
  ...(this.getTags),
155
- params: zodToJsonSchema(z.object({
154
+ params: z.toJSONSchema(z.object({
156
155
  ids: z.string().regex(/^[^,]+(,[^,]+)*$/, "Debe ser una lista de valores separados por coma sin comas consecutivas")
157
156
  }), {target: this.target}),
158
157
  response: {
@@ -339,7 +338,7 @@ export class CrudSchemaBuilder<T extends z.ZodObject<z.ZodRawShape>, TCreate ext
339
338
  return {
340
339
  ...(this.getTags),
341
340
  params: this.jsonIdParamSchema,
342
- body: zodToJsonSchema(this.entityUpdateSchema.partial(), {target: this.target}),
341
+ body: z.toJSONSchema(this.entityUpdateSchema.partial(), {target: this.target}),
343
342
  response: {
344
343
  200: this.jsonEntitySchema,
345
344
  401: this.jsonErrorBodyResponse,