lonnymq 0.0.25 → 0.0.26
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 +60 -49
- package/dist/index.d.ts +11 -2
- package/dist/index.js +36 -25
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
var{defineProperty:
|
|
1
|
+
var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=Object.prototype.hasOwnProperty;var M=new WeakMap,V=(e)=>{var t=M.get(e),a;if(t)return t;if(t=h({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")k(e).map((r)=>!Q.call(t,r)&&h(t,r,{get:()=>e[r],enumerable:!(a=P(e,r))||a.enumerable}));return M.set(e,t),t};var W=(e,t)=>{for(var a in t)h(e,a,{get:t[a],enumerable:!0,configurable:!0,set:(r)=>t[a]=()=>r})};var le={};W(le,{queueEventDecode:()=>v,Queue:()=>y,MessageHeartbeatCommand:()=>d,MessageDequeueCommand:()=>m,MessageDeleteCommand:()=>i,MessageDeferCommand:()=>u,MessageCreateCommand:()=>l,ChannelPolicySetCommand:()=>o,ChannelPolicyClearCommand:()=>c});module.exports=V(le);var I=(e)=>{return e*1000};var T=I(0);var v=(e)=>{let t=JSON.parse(e);if(t.type===0)return{eventType:"MESSAGE_CREATED",id:t.id,delayMs:t.delay_ms};else if(t.type===1)return{eventType:"MESSAGE_DELETED",id:t.id};else if(t.type===2)return{eventType:"MESSAGE_DEFERRED",id:t.id,delayMs:t.delay_ms};else throw new Error("Unknown event type")};var E=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Y=(e)=>({nodeType:"RAW",value:e}),z=(e)=>{return`'${e.replace(/'/g,"''")}'`},J=(e)=>{if(e===null)return"NULL";else if(typeof e==="string")return z(e);else if(typeof e==="number")return e.toString();else if(typeof e==="boolean")return e?"TRUE":"FALSE";else if(e instanceof Date)return`'${e.toISOString()}'`;else if(typeof e==="bigint")return e.toString();else throw new Error(`Unsupported value type: ${typeof e}`)},X=(e)=>{return`"${e.replace(/"/g,'""')}"`},j=(e)=>{if(e.nodeType==="VALUE")return J(e.value);else if(e.nodeType==="REF")return X(e.value);else if(e.nodeType==="RAW")return e.value;else throw new Error("Unsupported SQL node type")};var n=(e,...t)=>{let a=[];for(let r=0;r<e.length;r+=1)if(a.push(e[r]),r<t.length)a.push(j(t[r]));return Y(a.join(""))};class c{schema;channelName;createdAt;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.createdAt=new Date}async execute(e){await e.query(n`
|
|
2
2
|
SELECT 1 FROM ${s(this.schema)}."channel_policy_clear"(
|
|
3
3
|
$1
|
|
4
4
|
)
|
|
5
|
-
`.value,[this.channelName])}}class
|
|
5
|
+
`.value,[this.channelName])}}class o{schema;channelName;maxConcurrency;releaseIntervalMs;createdAt;constructor(e){this.schema=e.schema,this.channelName=e.channelName;let t=e.maxConcurrency??null;this.maxConcurrency=t!==null?Math.max(0,t):null;let a=e.releaseIntervalMs??null;this.releaseIntervalMs=a!==null?Math.max(0,a):null,this.createdAt=new Date}async execute(e){await e.query(n`
|
|
6
6
|
SELECT 1 FROM ${s(this.schema)}."channel_policy_set"(
|
|
7
7
|
$1,
|
|
8
8
|
$2::INTEGER,
|
|
9
9
|
$3::INTEGER
|
|
10
10
|
)
|
|
11
|
-
`.value,[this.channelName,this.maxConcurrency,this.releaseIntervalMs])}}var L=require("crypto"),
|
|
12
|
-
SELECT
|
|
11
|
+
`.value,[this.channelName,this.maxConcurrency,this.releaseIntervalMs])}}var L=require("crypto"),C=()=>{return L.randomBytes(16).toString("base64url")};class l{schema;channelName;content;delayMs;createdAt;constructor(e){let t=e.delayMs===void 0?T:e.delayMs;this.schema=e.schema,this.channelName=e.channelName??C(),this.content=e.content,this.delayMs=t,this.createdAt=new Date}async execute(e){let t=await e.query(n`
|
|
12
|
+
SELECT
|
|
13
|
+
result_code,
|
|
14
|
+
metadata
|
|
15
|
+
FROM ${s(this.schema)}."message_create"(
|
|
13
16
|
$1,
|
|
14
|
-
$2,
|
|
15
|
-
$3
|
|
16
|
-
$4::BIGINT
|
|
17
|
+
$2,
|
|
18
|
+
$3::BIGINT
|
|
17
19
|
)
|
|
18
|
-
`.value,[this.
|
|
20
|
+
`.value,[this.channelName,this.content,this.delayMs]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_CREATED",metadata:{id:t.metadata.id,channelSize:t.metadata.channel_size}};else throw new Error("Unexpected result code")}}class m{schema;lockMs;constructor(e){this.schema=e.schema,this.lockMs=e.lockMs}async execute(e){let t=await e.query(n`
|
|
19
21
|
SELECT
|
|
20
22
|
result_code,
|
|
21
23
|
metadata,
|
|
@@ -40,9 +42,9 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
40
42
|
$2::BIGINT,
|
|
41
43
|
$3::BIGINT
|
|
42
44
|
)
|
|
43
|
-
`.value,[this.id,this.numAttempts,this.lockMs]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(t.result_code===1)return{resultType:"MESSAGE_STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_HEARTBEATED"};else throw new Error("Unexpected result")}}var
|
|
44
|
-
`),a=Number.MAX_SAFE_INTEGER;for(let r of t){if(r.trim().length===0)continue;let
|
|
45
|
-
`).trim()};var S=require("path"),__filename="/home/runner/work/lonnymq/lonnymq/src/core/path.ts",ne=S.dirname(S.dirname(__filename)),ae=new RegExp(`^${ne}/`),
|
|
45
|
+
`.value,[this.id,this.numAttempts,this.lockMs]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(t.result_code===1)return{resultType:"MESSAGE_STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_HEARTBEATED"};else throw new Error("Unexpected result")}}var U=(e)=>{let t=e.split(`
|
|
46
|
+
`),a=Number.MAX_SAFE_INTEGER;for(let r of t){if(r.trim().length===0)continue;let H=r.search(/\S/);a=Math.min(a,H)}return t.map((r)=>r.slice(a)).join(`
|
|
47
|
+
`).trim()};var S=require("path"),__filename="/home/runner/work/lonnymq/lonnymq/src/core/path.ts",ne=S.dirname(S.dirname(__filename)),ae=new RegExp(`^${ne}/`),_=(e)=>{return e.replace(ae,"")};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/00-table-channel-policy.ts",O={name:_(__filename),sql:(e)=>{let t=[e.schema,"channel_policy_name_ux"].join("_");return[n`
|
|
46
48
|
CREATE TABLE ${s(e.schema)}."channel_policy" (
|
|
47
49
|
"id" UUID NOT NULL DEFAULT GEN_RANDOM_UUID(),
|
|
48
50
|
"name" TEXT NOT NULL,
|
|
@@ -54,7 +56,7 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
54
56
|
`,n`
|
|
55
57
|
CREATE UNIQUE INDEX ${s(t)}
|
|
56
58
|
ON ${s(e.schema)}."channel_policy" ("name");
|
|
57
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/01-table-channel-state.ts",
|
|
59
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/01-table-channel-state.ts",f={name:_(__filename),sql:(e)=>{let t=[e.schema,"channel_state_name_ux"].join("_"),a=[e.schema,"channel_state_dequeue_ix"].join("_");return[n`
|
|
58
60
|
CREATE TABLE ${s(e.schema)}."channel_state" (
|
|
59
61
|
"id" UUID NOT NULL DEFAULT GEN_RANDOM_UUID(),
|
|
60
62
|
"name" TEXT NOT NULL,
|
|
@@ -79,7 +81,7 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
79
81
|
"active_next_at" ASC
|
|
80
82
|
) WHERE "message_id" IS NOT NULL
|
|
81
83
|
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency");
|
|
82
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/02-table-message.ts",
|
|
84
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/02-table-message.ts",G={name:_(__filename),sql:(e)=>{return[n`
|
|
83
85
|
CREATE TABLE ${s(e.schema)}."message" (
|
|
84
86
|
"id" UUID NOT NULL,
|
|
85
87
|
"channel_name" TEXT NOT NULL,
|
|
@@ -105,13 +107,15 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
105
107
|
ON ${s(e.schema)}."message" (
|
|
106
108
|
"unlock_at" ASC
|
|
107
109
|
) WHERE "is_locked";
|
|
108
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/03-function-message-create.ts",
|
|
110
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/03-function-message-create.ts",q={name:_(__filename),sql:(e)=>{return[n`
|
|
109
111
|
CREATE FUNCTION ${s(e.schema)}."message_create" (
|
|
110
|
-
p_id UUID,
|
|
111
112
|
p_channel_name TEXT,
|
|
112
113
|
p_content BYTEA,
|
|
113
114
|
p_delay_ms BIGINT
|
|
114
|
-
) RETURNS
|
|
115
|
+
) RETURNS TABLE (
|
|
116
|
+
result_code INTEGER,
|
|
117
|
+
metadata JSON
|
|
118
|
+
) AS $$
|
|
115
119
|
DECLARE
|
|
116
120
|
v_now TIMESTAMP;
|
|
117
121
|
v_channel_policy RECORD;
|
|
@@ -129,7 +133,7 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
129
133
|
"dequeue_at",
|
|
130
134
|
"created_at"
|
|
131
135
|
) VALUES (
|
|
132
|
-
|
|
136
|
+
GEN_RANDOM_UUID(),
|
|
133
137
|
p_channel_name,
|
|
134
138
|
p_content,
|
|
135
139
|
FALSE,
|
|
@@ -201,16 +205,23 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
201
205
|
WHERE "id" = v_channel_state."id";
|
|
202
206
|
END IF;
|
|
203
207
|
|
|
204
|
-
IF ${
|
|
208
|
+
IF ${E(e.eventChannel!==null)} THEN
|
|
205
209
|
PERFORM PG_NOTIFY(
|
|
206
|
-
${
|
|
210
|
+
${E(e.eventChannel)},
|
|
207
211
|
JSON_BUILD_OBJECT(
|
|
208
|
-
'type', ${
|
|
209
|
-
'id',
|
|
212
|
+
'type', ${E(0)},
|
|
213
|
+
'id', v_message."id",
|
|
210
214
|
'delay_ms', p_delay_ms
|
|
211
215
|
)::TEXT
|
|
212
216
|
);
|
|
213
217
|
END IF;
|
|
218
|
+
|
|
219
|
+
RETURN QUERY SELECT
|
|
220
|
+
${E(0)},
|
|
221
|
+
JSON_BUILD_OBJECT(
|
|
222
|
+
'id', v_message."id",
|
|
223
|
+
'channel_size', v_channel_state."current_size" + 1
|
|
224
|
+
);
|
|
214
225
|
END;
|
|
215
226
|
$$ LANGUAGE plpgsql;
|
|
216
227
|
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/04-function-message-dequeue.ts",re=(e)=>n`
|
|
@@ -225,7 +236,7 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
225
236
|
WHERE "is_locked"
|
|
226
237
|
AND "unlock_at" <= ${e.now}
|
|
227
238
|
ORDER BY "unlock_at" ASC
|
|
228
|
-
`,
|
|
239
|
+
`,Ee=(e)=>n`
|
|
229
240
|
SELECT
|
|
230
241
|
"channel_state"."id",
|
|
231
242
|
"channel_state"."name",
|
|
@@ -238,7 +249,7 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
238
249
|
WHERE "message_id" IS NOT NULL
|
|
239
250
|
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency")
|
|
240
251
|
ORDER BY "active_next_at" ASC
|
|
241
|
-
`,
|
|
252
|
+
`,_e=(e)=>n`
|
|
242
253
|
SELECT
|
|
243
254
|
"message"."id",
|
|
244
255
|
"message"."dequeue_at",
|
|
@@ -247,7 +258,7 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
247
258
|
WHERE NOT "is_locked"
|
|
248
259
|
AND "channel_name" = ${e.channelName}
|
|
249
260
|
ORDER BY "dequeue_at" ASC, "seq_no" ASC
|
|
250
|
-
|
|
261
|
+
`,x={name:_(__filename),sql:(e)=>{let t=re({now:n`v_now`,schema:e.schema}),a=_e({channelName:n`v_channel_state."name"`,schema:e.schema}),r=Ee({schema:e.schema});return[n`
|
|
251
262
|
CREATE FUNCTION ${s(e.schema)}."message_dequeue" (
|
|
252
263
|
p_lock_ms BIGINT
|
|
253
264
|
)
|
|
@@ -279,7 +290,7 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
279
290
|
WHERE "id" = v_message_locked."id";
|
|
280
291
|
|
|
281
292
|
RETURN QUERY SELECT
|
|
282
|
-
${
|
|
293
|
+
${E(1)},
|
|
283
294
|
v_message_locked.content,
|
|
284
295
|
v_message_locked.state,
|
|
285
296
|
JSON_BUILD_OBJECT(
|
|
@@ -299,7 +310,7 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
299
310
|
|
|
300
311
|
IF v_channel_state."id" IS NULL THEN
|
|
301
312
|
RETURN QUERY SELECT
|
|
302
|
-
${
|
|
313
|
+
${E(0)},
|
|
303
314
|
NULL::BYTEA,
|
|
304
315
|
NULL::BYTEA,
|
|
305
316
|
JSON_BUILD_OBJECT('retry_ms', NULL);
|
|
@@ -308,7 +319,7 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
308
319
|
|
|
309
320
|
IF v_channel_state."active_next_at" > v_now THEN
|
|
310
321
|
RETURN QUERY SELECT
|
|
311
|
-
${
|
|
322
|
+
${E(0)},
|
|
312
323
|
NULL::BYTEA,
|
|
313
324
|
NULL::BYTEA,
|
|
314
325
|
JSON_BUILD_OBJECT(
|
|
@@ -358,7 +369,7 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
358
369
|
END IF;
|
|
359
370
|
|
|
360
371
|
RETURN QUERY SELECT
|
|
361
|
-
${
|
|
372
|
+
${E(1)},
|
|
362
373
|
v_message_dequeue.content,
|
|
363
374
|
v_message_dequeue.state,
|
|
364
375
|
JSON_BUILD_OBJECT(
|
|
@@ -370,7 +381,7 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
370
381
|
RETURN;
|
|
371
382
|
END;
|
|
372
383
|
$$ LANGUAGE plpgsql;
|
|
373
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/05-function-message-delete.ts"
|
|
384
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/05-function-message-delete.ts",$={name:_(__filename),sql:(e)=>{return[n`
|
|
374
385
|
CREATE FUNCTION ${s(e.schema)}."message_delete" (
|
|
375
386
|
p_id UUID,
|
|
376
387
|
p_num_attempts BIGINT
|
|
@@ -395,11 +406,11 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
395
406
|
|
|
396
407
|
IF v_message."id" IS NULL THEN
|
|
397
408
|
RETURN QUERY SELECT
|
|
398
|
-
${
|
|
409
|
+
${E(0)};
|
|
399
410
|
RETURN;
|
|
400
411
|
ELSIF NOT v_message."is_locked" OR v_message."num_attempts" <> p_num_attempts THEN
|
|
401
412
|
RETURN QUERY SELECT
|
|
402
|
-
${
|
|
413
|
+
${E(1)};
|
|
403
414
|
RETURN;
|
|
404
415
|
END IF;
|
|
405
416
|
|
|
@@ -429,11 +440,11 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
429
440
|
WHERE "id" = v_channel_state."id";
|
|
430
441
|
END IF;
|
|
431
442
|
|
|
432
|
-
IF ${
|
|
443
|
+
IF ${E(e.eventChannel!==null)} THEN
|
|
433
444
|
PERFORM PG_NOTIFY(
|
|
434
|
-
${
|
|
445
|
+
${E(e.eventChannel)},
|
|
435
446
|
JSON_BUILD_OBJECT(
|
|
436
|
-
'type', ${
|
|
447
|
+
'type', ${E(1)},
|
|
437
448
|
'id', p_id
|
|
438
449
|
)::TEXT
|
|
439
450
|
);
|
|
@@ -443,11 +454,11 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
443
454
|
WHERE "id" = p_id;
|
|
444
455
|
|
|
445
456
|
RETURN QUERY SELECT
|
|
446
|
-
${
|
|
457
|
+
${E(2)};
|
|
447
458
|
RETURN;
|
|
448
459
|
END;
|
|
449
460
|
$$ LANGUAGE plpgsql;
|
|
450
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/06-function-message-defer.ts",
|
|
461
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/06-function-message-defer.ts",F={name:_(__filename),sql:(e)=>{return[n`
|
|
451
462
|
CREATE FUNCTION ${s(e.schema)}."message_defer" (
|
|
452
463
|
p_id UUID,
|
|
453
464
|
p_num_attempts BIGINT,
|
|
@@ -478,11 +489,11 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
478
489
|
|
|
479
490
|
IF v_message."id" IS NULL THEN
|
|
480
491
|
RETURN QUERY SELECT
|
|
481
|
-
${
|
|
492
|
+
${E(0)};
|
|
482
493
|
RETURN;
|
|
483
494
|
ELSIF NOT v_message."is_locked" OR v_message."num_attempts" <> p_num_attempts THEN
|
|
484
495
|
RETURN QUERY SELECT
|
|
485
|
-
${
|
|
496
|
+
${E(1)};
|
|
486
497
|
RETURN;
|
|
487
498
|
END IF;
|
|
488
499
|
|
|
@@ -527,11 +538,11 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
527
538
|
"dequeue_at" = v_dequeue_at
|
|
528
539
|
WHERE "id" = p_id;
|
|
529
540
|
|
|
530
|
-
IF ${
|
|
541
|
+
IF ${E(e.eventChannel!==null)} THEN
|
|
531
542
|
PERFORM PG_NOTIFY(
|
|
532
|
-
${
|
|
543
|
+
${E(e.eventChannel)},
|
|
533
544
|
JSON_BUILD_OBJECT(
|
|
534
|
-
'type', ${
|
|
545
|
+
'type', ${E(2)},
|
|
535
546
|
'delay_ms', p_delay_ms,
|
|
536
547
|
'id', p_id
|
|
537
548
|
)::TEXT
|
|
@@ -539,11 +550,11 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
539
550
|
END IF;
|
|
540
551
|
|
|
541
552
|
RETURN QUERY SELECT
|
|
542
|
-
${
|
|
553
|
+
${E(2)};
|
|
543
554
|
RETURN;
|
|
544
555
|
END;
|
|
545
556
|
$$ LANGUAGE plpgsql;
|
|
546
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/08-function-channel-policy-clear.ts",
|
|
557
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/08-function-channel-policy-clear.ts",b={name:_(__filename),sql:(e)=>{return[n`
|
|
547
558
|
CREATE FUNCTION ${s(e.schema)}."channel_policy_clear" (
|
|
548
559
|
p_name TEXT
|
|
549
560
|
) RETURNS VOID AS $$
|
|
@@ -572,7 +583,7 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
572
583
|
END IF;
|
|
573
584
|
END;
|
|
574
585
|
$$ LANGUAGE plpgsql;
|
|
575
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/09-function-channel-policy-set.ts",
|
|
586
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/09-function-channel-policy-set.ts",B={name:_(__filename),sql:(e)=>{return[n`
|
|
576
587
|
CREATE FUNCTION ${s(e.schema)}."channel_policy_set" (
|
|
577
588
|
p_name TEXT,
|
|
578
589
|
p_max_concurrency INTEGER,
|
|
@@ -603,7 +614,7 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
603
614
|
WHERE "name" = p_name;
|
|
604
615
|
END;
|
|
605
616
|
$$ LANGUAGE plpgsql;
|
|
606
|
-
`]}};class R{schema;channelName;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.channelName=e.channelName}async create(e){let t=this.adaptor(e.databaseClient),a=new l({schema:this.schema,channelName:this.channelName,content:e.content,delayMs:e.delayMs})
|
|
617
|
+
`]}};class R{schema;channelName;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.channelName=e.channelName}async create(e){let t=this.adaptor(e.databaseClient),a=new l({schema:this.schema,channelName:this.channelName,content:e.content,delayMs:e.delayMs}),r=await a.execute(t);return{messageId:r.metadata.id,channelName:a.channelName,channelSize:r.metadata.channelSize}}}class A{schema;adaptor;channelName;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.channelName=e.channelName}set(e){let t=this.adaptor(e.databaseClient);return new o({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,releaseIntervalMs:e.releaseIntervalMs}).execute(t)}clear(e){let t=this.adaptor(e.databaseClient);return new c({schema:this.schema,channelName:this.channelName}).execute(t)}}class g{policy;message;constructor(e){this.message=new R({schema:e.schema,adaptor:e.adaptor,channelName:e.channelName}),this.policy=new A({schema:e.schema,adaptor:e.adaptor,channelName:e.channelName})}}class D{schema;adaptor;id;isUnlocked;channelName;content;state;numAttempts;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.id=e.id,this.channelName=e.channelName,this.isUnlocked=e.isUnlocked,this.content=e.content,this.state=e.state,this.numAttempts=e.numAttempts}async defer(e){let t=this.adaptor(e.databaseClient);return new u({schema:this.schema,id:this.id,numAttempts:this.numAttempts,delayMs:e.delayMs,state:e.state}).execute(t)}async delete(e){let t=this.adaptor(e.databaseClient);return new i({schema:this.schema,numAttempts:this.numAttempts,id:this.id}).execute(t)}async heartbeat(e){let t=this.adaptor(e.databaseClient);return new d({schema:this.schema,id:this.id,numAttempts:this.numAttempts,lockMs:e.lockMs}).execute(t)}}class p{schema;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor}async create(e){let t=this.adaptor(e.databaseClient),a=new l({schema:this.schema,content:e.content,delayMs:e.delayMs}),r=await a.execute(t);return{messageId:r.metadata.id,channelName:a.channelName,channelSize:r.metadata.channelSize}}}var __filename="/home/runner/work/lonnymq/lonnymq/src/install/07-function-message-heartbeat.ts",w={name:_(__filename),sql:(e)=>{return[n`
|
|
607
618
|
CREATE FUNCTION ${s(e.schema)}."message_heartbeat" (
|
|
608
619
|
p_id UUID,
|
|
609
620
|
p_num_attempts BIGINT,
|
|
@@ -633,11 +644,11 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
633
644
|
|
|
634
645
|
IF v_message."id" IS NULL THEN
|
|
635
646
|
RETURN QUERY SELECT
|
|
636
|
-
${
|
|
647
|
+
${E(0)};
|
|
637
648
|
RETURN;
|
|
638
649
|
ELSIF NOT v_message."is_locked" OR v_message."num_attempts" <> p_num_attempts THEN
|
|
639
650
|
RETURN QUERY SELECT
|
|
640
|
-
${
|
|
651
|
+
${E(1)};
|
|
641
652
|
RETURN;
|
|
642
653
|
END IF;
|
|
643
654
|
|
|
@@ -649,8 +660,8 @@ var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=
|
|
|
649
660
|
WHERE "id" = p_id;
|
|
650
661
|
|
|
651
662
|
RETURN QUERY SELECT
|
|
652
|
-
${
|
|
663
|
+
${E(2)};
|
|
653
664
|
RETURN;
|
|
654
665
|
END;
|
|
655
666
|
$$ LANGUAGE plpgsql;
|
|
656
|
-
`]}};class y{schema;message;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor?e.adaptor:(t)=>t,this.message=new
|
|
667
|
+
`]}};class y{schema;message;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor?e.adaptor:(t)=>t,this.message=new p({schema:this.schema,adaptor:this.adaptor})}async dequeue(e){let t=new m({schema:this.schema,lockMs:e.lockMs}),a=this.adaptor(e.databaseClient),r=await t.execute(a);if(r.resultType==="MESSAGE_DEQUEUED")return{resultType:"MESSAGE_DEQUEUED",message:new D({schema:this.schema,adaptor:this.adaptor,id:r.message.id,channelName:r.message.channelName,isUnlocked:r.message.isUnlocked,content:r.message.content,state:r.message.state,numAttempts:r.message.numAttempts})};else return r}channel(e){return new g({adaptor:this.adaptor,schema:this.schema,channelName:e})}install(e={}){return[O,f,G,q,x,$,F,w,B,b].sort((t,a)=>t.name.localeCompare(a.name)).flatMap((t)=>t.sql({schema:this.schema,eventChannel:e.eventChannel??null})).map((t)=>U(t.value))}}
|
package/dist/index.d.ts
CHANGED
|
@@ -52,11 +52,17 @@ export declare class ChannelPolicySetCommand {
|
|
|
52
52
|
});
|
|
53
53
|
execute(databaseClient: DatabaseClient): Promise<void>;
|
|
54
54
|
}
|
|
55
|
+
export type MessageCreateCommandResult = {
|
|
56
|
+
resultType: "MESSAGE_CREATED";
|
|
57
|
+
metadata: {
|
|
58
|
+
id: string;
|
|
59
|
+
channelSize: number;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
55
62
|
export declare class MessageCreateCommand {
|
|
56
63
|
readonly schema: string;
|
|
57
64
|
readonly channelName: string;
|
|
58
65
|
readonly content: Buffer;
|
|
59
|
-
readonly id: string;
|
|
60
66
|
readonly delayMs: number;
|
|
61
67
|
readonly createdAt: Date;
|
|
62
68
|
constructor(params: {
|
|
@@ -65,7 +71,7 @@ export declare class MessageCreateCommand {
|
|
|
65
71
|
content: Buffer;
|
|
66
72
|
delayMs?: number;
|
|
67
73
|
});
|
|
68
|
-
execute(databaseClient: DatabaseClient): Promise<
|
|
74
|
+
execute(databaseClient: DatabaseClient): Promise<MessageCreateCommandResult>;
|
|
69
75
|
}
|
|
70
76
|
export type MessageDequeueCommandResultMessageDequeued = {
|
|
71
77
|
resultType: "MESSAGE_DEQUEUED";
|
|
@@ -176,6 +182,8 @@ export declare class QueueChannelMessageModule<T> {
|
|
|
176
182
|
delayMs?: number;
|
|
177
183
|
}): Promise<{
|
|
178
184
|
messageId: string;
|
|
185
|
+
channelName: string;
|
|
186
|
+
channelSize: number;
|
|
179
187
|
}>;
|
|
180
188
|
}
|
|
181
189
|
export declare class QueueChannelPolicyModule<T> {
|
|
@@ -251,6 +259,7 @@ export declare class QueueMessageModule<T> {
|
|
|
251
259
|
}): Promise<{
|
|
252
260
|
messageId: string;
|
|
253
261
|
channelName: string;
|
|
262
|
+
channelSize: number;
|
|
254
263
|
}>;
|
|
255
264
|
}
|
|
256
265
|
export type MessageDequeueResult<T> = {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var D=(e)=>{return e*1000};var c=D(0);var b=(e)=>{let t=JSON.parse(e);if(t.type===0)return{eventType:"MESSAGE_CREATED",id:t.id,delayMs:t.delay_ms};else if(t.type===1)return{eventType:"MESSAGE_DELETED",id:t.id};else if(t.type===2)return{eventType:"MESSAGE_DEFERRED",id:t.id,delayMs:t.delay_ms};else throw new Error("Unknown event type")};var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),B=(e)=>({nodeType:"RAW",value:e}),w=(e)=>{return`'${e.replace(/'/g,"''")}'`},H=(e)=>{if(e===null)return"NULL";else if(typeof e==="string")return w(e);else if(typeof e==="number")return e.toString();else if(typeof e==="boolean")return e?"TRUE":"FALSE";else if(e instanceof Date)return`'${e.toISOString()}'`;else if(typeof e==="bigint")return e.toString();else throw new Error(`Unsupported value type: ${typeof e}`)},k=(e)=>{return`"${e.replace(/"/g,'""')}"`},P=(e)=>{if(e.nodeType==="VALUE")return H(e.value);else if(e.nodeType==="REF")return k(e.value);else if(e.nodeType==="RAW")return e.value;else throw new Error("Unsupported SQL node type")};var n=(e,...t)=>{let a=[];for(let E=0;E<e.length;E+=1)if(a.push(e[E]),E<t.length)a.push(P(t[E]));return B(a.join(""))};class o{schema;channelName;createdAt;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.createdAt=new Date}async execute(e){await e.query(n`
|
|
2
2
|
SELECT 1 FROM ${s(this.schema)}."channel_policy_clear"(
|
|
3
3
|
$1
|
|
4
4
|
)
|
|
@@ -8,14 +8,16 @@ var p=(e)=>{return e*1000};var o=p(0);var b=(e)=>{let t=JSON.parse(e);if(t.type=
|
|
|
8
8
|
$2::INTEGER,
|
|
9
9
|
$3::INTEGER
|
|
10
10
|
)
|
|
11
|
-
`.value,[this.channelName,this.maxConcurrency,this.releaseIntervalMs])}}import{randomBytes as Q}from"crypto";var
|
|
12
|
-
SELECT
|
|
11
|
+
`.value,[this.channelName,this.maxConcurrency,this.releaseIntervalMs])}}import{randomBytes as Q}from"crypto";var p=()=>{return Q(16).toString("base64url")};class l{schema;channelName;content;delayMs;createdAt;constructor(e){let t=e.delayMs===void 0?c:e.delayMs;this.schema=e.schema,this.channelName=e.channelName??p(),this.content=e.content,this.delayMs=t,this.createdAt=new Date}async execute(e){let t=await e.query(n`
|
|
12
|
+
SELECT
|
|
13
|
+
result_code,
|
|
14
|
+
metadata
|
|
15
|
+
FROM ${s(this.schema)}."message_create"(
|
|
13
16
|
$1,
|
|
14
|
-
$2,
|
|
15
|
-
$3
|
|
16
|
-
$4::BIGINT
|
|
17
|
+
$2,
|
|
18
|
+
$3::BIGINT
|
|
17
19
|
)
|
|
18
|
-
`.value,[this.
|
|
20
|
+
`.value,[this.channelName,this.content,this.delayMs]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_CREATED",metadata:{id:t.metadata.id,channelSize:t.metadata.channel_size}};else throw new Error("Unexpected result code")}}class i{schema;lockMs;constructor(e){this.schema=e.schema,this.lockMs=e.lockMs}async execute(e){let t=await e.query(n`
|
|
19
21
|
SELECT
|
|
20
22
|
result_code,
|
|
21
23
|
metadata,
|
|
@@ -27,7 +29,7 @@ var p=(e)=>{return e*1000};var o=p(0);var b=(e)=>{let t=JSON.parse(e);if(t.type=
|
|
|
27
29
|
$1,
|
|
28
30
|
$2::BIGINT
|
|
29
31
|
)
|
|
30
|
-
`.value,[this.id,this.numAttempts]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(t.result_code===1)return{resultType:"STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_DELETED"};else throw new Error("Unexpected result")}}class d{schema;id;numAttempts;delayMs;state;constructor(e){let t=e.delayMs===void 0?
|
|
32
|
+
`.value,[this.id,this.numAttempts]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(t.result_code===1)return{resultType:"STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_DELETED"};else throw new Error("Unexpected result")}}class d{schema;id;numAttempts;delayMs;state;constructor(e){let t=e.delayMs===void 0?c:e.delayMs;this.schema=e.schema,this.numAttempts=e.numAttempts,this.id=e.id,this.delayMs=t,this.state=e.state??null}async execute(e){let t=await e.query(n`
|
|
31
33
|
SELECT * FROM ${s(this.schema)}."message_defer"(
|
|
32
34
|
$1,
|
|
33
35
|
$2::BIGINT,
|
|
@@ -41,8 +43,8 @@ var p=(e)=>{return e*1000};var o=p(0);var b=(e)=>{let t=JSON.parse(e);if(t.type=
|
|
|
41
43
|
$3::BIGINT
|
|
42
44
|
)
|
|
43
45
|
`.value,[this.id,this.numAttempts,this.lockMs]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(t.result_code===1)return{resultType:"MESSAGE_STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_HEARTBEATED"};else throw new Error("Unexpected result")}}var y=(e)=>{let t=e.split(`
|
|
44
|
-
`),a=Number.MAX_SAFE_INTEGER;for(let
|
|
45
|
-
`).trim()};import{dirname as M}from"path";var __filename="/home/runner/work/lonnymq/lonnymq/src/core/path.ts",
|
|
46
|
+
`),a=Number.MAX_SAFE_INTEGER;for(let E of t){if(E.trim().length===0)continue;let F=E.search(/\S/);a=Math.min(a,F)}return t.map((E)=>E.slice(a)).join(`
|
|
47
|
+
`).trim()};import{dirname as M}from"path";var __filename="/home/runner/work/lonnymq/lonnymq/src/core/path.ts",X=M(M(__filename)),j=new RegExp(`^${X}/`),_=(e)=>{return e.replace(j,"")};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/00-table-channel-policy.ts",I={name:_(__filename),sql:(e)=>{let t=[e.schema,"channel_policy_name_ux"].join("_");return[n`
|
|
46
48
|
CREATE TABLE ${s(e.schema)}."channel_policy" (
|
|
47
49
|
"id" UUID NOT NULL DEFAULT GEN_RANDOM_UUID(),
|
|
48
50
|
"name" TEXT NOT NULL,
|
|
@@ -54,7 +56,7 @@ var p=(e)=>{return e*1000};var o=p(0);var b=(e)=>{let t=JSON.parse(e);if(t.type=
|
|
|
54
56
|
`,n`
|
|
55
57
|
CREATE UNIQUE INDEX ${s(t)}
|
|
56
58
|
ON ${s(e.schema)}."channel_policy" ("name");
|
|
57
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/01-table-channel-state.ts",v={name:
|
|
59
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/01-table-channel-state.ts",v={name:_(__filename),sql:(e)=>{let t=[e.schema,"channel_state_name_ux"].join("_"),a=[e.schema,"channel_state_dequeue_ix"].join("_");return[n`
|
|
58
60
|
CREATE TABLE ${s(e.schema)}."channel_state" (
|
|
59
61
|
"id" UUID NOT NULL DEFAULT GEN_RANDOM_UUID(),
|
|
60
62
|
"name" TEXT NOT NULL,
|
|
@@ -79,7 +81,7 @@ var p=(e)=>{return e*1000};var o=p(0);var b=(e)=>{let t=JSON.parse(e);if(t.type=
|
|
|
79
81
|
"active_next_at" ASC
|
|
80
82
|
) WHERE "message_id" IS NOT NULL
|
|
81
83
|
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency");
|
|
82
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/02-table-message.ts",L={name:
|
|
84
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/02-table-message.ts",L={name:_(__filename),sql:(e)=>{return[n`
|
|
83
85
|
CREATE TABLE ${s(e.schema)}."message" (
|
|
84
86
|
"id" UUID NOT NULL,
|
|
85
87
|
"channel_name" TEXT NOT NULL,
|
|
@@ -105,13 +107,15 @@ var p=(e)=>{return e*1000};var o=p(0);var b=(e)=>{let t=JSON.parse(e);if(t.type=
|
|
|
105
107
|
ON ${s(e.schema)}."message" (
|
|
106
108
|
"unlock_at" ASC
|
|
107
109
|
) WHERE "is_locked";
|
|
108
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/03-function-message-create.ts",
|
|
110
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/03-function-message-create.ts",C={name:_(__filename),sql:(e)=>{return[n`
|
|
109
111
|
CREATE FUNCTION ${s(e.schema)}."message_create" (
|
|
110
|
-
p_id UUID,
|
|
111
112
|
p_channel_name TEXT,
|
|
112
113
|
p_content BYTEA,
|
|
113
114
|
p_delay_ms BIGINT
|
|
114
|
-
) RETURNS
|
|
115
|
+
) RETURNS TABLE (
|
|
116
|
+
result_code INTEGER,
|
|
117
|
+
metadata JSON
|
|
118
|
+
) AS $$
|
|
115
119
|
DECLARE
|
|
116
120
|
v_now TIMESTAMP;
|
|
117
121
|
v_channel_policy RECORD;
|
|
@@ -129,7 +133,7 @@ var p=(e)=>{return e*1000};var o=p(0);var b=(e)=>{let t=JSON.parse(e);if(t.type=
|
|
|
129
133
|
"dequeue_at",
|
|
130
134
|
"created_at"
|
|
131
135
|
) VALUES (
|
|
132
|
-
|
|
136
|
+
GEN_RANDOM_UUID(),
|
|
133
137
|
p_channel_name,
|
|
134
138
|
p_content,
|
|
135
139
|
FALSE,
|
|
@@ -206,11 +210,18 @@ var p=(e)=>{return e*1000};var o=p(0);var b=(e)=>{let t=JSON.parse(e);if(t.type=
|
|
|
206
210
|
${r(e.eventChannel)},
|
|
207
211
|
JSON_BUILD_OBJECT(
|
|
208
212
|
'type', ${r(0)},
|
|
209
|
-
'id',
|
|
213
|
+
'id', v_message."id",
|
|
210
214
|
'delay_ms', p_delay_ms
|
|
211
215
|
)::TEXT
|
|
212
216
|
);
|
|
213
217
|
END IF;
|
|
218
|
+
|
|
219
|
+
RETURN QUERY SELECT
|
|
220
|
+
${r(0)},
|
|
221
|
+
JSON_BUILD_OBJECT(
|
|
222
|
+
'id', v_message."id",
|
|
223
|
+
'channel_size', v_channel_state."current_size" + 1
|
|
224
|
+
);
|
|
214
225
|
END;
|
|
215
226
|
$$ LANGUAGE plpgsql;
|
|
216
227
|
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/04-function-message-dequeue.ts",K=(e)=>n`
|
|
@@ -247,7 +258,7 @@ var p=(e)=>{return e*1000};var o=p(0);var b=(e)=>{let t=JSON.parse(e);if(t.type=
|
|
|
247
258
|
WHERE NOT "is_locked"
|
|
248
259
|
AND "channel_name" = ${e.channelName}
|
|
249
260
|
ORDER BY "dequeue_at" ASC, "seq_no" ASC
|
|
250
|
-
`,
|
|
261
|
+
`,U={name:_(__filename),sql:(e)=>{let t=K({now:n`v_now`,schema:e.schema}),a=ee({channelName:n`v_channel_state."name"`,schema:e.schema}),E=Z({schema:e.schema});return[n`
|
|
251
262
|
CREATE FUNCTION ${s(e.schema)}."message_dequeue" (
|
|
252
263
|
p_lock_ms BIGINT
|
|
253
264
|
)
|
|
@@ -291,7 +302,7 @@ var p=(e)=>{return e*1000};var o=p(0);var b=(e)=>{let t=JSON.parse(e);if(t.type=
|
|
|
291
302
|
RETURN;
|
|
292
303
|
END IF;
|
|
293
304
|
|
|
294
|
-
${
|
|
305
|
+
${E}
|
|
295
306
|
FOR UPDATE
|
|
296
307
|
SKIP LOCKED
|
|
297
308
|
LIMIT 1
|
|
@@ -370,7 +381,7 @@ var p=(e)=>{return e*1000};var o=p(0);var b=(e)=>{let t=JSON.parse(e);if(t.type=
|
|
|
370
381
|
RETURN;
|
|
371
382
|
END;
|
|
372
383
|
$$ LANGUAGE plpgsql;
|
|
373
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/05-function-message-delete.ts",O={name:
|
|
384
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/05-function-message-delete.ts",O={name:_(__filename),sql:(e)=>{return[n`
|
|
374
385
|
CREATE FUNCTION ${s(e.schema)}."message_delete" (
|
|
375
386
|
p_id UUID,
|
|
376
387
|
p_num_attempts BIGINT
|
|
@@ -447,7 +458,7 @@ var p=(e)=>{return e*1000};var o=p(0);var b=(e)=>{let t=JSON.parse(e);if(t.type=
|
|
|
447
458
|
RETURN;
|
|
448
459
|
END;
|
|
449
460
|
$$ LANGUAGE plpgsql;
|
|
450
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/06-function-message-defer.ts",f={name:
|
|
461
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/06-function-message-defer.ts",f={name:_(__filename),sql:(e)=>{return[n`
|
|
451
462
|
CREATE FUNCTION ${s(e.schema)}."message_defer" (
|
|
452
463
|
p_id UUID,
|
|
453
464
|
p_num_attempts BIGINT,
|
|
@@ -543,7 +554,7 @@ var p=(e)=>{return e*1000};var o=p(0);var b=(e)=>{let t=JSON.parse(e);if(t.type=
|
|
|
543
554
|
RETURN;
|
|
544
555
|
END;
|
|
545
556
|
$$ LANGUAGE plpgsql;
|
|
546
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/08-function-channel-policy-clear.ts",G={name:
|
|
557
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/08-function-channel-policy-clear.ts",G={name:_(__filename),sql:(e)=>{return[n`
|
|
547
558
|
CREATE FUNCTION ${s(e.schema)}."channel_policy_clear" (
|
|
548
559
|
p_name TEXT
|
|
549
560
|
) RETURNS VOID AS $$
|
|
@@ -572,7 +583,7 @@ var p=(e)=>{return e*1000};var o=p(0);var b=(e)=>{let t=JSON.parse(e);if(t.type=
|
|
|
572
583
|
END IF;
|
|
573
584
|
END;
|
|
574
585
|
$$ LANGUAGE plpgsql;
|
|
575
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/09-function-channel-policy-set.ts",q={name:
|
|
586
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/09-function-channel-policy-set.ts",q={name:_(__filename),sql:(e)=>{return[n`
|
|
576
587
|
CREATE FUNCTION ${s(e.schema)}."channel_policy_set" (
|
|
577
588
|
p_name TEXT,
|
|
578
589
|
p_max_concurrency INTEGER,
|
|
@@ -603,7 +614,7 @@ var p=(e)=>{return e*1000};var o=p(0);var b=(e)=>{let t=JSON.parse(e);if(t.type=
|
|
|
603
614
|
WHERE "name" = p_name;
|
|
604
615
|
END;
|
|
605
616
|
$$ LANGUAGE plpgsql;
|
|
606
|
-
`]}};class
|
|
617
|
+
`]}};class N{schema;channelName;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.channelName=e.channelName}async create(e){let t=this.adaptor(e.databaseClient),a=new l({schema:this.schema,channelName:this.channelName,content:e.content,delayMs:e.delayMs}),E=await a.execute(t);return{messageId:E.metadata.id,channelName:a.channelName,channelSize:E.metadata.channelSize}}}class S{schema;adaptor;channelName;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.channelName=e.channelName}set(e){let t=this.adaptor(e.databaseClient);return new m({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,releaseIntervalMs:e.releaseIntervalMs}).execute(t)}clear(e){let t=this.adaptor(e.databaseClient);return new o({schema:this.schema,channelName:this.channelName}).execute(t)}}class R{policy;message;constructor(e){this.message=new N({schema:e.schema,adaptor:e.adaptor,channelName:e.channelName}),this.policy=new S({schema:e.schema,adaptor:e.adaptor,channelName:e.channelName})}}class A{schema;adaptor;id;isUnlocked;channelName;content;state;numAttempts;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.id=e.id,this.channelName=e.channelName,this.isUnlocked=e.isUnlocked,this.content=e.content,this.state=e.state,this.numAttempts=e.numAttempts}async defer(e){let t=this.adaptor(e.databaseClient);return new d({schema:this.schema,id:this.id,numAttempts:this.numAttempts,delayMs:e.delayMs,state:e.state}).execute(t)}async delete(e){let t=this.adaptor(e.databaseClient);return new u({schema:this.schema,numAttempts:this.numAttempts,id:this.id}).execute(t)}async heartbeat(e){let t=this.adaptor(e.databaseClient);return new T({schema:this.schema,id:this.id,numAttempts:this.numAttempts,lockMs:e.lockMs}).execute(t)}}class g{schema;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor}async create(e){let t=this.adaptor(e.databaseClient),a=new l({schema:this.schema,content:e.content,delayMs:e.delayMs}),E=await a.execute(t);return{messageId:E.metadata.id,channelName:a.channelName,channelSize:E.metadata.channelSize}}}var __filename="/home/runner/work/lonnymq/lonnymq/src/install/07-function-message-heartbeat.ts",x={name:_(__filename),sql:(e)=>{return[n`
|
|
607
618
|
CREATE FUNCTION ${s(e.schema)}."message_heartbeat" (
|
|
608
619
|
p_id UUID,
|
|
609
620
|
p_num_attempts BIGINT,
|
|
@@ -653,4 +664,4 @@ var p=(e)=>{return e*1000};var o=p(0);var b=(e)=>{let t=JSON.parse(e);if(t.type=
|
|
|
653
664
|
RETURN;
|
|
654
665
|
END;
|
|
655
666
|
$$ LANGUAGE plpgsql;
|
|
656
|
-
`]}};class ${schema;message;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor?e.adaptor:(t)=>t,this.message=new g({schema:this.schema,adaptor:this.adaptor})}async dequeue(e){let t=new i({schema:this.schema,lockMs:e.lockMs}),a=this.adaptor(e.databaseClient),
|
|
667
|
+
`]}};class ${schema;message;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor?e.adaptor:(t)=>t,this.message=new g({schema:this.schema,adaptor:this.adaptor})}async dequeue(e){let t=new i({schema:this.schema,lockMs:e.lockMs}),a=this.adaptor(e.databaseClient),E=await t.execute(a);if(E.resultType==="MESSAGE_DEQUEUED")return{resultType:"MESSAGE_DEQUEUED",message:new A({schema:this.schema,adaptor:this.adaptor,id:E.message.id,channelName:E.message.channelName,isUnlocked:E.message.isUnlocked,content:E.message.content,state:E.message.state,numAttempts:E.message.numAttempts})};else return E}channel(e){return new R({adaptor:this.adaptor,schema:this.schema,channelName:e})}install(e={}){return[I,v,L,C,U,O,f,x,q,G].sort((t,a)=>t.name.localeCompare(a.name)).flatMap((t)=>t.sql({schema:this.schema,eventChannel:e.eventChannel??null})).map((t)=>y(t.value))}}export{b as queueEventDecode,$ as Queue,T as MessageHeartbeatCommand,i as MessageDequeueCommand,u as MessageDeleteCommand,d as MessageDeferCommand,l as MessageCreateCommand,m as ChannelPolicySetCommand,o as ChannelPolicyClearCommand};
|