two-stroke 1.0.15 → 1.0.17
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/bin/deploy.mjs +0 -12
- package/package.json +1 -1
- package/src/index.ts +26 -0
- package/src/test.ts +16 -16
package/bin/deploy.mjs
CHANGED
|
@@ -10,16 +10,4 @@ const release = process.argv[3];
|
|
|
10
10
|
fs.writeFileSync("src/release.ts", `export default "${release}";`);
|
|
11
11
|
|
|
12
12
|
cmd(`wrangler secret:bulk /dev/stdin --env ${env}`);
|
|
13
|
-
cmd(
|
|
14
|
-
`sentry-cli releases --org change-engine --project ${basename(process.cwd())} new ${release} --finalize`,
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
cmd(
|
|
18
|
-
`sentry-cli releases --org change-engine --project ${basename(process.cwd())} set-commits ${release}`,
|
|
19
|
-
);
|
|
20
|
-
|
|
21
13
|
cmd(`wrangler deploy --env ${env} --outdir dist`);
|
|
22
|
-
|
|
23
|
-
cmd(
|
|
24
|
-
`sentry-cli sourcemaps --org change-engine --project ${basename(process.cwd())} upload --release="${release}" dist`,
|
|
25
|
-
);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -380,3 +380,29 @@ export function twoStroke<T extends Env>(title: string, release: string) {
|
|
|
380
380
|
},
|
|
381
381
|
};
|
|
382
382
|
}
|
|
383
|
+
|
|
384
|
+
type AddToQueueConfig = QueueSendOptions & {
|
|
385
|
+
retries?: number;
|
|
386
|
+
backoffFactor?: number;
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
export async function addToQueue<T>(
|
|
390
|
+
queue: Queue<T>,
|
|
391
|
+
message: T,
|
|
392
|
+
config: AddToQueueConfig = {}
|
|
393
|
+
) {
|
|
394
|
+
const { retries, backoffFactor, ...options } = config;
|
|
395
|
+
|
|
396
|
+
for (let i = 0; i < (retries ?? 5); i++) {
|
|
397
|
+
try {
|
|
398
|
+
await queue.send(message, options);
|
|
399
|
+
return;
|
|
400
|
+
} catch (err) {
|
|
401
|
+
const backoff = (backoffFactor ?? 2) ** i;
|
|
402
|
+
console.log(`Error adding to queue: ${err}`);
|
|
403
|
+
console.log(`Retrying in ${backoff} seconds`);
|
|
404
|
+
await new Promise((resolve) => setTimeout(resolve, backoff * 1000));
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
throw new Error("Failed to add to queue");
|
|
408
|
+
}
|
package/src/test.ts
CHANGED
|
@@ -25,32 +25,32 @@ export const setupTests = async <Paths extends {}>(bindings: Env) => {
|
|
|
25
25
|
...bindings,
|
|
26
26
|
},
|
|
27
27
|
queueConsumers: (config.queues?.consumers ?? []).map(
|
|
28
|
-
({ queue }: { queue: string }) => queue
|
|
28
|
+
({ queue }: { queue: string }) => queue,
|
|
29
29
|
),
|
|
30
30
|
queueProducers: Object.fromEntries(
|
|
31
31
|
(config.queues?.producers ?? []).map(
|
|
32
32
|
({ binding, queue }: { queue: string; binding: string }) => [
|
|
33
33
|
binding,
|
|
34
34
|
queue,
|
|
35
|
-
]
|
|
36
|
-
)
|
|
35
|
+
],
|
|
36
|
+
),
|
|
37
37
|
),
|
|
38
38
|
r2Buckets: (config.r2_buckets ?? []).map(
|
|
39
|
-
({ binding }: { binding: string }) => binding
|
|
39
|
+
({ binding }: { binding: string }) => binding,
|
|
40
40
|
),
|
|
41
41
|
kvNamespaces: (config.kv_namespaces ?? []).map(
|
|
42
|
-
({ binding }: { binding: string }) => binding
|
|
42
|
+
({ binding }: { binding: string }) => binding,
|
|
43
43
|
),
|
|
44
44
|
d1Databases: (config.d1_databases ?? []).map(
|
|
45
|
-
({ binding }: { binding: string }) => binding
|
|
45
|
+
({ binding }: { binding: string }) => binding,
|
|
46
46
|
),
|
|
47
47
|
serviceBindings: Object.fromEntries(
|
|
48
48
|
(config.services ?? []).map(
|
|
49
49
|
({ binding, service }: { binding: string; service: string }) => [
|
|
50
50
|
binding,
|
|
51
51
|
service,
|
|
52
|
-
]
|
|
53
|
-
)
|
|
52
|
+
],
|
|
53
|
+
),
|
|
54
54
|
),
|
|
55
55
|
fetchMock,
|
|
56
56
|
});
|
|
@@ -94,8 +94,8 @@ export const setupTests = async <Paths extends {}>(bindings: Env) => {
|
|
|
94
94
|
migration = migration.split("\n").slice(1).join(" ");
|
|
95
95
|
await d1.exec(migration);
|
|
96
96
|
}
|
|
97
|
-
}
|
|
98
|
-
)
|
|
97
|
+
},
|
|
98
|
+
),
|
|
99
99
|
);
|
|
100
100
|
|
|
101
101
|
const client = createClient<Paths>({ baseUrl: url.toString() });
|
|
@@ -134,7 +134,7 @@ export const setupTests = async <Paths extends {}>(bindings: Env) => {
|
|
|
134
134
|
headers: {
|
|
135
135
|
"Content-Type": "application/json",
|
|
136
136
|
},
|
|
137
|
-
}
|
|
137
|
+
},
|
|
138
138
|
)
|
|
139
139
|
.persist();
|
|
140
140
|
fetchMock
|
|
@@ -149,7 +149,7 @@ export const setupTests = async <Paths extends {}>(bindings: Env) => {
|
|
|
149
149
|
headers: {
|
|
150
150
|
"Content-Type": "application/json",
|
|
151
151
|
},
|
|
152
|
-
}
|
|
152
|
+
},
|
|
153
153
|
)
|
|
154
154
|
.persist();
|
|
155
155
|
return await new SignJWT(claims)
|
|
@@ -181,7 +181,7 @@ export function recordRequest(
|
|
|
181
181
|
data: string | object | Buffer | undefined,
|
|
182
182
|
responseOptions?: {
|
|
183
183
|
headers: Record<string, string | string[] | undefined>;
|
|
184
|
-
}
|
|
184
|
+
},
|
|
185
185
|
) {
|
|
186
186
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
187
187
|
return ({ body }: any) => {
|
|
@@ -197,7 +197,7 @@ export function recordFormRequest(
|
|
|
197
197
|
data: string | object | Buffer | undefined,
|
|
198
198
|
responseOptions?: {
|
|
199
199
|
headers: Record<string, string | string[] | undefined>;
|
|
200
|
-
}
|
|
200
|
+
},
|
|
201
201
|
) {
|
|
202
202
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
203
203
|
return ({ body }: any) => {
|
|
@@ -205,7 +205,7 @@ export function recordFormRequest(
|
|
|
205
205
|
.text(body)
|
|
206
206
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
207
207
|
.then((data: any) =>
|
|
208
|
-
cb(Object.fromEntries(new URLSearchParams(data).entries()))
|
|
208
|
+
cb(Object.fromEntries(new URLSearchParams(data).entries())),
|
|
209
209
|
);
|
|
210
210
|
return { statusCode, data, responseOptions };
|
|
211
211
|
};
|
|
@@ -218,7 +218,7 @@ export function recordFirehoseRequest(
|
|
|
218
218
|
data: string | object | Buffer | undefined,
|
|
219
219
|
responseOptions?: {
|
|
220
220
|
headers: Record<string, string | string[] | undefined>;
|
|
221
|
-
}
|
|
221
|
+
},
|
|
222
222
|
) {
|
|
223
223
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
224
224
|
return ({ body }: any) => {
|