@upstash/qstash 0.1.6 → 0.1.7

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.
Files changed (42) hide show
  1. package/README.md +3 -3
  2. package/esm/deps/deno.land/{std@0.149.0 → std@0.152.0}/_wasm_crypto/lib/deno_std_wasm_crypto.generated.mjs +0 -0
  3. package/esm/deps/deno.land/{std@0.149.0 → std@0.152.0}/_wasm_crypto/mod.js +0 -0
  4. package/esm/deps/deno.land/{std@0.149.0 → std@0.152.0}/crypto/_fnv/fnv32.js +0 -0
  5. package/esm/deps/deno.land/{std@0.149.0 → std@0.152.0}/crypto/_fnv/fnv64.js +0 -0
  6. package/esm/deps/deno.land/{std@0.149.0 → std@0.152.0}/crypto/_fnv/index.js +0 -0
  7. package/esm/deps/deno.land/{std@0.149.0 → std@0.152.0}/crypto/_fnv/util.js +0 -0
  8. package/esm/deps/deno.land/{std@0.149.0 → std@0.152.0}/crypto/mod.js +17 -9
  9. package/esm/deps/deno.land/std@0.152.0/crypto/timing_safe_equal.js +24 -0
  10. package/esm/deps/deno.land/std@0.152.0/fmt/colors.js +442 -0
  11. package/esm/deps/deno.land/std@0.152.0/testing/_diff.js +304 -0
  12. package/esm/deps/deno.land/std@0.152.0/testing/_format.js +21 -0
  13. package/esm/deps/deno.land/std@0.152.0/testing/asserts.js +620 -0
  14. package/esm/pkg/client/client.js +1 -1
  15. package/package.json +1 -1
  16. package/script/deps/deno.land/{std@0.149.0 → std@0.152.0}/_wasm_crypto/lib/deno_std_wasm_crypto.generated.mjs +0 -0
  17. package/script/deps/deno.land/{std@0.149.0 → std@0.152.0}/_wasm_crypto/mod.js +0 -0
  18. package/script/deps/deno.land/{std@0.149.0 → std@0.152.0}/crypto/_fnv/fnv32.js +0 -0
  19. package/script/deps/deno.land/{std@0.149.0 → std@0.152.0}/crypto/_fnv/fnv64.js +0 -0
  20. package/script/deps/deno.land/{std@0.149.0 → std@0.152.0}/crypto/_fnv/index.js +0 -0
  21. package/script/deps/deno.land/{std@0.149.0 → std@0.152.0}/crypto/_fnv/util.js +0 -0
  22. package/script/deps/deno.land/{std@0.149.0 → std@0.152.0}/crypto/mod.js +18 -10
  23. package/script/deps/deno.land/std@0.152.0/crypto/timing_safe_equal.js +28 -0
  24. package/script/deps/deno.land/std@0.152.0/fmt/colors.js +516 -0
  25. package/script/deps/deno.land/std@0.152.0/testing/_diff.js +310 -0
  26. package/script/deps/deno.land/std@0.152.0/testing/_format.js +48 -0
  27. package/script/deps/deno.land/std@0.152.0/testing/asserts.js +645 -0
  28. package/script/pkg/client/client.js +1 -1
  29. package/types/deps/deno.land/{std@0.149.0 → std@0.152.0}/_wasm_crypto/lib/deno_std_wasm_crypto.generated.d.mts +0 -0
  30. package/types/deps/deno.land/{std@0.149.0 → std@0.152.0}/_wasm_crypto/mod.d.ts +0 -0
  31. package/types/deps/deno.land/{std@0.149.0 → std@0.152.0}/crypto/_fnv/fnv32.d.ts +0 -0
  32. package/types/deps/deno.land/{std@0.149.0 → std@0.152.0}/crypto/_fnv/fnv64.d.ts +0 -0
  33. package/types/deps/deno.land/{std@0.149.0 → std@0.152.0}/crypto/_fnv/index.d.ts +0 -0
  34. package/types/deps/deno.land/{std@0.149.0 → std@0.152.0}/crypto/_fnv/util.d.ts +0 -0
  35. package/types/deps/deno.land/std@0.152.0/crypto/mod.d.ts +51 -0
  36. package/types/deps/deno.land/std@0.152.0/crypto/timing_safe_equal.d.ts +3 -0
  37. package/types/deps/deno.land/std@0.152.0/fmt/colors.d.ts +270 -0
  38. package/types/deps/deno.land/std@0.152.0/testing/_diff.d.ts +26 -0
  39. package/types/deps/deno.land/std@0.152.0/testing/_format.d.ts +1 -0
  40. package/types/deps/deno.land/std@0.152.0/testing/asserts.d.ts +160 -0
  41. package/types/pkg/receiver.d.ts +1 -1
  42. package/types/deps/deno.land/std@0.149.0/crypto/mod.d.ts +0 -53
