@develit-io/backend-sdk 11.2.0 → 12.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.
package/dist/index.d.mts CHANGED
@@ -1,19 +1,21 @@
1
1
  import * as drizzle_orm from 'drizzle-orm';
2
- import { Table, InferInsertModel, AnyColumn } from 'drizzle-orm';
2
+ import { Table, InferInsertModel, InferSelectModel, 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, ZodObject, ZodOptional, ZodType } from 'zod';
5
+ import { z as z$1, ZodType, ZodObject, ZodOptional } 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';
9
9
  import { Queue } from '@cloudflare/workers-types';
10
10
  import { BatchItem } from 'drizzle-orm/batch';
11
11
  import { DrizzleD1Database } from 'drizzle-orm/d1';
12
- export { createSelectSchema } from 'drizzle-orm/zod';
13
12
 
14
13
  declare const ENVIRONMENT: string[];
15
14
 
16
- type Environment = string | 'localhost' | 'dev' | 'staging' | 'production';
15
+ declare const NAMED_ENVIRONMENTS: readonly ["localhost", "dev", "staging", "production"];
16
+ type NamedEnvironment = (typeof NAMED_ENVIRONMENTS)[number];
17
+ type PreviewEnvironment = number;
18
+ type Environment = NamedEnvironment | PreviewEnvironment;
17
19
 
18
20
  type Project = 'creditio' | 'cryptobyte-website' | 'dbu-payments-api' | 'dbu-mdm' | 'dbu-txs' | 'develit-sdk' | 'kachlikarna-pridavac' | 'lrf-website' | 'moneio' | 'stable-labs-emi-processor';
19
21
 
