@develit-io/backend-sdk 11.2.0 → 11.3.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,15 +1,14 @@
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
 
@@ -838,34 +837,63 @@ declare const bankAccount: {
838
837
 
839
838
  declare const auditFieldKeys: readonly ["createdAt", "createdBy", "updatedAt", "updatedBy", "deletedAt", "deletedBy"];
840
839
  type AuditKey = (typeof auditFieldKeys)[number];
840
+ type Customizations = Record<string, () => ZodType>;
841
+ type ResolveCustomizations<TC extends Customizations> = {
842
+ [K in keyof TC]: TC[K] extends () => infer R ? R extends ZodType ? R : never : never;
843
+ };
841
844
  type FieldSchema<T> = undefined extends T ? ZodOptional<ZodType<Exclude<T, undefined>>> : ZodType<T>;
842
- type InsertSchemaOf<TTable extends Table> = ZodObject<{
845
+ type InsertShape<TTable extends Table> = {
843
846
  [K in keyof Omit<InferInsertModel<TTable>, AuditKey | 'id'>]-?: FieldSchema<InferInsertModel<TTable>[K]>;
844
847
  } & {
845
848
  id: ZodOptional<ZodType<string>>;
846
- }>;
847
- type UpdateSchemaOf<TTable extends Table> = ZodObject<{
849
+ };
850
+ type UpdateShape<TTable extends Table> = {
848
851
  [K in keyof Omit<InferInsertModel<TTable>, AuditKey | 'id'>]-?: ZodOptional<ZodType<Exclude<InferInsertModel<TTable>[K], undefined>>>;
849
852
  } & {
850
853
  id: ZodType<string>;
851
- }>;
854
+ };
855
+ type SelectShape<TTable extends Table> = {
856
+ [K in keyof InferSelectModel<TTable>]-?: FieldSchema<InferSelectModel<TTable>[K]>;
857
+ };
858
+ type WithCustomizations<TShape, TC extends Customizations> = Omit<TShape, keyof TC> & ResolveCustomizations<TC>;
859
+ type InsertSchemaOf<TTable extends Table, TC extends Customizations = Record<never, never>> = ZodObject<WithCustomizations<InsertShape<TTable>, TC>>;
860
+ type UpdateSchemaOf<TTable extends Table, TC extends Customizations = Record<never, never>> = ZodObject<WithCustomizations<UpdateShape<TTable>, TC>>;
861
+ type SelectSchemaOf<TTable extends Table, TC extends Customizations = Record<never, never>> = ZodObject<WithCustomizations<SelectShape<TTable>, TC>>;
852
862
  /**
853
- * Creates Zod schema for DB insert
863
+ * Creates Zod schema for DB insert.
854
864
  * - `id` optional (auto-generated if not provided)
855
865
  * - Audit fields omitted (set by DB)
866
+ *
867
+ * Pass `customizations` to re-narrow columns whose `.$type<T>()` annotation
868
+ * is lost by drizzle-orm/zod (typically JSON columns).
869
+ *
870
+ * @example
871
+ * const schema = createInsertSchema(account, {
872
+ * lastSyncMetadata: () => z.custom<LastSyncMetadata>().optional(),
873
+ * })
856
874
  */
857
- declare function createInsertSchema<TTable extends Table>(table: TTable): InsertSchemaOf<TTable>;
875
+ declare function createInsertSchema<TTable extends Table, const TC extends Customizations = Record<never, never>>(table: TTable, customizations?: TC): InsertSchemaOf<TTable, TC>;
858
876
  /**
859
- * Creates Zod schema for DB update
877
+ * Creates Zod schema for DB update.
860
878
  * - `id` required
861
879
  * - All other fields optional
862
880
  * - Audit fields omitted
881
+ *
882
+ * Pass `customizations` to re-narrow columns whose `.$type<T>()` annotation
883
+ * is lost by drizzle-orm/zod (typically JSON columns).
863
884
  */
864
- declare function createUpdateSchema<TTable extends Table>(table: TTable): UpdateSchemaOf<TTable>;
885
+ declare function createUpdateSchema<TTable extends Table, const TC extends Customizations = Record<never, never>>(table: TTable, customizations?: TC): UpdateSchemaOf<TTable, TC>;
865
886
  /**
866
887
  * Creates Zod schema for API PATCH (alias for updateSchema)
867
888
  */
868
889
  declare const createPatchSchema: typeof createUpdateSchema;
890
+ /**
891
+ * Creates Zod schema for DB select rows.
892
+ *
893
+ * Pass `customizations` to re-narrow columns whose `.$type<T>()` annotation
894
+ * is lost by drizzle-orm/zod (typically JSON columns).
895
+ */
896
+ declare function createSelectSchema<TTable extends Table, const TC extends Customizations = Record<never, never>>(table: TTable, customizations?: TC): SelectSchemaOf<TTable, TC>;
869
897
 
870
898
  declare const USER_ROLES: readonly ["OWNER", "ADMIN", "MEMBER"];
871
899
  type UserRole = (typeof USER_ROLES)[number];
@@ -1160,6 +1188,28 @@ declare const getDrizzleD1Config: () => Promise<{
1160
1188
  dialect: "sqlite";
1161
1189
  }>;
1162
1190
 
1191
+ interface QueryInChunksOptions {
1192
+ /**
1193
+ * Maximum number of values per chunk. Cloudflare D1's hard limit is 100
1194
+ * bound parameters per statement; defaults to 90 to leave room for
1195
+ * additional `WHERE` predicates.
1196
+ */
1197
+ chunkSize?: number;
1198
+ }
1199
+ /**
1200
+ * Runs the given query function over `values` in chunks small enough to fit
1201
+ * under Cloudflare D1's 100-parameter limit, concatenating the results.
1202
+ *
1203
+ * Use this whenever an `inArray(column, ids)` (or similar) query may exceed
1204
+ * ~80 values — D1 will reject larger statements with a parameter limit error.
1205
+ *
1206
+ * @example
1207
+ * const payments = await queryInChunks(bankRefIds, (chunk) =>
1208
+ * db.select().from(payment).where(inArray(payment.bankRefId, chunk)),
1209
+ * )
1210
+ */
1211
+ declare function queryInChunks<TParam, TResult>(values: readonly TParam[], queryFn: (chunk: TParam[]) => Promise<TResult[]>, options?: QueryInChunksOptions): Promise<TResult[]>;
1212
+
1163
1213
  type Operator = 'like' | 'ilike';
1164
1214
  type Wrap = 'both' | 'prefix' | 'suffix' | 'none';
1165
1215
  type BuildSearchOptions = {
@@ -1333,5 +1383,5 @@ interface WithRetryCounterOptions {
1333
1383
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
1334
1384
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
1335
1385
 
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 };
1386
+ 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
1387
  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,15 +1,14 @@
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
 
@@ -838,34 +837,63 @@ declare const bankAccount: {
838
837
 
839
838
  declare const auditFieldKeys: readonly ["createdAt", "createdBy", "updatedAt", "updatedBy", "deletedAt", "deletedBy"];
840
839
  type AuditKey = (typeof auditFieldKeys)[number];
840
+ type Customizations = Record<string, () => ZodType>;
841
+ type ResolveCustomizations<TC extends Customizations> = {
842
+ [K in keyof TC]: TC[K] extends () => infer R ? R extends ZodType ? R : never : never;
843
+ };
841
844
  type FieldSchema<T> = undefined extends T ? ZodOptional<ZodType<Exclude<T, undefined>>> : ZodType<T>;
842
- type InsertSchemaOf<TTable extends Table> = ZodObject<{
845
+ type InsertShape<TTable extends Table> = {
843
846
  [K in keyof Omit<InferInsertModel<TTable>, AuditKey | 'id'>]-?: FieldSchema<InferInsertModel<TTable>[K]>;
844
847
  } & {
845
848
  id: ZodOptional<ZodType<string>>;
846
- }>;
847
- type UpdateSchemaOf<TTable extends Table> = ZodObject<{
849
+ };
850
+ type UpdateShape<TTable extends Table> = {
848
851
  [K in keyof Omit<InferInsertModel<TTable>, AuditKey | 'id'>]-?: ZodOptional<ZodType<Exclude<InferInsertModel<TTable>[K], undefined>>>;
849
852
  } & {
850
853
  id: ZodType<string>;
851
- }>;
854
+ };
855
+ type SelectShape<TTable extends Table> = {
856
+ [K in keyof InferSelectModel<TTable>]-?: FieldSchema<InferSelectModel<TTable>[K]>;
857
+ };
858
+ type WithCustomizations<TShape, TC extends Customizations> = Omit<TShape, keyof TC> & ResolveCustomizations<TC>;
859
+ type InsertSchemaOf<TTable extends Table, TC extends Customizations = Record<never, never>> = ZodObject<WithCustomizations<InsertShape<TTable>, TC>>;
860
+ type UpdateSchemaOf<TTable extends Table, TC extends Customizations = Record<never, never>> = ZodObject<WithCustomizations<UpdateShape<TTable>, TC>>;
861
+ type SelectSchemaOf<TTable extends Table, TC extends Customizations = Record<never, never>> = ZodObject<WithCustomizations<SelectShape<TTable>, TC>>;
852
862
  /**
853
- * Creates Zod schema for DB insert
863
+ * Creates Zod schema for DB insert.
854
864
  * - `id` optional (auto-generated if not provided)
855
865
  * - Audit fields omitted (set by DB)
866
+ *
867
+ * Pass `customizations` to re-narrow columns whose `.$type<T>()` annotation
868
+ * is lost by drizzle-orm/zod (typically JSON columns).
869
+ *
870
+ * @example
871
+ * const schema = createInsertSchema(account, {
872
+ * lastSyncMetadata: () => z.custom<LastSyncMetadata>().optional(),
873
+ * })
856
874
  */
857
- declare function createInsertSchema<TTable extends Table>(table: TTable): InsertSchemaOf<TTable>;
875
+ declare function createInsertSchema<TTable extends Table, const TC extends Customizations = Record<never, never>>(table: TTable, customizations?: TC): InsertSchemaOf<TTable, TC>;
858
876
  /**
859
- * Creates Zod schema for DB update
877
+ * Creates Zod schema for DB update.
860
878
  * - `id` required
861
879
  * - All other fields optional
862
880
  * - Audit fields omitted
881
+ *
882
+ * Pass `customizations` to re-narrow columns whose `.$type<T>()` annotation
883
+ * is lost by drizzle-orm/zod (typically JSON columns).
863
884
  */
864
- declare function createUpdateSchema<TTable extends Table>(table: TTable): UpdateSchemaOf<TTable>;
885
+ declare function createUpdateSchema<TTable extends Table, const TC extends Customizations = Record<never, never>>(table: TTable, customizations?: TC): UpdateSchemaOf<TTable, TC>;
865
886
  /**
866
887
  * Creates Zod schema for API PATCH (alias for updateSchema)
867
888
  */
868
889
  declare const createPatchSchema: typeof createUpdateSchema;
890
+ /**
891
+ * Creates Zod schema for DB select rows.
892
+ *
893
+ * Pass `customizations` to re-narrow columns whose `.$type<T>()` annotation
894
+ * is lost by drizzle-orm/zod (typically JSON columns).
895
+ */
896
+ declare function createSelectSchema<TTable extends Table, const TC extends Customizations = Record<never, never>>(table: TTable, customizations?: TC): SelectSchemaOf<TTable, TC>;
869
897
 
870
898
  declare const USER_ROLES: readonly ["OWNER", "ADMIN", "MEMBER"];
871
899
  type UserRole = (typeof USER_ROLES)[number];
@@ -1160,6 +1188,28 @@ declare const getDrizzleD1Config: () => Promise<{
1160
1188
  dialect: "sqlite";
1161
1189
  }>;
1162
1190
 
1191
+ interface QueryInChunksOptions {
1192
+ /**
1193
+ * Maximum number of values per chunk. Cloudflare D1's hard limit is 100
1194
+ * bound parameters per statement; defaults to 90 to leave room for
1195
+ * additional `WHERE` predicates.
1196
+ */
1197
+ chunkSize?: number;
1198
+ }
1199
+ /**
1200
+ * Runs the given query function over `values` in chunks small enough to fit
1201
+ * under Cloudflare D1's 100-parameter limit, concatenating the results.
1202
+ *
1203
+ * Use this whenever an `inArray(column, ids)` (or similar) query may exceed
1204
+ * ~80 values — D1 will reject larger statements with a parameter limit error.
1205
+ *
1206
+ * @example
1207
+ * const payments = await queryInChunks(bankRefIds, (chunk) =>
1208
+ * db.select().from(payment).where(inArray(payment.bankRefId, chunk)),
1209
+ * )
1210
+ */
1211
+ declare function queryInChunks<TParam, TResult>(values: readonly TParam[], queryFn: (chunk: TParam[]) => Promise<TResult[]>, options?: QueryInChunksOptions): Promise<TResult[]>;
1212
+
1163
1213
  type Operator = 'like' | 'ilike';
1164
1214
  type Wrap = 'both' | 'prefix' | 'suffix' | 'none';
1165
1215
  type BuildSearchOptions = {
@@ -1333,5 +1383,5 @@ interface WithRetryCounterOptions {
1333
1383
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
1334
1384
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
1335
1385
 
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 };
1386
+ 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
1387
  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": "11.3.0",
4
4
  "description": "Develit Backend SDK",
5
5
  "author": "Develit.io",
6
6
  "license": "ISC",