lonnymq 0.0.15 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +57 -58
- package/dist/index.d.ts +50 -37
- package/dist/index.js +23 -24
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var{defineProperty:h,getOwnPropertyNames:
|
|
1
|
+
var{defineProperty:h,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=Object.prototype.hasOwnProperty;var L=new WeakMap,Y=(e)=>{var t=L.get(e),a;if(t)return t;if(t=h({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")V(e).map((r)=>!W.call(t,r)&&h(t,r,{get:()=>e[r],enumerable:!(a=z(e,r))||a.enumerable}));return L.set(e,t),t};var X=(e,t)=>{for(var a in t)h(e,a,{get:t[a],enumerable:!0,configurable:!0,set:(r)=>t[a]=()=>r})};var ie={};X(ie,{queueEventDecode:()=>O,Queue:()=>v,MessageHeartbeatCommand:()=>R,MessageDequeueCommand:()=>i,MessageDeleteCommand:()=>u,MessageDeferCommand:()=>c,MessageCreateCommand:()=>o,ChannelPolicySetCommand:()=>m,ChannelPolicyClearCommand:()=>l});module.exports=Y(ie);var E=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),J=(e)=>({nodeType:"RAW",value:e}),K=(e)=>{return`'${e.replace(/'/g,"''")}'`},j=(e)=>{if(e===null)return"NULL";else if(typeof e==="string")return K(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}`)},Z=(e)=>{return`"${e.replace(/"/g,'""')}"`},ee=(e)=>{if(e.nodeType==="VALUE")return j(e.value);else if(e.nodeType==="REF")return Z(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(ee(t[r]));return J(a.join(""))};class l{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 m{schema;channelName;maxSize;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
|
|
5
|
+
`.value,[this.channelName])}}class m{schema;channelName;maxSize;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.maxSize??null;this.maxSize=a!==null?Math.max(0,a):null;let r=e.releaseIntervalMs??null;this.releaseIntervalMs=r!==null?Math.max(0,r):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
|
$4::INTEGER
|
|
11
11
|
)
|
|
12
|
-
`.value,[this.channelName,this.maxSize,this.maxConcurrency,this.releaseIntervalMs])}}var
|
|
12
|
+
`.value,[this.channelName,this.maxSize,this.maxConcurrency,this.releaseIntervalMs])}}var U=(e)=>{return e*1000};var d=U(0);var O=(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 f=require("node:crypto");class o{schema;channelName;name;content;lockMs;id;delayMs;createdAt;constructor(e){let t=e.name??null,a=Math.max(0,e.lockMs),r=e.delayMs===void 0?d:e.delayMs;this.id=f.randomUUID(),this.schema=e.schema,this.channelName=e.channelName,this.content=e.content,this.name=t,this.lockMs=a,this.delayMs=r,this.createdAt=new Date}async execute(e){let t=await e.query(n`
|
|
13
13
|
SELECT * FROM ${s(this.schema)}."message_create"(
|
|
14
14
|
$1,
|
|
15
15
|
$2,
|
|
@@ -18,33 +18,33 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
18
18
|
$5::BIGINT,
|
|
19
19
|
$6::BIGINT
|
|
20
20
|
)
|
|
21
|
-
`.value,[this.id,this.channelName,this.name,this.content,this.lockMs,this.delayMs]).then((
|
|
21
|
+
`.value,[this.id,this.channelName,this.name,this.content,this.lockMs,this.delayMs]).then((a)=>a.rows[0]);if(t.result_code===1)return{resultType:"MESSAGE_DROPPED"};else if(t.result_code===2)return{resultType:"MESSAGE_DEDUPLICATED"};else if(t.result_code===0)return{resultType:"MESSAGE_CREATED"};else throw new Error("Unexpected result")}}class i{schema;constructor(e){this.schema=e.schema}async execute(e){let t=await e.query(n`
|
|
22
22
|
SELECT
|
|
23
23
|
result_code,
|
|
24
24
|
metadata,
|
|
25
25
|
content,
|
|
26
26
|
state
|
|
27
27
|
FROM ${s(this.schema)}."message_dequeue"()
|
|
28
|
-
`.value,[]).then((
|
|
28
|
+
`.value,[]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_AVAILABLE",retryMs:t.metadata.retry_ms};else if(t.result_code===1)return{resultType:"MESSAGE_DEQUEUED",message:{id:t.metadata.id,channelName:t.metadata.channel_name,isUnlocked:t.metadata.is_unlocked,name:t.metadata.name,content:t.content,state:t.state,numAttempts:t.metadata.num_attempts}};else throw new Error("Unexpected dequeue result")}}class u{schema;id;numAttempts;constructor(e){this.schema=e.schema,this.id=e.id,this.numAttempts=e.numAttempts}async execute(e){let t=await e.query(n`
|
|
29
29
|
SELECT * FROM ${s(this.schema)}."message_delete"(
|
|
30
30
|
$1,
|
|
31
31
|
$2::BIGINT
|
|
32
32
|
)
|
|
33
|
-
`.value,[this.id,this.numAttempts]).then((
|
|
33
|
+
`.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 c{schema;id;numAttempts;delayMs;state;constructor(e){let t=e.delayMs===void 0?d: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`
|
|
34
34
|
SELECT * FROM ${s(this.schema)}."message_defer"(
|
|
35
35
|
$1,
|
|
36
36
|
$2::BIGINT,
|
|
37
37
|
$3::BIGINT,
|
|
38
38
|
$4
|
|
39
39
|
)
|
|
40
|
-
`.value,[this.id,this.numAttempts,this.delayMs,this.state]).then((
|
|
40
|
+
`.value,[this.id,this.numAttempts,this.delayMs,this.state]).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_DEFERRED"};else throw new Error("Unexpected result")}}class R{schema;id;numAttempts;constructor(e){this.schema=e.schema,this.numAttempts=e.numAttempts,this.id=e.id}async execute(e){let t=await e.query(n`
|
|
41
41
|
SELECT * FROM ${s(this.schema)}."message_heartbeat"(
|
|
42
42
|
$1,
|
|
43
43
|
$2::BIGINT
|
|
44
44
|
)
|
|
45
|
-
`.value,[this.id,this.numAttempts]).then((
|
|
46
|
-
`),
|
|
47
|
-
`).trim()};var
|
|
45
|
+
`.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:"MESSAGE_STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_HEARTBEATED"};else throw new Error("Unexpected result")}}var x=(e)=>{let t=e.split(`
|
|
46
|
+
`),a=Number.MAX_SAFE_INTEGER;for(let r of t){if(r.trim().length===0)continue;let T=r.search(/\S/);a=Math.min(a,T)}return t.map((r)=>r.slice(a)).join(`
|
|
47
|
+
`).trim()};var S=require("path"),__filename="/home/runner/work/lonnymq/lonnymq/src/core/path.ts",Ee=S.dirname(S.dirname(__filename)),_e=new RegExp(`^${Ee}/`),_=(e)=>{return e.replace(_e,"")};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/00-table-channel-policy.ts",G={name:_(__filename),sql:(e)=>{return[n`
|
|
48
48
|
CREATE TABLE ${s(e.schema)}."channel_policy" (
|
|
49
49
|
"id" UUID NOT NULL DEFAULT GEN_RANDOM_UUID(),
|
|
50
50
|
"name" TEXT NOT NULL,
|
|
@@ -54,10 +54,10 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
54
54
|
"created_at" TIMESTAMP NOT NULL,
|
|
55
55
|
PRIMARY KEY ("id")
|
|
56
56
|
);
|
|
57
|
-
`,
|
|
57
|
+
`,n`
|
|
58
58
|
CREATE UNIQUE INDEX "channel_policy_name_ux"
|
|
59
59
|
ON ${s(e.schema)}."channel_policy" ("name");
|
|
60
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/01-table-channel-state.ts"
|
|
60
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/01-table-channel-state.ts",F={name:_(__filename),sql:(e)=>{return[n`
|
|
61
61
|
CREATE TABLE ${s(e.schema)}."channel_state" (
|
|
62
62
|
"id" UUID NOT NULL DEFAULT GEN_RANDOM_UUID(),
|
|
63
63
|
"name" TEXT NOT NULL,
|
|
@@ -74,16 +74,16 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
74
74
|
"created_at" TIMESTAMP NOT NULL,
|
|
75
75
|
PRIMARY KEY ("id")
|
|
76
76
|
);
|
|
77
|
-
`,
|
|
77
|
+
`,n`
|
|
78
78
|
CREATE UNIQUE INDEX "channel_state_name_ux"
|
|
79
79
|
ON ${s(e.schema)}."channel_state" ("name");
|
|
80
|
-
`,
|
|
80
|
+
`,n`
|
|
81
81
|
CREATE INDEX "channel_state_dequeue_ix"
|
|
82
82
|
ON ${s(e.schema)}."channel_state" (
|
|
83
83
|
"active_next_at" ASC
|
|
84
84
|
) WHERE "message_id" IS NOT NULL
|
|
85
85
|
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency");
|
|
86
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/02-table-message.ts",
|
|
86
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/02-table-message.ts",q={name:_(__filename),sql:(e)=>{return[n`
|
|
87
87
|
CREATE TABLE ${s(e.schema)}."message" (
|
|
88
88
|
"id" UUID NOT NULL,
|
|
89
89
|
"channel_name" TEXT NOT NULL,
|
|
@@ -99,25 +99,25 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
99
99
|
"created_at" TIMESTAMP NOT NULL,
|
|
100
100
|
PRIMARY KEY ("id")
|
|
101
101
|
);
|
|
102
|
-
`,
|
|
102
|
+
`,n`
|
|
103
103
|
CREATE UNIQUE INDEX "message_name_ux"
|
|
104
104
|
ON ${s(e.schema)}."message" (
|
|
105
105
|
"channel_name",
|
|
106
106
|
"name"
|
|
107
107
|
) WHERE "num_attempts" = 0
|
|
108
|
-
`,
|
|
108
|
+
`,n`
|
|
109
109
|
CREATE INDEX "message_dequeue_ix"
|
|
110
110
|
ON ${s(e.schema)}."message" (
|
|
111
111
|
"channel_name",
|
|
112
112
|
"dequeue_at" ASC,
|
|
113
113
|
"seq_no" ASC
|
|
114
114
|
) WHERE NOT "is_locked";
|
|
115
|
-
`,
|
|
115
|
+
`,n`
|
|
116
116
|
CREATE INDEX "message_locked_dequeue_ix"
|
|
117
117
|
ON ${s(e.schema)}."message" (
|
|
118
118
|
"unlock_at" ASC
|
|
119
119
|
) WHERE "is_locked";
|
|
120
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/03-function-message-create.ts"
|
|
120
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/03-function-message-create.ts",$={name:_(__filename),sql:(e)=>{return[n`
|
|
121
121
|
CREATE FUNCTION ${s(e.schema)}."message_create" (
|
|
122
122
|
p_id UUID,
|
|
123
123
|
p_channel_name TEXT,
|
|
@@ -130,7 +130,6 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
130
130
|
) AS $$
|
|
131
131
|
DECLARE
|
|
132
132
|
v_now TIMESTAMP;
|
|
133
|
-
v_active_next_at TIMESTAMP;
|
|
134
133
|
v_channel_policy RECORD;
|
|
135
134
|
v_channel_state RECORD;
|
|
136
135
|
v_message RECORD;
|
|
@@ -165,7 +164,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
165
164
|
v_now,
|
|
166
165
|
v_now
|
|
167
166
|
) ON CONFLICT ("name")
|
|
168
|
-
DO UPDATE SET "
|
|
167
|
+
DO UPDATE SET "name" = EXCLUDED."name"
|
|
169
168
|
RETURNING
|
|
170
169
|
"id",
|
|
171
170
|
"current_size",
|
|
@@ -181,7 +180,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
181
180
|
|
|
182
181
|
IF v_channel_state."current_size" >= v_channel_policy."max_size" THEN
|
|
183
182
|
RETURN QUERY SELECT
|
|
184
|
-
${
|
|
183
|
+
${E(1)};
|
|
185
184
|
RETURN;
|
|
186
185
|
END IF;
|
|
187
186
|
|
|
@@ -218,7 +217,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
218
217
|
|
|
219
218
|
IF v_message."id" != p_id THEN
|
|
220
219
|
RETURN QUERY SELECT
|
|
221
|
-
${
|
|
220
|
+
${E(2)};
|
|
222
221
|
RETURN;
|
|
223
222
|
END IF;
|
|
224
223
|
|
|
@@ -243,11 +242,11 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
243
242
|
WHERE "id" = v_channel_state."id";
|
|
244
243
|
END IF;
|
|
245
244
|
|
|
246
|
-
IF ${
|
|
245
|
+
IF ${E(e.eventChannel!==null)} THEN
|
|
247
246
|
PERFORM PG_NOTIFY(
|
|
248
|
-
${
|
|
247
|
+
${E(e.eventChannel)},
|
|
249
248
|
JSON_BUILD_OBJECT(
|
|
250
|
-
'type', ${
|
|
249
|
+
'type', ${E(0)},
|
|
251
250
|
'id', p_id,
|
|
252
251
|
'delay_ms', p_delay_ms
|
|
253
252
|
)::TEXT
|
|
@@ -255,11 +254,11 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
255
254
|
END IF;
|
|
256
255
|
|
|
257
256
|
RETURN QUERY SELECT
|
|
258
|
-
${
|
|
257
|
+
${E(0)};
|
|
259
258
|
RETURN;
|
|
260
259
|
END;
|
|
261
260
|
$$ LANGUAGE plpgsql;
|
|
262
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/04-function-message-dequeue.ts",
|
|
261
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/04-function-message-dequeue.ts",le=(e)=>n`
|
|
263
262
|
SELECT
|
|
264
263
|
"message"."id",
|
|
265
264
|
"message"."name",
|
|
@@ -273,7 +272,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
273
272
|
WHERE "is_locked"
|
|
274
273
|
AND "unlock_at" <= ${e.now}
|
|
275
274
|
ORDER BY "unlock_at" ASC
|
|
276
|
-
`,
|
|
275
|
+
`,me=(e)=>n`
|
|
277
276
|
SELECT
|
|
278
277
|
"channel_state"."id",
|
|
279
278
|
"channel_state"."name",
|
|
@@ -286,7 +285,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
286
285
|
WHERE "message_id" IS NOT NULL
|
|
287
286
|
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency")
|
|
288
287
|
ORDER BY "active_next_at" ASC
|
|
289
|
-
`,
|
|
288
|
+
`,oe=(e)=>n`
|
|
290
289
|
SELECT
|
|
291
290
|
"message"."id",
|
|
292
291
|
"message"."dequeue_at",
|
|
@@ -295,7 +294,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
295
294
|
WHERE NOT "is_locked"
|
|
296
295
|
AND "channel_name" = ${e.channelName}
|
|
297
296
|
ORDER BY "dequeue_at" ASC, "seq_no" ASC
|
|
298
|
-
`,
|
|
297
|
+
`,b={name:_(__filename),sql:(e)=>{let t=le({now:n`v_now`,schema:e.schema}),a=oe({channelName:n`v_channel_state."name"`,schema:e.schema}),r=me({schema:e.schema});return[n`
|
|
299
298
|
CREATE FUNCTION ${s(e.schema)}."message_dequeue" ()
|
|
300
299
|
RETURNS TABLE (
|
|
301
300
|
result_code INTEGER,
|
|
@@ -325,7 +324,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
325
324
|
WHERE "id" = v_message_locked."id";
|
|
326
325
|
|
|
327
326
|
RETURN QUERY SELECT
|
|
328
|
-
${
|
|
327
|
+
${E(1)},
|
|
329
328
|
v_message_locked.content,
|
|
330
329
|
v_message_locked.state,
|
|
331
330
|
JSON_BUILD_OBJECT(
|
|
@@ -338,7 +337,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
338
337
|
RETURN;
|
|
339
338
|
END IF;
|
|
340
339
|
|
|
341
|
-
${
|
|
340
|
+
${r}
|
|
342
341
|
FOR UPDATE
|
|
343
342
|
SKIP LOCKED
|
|
344
343
|
LIMIT 1
|
|
@@ -346,7 +345,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
346
345
|
|
|
347
346
|
IF v_channel_state."id" IS NULL THEN
|
|
348
347
|
RETURN QUERY SELECT
|
|
349
|
-
${
|
|
348
|
+
${E(0)},
|
|
350
349
|
NULL::BYTEA,
|
|
351
350
|
NULL::BYTEA,
|
|
352
351
|
JSON_BUILD_OBJECT('retry_ms', NULL);
|
|
@@ -355,7 +354,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
355
354
|
|
|
356
355
|
IF v_channel_state."active_next_at" > v_now THEN
|
|
357
356
|
RETURN QUERY SELECT
|
|
358
|
-
${
|
|
357
|
+
${E(0)},
|
|
359
358
|
NULL::BYTEA,
|
|
360
359
|
NULL::BYTEA,
|
|
361
360
|
JSON_BUILD_OBJECT(
|
|
@@ -382,7 +381,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
382
381
|
"unlock_at" = v_now + (v_message_dequeue."lock_ms" * INTERVAL '1 millisecond')
|
|
383
382
|
WHERE "id" = v_message_dequeue."id";
|
|
384
383
|
|
|
385
|
-
${
|
|
384
|
+
${a}
|
|
386
385
|
LIMIT 1
|
|
387
386
|
INTO v_message_next;
|
|
388
387
|
|
|
@@ -407,7 +406,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
407
406
|
END IF;
|
|
408
407
|
|
|
409
408
|
RETURN QUERY SELECT
|
|
410
|
-
${
|
|
409
|
+
${E(1)},
|
|
411
410
|
v_message_dequeue.content,
|
|
412
411
|
v_message_dequeue.state,
|
|
413
412
|
JSON_BUILD_OBJECT(
|
|
@@ -420,7 +419,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
420
419
|
RETURN;
|
|
421
420
|
END;
|
|
422
421
|
$$ LANGUAGE plpgsql;
|
|
423
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/05-function-message-delete.ts",
|
|
422
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/05-function-message-delete.ts",B={name:_(__filename),sql:(e)=>{return[n`
|
|
424
423
|
CREATE FUNCTION ${s(e.schema)}."message_delete" (
|
|
425
424
|
p_id UUID,
|
|
426
425
|
p_num_attempts BIGINT
|
|
@@ -445,11 +444,11 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
445
444
|
|
|
446
445
|
IF v_message."id" IS NULL THEN
|
|
447
446
|
RETURN QUERY SELECT
|
|
448
|
-
${
|
|
447
|
+
${E(0)};
|
|
449
448
|
RETURN;
|
|
450
449
|
ELSIF NOT v_message."is_locked" OR v_message."num_attempts" <> p_num_attempts THEN
|
|
451
450
|
RETURN QUERY SELECT
|
|
452
|
-
${
|
|
451
|
+
${E(1)};
|
|
453
452
|
RETURN;
|
|
454
453
|
END IF;
|
|
455
454
|
|
|
@@ -479,11 +478,11 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
479
478
|
WHERE "id" = v_channel_state."id";
|
|
480
479
|
END IF;
|
|
481
480
|
|
|
482
|
-
IF ${
|
|
481
|
+
IF ${E(e.eventChannel!==null)} THEN
|
|
483
482
|
PERFORM PG_NOTIFY(
|
|
484
|
-
${
|
|
483
|
+
${E(e.eventChannel)},
|
|
485
484
|
JSON_BUILD_OBJECT(
|
|
486
|
-
'type', ${
|
|
485
|
+
'type', ${E(1)},
|
|
487
486
|
'id', p_id
|
|
488
487
|
)::TEXT
|
|
489
488
|
);
|
|
@@ -493,11 +492,11 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
493
492
|
WHERE "id" = p_id;
|
|
494
493
|
|
|
495
494
|
RETURN QUERY SELECT
|
|
496
|
-
${
|
|
495
|
+
${E(2)};
|
|
497
496
|
RETURN;
|
|
498
497
|
END;
|
|
499
498
|
$$ LANGUAGE plpgsql;
|
|
500
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/06-function-message-defer.ts",
|
|
499
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/06-function-message-defer.ts",P={name:_(__filename),sql:(e)=>{return[n`
|
|
501
500
|
CREATE FUNCTION ${s(e.schema)}."message_defer" (
|
|
502
501
|
p_id UUID,
|
|
503
502
|
p_num_attempts BIGINT,
|
|
@@ -528,11 +527,11 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
528
527
|
|
|
529
528
|
IF v_message."id" IS NULL THEN
|
|
530
529
|
RETURN QUERY SELECT
|
|
531
|
-
${
|
|
530
|
+
${E(0)};
|
|
532
531
|
RETURN;
|
|
533
532
|
ELSIF NOT v_message."is_locked" OR v_message."num_attempts" <> p_num_attempts THEN
|
|
534
533
|
RETURN QUERY SELECT
|
|
535
|
-
${
|
|
534
|
+
${E(1)};
|
|
536
535
|
RETURN;
|
|
537
536
|
END IF;
|
|
538
537
|
|
|
@@ -577,11 +576,11 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
577
576
|
"dequeue_at" = v_dequeue_at
|
|
578
577
|
WHERE "id" = p_id;
|
|
579
578
|
|
|
580
|
-
IF ${
|
|
579
|
+
IF ${E(e.eventChannel!==null)} THEN
|
|
581
580
|
PERFORM PG_NOTIFY(
|
|
582
|
-
${
|
|
581
|
+
${E(e.eventChannel)},
|
|
583
582
|
JSON_BUILD_OBJECT(
|
|
584
|
-
'type', ${
|
|
583
|
+
'type', ${E(2)},
|
|
585
584
|
'delay_ms', p_delay_ms,
|
|
586
585
|
'id', p_id
|
|
587
586
|
)::TEXT
|
|
@@ -589,11 +588,11 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
589
588
|
END IF;
|
|
590
589
|
|
|
591
590
|
RETURN QUERY SELECT
|
|
592
|
-
${
|
|
591
|
+
${E(2)};
|
|
593
592
|
RETURN;
|
|
594
593
|
END;
|
|
595
594
|
$$ LANGUAGE plpgsql;
|
|
596
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/07-function-message-heartbeat.ts",
|
|
595
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/07-function-message-heartbeat.ts",Q={name:_(__filename),sql:(e)=>{return[n`
|
|
597
596
|
CREATE FUNCTION ${s(e.schema)}."message_heartbeat" (
|
|
598
597
|
p_id UUID,
|
|
599
598
|
p_num_attempts BIGINT
|
|
@@ -619,11 +618,11 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
619
618
|
|
|
620
619
|
IF v_message."id" IS NULL THEN
|
|
621
620
|
RETURN QUERY SELECT
|
|
622
|
-
${
|
|
621
|
+
${E(0)};
|
|
623
622
|
RETURN;
|
|
624
623
|
ELSIF NOT v_message."is_locked" OR v_message."num_attempts" <> p_num_attempts THEN
|
|
625
624
|
RETURN QUERY SELECT
|
|
626
|
-
${
|
|
625
|
+
${E(1)};
|
|
627
626
|
RETURN;
|
|
628
627
|
END IF;
|
|
629
628
|
|
|
@@ -632,11 +631,11 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
632
631
|
WHERE "id" = p_id;
|
|
633
632
|
|
|
634
633
|
RETURN QUERY SELECT
|
|
635
|
-
${
|
|
634
|
+
${E(2)};
|
|
636
635
|
RETURN;
|
|
637
636
|
END;
|
|
638
637
|
$$ LANGUAGE plpgsql;
|
|
639
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/08-function-channel-policy-clear.ts",
|
|
638
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/08-function-channel-policy-clear.ts",w={name:_(__filename),sql:(e)=>{return[n`
|
|
640
639
|
CREATE FUNCTION ${s(e.schema)}."channel_policy_clear" (
|
|
641
640
|
p_name TEXT
|
|
642
641
|
) RETURNS VOID AS $$
|
|
@@ -666,7 +665,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
666
665
|
END IF;
|
|
667
666
|
END;
|
|
668
667
|
$$ LANGUAGE plpgsql;
|
|
669
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/09-function-channel-policy-set.ts",
|
|
668
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/09-function-channel-policy-set.ts",H={name:_(__filename),sql:(e)=>{return[n`
|
|
670
669
|
CREATE FUNCTION ${s(e.schema)}."channel_policy_set" (
|
|
671
670
|
p_name TEXT,
|
|
672
671
|
p_max_size INTEGER,
|
|
@@ -702,4 +701,4 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
702
701
|
WHERE "name" = p_name;
|
|
703
702
|
END;
|
|
704
703
|
$$ LANGUAGE plpgsql;
|
|
705
|
-
`]}};class
|
|
704
|
+
`]}};class g{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}create(e){let t=new o({schema:this.schema,channelName:this.channelName,name:e.name,content:e.content,lockMs:e.lockMs,delayMs:e.delayMs}),a=new Promise((r)=>{this.registerFn({sortKey:JSON.stringify([t.channelName,t.name,t.createdAt.toISOString()]),execute:(T)=>t.execute(T).then((k)=>r(k))})});return{messageId:t.id,promise:a}}}class A{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}set(e){let t=new m({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,maxSize:e.maxSize,releaseIntervalMs:e.releaseIntervalMs});this.registerFn({sortKey:JSON.stringify([t.channelName,null,t.createdAt.toISOString()]),execute:async(a)=>{await t.execute(a)}})}clear(){let e=new l({schema:this.schema,channelName:this.channelName});this.registerFn({sortKey:JSON.stringify([e.channelName,null,e.createdAt.toISOString()]),execute:async(t)=>{await e.execute(t)}})}}class p{policy;message;constructor(e){this.message=new g(e),this.policy=new A(e)}}var ce=(e,t)=>{return e.sortKey.localeCompare(t.sortKey)};class D{commands;schema;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.commands=[]}channel(e){return new p({schema:this.schema,channelName:e,registerFn:(t)=>{this.commands.push(t)}})}async execute(e){let t=this.adaptor(e.databaseClient);for(let a of this.commands.sort(ce))await a.execute(t)}}class y{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);return new o({schema:this.schema,channelName:this.channelName,name:e.name,content:e.content,lockMs:e.lockMs,delayMs:e.delayMs}).execute(t)}}class M{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,maxSize:e.maxSize,releaseIntervalMs:e.releaseIntervalMs}).execute(t)}clear(e){let t=this.adaptor(e.databaseClient);return new l({schema:this.schema,channelName:this.channelName}).execute(t)}}class C{policy;message;constructor(e){this.message=new y({schema:e.schema,adaptor:e.adaptor,channelName:e.channelName}),this.policy=new M({schema:e.schema,adaptor:e.adaptor,channelName:e.channelName})}}class I{schema;adaptor;id;isUnlocked;channelName;name;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.name=e.name,this.content=e.content,this.state=e.state,this.numAttempts=e.numAttempts}async defer(e){let t=this.adaptor(e.databaseClient);return new c({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 c({schema:this.schema,id:this.id,numAttempts:this.numAttempts}).execute(t)}}class v{schema;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor?e.adaptor:(t)=>t}async dequeue(e){let t=new i({schema:this.schema}),a=this.adaptor(e.databaseClient),r=await t.execute(a);if(r.resultType==="MESSAGE_DEQUEUED")return{resultType:"MESSAGE_DEQUEUED",message:new I({schema:this.schema,adaptor:this.adaptor,id:r.message.id,channelName:r.message.channelName,name:r.message.name,isUnlocked:r.message.isUnlocked,content:r.message.content,state:r.message.state,numAttempts:r.message.numAttempts})};else return r}channel(e){return new C({adaptor:this.adaptor,schema:this.schema,channelName:e})}batch(){return new D({schema:this.schema,adaptor:this.adaptor})}migrations(e={}){return[G,F,q,$,b,B,P,Q,H,w].sort((t,a)=>t.name.localeCompare(a.name)).flatMap((t)=>t.sql({schema:this.schema,eventChannel:e.eventChannel??null})).map((t)=>x(t.value))}}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,19 +6,19 @@ export type DatabaseClientQueryResult = {
|
|
|
6
6
|
export interface DatabaseClient {
|
|
7
7
|
query(query: string, params: Array<unknown>): Promise<DatabaseClientQueryResult>;
|
|
8
8
|
}
|
|
9
|
+
export type DatabaseClientAdaptor<T> = (client: T) => DatabaseClient;
|
|
9
10
|
export declare class ChannelPolicyClearCommand {
|
|
10
|
-
readonly schema
|
|
11
|
+
private readonly schema;
|
|
11
12
|
readonly channelName: string;
|
|
12
13
|
readonly createdAt: Date;
|
|
13
14
|
constructor(params: {
|
|
14
15
|
schema: string;
|
|
15
16
|
channelName: string;
|
|
16
17
|
});
|
|
17
|
-
sortKeyGet(): string;
|
|
18
18
|
execute(databaseClient: DatabaseClient): Promise<void>;
|
|
19
19
|
}
|
|
20
20
|
export declare class ChannelPolicySetCommand {
|
|
21
|
-
readonly schema
|
|
21
|
+
private readonly schema;
|
|
22
22
|
readonly channelName: string;
|
|
23
23
|
readonly maxSize: number | null;
|
|
24
24
|
readonly maxConcurrency: number | null;
|
|
@@ -31,7 +31,6 @@ export declare class ChannelPolicySetCommand {
|
|
|
31
31
|
maxConcurrency?: number | null;
|
|
32
32
|
releaseIntervalMs?: number | null;
|
|
33
33
|
});
|
|
34
|
-
sortKeyGet(): string;
|
|
35
34
|
execute(databaseClient: DatabaseClient): Promise<void>;
|
|
36
35
|
}
|
|
37
36
|
export type QueueEventMessageCreate = {
|
|
@@ -66,7 +65,7 @@ export type MessageCreateCommandResultMessageDropped = {
|
|
|
66
65
|
};
|
|
67
66
|
export type MessageCreateCommandResult = MessageCreateCommandResultMessageCreated | MessageCreateCommandResultMessageDeduplicated | MessageCreateCommandResultMessageDropped;
|
|
68
67
|
export declare class MessageCreateCommand {
|
|
69
|
-
readonly schema
|
|
68
|
+
private readonly schema;
|
|
70
69
|
readonly channelName: string;
|
|
71
70
|
readonly name: string | null;
|
|
72
71
|
readonly content: Buffer;
|
|
@@ -79,7 +78,7 @@ export declare class MessageCreateCommand {
|
|
|
79
78
|
channelName: string;
|
|
80
79
|
name?: string;
|
|
81
80
|
content: Buffer;
|
|
82
|
-
lockMs
|
|
81
|
+
lockMs: number;
|
|
83
82
|
delayMs?: number;
|
|
84
83
|
});
|
|
85
84
|
execute(databaseClient: DatabaseClient): Promise<MessageCreateCommandResult>;
|
|
@@ -102,7 +101,7 @@ export type MessageDequeueCommandResultMessageNotAvailable = {
|
|
|
102
101
|
};
|
|
103
102
|
export type MessageDequeueCommandResult = MessageDequeueCommandResultMessageDequeued | MessageDequeueCommandResultMessageNotAvailable;
|
|
104
103
|
export declare class MessageDequeueCommand {
|
|
105
|
-
readonly schema
|
|
104
|
+
private readonly schema;
|
|
106
105
|
constructor(params: {
|
|
107
106
|
schema: string;
|
|
108
107
|
});
|
|
@@ -119,7 +118,7 @@ export type MessageDeleteCommandResultMessageDeleted = {
|
|
|
119
118
|
};
|
|
120
119
|
export type MessageDeleteCommandResult = MessageDeleteCommandResultMessageNotFound | MessageDeleteCommandResultStateInvalid | MessageDeleteCommandResultMessageDeleted;
|
|
121
120
|
export declare class MessageDeleteCommand {
|
|
122
|
-
readonly schema
|
|
121
|
+
private readonly schema;
|
|
123
122
|
readonly id: string;
|
|
124
123
|
readonly numAttempts: number;
|
|
125
124
|
constructor(params: {
|
|
@@ -140,7 +139,7 @@ export type MessageDeferCommandResultMessageDeferred = {
|
|
|
140
139
|
};
|
|
141
140
|
export type MessageDeferCommandResult = MessageDeferCommandResultMessageNotFound | MessageDeferCommandResultStateInvalid | MessageDeferCommandResultMessageDeferred;
|
|
142
141
|
export declare class MessageDeferCommand {
|
|
143
|
-
readonly schema
|
|
142
|
+
private readonly schema;
|
|
144
143
|
readonly id: string;
|
|
145
144
|
readonly numAttempts: number;
|
|
146
145
|
readonly delayMs: number;
|
|
@@ -165,7 +164,7 @@ export type MessageHeartbeatCommandResultMessageHeartbeated = {
|
|
|
165
164
|
};
|
|
166
165
|
export type MessageHeartbeatCommandResult = MessageHeartbeatCommandResultMessageNotFound | MessageHeartbeatCommandResultStateInvalid | MessageHeartbeatCommandResultMessageHeartbeated;
|
|
167
166
|
export declare class MessageHeartbeatCommand {
|
|
168
|
-
readonly schema
|
|
167
|
+
private readonly schema;
|
|
169
168
|
readonly id: string;
|
|
170
169
|
readonly numAttempts: number;
|
|
171
170
|
constructor(params: {
|
|
@@ -190,7 +189,7 @@ export declare class QueueBatchChannelMessage {
|
|
|
190
189
|
});
|
|
191
190
|
create(params: {
|
|
192
191
|
name?: string;
|
|
193
|
-
lockMs
|
|
192
|
+
lockMs: number;
|
|
194
193
|
content: Buffer;
|
|
195
194
|
delayMs?: number;
|
|
196
195
|
}): QueueBatchChannelMessageCreateResult;
|
|
@@ -225,59 +224,67 @@ export type BatchedCommand = {
|
|
|
225
224
|
execute: (databaseClient: DatabaseClient) => Promise<void>;
|
|
226
225
|
};
|
|
227
226
|
export type BatchedCommandRegisterFn = (command: BatchedCommand) => void;
|
|
228
|
-
export declare class QueueBatch {
|
|
227
|
+
export declare class QueueBatch<T> {
|
|
229
228
|
private readonly commands;
|
|
230
229
|
private readonly schema;
|
|
230
|
+
private readonly adaptor;
|
|
231
231
|
constructor(params: {
|
|
232
232
|
schema: string;
|
|
233
|
+
adaptor: DatabaseClientAdaptor<T>;
|
|
233
234
|
});
|
|
234
235
|
channel(channelName: string): QueueBatchChannel;
|
|
235
236
|
execute(params: {
|
|
236
|
-
databaseClient:
|
|
237
|
+
databaseClient: T;
|
|
237
238
|
}): Promise<void>;
|
|
238
239
|
}
|
|
239
|
-
export declare class QueueChannelMessage {
|
|
240
|
+
export declare class QueueChannelMessage<T> {
|
|
240
241
|
private readonly schema;
|
|
241
242
|
private readonly channelName;
|
|
243
|
+
private readonly adaptor;
|
|
242
244
|
constructor(params: {
|
|
243
245
|
schema: string;
|
|
246
|
+
adaptor: DatabaseClientAdaptor<T>;
|
|
244
247
|
channelName: string;
|
|
245
248
|
});
|
|
246
249
|
create(params: {
|
|
247
|
-
databaseClient:
|
|
250
|
+
databaseClient: T;
|
|
248
251
|
name?: string;
|
|
249
|
-
lockMs
|
|
252
|
+
lockMs: number;
|
|
250
253
|
content: Buffer;
|
|
251
254
|
delayMs?: number;
|
|
252
255
|
}): Promise<MessageCreateCommandResult>;
|
|
253
256
|
}
|
|
254
|
-
export declare class QueueChannelPolicy {
|
|
257
|
+
export declare class QueueChannelPolicy<T> {
|
|
255
258
|
private readonly schema;
|
|
259
|
+
private readonly adaptor;
|
|
256
260
|
private readonly channelName;
|
|
257
261
|
constructor(params: {
|
|
258
262
|
schema: string;
|
|
263
|
+
adaptor: DatabaseClientAdaptor<T>;
|
|
259
264
|
channelName: string;
|
|
260
265
|
});
|
|
261
266
|
set(params: {
|
|
262
|
-
databaseClient:
|
|
267
|
+
databaseClient: T;
|
|
263
268
|
maxConcurrency?: number | null;
|
|
264
269
|
maxSize?: number | null;
|
|
265
270
|
releaseIntervalMs?: number | null;
|
|
266
271
|
}): Promise<void>;
|
|
267
272
|
clear(params: {
|
|
268
|
-
databaseClient:
|
|
273
|
+
databaseClient: T;
|
|
269
274
|
}): Promise<void>;
|
|
270
275
|
}
|
|
271
|
-
export declare class QueueChannel {
|
|
272
|
-
readonly policy: QueueChannelPolicy
|
|
273
|
-
readonly message: QueueChannelMessage
|
|
276
|
+
export declare class QueueChannel<T> {
|
|
277
|
+
readonly policy: QueueChannelPolicy<T>;
|
|
278
|
+
readonly message: QueueChannelMessage<T>;
|
|
274
279
|
constructor(params: {
|
|
275
280
|
schema: string;
|
|
281
|
+
adaptor: DatabaseClientAdaptor<T>;
|
|
276
282
|
channelName: string;
|
|
277
283
|
});
|
|
278
284
|
}
|
|
279
|
-
export declare class QueueMessage {
|
|
285
|
+
export declare class QueueMessage<T> {
|
|
280
286
|
private readonly schema;
|
|
287
|
+
private readonly adaptor;
|
|
281
288
|
readonly id: string;
|
|
282
289
|
readonly isUnlocked: boolean;
|
|
283
290
|
readonly channelName: string;
|
|
@@ -287,6 +294,7 @@ export declare class QueueMessage {
|
|
|
287
294
|
readonly numAttempts: number;
|
|
288
295
|
constructor(params: {
|
|
289
296
|
schema: string;
|
|
297
|
+
adaptor: DatabaseClientAdaptor<T>;
|
|
290
298
|
id: string;
|
|
291
299
|
channelName: string;
|
|
292
300
|
isUnlocked: boolean;
|
|
@@ -296,35 +304,40 @@ export declare class QueueMessage {
|
|
|
296
304
|
numAttempts: number;
|
|
297
305
|
});
|
|
298
306
|
defer(params: {
|
|
299
|
-
databaseClient:
|
|
307
|
+
databaseClient: T;
|
|
300
308
|
delayMs?: number;
|
|
301
309
|
state?: Buffer;
|
|
302
310
|
}): Promise<MessageDeferCommandResult>;
|
|
303
311
|
delete(params: {
|
|
304
|
-
databaseClient:
|
|
312
|
+
databaseClient: T;
|
|
305
313
|
}): Promise<MessageDeleteCommandResult>;
|
|
306
314
|
heartbeat(params: {
|
|
307
|
-
databaseClient:
|
|
308
|
-
delayMs?: number;
|
|
315
|
+
databaseClient: T;
|
|
309
316
|
}): Promise<MessageDeferCommandResult>;
|
|
310
317
|
}
|
|
311
|
-
export type MessageDequeueResult = {
|
|
318
|
+
export type MessageDequeueResult<T> = {
|
|
312
319
|
resultType: "MESSAGE_NOT_AVAILABLE";
|
|
313
320
|
retryMs: number | null;
|
|
314
321
|
} | {
|
|
315
322
|
resultType: "MESSAGE_DEQUEUED";
|
|
316
|
-
message: QueueMessage
|
|
323
|
+
message: QueueMessage<T>;
|
|
324
|
+
};
|
|
325
|
+
export type QueueParams<T> = T extends DatabaseClient ? {
|
|
326
|
+
schema: string;
|
|
327
|
+
adaptor?: DatabaseClientAdaptor<T>;
|
|
328
|
+
} : {
|
|
329
|
+
schema: string;
|
|
330
|
+
adaptor: DatabaseClientAdaptor<T>;
|
|
317
331
|
};
|
|
318
|
-
export declare class Queue {
|
|
332
|
+
export declare class Queue<T = DatabaseClient> {
|
|
319
333
|
private readonly schema;
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
});
|
|
334
|
+
private readonly adaptor;
|
|
335
|
+
constructor(params: QueueParams<T>);
|
|
323
336
|
dequeue(params: {
|
|
324
|
-
databaseClient:
|
|
325
|
-
}): Promise<MessageDequeueResult
|
|
326
|
-
channel(channelName: string): QueueChannel
|
|
327
|
-
batch(): QueueBatch
|
|
337
|
+
databaseClient: T;
|
|
338
|
+
}): Promise<MessageDequeueResult<T>>;
|
|
339
|
+
channel(channelName: string): QueueChannel<T>;
|
|
340
|
+
batch(): QueueBatch<T>;
|
|
328
341
|
migrations(params?: {
|
|
329
342
|
eventChannel?: string;
|
|
330
343
|
}): string[];
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),
|
|
1
|
+
var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(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,'""')}"`},V=(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(V(t[E]));return Q(a.join(""))};class l{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 m{schema;channelName;maxSize;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.maxSize??null;this.maxSize=a!==null?Math.max(0,a):null;let
|
|
5
|
+
`.value,[this.channelName])}}class m{schema;channelName;maxSize;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.maxSize??null;this.maxSize=a!==null?Math.max(0,a):null;let E=e.releaseIntervalMs??null;this.releaseIntervalMs=E!==null?Math.max(0,E):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
|
$4::INTEGER
|
|
11
11
|
)
|
|
12
|
-
`.value,[this.channelName,this.maxSize,this.maxConcurrency,this.releaseIntervalMs])}}var
|
|
12
|
+
`.value,[this.channelName,this.maxSize,this.maxConcurrency,this.releaseIntervalMs])}}var M=(e)=>{return e*1000};var i=M(0);var z=(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")};import{randomUUID as Y}from"node:crypto";class o{schema;channelName;name;content;lockMs;id;delayMs;createdAt;constructor(e){let t=e.name??null,a=Math.max(0,e.lockMs),E=e.delayMs===void 0?i:e.delayMs;this.id=Y(),this.schema=e.schema,this.channelName=e.channelName,this.content=e.content,this.name=t,this.lockMs=a,this.delayMs=E,this.createdAt=new Date}async execute(e){let t=await e.query(n`
|
|
13
13
|
SELECT * FROM ${s(this.schema)}."message_create"(
|
|
14
14
|
$1,
|
|
15
15
|
$2,
|
|
@@ -30,21 +30,21 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=
|
|
|
30
30
|
$1,
|
|
31
31
|
$2::BIGINT
|
|
32
32
|
)
|
|
33
|
-
`.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
|
|
33
|
+
`.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 c{schema;id;numAttempts;delayMs;state;constructor(e){let t=e.delayMs===void 0?i: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`
|
|
34
34
|
SELECT * FROM ${s(this.schema)}."message_defer"(
|
|
35
35
|
$1,
|
|
36
36
|
$2::BIGINT,
|
|
37
37
|
$3::BIGINT,
|
|
38
38
|
$4
|
|
39
39
|
)
|
|
40
|
-
`.value,[this.id,this.numAttempts,this.delayMs,this.state]).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_DEFERRED"};else throw new Error("Unexpected result")}}class
|
|
40
|
+
`.value,[this.id,this.numAttempts,this.delayMs,this.state]).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_DEFERRED"};else throw new Error("Unexpected result")}}class C{schema;id;numAttempts;constructor(e){this.schema=e.schema,this.numAttempts=e.numAttempts,this.id=e.id}async execute(e){let t=await e.query(n`
|
|
41
41
|
SELECT * FROM ${s(this.schema)}."message_heartbeat"(
|
|
42
42
|
$1,
|
|
43
43
|
$2::BIGINT
|
|
44
44
|
)
|
|
45
|
-
`.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:"MESSAGE_STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_HEARTBEATED"};else throw new Error("Unexpected result")}}var
|
|
46
|
-
`),a=Number.MAX_SAFE_INTEGER;for(let
|
|
47
|
-
`).trim()};import{dirname as
|
|
45
|
+
`.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:"MESSAGE_STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_HEARTBEATED"};else throw new Error("Unexpected result")}}var I=(e)=>{let t=e.split(`
|
|
46
|
+
`),a=Number.MAX_SAFE_INTEGER;for(let E of t){if(E.trim().length===0)continue;let T=E.search(/\S/);a=Math.min(a,T)}return t.map((E)=>E.slice(a)).join(`
|
|
47
|
+
`).trim()};import{dirname as v}from"path";var __filename="/home/runner/work/lonnymq/lonnymq/src/core/path.ts",Z=v(v(__filename)),ee=new RegExp(`^${Z}/`),_=(e)=>{return e.replace(ee,"")};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/00-table-channel-policy.ts",L={name:_(__filename),sql:(e)=>{return[n`
|
|
48
48
|
CREATE TABLE ${s(e.schema)}."channel_policy" (
|
|
49
49
|
"id" UUID NOT NULL DEFAULT GEN_RANDOM_UUID(),
|
|
50
50
|
"name" TEXT NOT NULL,
|
|
@@ -57,7 +57,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=
|
|
|
57
57
|
`,n`
|
|
58
58
|
CREATE UNIQUE INDEX "channel_policy_name_ux"
|
|
59
59
|
ON ${s(e.schema)}."channel_policy" ("name");
|
|
60
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/01-table-channel-state.ts",
|
|
60
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/01-table-channel-state.ts",U={name:_(__filename),sql:(e)=>{return[n`
|
|
61
61
|
CREATE TABLE ${s(e.schema)}."channel_state" (
|
|
62
62
|
"id" UUID NOT NULL DEFAULT GEN_RANDOM_UUID(),
|
|
63
63
|
"name" TEXT NOT NULL,
|
|
@@ -83,7 +83,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=
|
|
|
83
83
|
"active_next_at" ASC
|
|
84
84
|
) WHERE "message_id" IS NOT NULL
|
|
85
85
|
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency");
|
|
86
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/02-table-message.ts",
|
|
86
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/02-table-message.ts",O={name:_(__filename),sql:(e)=>{return[n`
|
|
87
87
|
CREATE TABLE ${s(e.schema)}."message" (
|
|
88
88
|
"id" UUID NOT NULL,
|
|
89
89
|
"channel_name" TEXT NOT NULL,
|
|
@@ -117,7 +117,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=
|
|
|
117
117
|
ON ${s(e.schema)}."message" (
|
|
118
118
|
"unlock_at" ASC
|
|
119
119
|
) WHERE "is_locked";
|
|
120
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/03-function-message-create.ts",
|
|
120
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/03-function-message-create.ts",f={name:_(__filename),sql:(e)=>{return[n`
|
|
121
121
|
CREATE FUNCTION ${s(e.schema)}."message_create" (
|
|
122
122
|
p_id UUID,
|
|
123
123
|
p_channel_name TEXT,
|
|
@@ -130,7 +130,6 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=
|
|
|
130
130
|
) AS $$
|
|
131
131
|
DECLARE
|
|
132
132
|
v_now TIMESTAMP;
|
|
133
|
-
v_active_next_at TIMESTAMP;
|
|
134
133
|
v_channel_policy RECORD;
|
|
135
134
|
v_channel_state RECORD;
|
|
136
135
|
v_message RECORD;
|
|
@@ -165,7 +164,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=
|
|
|
165
164
|
v_now,
|
|
166
165
|
v_now
|
|
167
166
|
) ON CONFLICT ("name")
|
|
168
|
-
DO UPDATE SET "
|
|
167
|
+
DO UPDATE SET "name" = EXCLUDED."name"
|
|
169
168
|
RETURNING
|
|
170
169
|
"id",
|
|
171
170
|
"current_size",
|
|
@@ -259,7 +258,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=
|
|
|
259
258
|
RETURN;
|
|
260
259
|
END;
|
|
261
260
|
$$ LANGUAGE plpgsql;
|
|
262
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/04-function-message-dequeue.ts",
|
|
261
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/04-function-message-dequeue.ts",te=(e)=>n`
|
|
263
262
|
SELECT
|
|
264
263
|
"message"."id",
|
|
265
264
|
"message"."name",
|
|
@@ -273,7 +272,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=
|
|
|
273
272
|
WHERE "is_locked"
|
|
274
273
|
AND "unlock_at" <= ${e.now}
|
|
275
274
|
ORDER BY "unlock_at" ASC
|
|
276
|
-
`,
|
|
275
|
+
`,se=(e)=>n`
|
|
277
276
|
SELECT
|
|
278
277
|
"channel_state"."id",
|
|
279
278
|
"channel_state"."name",
|
|
@@ -286,7 +285,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=
|
|
|
286
285
|
WHERE "message_id" IS NOT NULL
|
|
287
286
|
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency")
|
|
288
287
|
ORDER BY "active_next_at" ASC
|
|
289
|
-
`,
|
|
288
|
+
`,ne=(e)=>n`
|
|
290
289
|
SELECT
|
|
291
290
|
"message"."id",
|
|
292
291
|
"message"."dequeue_at",
|
|
@@ -295,7 +294,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=
|
|
|
295
294
|
WHERE NOT "is_locked"
|
|
296
295
|
AND "channel_name" = ${e.channelName}
|
|
297
296
|
ORDER BY "dequeue_at" ASC, "seq_no" ASC
|
|
298
|
-
`,
|
|
297
|
+
`,x={name:_(__filename),sql:(e)=>{let t=te({now:n`v_now`,schema:e.schema}),a=ne({channelName:n`v_channel_state."name"`,schema:e.schema}),E=se({schema:e.schema});return[n`
|
|
299
298
|
CREATE FUNCTION ${s(e.schema)}."message_dequeue" ()
|
|
300
299
|
RETURNS TABLE (
|
|
301
300
|
result_code INTEGER,
|
|
@@ -338,7 +337,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=
|
|
|
338
337
|
RETURN;
|
|
339
338
|
END IF;
|
|
340
339
|
|
|
341
|
-
${
|
|
340
|
+
${E}
|
|
342
341
|
FOR UPDATE
|
|
343
342
|
SKIP LOCKED
|
|
344
343
|
LIMIT 1
|
|
@@ -420,7 +419,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=
|
|
|
420
419
|
RETURN;
|
|
421
420
|
END;
|
|
422
421
|
$$ LANGUAGE plpgsql;
|
|
423
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/05-function-message-delete.ts",
|
|
422
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/05-function-message-delete.ts",G={name:_(__filename),sql:(e)=>{return[n`
|
|
424
423
|
CREATE FUNCTION ${s(e.schema)}."message_delete" (
|
|
425
424
|
p_id UUID,
|
|
426
425
|
p_num_attempts BIGINT
|
|
@@ -497,7 +496,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=
|
|
|
497
496
|
RETURN;
|
|
498
497
|
END;
|
|
499
498
|
$$ LANGUAGE plpgsql;
|
|
500
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/06-function-message-defer.ts"
|
|
499
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/06-function-message-defer.ts",F={name:_(__filename),sql:(e)=>{return[n`
|
|
501
500
|
CREATE FUNCTION ${s(e.schema)}."message_defer" (
|
|
502
501
|
p_id UUID,
|
|
503
502
|
p_num_attempts BIGINT,
|
|
@@ -593,7 +592,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=
|
|
|
593
592
|
RETURN;
|
|
594
593
|
END;
|
|
595
594
|
$$ LANGUAGE plpgsql;
|
|
596
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/07-function-message-heartbeat.ts",
|
|
595
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/07-function-message-heartbeat.ts",q={name:_(__filename),sql:(e)=>{return[n`
|
|
597
596
|
CREATE FUNCTION ${s(e.schema)}."message_heartbeat" (
|
|
598
597
|
p_id UUID,
|
|
599
598
|
p_num_attempts BIGINT
|
|
@@ -636,7 +635,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=
|
|
|
636
635
|
RETURN;
|
|
637
636
|
END;
|
|
638
637
|
$$ LANGUAGE plpgsql;
|
|
639
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/08-function-channel-policy-clear.ts"
|
|
638
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/08-function-channel-policy-clear.ts",$={name:_(__filename),sql:(e)=>{return[n`
|
|
640
639
|
CREATE FUNCTION ${s(e.schema)}."channel_policy_clear" (
|
|
641
640
|
p_name TEXT
|
|
642
641
|
) RETURNS VOID AS $$
|
|
@@ -666,7 +665,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=
|
|
|
666
665
|
END IF;
|
|
667
666
|
END;
|
|
668
667
|
$$ LANGUAGE plpgsql;
|
|
669
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/09-function-channel-policy-set.ts",
|
|
668
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/09-function-channel-policy-set.ts",b={name:_(__filename),sql:(e)=>{return[n`
|
|
670
669
|
CREATE FUNCTION ${s(e.schema)}."channel_policy_set" (
|
|
671
670
|
p_name TEXT,
|
|
672
671
|
p_max_size INTEGER,
|
|
@@ -702,4 +701,4 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=
|
|
|
702
701
|
WHERE "name" = p_name;
|
|
703
702
|
END;
|
|
704
703
|
$$ LANGUAGE plpgsql;
|
|
705
|
-
`]}};class
|
|
704
|
+
`]}};class N{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}create(e){let t=new o({schema:this.schema,channelName:this.channelName,name:e.name,content:e.content,lockMs:e.lockMs,delayMs:e.delayMs}),a=new Promise((E)=>{this.registerFn({sortKey:JSON.stringify([t.channelName,t.name,t.createdAt.toISOString()]),execute:(T)=>t.execute(T).then((P)=>E(P))})});return{messageId:t.id,promise:a}}}class R{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}set(e){let t=new m({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,maxSize:e.maxSize,releaseIntervalMs:e.releaseIntervalMs});this.registerFn({sortKey:JSON.stringify([t.channelName,null,t.createdAt.toISOString()]),execute:async(a)=>{await t.execute(a)}})}clear(){let e=new l({schema:this.schema,channelName:this.channelName});this.registerFn({sortKey:JSON.stringify([e.channelName,null,e.createdAt.toISOString()]),execute:async(t)=>{await e.execute(t)}})}}class S{policy;message;constructor(e){this.message=new N(e),this.policy=new R(e)}}var ae=(e,t)=>{return e.sortKey.localeCompare(t.sortKey)};class g{commands;schema;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.commands=[]}channel(e){return new S({schema:this.schema,channelName:e,registerFn:(t)=>{this.commands.push(t)}})}async execute(e){let t=this.adaptor(e.databaseClient);for(let a of this.commands.sort(ae))await a.execute(t)}}class A{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);return new o({schema:this.schema,channelName:this.channelName,name:e.name,content:e.content,lockMs:e.lockMs,delayMs:e.delayMs}).execute(t)}}class p{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,maxSize:e.maxSize,releaseIntervalMs:e.releaseIntervalMs}).execute(t)}clear(e){let t=this.adaptor(e.databaseClient);return new l({schema:this.schema,channelName:this.channelName}).execute(t)}}class D{policy;message;constructor(e){this.message=new A({schema:e.schema,adaptor:e.adaptor,channelName:e.channelName}),this.policy=new p({schema:e.schema,adaptor:e.adaptor,channelName:e.channelName})}}class y{schema;adaptor;id;isUnlocked;channelName;name;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.name=e.name,this.content=e.content,this.state=e.state,this.numAttempts=e.numAttempts}async defer(e){let t=this.adaptor(e.databaseClient);return new c({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 d({schema:this.schema,numAttempts:this.numAttempts,id:this.id}).execute(t)}async heartbeat(e){let t=this.adaptor(e.databaseClient);return new c({schema:this.schema,id:this.id,numAttempts:this.numAttempts}).execute(t)}}class B{schema;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor?e.adaptor:(t)=>t}async dequeue(e){let t=new u({schema:this.schema}),a=this.adaptor(e.databaseClient),E=await t.execute(a);if(E.resultType==="MESSAGE_DEQUEUED")return{resultType:"MESSAGE_DEQUEUED",message:new y({schema:this.schema,adaptor:this.adaptor,id:E.message.id,channelName:E.message.channelName,name:E.message.name,isUnlocked:E.message.isUnlocked,content:E.message.content,state:E.message.state,numAttempts:E.message.numAttempts})};else return E}channel(e){return new D({adaptor:this.adaptor,schema:this.schema,channelName:e})}batch(){return new g({schema:this.schema,adaptor:this.adaptor})}migrations(e={}){return[L,U,O,f,x,G,F,q,b,$].sort((t,a)=>t.name.localeCompare(a.name)).flatMap((t)=>t.sql({schema:this.schema,eventChannel:e.eventChannel??null})).map((t)=>I(t.value))}}export{z as queueEventDecode,B as Queue,C as MessageHeartbeatCommand,u as MessageDequeueCommand,d as MessageDeleteCommand,c as MessageDeferCommand,o as MessageCreateCommand,m as ChannelPolicySetCommand,l as ChannelPolicyClearCommand};
|