tspace-mysql 1.9.3 → 1.9.4-beta.10

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 (129) hide show
  1. package/README.md +497 -80
  2. package/dist/cli/dump/db.js +3 -15
  3. package/dist/cli/dump/db.js.map +1 -1
  4. package/dist/cli/index.js +0 -3
  5. package/dist/cli/index.js.map +1 -1
  6. package/dist/cli/migrations/make-db.js +1 -1
  7. package/dist/cli/migrations/make-db.js.map +1 -1
  8. package/dist/cli/migrations/make-model.js +1 -6
  9. package/dist/cli/migrations/make-model.js.map +1 -1
  10. package/dist/lib/config/index.d.ts +4 -4
  11. package/dist/lib/config/index.js +16 -7
  12. package/dist/lib/config/index.js.map +1 -1
  13. package/dist/lib/constants/index.d.ts +2 -2
  14. package/dist/lib/constants/index.js +9 -2
  15. package/dist/lib/constants/index.js.map +1 -1
  16. package/dist/lib/core/Abstracts/AbstractBuilder.d.ts +3 -2
  17. package/dist/lib/core/Abstracts/AbstractBuilder.js +1 -0
  18. package/dist/lib/core/Abstracts/AbstractBuilder.js.map +1 -1
  19. package/dist/lib/core/Abstracts/AbstractDB.d.ts +5 -3
  20. package/dist/lib/core/Abstracts/AbstractDB.js.map +1 -1
  21. package/dist/lib/core/Abstracts/AbstractModel.d.ts +1 -2
  22. package/dist/lib/core/Abstracts/AbstractModel.js +0 -1
  23. package/dist/lib/core/Abstracts/AbstractModel.js.map +1 -1
  24. package/dist/lib/core/Abstracts/AbstractView.d.ts +2 -1
  25. package/dist/lib/core/Abstracts/AbstractView.js.map +1 -1
  26. package/dist/lib/core/Blueprint.d.ts +56 -13
  27. package/dist/lib/core/Blueprint.js +58 -2
  28. package/dist/lib/core/Blueprint.js.map +1 -1
  29. package/dist/lib/core/Builder.d.ts +172 -19
  30. package/dist/lib/core/Builder.js +574 -210
  31. package/dist/lib/core/Builder.js.map +1 -1
  32. package/dist/lib/core/Cache/DBCache.js +6 -5
  33. package/dist/lib/core/Cache/DBCache.js.map +1 -1
  34. package/dist/lib/core/Cache/index.js +1 -1
  35. package/dist/lib/core/Cache/index.js.map +1 -1
  36. package/dist/lib/core/Contracts/Audit.d.ts +7 -5
  37. package/dist/lib/core/Contracts/Audit.js +18 -2
  38. package/dist/lib/core/Contracts/Audit.js.map +1 -1
  39. package/dist/lib/core/Contracts/Logger.d.ts +2 -2
  40. package/dist/lib/core/DB.d.ts +242 -169
  41. package/dist/lib/core/DB.js +559 -524
  42. package/dist/lib/core/DB.js.map +1 -1
  43. package/dist/lib/core/Driver/index.d.ts +41 -15
  44. package/dist/lib/core/Driver/index.js +14 -0
  45. package/dist/lib/core/Driver/index.js.map +1 -1
  46. package/dist/lib/core/Driver/mariadb/MariadbDriver.d.ts +6 -2
  47. package/dist/lib/core/Driver/mariadb/MariadbDriver.js +24 -7
  48. package/dist/lib/core/Driver/mariadb/MariadbDriver.js.map +1 -1
  49. package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.d.ts +42 -17
  50. package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.js +281 -154
  51. package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.js.map +1 -1
  52. package/dist/lib/core/Driver/mongodb/MongodbDriver.d.ts +7 -3
  53. package/dist/lib/core/Driver/mongodb/MongodbDriver.js +11 -6
  54. package/dist/lib/core/Driver/mongodb/MongodbDriver.js.map +1 -1
  55. package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.d.ts +40 -15
  56. package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.js +205 -157
  57. package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.js.map +1 -1
  58. package/dist/lib/core/Driver/mysql/MysqlDriver.d.ts +6 -2
  59. package/dist/lib/core/Driver/mysql/MysqlDriver.js +29 -7
  60. package/dist/lib/core/Driver/mysql/MysqlDriver.js.map +1 -1
  61. package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.d.ts +42 -17
  62. package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.js +251 -144
  63. package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.js.map +1 -1
  64. package/dist/lib/core/Driver/postgres/PostgresDriver.d.ts +6 -2
  65. package/dist/lib/core/Driver/postgres/PostgresDriver.js +27 -8
  66. package/dist/lib/core/Driver/postgres/PostgresDriver.js.map +1 -1
  67. package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.d.ts +45 -19
  68. package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.js +471 -287
  69. package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.js.map +1 -1
  70. package/dist/lib/core/Driver/sqlite/SqliteDriver.d.ts +6 -2
  71. package/dist/lib/core/Driver/sqlite/SqliteDriver.js +18 -7
  72. package/dist/lib/core/Driver/sqlite/SqliteDriver.js.map +1 -1
  73. package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.d.ts +47 -19
  74. package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.js +331 -203
  75. package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.js.map +1 -1
  76. package/dist/lib/core/Model.d.ts +541 -36
  77. package/dist/lib/core/Model.js +726 -81
  78. package/dist/lib/core/Model.js.map +1 -1
  79. package/dist/lib/core/Package.d.ts +5 -0
  80. package/dist/lib/core/Package.js +7 -2
  81. package/dist/lib/core/Package.js.map +1 -1
  82. package/dist/lib/core/Pool.d.ts +1 -1
  83. package/dist/lib/core/Pool.js +57 -73
  84. package/dist/lib/core/Pool.js.map +1 -1
  85. package/dist/lib/core/{Queue.d.ts → Queue/index.d.ts} +112 -117
  86. package/dist/lib/core/Queue/index.js +283 -0
  87. package/dist/lib/core/Queue/index.js.map +1 -0
  88. package/dist/lib/core/Queue/types.d.ts +68 -0
  89. package/dist/lib/core/Queue/types.js +3 -0
  90. package/dist/lib/core/Queue/types.js.map +1 -0
  91. package/dist/lib/core/Queue/worker-lock.d.ts +17 -0
  92. package/dist/lib/core/Queue/worker-lock.js +28 -0
  93. package/dist/lib/core/Queue/worker-lock.js.map +1 -0
  94. package/dist/lib/core/Queue/worker.d.ts +113 -0
  95. package/dist/lib/core/Queue/worker.js +853 -0
  96. package/dist/lib/core/Queue/worker.js.map +1 -0
  97. package/dist/lib/core/RelationManager.js +1 -1
  98. package/dist/lib/core/RelationManager.js.map +1 -1
  99. package/dist/lib/core/Repository.d.ts +175 -20
  100. package/dist/lib/core/Repository.js +180 -18
  101. package/dist/lib/core/Repository.js.map +1 -1
  102. package/dist/lib/core/Schema.d.ts +11 -7
  103. package/dist/lib/core/Schema.js +249 -80
  104. package/dist/lib/core/Schema.js.map +1 -1
  105. package/dist/lib/core/SqlLike.js +4 -4
  106. package/dist/lib/core/SqlLike.js.map +1 -1
  107. package/dist/lib/core/StateManager.d.ts +19 -0
  108. package/dist/lib/core/StateManager.js +9 -4
  109. package/dist/lib/core/StateManager.js.map +1 -1
  110. package/dist/lib/core/UtilityTypes.d.ts +24 -6
  111. package/dist/lib/core/UtilityTypes.js.map +1 -1
  112. package/dist/lib/core/View.d.ts +3 -1
  113. package/dist/lib/core/View.js +18 -25
  114. package/dist/lib/core/View.js.map +1 -1
  115. package/dist/lib/core/index.d.ts +2 -0
  116. package/dist/lib/core/index.js +3 -1
  117. package/dist/lib/core/index.js.map +1 -1
  118. package/dist/lib/types/decorator/index.d.ts +3 -0
  119. package/dist/lib/types/index.d.ts +93 -105
  120. package/dist/lib/types/repository/index.d.ts +20 -28
  121. package/dist/lib/utils/index.d.ts +16 -7
  122. package/dist/lib/utils/index.js +127 -24
  123. package/dist/lib/utils/index.js.map +1 -1
  124. package/package.json +3 -6
  125. package/dist/cli/dump/table.d.ts +0 -4
  126. package/dist/cli/dump/table.js +0 -41
  127. package/dist/cli/dump/table.js.map +0 -1
  128. package/dist/lib/core/Queue.js +0 -726
  129. package/dist/lib/core/Queue.js.map +0 -1
