@ai0x0/utils 0.0.18 → 0.0.21

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.
@@ -20,7 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  var schemas_exports = {};
21
21
  __export(schemas_exports, {
22
22
  basicFields: () => basicFields,
23
+ createInsertBodySchema: () => createInsertBodySchema,
23
24
  createTableSchema: () => createTableSchema,
25
+ createUpdateBodySchema: () => createUpdateBodySchema,
24
26
  listBodySchema: () => listBodySchema,
25
27
  queryListSchema: () => queryListSchema
26
28
  });
@@ -40,6 +42,23 @@ var basicFields = {
40
42
  createdAt: createdAt(),
41
43
  updatedAt: updatedAt()
42
44
  };
45
+ var basicInsertOmit = {
46
+ id: true,
47
+ creatorId: true,
48
+ editorId: true,
49
+ accessedAt: true,
50
+ createdAt: true,
51
+ updatedAt: true
52
+ };
53
+ var basicUpdateOmit = {
54
+ creatorId: true,
55
+ editorId: true,
56
+ accessedAt: true,
57
+ createdAt: true,
58
+ updatedAt: true
59
+ };
60
+ var createInsertBodySchema = (table) => (0, import_drizzle_zod.createInsertSchema)(table).omit(basicInsertOmit);
61
+ var createUpdateBodySchema = (table) => (0, import_drizzle_zod.createUpdateSchema)(table).omit(basicUpdateOmit).required({ id: true });
43
62
  var queryListSchema = (schema) => import_zod.z.object({
44
63
  current: import_zod.z.string().optional().default("1"),
45
64
  // 默认页码为 1
@@ -60,49 +79,39 @@ var listBodySchema = (schema) => import_zod.z.object({
60
79
  var createTableSchema = ({
61
80
  name,
62
81
  columns,
63
- refineSchema,
64
82
  extraConfig
65
83
  }) => {
84
+ const mergedColumns = { ...basicFields, ...columns };
66
85
  const table = (0, import_pg_core.pgTable)(
67
86
  name,
68
- {
69
- ...basicFields,
70
- ...columns
71
- },
87
+ mergedColumns,
72
88
  extraConfig
73
89
  );
74
- const selectSchema = (0, import_drizzle_zod.createSelectSchema)(
75
- table,
76
- refineSchema
90
+ const selectSchema = (0, import_drizzle_zod.createSelectSchema)(table);
91
+ const insertSchema = (0, import_drizzle_zod.createInsertSchema)((0, import_pg_core.pgTable)(name, columns));
92
+ const updateSchema = (0, import_drizzle_zod.createUpdateSchema)(
93
+ (0, import_pg_core.pgTable)(name, { id: (0, import_pg_core.uuid)("id"), ...columns })
94
+ ).extend({ id: import_zod.z.string() });
95
+ const querySchema = import_zod.z.object({ id: import_zod.z.string() });
96
+ const queryListWithSchema = queryListSchema(
97
+ import_zod.z.object({}).catchall(import_zod.z.unknown())
77
98
  );
78
- const insertTable = (0, import_pg_core.pgTable)(name, columns);
79
- const updateTable = (0, import_pg_core.pgTable)(name, {
80
- id: (0, import_pg_core.uuid)(),
81
- ...columns
82
- });
83
99
  return {
84
100
  table,
85
101
  selectSchema,
86
- insertSchema: (0, import_drizzle_zod.createInsertSchema)(
87
- insertTable,
88
- refineSchema
89
- ),
90
- updateSchema: (0, import_drizzle_zod.createUpdateSchema)(
91
- updateTable,
92
- {
93
- id: import_zod.z.string(),
94
- ...refineSchema
95
- }
96
- ),
97
- querySchema: selectSchema.pick({ id: true }),
98
- queryListSchema: queryListSchema(selectSchema.partial()),
102
+ insertSchema,
103
+ updateSchema,
104
+ querySchema,
105
+ queryListSchema: queryListWithSchema,
99
106
  queryListSelectSchema: selectSchema
100
107
  };
101
108
  };
102
109
  // Annotate the CommonJS export names for ESM import in node:
103
110
  0 && (module.exports = {
104
111
  basicFields,
112
+ createInsertBodySchema,
105
113
  createTableSchema,
114
+ createUpdateBodySchema,
106
115
  listBodySchema,
107
116
  queryListSchema
108
117
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai0x0/utils",
3
- "version": "0.0.18",
3
+ "version": "0.0.21",
4
4
  "description": "AI0x0 utils",
5
5
  "keywords": [
6
6
  "ai0x0"