@@ -838,34 +840,63 @@ declare const bankAccount: {
838
840
 
839
841
  declare const auditFieldKeys: readonly ["createdAt", "createdBy", "updatedAt", "updatedBy", "deletedAt", "deletedBy"];
840
842
  type AuditKey = (typeof auditFieldKeys)[number];
843
+ type Customizations = Record<string, () => ZodType>;
844
+ type ResolveCustomizations<TC extends Customizations> = {
845
+ [K in keyof TC]: TC[K] extends () => infer R ? R extends ZodType ? R : never : never;
846
+ };
841
847
  type FieldSchema<T> = undefined extends T ? ZodOptional<ZodType<Exclude<T, undefined>>> : ZodType<T>;
842
- type InsertSchemaOf<TTable extends Table> = ZodObject<{
848
+ type InsertShape<TTable extends Table> = {
843
849
  [K in keyof Omit<InferInsertModel<TTable>, AuditKey | 'id'>]-?: FieldSchema<InferInsertModel<TTable>[K]>;
844
850
  } & {
845
851
  id: ZodOptional<ZodType<string>>;
846
- }>;
847
- type UpdateSchemaOf<TTable extends Table> = ZodObject<{
852
+ };
853
+ type UpdateShape<TTable extends Table> = {
848
854
  [K in keyof Omit<InferInsertModel<TTable>, AuditKey | 'id'>]-?: ZodOptional<ZodType<Exclude<InferInsertModel<TTable>[K], undefined>>>;
849
855
  } & {
850
856
  id: ZodType<string>;
851
- }>;
857
+ };
858
+ type SelectShape<TTable extends Table> = {
859
+ [K in keyof InferSelectModel<TTable>]-?: FieldSchema<InferSelectModel<TTable>[K]>;
860
+ };
861
+ type WithCustomizations<TShape, TC extends Customizations> = Omit<TShape, keyof TC> & ResolveCustomizations<TC>;
862
+ type InsertSchemaOf<TTable extends Table, TC extends Customizations = Record<never, never>> = ZodObject<WithCustomizations<InsertShape<TTable>, TC>>;
863
+ type UpdateSchemaOf<TTable extends Table, TC extends Customizations = Record<never, never>> = ZodObject<WithCustomizations<UpdateShape<TTable>, TC>>;
864
+ type SelectSchemaOf<TTable extends Table, TC extends Customizations = Record<never, never>> = ZodObject<WithCustomizations<SelectShape<TTable>, TC>>;
852
865
  /**
853
- * Creates Zod schema for DB insert
866
+ * Creates Zod schema for DB insert.
854
867
  * - `id` optional (auto-generated if not provided)
855
868
  * - Audit fields omitted (set by DB)
869
+ *
870
+ * Pass `customizations` to re-narrow columns whose `.$type<T>()` annotation
871
+ * is lost by drizzle-orm/zod (typically JSON columns).
872
+ *
873
+ * @example
874
+ * const schema = createInsertSchema(account, {
875
+ * lastSyncMetadata: () => z.custom<LastSyncMetadata>().optional(),
876
+ * })
856
877
  */
857
- declare function createInsertSchema<TTable extends Table>(table: TTable): InsertSchemaOf<TTable>;
878
+ declare function createInsertSchema<TTable extends Table, const TC extends Customizations = Record<never, never>>(table: TTable, customizations?: TC): InsertSchemaOf<TTable, TC>;
858
879
  /**
859
- * Creates Zod schema for DB update
880
+ * Creates Zod schema for DB update.
860
881
  * - `id` required
861
882
  * - All other fields optional
862
883
  * - Audit fields omitted
884
+ *
885
+ * Pass `customizations` to re-narrow columns whose `.$type<T>()` annotation
886
+ * is lost by drizzle-orm/zod (typically JSON columns).
863
887
  */
864
- declare function createUpdateSchema<TTable extends Table>(table: TTable): UpdateSchemaOf<TTable>;
888
+ declare function createUpdateSchema<TTable extends Table, const TC extends Customizations = Record<never, never>>(table: TTable, customizations?: TC): UpdateSchemaOf<TTable, TC>;
865
889
  /**
866
890
  * Creates Zod schema for API PATCH (alias for updateSchema)
867
891
  */
868
892
  declare const createPatchSchema: typeof createUpdateSchema;
893
+ /**
894
+ * Creates Zod schema for DB select rows.
895
+ *
896
+ * Pass `customizations` to re-narrow columns whose `.$type<T>()` annotation
897
+ * is lost by drizzle-orm/zod (typically JSON columns).
898
+ */
899
+ declare function createSelectSchema<TTable extends Table, const TC extends Customizations = Record<never, never>>(table: TTable, customizations?: TC): SelectSchemaOf<TTable, TC>;
869
900
 
870
901
  declare const USER_ROLES: readonly ["OWNER", "ADMIN", "MEMBER"];
871
902
  type UserRole = (typeof USER_ROLES)[number];
@@ -1160,6 +1191,28 @@ declare const getDrizzleD1Config: () => Promise<{
1160
1191
  dialect: "sqlite";
1161
1192
  }>;
1162
1193
 
1194
+ interface QueryInChunksOptions {
1195
+ /**
1196
+ * Maximum number of values per chunk. Cloudflare D1's hard limit is 100
1197
+ * bound parameters per statement; defaults to 90 to leave room for
1198
+ * additional `WHERE` predicates.
1199
+ */
1200
+ chunkSize?: number;
1201
+ }
1202
+ /**
1203
+ * Runs the given query function over `values` in chunks small enough to fit
1204
+ * under Cloudflare D1's 100-parameter limit, concatenating the results.
1205
+ *
1206
+ * Use this whenever an `inArray(column, ids)` (or similar) query may exceed
1207
+ * ~80 values — D1 will reject larger statements with a parameter limit error.
1208
+ *
1209
+ * @example
1210
+ * const payments = await queryInChunks(bankRefIds, (chunk) =>
1211
+ * db.select().from(payment).where(inArray(payment.bankRefId, chunk)),
1212
+ * )
1213
+ */
1214
+ declare function queryInChunks<TParam, TResult>(values: readonly TParam[], queryFn: (chunk: TParam[]) => Promise<TResult[]>, options?: QueryInChunksOptions): Promise<TResult[]>;
1215
+
1163
1216
  type Operator = 'like' | 'ilike';
1164
1217
  type Wrap = 'both' | 'prefix' | 'suffix' | 'none';
1165
1218
  type BuildSearchOptions = {
@@ -1333,5 +1386,5 @@ interface WithRetryCounterOptions {
1333
1386
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
1334
1387
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
1335
1388
 
1336
- export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, chunkQueueMessages, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInsertSchema, createInternalError, createPatchSchema, createUpdateSchema, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getDrizzleD1Config, getLocalD1DatabaseIdFromWrangler, getSecret, handleAction, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, pushToQueue, redact, resolveColumn, service, structuredAddressSchema, useFetch, useResult, useResultSync, uuidv4, uuidv5, workflowInstanceStatusSchema };
1389
+ export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, chunkQueueMessages, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInsertSchema, createInternalError, createPatchSchema, createSelectSchema, createUpdateSchema, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getDrizzleD1Config, getLocalD1DatabaseIdFromWrangler, getSecret, handleAction, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, pushToQueue, queryInChunks, redact, resolveColumn, service, structuredAddressSchema, useFetch, useResult, useResultSync, uuidv4, uuidv5, workflowInstanceStatusSchema };
1337
1390
  export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, BankAccountMetadata, BaseEvent, BuildSearchOptions, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IdempotencyContextVariables, IdentityContextVariables, InternalError, InternalErrorResponseStatus, Project, RequestLog, ResponseLog, StructuredAddress, UserRole, ValidatedInput, WorkflowInstanceStatus };