@@ -0,0 +1,645 @@
1
+ "use strict";
2
+ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.unreachable = exports.unimplemented = exports.assertRejects = exports.assertThrows = exports.assertIsError = exports.fail = exports.assertObjectMatch = exports.assertNotMatch = exports.assertMatch = exports.assertArrayIncludes = exports.assertStringIncludes = exports.assertExists = exports.assertInstanceOf = exports.assertAlmostEquals = exports.assertNotStrictEquals = exports.assertStrictEquals = exports.assertNotEquals = exports.assertEquals = exports.assertFalse = exports.assert = exports.equal = exports.AssertionError = void 0;
5
+ /** A library of assertion functions.
6
+ *
7
+ * This module is browser compatible, but do not rely on good formatting of
8
+ * values for AssertionError messages in browsers.
9
+ *
10
+ * @module
11
+ */
12
+ const colors_js_1 = require("../fmt/colors.js");
13
+ const _diff_js_1 = require("./_diff.js");
14
+ const _format_js_1 = require("./_format.js");
15
+ const CAN_NOT_DISPLAY = "[Cannot display]";
16
+ class AssertionError extends Error {
17
+ constructor(message) {
18
+ super(message);
19
+ Object.defineProperty(this, "name", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: "AssertionError"
24
+ });
25
+ }
26
+ }
27
+ exports.AssertionError = AssertionError;
28
+ function isKeyedCollection(x) {
29
+ return [Symbol.iterator, "size"].every((k) => k in x);
30
+ }
31
+ /**
32
+ * Deep equality comparison used in assertions
33
+ * @param c actual value
34
+ * @param d expected value
35
+ */
36
+ function equal(c, d) {
37
+ const seen = new Map();
38
+ return (function compare(a, b) {
39
+ // Have to render RegExp & Date for string comparison
40
+ // unless it's mistreated as object
41
+ if (a &&
42
+ b &&
43
+ ((a instanceof RegExp && b instanceof RegExp) ||
44
+ (a instanceof URL && b instanceof URL))) {
45
+ return String(a) === String(b);
46
+ }
47
+ if (a instanceof Date && b instanceof Date) {
48
+ const aTime = a.getTime();
49
+ const bTime = b.getTime();
50
+ // Check for NaN equality manually since NaN is not
51
+ // equal to itself.
52
+ if (Number.isNaN(aTime) && Number.isNaN(bTime)) {
53
+ return true;
54
+ }
55
+ return aTime === bTime;
56
+ }
57
+ if (typeof a === "number" && typeof b === "number") {
58
+ return Number.isNaN(a) && Number.isNaN(b) || a === b;
59
+ }
60
+ if (Object.is(a, b)) {
61
+ return true;
62
+ }
63
+ if (a && typeof a === "object" && b && typeof b === "object") {
64
+ if (a && b && !constructorsEqual(a, b)) {
65
+ return false;
66
+ }
67
+ if (a instanceof WeakMap || b instanceof WeakMap) {
68
+ if (!(a instanceof WeakMap && b instanceof WeakMap))
69
+ return false;
70
+ throw new TypeError("cannot compare WeakMap instances");
71
+ }
72
+ if (a instanceof WeakSet || b instanceof WeakSet) {
73
+ if (!(a instanceof WeakSet && b instanceof WeakSet))
74
+ return false;
75
+ throw new TypeError("cannot compare WeakSet instances");
76
+ }
77
+ if (seen.get(a) === b) {
78
+ return true;
79
+ }
80
+ if (Object.keys(a || {}).length !== Object.keys(b || {}).length) {
81
+ return false;
82
+ }
83
+ seen.set(a, b);
84
+ if (isKeyedCollection(a) && isKeyedCollection(b)) {
85
+ if (a.size !== b.size) {
86
+ return false;
87
+ }
88
+ let unmatchedEntries = a.size;
89
+ for (const [aKey, aValue] of a.entries()) {
90
+ for (const [bKey, bValue] of b.entries()) {
91
+ /* Given that Map keys can be references, we need
92
+ * to ensure that they are also deeply equal */
93
+ if ((aKey === aValue && bKey === bValue && compare(aKey, bKey)) ||
94
+ (compare(aKey, bKey) && compare(aValue, bValue))) {
95
+ unmatchedEntries--;
96
+ break;
97
+ }
98
+ }
99
+ }
100
+ return unmatchedEntries === 0;
101
+ }
102
+ const merged = { ...a, ...b };
103
+ for (const key of [
104
+ ...Object.getOwnPropertyNames(merged),
105
+ ...Object.getOwnPropertySymbols(merged),
106
+ ]) {
107
+ if (!compare(a && a[key], b && b[key])) {
108
+ return false;
109
+ }
110
+ if (((key in a) && (!(key in b))) || ((key in b) && (!(key in a)))) {
111
+ return false;
112
+ }
113
+ }
114
+ if (a instanceof WeakRef || b instanceof WeakRef) {
115
+ if (!(a instanceof WeakRef && b instanceof WeakRef))
116
+ return false;
117
+ return compare(a.deref(), b.deref());
118
+ }
119
+ return true;
120
+ }
121
+ return false;
122
+ })(c, d);
123
+ }
124
+ exports.equal = equal;
125
+ // deno-lint-ignore ban-types
126
+ function constructorsEqual(a, b) {
127
+ return a.constructor === b.constructor ||
128
+ a.constructor === Object && !b.constructor ||
129
+ !a.constructor && b.constructor === Object;
130
+ }
131
+ /** Make an assertion, error will be thrown if `expr` does not have truthy value. */
132
+ function assert(expr, msg = "") {
133
+ if (!expr) {
134
+ throw new AssertionError(msg);
135
+ }
136
+ }
137
+ exports.assert = assert;
138
+ /** Make an assertion, error will be thrown if `expr` have truthy value. */
139
+ function assertFalse(expr, msg = "") {
140
+ if (expr) {
141
+ throw new AssertionError(msg);
142
+ }
143
+ }
144
+ exports.assertFalse = assertFalse;
145
+ /**
146
+ * Make an assertion that `actual` and `expected` are equal, deeply. If not
147
+ * deeply equal, then throw.
148
+ *
149
+ * Type parameter can be specified to ensure values under comparison have the same type.
150
+ * For example:
151
+ * ```ts
152
+ * import { assertEquals } from "./asserts.ts";
153
+ *
154
+ * assertEquals<number>(1, 2)
155
+ * ```
156
+ */
157
+ function assertEquals(actual, expected, msg) {
158
+ if (equal(actual, expected)) {
159
+ return;
160
+ }
161
+ let message = "";
162
+ const actualString = (0, _format_js_1.format)(actual);
163
+ const expectedString = (0, _format_js_1.format)(expected);
164
+ try {
165
+ const stringDiff = (typeof actual === "string") &&
166
+ (typeof expected === "string");
167
+ const diffResult = stringDiff
168
+ ? (0, _diff_js_1.diffstr)(actual, expected)
169
+ : (0, _diff_js_1.diff)(actualString.split("\n"), expectedString.split("\n"));
170
+ const diffMsg = (0, _diff_js_1.buildMessage)(diffResult, { stringDiff }).join("\n");
171
+ message = `Values are not equal:\n${diffMsg}`;
172
+ }
173
+ catch {
174
+ message = `\n${(0, colors_js_1.red)(CAN_NOT_DISPLAY)} + \n\n`;
175
+ }
176
+ if (msg) {
177
+ message = msg;
178
+ }
179
+ throw new AssertionError(message);
180
+ }
181
+ exports.assertEquals = assertEquals;
182
+ /**
183
+ * Make an assertion that `actual` and `expected` are not equal, deeply.
184
+ * If not then throw.
185
+ *
186
+ * Type parameter can be specified to ensure values under comparison have the same type.
187
+ * For example:
188
+ * ```ts
189
+ * import { assertNotEquals } from "./asserts.ts";
190
+ *
191
+ * assertNotEquals<number>(1, 2)
192
+ * ```
193
+ */
194
+ function assertNotEquals(actual, expected, msg) {
195
+ if (!equal(actual, expected)) {
196
+ return;
197
+ }
198
+ let actualString;
199
+ let expectedString;
200
+ try {
201
+ actualString = String(actual);
202
+ }
203
+ catch {
204
+ actualString = "[Cannot display]";
205
+ }
206
+ try {
207
+ expectedString = String(expected);
208
+ }
209
+ catch {
210
+ expectedString = "[Cannot display]";
211
+ }
212
+ if (!msg) {
213
+ msg = `actual: ${actualString} expected not to be: ${expectedString}`;
214
+ }
215
+ throw new AssertionError(msg);
216
+ }
217
+ exports.assertNotEquals = assertNotEquals;
218
+ /**
219
+ * Make an assertion that `actual` and `expected` are strictly equal. If
220
+ * not then throw.
221
+ *
222
+ * ```ts
223
+ * import { assertStrictEquals } from "./asserts.ts";
224
+ *
225
+ * assertStrictEquals(1, 2)
226
+ * ```
227
+ */
228
+ function assertStrictEquals(actual, expected, msg) {
229
+ if (Object.is(actual, expected)) {
230
+ return;
231
+ }
232
+ let message;
233
+ if (msg) {
234
+ message = msg;
235
+ }
236
+ else {
237
+ const actualString = (0, _format_js_1.format)(actual);
238
+ const expectedString = (0, _format_js_1.format)(expected);
239
+ if (actualString === expectedString) {
240
+ const withOffset = actualString
241
+ .split("\n")
242
+ .map((l) => ` ${l}`)
243
+ .join("\n");
244
+ message =
245
+ `Values have the same structure but are not reference-equal:\n\n${(0, colors_js_1.red)(withOffset)}\n`;
246
+ }
247
+ else {
248
+ try {
249
+ const stringDiff = (typeof actual === "string") &&
250
+ (typeof expected === "string");
251
+ const diffResult = stringDiff
252
+ ? (0, _diff_js_1.diffstr)(actual, expected)
253
+ : (0, _diff_js_1.diff)(actualString.split("\n"), expectedString.split("\n"));
254
+ const diffMsg = (0, _diff_js_1.buildMessage)(diffResult, { stringDiff }).join("\n");
255
+ message = `Values are not strictly equal:\n${diffMsg}`;
256
+ }
257
+ catch {
258
+ message = `\n${(0, colors_js_1.red)(CAN_NOT_DISPLAY)} + \n\n`;
259
+ }
260
+ }
261
+ }
262
+ throw new AssertionError(message);
263
+ }
264
+ exports.assertStrictEquals = assertStrictEquals;
265
+ /**
266
+ * Make an assertion that `actual` and `expected` are not strictly equal.
267
+ * If the values are strictly equal then throw.
268
+ *
269
+ * ```ts
270
+ * import { assertNotStrictEquals } from "./asserts.ts";
271
+ *
272
+ * assertNotStrictEquals(1, 1)
273
+ * ```
274
+ */
275
+ function assertNotStrictEquals(actual, expected, msg) {
276
+ if (!Object.is(actual, expected)) {
277
+ return;
278
+ }
279
+ throw new AssertionError(msg ?? `Expected "actual" to be strictly unequal to: ${(0, _format_js_1.format)(actual)}\n`);
280
+ }
281
+ exports.assertNotStrictEquals = assertNotStrictEquals;
282
+ /**
283
+ * Make an assertion that `actual` and `expected` are almost equal numbers through
284
+ * a given tolerance. It can be used to take into account IEEE-754 double-precision
285
+ * floating-point representation limitations.
286
+ * If the values are not almost equal then throw.
287
+ *
288
+ * ```ts
289
+ * import { assertAlmostEquals, assertThrows } from "./asserts.ts";
290
+ *
291
+ * assertAlmostEquals(0.1, 0.2);
292
+ *
293
+ * // Using a custom tolerance value
294
+ * assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16);
295
+ * assertThrows(() => assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17));
296
+ * ```
297
+ */
298
+ function assertAlmostEquals(actual, expected, tolerance = 1e-7, msg) {
299
+ if (Object.is(actual, expected)) {
300
+ return;
301
+ }
302
+ const delta = Math.abs(expected - actual);
303
+ if (delta <= tolerance) {
304
+ return;
305
+ }
306
+ const f = (n) => Number.isInteger(n) ? n : n.toExponential();
307
+ throw new AssertionError(msg ??
308
+ `actual: "${f(actual)}" expected to be close to "${f(expected)}": \
309
+ delta "${f(delta)}" is greater than "${f(tolerance)}"`);
310
+ }
311
+ exports.assertAlmostEquals = assertAlmostEquals;
312
+ /**
313
+ * Make an assertion that `obj` is an instance of `type`.
314
+ * If not then throw.
315
+ */
316
+ function assertInstanceOf(actual, expectedType, msg = "") {
317
+ if (!msg) {
318
+ const expectedTypeStr = expectedType.name;
319
+ let actualTypeStr = "";
320
+ if (actual === null) {
321
+ actualTypeStr = "null";
322
+ }
323
+ else if (actual === undefined) {
324
+ actualTypeStr = "undefined";
325
+ }
326
+ else if (typeof actual === "object") {
327
+ actualTypeStr = actual.constructor?.name ?? "Object";
328
+ }
329
+ else {
330
+ actualTypeStr = typeof actual;
331
+ }
332
+ if (expectedTypeStr == actualTypeStr) {
333
+ msg = `Expected object to be an instance of "${expectedTypeStr}".`;
334
+ }
335
+ else if (actualTypeStr == "function") {
336
+ msg =
337
+ `Expected object to be an instance of "${expectedTypeStr}" but was not an instanced object.`;
338
+ }
339
+ else {
340
+ msg =
341
+ `Expected object to be an instance of "${expectedTypeStr}" but was "${actualTypeStr}".`;
342
+ }
343
+ }
344
+ assert(actual instanceof expectedType, msg);
345
+ }
346
+ exports.assertInstanceOf = assertInstanceOf;
347
+ /**
348
+ * Make an assertion that actual is not null or undefined.
349
+ * If not then throw.
350
+ */
351
+ function assertExists(actual, msg) {
352
+ if (actual === undefined || actual === null) {
353
+ if (!msg) {
354
+ msg = `actual: "${actual}" expected to not be null or undefined`;
355
+ }
356
+ throw new AssertionError(msg);
357
+ }
358
+ }
359
+ exports.assertExists = assertExists;
360
+ /**
361
+ * Make an assertion that actual includes expected. If not
362
+ * then throw.
363
+ */
364
+ function assertStringIncludes(actual, expected, msg) {
365
+ if (!actual.includes(expected)) {
366
+ if (!msg) {
367
+ msg = `actual: "${actual}" expected to contain: "${expected}"`;
368
+ }
369
+ throw new AssertionError(msg);
370
+ }
371
+ }
372
+ exports.assertStringIncludes = assertStringIncludes;
373
+ /**
374
+ * Make an assertion that `actual` includes the `expected` values.
375
+ * If not then an error will be thrown.
376
+ *
377
+ * Type parameter can be specified to ensure values under comparison have the same type.
378
+ * For example:
379
+ *
380
+ * ```ts
381
+ * import { assertArrayIncludes } from "./asserts.ts";
382
+ *
383
+ * assertArrayIncludes<number>([1, 2], [2])
384
+ * ```
385
+ */
386
+ function assertArrayIncludes(actual, expected, msg) {
387
+ const missing = [];
388
+ for (let i = 0; i < expected.length; i++) {
389
+ let found = false;
390
+ for (let j = 0; j < actual.length; j++) {
391
+ if (equal(expected[i], actual[j])) {
392
+ found = true;
393
+ break;
394
+ }
395
+ }
396
+ if (!found) {
397
+ missing.push(expected[i]);
398
+ }
399
+ }
400
+ if (missing.length === 0) {
401
+ return;
402
+ }
403
+ if (!msg) {
404
+ msg = `actual: "${(0, _format_js_1.format)(actual)}" expected to include: "${(0, _format_js_1.format)(expected)}"\nmissing: ${(0, _format_js_1.format)(missing)}`;
405
+ }
406
+ throw new AssertionError(msg);
407
+ }
408
+ exports.assertArrayIncludes = assertArrayIncludes;
409
+ /**
410
+ * Make an assertion that `actual` match RegExp `expected`. If not
411
+ * then throw.
412
+ */
413
+ function assertMatch(actual, expected, msg) {
414
+ if (!expected.test(actual)) {
415
+ if (!msg) {
416
+ msg = `actual: "${actual}" expected to match: "${expected}"`;
417
+ }
418
+ throw new AssertionError(msg);
419
+ }
420
+ }
421
+ exports.assertMatch = assertMatch;
422
+ /**
423
+ * Make an assertion that `actual` not match RegExp `expected`. If match
424
+ * then throw.
425
+ */
426
+ function assertNotMatch(actual, expected, msg) {
427
+ if (expected.test(actual)) {
428
+ if (!msg) {
429
+ msg = `actual: "${actual}" expected to not match: "${expected}"`;
430
+ }
431
+ throw new AssertionError(msg);
432
+ }
433
+ }
434
+ exports.assertNotMatch = assertNotMatch;
435
+ /**
436
+ * Make an assertion that `actual` object is a subset of `expected` object, deeply.
437
+ * If not, then throw.
438
+ */
439
+ function assertObjectMatch(
440
+ // deno-lint-ignore no-explicit-any
441
+ actual, expected) {
442
+ function filter(a, b) {
443
+ const seen = new WeakMap();
444
+ return fn(a, b);
445
+ function fn(a, b) {
446
+ // Prevent infinite loop with circular references with same filter
447
+ if ((seen.has(a)) && (seen.get(a) === b)) {
448
+ return a;
449
+ }
450
+ seen.set(a, b);
451
+ // Filter keys and symbols which are present in both actual and expected
452
+ const filtered = {};
453
+ const entries = [
454
+ ...Object.getOwnPropertyNames(a),
455
+ ...Object.getOwnPropertySymbols(a),
456
+ ]
457
+ .filter((key) => key in b)
458
+ .map((key) => [key, a[key]]);
459
+ for (const [key, value] of entries) {
460
+ // On array references, build a filtered array and filter nested objects inside
461
+ if (Array.isArray(value)) {
462
+ const subset = b[key];
463
+ if (Array.isArray(subset)) {
464
+ filtered[key] = fn({ ...value }, { ...subset });
465
+ continue;
466
+ }
467
+ } // On regexp references, keep value as it to avoid loosing pattern and flags
468
+ else if (value instanceof RegExp) {
469
+ filtered[key] = value;
470
+ continue;
471
+ } // On nested objects references, build a filtered object recursively
472
+ else if (typeof value === "object") {
473
+ const subset = b[key];
474
+ if ((typeof subset === "object") && (subset)) {
475
+ // When both operands are maps, build a filtered map with common keys and filter nested objects inside
476
+ if ((value instanceof Map) && (subset instanceof Map)) {
477
+ filtered[key] = new Map([...value].filter(([k]) => subset.has(k)).map(([k, v]) => [k, typeof v === "object" ? fn(v, subset.get(k)) : v]));
478
+ continue;
479
+ }
480
+ // When both operands are set, build a filtered set with common values
481
+ if ((value instanceof Set) && (subset instanceof Set)) {
482
+ filtered[key] = new Set([...value].filter((v) => subset.has(v)));
483
+ continue;
484
+ }
485
+ filtered[key] = fn(value, subset);
486
+ continue;
487
+ }
488
+ }
489
+ filtered[key] = value;
490
+ }
491
+ return filtered;
492
+ }
493
+ }
494
+ return assertEquals(
495
+ // get the intersection of "actual" and "expected"
496
+ // side effect: all the instances' constructor field is "Object" now.
497
+ filter(actual, expected),
498
+ // set (nested) instances' constructor field to be "Object" without changing expected value.
499
+ // see https://github.com/denoland/deno_std/pull/1419
500
+ filter(expected, expected));
501
+ }
502
+ exports.assertObjectMatch = assertObjectMatch;
503
+ /**
504
+ * Forcefully throws a failed assertion
505
+ */
506
+ function fail(msg) {
507
+ assert(false, `Failed assertion${msg ? `: ${msg}` : "."}`);
508
+ }
509
+ exports.fail = fail;
510
+ /**
511
+ * Make an assertion that `error` is an `Error`.
512
+ * If not then an error will be thrown.
513
+ * An error class and a string that should be included in the
514
+ * error message can also be asserted.
515
+ */
516
+ function assertIsError(error,
517
+ // deno-lint-ignore no-explicit-any
518
+ ErrorClass, msgIncludes, msg) {
519
+ if (error instanceof Error === false) {
520
+ throw new AssertionError(`Expected "error" to be an Error object.`);
521
+ }
522
+ if (ErrorClass && !(error instanceof ErrorClass)) {
523
+ msg = `Expected error to be instance of "${ErrorClass.name}", but was "${typeof error === "object" ? error?.constructor?.name : "[not an object]"}"${msg ? `: ${msg}` : "."}`;
524
+ throw new AssertionError(msg);
525
+ }
526
+ if (msgIncludes && (!(error instanceof Error) ||
527
+ !(0, colors_js_1.stripColor)(error.message).includes((0, colors_js_1.stripColor)(msgIncludes)))) {
528
+ msg = `Expected error message to include "${msgIncludes}", but got "${error instanceof Error ? error.message : "[not an Error]"}"${msg ? `: ${msg}` : "."}`;
529
+ throw new AssertionError(msg);
530
+ }
531
+ }
532
+ exports.assertIsError = assertIsError;
533
+ function assertThrows(fn, errorClassOrCallbackOrMsg, msgIncludesOrMsg, msg) {
534
+ // deno-lint-ignore no-explicit-any
535
+ let ErrorClass = undefined;
536
+ let msgIncludes = undefined;
537
+ let errorCallback = undefined;
538
+ let err;
539
+ if (typeof errorClassOrCallbackOrMsg !== "string") {
540
+ if (errorClassOrCallbackOrMsg === undefined ||
541
+ errorClassOrCallbackOrMsg.prototype instanceof Error ||
542
+ errorClassOrCallbackOrMsg.prototype === Error.prototype) {
543
+ // deno-lint-ignore no-explicit-any
544
+ ErrorClass = errorClassOrCallbackOrMsg;
545
+ msgIncludes = msgIncludesOrMsg;
546
+ }
547
+ else {
548
+ errorCallback = errorClassOrCallbackOrMsg;
549
+ msg = msgIncludesOrMsg;
550
+ }
551
+ }
552
+ else {
553
+ msg = errorClassOrCallbackOrMsg;
554
+ }
555
+ let doesThrow = false;
556
+ const msgToAppendToError = msg ? `: ${msg}` : ".";
557
+ try {
558
+ fn();
559
+ }
560
+ catch (error) {
561
+ if (ErrorClass || errorCallback) {
562
+ if (error instanceof Error === false) {
563
+ throw new AssertionError("A non-Error object was thrown.");
564
+ }
565
+ assertIsError(error, ErrorClass, msgIncludes, msg);
566
+ if (typeof errorCallback === "function") {
567
+ errorCallback(error);
568
+ }
569
+ }
570
+ err = error;
571
+ doesThrow = true;
572
+ }
573
+ if (!doesThrow) {
574
+ msg = `Expected function to throw${msgToAppendToError}`;
575
+ throw new AssertionError(msg);
576
+ }
577
+ return err;
578
+ }
579
+ exports.assertThrows = assertThrows;
580
+ async function assertRejects(fn, errorClassOrCallbackOrMsg, msgIncludesOrMsg, msg) {
581
+ // deno-lint-ignore no-explicit-any
582
+ let ErrorClass = undefined;
583
+ let msgIncludes = undefined;
584
+ let errorCallback = undefined;
585
+ let err;
586
+ if (typeof errorClassOrCallbackOrMsg !== "string") {
587
+ if (errorClassOrCallbackOrMsg === undefined ||
588
+ errorClassOrCallbackOrMsg.prototype instanceof Error ||
589
+ errorClassOrCallbackOrMsg.prototype === Error.prototype) {
590
+ // deno-lint-ignore no-explicit-any
591
+ ErrorClass = errorClassOrCallbackOrMsg;
592
+ msgIncludes = msgIncludesOrMsg;
593
+ }
594
+ else {
595
+ errorCallback = errorClassOrCallbackOrMsg;
596
+ msg = msgIncludesOrMsg;
597
+ }
598
+ }
599
+ else {
600
+ msg = errorClassOrCallbackOrMsg;
601
+ }
602
+ let doesThrow = false;
603
+ let isPromiseReturned = false;
604
+ const msgToAppendToError = msg ? `: ${msg}` : ".";
605
+ try {
606
+ const possiblePromise = fn();
607
+ if (possiblePromise &&
608
+ typeof possiblePromise === "object" &&
609
+ typeof possiblePromise.then === "function") {
610
+ isPromiseReturned = true;
611
+ await possiblePromise;
612
+ }
613
+ }
614
+ catch (error) {
615
+ if (!isPromiseReturned) {
616
+ throw new AssertionError(`Function throws when expected to reject${msgToAppendToError}`);
617
+ }
618
+ if (ErrorClass || errorCallback) {
619
+ if (error instanceof Error === false) {
620
+ throw new AssertionError("A non-Error object was rejected.");
621
+ }
622
+ assertIsError(error, ErrorClass, msgIncludes, msg);
623
+ if (typeof errorCallback == "function") {
624
+ errorCallback(error);
625
+ }
626
+ }
627
+ err = error;
628
+ doesThrow = true;
629
+ }
630
+ if (!doesThrow) {
631
+ throw new AssertionError(`Expected function to reject${msgToAppendToError}`);
632
+ }
633
+ return err;
634
+ }
635
+ exports.assertRejects = assertRejects;
636
+ /** Use this to stub out methods that will throw when invoked. */
637
+ function unimplemented(msg) {
638
+ throw new AssertionError(msg || "unimplemented");
639
+ }
640
+ exports.unimplemented = unimplemented;
641
+ /** Use this to assert unreachable code. */
642
+ function unreachable() {
643
+ throw new AssertionError("unreachable");
644
+ }
645
+ exports.unreachable = unreachable;
@@ -60,7 +60,7 @@ class Client {
60
60
  }
61
61
  const headers = new Headers(req.headers);
62
62
  if (req.delay) {
63
- headers.set("Upstash-Delay", req.delay.toFixed());
63
+ headers.set("Upstash-Delay", `${req.delay.toFixed()}s`);
64
64
  }
65
65
  if (req.notBefore) {
66
66
  headers.set("Upstash-Not-Before", req.notBefore.toFixed());