@develit-io/backend-sdk 9.10.3 → 9.11.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.
package/README.md CHANGED
@@ -60,7 +60,7 @@ export { defineCommand, DatabaseTransaction, createAuditLogWriter } from '@devel
60
60
 
61
61
  ## Requirements
62
62
 
63
- - Node.js 18+
63
+ - Node.js 22+
64
64
  - TypeScript 5.0+
65
65
  - Cloudflare Workers environment
66
66
  - Drizzle ORM setup
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): z$1.ZodObject<{
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): z$1.ZodObject<{
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): z$1.ZodObject<{
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): z$1.ZodObject<{
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 AUDIT_FIELDS = [
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 createInsertSchema(table) {
63
+ function toShape(table) {
64
64
  const schema = createInsertSchema$1(table);
65
- const shape = { ...schema.shape };
66
- for (const field of AUDIT_FIELDS) {
67
- delete shape[field];
68
- }
69
- if (shape.id) {
70
- shape.id = shape.id.optional();
71
- }
72
- return z$1.object(shape);
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 schema = createInsertSchema$1(table);
76
- const shape = { ...schema.shape };
77
- for (const field of AUDIT_FIELDS) {
78
- delete shape[field];
79
- }
80
- for (const key of Object.keys(shape)) {
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
 
@@ -368,7 +372,7 @@ async function handleAction(worker, input, options = {}, actionExecution) {
368
372
  }
369
373
  return RPCResponse.ok(successMessage, { data });
370
374
  } catch (error) {
371
- const internalError = createInternalError(error);
375
+ const internalError = isInternalError(error) ? error : createInternalError(error);
372
376
  worker.logError(internalError);
373
377
  return RPCResponse.serviceError(internalError);
374
378
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@develit-io/backend-sdk",
3
- "version": "9.10.3",
3
+ "version": "9.11.0",
4
4
  "description": "Develit Backend SDK",
5
5
  "author": "Develit.io",
6
6
  "license": "ISC",