package/dist/index.d.ts CHANGED
@@ -1,19 +1,21 @@
1
1
  import * as drizzle_orm from 'drizzle-orm';
2
- import { Table, InferInsertModel, AnyColumn } from 'drizzle-orm';
2
+ import { Table, InferInsertModel, InferSelectModel, 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, ZodObject, ZodOptional, ZodType } from 'zod';
5
+ import { z as z$1, ZodType, ZodObject, ZodOptional } 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';
9
9
  import { Queue } from '@cloudflare/workers-types';
10
10
  import { BatchItem } from 'drizzle-orm/batch';
11
11
  import { DrizzleD1Database } from 'drizzle-orm/d1';
12
- export { createSelectSchema } from 'drizzle-orm/zod';
13
12
 
14
13
  declare const ENVIRONMENT: string[];
15
14
 
16
- type Environment = string | 'localhost' | 'dev' | 'staging' | 'production';
15
+ declare const NAMED_ENVIRONMENTS: readonly ["localhost", "dev", "staging", "production"];
16
+ type NamedEnvironment = (typeof NAMED_ENVIRONMENTS)[number];
17
+ type PreviewEnvironment = number;
18
+ type Environment = NamedEnvironment | PreviewEnvironment;
17
19
 
18
20
  type Project = 'creditio' | 'cryptobyte-website' | 'dbu-payments-api' | 'dbu-mdm' | 'dbu-txs' | 'develit-sdk' | 'kachlikarna-pridavac' | 'lrf-website' | 'moneio' | 'stable-labs-emi-processor';
19
21
 
