@develit-io/backend-sdk 5.30.3 → 5.30.5
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 +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.mjs +5 -3
- package/package.json +5 -18
- package/dist/deployment/index.cjs +0 -357
- package/dist/deployment/index.d.cts +0 -252
- package/dist/deployment/index.d.mts +0 -252
- package/dist/deployment/index.d.ts +0 -252
- package/dist/deployment/index.mjs +0 -344
- package/dist/index.cjs +0 -783
- package/dist/index.d.cts +0 -443
- package/dist/node/index.cjs +0 -13
- package/dist/node/index.d.cts +0 -3
- package/dist/node/index.d.mts +0 -3
- package/dist/node/index.d.ts +0 -3
- package/dist/node/index.mjs +0 -4
- package/dist/shared/backend-sdk.BdcrYpFD.cjs +0 -5
- package/dist/shared/backend-sdk.C-0xIdM4.d.mts +0 -69
- package/dist/shared/backend-sdk.CP78x0gl.d.cts +0 -3
- package/dist/shared/backend-sdk.CP78x0gl.d.mts +0 -3
- package/dist/shared/backend-sdk.CP78x0gl.d.ts +0 -3
- package/dist/shared/backend-sdk.CYcpgphg.d.cts +0 -3
- package/dist/shared/backend-sdk.CYcpgphg.d.mts +0 -3
- package/dist/shared/backend-sdk.CYcpgphg.d.ts +0 -3
- package/dist/shared/backend-sdk.CdngrAa0.d.cts +0 -69
- package/dist/shared/backend-sdk.DXRpnctc.mjs +0 -3
- package/dist/shared/backend-sdk.Fdiq3Ek5.mjs +0 -70
- package/dist/shared/backend-sdk.Vru_rcK6.cjs +0 -85
- package/dist/shared/backend-sdk.qPzlx18G.d.ts +0 -69
package/dist/index.d.mts
CHANGED
|
@@ -5,14 +5,14 @@ import { ExtractTablesWithRelations, DBQueryConfig, BuildQueryResult } from 'dri
|
|
|
5
5
|
import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
|
|
6
6
|
import { AnySQLiteTable } from 'drizzle-orm/sqlite-core';
|
|
7
7
|
import * as z from 'zod/v4/core';
|
|
8
|
-
export { E as Environment } from './shared/backend-sdk.CYcpgphg.mjs';
|
|
9
|
-
export { P as Project } from './shared/backend-sdk.CP78x0gl.mjs';
|
|
10
8
|
import { StatusCodes, ReasonPhrases } from 'http-status-codes';
|
|
11
9
|
export { ReasonPhrases as InternalResponsePhrase, StatusCodes as InternalResponseStatus } from 'http-status-codes';
|
|
12
10
|
import { Queue } from '@cloudflare/workers-types';
|
|
13
11
|
import { BatchItem } from 'drizzle-orm/batch';
|
|
14
12
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
15
13
|
|
|
14
|
+
declare const uuidv4: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
15
|
+
|
|
16
16
|
declare const base: {
|
|
17
17
|
id: drizzle_orm.IsPrimaryKey<drizzle_orm.NotNull<drizzle_orm_sqlite_core.SQLiteTextBuilderInitial<"id", [string, ...string[]], number | undefined>>>;
|
|
18
18
|
createdAt: drizzle_orm.HasDefault<drizzle_orm_sqlite_core.SQLiteTimestampBuilderInitial<"created_at">>;
|
|
@@ -50,6 +50,10 @@ declare const bankAccountPostgres: {
|
|
|
50
50
|
|
|
51
51
|
declare const ENVIRONMENT: string[];
|
|
52
52
|
|
|
53
|
+
type Environment = string | 'dev' | 'test' | 'staging' | 'production';
|
|
54
|
+
|
|
55
|
+
type Project = 'creditio' | 'paycorp-fiat-processor' | 'dbu-mdm' | 'moneio' | 'dbu-txs' | 'lrf-website';
|
|
56
|
+
|
|
53
57
|
interface AuditLogPayload<T> {
|
|
54
58
|
action: T;
|
|
55
59
|
actorId: string;
|
|
@@ -317,7 +321,6 @@ declare class DatabaseTransaction<TAuditAction = string> {
|
|
|
317
321
|
|
|
318
322
|
declare function first<T>(rows: T[]): T | undefined;
|
|
319
323
|
declare function firstOrError<T>(rows: T[]): T;
|
|
320
|
-
declare const uuidv4: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
321
324
|
declare function derivePortFromId(id: string, base?: number, range?: number): number;
|
|
322
325
|
|
|
323
326
|
declare const createInternalError: (error: unknown, details?: {
|
|
@@ -440,4 +443,4 @@ type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...a
|
|
|
440
443
|
declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
|
|
441
444
|
|
|
442
445
|
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, action, bankAccount, bankAccountBankCodeEnum, bankAccountCountryCodeEnum, bankAccountCurrencyEnum, bankAccountPostgres, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useFetch, useResult, useResultSync, uuidv4 };
|
|
443
|
-
export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, ValidatedInput };
|
|
446
|
+
export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,14 +5,14 @@ import { ExtractTablesWithRelations, DBQueryConfig, BuildQueryResult } from 'dri
|
|
|
5
5
|
import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
|
|
6
6
|
import { AnySQLiteTable } from 'drizzle-orm/sqlite-core';
|
|
7
7
|
import * as z from 'zod/v4/core';
|
|
8
|
-
export { E as Environment } from './shared/backend-sdk.CYcpgphg.js';
|
|
9
|
-
export { P as Project } from './shared/backend-sdk.CP78x0gl.js';
|
|
10
8
|
import { StatusCodes, ReasonPhrases } from 'http-status-codes';
|
|
11
9
|
export { ReasonPhrases as InternalResponsePhrase, StatusCodes as InternalResponseStatus } from 'http-status-codes';
|
|
12
10
|
import { Queue } from '@cloudflare/workers-types';
|
|
13
11
|
import { BatchItem } from 'drizzle-orm/batch';
|
|
14
12
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
15
13
|
|
|
14
|
+
declare const uuidv4: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
15
|
+
|
|
16
16
|
declare const base: {
|
|
17
17
|
id: drizzle_orm.IsPrimaryKey<drizzle_orm.NotNull<drizzle_orm_sqlite_core.SQLiteTextBuilderInitial<"id", [string, ...string[]], number | undefined>>>;
|
|
18
18
|
createdAt: drizzle_orm.HasDefault<drizzle_orm_sqlite_core.SQLiteTimestampBuilderInitial<"created_at">>;
|
|
@@ -50,6 +50,10 @@ declare const bankAccountPostgres: {
|
|
|
50
50
|
|
|
51
51
|
declare const ENVIRONMENT: string[];
|
|
52
52
|
|
|
53
|
+
type Environment = string | 'dev' | 'test' | 'staging' | 'production';
|
|
54
|
+
|
|
55
|
+
type Project = 'creditio' | 'paycorp-fiat-processor' | 'dbu-mdm' | 'moneio' | 'dbu-txs' | 'lrf-website';
|
|
56
|
+
|
|
53
57
|
interface AuditLogPayload<T> {
|
|
54
58
|
action: T;
|
|
55
59
|
actorId: string;
|
|
@@ -317,7 +321,6 @@ declare class DatabaseTransaction<TAuditAction = string> {
|
|
|
317
321
|
|
|
318
322
|
declare function first<T>(rows: T[]): T | undefined;
|
|
319
323
|
declare function firstOrError<T>(rows: T[]): T;
|
|
320
|
-
declare const uuidv4: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
321
324
|
declare function derivePortFromId(id: string, base?: number, range?: number): number;
|
|
322
325
|
|
|
323
326
|
declare const createInternalError: (error: unknown, details?: {
|
|
@@ -440,4 +443,4 @@ type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...a
|
|
|
440
443
|
declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
|
|
441
444
|
|
|
442
445
|
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, action, bankAccount, bankAccountBankCodeEnum, bankAccountCountryCodeEnum, bankAccountCurrencyEnum, bankAccountPostgres, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useFetch, useResult, useResultSync, uuidv4 };
|
|
443
|
-
export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, ValidatedInput };
|
|
446
|
+
export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { sql } from 'drizzle-orm';
|
|
|
2
2
|
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
|
-
export { E as ENVIRONMENT } from './shared/backend-sdk.DXRpnctc.mjs';
|
|
6
5
|
import * as z from 'zod/v4/core';
|
|
7
6
|
import 'http-status-codes';
|
|
8
7
|
import { createError } from 'h3';
|
|
@@ -12,6 +11,8 @@ import path from 'node:path';
|
|
|
12
11
|
import { parse } from 'comment-json';
|
|
13
12
|
import superjson from 'superjson';
|
|
14
13
|
|
|
14
|
+
const uuidv4 = () => crypto.randomUUID();
|
|
15
|
+
|
|
15
16
|
const base = {
|
|
16
17
|
id: text("id").primaryKey(),
|
|
17
18
|
createdAt: integer("created_at", { mode: "timestamp_ms" }).default(
|
|
@@ -55,6 +56,8 @@ const bankAccountPostgres = {
|
|
|
55
56
|
countryCode: bankAccountCountryCodeEnum().$type().notNull()
|
|
56
57
|
};
|
|
57
58
|
|
|
59
|
+
const ENVIRONMENT = ["dev", "test", "staging", "production"];
|
|
60
|
+
|
|
58
61
|
const ibanZodSchema = new z.$ZodString({
|
|
59
62
|
type: "string",
|
|
60
63
|
checks: [
|
|
@@ -330,7 +333,6 @@ function firstOrError(rows) {
|
|
|
330
333
|
}
|
|
331
334
|
return rows[0];
|
|
332
335
|
}
|
|
333
|
-
const uuidv4 = () => crypto.randomUUID();
|
|
334
336
|
const isRemoteEnvironment = () => {
|
|
335
337
|
const environment = process.env.ENVIRONMENT;
|
|
336
338
|
return environment && environment !== "localhost";
|
|
@@ -719,4 +721,4 @@ function develitWorker(Worker) {
|
|
|
719
721
|
return DevelitWorker;
|
|
720
722
|
}
|
|
721
723
|
|
|
722
|
-
export { DatabaseTransaction, RPCResponse, action, bankAccount, bankAccountBankCodeEnum, bankAccountCountryCodeEnum, bankAccountCurrencyEnum, bankAccountPostgres, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useFetch, useResult, useResultSync, uuidv4 };
|
|
724
|
+
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, action, bankAccount, bankAccountBankCodeEnum, bankAccountCountryCodeEnum, bankAccountCurrencyEnum, bankAccountPostgres, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useFetch, useResult, useResultSync, uuidv4 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@develit-io/backend-sdk",
|
|
3
|
-
"version": "5.30.
|
|
3
|
+
"version": "5.30.5",
|
|
4
4
|
"description": "Develit Backend SDK",
|
|
5
5
|
"author": "Develit.io",
|
|
6
6
|
"license": "ISC",
|
|
@@ -20,17 +20,7 @@
|
|
|
20
20
|
".": {
|
|
21
21
|
"types": "./dist/index.d.ts",
|
|
22
22
|
"import": "./dist/index.mjs",
|
|
23
|
-
"
|
|
24
|
-
},
|
|
25
|
-
"./deployment": {
|
|
26
|
-
"types": "./dist/deployment/index.d.ts",
|
|
27
|
-
"import": "./dist/deployment/index.mjs",
|
|
28
|
-
"require": "./dist/deployment/index.cjs"
|
|
29
|
-
},
|
|
30
|
-
"./node": {
|
|
31
|
-
"types": "./dist/node/index.d.ts",
|
|
32
|
-
"import": "./dist/node/index.mjs",
|
|
33
|
-
"require": "./dist/node/index.cjs"
|
|
23
|
+
"default": "./dist/index.mjs"
|
|
34
24
|
},
|
|
35
25
|
"./package.json": "./package.json"
|
|
36
26
|
},
|
|
@@ -38,19 +28,16 @@
|
|
|
38
28
|
"dist"
|
|
39
29
|
],
|
|
40
30
|
"dependencies": {
|
|
41
|
-
"@cloudflare/workers-types": "4.
|
|
42
|
-
"
|
|
43
|
-
"@std/text": "npm:@jsr/std__text",
|
|
44
|
-
"comment-json": "^4.3.0",
|
|
31
|
+
"@cloudflare/workers-types": "4.20251004.0",
|
|
32
|
+
"comment-json": "^4.4.1",
|
|
45
33
|
"drizzle-kit": "^0.31.5",
|
|
46
|
-
"drizzle-orm": "^0.44.
|
|
34
|
+
"drizzle-orm": "^0.44.6",
|
|
47
35
|
"h3": "^1.15.4",
|
|
48
36
|
"http-status-codes": "2.3.0",
|
|
49
37
|
"superjson": "^2.2.2"
|
|
50
38
|
},
|
|
51
39
|
"peerDependencies": {
|
|
52
40
|
"@develit-io/general-codes": "^1.14.0",
|
|
53
|
-
"alchemy": "^0.69.1",
|
|
54
41
|
"zod": "^4.1.8"
|
|
55
42
|
}
|
|
56
43
|
}
|
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const worker = require('../shared/backend-sdk.Vru_rcK6.cjs');
|
|
4
|
-
const text = require('@std/text');
|
|
5
|
-
const cloudflare = require('alchemy/cloudflare');
|
|
6
|
-
require('../shared/backend-sdk.BdcrYpFD.cjs');
|
|
7
|
-
require('@std/path');
|
|
8
|
-
require('comment-json');
|
|
9
|
-
|
|
10
|
-
const composeD1Arguments = ({
|
|
11
|
-
resourceName
|
|
12
|
-
}) => {
|
|
13
|
-
return {
|
|
14
|
-
name: resourceName,
|
|
15
|
-
primaryLocationHint: worker.D1_LOCATION_HINT
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const composeDlqArguments = ({
|
|
20
|
-
resourceName,
|
|
21
|
-
deliveryDelay = worker.QUEUE_DELIVERY_DELAY,
|
|
22
|
-
messageRetentionPeriod = worker.QUEUE_MESSAGE_RETENTION_PERIOD
|
|
23
|
-
}) => {
|
|
24
|
-
return {
|
|
25
|
-
name: resourceName,
|
|
26
|
-
settings: {
|
|
27
|
-
deliveryDelay,
|
|
28
|
-
messageRetentionPeriod
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const composeKvArguments = ({
|
|
34
|
-
resourceName
|
|
35
|
-
}) => {
|
|
36
|
-
return {
|
|
37
|
-
title: resourceName
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const composeQueueArguments = ({
|
|
42
|
-
resourceName,
|
|
43
|
-
dlq,
|
|
44
|
-
deliveryDelay = worker.QUEUE_DELIVERY_DELAY,
|
|
45
|
-
messageRetentionPeriod = worker.QUEUE_MESSAGE_RETENTION_PERIOD
|
|
46
|
-
}) => {
|
|
47
|
-
return {
|
|
48
|
-
name: resourceName,
|
|
49
|
-
dlq,
|
|
50
|
-
settings: {
|
|
51
|
-
deliveryDelay,
|
|
52
|
-
messageRetentionPeriod
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const composeR2Arguments = ({
|
|
58
|
-
resourceName,
|
|
59
|
-
storageClass = worker.R2_STORAGE_CLASS
|
|
60
|
-
}) => {
|
|
61
|
-
return {
|
|
62
|
-
name: resourceName,
|
|
63
|
-
storageClass,
|
|
64
|
-
jurisdiction: worker.R2_JURISDICTION,
|
|
65
|
-
locationHint: worker.R2_LOCATION_HINT
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const composeIdentifierName = ({
|
|
70
|
-
resource,
|
|
71
|
-
resourceName
|
|
72
|
-
}) => {
|
|
73
|
-
return `${text.toKebabCase(resourceName).toLowerCase()}-${resource}`;
|
|
74
|
-
};
|
|
75
|
-
const composeResourceName = ({
|
|
76
|
-
project,
|
|
77
|
-
environment,
|
|
78
|
-
resourceName
|
|
79
|
-
}) => {
|
|
80
|
-
return `${project}-${text.toKebabCase(resourceName).toLowerCase()}-${environment}`;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
class Deployment {
|
|
84
|
-
project;
|
|
85
|
-
environment;
|
|
86
|
-
// TODO: Check if the type is most correct
|
|
87
|
-
// TODO: Keeping this in class creates issues with destroy
|
|
88
|
-
// public alchemy: Promise<Awaited<ReturnType<typeof alchemy>>>
|
|
89
|
-
constructor({ project }) {
|
|
90
|
-
this.project = project;
|
|
91
|
-
this.environment = Bun.env.ENVIRONMENT || "unknown";
|
|
92
|
-
}
|
|
93
|
-
// TODO: Keeping this in class creates issues with destroy
|
|
94
|
-
/**
|
|
95
|
-
* Finalizes the deployment and correctly quits the Alchemy process.
|
|
96
|
-
*/
|
|
97
|
-
// async finalize() {
|
|
98
|
-
// return (await this.alchemy).finalize()
|
|
99
|
-
// }
|
|
100
|
-
/**
|
|
101
|
-
* Creates an instance of Cloudflare KV.
|
|
102
|
-
*/
|
|
103
|
-
async kv(options) {
|
|
104
|
-
const { resourceName } = options;
|
|
105
|
-
return await cloudflare.KVNamespace(
|
|
106
|
-
composeIdentifierName({ resourceName, resource: "kv" }),
|
|
107
|
-
composeKvArguments({
|
|
108
|
-
resourceName: composeResourceName({
|
|
109
|
-
project: this.project,
|
|
110
|
-
environment: this.environment,
|
|
111
|
-
resourceName
|
|
112
|
-
})
|
|
113
|
-
})
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Creates an instance of Cloudflare D1.
|
|
118
|
-
*/
|
|
119
|
-
async d1(options) {
|
|
120
|
-
const { resourceName } = options;
|
|
121
|
-
return await cloudflare.D1Database(
|
|
122
|
-
composeIdentifierName({ resourceName, resource: "d1" }),
|
|
123
|
-
composeD1Arguments({
|
|
124
|
-
resourceName: composeResourceName({
|
|
125
|
-
project: this.project,
|
|
126
|
-
environment: this.environment,
|
|
127
|
-
resourceName
|
|
128
|
-
})
|
|
129
|
-
})
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Creates an instance of Cloudflare Queue. A DLQ is created automatically.
|
|
134
|
-
*/
|
|
135
|
-
async queue(options) {
|
|
136
|
-
const { resourceName, deliveryDelay, messageRetentionPeriod } = options;
|
|
137
|
-
const deadLetterQueue = await this.dlq({
|
|
138
|
-
resourceName
|
|
139
|
-
});
|
|
140
|
-
return await cloudflare.Queue(
|
|
141
|
-
composeIdentifierName({ resourceName, resource: "queue" }),
|
|
142
|
-
composeQueueArguments({
|
|
143
|
-
resourceName: composeResourceName({
|
|
144
|
-
project: this.project,
|
|
145
|
-
environment: this.environment,
|
|
146
|
-
resourceName
|
|
147
|
-
}),
|
|
148
|
-
dlq: deadLetterQueue,
|
|
149
|
-
deliveryDelay,
|
|
150
|
-
messageRetentionPeriod
|
|
151
|
-
})
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Creates an instance of Cloudflare Queue as a DLQ.
|
|
156
|
-
*/
|
|
157
|
-
async dlq(options) {
|
|
158
|
-
const { resourceName, deliveryDelay, messageRetentionPeriod } = options;
|
|
159
|
-
return await cloudflare.Queue(
|
|
160
|
-
composeIdentifierName({ resourceName, resource: "dlq" }),
|
|
161
|
-
composeDlqArguments({
|
|
162
|
-
resourceName: composeResourceName({
|
|
163
|
-
project: this.project,
|
|
164
|
-
environment: this.environment,
|
|
165
|
-
// TODO: Convert to a util
|
|
166
|
-
resourceName: `${resourceName}-dlq`
|
|
167
|
-
}),
|
|
168
|
-
deliveryDelay,
|
|
169
|
-
messageRetentionPeriod
|
|
170
|
-
})
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Creates an instance of Cloudflare R2.
|
|
175
|
-
*/
|
|
176
|
-
async r2(options) {
|
|
177
|
-
const { resourceName, storageClass } = options;
|
|
178
|
-
return await cloudflare.R2Bucket(
|
|
179
|
-
composeIdentifierName({ resourceName, resource: "r2" }),
|
|
180
|
-
composeR2Arguments({
|
|
181
|
-
resourceName: composeResourceName({
|
|
182
|
-
project: this.project,
|
|
183
|
-
environment: this.environment,
|
|
184
|
-
resourceName
|
|
185
|
-
}),
|
|
186
|
-
storageClass
|
|
187
|
-
})
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Creates an instance of Cloudflare Durable Object.
|
|
192
|
-
*/
|
|
193
|
-
async durableObject(options) {
|
|
194
|
-
const { className } = options;
|
|
195
|
-
return cloudflare.DurableObjectNamespace(
|
|
196
|
-
composeIdentifierName({
|
|
197
|
-
resourceName: className,
|
|
198
|
-
resource: "durable-object"
|
|
199
|
-
}),
|
|
200
|
-
// TODO: Create util
|
|
201
|
-
{
|
|
202
|
-
// TODO: Create util
|
|
203
|
-
className: `${className}DurableObject`,
|
|
204
|
-
sqlite: true
|
|
205
|
-
}
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Creates an instance of Cloudflare Worker.
|
|
210
|
-
*/
|
|
211
|
-
async worker(options) {
|
|
212
|
-
const {
|
|
213
|
-
resourceName,
|
|
214
|
-
resource,
|
|
215
|
-
path,
|
|
216
|
-
domains,
|
|
217
|
-
assets,
|
|
218
|
-
crons,
|
|
219
|
-
bindings,
|
|
220
|
-
eventSources
|
|
221
|
-
} = options;
|
|
222
|
-
const identifierName = composeIdentifierName({
|
|
223
|
-
resourceName,
|
|
224
|
-
// TODO: Convert to a util
|
|
225
|
-
resource: resource || "worker"
|
|
226
|
-
});
|
|
227
|
-
const workerConfig = await worker.loadWorkerConfig({ path });
|
|
228
|
-
const vars = worker.extractWorkerVars({
|
|
229
|
-
workerConfig,
|
|
230
|
-
environment: this.environment
|
|
231
|
-
});
|
|
232
|
-
for (const key in vars) {
|
|
233
|
-
const value = vars[key];
|
|
234
|
-
switch (typeof value) {
|
|
235
|
-
case "number":
|
|
236
|
-
vars[key] = JSON.stringify(value);
|
|
237
|
-
break;
|
|
238
|
-
case "boolean":
|
|
239
|
-
vars[key] = JSON.stringify(value);
|
|
240
|
-
break;
|
|
241
|
-
case "object":
|
|
242
|
-
vars[key] = JSON.stringify(value);
|
|
243
|
-
break;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
const consumers = eventSources?.map((queue) => {
|
|
247
|
-
return {
|
|
248
|
-
queue,
|
|
249
|
-
settings: {
|
|
250
|
-
deadLetterQueue: queue.dlq,
|
|
251
|
-
batchSize: worker.QUEUE_MAX_BATCH_SIZE,
|
|
252
|
-
maxWaitTimeMs: worker.QUEUE_MAX_BATCH_TIMEOUT
|
|
253
|
-
// TODO: Watch out for the type
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
});
|
|
257
|
-
return await cloudflare.Worker(
|
|
258
|
-
// TODO: Make it to use composeIdentifierName similary to other resources
|
|
259
|
-
identifierName,
|
|
260
|
-
worker.composeWorkerArguments({
|
|
261
|
-
resourceName: composeResourceName({
|
|
262
|
-
project: this.project,
|
|
263
|
-
environment: this.environment,
|
|
264
|
-
resourceName: identifierName
|
|
265
|
-
}),
|
|
266
|
-
// TODO: Convert to util
|
|
267
|
-
entrypoint: `${path}/src/index.ts`,
|
|
268
|
-
domains,
|
|
269
|
-
assets,
|
|
270
|
-
// TODO: Convert to a util
|
|
271
|
-
crons: crons || worker.extractWorkerCrons({
|
|
272
|
-
workerConfig,
|
|
273
|
-
environment: this.environment
|
|
274
|
-
}),
|
|
275
|
-
bindings: {
|
|
276
|
-
...bindings,
|
|
277
|
-
...vars
|
|
278
|
-
},
|
|
279
|
-
eventSources: consumers
|
|
280
|
-
})
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Creates an instance of Cloudflare Worker as a service.
|
|
285
|
-
*/
|
|
286
|
-
async service(options) {
|
|
287
|
-
const { resourceName, bindings, eventSources } = options;
|
|
288
|
-
return await this.worker({
|
|
289
|
-
resourceName,
|
|
290
|
-
resource: "service",
|
|
291
|
-
// TODO: Convert to util
|
|
292
|
-
path: `./services/${resourceName}`,
|
|
293
|
-
bindings,
|
|
294
|
-
eventSources
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Creates an instance of Cloudflare Worker as an orchestrator.
|
|
299
|
-
*/
|
|
300
|
-
async orchestrator(options) {
|
|
301
|
-
const { resourceName, domains, bindings, eventSources } = options;
|
|
302
|
-
return await this.worker({
|
|
303
|
-
resourceName,
|
|
304
|
-
resource: "orchestrator",
|
|
305
|
-
// TODO: Convert to util
|
|
306
|
-
path: `./apps/${resourceName}`,
|
|
307
|
-
domains,
|
|
308
|
-
bindings,
|
|
309
|
-
eventSources
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Creates an instance of Cloudflare Worker as a client.
|
|
314
|
-
*/
|
|
315
|
-
async client(options) {
|
|
316
|
-
const { resourceName, domains, bindings, variables } = options;
|
|
317
|
-
return await cloudflare.Nuxt(
|
|
318
|
-
composeIdentifierName({
|
|
319
|
-
resourceName,
|
|
320
|
-
resource: "client"
|
|
321
|
-
}),
|
|
322
|
-
{
|
|
323
|
-
name: composeResourceName({
|
|
324
|
-
project: this.project,
|
|
325
|
-
environment: this.environment,
|
|
326
|
-
resourceName
|
|
327
|
-
}),
|
|
328
|
-
compatibilityDate: worker.COMPATIBILITY_DATE,
|
|
329
|
-
compatibilityFlags: worker.COMPATIBILITY_FLAGS,
|
|
330
|
-
observability: {
|
|
331
|
-
enabled: true
|
|
332
|
-
},
|
|
333
|
-
url: false,
|
|
334
|
-
domains,
|
|
335
|
-
bindings: {
|
|
336
|
-
...bindings,
|
|
337
|
-
...variables
|
|
338
|
-
},
|
|
339
|
-
// TODO: Convert to util
|
|
340
|
-
cwd: `./apps/${resourceName}`
|
|
341
|
-
}
|
|
342
|
-
);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
exports.composeWorkerArguments = worker.composeWorkerArguments;
|
|
347
|
-
exports.extractWorkerCrons = worker.extractWorkerCrons;
|
|
348
|
-
exports.extractWorkerVars = worker.extractWorkerVars;
|
|
349
|
-
exports.loadWorkerConfig = worker.loadWorkerConfig;
|
|
350
|
-
exports.Deployment = Deployment;
|
|
351
|
-
exports.composeD1Arguments = composeD1Arguments;
|
|
352
|
-
exports.composeDlqArguments = composeDlqArguments;
|
|
353
|
-
exports.composeIdentifierName = composeIdentifierName;
|
|
354
|
-
exports.composeKvArguments = composeKvArguments;
|
|
355
|
-
exports.composeQueueArguments = composeQueueArguments;
|
|
356
|
-
exports.composeR2Arguments = composeR2Arguments;
|
|
357
|
-
exports.composeResourceName = composeResourceName;
|