@develit-io/backend-sdk 5.14.1 → 5.15.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 +87 -72
- package/dist/index.d.cts +12 -55
- package/dist/index.d.mts +12 -55
- package/dist/index.d.ts +12 -55
- package/dist/index.mjs +85 -73
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -52,6 +52,82 @@ const basePostgres = {
|
|
|
52
52
|
}).default(drizzleOrm.sql`null`)
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
+
const ENVIRONMENT = ["dev", "test", "staging", "production"];
|
|
56
|
+
|
|
57
|
+
const composeD1Arguments = ({
|
|
58
|
+
resourceName
|
|
59
|
+
}) => {
|
|
60
|
+
return {
|
|
61
|
+
transform: {
|
|
62
|
+
database: {
|
|
63
|
+
name: resourceName,
|
|
64
|
+
primaryLocationHint: "weur"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const composeKvArguments = ({
|
|
71
|
+
resourceName
|
|
72
|
+
}) => {
|
|
73
|
+
return {
|
|
74
|
+
transform: {
|
|
75
|
+
namespace: {
|
|
76
|
+
title: resourceName
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const composeQueueArguments = ({
|
|
83
|
+
resourceName,
|
|
84
|
+
deliveryDelay = 5,
|
|
85
|
+
messageRetentionPeriod = 259200
|
|
86
|
+
}) => {
|
|
87
|
+
return {
|
|
88
|
+
transform: {
|
|
89
|
+
queue: {
|
|
90
|
+
queueName: resourceName,
|
|
91
|
+
settings: {
|
|
92
|
+
deliveryDelay,
|
|
93
|
+
messageRetentionPeriod
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const composeR2Arguments = ({
|
|
101
|
+
resourceName,
|
|
102
|
+
storageClass = "Standard"
|
|
103
|
+
}) => {
|
|
104
|
+
return {
|
|
105
|
+
transform: {
|
|
106
|
+
bucket: {
|
|
107
|
+
name: resourceName,
|
|
108
|
+
jurisdiction: "eu",
|
|
109
|
+
location: "weur",
|
|
110
|
+
storageClass
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const composeBindingName = ({
|
|
117
|
+
resource,
|
|
118
|
+
resourceName,
|
|
119
|
+
bindingName
|
|
120
|
+
}) => {
|
|
121
|
+
const convertedBindingName = bindingName ? text.toSnakeCase(bindingName) : `${text.toSnakeCase(resourceName)}_${resource}`;
|
|
122
|
+
return convertedBindingName.toUpperCase();
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const validateEnvironment = (environment) => {
|
|
126
|
+
if (ENVIRONMENT.includes(environment)) {
|
|
127
|
+
return environment;
|
|
128
|
+
}
|
|
129
|
+
return Number(environment);
|
|
130
|
+
};
|
|
55
131
|
class Infrastructure {
|
|
56
132
|
project;
|
|
57
133
|
environment;
|
|
@@ -66,73 +142,9 @@ class Infrastructure {
|
|
|
66
142
|
this.sst = sst;
|
|
67
143
|
}
|
|
68
144
|
// TODO(Pookensivee): Make tests for this util
|
|
69
|
-
composeBindingName({
|
|
70
|
-
resource,
|
|
71
|
-
resourceName,
|
|
72
|
-
bindingName
|
|
73
|
-
}) {
|
|
74
|
-
const convertedBindingName = bindingName ? text.toSnakeCase(bindingName) : `${text.toSnakeCase(resourceName)}_${resource}`;
|
|
75
|
-
return convertedBindingName.toUpperCase();
|
|
76
|
-
}
|
|
77
|
-
// TODO(Pookensivee): Make tests for this util
|
|
78
145
|
composeResourceName({ resourceName }) {
|
|
79
146
|
return `${this.project}-${resourceName}-${this.environment}`;
|
|
80
147
|
}
|
|
81
|
-
// TODO(Pookensivee): Make tests for this util
|
|
82
|
-
composeKvArguments({ resourceName }) {
|
|
83
|
-
return {
|
|
84
|
-
transform: {
|
|
85
|
-
namespace: {
|
|
86
|
-
title: resourceName
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
// TODO(Pookensivee): Make tests for this util
|
|
92
|
-
composeD1Arguments({ resourceName }) {
|
|
93
|
-
return {
|
|
94
|
-
transform: {
|
|
95
|
-
database: {
|
|
96
|
-
name: resourceName,
|
|
97
|
-
primaryLocationHint: "weur"
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
// TODO(Pookensivee): Make tests for this util
|
|
103
|
-
composeQueueArguments({
|
|
104
|
-
resourceName,
|
|
105
|
-
deliveryDelay = 5,
|
|
106
|
-
messageRetentionPeriod = 259200
|
|
107
|
-
}) {
|
|
108
|
-
return {
|
|
109
|
-
transform: {
|
|
110
|
-
queue: {
|
|
111
|
-
queueName: resourceName,
|
|
112
|
-
settings: {
|
|
113
|
-
deliveryDelay,
|
|
114
|
-
messageRetentionPeriod
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
// TODO(Pookensivee): Make tests for this util
|
|
121
|
-
composeR2Arguments({
|
|
122
|
-
resourceName,
|
|
123
|
-
storageClass = "Standard"
|
|
124
|
-
}) {
|
|
125
|
-
return {
|
|
126
|
-
transform: {
|
|
127
|
-
bucket: {
|
|
128
|
-
name: resourceName,
|
|
129
|
-
jurisdiction: "eu",
|
|
130
|
-
location: "weur",
|
|
131
|
-
storageClass
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
148
|
// TODO: Solve the circular dependency on post infrastructure deploy script
|
|
137
149
|
// TODO: Cannot assign a queue as a producer, work around: https://developers.cloudflare.com/workers/wrangler/commands/#queues-consumer-add-script-name
|
|
138
150
|
// async composeWorkerArguments({
|
|
@@ -214,8 +226,8 @@ class Infrastructure {
|
|
|
214
226
|
kv(options) {
|
|
215
227
|
const { resourceName, bindingName } = options;
|
|
216
228
|
return new this.sst.cloudflare.Kv(
|
|
217
|
-
`${
|
|
218
|
-
|
|
229
|
+
`${composeBindingName({ resource: "kv", resourceName, bindingName })}`,
|
|
230
|
+
composeKvArguments({
|
|
219
231
|
resourceName: this.composeResourceName({ resourceName })
|
|
220
232
|
})
|
|
221
233
|
);
|
|
@@ -226,8 +238,8 @@ class Infrastructure {
|
|
|
226
238
|
d1(options) {
|
|
227
239
|
const { resourceName, bindingName } = options;
|
|
228
240
|
return new this.sst.cloudflare.D1(
|
|
229
|
-
`${
|
|
230
|
-
|
|
241
|
+
`${composeBindingName({ resource: "d1", resourceName, bindingName })}`,
|
|
242
|
+
composeD1Arguments({
|
|
231
243
|
resourceName: this.composeResourceName({ resourceName })
|
|
232
244
|
})
|
|
233
245
|
);
|
|
@@ -238,8 +250,8 @@ class Infrastructure {
|
|
|
238
250
|
queue(options) {
|
|
239
251
|
const { resourceName, bindingName, deliveryDelay, messageRetentionPeriod } = options;
|
|
240
252
|
return new this.sst.cloudflare.Queue(
|
|
241
|
-
`${
|
|
242
|
-
|
|
253
|
+
`${composeBindingName({ resource: "queue", resourceName, bindingName })}`,
|
|
254
|
+
composeQueueArguments({
|
|
243
255
|
resourceName: this.composeResourceName({ resourceName }),
|
|
244
256
|
deliveryDelay,
|
|
245
257
|
messageRetentionPeriod
|
|
@@ -252,8 +264,8 @@ class Infrastructure {
|
|
|
252
264
|
r2(options) {
|
|
253
265
|
const { resourceName, bindingName, storageClass } = options;
|
|
254
266
|
return new this.sst.cloudflare.Bucket(
|
|
255
|
-
`${
|
|
256
|
-
|
|
267
|
+
`${composeBindingName({ resource: "r2", resourceName, bindingName })}`,
|
|
268
|
+
composeR2Arguments({
|
|
257
269
|
resourceName: this.composeResourceName({ resourceName }),
|
|
258
270
|
storageClass
|
|
259
271
|
})
|
|
@@ -951,6 +963,7 @@ function develitWorker(Worker) {
|
|
|
951
963
|
}
|
|
952
964
|
|
|
953
965
|
exports.DatabaseTransaction = DatabaseTransaction;
|
|
966
|
+
exports.ENVIRONMENT = ENVIRONMENT;
|
|
954
967
|
exports.Infrastructure = Infrastructure;
|
|
955
968
|
exports.RPCResponse = RPCResponse;
|
|
956
969
|
exports.action = action;
|
|
@@ -958,6 +971,7 @@ exports.base = base;
|
|
|
958
971
|
exports.basePostgres = basePostgres;
|
|
959
972
|
exports.calculateExponentialBackoff = calculateExponentialBackoff;
|
|
960
973
|
exports.cloudflareQueue = cloudflareQueue;
|
|
974
|
+
exports.composeBindingName = composeBindingName;
|
|
961
975
|
exports.createAuditLogWriter = createAuditLogWriter;
|
|
962
976
|
exports.createInternalError = createInternalError;
|
|
963
977
|
exports.defineCommand = defineCommand;
|
|
@@ -984,3 +998,4 @@ exports.swiftZodSchema = swiftZodSchema;
|
|
|
984
998
|
exports.useResult = useResult;
|
|
985
999
|
exports.useResultSync = useResultSync;
|
|
986
1000
|
exports.uuidv4 = uuidv4;
|
|
1001
|
+
exports.validateEnvironment = validateEnvironment;
|
package/dist/index.d.cts
CHANGED
|
@@ -26,10 +26,9 @@ declare const basePostgres: {
|
|
|
26
26
|
|
|
27
27
|
type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
|
|
28
28
|
|
|
29
|
-
type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
|
|
30
|
-
|
|
31
29
|
type Environment = number | 'dev' | 'test' | 'staging' | 'production';
|
|
32
30
|
|
|
31
|
+
declare const validateEnvironment: (environment: string) => Environment;
|
|
33
32
|
interface SstInstance {
|
|
34
33
|
cloudflare: {
|
|
35
34
|
[key: string]: any;
|
|
@@ -44,61 +43,9 @@ declare class Infrastructure {
|
|
|
44
43
|
environment: Environment;
|
|
45
44
|
sst: SstInstance;
|
|
46
45
|
});
|
|
47
|
-
composeBindingName({ resource, resourceName, bindingName, }: {
|
|
48
|
-
resource: Resource;
|
|
49
|
-
resourceName: string;
|
|
50
|
-
bindingName?: string;
|
|
51
|
-
}): string;
|
|
52
46
|
composeResourceName({ resourceName }: {
|
|
53
47
|
resourceName: string;
|
|
54
48
|
}): string;
|
|
55
|
-
composeKvArguments({ resourceName }: {
|
|
56
|
-
resourceName: string;
|
|
57
|
-
}): {
|
|
58
|
-
transform: {
|
|
59
|
-
namespace: {
|
|
60
|
-
title: string;
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
composeD1Arguments({ resourceName }: {
|
|
65
|
-
resourceName: string;
|
|
66
|
-
}): {
|
|
67
|
-
transform: {
|
|
68
|
-
database: {
|
|
69
|
-
name: string;
|
|
70
|
-
primaryLocationHint: string;
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
composeQueueArguments({ resourceName, deliveryDelay, messageRetentionPeriod, }: {
|
|
75
|
-
resourceName: string;
|
|
76
|
-
deliveryDelay?: number;
|
|
77
|
-
messageRetentionPeriod?: number;
|
|
78
|
-
}): {
|
|
79
|
-
transform: {
|
|
80
|
-
queue: {
|
|
81
|
-
queueName: string;
|
|
82
|
-
settings: {
|
|
83
|
-
deliveryDelay: number;
|
|
84
|
-
messageRetentionPeriod: number;
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
composeR2Arguments({ resourceName, storageClass, }: {
|
|
90
|
-
resourceName: string;
|
|
91
|
-
storageClass?: 'Standard' | 'InfrequentAccess';
|
|
92
|
-
}): {
|
|
93
|
-
transform: {
|
|
94
|
-
bucket: {
|
|
95
|
-
name: string;
|
|
96
|
-
jurisdiction: string;
|
|
97
|
-
location: string;
|
|
98
|
-
storageClass: "Standard" | "InfrequentAccess";
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
49
|
/**
|
|
103
50
|
* Creates an instance of Cloudflare KV.
|
|
104
51
|
*/
|
|
@@ -165,6 +112,16 @@ declare class Infrastructure {
|
|
|
165
112
|
}): any;
|
|
166
113
|
}
|
|
167
114
|
|
|
115
|
+
type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
|
|
116
|
+
|
|
117
|
+
declare const composeBindingName: ({ resource, resourceName, bindingName, }: {
|
|
118
|
+
resource: Resource;
|
|
119
|
+
resourceName: string;
|
|
120
|
+
bindingName?: string;
|
|
121
|
+
}) => string;
|
|
122
|
+
|
|
123
|
+
declare const ENVIRONMENT: string[];
|
|
124
|
+
|
|
168
125
|
type InternalErrorResponseStatus = Exclude<StatusCodes, 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207>;
|
|
169
126
|
interface InternalError {
|
|
170
127
|
status: InternalErrorResponseStatus;
|
|
@@ -547,5 +504,5 @@ interface WithRetryCounterOptions {
|
|
|
547
504
|
type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
|
|
548
505
|
declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
|
|
549
506
|
|
|
550
|
-
export { DatabaseTransaction, Infrastructure, RPCResponse, action, 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, useResult, useResultSync, uuidv4 };
|
|
507
|
+
export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, composeBindingName, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useResult, useResultSync, uuidv4, validateEnvironment };
|
|
551
508
|
export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
|
package/dist/index.d.mts
CHANGED
|
@@ -26,10 +26,9 @@ declare const basePostgres: {
|
|
|
26
26
|
|
|
27
27
|
type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
|
|
28
28
|
|
|
29
|
-
type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
|
|
30
|
-
|
|
31
29
|
type Environment = number | 'dev' | 'test' | 'staging' | 'production';
|
|
32
30
|
|
|
31
|
+
declare const validateEnvironment: (environment: string) => Environment;
|
|
33
32
|
interface SstInstance {
|
|
34
33
|
cloudflare: {
|
|
35
34
|
[key: string]: any;
|
|
@@ -44,61 +43,9 @@ declare class Infrastructure {
|
|
|
44
43
|
environment: Environment;
|
|
45
44
|
sst: SstInstance;
|
|
46
45
|
});
|
|
47
|
-
composeBindingName({ resource, resourceName, bindingName, }: {
|
|
48
|
-
resource: Resource;
|
|
49
|
-
resourceName: string;
|
|
50
|
-
bindingName?: string;
|
|
51
|
-
}): string;
|
|
52
46
|
composeResourceName({ resourceName }: {
|
|
53
47
|
resourceName: string;
|
|
54
48
|
}): string;
|
|
55
|
-
composeKvArguments({ resourceName }: {
|
|
56
|
-
resourceName: string;
|
|
57
|
-
}): {
|
|
58
|
-
transform: {
|
|
59
|
-
namespace: {
|
|
60
|
-
title: string;
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
composeD1Arguments({ resourceName }: {
|
|
65
|
-
resourceName: string;
|
|
66
|
-
}): {
|
|
67
|
-
transform: {
|
|
68
|
-
database: {
|
|
69
|
-
name: string;
|
|
70
|
-
primaryLocationHint: string;
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
composeQueueArguments({ resourceName, deliveryDelay, messageRetentionPeriod, }: {
|
|
75
|
-
resourceName: string;
|
|
76
|
-
deliveryDelay?: number;
|
|
77
|
-
messageRetentionPeriod?: number;
|
|
78
|
-
}): {
|
|
79
|
-
transform: {
|
|
80
|
-
queue: {
|
|
81
|
-
queueName: string;
|
|
82
|
-
settings: {
|
|
83
|
-
deliveryDelay: number;
|
|
84
|
-
messageRetentionPeriod: number;
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
composeR2Arguments({ resourceName, storageClass, }: {
|
|
90
|
-
resourceName: string;
|
|
91
|
-
storageClass?: 'Standard' | 'InfrequentAccess';
|
|
92
|
-
}): {
|
|
93
|
-
transform: {
|
|
94
|
-
bucket: {
|
|
95
|
-
name: string;
|
|
96
|
-
jurisdiction: string;
|
|
97
|
-
location: string;
|
|
98
|
-
storageClass: "Standard" | "InfrequentAccess";
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
49
|
/**
|
|
103
50
|
* Creates an instance of Cloudflare KV.
|
|
104
51
|
*/
|
|
@@ -165,6 +112,16 @@ declare class Infrastructure {
|
|
|
165
112
|
}): any;
|
|
166
113
|
}
|
|
167
114
|
|
|
115
|
+
type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
|
|
116
|
+
|
|
117
|
+
declare const composeBindingName: ({ resource, resourceName, bindingName, }: {
|
|
118
|
+
resource: Resource;
|
|
119
|
+
resourceName: string;
|
|
120
|
+
bindingName?: string;
|
|
121
|
+
}) => string;
|
|
122
|
+
|
|
123
|
+
declare const ENVIRONMENT: string[];
|
|
124
|
+
|
|
168
125
|
type InternalErrorResponseStatus = Exclude<StatusCodes, 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207>;
|
|
169
126
|
interface InternalError {
|
|
170
127
|
status: InternalErrorResponseStatus;
|
|
@@ -547,5 +504,5 @@ interface WithRetryCounterOptions {
|
|
|
547
504
|
type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
|
|
548
505
|
declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
|
|
549
506
|
|
|
550
|
-
export { DatabaseTransaction, Infrastructure, RPCResponse, action, 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, useResult, useResultSync, uuidv4 };
|
|
507
|
+
export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, composeBindingName, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useResult, useResultSync, uuidv4, validateEnvironment };
|
|
551
508
|
export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
|
package/dist/index.d.ts
CHANGED
|
@@ -26,10 +26,9 @@ declare const basePostgres: {
|
|
|
26
26
|
|
|
27
27
|
type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
|
|
28
28
|
|
|
29
|
-
type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
|
|
30
|
-
|
|
31
29
|
type Environment = number | 'dev' | 'test' | 'staging' | 'production';
|
|
32
30
|
|
|
31
|
+
declare const validateEnvironment: (environment: string) => Environment;
|
|
33
32
|
interface SstInstance {
|
|
34
33
|
cloudflare: {
|
|
35
34
|
[key: string]: any;
|
|
@@ -44,61 +43,9 @@ declare class Infrastructure {
|
|
|
44
43
|
environment: Environment;
|
|
45
44
|
sst: SstInstance;
|
|
46
45
|
});
|
|
47
|
-
composeBindingName({ resource, resourceName, bindingName, }: {
|
|
48
|
-
resource: Resource;
|
|
49
|
-
resourceName: string;
|
|
50
|
-
bindingName?: string;
|
|
51
|
-
}): string;
|
|
52
46
|
composeResourceName({ resourceName }: {
|
|
53
47
|
resourceName: string;
|
|
54
48
|
}): string;
|
|
55
|
-
composeKvArguments({ resourceName }: {
|
|
56
|
-
resourceName: string;
|
|
57
|
-
}): {
|
|
58
|
-
transform: {
|
|
59
|
-
namespace: {
|
|
60
|
-
title: string;
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
composeD1Arguments({ resourceName }: {
|
|
65
|
-
resourceName: string;
|
|
66
|
-
}): {
|
|
67
|
-
transform: {
|
|
68
|
-
database: {
|
|
69
|
-
name: string;
|
|
70
|
-
primaryLocationHint: string;
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
composeQueueArguments({ resourceName, deliveryDelay, messageRetentionPeriod, }: {
|
|
75
|
-
resourceName: string;
|
|
76
|
-
deliveryDelay?: number;
|
|
77
|
-
messageRetentionPeriod?: number;
|
|
78
|
-
}): {
|
|
79
|
-
transform: {
|
|
80
|
-
queue: {
|
|
81
|
-
queueName: string;
|
|
82
|
-
settings: {
|
|
83
|
-
deliveryDelay: number;
|
|
84
|
-
messageRetentionPeriod: number;
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
composeR2Arguments({ resourceName, storageClass, }: {
|
|
90
|
-
resourceName: string;
|
|
91
|
-
storageClass?: 'Standard' | 'InfrequentAccess';
|
|
92
|
-
}): {
|
|
93
|
-
transform: {
|
|
94
|
-
bucket: {
|
|
95
|
-
name: string;
|
|
96
|
-
jurisdiction: string;
|
|
97
|
-
location: string;
|
|
98
|
-
storageClass: "Standard" | "InfrequentAccess";
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
49
|
/**
|
|
103
50
|
* Creates an instance of Cloudflare KV.
|
|
104
51
|
*/
|
|
@@ -165,6 +112,16 @@ declare class Infrastructure {
|
|
|
165
112
|
}): any;
|
|
166
113
|
}
|
|
167
114
|
|
|
115
|
+
type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
|
|
116
|
+
|
|
117
|
+
declare const composeBindingName: ({ resource, resourceName, bindingName, }: {
|
|
118
|
+
resource: Resource;
|
|
119
|
+
resourceName: string;
|
|
120
|
+
bindingName?: string;
|
|
121
|
+
}) => string;
|
|
122
|
+
|
|
123
|
+
declare const ENVIRONMENT: string[];
|
|
124
|
+
|
|
168
125
|
type InternalErrorResponseStatus = Exclude<StatusCodes, 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207>;
|
|
169
126
|
interface InternalError {
|
|
170
127
|
status: InternalErrorResponseStatus;
|
|
@@ -547,5 +504,5 @@ interface WithRetryCounterOptions {
|
|
|
547
504
|
type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
|
|
548
505
|
declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
|
|
549
506
|
|
|
550
|
-
export { DatabaseTransaction, Infrastructure, RPCResponse, action, 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, useResult, useResultSync, uuidv4 };
|
|
507
|
+
export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, composeBindingName, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useResult, useResultSync, uuidv4, validateEnvironment };
|
|
551
508
|
export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
|
package/dist/index.mjs
CHANGED
|
@@ -30,6 +30,82 @@ const basePostgres = {
|
|
|
30
30
|
}).default(sql`null`)
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
const ENVIRONMENT = ["dev", "test", "staging", "production"];
|
|
34
|
+
|
|
35
|
+
const composeD1Arguments = ({
|
|
36
|
+
resourceName
|
|
37
|
+
}) => {
|
|
38
|
+
return {
|
|
39
|
+
transform: {
|
|
40
|
+
database: {
|
|
41
|
+
name: resourceName,
|
|
42
|
+
primaryLocationHint: "weur"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const composeKvArguments = ({
|
|
49
|
+
resourceName
|
|
50
|
+
}) => {
|
|
51
|
+
return {
|
|
52
|
+
transform: {
|
|
53
|
+
namespace: {
|
|
54
|
+
title: resourceName
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const composeQueueArguments = ({
|
|
61
|
+
resourceName,
|
|
62
|
+
deliveryDelay = 5,
|
|
63
|
+
messageRetentionPeriod = 259200
|
|
64
|
+
}) => {
|
|
65
|
+
return {
|
|
66
|
+
transform: {
|
|
67
|
+
queue: {
|
|
68
|
+
queueName: resourceName,
|
|
69
|
+
settings: {
|
|
70
|
+
deliveryDelay,
|
|
71
|
+
messageRetentionPeriod
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const composeR2Arguments = ({
|
|
79
|
+
resourceName,
|
|
80
|
+
storageClass = "Standard"
|
|
81
|
+
}) => {
|
|
82
|
+
return {
|
|
83
|
+
transform: {
|
|
84
|
+
bucket: {
|
|
85
|
+
name: resourceName,
|
|
86
|
+
jurisdiction: "eu",
|
|
87
|
+
location: "weur",
|
|
88
|
+
storageClass
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const composeBindingName = ({
|
|
95
|
+
resource,
|
|
96
|
+
resourceName,
|
|
97
|
+
bindingName
|
|
98
|
+
}) => {
|
|
99
|
+
const convertedBindingName = bindingName ? toSnakeCase(bindingName) : `${toSnakeCase(resourceName)}_${resource}`;
|
|
100
|
+
return convertedBindingName.toUpperCase();
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const validateEnvironment = (environment) => {
|
|
104
|
+
if (ENVIRONMENT.includes(environment)) {
|
|
105
|
+
return environment;
|
|
106
|
+
}
|
|
107
|
+
return Number(environment);
|
|
108
|
+
};
|
|
33
109
|
class Infrastructure {
|
|
34
110
|
project;
|
|
35
111
|
environment;
|
|
@@ -44,73 +120,9 @@ class Infrastructure {
|
|
|
44
120
|
this.sst = sst;
|
|
45
121
|
}
|
|
46
122
|
// TODO(Pookensivee): Make tests for this util
|
|
47
|
-
composeBindingName({
|
|
48
|
-
resource,
|
|
49
|
-
resourceName,
|
|
50
|
-
bindingName
|
|
51
|
-
}) {
|
|
52
|
-
const convertedBindingName = bindingName ? toSnakeCase(bindingName) : `${toSnakeCase(resourceName)}_${resource}`;
|
|
53
|
-
return convertedBindingName.toUpperCase();
|
|
54
|
-
}
|
|
55
|
-
// TODO(Pookensivee): Make tests for this util
|
|
56
123
|
composeResourceName({ resourceName }) {
|
|
57
124
|
return `${this.project}-${resourceName}-${this.environment}`;
|
|
58
125
|
}
|
|
59
|
-
// TODO(Pookensivee): Make tests for this util
|
|
60
|
-
composeKvArguments({ resourceName }) {
|
|
61
|
-
return {
|
|
62
|
-
transform: {
|
|
63
|
-
namespace: {
|
|
64
|
-
title: resourceName
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
// TODO(Pookensivee): Make tests for this util
|
|
70
|
-
composeD1Arguments({ resourceName }) {
|
|
71
|
-
return {
|
|
72
|
-
transform: {
|
|
73
|
-
database: {
|
|
74
|
-
name: resourceName,
|
|
75
|
-
primaryLocationHint: "weur"
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
// TODO(Pookensivee): Make tests for this util
|
|
81
|
-
composeQueueArguments({
|
|
82
|
-
resourceName,
|
|
83
|
-
deliveryDelay = 5,
|
|
84
|
-
messageRetentionPeriod = 259200
|
|
85
|
-
}) {
|
|
86
|
-
return {
|
|
87
|
-
transform: {
|
|
88
|
-
queue: {
|
|
89
|
-
queueName: resourceName,
|
|
90
|
-
settings: {
|
|
91
|
-
deliveryDelay,
|
|
92
|
-
messageRetentionPeriod
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
// TODO(Pookensivee): Make tests for this util
|
|
99
|
-
composeR2Arguments({
|
|
100
|
-
resourceName,
|
|
101
|
-
storageClass = "Standard"
|
|
102
|
-
}) {
|
|
103
|
-
return {
|
|
104
|
-
transform: {
|
|
105
|
-
bucket: {
|
|
106
|
-
name: resourceName,
|
|
107
|
-
jurisdiction: "eu",
|
|
108
|
-
location: "weur",
|
|
109
|
-
storageClass
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
126
|
// TODO: Solve the circular dependency on post infrastructure deploy script
|
|
115
127
|
// TODO: Cannot assign a queue as a producer, work around: https://developers.cloudflare.com/workers/wrangler/commands/#queues-consumer-add-script-name
|
|
116
128
|
// async composeWorkerArguments({
|
|
@@ -192,8 +204,8 @@ class Infrastructure {
|
|
|
192
204
|
kv(options) {
|
|
193
205
|
const { resourceName, bindingName } = options;
|
|
194
206
|
return new this.sst.cloudflare.Kv(
|
|
195
|
-
`${
|
|
196
|
-
|
|
207
|
+
`${composeBindingName({ resource: "kv", resourceName, bindingName })}`,
|
|
208
|
+
composeKvArguments({
|
|
197
209
|
resourceName: this.composeResourceName({ resourceName })
|
|
198
210
|
})
|
|
199
211
|
);
|
|
@@ -204,8 +216,8 @@ class Infrastructure {
|
|
|
204
216
|
d1(options) {
|
|
205
217
|
const { resourceName, bindingName } = options;
|
|
206
218
|
return new this.sst.cloudflare.D1(
|
|
207
|
-
`${
|
|
208
|
-
|
|
219
|
+
`${composeBindingName({ resource: "d1", resourceName, bindingName })}`,
|
|
220
|
+
composeD1Arguments({
|
|
209
221
|
resourceName: this.composeResourceName({ resourceName })
|
|
210
222
|
})
|
|
211
223
|
);
|
|
@@ -216,8 +228,8 @@ class Infrastructure {
|
|
|
216
228
|
queue(options) {
|
|
217
229
|
const { resourceName, bindingName, deliveryDelay, messageRetentionPeriod } = options;
|
|
218
230
|
return new this.sst.cloudflare.Queue(
|
|
219
|
-
`${
|
|
220
|
-
|
|
231
|
+
`${composeBindingName({ resource: "queue", resourceName, bindingName })}`,
|
|
232
|
+
composeQueueArguments({
|
|
221
233
|
resourceName: this.composeResourceName({ resourceName }),
|
|
222
234
|
deliveryDelay,
|
|
223
235
|
messageRetentionPeriod
|
|
@@ -230,8 +242,8 @@ class Infrastructure {
|
|
|
230
242
|
r2(options) {
|
|
231
243
|
const { resourceName, bindingName, storageClass } = options;
|
|
232
244
|
return new this.sst.cloudflare.Bucket(
|
|
233
|
-
`${
|
|
234
|
-
|
|
245
|
+
`${composeBindingName({ resource: "r2", resourceName, bindingName })}`,
|
|
246
|
+
composeR2Arguments({
|
|
235
247
|
resourceName: this.composeResourceName({ resourceName }),
|
|
236
248
|
storageClass
|
|
237
249
|
})
|
|
@@ -928,4 +940,4 @@ function develitWorker(Worker) {
|
|
|
928
940
|
return DevelitWorker;
|
|
929
941
|
}
|
|
930
942
|
|
|
931
|
-
export { DatabaseTransaction, Infrastructure, RPCResponse, action, 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, useResult, useResultSync, uuidv4 };
|
|
943
|
+
export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, composeBindingName, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useResult, useResultSync, uuidv4, validateEnvironment };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@develit-io/backend-sdk",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.15.1",
|
|
4
4
|
"description": "Develit Backend SDK",
|
|
5
5
|
"author": "Develit.io",
|
|
6
6
|
"license": "ISC",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"sst": "^3.17.12",
|
|
47
|
-
"zod": "^4.1.5"
|
|
47
|
+
"zod": "^4.1.5",
|
|
48
|
+
"@develit-io/general-codes": "^1.11.0"
|
|
48
49
|
}
|
|
49
50
|
}
|