@@ -838,34 +840,63 @@ declare const bankAccount: {
838
840
 
839
841
  declare const auditFieldKeys: readonly ["createdAt", "createdBy", "updatedAt", "updatedBy", "deletedAt", "deletedBy"];
840
842
  type AuditKey = (typeof auditFieldKeys)[number];
843
+ type Customizations = Record<string, () => ZodType>;
844
+ type ResolveCustomizations<TC extends Customizations> = {
845
+ [K in keyof TC]: TC[K] extends () => infer R ? R extends ZodType ? R : never : never;
846
+ };
841
847
  type FieldSchema<T> = undefined extends T ? ZodOptional<ZodType<Exclude<T, undefined>>> : ZodType<T>;
842
- type InsertSchemaOf<TTable extends Table> = ZodObject<{
848
+ type InsertShape<TTable extends Table> = {
843
849
  [K in keyof Omit<InferInsertModel<TTable>, AuditKey | 'id'>]-?: FieldSchema<InferInsertModel<TTable>[K]>;
844
850
  } & {
845
851
  id: ZodOptional<ZodType<string>>;
846
- }>;
847
- type UpdateSchemaOf<TTable extends Table> = ZodObject<{
852
+ };
853
+ type UpdateShape<TTable extends Table> = {
848
854
  [K in keyof Omit<InferInsertModel<TTable>, AuditKey | 'id'>]-?: ZodOptional<ZodType<Exclude<InferInsertModel<TTable>[K], undefined>>>;
849
855
  } & {
850
856
  id: ZodType<string>;
851
- }>;
857
+ };
858
+ type SelectShape<TTable extends Table> = {
859
+ [K in keyof InferSelectModel<TTable>]-?: FieldSchema<InferSelectModel<TTable>[K]>;
860
+ };
861
+ type WithCustomizations<TShape, TC extends Customizations> = Omit<TShape, keyof TC> & ResolveCustomizations<TC>;
862
+ type InsertSchemaOf<TTable extends Table, TC extends Customizations = Record<never, never>> = ZodObject<WithCustomizations<InsertShape<TTable>, TC>>;
863
+ type UpdateSchemaOf<TTable extends Table, TC extends Customizations = Record<never, never>> = ZodObject<WithCustomizations<UpdateShape<TTable>, TC>>;
864
+ type SelectSchemaOf<TTable extends Table, TC extends Customizations = Record<never, never>> = ZodObject<WithCustomizations<SelectShape<TTable>, TC>>;
852
865
  /**
853
- * Creates Zod schema for DB insert
866
+ * Creates Zod schema for DB insert.
854
867
  * - `id` optional (auto-generated if not provided)
855
868
  * - Audit fields omitted (set by DB)
869
+ *
870
+ * Pass `customizations` to re-narrow columns whose `.$type<T>()` annotation
871
+ * is lost by drizzle-orm/zod (typically JSON columns).
872
+ *
873
+ * @example
874
+ * const schema = createInsertSchema(account, {
875
+ * lastSyncMetadata: () => z.custom<LastSyncMetadata>().optional(),
876
+ * })
856
877
  */
857
- declare function createInsertSchema<TTable extends Table>(table: TTable): InsertSchemaOf<TTable>;
878
+ declare function createInsertSchema<TTable extends Table, const TC extends Customizations = Record<never, never>>(table: TTable, customizations?: TC): InsertSchemaOf<TTable, TC>;
858
879
  /**
859
- * Creates Zod schema for DB update
880
+ * Creates Zod schema for DB update.
860
881
  * - `id` required
861
882
  * - All other fields optional
862
883
  * - Audit fields omitted
884
+ *
885
+ * Pass `customizations` to re-narrow columns whose `.$type<T>()` annotation
886
+ * is lost by drizzle-orm/zod (typically JSON columns).
863
887
  */
864
- declare function createUpdateSchema<TTable extends Table>(table: TTable): UpdateSchemaOf<TTable>;
888
+ declare function createUpdateSchema<TTable extends Table, const TC extends Customizations = Record<never, never>>(table: TTable, customizations?: TC): UpdateSchemaOf<TTable, TC>;
865
889
  /**
866
890
  * Creates Zod schema for API PATCH (alias for updateSchema)
867
891
  */
868
892
  declare const createPatchSchema: typeof createUpdateSchema;
893
+ /**
894
+ * Creates Zod schema for DB select rows.
895
+ *
896
+ * Pass `customizations` to re-narrow columns whose `.$type<T>()` annotation
897
+ * is lost by drizzle-orm/zod (typically JSON columns).
898
+ */
899
+ declare function createSelectSchema<TTable extends Table, const TC extends Customizations = Record<never, never>>(table: TTable, customizations?: TC): SelectSchemaOf<TTable, TC>;
869
900
 
870
901
  declare const USER_ROLES: readonly ["OWNER", "ADMIN", "MEMBER"];
871
902
  type UserRole = (typeof USER_ROLES)[number];
@@ -1160,6 +1191,28 @@ declare const getDrizzleD1Config: () => Promise<{
1160
1191
  dialect: "sqlite";
1161
1192
  }>;
1162
1193
 
1194
+ interface QueryInChunksOptions {
1195
+ /**
1196
+ * Maximum number of values per chunk. Cloudflare D1's hard limit is 100
1197
+ * bound parameters per statement; defaults to 90 to leave room for
1198
+ * additional `WHERE` predicates.
1199
+ */
1200
+ chunkSize?: number;
1201
+ }
1202
+ /**
1203
+ * Runs the given query function over `values` in chunks small enough to fit
1204
+ * under Cloudflare D1's 100-parameter limit, concatenating the results.
1205
+ *
1206
+ * Use this whenever an `inArray(column, ids)` (or similar) query may exceed
1207
+ * ~80 values — D1 will reject larger statements with a parameter limit error.
1208
+ *
1209
+ * @example
1210
+ * const payments = await queryInChunks(bankRefIds, (chunk) =>
1211
+ * db.select().from(payment).where(inArray(payment.bankRefId, chunk)),
1212
+ * )
1213
+ */
1214
+ declare function queryInChunks<TParam, TResult>(values: readonly TParam[], queryFn: (chunk: TParam[]) => Promise<TResult[]>, options?: QueryInChunksOptions): Promise<TResult[]>;
1215
+
1163
1216
  type Operator = 'like' | 'ilike';
1164
1217
  type Wrap = 'both' | 'prefix' | 'suffix' | 'none';
1165
1218
  type BuildSearchOptions = {
@@ -1333,5 +1386,5 @@ interface WithRetryCounterOptions {
1333
1386
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
1334
1387
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
1335
1388
 
1336
- export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, chunkQueueMessages, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInsertSchema, createInternalError, createPatchSchema, createUpdateSchema, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getDrizzleD1Config, getLocalD1DatabaseIdFromWrangler, getSecret, handleAction, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, pushToQueue, redact, resolveColumn, service, structuredAddressSchema, useFetch, useResult, useResultSync, uuidv4, uuidv5, workflowInstanceStatusSchema };
1389
+ export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, chunkQueueMessages, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInsertSchema, createInternalError, createPatchSchema, createSelectSchema, createUpdateSchema, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getDrizzleD1Config, getLocalD1DatabaseIdFromWrangler, getSecret, handleAction, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, pushToQueue, queryInChunks, redact, resolveColumn, service, structuredAddressSchema, useFetch, useResult, useResultSync, uuidv4, uuidv5, workflowInstanceStatusSchema };
1337
1390
  export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, BankAccountMetadata, BaseEvent, BuildSearchOptions, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IdempotencyContextVariables, IdentityContextVariables, InternalError, InternalErrorResponseStatus, Project, RequestLog, ResponseLog, StructuredAddress, UserRole, ValidatedInput, WorkflowInstanceStatus };
