flashq 0.3.2 → 0.3.4

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.
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ /**
3
+ * Input validation utilities for FlashQ client.
4
+ *
5
+ * Provides validation functions for queue names, job data sizes,
6
+ * and batch operation limits.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.MAX_BATCH_SIZE = exports.MAX_JOB_DATA_SIZE = void 0;
10
+ exports.validateQueueName = validateQueueName;
11
+ exports.validateJobDataSize = validateJobDataSize;
12
+ exports.validateBatchSize = validateBatchSize;
13
+ exports.validateJobId = validateJobId;
14
+ exports.validateTimeout = validateTimeout;
15
+ const errors_1 = require("../errors");
16
+ /** Maximum allowed job data size in bytes (1MB) */
17
+ exports.MAX_JOB_DATA_SIZE = 1024 * 1024;
18
+ /** Maximum number of jobs per batch operation */
19
+ exports.MAX_BATCH_SIZE = 1000;
20
+ /** Regex pattern for valid queue names: alphanumeric, underscore, hyphen, dot (1-256 chars) */
21
+ const QUEUE_NAME_REGEX = /^[a-zA-Z0-9_.-]{1,256}$/;
22
+ /**
23
+ * Validates a queue name against naming rules.
24
+ *
25
+ * Queue names must:
26
+ * - Be non-empty strings
27
+ * - Contain only alphanumeric characters, underscores, hyphens, or dots
28
+ * - Be between 1 and 256 characters long
29
+ *
30
+ * @param queue - The queue name to validate
31
+ * @throws ValidationError if the queue name is invalid
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * validateQueueName('my-queue'); // OK
36
+ * validateQueueName('queue.name'); // OK
37
+ * validateQueueName('queue name'); // Throws: contains space
38
+ * validateQueueName(''); // Throws: empty
39
+ * ```
40
+ */
41
+ function validateQueueName(queue) {
42
+ if (!queue || typeof queue !== 'string') {
43
+ throw new errors_1.ValidationError('Queue name is required', 'queue');
44
+ }
45
+ if (!QUEUE_NAME_REGEX.test(queue)) {
46
+ throw new errors_1.ValidationError(`Invalid queue name: "${queue}". Must be alphanumeric, _, -, . (1-256 chars)`, 'queue');
47
+ }
48
+ }
49
+ /**
50
+ * Validates that job data does not exceed the maximum allowed size.
51
+ *
52
+ * The size is calculated by JSON-stringifying the data and measuring
53
+ * the resulting string length in bytes.
54
+ *
55
+ * @param data - The job data to validate
56
+ * @throws ValidationError if the data exceeds MAX_JOB_DATA_SIZE
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * validateJobDataSize({ small: 'data' }); // OK
61
+ * validateJobDataSize(largeBuffer); // Throws if > 1MB
62
+ * ```
63
+ */
64
+ function validateJobDataSize(data) {
65
+ const size = JSON.stringify(data).length;
66
+ if (size > exports.MAX_JOB_DATA_SIZE) {
67
+ throw new errors_1.ValidationError(`Job data size (${size} bytes) exceeds max (${exports.MAX_JOB_DATA_SIZE} bytes)`, 'data');
68
+ }
69
+ }
70
+ /**
71
+ * Validates batch operation size.
72
+ *
73
+ * @param count - Number of items in the batch
74
+ * @param operation - Name of the operation for error messages
75
+ * @throws ValidationError if count exceeds MAX_BATCH_SIZE
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * validateBatchSize(100, 'push'); // OK
80
+ * validateBatchSize(1500, 'push'); // Throws: exceeds 1000
81
+ * ```
82
+ */
83
+ function validateBatchSize(count, operation) {
84
+ if (count > exports.MAX_BATCH_SIZE) {
85
+ throw new errors_1.ValidationError(`Batch ${operation} size (${count}) exceeds max (${exports.MAX_BATCH_SIZE})`, 'batch');
86
+ }
87
+ }
88
+ /**
89
+ * Validates a job ID is a positive integer.
90
+ *
91
+ * @param jobId - The job ID to validate
92
+ * @throws ValidationError if jobId is not a positive integer
93
+ */
94
+ function validateJobId(jobId) {
95
+ if (!Number.isInteger(jobId) || jobId <= 0) {
96
+ throw new errors_1.ValidationError(`Invalid job ID: ${jobId}. Must be a positive integer`, 'jobId');
97
+ }
98
+ }
99
+ /**
100
+ * Validates a timeout value is within acceptable bounds.
101
+ *
102
+ * @param timeout - Timeout in milliseconds
103
+ * @param min - Minimum allowed value (default: 0)
104
+ * @param max - Maximum allowed value (default: 10 minutes)
105
+ * @throws ValidationError if timeout is out of bounds
106
+ */
107
+ function validateTimeout(timeout, min = 0, max = 600000) {
108
+ if (timeout < min || timeout > max) {
109
+ throw new errors_1.ValidationError(`Timeout ${timeout}ms out of bounds (${min}-${max}ms)`, 'timeout');
110
+ }
111
+ }
112
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/client/validation.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAgCH,8CAUC;AAiBD,kDAQC;AAeD,8CAOC;AAQD,sCAIC;AAUD,0CAOC;AApHD,sCAA4C;AAE5C,mDAAmD;AACtC,QAAA,iBAAiB,GAAG,IAAI,GAAG,IAAI,CAAC;AAE7C,iDAAiD;AACpC,QAAA,cAAc,GAAG,IAAI,CAAC;AAEnC,+FAA+F;AAC/F,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AAEnD;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,iBAAiB,CAAC,KAAa;IAC7C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,MAAM,IAAI,wBAAe,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAC;IAC/D,CAAC;IACD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,wBAAe,CACvB,wBAAwB,KAAK,gDAAgD,EAC7E,OAAO,CACR,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,mBAAmB,CAAC,IAAa;IAC/C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;IACzC,IAAI,IAAI,GAAG,yBAAiB,EAAE,CAAC;QAC7B,MAAM,IAAI,wBAAe,CACvB,kBAAkB,IAAI,wBAAwB,yBAAiB,SAAS,EACxE,MAAM,CACP,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,iBAAiB,CAAC,KAAa,EAAE,SAAiB;IAChE,IAAI,KAAK,GAAG,sBAAc,EAAE,CAAC;QAC3B,MAAM,IAAI,wBAAe,CACvB,SAAS,SAAS,UAAU,KAAK,kBAAkB,sBAAc,GAAG,EACpE,OAAO,CACR,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,KAAa;IACzC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,wBAAe,CAAC,mBAAmB,KAAK,8BAA8B,EAAE,OAAO,CAAC,CAAC;IAC7F,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,eAAe,CAAC,OAAe,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,MAAM;IACpE,IAAI,OAAO,GAAG,GAAG,IAAI,OAAO,GAAG,GAAG,EAAE,CAAC;QACnC,MAAM,IAAI,wBAAe,CACvB,WAAW,OAAO,qBAAqB,GAAG,IAAI,GAAG,KAAK,EACtD,SAAS,CACV,CAAC;IACJ,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flashq",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "Official TypeScript SDK for flashQ - High-Performance Job Queue (BullMQ-compatible API)",
5
5
  "author": "Egeo Minotti",
6
6
  "license": "MIT",