@@ -0,0 +1,283 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Queue = void 0;
4
+ const worker_1 = require("./worker");
5
+ /**
6
+ * Queue facade class (static API wrapper)
7
+ *
8
+ * This class provides a singleton-style interface over the underlying Worker instance.
9
+ * It must be initialized before use via `Queue.start()`.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const sendEmail = (job) => console.log('send mail :' + job.payload.email)
14
+ *
15
+ * await Queue.start({ inspect : true, flush : true // **remove all jobs });
16
+ *
17
+ * // register
18
+ * Queue.progress("send-email", async (job) => {
19
+ * return await sendEmail(job);
20
+ * }, { concurrency : 3 });
21
+ *
22
+ * // add
23
+ * Queue.add("send-email", { email: "test@gmail.com" });
24
+ *
25
+ * ```
26
+ */
27
+ class Queue {
28
+ /**
29
+ * Internal Worker instance used for all queue operations.
30
+ * @type {Worker | null}
31
+ */
32
+ static WORKER;
33
+ static MESSAGE = {
34
+ INIT_ERROR: `Queue is not initialized. Please call 'await Queue.start()' before using it.`
35
+ };
36
+ /**
37
+ * The 'start' method is used to initialize the Queue system.
38
+ * Creates and prepares the underlying Worker instance.
39
+ *
40
+ * @param {Object} [opts] - options (inspect, flush)
41
+ * @property {boolean?} opts.inspect queue work flow
42
+ * @property {boolean?} opts.flush remove all queue
43
+ * @property {number?} opts.maxIdleRetries - Maximum idle time () when no jobs are available
44
+ * @property {boolean} [opts.poll.enabled] - Enable or disable worker job polling.
45
+ * @property {number} [opts.poll.timeout] - Polling interval in milliseconds.
46
+ * @returns {Promise<void>}
47
+ */
48
+ static async start(opts = {}) {
49
+ this.WORKER = await new worker_1.Worker().initialize(opts);
50
+ return;
51
+ }
52
+ /**
53
+ * The 'end' method is used to shutdown the Queue system.
54
+ *
55
+ * @returns {Promise<void>}
56
+ */
57
+ static async end() {
58
+ if (this.WORKER == null) {
59
+ throw new Error(this.MESSAGE.INIT_ERROR);
60
+ }
61
+ await this.WORKER.shutdown();
62
+ this.WORKER = null;
63
+ return;
64
+ }
65
+ /**
66
+ * The 'flush' method is used to flush all jobs in the queue (dangerous operation).
67
+ *
68
+ * @throws {Error} If Queue is not initialized.
69
+ * @returns {Promise<void>}
70
+ */
71
+ static async flush() {
72
+ if (this.WORKER == null) {
73
+ throw new Error(this.MESSAGE.INIT_ERROR);
74
+ }
75
+ await this.WORKER.flush();
76
+ }
77
+ /**
78
+ * The 'getJobOverallStats' method is used to get aggregated queue statistics.
79
+ *
80
+ * @param {string} [name] - Optional queue name filter.
81
+ * @throws {Error} If Queue is not initialized.
82
+ * @returns {Promise<any>}
83
+ */
84
+ static async getJobOverallStats(name) {
85
+ if (this.WORKER == null) {
86
+ throw new Error(this.MESSAGE.INIT_ERROR);
87
+ }
88
+ return await this.WORKER.getJobOverallStats(name);
89
+ }
90
+ /**
91
+ * The 'getJobStats' method is used to Get jobs statistics grouped by name.
92
+ *
93
+ * @param {string} [name] - Optional queue name filter.
94
+ * @throws {Error} If Queue is not initialized.
95
+ * @returns {Promise<any>}
96
+ */
97
+ static async getJobStats(name) {
98
+ if (this.WORKER == null) {
99
+ throw new Error(this.MESSAGE.INIT_ERROR);
100
+ }
101
+ return await this.WORKER.getJobStats(name);
102
+ }
103
+ /**
104
+ * The 'getJobs' method is used to Get jobs.
105
+ *
106
+ * @param {string} [name] - Optional queue name filter.
107
+ * @throws {Error} If Queue is not initialized.
108
+ * @returns {Promise<T.Result<Worker>[]>}
109
+ */
110
+ static async getJobs(name) {
111
+ if (this.WORKER == null) {
112
+ throw new Error(this.MESSAGE.INIT_ERROR);
113
+ }
114
+ return await this.WORKER.getJobs(name);
115
+ }
116
+ /**
117
+ * Get all unique queue names.
118
+ *
119
+ * @throws {Error} If Queue is not initialized.
120
+ * @returns {Promise<string[]>}
121
+ */
122
+ static async getNames() {
123
+ if (this.WORKER == null) {
124
+ throw new Error(this.MESSAGE.INIT_ERROR);
125
+ }
126
+ return await this.WORKER.getNames();
127
+ }
128
+ /**
129
+ * Access raw Worker instance safely.
130
+ *
131
+ * @param {(worker: Worker) => any} cb - Callback with Worker instance.
132
+ * @throws {Error} If Queue is not initialized.
133
+ * @returns {Promise<Work>}
134
+ */
135
+ static async worker(cb) {
136
+ if (this.WORKER == null) {
137
+ throw new Error(this.MESSAGE.INIT_ERROR);
138
+ }
139
+ return await cb(this.WORKER);
140
+ }
141
+ /**
142
+ * Start a worker for processing jobs of a specific name.
143
+ *
144
+ * @param {string} name - Queue name to process.
145
+ * @param {Handler} handler - Job handler function.
146
+ * @param {QueueProcessOptions} [opts] - Job options (interval, concurrency)
147
+ * @throws {Error} If Queue is not initialized.
148
+ * @returns {Promise<void>}
149
+ *
150
+ * @example
151
+ * const helloWorld = (job) => console.log('hello world :' + job.id);
152
+ *
153
+ * Queue.progress("hello", async (job) => {
154
+ * return await helloWorld(job)
155
+ * }, { concurrency : 3 });
156
+ */
157
+ static async process(name, handler, opts = {}) {
158
+ if (this.WORKER == null) {
159
+ throw new Error(this.MESSAGE.INIT_ERROR);
160
+ }
161
+ return await this.WORKER.process(name, handler, opts);
162
+ }
163
+ /**
164
+ * Start a worker for processing jobs of a specific name.
165
+ *
166
+ * @param {string} name - Queue name to process.
167
+ * @param {Handler} handler - Job handler function.
168
+ * @param {QueueProcessOptions} [opts] - Job options (interval, concurrency)
169
+ * @throws {Error} If Queue is not initialized.
170
+ * @returns {Promise<void>}
171
+ *
172
+ * @example
173
+ * const helloWorld = (job) => console.log('hello world :' + job.id);
174
+ *
175
+ * Queue.on("hello", async (job) => {
176
+ * return await helloWorld(job)
177
+ * }, { concurrency : 3 });
178
+ */
179
+ static async on(name, handler, opts = {}) {
180
+ return await this.process(name, handler, opts);
181
+ }
182
+ /**
183
+ * Add a new job into the queue.
184
+ *
185
+ * @param {string} name - Queue name / job type.
186
+ * @param {any} payload - Job payload data, send to process
187
+ * @param {QueueAddOptions} [opts] - Job options (delay, priority, retry, etc.)
188
+ * @throws {Error} If Queue is not initialized.
189
+ * @returns {Promise<T.Result<Worker>>}
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * Queue.add("send-email", { email: "test@gmail.com" });
194
+ * Queue.add("send-email", { email: "test2@gmail.com" }, {
195
+ * metadata : 'first priority',
196
+ * priority : 9999
197
+ * delayMs : 100
198
+ * maxAttempts : 1
199
+ * });
200
+ * ```
201
+ */
202
+ static async add(name, payload, opts = {}) {
203
+ if (this.WORKER == null) {
204
+ throw new Error(this.MESSAGE.INIT_ERROR);
205
+ }
206
+ await this.WORKER.add(name, payload, opts);
207
+ return;
208
+ }
209
+ /**
210
+ * Publishes an event to all registered subscribers.
211
+ *
212
+ * Each subscriber receives the event payload as an individual job.
213
+ *
214
+ * @param event - The event name to publish.
215
+ * @param payload - The data associated with the event.
216
+ * @param {QueueAddOptions} [opts] - Job options (delay, priority, retry, etc.)
217
+ * @throws {Error} If the queue worker has not been initialized.
218
+ *
219
+ * @example
220
+ * ```ts
221
+ * Queue.publish('user.created', {
222
+ * userId: 123,
223
+ * email: 'user@example.com',
224
+ * });
225
+ *
226
+ * Queue.publish('user.created', {
227
+ * userId: 123,
228
+ * email: 'user@example.com',
229
+ * }, {
230
+ * metadata : 'first priority',
231
+ * priority : 9999
232
+ * delayMs : 100
233
+ * maxAttempts : 1
234
+ * });
235
+ * ```
236
+ */
237
+ static async publish(event, payload, opts = {}) {
238
+ if (this.WORKER == null) {
239
+ throw new Error(this.MESSAGE.INIT_ERROR);
240
+ }
241
+ return await this.WORKER.publish(event, payload, opts);
242
+ }
243
+ /**
244
+ * Subscribes a handler to an event.
245
+ *
246
+ * The subscriber name is combined with the event name to create
247
+ * a unique job name in the format `{event}.{name}`.
248
+ *
249
+ * @param event - The event name to subscribe to.
250
+ * @param name - The unique name of the subscriber.
251
+ * @param handler - The function executed when the event is received.
252
+ * @param opts - Options controlling job processing behavior.
253
+ *
254
+ * @throws {Error} If the queue worker has not been initialized.
255
+ *
256
+ * @example
257
+ * ```ts
258
+ * await Queue.subscribe(
259
+ * 'user.created',
260
+ * 'email',
261
+ * async (job) => {
262
+ * await sendEmail(job.payload);
263
+ * },
264
+ * {
265
+ * concurrency: 5,
266
+ * }
267
+ * );
268
+ * ```
269
+ *
270
+ * @remarks
271
+ * A subscription to `user.created` with the name `email`
272
+ * creates the job queue `user.created.email`.
273
+ */
274
+ static async subscribe(event, name, handler, opts = {}) {
275
+ if (this.WORKER == null) {
276
+ throw new Error(this.MESSAGE.INIT_ERROR);
277
+ }
278
+ return await this.WORKER.subscribe(event, name, handler, opts);
279
+ }
280
+ }
281
+ exports.Queue = Queue;
282
+ exports.default = Queue;
283
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/core/Queue/index.ts"],"names":[],"mappings":";;;AACA,qCAAkC;AAsDlC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,KAAK;IACP;;;OAGG;IACK,MAAM,CAAC,MAAM,CAAgB;IAE7B,MAAM,CAAC,OAAO,GAAG;QACrB,UAAU,EAAE,8EAA8E;KAC7F,CAAC;IAEF;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAkB,EAAE;QAErC,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,eAAM,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAElD,OAAO;IACT,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG;QAEd,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC3C,CAAC;QAED,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QAE7B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QAEnB,OAAO;IACT,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,KAAK;QAEd,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC7C,CAAC;QAED,MAAM,IAAI,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,CAGhB,KAAW,EACX,OAAa,EACb,OAA4B,EAAE;QAG9B,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC7C,CAAC;QAED,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAC,OAAO,EAAC,IAAI,CAAC,CAAC;IACzD,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,MAAM,CAAC,KAAK,CAAC,SAAS,CAGlB,KAAW,EACX,IAAyB,EACzB,OAAiB,EACjB,OAAgC,EAAE;QAGlC,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC7C,CAAC;QAED,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAC,IAAI,EAAC,OAAO,EAAC,IAAI,CAAC,CAAC;IAChE,CAAC;;AAGI,sBAAK;AACd,kBAAe,KAAK,CAAA"}
@@ -0,0 +1,68 @@
1
+ import { Worker } from "./worker";
2
+ import type { T } from "..";
3
+ import type { Job, QueueContract } from ".";
4
+ import { TConnectionOptions, TDriver, TPoolConnected } from "../../types";
5
+ export type JobInternal = Job & {
6
+ __job: T.Result<Worker>;
7
+ };
8
+ export type Handler = (job: Job) => any | Promise<any>;
9
+ export type State = {
10
+ handler: Handler;
11
+ idle: number;
12
+ sleeping: boolean;
13
+ running: number;
14
+ opts: QueueProcessOptions;
15
+ };
16
+ export type QueueConnection = {
17
+ driver?: TDriver;
18
+ host: string;
19
+ port: number;
20
+ database: string;
21
+ username: string;
22
+ password: string;
23
+ };
24
+ export type QueueInit = {
25
+ inspect?: boolean;
26
+ flush?: boolean;
27
+ hostname?: string;
28
+ maxIdleRetries?: number;
29
+ poll?: {
30
+ enabled?: boolean;
31
+ interval?: number;
32
+ };
33
+ cleanup?: {
34
+ enabled?: boolean;
35
+ interval?: number;
36
+ statuses?: JobStatus[];
37
+ };
38
+ connection?: TConnectionOptions | TPoolConnected;
39
+ };
40
+ export type QueueAddOptions = {
41
+ delayMs?: number;
42
+ priority?: number;
43
+ metadata?: Record<string, any>;
44
+ maxAttempts?: number;
45
+ uniqueKey?: string;
46
+ };
47
+ export type QueueProcessOptions = {
48
+ interval?: number;
49
+ concurrency?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100;
50
+ onSuccess?: (job: Job) => Promise<void> | void;
51
+ onError?: (error: unknown, job: Job) => Promise<void> | void;
52
+ };
53
+ export type BufferedJob = {
54
+ jobData: T.Result<Worker>;
55
+ resolve: (value: any) => void;
56
+ reject: (reason?: any) => void;
57
+ };
58
+ export type JobStatus = 'pending' | 'active' | 'completed' | 'failed';
59
+ type QueueEvents = QueueContract extends {
60
+ events: infer E;
61
+ } ? E : never;
62
+ type QueueJobs = QueueContract extends {
63
+ jobs: infer J;
64
+ } ? J : never;
65
+ export type EventName = QueueEvents extends Record<string, readonly string[]> ? keyof QueueEvents & string : string;
66
+ export type EventJobName<E extends EventName> = QueueEvents extends Record<string, readonly string[]> ? E extends keyof QueueEvents ? QueueEvents[E][number] extends never ? string : QueueEvents[E][number] : string : string;
67
+ export type JobName = QueueJobs extends readonly string[] ? QueueJobs[number] extends never ? string : QueueJobs[number] : string;
68
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/lib/core/Queue/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ import type { T } from "../UtilityTypes";
2
+ import { Blueprint } from "../Blueprint";
3
+ import { Model } from "../Model";
4
+ declare const schema: {
5
+ id: Blueprint<number>;
6
+ uuid: Blueprint<string | null>;
7
+ name: Blueprint<string>;
8
+ job_id: Blueprint<number>;
9
+ unique_key: Blueprint<string>;
10
+ created_at: Blueprint<T.DateTime | null>;
11
+ updated_at: Blueprint<T.DateTime | null>;
12
+ };
13
+ declare class WorkerLock extends Model<T.Schema<typeof schema>> {
14
+ protected boot(): void;
15
+ }
16
+ export { WorkerLock };
17
+ export default WorkerLock;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkerLock = void 0;
4
+ const Blueprint_1 = require("../Blueprint");
5
+ const Model_1 = require("../Model");
6
+ const schema = {
7
+ id: Blueprint_1.Blueprint.int().primary().autoIncrement(),
8
+ uuid: Blueprint_1.Blueprint.varchar(36).null(),
9
+ name: Blueprint_1.Blueprint.varchar(255).notNull(),
10
+ job_id: Blueprint_1.Blueprint.int().notNull().unique(),
11
+ unique_key: Blueprint_1.Blueprint
12
+ .varchar(255)
13
+ .notNull()
14
+ .compositeUnique(["name"]),
15
+ created_at: Blueprint_1.Blueprint.timestamp().null(),
16
+ updated_at: Blueprint_1.Blueprint.timestamp().null()
17
+ };
18
+ class WorkerLock extends Model_1.Model {
19
+ boot() {
20
+ this.useUUID();
21
+ this.useTimestamp();
22
+ this.useSchema(schema);
23
+ this.useTable(this.$state.get("TABLE_JOB_LOCK"));
24
+ }
25
+ }
26
+ exports.WorkerLock = WorkerLock;
27
+ exports.default = WorkerLock;
28
+ //# sourceMappingURL=worker-lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-lock.js","sourceRoot":"","sources":["../../../../src/lib/core/Queue/worker-lock.ts"],"names":[],"mappings":";;;AACA,4CAA4C;AAC5C,oCAAwC;AAExC,MAAM,MAAM,GAAG;IACX,EAAE,EAAW,qBAAS,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,aAAa,EAAE;IACtD,IAAI,EAAS,qBAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE;IACzC,IAAI,EAAS,qBAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE;IAC7C,MAAM,EAAO,qBAAS,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE;IAE/C,UAAU,EAAG,qBAAS;SACrB,OAAO,CAAC,GAAG,CAAC;SACZ,OAAO,EAAE;SACT,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;IAE1B,UAAU,EAAG,qBAAS,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE;IACzC,UAAU,EAAG,qBAAS,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE;CAC5C,CAAC;AAEF,MAAM,UAAW,SAAQ,aAA8B;IAEzC,IAAI;QACV,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACvB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC;IACrD,CAAC;CACJ;AAEQ,gCAAU;AACnB,kBAAe,UAAU,CAAA"}
@@ -0,0 +1,113 @@
1
+ import type { T } from "../UtilityTypes";
2
+ import { Blueprint } from "../Blueprint";
3
+ import { Model } from "../Model";
4
+ import { WorkerLock } from "./worker-lock";
5
+ import type { Handler, QueueAddOptions, QueueInit, QueueProcessOptions } from "./types";
6
+ declare const schema: {
7
+ id: Blueprint<number>;
8
+ uuid: Blueprint<string | null>;
9
+ name: Blueprint<string>;
10
+ status: Blueprint<T.Default<NonNullable<"pending" | "active" | "sent" | "completed" | "failed">>>;
11
+ priority: Blueprint<T.Default<number>>;
12
+ payload: Blueprint<string | null>;
13
+ result: Blueprint<string | null>;
14
+ error: Blueprint<string | null>;
15
+ metadata: Blueprint<string | null>;
16
+ unique_key: Blueprint<string | null>;
17
+ attempts: Blueprint<T.Default<number>>;
18
+ max_attempts: Blueprint<T.Default<number>>;
19
+ delay_ms: Blueprint<T.Default<number>>;
20
+ locked_by: Blueprint<string | null>;
21
+ locked_at: Blueprint<T.DateTime | null>;
22
+ available_at: Blueprint<NonNullable<T.DateTime>>;
23
+ sent_at: Blueprint<T.DateTime | null>;
24
+ completed_at: Blueprint<T.DateTime | null>;
25
+ created_at: Blueprint<T.DateTime | null>;
26
+ updated_at: Blueprint<T.DateTime | null>;
27
+ };
28
+ export declare class Worker extends Model<T.Schema<typeof schema>> {
29
+ private DRIVER;
30
+ private HOSTNAME;
31
+ private INSPECT_EXEC;
32
+ private STOPPING;
33
+ private IS_FLUSHING;
34
+ private ACTIVE_JOBS;
35
+ private BATCH_SIZE;
36
+ private BATCH_WAIT_MS;
37
+ private CONCURRENCY;
38
+ private MAX_CONCURRENCY;
39
+ private CONNECTED_POOL;
40
+ private IDLE;
41
+ private POLL;
42
+ private CLEANUP;
43
+ private BUFFER;
44
+ private WORKER_STATE;
45
+ private EVENT_SUBSCRIBERS;
46
+ protected boot(): void;
47
+ protected WorkerRepository({ onTrx }?: {
48
+ onTrx?: boolean;
49
+ }): Worker;
50
+ protected WorkerLockRepository({ onTrx }?: {
51
+ onTrx?: boolean;
52
+ }): WorkerLock;
53
+ initialize(opts?: QueueInit): Promise<this>;
54
+ shutdown(): Promise<void>;
55
+ flush(): Promise<void>;
56
+ getJobOverallStats(name?: string): Promise<{
57
+ total: number;
58
+ completed: number;
59
+ active: number;
60
+ pending: number;
61
+ failed: number;
62
+ }>;
63
+ getJobStats(name?: string): Promise<{
64
+ name: string;
65
+ completed: number;
66
+ active: number;
67
+ pending: number;
68
+ failed: number;
69
+ }[]>;
70
+ getJobs(name?: string): Promise<{
71
+ [x: string]: unknown;
72
+ id: number;
73
+ uuid: string | null;
74
+ name: string;
75
+ status: "pending" | "active" | "sent" | "completed" | "failed";
76
+ priority: number;
77
+ payload: string | null;
78
+ result: string | null;
79
+ error: string | null;
80
+ metadata: string | null;
81
+ unique_key: string | null;
82
+ attempts: number;
83
+ max_attempts: number;
84
+ delay_ms: number;
85
+ locked_by: string | null;
86
+ locked_at: T.DateTime | null;
87
+ available_at: NonNullable<T.DateTime>;
88
+ sent_at: T.DateTime | null;
89
+ completed_at: T.DateTime | null;
90
+ created_at: T.DateTime | null;
91
+ updated_at: T.DateTime | null;
92
+ }[]>;
93
+ getNames(): Promise<string[]>;
94
+ add(name: string, payload: any, opts?: QueueAddOptions): Promise<void>;
95
+ process(name: string, handler: Handler, opts: QueueProcessOptions): Promise<void>;
96
+ publish(event: string, payload: any, opts: QueueAddOptions): Promise<void>;
97
+ subscribe(event: string, name: string, handler: Handler, opts: QueueProcessOptions): Promise<void>;
98
+ private _runJob;
99
+ private _executeJob;
100
+ private _findJobs;
101
+ private _flushBuffer;
102
+ private _insertJobs;
103
+ private _wakeWorker;
104
+ private _pollWorkerJobs;
105
+ private _cleanupWorkerJobs;
106
+ private _initializeWorkers;
107
+ private _getLockExpiredAt;
108
+ private _getRunnableOrActiveJobs;
109
+ private _safeJsonParse;
110
+ private _safeJsonStringify;
111
+ private _waitMs;
112
+ }
113
+ export {};