@develit-io/backend-sdk 5.21.0 → 5.21.1
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.cjs +30 -47
- package/dist/index.d.cts +18 -40
- package/dist/index.d.mts +18 -40
- package/dist/index.d.ts +18 -40
- package/dist/index.mjs +30 -47
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ const pgCore = require('drizzle-orm/pg-core');
|
|
|
5
5
|
const sqliteCore = require('drizzle-orm/sqlite-core');
|
|
6
6
|
const generalCodes = require('@develit-io/general-codes');
|
|
7
7
|
const text = require('@std/text');
|
|
8
|
+
const cloudflare = require('alchemy/cloudflare');
|
|
8
9
|
const z = require('zod/v4/core');
|
|
9
10
|
require('http-status-codes');
|
|
10
11
|
const h3 = require('h3');
|
|
@@ -81,12 +82,9 @@ const composeD1Arguments = ({
|
|
|
81
82
|
resourceName
|
|
82
83
|
}) => {
|
|
83
84
|
return {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
primaryLocationHint: "weur"
|
|
88
|
-
}
|
|
89
|
-
}
|
|
85
|
+
name: resourceName,
|
|
86
|
+
primaryLocationHint: "weur"
|
|
87
|
+
// TODO: It's possible that it will take care of migrations as well
|
|
90
88
|
};
|
|
91
89
|
};
|
|
92
90
|
|
|
@@ -94,11 +92,7 @@ const composeKvArguments = ({
|
|
|
94
92
|
resourceName
|
|
95
93
|
}) => {
|
|
96
94
|
return {
|
|
97
|
-
|
|
98
|
-
namespace: {
|
|
99
|
-
title: resourceName
|
|
100
|
-
}
|
|
101
|
-
}
|
|
95
|
+
title: resourceName
|
|
102
96
|
};
|
|
103
97
|
};
|
|
104
98
|
|
|
@@ -108,14 +102,10 @@ const composeQueueArguments = ({
|
|
|
108
102
|
messageRetentionPeriod = 259200
|
|
109
103
|
}) => {
|
|
110
104
|
return {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
deliveryDelay,
|
|
116
|
-
messageRetentionPeriod
|
|
117
|
-
}
|
|
118
|
-
}
|
|
105
|
+
name: resourceName,
|
|
106
|
+
settings: {
|
|
107
|
+
deliveryDelay,
|
|
108
|
+
messageRetentionPeriod
|
|
119
109
|
}
|
|
120
110
|
};
|
|
121
111
|
};
|
|
@@ -125,14 +115,10 @@ const composeR2Arguments = ({
|
|
|
125
115
|
storageClass = "Standard"
|
|
126
116
|
}) => {
|
|
127
117
|
return {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
location: "weur",
|
|
133
|
-
storageClass
|
|
134
|
-
}
|
|
135
|
-
}
|
|
118
|
+
name: resourceName,
|
|
119
|
+
jurisdiction: "eu",
|
|
120
|
+
locationHint: "weur",
|
|
121
|
+
storageClass
|
|
136
122
|
};
|
|
137
123
|
};
|
|
138
124
|
|
|
@@ -155,23 +141,20 @@ const composeResourceName = ({
|
|
|
155
141
|
class Infrastructure {
|
|
156
142
|
project;
|
|
157
143
|
environment;
|
|
158
|
-
sst;
|
|
159
144
|
constructor({
|
|
160
145
|
project,
|
|
161
|
-
environment
|
|
162
|
-
sst
|
|
146
|
+
environment
|
|
163
147
|
}) {
|
|
164
148
|
this.project = project;
|
|
165
149
|
this.environment = environment;
|
|
166
|
-
this.sst = sst;
|
|
167
150
|
}
|
|
168
151
|
/**
|
|
169
152
|
* Creates an instance of Cloudflare KV.
|
|
170
153
|
*/
|
|
171
|
-
kv(options) {
|
|
172
|
-
const { resourceName
|
|
173
|
-
return
|
|
174
|
-
|
|
154
|
+
async kv(options) {
|
|
155
|
+
const { resourceName } = options;
|
|
156
|
+
return await cloudflare.KVNamespace(
|
|
157
|
+
resourceName,
|
|
175
158
|
composeKvArguments({
|
|
176
159
|
resourceName: composeResourceName({
|
|
177
160
|
project: this.project,
|
|
@@ -184,10 +167,10 @@ class Infrastructure {
|
|
|
184
167
|
/**
|
|
185
168
|
* Creates an instance of Cloudflare D1.
|
|
186
169
|
*/
|
|
187
|
-
d1(options) {
|
|
188
|
-
const { resourceName
|
|
189
|
-
return
|
|
190
|
-
|
|
170
|
+
async d1(options) {
|
|
171
|
+
const { resourceName } = options;
|
|
172
|
+
return await cloudflare.D1Database(
|
|
173
|
+
resourceName,
|
|
191
174
|
composeD1Arguments({
|
|
192
175
|
resourceName: composeResourceName({
|
|
193
176
|
project: this.project,
|
|
@@ -200,10 +183,10 @@ class Infrastructure {
|
|
|
200
183
|
/**
|
|
201
184
|
* Creates an instance of Cloudflare Queue.
|
|
202
185
|
*/
|
|
203
|
-
queue(options) {
|
|
204
|
-
const { resourceName,
|
|
205
|
-
return
|
|
206
|
-
|
|
186
|
+
async queue(options) {
|
|
187
|
+
const { resourceName, deliveryDelay, messageRetentionPeriod } = options;
|
|
188
|
+
return await cloudflare.Queue(
|
|
189
|
+
resourceName,
|
|
207
190
|
composeQueueArguments({
|
|
208
191
|
resourceName: composeResourceName({
|
|
209
192
|
project: this.project,
|
|
@@ -218,10 +201,10 @@ class Infrastructure {
|
|
|
218
201
|
/**
|
|
219
202
|
* Creates an instance of Cloudflare R2.
|
|
220
203
|
*/
|
|
221
|
-
r2(options) {
|
|
222
|
-
const { resourceName,
|
|
223
|
-
return
|
|
224
|
-
|
|
204
|
+
async r2(options) {
|
|
205
|
+
const { resourceName, storageClass } = options;
|
|
206
|
+
return await cloudflare.R2Bucket(
|
|
207
|
+
resourceName,
|
|
225
208
|
composeR2Arguments({
|
|
226
209
|
resourceName: composeResourceName({
|
|
227
210
|
project: this.project,
|
package/dist/index.d.cts
CHANGED
|
@@ -4,10 +4,11 @@ import * as drizzle_orm from 'drizzle-orm';
|
|
|
4
4
|
import { ExtractTablesWithRelations, DBQueryConfig, BuildQueryResult } from 'drizzle-orm';
|
|
5
5
|
import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
|
|
6
6
|
import { AnySQLiteTable } from 'drizzle-orm/sqlite-core';
|
|
7
|
+
import { KVNamespace, D1Database, Queue, R2Bucket } from 'alchemy/cloudflare';
|
|
7
8
|
import * as z from 'zod/v4/core';
|
|
8
9
|
import { StatusCodes, ReasonPhrases } from 'http-status-codes';
|
|
9
10
|
export { ReasonPhrases as InternalResponsePhrase, StatusCodes as InternalResponseStatus } from 'http-status-codes';
|
|
10
|
-
import { Queue } from '@cloudflare/workers-types';
|
|
11
|
+
import { Queue as Queue$1 } from '@cloudflare/workers-types';
|
|
11
12
|
import { BatchItem } from 'drizzle-orm/batch';
|
|
12
13
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
13
14
|
|
|
@@ -50,19 +51,12 @@ type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
|
|
|
50
51
|
|
|
51
52
|
type Environment = number | 'dev' | 'test' | 'staging' | 'production';
|
|
52
53
|
|
|
53
|
-
interface SstInstance {
|
|
54
|
-
cloudflare: {
|
|
55
|
-
[key: string]: any;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
54
|
declare class Infrastructure {
|
|
59
55
|
private project;
|
|
60
56
|
private environment;
|
|
61
|
-
|
|
62
|
-
constructor({ project, environment, sst, }: {
|
|
57
|
+
constructor({ project, environment, }: {
|
|
63
58
|
project: Project;
|
|
64
59
|
environment: Environment;
|
|
65
|
-
sst: SstInstance;
|
|
66
60
|
});
|
|
67
61
|
/**
|
|
68
62
|
* Creates an instance of Cloudflare KV.
|
|
@@ -72,11 +66,7 @@ declare class Infrastructure {
|
|
|
72
66
|
* Name of the KV. Do not include the 'kv' prefix.
|
|
73
67
|
*/
|
|
74
68
|
resourceName: string;
|
|
75
|
-
|
|
76
|
-
* Name of the KV's binding. If not set, it is generated automatically based on the provided name.
|
|
77
|
-
*/
|
|
78
|
-
bindingName?: string;
|
|
79
|
-
}): any;
|
|
69
|
+
}): Promise<KVNamespace>;
|
|
80
70
|
/**
|
|
81
71
|
* Creates an instance of Cloudflare D1.
|
|
82
72
|
*/
|
|
@@ -85,11 +75,7 @@ declare class Infrastructure {
|
|
|
85
75
|
* Name of the D1. Do not include the 'd1' prefix.
|
|
86
76
|
*/
|
|
87
77
|
resourceName: string;
|
|
88
|
-
|
|
89
|
-
* Name of the D1's binding. If not set, it is generated automatically based on the provided name.
|
|
90
|
-
*/
|
|
91
|
-
bindingName?: string;
|
|
92
|
-
}): any;
|
|
78
|
+
}): Promise<D1Database>;
|
|
93
79
|
/**
|
|
94
80
|
* Creates an instance of Cloudflare Queue.
|
|
95
81
|
*/
|
|
@@ -98,10 +84,6 @@ declare class Infrastructure {
|
|
|
98
84
|
* Name of the Queue. Do not include the 'queue' prefix.
|
|
99
85
|
*/
|
|
100
86
|
resourceName: string;
|
|
101
|
-
/**
|
|
102
|
-
* Name of the Queue's binding. If not set, it is generated automatically based on the provided name.
|
|
103
|
-
*/
|
|
104
|
-
bindingName?: string;
|
|
105
87
|
/**
|
|
106
88
|
* The number of seconds to delay delivery of messages to the queue.
|
|
107
89
|
*/
|
|
@@ -110,7 +92,7 @@ declare class Infrastructure {
|
|
|
110
92
|
* The number of seconds a message will remain in the queue before being deleted.
|
|
111
93
|
*/
|
|
112
94
|
messageRetentionPeriod?: number;
|
|
113
|
-
}):
|
|
95
|
+
}): Promise<Queue<unknown>>;
|
|
114
96
|
/**
|
|
115
97
|
* Creates an instance of Cloudflare R2.
|
|
116
98
|
*/
|
|
@@ -119,15 +101,11 @@ declare class Infrastructure {
|
|
|
119
101
|
* Name of the R2. Do not include the 'r2' prefix.
|
|
120
102
|
*/
|
|
121
103
|
resourceName: string;
|
|
122
|
-
/**
|
|
123
|
-
* Name of the R2's binding. If not set, it is generated automatically based on the provided name.
|
|
124
|
-
*/
|
|
125
|
-
bindingName?: string;
|
|
126
104
|
/**
|
|
127
105
|
* The storage class for the R2 bucket.
|
|
128
106
|
*/
|
|
129
107
|
storageClass?: 'Standard' | 'InfrequentAccess';
|
|
130
|
-
}):
|
|
108
|
+
}): Promise<R2Bucket>;
|
|
131
109
|
}
|
|
132
110
|
|
|
133
111
|
interface AuditLogPayload<T> {
|
|
@@ -244,8 +222,8 @@ interface DevelitWorkerMethods {
|
|
|
244
222
|
logInput(data: object): void;
|
|
245
223
|
logOutput(data: object): void;
|
|
246
224
|
logError(error: object): void;
|
|
247
|
-
pushToQueue<T>(queue: Queue, message: T | T[]): Promise<void>;
|
|
248
|
-
recordAuditLogMessage<T>(queue: Queue, message: T | T[]): Promise<void>;
|
|
225
|
+
pushToQueue<T>(queue: Queue$1, message: T | T[]): Promise<void>;
|
|
226
|
+
recordAuditLogMessage<T>(queue: Queue$1, message: T | T[]): Promise<void>;
|
|
249
227
|
handleInput<T extends z.$ZodType>(args: {
|
|
250
228
|
input: z.infer<T>;
|
|
251
229
|
schema: T;
|
|
@@ -329,7 +307,7 @@ type AuditLogWriter<TAuditAction = string> = (logs: AuditLogPayload<TAuditAction
|
|
|
329
307
|
*/
|
|
330
308
|
declare function createAuditLogWriter<TAuditAction = string>(table: AuditLogTable): AuditLogWriter<TAuditAction>;
|
|
331
309
|
|
|
332
|
-
declare function durableObjectNamespaceIdFromName(uniqueKey: string, name: string):
|
|
310
|
+
declare function durableObjectNamespaceIdFromName(uniqueKey: string, name: string): any;
|
|
333
311
|
declare const getD1DatabaseIdFromWrangler: () => string | undefined;
|
|
334
312
|
declare const getD1Credentials: () => {
|
|
335
313
|
driver?: undefined;
|
|
@@ -337,14 +315,14 @@ declare const getD1Credentials: () => {
|
|
|
337
315
|
} | {
|
|
338
316
|
driver: string;
|
|
339
317
|
dbCredentials: {
|
|
340
|
-
accountId:
|
|
318
|
+
accountId: any;
|
|
341
319
|
databaseId: string;
|
|
342
|
-
token:
|
|
320
|
+
token: any;
|
|
343
321
|
url?: undefined;
|
|
344
322
|
};
|
|
345
323
|
} | {
|
|
346
324
|
dbCredentials: {
|
|
347
|
-
url:
|
|
325
|
+
url: any;
|
|
348
326
|
accountId?: undefined;
|
|
349
327
|
databaseId?: undefined;
|
|
350
328
|
token?: undefined;
|
|
@@ -360,9 +338,9 @@ declare const getDrizzleD1Config: () => {
|
|
|
360
338
|
} | {
|
|
361
339
|
driver: string;
|
|
362
340
|
dbCredentials: {
|
|
363
|
-
accountId:
|
|
341
|
+
accountId: any;
|
|
364
342
|
databaseId: string;
|
|
365
|
-
token:
|
|
343
|
+
token: any;
|
|
366
344
|
url?: undefined;
|
|
367
345
|
};
|
|
368
346
|
schema: string;
|
|
@@ -370,7 +348,7 @@ declare const getDrizzleD1Config: () => {
|
|
|
370
348
|
dialect: "sqlite";
|
|
371
349
|
} | {
|
|
372
350
|
dbCredentials: {
|
|
373
|
-
url:
|
|
351
|
+
url: any;
|
|
374
352
|
accountId?: undefined;
|
|
375
353
|
databaseId?: undefined;
|
|
376
354
|
token?: undefined;
|
|
@@ -428,7 +406,7 @@ declare const getPgLocalConnectionString: (id: string) => string;
|
|
|
428
406
|
declare const getPgDatabaseIdFromWrangler: () => string | undefined;
|
|
429
407
|
declare const getPgCredentials: (serviceName?: string) => {
|
|
430
408
|
dbCredentials: {
|
|
431
|
-
url:
|
|
409
|
+
url: any;
|
|
432
410
|
};
|
|
433
411
|
};
|
|
434
412
|
declare const getDrizzlePgConfig: () => {
|
|
@@ -437,7 +415,7 @@ declare const getDrizzlePgConfig: () => {
|
|
|
437
415
|
schema: string;
|
|
438
416
|
};
|
|
439
417
|
dbCredentials: {
|
|
440
|
-
url:
|
|
418
|
+
url: any;
|
|
441
419
|
};
|
|
442
420
|
schema: string;
|
|
443
421
|
out: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -4,10 +4,11 @@ import * as drizzle_orm from 'drizzle-orm';
|
|
|
4
4
|
import { ExtractTablesWithRelations, DBQueryConfig, BuildQueryResult } from 'drizzle-orm';
|
|
5
5
|
import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
|
|
6
6
|
import { AnySQLiteTable } from 'drizzle-orm/sqlite-core';
|
|
7
|
+
import { KVNamespace, D1Database, Queue, R2Bucket } from 'alchemy/cloudflare';
|
|
7
8
|
import * as z from 'zod/v4/core';
|
|
8
9
|
import { StatusCodes, ReasonPhrases } from 'http-status-codes';
|
|
9
10
|
export { ReasonPhrases as InternalResponsePhrase, StatusCodes as InternalResponseStatus } from 'http-status-codes';
|
|
10
|
-
import { Queue } from '@cloudflare/workers-types';
|
|
11
|
+
import { Queue as Queue$1 } from '@cloudflare/workers-types';
|
|
11
12
|
import { BatchItem } from 'drizzle-orm/batch';
|
|
12
13
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
13
14
|
|
|
@@ -50,19 +51,12 @@ type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
|
|
|
50
51
|
|
|
51
52
|
type Environment = number | 'dev' | 'test' | 'staging' | 'production';
|
|
52
53
|
|
|
53
|
-
interface SstInstance {
|
|
54
|
-
cloudflare: {
|
|
55
|
-
[key: string]: any;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
54
|
declare class Infrastructure {
|
|
59
55
|
private project;
|
|
60
56
|
private environment;
|
|
61
|
-
|
|
62
|
-
constructor({ project, environment, sst, }: {
|
|
57
|
+
constructor({ project, environment, }: {
|
|
63
58
|
project: Project;
|
|
64
59
|
environment: Environment;
|
|
65
|
-
sst: SstInstance;
|
|
66
60
|
});
|
|
67
61
|
/**
|
|
68
62
|
* Creates an instance of Cloudflare KV.
|
|
@@ -72,11 +66,7 @@ declare class Infrastructure {
|
|
|
72
66
|
* Name of the KV. Do not include the 'kv' prefix.
|
|
73
67
|
*/
|
|
74
68
|
resourceName: string;
|
|
75
|
-
|
|
76
|
-
* Name of the KV's binding. If not set, it is generated automatically based on the provided name.
|
|
77
|
-
*/
|
|
78
|
-
bindingName?: string;
|
|
79
|
-
}): any;
|
|
69
|
+
}): Promise<KVNamespace>;
|
|
80
70
|
/**
|
|
81
71
|
* Creates an instance of Cloudflare D1.
|
|
82
72
|
*/
|
|
@@ -85,11 +75,7 @@ declare class Infrastructure {
|
|
|
85
75
|
* Name of the D1. Do not include the 'd1' prefix.
|
|
86
76
|
*/
|
|
87
77
|
resourceName: string;
|
|
88
|
-
|
|
89
|
-
* Name of the D1's binding. If not set, it is generated automatically based on the provided name.
|
|
90
|
-
*/
|
|
91
|
-
bindingName?: string;
|
|
92
|
-
}): any;
|
|
78
|
+
}): Promise<D1Database>;
|
|
93
79
|
/**
|
|
94
80
|
* Creates an instance of Cloudflare Queue.
|
|
95
81
|
*/
|
|
@@ -98,10 +84,6 @@ declare class Infrastructure {
|
|
|
98
84
|
* Name of the Queue. Do not include the 'queue' prefix.
|
|
99
85
|
*/
|
|
100
86
|
resourceName: string;
|
|
101
|
-
/**
|
|
102
|
-
* Name of the Queue's binding. If not set, it is generated automatically based on the provided name.
|
|
103
|
-
*/
|
|
104
|
-
bindingName?: string;
|
|
105
87
|
/**
|
|
106
88
|
* The number of seconds to delay delivery of messages to the queue.
|
|
107
89
|
*/
|
|
@@ -110,7 +92,7 @@ declare class Infrastructure {
|
|
|
110
92
|
* The number of seconds a message will remain in the queue before being deleted.
|
|
111
93
|
*/
|
|
112
94
|
messageRetentionPeriod?: number;
|
|
113
|
-
}):
|
|
95
|
+
}): Promise<Queue<unknown>>;
|
|
114
96
|
/**
|
|
115
97
|
* Creates an instance of Cloudflare R2.
|
|
116
98
|
*/
|
|
@@ -119,15 +101,11 @@ declare class Infrastructure {
|
|
|
119
101
|
* Name of the R2. Do not include the 'r2' prefix.
|
|
120
102
|
*/
|
|
121
103
|
resourceName: string;
|
|
122
|
-
/**
|
|
123
|
-
* Name of the R2's binding. If not set, it is generated automatically based on the provided name.
|
|
124
|
-
*/
|
|
125
|
-
bindingName?: string;
|
|
126
104
|
/**
|
|
127
105
|
* The storage class for the R2 bucket.
|
|
128
106
|
*/
|
|
129
107
|
storageClass?: 'Standard' | 'InfrequentAccess';
|
|
130
|
-
}):
|
|
108
|
+
}): Promise<R2Bucket>;
|
|
131
109
|
}
|
|
132
110
|
|
|
133
111
|
interface AuditLogPayload<T> {
|
|
@@ -244,8 +222,8 @@ interface DevelitWorkerMethods {
|
|
|
244
222
|
logInput(data: object): void;
|
|
245
223
|
logOutput(data: object): void;
|
|
246
224
|
logError(error: object): void;
|
|
247
|
-
pushToQueue<T>(queue: Queue, message: T | T[]): Promise<void>;
|
|
248
|
-
recordAuditLogMessage<T>(queue: Queue, message: T | T[]): Promise<void>;
|
|
225
|
+
pushToQueue<T>(queue: Queue$1, message: T | T[]): Promise<void>;
|
|
226
|
+
recordAuditLogMessage<T>(queue: Queue$1, message: T | T[]): Promise<void>;
|
|
249
227
|
handleInput<T extends z.$ZodType>(args: {
|
|
250
228
|
input: z.infer<T>;
|
|
251
229
|
schema: T;
|
|
@@ -329,7 +307,7 @@ type AuditLogWriter<TAuditAction = string> = (logs: AuditLogPayload<TAuditAction
|
|
|
329
307
|
*/
|
|
330
308
|
declare function createAuditLogWriter<TAuditAction = string>(table: AuditLogTable): AuditLogWriter<TAuditAction>;
|
|
331
309
|
|
|
332
|
-
declare function durableObjectNamespaceIdFromName(uniqueKey: string, name: string):
|
|
310
|
+
declare function durableObjectNamespaceIdFromName(uniqueKey: string, name: string): any;
|
|
333
311
|
declare const getD1DatabaseIdFromWrangler: () => string | undefined;
|
|
334
312
|
declare const getD1Credentials: () => {
|
|
335
313
|
driver?: undefined;
|
|
@@ -337,14 +315,14 @@ declare const getD1Credentials: () => {
|
|
|
337
315
|
} | {
|
|
338
316
|
driver: string;
|
|
339
317
|
dbCredentials: {
|
|
340
|
-
accountId:
|
|
318
|
+
accountId: any;
|
|
341
319
|
databaseId: string;
|
|
342
|
-
token:
|
|
320
|
+
token: any;
|
|
343
321
|
url?: undefined;
|
|
344
322
|
};
|
|
345
323
|
} | {
|
|
346
324
|
dbCredentials: {
|
|
347
|
-
url:
|
|
325
|
+
url: any;
|
|
348
326
|
accountId?: undefined;
|
|
349
327
|
databaseId?: undefined;
|
|
350
328
|
token?: undefined;
|
|
@@ -360,9 +338,9 @@ declare const getDrizzleD1Config: () => {
|
|
|
360
338
|
} | {
|
|
361
339
|
driver: string;
|
|
362
340
|
dbCredentials: {
|
|
363
|
-
accountId:
|
|
341
|
+
accountId: any;
|
|
364
342
|
databaseId: string;
|
|
365
|
-
token:
|
|
343
|
+
token: any;
|
|
366
344
|
url?: undefined;
|
|
367
345
|
};
|
|
368
346
|
schema: string;
|
|
@@ -370,7 +348,7 @@ declare const getDrizzleD1Config: () => {
|
|
|
370
348
|
dialect: "sqlite";
|
|
371
349
|
} | {
|
|
372
350
|
dbCredentials: {
|
|
373
|
-
url:
|
|
351
|
+
url: any;
|
|
374
352
|
accountId?: undefined;
|
|
375
353
|
databaseId?: undefined;
|
|
376
354
|
token?: undefined;
|
|
@@ -428,7 +406,7 @@ declare const getPgLocalConnectionString: (id: string) => string;
|
|
|
428
406
|
declare const getPgDatabaseIdFromWrangler: () => string | undefined;
|
|
429
407
|
declare const getPgCredentials: (serviceName?: string) => {
|
|
430
408
|
dbCredentials: {
|
|
431
|
-
url:
|
|
409
|
+
url: any;
|
|
432
410
|
};
|
|
433
411
|
};
|
|
434
412
|
declare const getDrizzlePgConfig: () => {
|
|
@@ -437,7 +415,7 @@ declare const getDrizzlePgConfig: () => {
|
|
|
437
415
|
schema: string;
|
|
438
416
|
};
|
|
439
417
|
dbCredentials: {
|
|
440
|
-
url:
|
|
418
|
+
url: any;
|
|
441
419
|
};
|
|
442
420
|
schema: string;
|
|
443
421
|
out: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,10 +4,11 @@ import * as drizzle_orm from 'drizzle-orm';
|
|
|
4
4
|
import { ExtractTablesWithRelations, DBQueryConfig, BuildQueryResult } from 'drizzle-orm';
|
|
5
5
|
import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
|
|
6
6
|
import { AnySQLiteTable } from 'drizzle-orm/sqlite-core';
|
|
7
|
+
import { KVNamespace, D1Database, Queue, R2Bucket } from 'alchemy/cloudflare';
|
|
7
8
|
import * as z from 'zod/v4/core';
|
|
8
9
|
import { StatusCodes, ReasonPhrases } from 'http-status-codes';
|
|
9
10
|
export { ReasonPhrases as InternalResponsePhrase, StatusCodes as InternalResponseStatus } from 'http-status-codes';
|
|
10
|
-
import { Queue } from '@cloudflare/workers-types';
|
|
11
|
+
import { Queue as Queue$1 } from '@cloudflare/workers-types';
|
|
11
12
|
import { BatchItem } from 'drizzle-orm/batch';
|
|
12
13
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
13
14
|
|
|
@@ -50,19 +51,12 @@ type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
|
|
|
50
51
|
|
|
51
52
|
type Environment = number | 'dev' | 'test' | 'staging' | 'production';
|
|
52
53
|
|
|
53
|
-
interface SstInstance {
|
|
54
|
-
cloudflare: {
|
|
55
|
-
[key: string]: any;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
54
|
declare class Infrastructure {
|
|
59
55
|
private project;
|
|
60
56
|
private environment;
|
|
61
|
-
|
|
62
|
-
constructor({ project, environment, sst, }: {
|
|
57
|
+
constructor({ project, environment, }: {
|
|
63
58
|
project: Project;
|
|
64
59
|
environment: Environment;
|
|
65
|
-
sst: SstInstance;
|
|
66
60
|
});
|
|
67
61
|
/**
|
|
68
62
|
* Creates an instance of Cloudflare KV.
|
|
@@ -72,11 +66,7 @@ declare class Infrastructure {
|
|
|
72
66
|
* Name of the KV. Do not include the 'kv' prefix.
|
|
73
67
|
*/
|
|
74
68
|
resourceName: string;
|
|
75
|
-
|
|
76
|
-
* Name of the KV's binding. If not set, it is generated automatically based on the provided name.
|
|
77
|
-
*/
|
|
78
|
-
bindingName?: string;
|
|
79
|
-
}): any;
|
|
69
|
+
}): Promise<KVNamespace>;
|
|
80
70
|
/**
|
|
81
71
|
* Creates an instance of Cloudflare D1.
|
|
82
72
|
*/
|
|
@@ -85,11 +75,7 @@ declare class Infrastructure {
|
|
|
85
75
|
* Name of the D1. Do not include the 'd1' prefix.
|
|
86
76
|
*/
|
|
87
77
|
resourceName: string;
|
|
88
|
-
|
|
89
|
-
* Name of the D1's binding. If not set, it is generated automatically based on the provided name.
|
|
90
|
-
*/
|
|
91
|
-
bindingName?: string;
|
|
92
|
-
}): any;
|
|
78
|
+
}): Promise<D1Database>;
|
|
93
79
|
/**
|
|
94
80
|
* Creates an instance of Cloudflare Queue.
|
|
95
81
|
*/
|
|
@@ -98,10 +84,6 @@ declare class Infrastructure {
|
|
|
98
84
|
* Name of the Queue. Do not include the 'queue' prefix.
|
|
99
85
|
*/
|
|
100
86
|
resourceName: string;
|
|
101
|
-
/**
|
|
102
|
-
* Name of the Queue's binding. If not set, it is generated automatically based on the provided name.
|
|
103
|
-
*/
|
|
104
|
-
bindingName?: string;
|
|
105
87
|
/**
|
|
106
88
|
* The number of seconds to delay delivery of messages to the queue.
|
|
107
89
|
*/
|
|
@@ -110,7 +92,7 @@ declare class Infrastructure {
|
|
|
110
92
|
* The number of seconds a message will remain in the queue before being deleted.
|
|
111
93
|
*/
|
|
112
94
|
messageRetentionPeriod?: number;
|
|
113
|
-
}):
|
|
95
|
+
}): Promise<Queue<unknown>>;
|
|
114
96
|
/**
|
|
115
97
|
* Creates an instance of Cloudflare R2.
|
|
116
98
|
*/
|
|
@@ -119,15 +101,11 @@ declare class Infrastructure {
|
|
|
119
101
|
* Name of the R2. Do not include the 'r2' prefix.
|
|
120
102
|
*/
|
|
121
103
|
resourceName: string;
|
|
122
|
-
/**
|
|
123
|
-
* Name of the R2's binding. If not set, it is generated automatically based on the provided name.
|
|
124
|
-
*/
|
|
125
|
-
bindingName?: string;
|
|
126
104
|
/**
|
|
127
105
|
* The storage class for the R2 bucket.
|
|
128
106
|
*/
|
|
129
107
|
storageClass?: 'Standard' | 'InfrequentAccess';
|
|
130
|
-
}):
|
|
108
|
+
}): Promise<R2Bucket>;
|
|
131
109
|
}
|
|
132
110
|
|
|
133
111
|
interface AuditLogPayload<T> {
|
|
@@ -244,8 +222,8 @@ interface DevelitWorkerMethods {
|
|
|
244
222
|
logInput(data: object): void;
|
|
245
223
|
logOutput(data: object): void;
|
|
246
224
|
logError(error: object): void;
|
|
247
|
-
pushToQueue<T>(queue: Queue, message: T | T[]): Promise<void>;
|
|
248
|
-
recordAuditLogMessage<T>(queue: Queue, message: T | T[]): Promise<void>;
|
|
225
|
+
pushToQueue<T>(queue: Queue$1, message: T | T[]): Promise<void>;
|
|
226
|
+
recordAuditLogMessage<T>(queue: Queue$1, message: T | T[]): Promise<void>;
|
|
249
227
|
handleInput<T extends z.$ZodType>(args: {
|
|
250
228
|
input: z.infer<T>;
|
|
251
229
|
schema: T;
|
|
@@ -329,7 +307,7 @@ type AuditLogWriter<TAuditAction = string> = (logs: AuditLogPayload<TAuditAction
|
|
|
329
307
|
*/
|
|
330
308
|
declare function createAuditLogWriter<TAuditAction = string>(table: AuditLogTable): AuditLogWriter<TAuditAction>;
|
|
331
309
|
|
|
332
|
-
declare function durableObjectNamespaceIdFromName(uniqueKey: string, name: string):
|
|
310
|
+
declare function durableObjectNamespaceIdFromName(uniqueKey: string, name: string): any;
|
|
333
311
|
declare const getD1DatabaseIdFromWrangler: () => string | undefined;
|
|
334
312
|
declare const getD1Credentials: () => {
|
|
335
313
|
driver?: undefined;
|
|
@@ -337,14 +315,14 @@ declare const getD1Credentials: () => {
|
|
|
337
315
|
} | {
|
|
338
316
|
driver: string;
|
|
339
317
|
dbCredentials: {
|
|
340
|
-
accountId:
|
|
318
|
+
accountId: any;
|
|
341
319
|
databaseId: string;
|
|
342
|
-
token:
|
|
320
|
+
token: any;
|
|
343
321
|
url?: undefined;
|
|
344
322
|
};
|
|
345
323
|
} | {
|
|
346
324
|
dbCredentials: {
|
|
347
|
-
url:
|
|
325
|
+
url: any;
|
|
348
326
|
accountId?: undefined;
|
|
349
327
|
databaseId?: undefined;
|
|
350
328
|
token?: undefined;
|
|
@@ -360,9 +338,9 @@ declare const getDrizzleD1Config: () => {
|
|
|
360
338
|
} | {
|
|
361
339
|
driver: string;
|
|
362
340
|
dbCredentials: {
|
|
363
|
-
accountId:
|
|
341
|
+
accountId: any;
|
|
364
342
|
databaseId: string;
|
|
365
|
-
token:
|
|
343
|
+
token: any;
|
|
366
344
|
url?: undefined;
|
|
367
345
|
};
|
|
368
346
|
schema: string;
|
|
@@ -370,7 +348,7 @@ declare const getDrizzleD1Config: () => {
|
|
|
370
348
|
dialect: "sqlite";
|
|
371
349
|
} | {
|
|
372
350
|
dbCredentials: {
|
|
373
|
-
url:
|
|
351
|
+
url: any;
|
|
374
352
|
accountId?: undefined;
|
|
375
353
|
databaseId?: undefined;
|
|
376
354
|
token?: undefined;
|
|
@@ -428,7 +406,7 @@ declare const getPgLocalConnectionString: (id: string) => string;
|
|
|
428
406
|
declare const getPgDatabaseIdFromWrangler: () => string | undefined;
|
|
429
407
|
declare const getPgCredentials: (serviceName?: string) => {
|
|
430
408
|
dbCredentials: {
|
|
431
|
-
url:
|
|
409
|
+
url: any;
|
|
432
410
|
};
|
|
433
411
|
};
|
|
434
412
|
declare const getDrizzlePgConfig: () => {
|
|
@@ -437,7 +415,7 @@ declare const getDrizzlePgConfig: () => {
|
|
|
437
415
|
schema: string;
|
|
438
416
|
};
|
|
439
417
|
dbCredentials: {
|
|
440
|
-
url:
|
|
418
|
+
url: any;
|
|
441
419
|
};
|
|
442
420
|
schema: string;
|
|
443
421
|
out: string;
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { timestamp, uuid, pgEnum, text as text$1 } from 'drizzle-orm/pg-core';
|
|
|
3
3
|
import { integer, text } from 'drizzle-orm/sqlite-core';
|
|
4
4
|
import { COUNTRY_CODES_2, CURRENCY_CODES, BANK_CODES } from '@develit-io/general-codes';
|
|
5
5
|
import { toSnakeCase } from '@std/text';
|
|
6
|
+
import { KVNamespace, D1Database, Queue, R2Bucket } from 'alchemy/cloudflare';
|
|
6
7
|
import * as z from 'zod/v4/core';
|
|
7
8
|
import 'http-status-codes';
|
|
8
9
|
import { createError } from 'h3';
|
|
@@ -59,12 +60,9 @@ const composeD1Arguments = ({
|
|
|
59
60
|
resourceName
|
|
60
61
|
}) => {
|
|
61
62
|
return {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
primaryLocationHint: "weur"
|
|
66
|
-
}
|
|
67
|
-
}
|
|
63
|
+
name: resourceName,
|
|
64
|
+
primaryLocationHint: "weur"
|
|
65
|
+
// TODO: It's possible that it will take care of migrations as well
|
|
68
66
|
};
|
|
69
67
|
};
|
|
70
68
|
|
|
@@ -72,11 +70,7 @@ const composeKvArguments = ({
|
|
|
72
70
|
resourceName
|
|
73
71
|
}) => {
|
|
74
72
|
return {
|
|
75
|
-
|
|
76
|
-
namespace: {
|
|
77
|
-
title: resourceName
|
|
78
|
-
}
|
|
79
|
-
}
|
|
73
|
+
title: resourceName
|
|
80
74
|
};
|
|
81
75
|
};
|
|
82
76
|
|
|
@@ -86,14 +80,10 @@ const composeQueueArguments = ({
|
|
|
86
80
|
messageRetentionPeriod = 259200
|
|
87
81
|
}) => {
|
|
88
82
|
return {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
deliveryDelay,
|
|
94
|
-
messageRetentionPeriod
|
|
95
|
-
}
|
|
96
|
-
}
|
|
83
|
+
name: resourceName,
|
|
84
|
+
settings: {
|
|
85
|
+
deliveryDelay,
|
|
86
|
+
messageRetentionPeriod
|
|
97
87
|
}
|
|
98
88
|
};
|
|
99
89
|
};
|
|
@@ -103,14 +93,10 @@ const composeR2Arguments = ({
|
|
|
103
93
|
storageClass = "Standard"
|
|
104
94
|
}) => {
|
|
105
95
|
return {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
location: "weur",
|
|
111
|
-
storageClass
|
|
112
|
-
}
|
|
113
|
-
}
|
|
96
|
+
name: resourceName,
|
|
97
|
+
jurisdiction: "eu",
|
|
98
|
+
locationHint: "weur",
|
|
99
|
+
storageClass
|
|
114
100
|
};
|
|
115
101
|
};
|
|
116
102
|
|
|
@@ -133,23 +119,20 @@ const composeResourceName = ({
|
|
|
133
119
|
class Infrastructure {
|
|
134
120
|
project;
|
|
135
121
|
environment;
|
|
136
|
-
sst;
|
|
137
122
|
constructor({
|
|
138
123
|
project,
|
|
139
|
-
environment
|
|
140
|
-
sst
|
|
124
|
+
environment
|
|
141
125
|
}) {
|
|
142
126
|
this.project = project;
|
|
143
127
|
this.environment = environment;
|
|
144
|
-
this.sst = sst;
|
|
145
128
|
}
|
|
146
129
|
/**
|
|
147
130
|
* Creates an instance of Cloudflare KV.
|
|
148
131
|
*/
|
|
149
|
-
kv(options) {
|
|
150
|
-
const { resourceName
|
|
151
|
-
return
|
|
152
|
-
|
|
132
|
+
async kv(options) {
|
|
133
|
+
const { resourceName } = options;
|
|
134
|
+
return await KVNamespace(
|
|
135
|
+
resourceName,
|
|
153
136
|
composeKvArguments({
|
|
154
137
|
resourceName: composeResourceName({
|
|
155
138
|
project: this.project,
|
|
@@ -162,10 +145,10 @@ class Infrastructure {
|
|
|
162
145
|
/**
|
|
163
146
|
* Creates an instance of Cloudflare D1.
|
|
164
147
|
*/
|
|
165
|
-
d1(options) {
|
|
166
|
-
const { resourceName
|
|
167
|
-
return
|
|
168
|
-
|
|
148
|
+
async d1(options) {
|
|
149
|
+
const { resourceName } = options;
|
|
150
|
+
return await D1Database(
|
|
151
|
+
resourceName,
|
|
169
152
|
composeD1Arguments({
|
|
170
153
|
resourceName: composeResourceName({
|
|
171
154
|
project: this.project,
|
|
@@ -178,10 +161,10 @@ class Infrastructure {
|
|
|
178
161
|
/**
|
|
179
162
|
* Creates an instance of Cloudflare Queue.
|
|
180
163
|
*/
|
|
181
|
-
queue(options) {
|
|
182
|
-
const { resourceName,
|
|
183
|
-
return
|
|
184
|
-
|
|
164
|
+
async queue(options) {
|
|
165
|
+
const { resourceName, deliveryDelay, messageRetentionPeriod } = options;
|
|
166
|
+
return await Queue(
|
|
167
|
+
resourceName,
|
|
185
168
|
composeQueueArguments({
|
|
186
169
|
resourceName: composeResourceName({
|
|
187
170
|
project: this.project,
|
|
@@ -196,10 +179,10 @@ class Infrastructure {
|
|
|
196
179
|
/**
|
|
197
180
|
* Creates an instance of Cloudflare R2.
|
|
198
181
|
*/
|
|
199
|
-
r2(options) {
|
|
200
|
-
const { resourceName,
|
|
201
|
-
return
|
|
202
|
-
|
|
182
|
+
async r2(options) {
|
|
183
|
+
const { resourceName, storageClass } = options;
|
|
184
|
+
return await R2Bucket(
|
|
185
|
+
resourceName,
|
|
203
186
|
composeR2Arguments({
|
|
204
187
|
resourceName: composeResourceName({
|
|
205
188
|
project: this.project,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@develit-io/backend-sdk",
|
|
3
|
-
"version": "5.21.
|
|
3
|
+
"version": "5.21.1",
|
|
4
4
|
"description": "Develit Backend SDK",
|
|
5
5
|
"author": "Develit.io",
|
|
6
6
|
"license": "ISC",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@cloudflare/workers-types": "4.20250923.0",
|
|
37
|
-
"@pulumi/cloudflare": "^6.9.1",
|
|
38
37
|
"@std/path": "npm:@jsr/std__path",
|
|
39
38
|
"@std/text": "npm:@jsr/std__text",
|
|
39
|
+
"alchemy": "^0.69.0",
|
|
40
40
|
"comment-json": "^4.2.5",
|
|
41
41
|
"drizzle-kit": "^0.31.4",
|
|
42
42
|
"drizzle-orm": "^0.44.5",
|