@develit-io/backend-sdk 9.10.3 → 9.10.4
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/dist/index.d.mts +15 -7
- package/dist/index.d.ts +15 -7
- package/dist/index.mjs +25 -21
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import * as drizzle_orm from 'drizzle-orm';
|
|
|
2
2
|
import { Table, ExtractTablesWithRelations, DBQueryConfig, BuildQueryResult, AnyColumn } from 'drizzle-orm';
|
|
3
3
|
import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
|
|
4
4
|
import { AnySQLiteTable } from 'drizzle-orm/sqlite-core';
|
|
5
|
-
import { z as z$1 } from 'zod';
|
|
5
|
+
import { ZodObject, ZodType, ZodOptional, z as z$1 } from 'zod';
|
|
6
6
|
import * as z from 'zod/v4/core';
|
|
7
7
|
import { ContentfulStatusCode, SuccessStatusCode } from 'hono/utils/http-status';
|
|
8
8
|
export { ContentfulStatusCode as InternalResponseStatus } from 'hono/utils/http-status';
|
|
@@ -46,23 +46,31 @@ declare const bankAccount: {
|
|
|
46
46
|
brBankNumber: drizzle_orm_sqlite_core.SQLiteTextBuilderInitial<"br_bank_number", [string, ...string[]], number | undefined>;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
+
declare const auditFieldKeys: readonly ["createdAt", "createdBy", "updatedAt", "updatedBy", "deletedAt", "deletedBy"];
|
|
50
|
+
type AuditKey = (typeof auditFieldKeys)[number];
|
|
51
|
+
type InsertSchemaOf<TTable extends Table> = ZodObject<{
|
|
52
|
+
[K in keyof Omit<TTable['$inferInsert'], AuditKey | 'id'>]: ZodType<TTable['$inferInsert'][K]>;
|
|
53
|
+
} & {
|
|
54
|
+
id: ZodOptional<ZodType<string>>;
|
|
55
|
+
}>;
|
|
56
|
+
type UpdateSchemaOf<TTable extends Table> = ZodObject<{
|
|
57
|
+
[K in keyof Omit<TTable['$inferInsert'], AuditKey | 'id'>]: ZodOptional<ZodType<TTable['$inferInsert'][K]>>;
|
|
58
|
+
} & {
|
|
59
|
+
id: ZodType<string>;
|
|
60
|
+
}>;
|
|
49
61
|
/**
|
|
50
62
|
* Creates Zod schema for DB insert
|
|
51
63
|
* - `id` optional (auto-generated if not provided)
|
|
52
64
|
* - Audit fields omitted (set by DB)
|
|
53
65
|
*/
|
|
54
|
-
declare function createInsertSchema<TTable extends Table>(table: TTable):
|
|
55
|
-
[x: string]: z$1.ZodType<unknown, unknown, z$1.core.$ZodTypeInternals<unknown, unknown>>;
|
|
56
|
-
}, z$1.core.$strip>;
|
|
66
|
+
declare function createInsertSchema<TTable extends Table>(table: TTable): InsertSchemaOf<TTable>;
|
|
57
67
|
/**
|
|
58
68
|
* Creates Zod schema for DB update
|
|
59
69
|
* - `id` required
|
|
60
70
|
* - All other fields optional
|
|
61
71
|
* - Audit fields omitted
|
|
62
72
|
*/
|
|
63
|
-
declare function createUpdateSchema<TTable extends Table>(table: TTable):
|
|
64
|
-
[x: string]: z$1.ZodType<unknown, unknown, z$1.core.$ZodTypeInternals<unknown, unknown>>;
|
|
65
|
-
}, z$1.core.$strip>;
|
|
73
|
+
declare function createUpdateSchema<TTable extends Table>(table: TTable): UpdateSchemaOf<TTable>;
|
|
66
74
|
/**
|
|
67
75
|
* Creates Zod schema for API PATCH (alias for updateSchema)
|
|
68
76
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as drizzle_orm from 'drizzle-orm';
|
|
|
2
2
|
import { Table, ExtractTablesWithRelations, DBQueryConfig, BuildQueryResult, AnyColumn } from 'drizzle-orm';
|
|
3
3
|
import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
|
|
4
4
|
import { AnySQLiteTable } from 'drizzle-orm/sqlite-core';
|
|
5
|
-
import { z as z$1 } from 'zod';
|
|
5
|
+
import { ZodObject, ZodType, ZodOptional, z as z$1 } from 'zod';
|
|
6
6
|
import * as z from 'zod/v4/core';
|
|
7
7
|
import { ContentfulStatusCode, SuccessStatusCode } from 'hono/utils/http-status';
|
|
8
8
|
export { ContentfulStatusCode as InternalResponseStatus } from 'hono/utils/http-status';
|
|
@@ -46,23 +46,31 @@ declare const bankAccount: {
|
|
|
46
46
|
brBankNumber: drizzle_orm_sqlite_core.SQLiteTextBuilderInitial<"br_bank_number", [string, ...string[]], number | undefined>;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
+
declare const auditFieldKeys: readonly ["createdAt", "createdBy", "updatedAt", "updatedBy", "deletedAt", "deletedBy"];
|
|
50
|
+
type AuditKey = (typeof auditFieldKeys)[number];
|
|
51
|
+
type InsertSchemaOf<TTable extends Table> = ZodObject<{
|
|
52
|
+
[K in keyof Omit<TTable['$inferInsert'], AuditKey | 'id'>]: ZodType<TTable['$inferInsert'][K]>;
|
|
53
|
+
} & {
|
|
54
|
+
id: ZodOptional<ZodType<string>>;
|
|
55
|
+
}>;
|
|
56
|
+
type UpdateSchemaOf<TTable extends Table> = ZodObject<{
|
|
57
|
+
[K in keyof Omit<TTable['$inferInsert'], AuditKey | 'id'>]: ZodOptional<ZodType<TTable['$inferInsert'][K]>>;
|
|
58
|
+
} & {
|
|
59
|
+
id: ZodType<string>;
|
|
60
|
+
}>;
|
|
49
61
|
/**
|
|
50
62
|
* Creates Zod schema for DB insert
|
|
51
63
|
* - `id` optional (auto-generated if not provided)
|
|
52
64
|
* - Audit fields omitted (set by DB)
|
|
53
65
|
*/
|
|
54
|
-
declare function createInsertSchema<TTable extends Table>(table: TTable):
|
|
55
|
-
[x: string]: z$1.ZodType<unknown, unknown, z$1.core.$ZodTypeInternals<unknown, unknown>>;
|
|
56
|
-
}, z$1.core.$strip>;
|
|
66
|
+
declare function createInsertSchema<TTable extends Table>(table: TTable): InsertSchemaOf<TTable>;
|
|
57
67
|
/**
|
|
58
68
|
* Creates Zod schema for DB update
|
|
59
69
|
* - `id` required
|
|
60
70
|
* - All other fields optional
|
|
61
71
|
* - Audit fields omitted
|
|
62
72
|
*/
|
|
63
|
-
declare function createUpdateSchema<TTable extends Table>(table: TTable):
|
|
64
|
-
[x: string]: z$1.ZodType<unknown, unknown, z$1.core.$ZodTypeInternals<unknown, unknown>>;
|
|
65
|
-
}, z$1.core.$strip>;
|
|
73
|
+
declare function createUpdateSchema<TTable extends Table>(table: TTable): UpdateSchemaOf<TTable>;
|
|
66
74
|
/**
|
|
67
75
|
* Creates Zod schema for API PATCH (alias for updateSchema)
|
|
68
76
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -52,7 +52,7 @@ const bankAccount = {
|
|
|
52
52
|
// Brazil
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
const
|
|
55
|
+
const auditFieldKeys = [
|
|
56
56
|
"createdAt",
|
|
57
57
|
"createdBy",
|
|
58
58
|
"updatedAt",
|
|
@@ -60,29 +60,33 @@ const AUDIT_FIELDS = [
|
|
|
60
60
|
"deletedAt",
|
|
61
61
|
"deletedBy"
|
|
62
62
|
];
|
|
63
|
-
function
|
|
63
|
+
function toShape(table) {
|
|
64
64
|
const schema = createInsertSchema$1(table);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
return schema.shape;
|
|
66
|
+
}
|
|
67
|
+
function omitAuditFields(shape) {
|
|
68
|
+
return Object.fromEntries(
|
|
69
|
+
Object.entries(shape).filter(
|
|
70
|
+
([k]) => !auditFieldKeys.includes(k)
|
|
71
|
+
)
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
function createInsertSchema(table) {
|
|
75
|
+
const shape = omitAuditFields(toShape(table));
|
|
76
|
+
const idField = shape["id"];
|
|
77
|
+
if (!idField) throw new Error(`createInsertSchema: table has no 'id' column`);
|
|
78
|
+
return z$1.object({
|
|
79
|
+
...shape,
|
|
80
|
+
id: idField.optional()
|
|
81
|
+
});
|
|
73
82
|
}
|
|
74
83
|
function createUpdateSchema(table) {
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (key !== "id") {
|
|
82
|
-
shape[key] = shape[key].optional();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return z$1.object(shape);
|
|
84
|
+
const { id, ...rest } = omitAuditFields(toShape(table));
|
|
85
|
+
if (!id) throw new Error(`createUpdateSchema: table has no 'id' column`);
|
|
86
|
+
const partialRest = Object.fromEntries(
|
|
87
|
+
Object.entries(rest).map(([k, v]) => [k, v.optional()])
|
|
88
|
+
);
|
|
89
|
+
return z$1.object({ ...partialRest, id });
|
|
86
90
|
}
|
|
87
91
|
const createPatchSchema = createUpdateSchema;
|
|
88
92
|
|