package/dist/index.mjs CHANGED
@@ -2,8 +2,7 @@ export { u as uuidv4, a as uuidv5 } from './shared/backend-sdk.D_gzDKeC.mjs';
2
2
  import { sql, inArray, eq, gte, lte, and, or } from 'drizzle-orm';
3
3
  import { text, integer } from 'drizzle-orm/sqlite-core';
4
4
  import { COUNTRY_CODES_2, CURRENCY_CODES, BANK_CODES } from '@develit-io/general-codes';
5
- import { createInsertSchema as createInsertSchema$1 } from 'drizzle-orm/zod';
6
- export { createSelectSchema } from 'drizzle-orm/zod';
5
+ import { createInsertSchema as createInsertSchema$1, createSelectSchema as createSelectSchema$1 } from 'drizzle-orm/zod';
7
6
  import { z as z$1 } from 'zod';
8
7
  import * as z from 'zod/v4/core';
9
8
  import Cloudflare from 'cloudflare';
@@ -62,10 +61,14 @@ const auditFieldKeys = [
62
61
  "deletedAt",
63
62
  "deletedBy"
64
63
  ];
65
- function toShape(table) {
64
+ function toInsertShape(table) {
66
65
  const schema = createInsertSchema$1(table);
67
66
  return schema.shape;
68
67
  }
68
+ function toSelectShape(table) {
69
+ const schema = createSelectSchema$1(table);
70
+ return schema.shape;
71
+ }
69
72
  function omitAuditFields(shape) {
70
73
  return Object.fromEntries(
71
74
  Object.entries(shape).filter(
@@ -73,24 +76,42 @@ function omitAuditFields(shape) {
73
76
  )
74
77
  );
75
78
  }
76
- function createInsertSchema(table) {
77
- const shape = omitAuditFields(toShape(table));
79
+ function resolveCustomizations(customizations) {
80
+ if (!customizations) return {};
81
+ return Object.fromEntries(
82
+ Object.entries(customizations).filter(([, fn]) => typeof fn === "function").map(([k, fn]) => [k, fn()])
83
+ );
84
+ }
85
+ function createInsertSchema(table, customizations) {
86
+ const shape = omitAuditFields(toInsertShape(table));
78
87
  const idField = shape["id"];
79
88
  if (!idField) throw new Error(`createInsertSchema: table has no 'id' column`);
80
89
  return z$1.object({
81
90
  ...shape,
91
+ ...resolveCustomizations(customizations),
82
92
  id: idField.optional()
83
93
  });
84
94
  }
85
- function createUpdateSchema(table) {
86
- const { id, ...rest } = omitAuditFields(toShape(table));
95
+ function createUpdateSchema(table, customizations) {
96
+ const { id, ...rest } = omitAuditFields(toInsertShape(table));
87
97
  if (!id) throw new Error(`createUpdateSchema: table has no 'id' column`);
88
98
  const partialRest = Object.fromEntries(
89
99
  Object.entries(rest).map(([k, v]) => [k, v.optional()])
90
100
  );
91
- return z$1.object({ ...partialRest, id });
101
+ return z$1.object({
102
+ ...partialRest,
103
+ ...resolveCustomizations(customizations),
104
+ id
105
+ });
92
106
  }
93
107
  const createPatchSchema = createUpdateSchema;
108
+ function createSelectSchema(table, customizations) {
109
+ const shape = toSelectShape(table);
110
+ return z$1.object({
111
+ ...shape,
112
+ ...resolveCustomizations(customizations)
113
+ });
114
+ }
94
115
 
95
116
  const USER_ROLES = ["OWNER", "ADMIN", "MEMBER"];
96
117
 
@@ -561,6 +582,24 @@ const getDrizzleD1Config = async () => ({
561
582
  ...await getD1Credentials()
562
583
  });
563
584
 
585
+ const D1_MAX_BIND_VALUES = 90;
586
+ async function queryInChunks(values, queryFn, options) {
587
+ const chunkSize = options?.chunkSize ?? D1_MAX_BIND_VALUES;
588
+ if (chunkSize <= 0) {
589
+ throw new Error(
590
+ `queryInChunks: chunkSize must be positive, got ${chunkSize}`
591
+ );
592
+ }
593
+ if (values.length === 0) return [];
594
+ const results = [];
595
+ for (let i = 0; i < values.length; i += chunkSize) {
596
+ const chunk = values.slice(i, i + chunkSize);
597
+ const rows = await queryFn(chunk);
598
+ results.push(...rows);
599
+ }
600
+ return results;
601
+ }
602
+
564
603
  const buildSearchConditions = (search, columns, opts = {}) => {
565
604
  const { wrap = "both" } = opts;
566
605
  if (!search || search.trim() === "" || columns.length === 0) return void 0;
@@ -919,4 +958,4 @@ function develitWorker(Worker) {
919
958
  return DevelitWorker;
920
959
  }
921
960
 
922
- export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, chunkQueueMessages, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInsertSchema, createInternalError, createPatchSchema, createUpdateSchema, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getDrizzleD1Config, getLocalD1DatabaseIdFromWrangler, getSecret, handleAction, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, pushToQueue, redact, resolveColumn, service, structuredAddressSchema, useFetch, useResult, useResultSync, workflowInstanceStatusSchema };
961
+ export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, chunkQueueMessages, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInsertSchema, createInternalError, createPatchSchema, createSelectSchema, createUpdateSchema, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getDrizzleD1Config, getLocalD1DatabaseIdFromWrangler, getSecret, handleAction, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, pushToQueue, queryInChunks, redact, resolveColumn, service, structuredAddressSchema, useFetch, useResult, useResultSync, workflowInstanceStatusSchema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@develit-io/backend-sdk",
3
- "version": "11.2.0",
3
+ "version": "12.0.0",
4
4
  "description": "Develit Backend SDK",
5
5
  "author": "Develit.io",
6
6
  "license": "ISC",