lonnymq 0.0.18 → 0.0.19
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 +73 -124
- package/dist/index.d.ts +24 -43
- package/dist/index.js +54 -105
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
var{defineProperty:N,getOwnPropertyNames:
|
|
1
|
+
var{defineProperty:N,getOwnPropertyNames:Q,getOwnPropertyDescriptor:V}=Object,W=Object.prototype.hasOwnProperty;var C=new WeakMap,Y=(e)=>{var t=C.get(e),a;if(t)return t;if(t=N({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")Q(e).map((r)=>!W.call(t,r)&&N(t,r,{get:()=>e[r],enumerable:!(a=V(e,r))||a.enumerable}));return C.set(e,t),t};var z=(e,t)=>{for(var a in t)N(e,a,{get:t[a],enumerable:!0,configurable:!0,set:(r)=>t[a]=()=>r})};var le={};z(le,{queueEventDecode:()=>O,Queue:()=>L,MessageHeartbeatCommand:()=>d,MessageDequeueCommand:()=>m,MessageDeleteCommand:()=>i,MessageDeferCommand:()=>u,MessageCreateCommand:()=>l,ChannelPolicySetCommand:()=>c,ChannelPolicyClearCommand:()=>o});module.exports=Y(le);var U=(e)=>{return e*1000};var T=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 _=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),X=(e)=>({nodeType:"RAW",value:e}),J=(e)=>{return`'${e.replace(/'/g,"''")}'`},K=(e)=>{if(e===null)return"NULL";else if(typeof e==="string")return J(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}`)},j=(e)=>{return`"${e.replace(/"/g,'""')}"`},Z=(e)=>{if(e.nodeType==="VALUE")return K(e.value);else if(e.nodeType==="REF")return j(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(Z(t[r]));return X(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
|
)
|
|
5
|
-
`.value,[this.channelName])}}class
|
|
5
|
+
`.value,[this.channelName])}}class c{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
|
-
$3::INTEGER
|
|
10
|
-
$4::INTEGER
|
|
9
|
+
$3::INTEGER
|
|
11
10
|
)
|
|
12
|
-
`.value,[this.channelName,this.
|
|
13
|
-
SELECT
|
|
11
|
+
`.value,[this.channelName,this.maxConcurrency,this.releaseIntervalMs])}}var f=require("node:crypto");class l{schema;channelName;content;lockMs;id;delayMs;createdAt;constructor(e){let t=Math.max(0,e.lockMs),a=e.delayMs===void 0?T:e.delayMs;this.id=f.randomUUID(),this.schema=e.schema,this.channelName=e.channelName,this.content=e.content,this.lockMs=t,this.delayMs=a,this.createdAt=new Date}async execute(e){await e.query(n`
|
|
12
|
+
SELECT 1 FROM ${s(this.schema)}."message_create"(
|
|
14
13
|
$1,
|
|
15
14
|
$2,
|
|
16
|
-
$3,
|
|
17
|
-
$4,
|
|
18
|
-
$5::BIGINT
|
|
19
|
-
$6::BIGINT
|
|
15
|
+
$3,
|
|
16
|
+
$4::BIGINT,
|
|
17
|
+
$5::BIGINT
|
|
20
18
|
)
|
|
21
|
-
`.value,[this.id,this.channelName,this.
|
|
19
|
+
`.value,[this.id,this.channelName,this.content,this.lockMs,this.delayMs])}}class m{schema;constructor(e){this.schema=e.schema}async execute(e){let t=await e.query(n`
|
|
22
20
|
SELECT
|
|
23
21
|
result_code,
|
|
24
22
|
metadata,
|
|
25
23
|
content,
|
|
26
24
|
state
|
|
27
25
|
FROM ${s(this.schema)}."message_dequeue"()
|
|
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,
|
|
26
|
+
`.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,content:t.content,state:t.state,numAttempts:t.metadata.num_attempts}};else throw new Error("Unexpected dequeue result")}}class i{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
27
|
SELECT * FROM ${s(this.schema)}."message_delete"(
|
|
30
28
|
$1,
|
|
31
29
|
$2::BIGINT
|
|
@@ -42,13 +40,12 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
42
40
|
$1,
|
|
43
41
|
$2::BIGINT
|
|
44
42
|
)
|
|
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
|
|
43
|
+
`.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 F=(e)=>{let t=e.split(`
|
|
46
44
|
`),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
|
|
45
|
+
`).trim()};var R=require("path"),__filename="/home/runner/work/lonnymq/lonnymq/src/core/path.ts",ae=R.dirname(R.dirname(__filename)),re=new RegExp(`^${ae}/`),E=(e)=>{return e.replace(re,"")};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/00-table-channel-policy.ts",G={name:E(__filename),sql:(e)=>{return[n`
|
|
48
46
|
CREATE TABLE ${s(e.schema)}."channel_policy" (
|
|
49
47
|
"id" UUID NOT NULL DEFAULT GEN_RANDOM_UUID(),
|
|
50
48
|
"name" TEXT NOT NULL,
|
|
51
|
-
"max_size" INTEGER,
|
|
52
49
|
"max_concurrency" INTEGER,
|
|
53
50
|
"release_interval_ms" INTEGER,
|
|
54
51
|
"created_at" TIMESTAMP NOT NULL,
|
|
@@ -57,11 +54,10 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
57
54
|
`,n`
|
|
58
55
|
CREATE UNIQUE INDEX "channel_policy_name_ux"
|
|
59
56
|
ON ${s(e.schema)}."channel_policy" ("name");
|
|
60
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/01-table-channel-state.ts",
|
|
57
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/01-table-channel-state.ts",x={name:E(__filename),sql:(e)=>{return[n`
|
|
61
58
|
CREATE TABLE ${s(e.schema)}."channel_state" (
|
|
62
59
|
"id" UUID NOT NULL DEFAULT GEN_RANDOM_UUID(),
|
|
63
60
|
"name" TEXT NOT NULL,
|
|
64
|
-
"max_size" INTEGER,
|
|
65
61
|
"max_concurrency" INTEGER,
|
|
66
62
|
"release_interval_ms" INTEGER,
|
|
67
63
|
"current_size" INTEGER NOT NULL,
|
|
@@ -83,12 +79,11 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
83
79
|
"active_next_at" ASC
|
|
84
80
|
) WHERE "message_id" IS NOT NULL
|
|
85
81
|
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency");
|
|
86
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/02-table-message.ts",q={name:
|
|
82
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/02-table-message.ts",q={name:E(__filename),sql:(e)=>{return[n`
|
|
87
83
|
CREATE TABLE ${s(e.schema)}."message" (
|
|
88
84
|
"id" UUID NOT NULL,
|
|
89
85
|
"channel_name" TEXT NOT NULL,
|
|
90
86
|
"seq_no" BIGSERIAL NOT NULL,
|
|
91
|
-
"name" TEXT,
|
|
92
87
|
"content" BYTEA NOT NULL,
|
|
93
88
|
"state" BYTEA,
|
|
94
89
|
"lock_ms" BIGINT NOT NULL,
|
|
@@ -99,12 +94,6 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
99
94
|
"created_at" TIMESTAMP NOT NULL,
|
|
100
95
|
PRIMARY KEY ("id")
|
|
101
96
|
);
|
|
102
|
-
`,n`
|
|
103
|
-
CREATE UNIQUE INDEX "message_name_ux"
|
|
104
|
-
ON ${s(e.schema)}."message" (
|
|
105
|
-
"channel_name",
|
|
106
|
-
"name"
|
|
107
|
-
) WHERE "num_attempts" = 0
|
|
108
97
|
`,n`
|
|
109
98
|
CREATE INDEX "message_dequeue_ix"
|
|
110
99
|
ON ${s(e.schema)}."message" (
|
|
@@ -117,17 +106,14 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
117
106
|
ON ${s(e.schema)}."message" (
|
|
118
107
|
"unlock_at" ASC
|
|
119
108
|
) WHERE "is_locked";
|
|
120
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/03-function-message-create.ts",$={name:
|
|
109
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/03-function-message-create.ts",$={name:E(__filename),sql:(e)=>{return[n`
|
|
121
110
|
CREATE FUNCTION ${s(e.schema)}."message_create" (
|
|
122
111
|
p_id UUID,
|
|
123
112
|
p_channel_name TEXT,
|
|
124
|
-
p_name TEXT,
|
|
125
113
|
p_content BYTEA,
|
|
126
114
|
p_lock_ms BIGINT,
|
|
127
115
|
p_delay_ms BIGINT
|
|
128
|
-
) RETURNS
|
|
129
|
-
result_code INTEGER
|
|
130
|
-
) AS $$
|
|
116
|
+
) RETURNS VOID AS $$
|
|
131
117
|
DECLARE
|
|
132
118
|
v_now TIMESTAMP;
|
|
133
119
|
v_channel_policy RECORD;
|
|
@@ -136,8 +122,31 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
136
122
|
BEGIN
|
|
137
123
|
v_now := NOW();
|
|
138
124
|
|
|
125
|
+
INSERT INTO ${s(e.schema)}."message" (
|
|
126
|
+
"id",
|
|
127
|
+
"channel_name",
|
|
128
|
+
"content",
|
|
129
|
+
"lock_ms",
|
|
130
|
+
"is_locked",
|
|
131
|
+
"num_attempts",
|
|
132
|
+
"dequeue_at",
|
|
133
|
+
"created_at"
|
|
134
|
+
) VALUES (
|
|
135
|
+
p_id,
|
|
136
|
+
p_channel_name,
|
|
137
|
+
p_content,
|
|
138
|
+
p_lock_ms,
|
|
139
|
+
FALSE,
|
|
140
|
+
0,
|
|
141
|
+
v_now + INTERVAL '1 MILLISECOND' * p_delay_ms,
|
|
142
|
+
v_now
|
|
143
|
+
) RETURNING
|
|
144
|
+
"id",
|
|
145
|
+
"seq_no",
|
|
146
|
+
"dequeue_at"
|
|
147
|
+
INTO v_message;
|
|
148
|
+
|
|
139
149
|
SELECT
|
|
140
|
-
"channel_policy"."max_size",
|
|
141
150
|
"channel_policy"."max_concurrency",
|
|
142
151
|
"channel_policy"."release_interval_ms"
|
|
143
152
|
FROM ${s(e.schema)}."channel_policy"
|
|
@@ -147,9 +156,8 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
147
156
|
|
|
148
157
|
INSERT INTO ${s(e.schema)}."channel_state" (
|
|
149
158
|
"name",
|
|
150
|
-
"current_size",
|
|
151
159
|
"current_concurrency",
|
|
152
|
-
"
|
|
160
|
+
"current_size",
|
|
153
161
|
"max_concurrency",
|
|
154
162
|
"release_interval_ms",
|
|
155
163
|
"active_prev_at",
|
|
@@ -158,7 +166,6 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
158
166
|
p_channel_name,
|
|
159
167
|
0,
|
|
160
168
|
0,
|
|
161
|
-
v_channel_policy."max_size",
|
|
162
169
|
v_channel_policy."max_concurrency",
|
|
163
170
|
v_channel_policy."release_interval_ms",
|
|
164
171
|
v_now,
|
|
@@ -167,9 +174,8 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
167
174
|
DO UPDATE SET "name" = EXCLUDED."name"
|
|
168
175
|
RETURNING
|
|
169
176
|
"id",
|
|
170
|
-
"current_size",
|
|
171
177
|
"current_concurrency",
|
|
172
|
-
"
|
|
178
|
+
"current_size",
|
|
173
179
|
"max_concurrency",
|
|
174
180
|
"release_interval_ms",
|
|
175
181
|
"active_prev_at",
|
|
@@ -178,49 +184,6 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
178
184
|
"message_seq_no"
|
|
179
185
|
INTO v_channel_state;
|
|
180
186
|
|
|
181
|
-
IF v_channel_state."current_size" >= v_channel_policy."max_size" THEN
|
|
182
|
-
RETURN QUERY SELECT
|
|
183
|
-
${E(1)};
|
|
184
|
-
RETURN;
|
|
185
|
-
END IF;
|
|
186
|
-
|
|
187
|
-
INSERT INTO ${s(e.schema)}."message" (
|
|
188
|
-
"id",
|
|
189
|
-
"channel_name",
|
|
190
|
-
"name",
|
|
191
|
-
"content",
|
|
192
|
-
"lock_ms",
|
|
193
|
-
"is_locked",
|
|
194
|
-
"num_attempts",
|
|
195
|
-
"dequeue_at",
|
|
196
|
-
"created_at"
|
|
197
|
-
) VALUES (
|
|
198
|
-
p_id,
|
|
199
|
-
p_channel_name,
|
|
200
|
-
p_name,
|
|
201
|
-
p_content,
|
|
202
|
-
p_lock_ms,
|
|
203
|
-
FALSE,
|
|
204
|
-
0,
|
|
205
|
-
v_now + INTERVAL '1 MILLISECOND' * p_delay_ms,
|
|
206
|
-
v_now
|
|
207
|
-
) ON CONFLICT ("channel_name", "name")
|
|
208
|
-
WHERE "num_attempts" = 0
|
|
209
|
-
DO UPDATE SET
|
|
210
|
-
"channel_name" = EXCLUDED."channel_name",
|
|
211
|
-
"name" = EXCLUDED."name"
|
|
212
|
-
RETURNING
|
|
213
|
-
"id",
|
|
214
|
-
"seq_no",
|
|
215
|
-
"dequeue_at"
|
|
216
|
-
INTO v_message;
|
|
217
|
-
|
|
218
|
-
IF v_message."id" != p_id THEN
|
|
219
|
-
RETURN QUERY SELECT
|
|
220
|
-
${E(2)};
|
|
221
|
-
RETURN;
|
|
222
|
-
END IF;
|
|
223
|
-
|
|
224
187
|
IF
|
|
225
188
|
v_channel_state."message_id" IS NULL OR
|
|
226
189
|
v_message."dequeue_at" < v_channel_state."message_dequeue_at" OR
|
|
@@ -242,26 +205,21 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
242
205
|
WHERE "id" = v_channel_state."id";
|
|
243
206
|
END IF;
|
|
244
207
|
|
|
245
|
-
IF ${
|
|
208
|
+
IF ${_(e.eventChannel!==null)} THEN
|
|
246
209
|
PERFORM PG_NOTIFY(
|
|
247
|
-
${
|
|
210
|
+
${_(e.eventChannel)},
|
|
248
211
|
JSON_BUILD_OBJECT(
|
|
249
|
-
'type', ${
|
|
212
|
+
'type', ${_(0)},
|
|
250
213
|
'id', p_id,
|
|
251
214
|
'delay_ms', p_delay_ms
|
|
252
215
|
)::TEXT
|
|
253
216
|
);
|
|
254
217
|
END IF;
|
|
255
|
-
|
|
256
|
-
RETURN QUERY SELECT
|
|
257
|
-
${E(0)};
|
|
258
|
-
RETURN;
|
|
259
218
|
END;
|
|
260
219
|
$$ LANGUAGE plpgsql;
|
|
261
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/04-function-message-dequeue.ts",
|
|
220
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/04-function-message-dequeue.ts",_e=(e)=>n`
|
|
262
221
|
SELECT
|
|
263
222
|
"message"."id",
|
|
264
|
-
"message"."name",
|
|
265
223
|
"message"."state",
|
|
266
224
|
"message"."content",
|
|
267
225
|
"message"."channel_name",
|
|
@@ -272,7 +230,7 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
272
230
|
WHERE "is_locked"
|
|
273
231
|
AND "unlock_at" <= ${e.now}
|
|
274
232
|
ORDER BY "unlock_at" ASC
|
|
275
|
-
`,
|
|
233
|
+
`,Ee=(e)=>n`
|
|
276
234
|
SELECT
|
|
277
235
|
"channel_state"."id",
|
|
278
236
|
"channel_state"."name",
|
|
@@ -294,7 +252,7 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
294
252
|
WHERE NOT "is_locked"
|
|
295
253
|
AND "channel_name" = ${e.channelName}
|
|
296
254
|
ORDER BY "dequeue_at" ASC, "seq_no" ASC
|
|
297
|
-
`,b={name:
|
|
255
|
+
`,b={name:E(__filename),sql:(e)=>{let t=_e({now:n`v_now`,schema:e.schema}),a=oe({channelName:n`v_channel_state."name"`,schema:e.schema}),r=Ee({schema:e.schema});return[n`
|
|
298
256
|
CREATE FUNCTION ${s(e.schema)}."message_dequeue" ()
|
|
299
257
|
RETURNS TABLE (
|
|
300
258
|
result_code INTEGER,
|
|
@@ -324,14 +282,13 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
324
282
|
WHERE "id" = v_message_locked."id";
|
|
325
283
|
|
|
326
284
|
RETURN QUERY SELECT
|
|
327
|
-
${
|
|
285
|
+
${_(1)},
|
|
328
286
|
v_message_locked.content,
|
|
329
287
|
v_message_locked.state,
|
|
330
288
|
JSON_BUILD_OBJECT(
|
|
331
289
|
'id', v_message_locked.id,
|
|
332
290
|
'is_unlocked', TRUE,
|
|
333
291
|
'channel_name', v_message_locked.channel_name,
|
|
334
|
-
'name', v_message_locked.name,
|
|
335
292
|
'num_attempts', v_message_locked.num_attempts + 1
|
|
336
293
|
);
|
|
337
294
|
RETURN;
|
|
@@ -345,7 +302,7 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
345
302
|
|
|
346
303
|
IF v_channel_state."id" IS NULL THEN
|
|
347
304
|
RETURN QUERY SELECT
|
|
348
|
-
${
|
|
305
|
+
${_(0)},
|
|
349
306
|
NULL::BYTEA,
|
|
350
307
|
NULL::BYTEA,
|
|
351
308
|
JSON_BUILD_OBJECT('retry_ms', NULL);
|
|
@@ -354,7 +311,7 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
354
311
|
|
|
355
312
|
IF v_channel_state."active_next_at" > v_now THEN
|
|
356
313
|
RETURN QUERY SELECT
|
|
357
|
-
${
|
|
314
|
+
${_(0)},
|
|
358
315
|
NULL::BYTEA,
|
|
359
316
|
NULL::BYTEA,
|
|
360
317
|
JSON_BUILD_OBJECT(
|
|
@@ -365,7 +322,6 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
365
322
|
|
|
366
323
|
SELECT
|
|
367
324
|
"message"."id",
|
|
368
|
-
"message"."name",
|
|
369
325
|
"message"."channel_name",
|
|
370
326
|
"message"."content",
|
|
371
327
|
"message"."num_attempts",
|
|
@@ -406,20 +362,19 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
406
362
|
END IF;
|
|
407
363
|
|
|
408
364
|
RETURN QUERY SELECT
|
|
409
|
-
${
|
|
365
|
+
${_(1)},
|
|
410
366
|
v_message_dequeue.content,
|
|
411
367
|
v_message_dequeue.state,
|
|
412
368
|
JSON_BUILD_OBJECT(
|
|
413
369
|
'id', v_message_dequeue.id,
|
|
414
370
|
'is_unlocked', FALSE,
|
|
415
371
|
'channel_name', v_message_dequeue.channel_name,
|
|
416
|
-
'name', v_message_dequeue.name,
|
|
417
372
|
'num_attempts', v_message_dequeue.num_attempts + 1
|
|
418
373
|
);
|
|
419
374
|
RETURN;
|
|
420
375
|
END;
|
|
421
376
|
$$ LANGUAGE plpgsql;
|
|
422
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/05-function-message-delete.ts",B={name:
|
|
377
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/05-function-message-delete.ts",B={name:E(__filename),sql:(e)=>{return[n`
|
|
423
378
|
CREATE FUNCTION ${s(e.schema)}."message_delete" (
|
|
424
379
|
p_id UUID,
|
|
425
380
|
p_num_attempts BIGINT
|
|
@@ -444,11 +399,11 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
444
399
|
|
|
445
400
|
IF v_message."id" IS NULL THEN
|
|
446
401
|
RETURN QUERY SELECT
|
|
447
|
-
${
|
|
402
|
+
${_(0)};
|
|
448
403
|
RETURN;
|
|
449
404
|
ELSIF NOT v_message."is_locked" OR v_message."num_attempts" <> p_num_attempts THEN
|
|
450
405
|
RETURN QUERY SELECT
|
|
451
|
-
${
|
|
406
|
+
${_(1)};
|
|
452
407
|
RETURN;
|
|
453
408
|
END IF;
|
|
454
409
|
|
|
@@ -478,11 +433,11 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
478
433
|
WHERE "id" = v_channel_state."id";
|
|
479
434
|
END IF;
|
|
480
435
|
|
|
481
|
-
IF ${
|
|
436
|
+
IF ${_(e.eventChannel!==null)} THEN
|
|
482
437
|
PERFORM PG_NOTIFY(
|
|
483
|
-
${
|
|
438
|
+
${_(e.eventChannel)},
|
|
484
439
|
JSON_BUILD_OBJECT(
|
|
485
|
-
'type', ${
|
|
440
|
+
'type', ${_(1)},
|
|
486
441
|
'id', p_id
|
|
487
442
|
)::TEXT
|
|
488
443
|
);
|
|
@@ -492,11 +447,11 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
492
447
|
WHERE "id" = p_id;
|
|
493
448
|
|
|
494
449
|
RETURN QUERY SELECT
|
|
495
|
-
${
|
|
450
|
+
${_(2)};
|
|
496
451
|
RETURN;
|
|
497
452
|
END;
|
|
498
453
|
$$ LANGUAGE plpgsql;
|
|
499
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/06-function-message-defer.ts",P={name:
|
|
454
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/06-function-message-defer.ts",P={name:E(__filename),sql:(e)=>{return[n`
|
|
500
455
|
CREATE FUNCTION ${s(e.schema)}."message_defer" (
|
|
501
456
|
p_id UUID,
|
|
502
457
|
p_num_attempts BIGINT,
|
|
@@ -527,11 +482,11 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
527
482
|
|
|
528
483
|
IF v_message."id" IS NULL THEN
|
|
529
484
|
RETURN QUERY SELECT
|
|
530
|
-
${
|
|
485
|
+
${_(0)};
|
|
531
486
|
RETURN;
|
|
532
487
|
ELSIF NOT v_message."is_locked" OR v_message."num_attempts" <> p_num_attempts THEN
|
|
533
488
|
RETURN QUERY SELECT
|
|
534
|
-
${
|
|
489
|
+
${_(1)};
|
|
535
490
|
RETURN;
|
|
536
491
|
END IF;
|
|
537
492
|
|
|
@@ -576,11 +531,11 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
576
531
|
"dequeue_at" = v_dequeue_at
|
|
577
532
|
WHERE "id" = p_id;
|
|
578
533
|
|
|
579
|
-
IF ${
|
|
534
|
+
IF ${_(e.eventChannel!==null)} THEN
|
|
580
535
|
PERFORM PG_NOTIFY(
|
|
581
|
-
${
|
|
536
|
+
${_(e.eventChannel)},
|
|
582
537
|
JSON_BUILD_OBJECT(
|
|
583
|
-
'type', ${
|
|
538
|
+
'type', ${_(2)},
|
|
584
539
|
'delay_ms', p_delay_ms,
|
|
585
540
|
'id', p_id
|
|
586
541
|
)::TEXT
|
|
@@ -588,11 +543,11 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
588
543
|
END IF;
|
|
589
544
|
|
|
590
545
|
RETURN QUERY SELECT
|
|
591
|
-
${
|
|
546
|
+
${_(2)};
|
|
592
547
|
RETURN;
|
|
593
548
|
END;
|
|
594
549
|
$$ LANGUAGE plpgsql;
|
|
595
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/07-function-message-heartbeat.ts",
|
|
550
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/07-function-message-heartbeat.ts",w={name:E(__filename),sql:(e)=>{return[n`
|
|
596
551
|
CREATE FUNCTION ${s(e.schema)}."message_heartbeat" (
|
|
597
552
|
p_id UUID,
|
|
598
553
|
p_num_attempts BIGINT
|
|
@@ -618,11 +573,11 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
618
573
|
|
|
619
574
|
IF v_message."id" IS NULL THEN
|
|
620
575
|
RETURN QUERY SELECT
|
|
621
|
-
${
|
|
576
|
+
${_(0)};
|
|
622
577
|
RETURN;
|
|
623
578
|
ELSIF NOT v_message."is_locked" OR v_message."num_attempts" <> p_num_attempts THEN
|
|
624
579
|
RETURN QUERY SELECT
|
|
625
|
-
${
|
|
580
|
+
${_(1)};
|
|
626
581
|
RETURN;
|
|
627
582
|
END IF;
|
|
628
583
|
|
|
@@ -631,11 +586,11 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
631
586
|
WHERE "id" = p_id;
|
|
632
587
|
|
|
633
588
|
RETURN QUERY SELECT
|
|
634
|
-
${
|
|
589
|
+
${_(2)};
|
|
635
590
|
RETURN;
|
|
636
591
|
END;
|
|
637
592
|
$$ LANGUAGE plpgsql;
|
|
638
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/08-function-channel-policy-clear.ts",
|
|
593
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/08-function-channel-policy-clear.ts",H={name:E(__filename),sql:(e)=>{return[n`
|
|
639
594
|
CREATE FUNCTION ${s(e.schema)}."channel_policy_clear" (
|
|
640
595
|
p_name TEXT
|
|
641
596
|
) RETURNS VOID AS $$
|
|
@@ -658,17 +613,15 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
658
613
|
WHERE "id" = v_channel_state."id";
|
|
659
614
|
ELSE
|
|
660
615
|
UPDATE ${s(e.schema)}."channel_state" SET
|
|
661
|
-
"max_size" = NULL,
|
|
662
616
|
"max_concurrency" = NULL,
|
|
663
617
|
"release_interval_ms" = NULL
|
|
664
618
|
WHERE "name" = p_name;
|
|
665
619
|
END IF;
|
|
666
620
|
END;
|
|
667
621
|
$$ LANGUAGE plpgsql;
|
|
668
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/09-function-channel-policy-set.ts",
|
|
622
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/09-function-channel-policy-set.ts",k={name:E(__filename),sql:(e)=>{return[n`
|
|
669
623
|
CREATE FUNCTION ${s(e.schema)}."channel_policy_set" (
|
|
670
624
|
p_name TEXT,
|
|
671
|
-
p_max_size INTEGER,
|
|
672
625
|
p_max_concurrency INTEGER,
|
|
673
626
|
p_release_interval_ms INTEGER
|
|
674
627
|
) RETURNS VOID AS $$
|
|
@@ -679,26 +632,22 @@ var{defineProperty:N,getOwnPropertyNames:V,getOwnPropertyDescriptor:z}=Object,W=
|
|
|
679
632
|
|
|
680
633
|
INSERT INTO ${s(e.schema)}."channel_policy" (
|
|
681
634
|
"name",
|
|
682
|
-
"max_size",
|
|
683
635
|
"max_concurrency",
|
|
684
636
|
"release_interval_ms",
|
|
685
637
|
"created_at"
|
|
686
638
|
) VALUES (
|
|
687
639
|
p_name,
|
|
688
|
-
p_max_size,
|
|
689
640
|
p_max_concurrency,
|
|
690
641
|
p_release_interval_ms,
|
|
691
642
|
v_now
|
|
692
643
|
) ON CONFLICT ("name") DO UPDATE SET
|
|
693
|
-
"max_size" = EXCLUDED."max_size",
|
|
694
644
|
"max_concurrency" = EXCLUDED."max_concurrency",
|
|
695
645
|
"release_interval_ms" = EXCLUDED."release_interval_ms";
|
|
696
646
|
|
|
697
647
|
UPDATE ${s(e.schema)}."channel_state" SET
|
|
698
|
-
"max_size" = p_max_size,
|
|
699
648
|
"max_concurrency" = p_max_concurrency,
|
|
700
649
|
"release_interval_ms" = p_release_interval_ms
|
|
701
650
|
WHERE "name" = p_name;
|
|
702
651
|
END;
|
|
703
652
|
$$ LANGUAGE plpgsql;
|
|
704
|
-
`]}};class S{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}create(e){let t=new
|
|
653
|
+
`]}};class S{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}create(e){let t=new l({schema:this.schema,channelName:this.channelName,content:e.content,lockMs:e.lockMs,delayMs:e.delayMs}),a=new Promise((r)=>{this.registerFn({sortKey:JSON.stringify([t.channelName,t.createdAt.toISOString()]),execute:(h)=>t.execute(h).then(()=>r())})});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 c({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,releaseIntervalMs:e.releaseIntervalMs});this.registerFn({sortKey:JSON.stringify([t.channelName,t.createdAt.toISOString()]),execute:async(a)=>{await t.execute(a)}})}clear(){let e=new o({schema:this.schema,channelName:this.channelName});this.registerFn({sortKey:JSON.stringify([e.channelName,e.createdAt.toISOString()]),execute:async(t)=>{await e.execute(t)}})}}class p{policy;message;constructor(e){this.message=new S(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}create(e){let t=this.adaptor(e.databaseClient);return new l({schema:this.schema,channelName:this.channelName,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 c({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 v{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;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}).execute(t)}}class L{schema;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor?e.adaptor:(t)=>t}async dequeue(e){let t=new m({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,isUnlocked:r.message.isUnlocked,content:r.message.content,state:r.message.state,numAttempts:r.message.numAttempts})};else return r}channel(e){return new v({adaptor:this.adaptor,schema:this.schema,channelName:e})}batch(){return new D({schema:this.schema,adaptor:this.adaptor})}migrations(e={}){return[G,x,q,$,b,B,P,w,k,H].sort((t,a)=>t.name.localeCompare(a.name)).flatMap((t)=>t.sql({schema:this.schema,eventChannel:e.eventChannel??null})).map((t)=>F(t.value))}}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,27 @@ export interface DatabaseClient {
|
|
|
7
7
|
query(query: string, params: Array<unknown>): Promise<DatabaseClientQueryResult>;
|
|
8
8
|
}
|
|
9
9
|
export type DatabaseClientAdaptor<T> = (client: T) => DatabaseClient;
|
|
10
|
+
export type QueueEventMessageCreate = {
|
|
11
|
+
eventType: "MESSAGE_CREATED";
|
|
12
|
+
id: string;
|
|
13
|
+
delayMs: number;
|
|
14
|
+
};
|
|
15
|
+
export type QueueEventMessageDequeued = {
|
|
16
|
+
eventType: "MESSAGE_DEQUEUED";
|
|
17
|
+
id: string;
|
|
18
|
+
lockMs: number;
|
|
19
|
+
};
|
|
20
|
+
export type QueueEventMessageDeleted = {
|
|
21
|
+
eventType: "MESSAGE_DELETED";
|
|
22
|
+
id: string;
|
|
23
|
+
};
|
|
24
|
+
export type QueueEventMessageDeferred = {
|
|
25
|
+
eventType: "MESSAGE_DEFERRED";
|
|
26
|
+
id: string;
|
|
27
|
+
delayMs: number;
|
|
28
|
+
};
|
|
29
|
+
export type QueueEvent = QueueEventMessageCreate | QueueEventMessageDeleted | QueueEventMessageDeferred;
|
|
30
|
+
export declare const queueEventDecode: (payload: string) => QueueEvent;
|
|
10
31
|
export declare class ChannelPolicyClearCommand {
|
|
11
32
|
private readonly schema;
|
|
12
33
|
readonly channelName: string;
|
|
@@ -20,54 +41,20 @@ export declare class ChannelPolicyClearCommand {
|
|
|
20
41
|
export declare class ChannelPolicySetCommand {
|
|
21
42
|
private readonly schema;
|
|
22
43
|
readonly channelName: string;
|
|
23
|
-
readonly maxSize: number | null;
|
|
24
44
|
readonly maxConcurrency: number | null;
|
|
25
45
|
readonly releaseIntervalMs: number | null;
|
|
26
46
|
readonly createdAt: Date;
|
|
27
47
|
constructor(params: {
|
|
28
48
|
schema: string;
|
|
29
49
|
channelName: string;
|
|
30
|
-
maxSize?: number | null;
|
|
31
50
|
maxConcurrency?: number | null;
|
|
32
51
|
releaseIntervalMs?: number | null;
|
|
33
52
|
});
|
|
34
53
|
execute(databaseClient: DatabaseClient): Promise<void>;
|
|
35
54
|
}
|
|
36
|
-
export type QueueEventMessageCreate = {
|
|
37
|
-
eventType: "MESSAGE_CREATED";
|
|
38
|
-
id: string;
|
|
39
|
-
delayMs: number;
|
|
40
|
-
};
|
|
41
|
-
export type QueueEventMessageDequeued = {
|
|
42
|
-
eventType: "MESSAGE_DEQUEUED";
|
|
43
|
-
id: string;
|
|
44
|
-
lockMs: number;
|
|
45
|
-
};
|
|
46
|
-
export type QueueEventMessageDeleted = {
|
|
47
|
-
eventType: "MESSAGE_DELETED";
|
|
48
|
-
id: string;
|
|
49
|
-
};
|
|
50
|
-
export type QueueEventMessageDeferred = {
|
|
51
|
-
eventType: "MESSAGE_DEFERRED";
|
|
52
|
-
id: string;
|
|
53
|
-
delayMs: number;
|
|
54
|
-
};
|
|
55
|
-
export type QueueEvent = QueueEventMessageCreate | QueueEventMessageDeleted | QueueEventMessageDeferred;
|
|
56
|
-
export declare const queueEventDecode: (payload: string) => QueueEvent;
|
|
57
|
-
export type MessageCreateCommandResultMessageCreated = {
|
|
58
|
-
resultType: "MESSAGE_CREATED";
|
|
59
|
-
};
|
|
60
|
-
export type MessageCreateCommandResultMessageDeduplicated = {
|
|
61
|
-
resultType: "MESSAGE_DEDUPLICATED";
|
|
62
|
-
};
|
|
63
|
-
export type MessageCreateCommandResultMessageDropped = {
|
|
64
|
-
resultType: "MESSAGE_DROPPED";
|
|
65
|
-
};
|
|
66
|
-
export type MessageCreateCommandResult = MessageCreateCommandResultMessageCreated | MessageCreateCommandResultMessageDeduplicated | MessageCreateCommandResultMessageDropped;
|
|
67
55
|
export declare class MessageCreateCommand {
|
|
68
56
|
private readonly schema;
|
|
69
57
|
readonly channelName: string;
|
|
70
|
-
readonly name: string | null;
|
|
71
58
|
readonly content: Buffer;
|
|
72
59
|
readonly lockMs: number;
|
|
73
60
|
readonly id: string;
|
|
@@ -76,12 +63,11 @@ export declare class MessageCreateCommand {
|
|
|
76
63
|
constructor(params: {
|
|
77
64
|
schema: string;
|
|
78
65
|
channelName: string;
|
|
79
|
-
name?: string;
|
|
80
66
|
content: Buffer;
|
|
81
67
|
lockMs: number;
|
|
82
68
|
delayMs?: number;
|
|
83
69
|
});
|
|
84
|
-
execute(databaseClient: DatabaseClient): Promise<
|
|
70
|
+
execute(databaseClient: DatabaseClient): Promise<void>;
|
|
85
71
|
}
|
|
86
72
|
export type MessageDequeueCommandResultMessageDequeued = {
|
|
87
73
|
resultType: "MESSAGE_DEQUEUED";
|
|
@@ -89,7 +75,6 @@ export type MessageDequeueCommandResultMessageDequeued = {
|
|
|
89
75
|
id: string;
|
|
90
76
|
channelName: string;
|
|
91
77
|
isUnlocked: boolean;
|
|
92
|
-
name: string | null;
|
|
93
78
|
content: Buffer;
|
|
94
79
|
state: Buffer | null;
|
|
95
80
|
numAttempts: number;
|
|
@@ -176,7 +161,7 @@ export declare class MessageHeartbeatCommand {
|
|
|
176
161
|
}
|
|
177
162
|
export type QueueBatchChannelMessageCreateResult = {
|
|
178
163
|
messageId: string;
|
|
179
|
-
promise: Promise<
|
|
164
|
+
promise: Promise<void>;
|
|
180
165
|
};
|
|
181
166
|
export declare class QueueBatchChannelMessage {
|
|
182
167
|
private readonly schema;
|
|
@@ -205,7 +190,6 @@ export declare class QueueBatchChannelPolicy {
|
|
|
205
190
|
});
|
|
206
191
|
set(params: {
|
|
207
192
|
maxConcurrency?: number | null;
|
|
208
|
-
maxSize?: number | null;
|
|
209
193
|
releaseIntervalMs?: number | null;
|
|
210
194
|
}): void;
|
|
211
195
|
clear(): void;
|
|
@@ -252,7 +236,7 @@ export declare class QueueChannelMessage<T> {
|
|
|
252
236
|
lockMs: number;
|
|
253
237
|
content: Buffer;
|
|
254
238
|
delayMs?: number;
|
|
255
|
-
}): Promise<
|
|
239
|
+
}): Promise<void>;
|
|
256
240
|
}
|
|
257
241
|
export declare class QueueChannelPolicy<T> {
|
|
258
242
|
private readonly schema;
|
|
@@ -266,7 +250,6 @@ export declare class QueueChannelPolicy<T> {
|
|
|
266
250
|
set(params: {
|
|
267
251
|
databaseClient: T;
|
|
268
252
|
maxConcurrency?: number | null;
|
|
269
|
-
maxSize?: number | null;
|
|
270
253
|
releaseIntervalMs?: number | null;
|
|
271
254
|
}): Promise<void>;
|
|
272
255
|
clear(params: {
|
|
@@ -288,7 +271,6 @@ export declare class QueueMessage<T> {
|
|
|
288
271
|
readonly id: string;
|
|
289
272
|
readonly isUnlocked: boolean;
|
|
290
273
|
readonly channelName: string;
|
|
291
|
-
readonly name: string | null;
|
|
292
274
|
readonly content: Buffer;
|
|
293
275
|
readonly state: Buffer | null;
|
|
294
276
|
readonly numAttempts: number;
|
|
@@ -298,7 +280,6 @@ export declare class QueueMessage<T> {
|
|
|
298
280
|
id: string;
|
|
299
281
|
channelName: string;
|
|
300
282
|
isUnlocked: boolean;
|
|
301
|
-
name: string | null;
|
|
302
283
|
content: Buffer;
|
|
303
284
|
state: Buffer | null;
|
|
304
285
|
numAttempts: number;
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,34 @@
|
|
|
1
|
-
var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),
|
|
1
|
+
var v=(e)=>{return e*1000};var m=v(0);var P=(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}),w=(e)=>({nodeType:"RAW",value:e}),H=(e)=>{return`'${e.replace(/'/g,"''")}'`},k=(e)=>{if(e===null)return"NULL";else if(typeof e==="string")return H(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}`)},Q=(e)=>{return`"${e.replace(/"/g,'""')}"`},V=(e)=>{if(e.nodeType==="VALUE")return k(e.value);else if(e.nodeType==="REF")return Q(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 _=0;_<e.length;_+=1)if(a.push(e[_]),_<t.length)a.push(V(t[_]));return w(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
|
)
|
|
5
|
-
`.value,[this.channelName])}}class
|
|
5
|
+
`.value,[this.channelName])}}class c{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
|
-
$3::INTEGER
|
|
10
|
-
$4::INTEGER
|
|
9
|
+
$3::INTEGER
|
|
11
10
|
)
|
|
12
|
-
`.value,[this.channelName,this.
|
|
13
|
-
SELECT
|
|
11
|
+
`.value,[this.channelName,this.maxConcurrency,this.releaseIntervalMs])}}import{randomUUID as W}from"node:crypto";class l{schema;channelName;content;lockMs;id;delayMs;createdAt;constructor(e){let t=Math.max(0,e.lockMs),a=e.delayMs===void 0?m:e.delayMs;this.id=W(),this.schema=e.schema,this.channelName=e.channelName,this.content=e.content,this.lockMs=t,this.delayMs=a,this.createdAt=new Date}async execute(e){await e.query(n`
|
|
12
|
+
SELECT 1 FROM ${s(this.schema)}."message_create"(
|
|
14
13
|
$1,
|
|
15
14
|
$2,
|
|
16
|
-
$3,
|
|
17
|
-
$4,
|
|
18
|
-
$5::BIGINT
|
|
19
|
-
$6::BIGINT
|
|
15
|
+
$3,
|
|
16
|
+
$4::BIGINT,
|
|
17
|
+
$5::BIGINT
|
|
20
18
|
)
|
|
21
|
-
`.value,[this.id,this.channelName,this.
|
|
19
|
+
`.value,[this.id,this.channelName,this.content,this.lockMs,this.delayMs])}}class i{schema;constructor(e){this.schema=e.schema}async execute(e){let t=await e.query(n`
|
|
22
20
|
SELECT
|
|
23
21
|
result_code,
|
|
24
22
|
metadata,
|
|
25
23
|
content,
|
|
26
24
|
state
|
|
27
25
|
FROM ${s(this.schema)}."message_dequeue"()
|
|
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,
|
|
26
|
+
`.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,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
27
|
SELECT * FROM ${s(this.schema)}."message_delete"(
|
|
30
28
|
$1,
|
|
31
29
|
$2::BIGINT
|
|
32
30
|
)
|
|
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 d{schema;id;numAttempts;delayMs;state;constructor(e){let t=e.delayMs===void 0?
|
|
31
|
+
`.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?m: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
32
|
SELECT * FROM ${s(this.schema)}."message_defer"(
|
|
35
33
|
$1,
|
|
36
34
|
$2::BIGINT,
|
|
@@ -43,12 +41,11 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
43
41
|
$2::BIGINT
|
|
44
42
|
)
|
|
45
43
|
`.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
|
|
47
|
-
`).trim()};import{dirname as
|
|
44
|
+
`),a=Number.MAX_SAFE_INTEGER;for(let _ of t){if(_.trim().length===0)continue;let h=_.search(/\S/);a=Math.min(a,h)}return t.map((_)=>_.slice(a)).join(`
|
|
45
|
+
`).trim()};import{dirname as L}from"path";var __filename="/home/runner/work/lonnymq/lonnymq/src/core/path.ts",K=L(L(__filename)),j=new RegExp(`^${K}/`),E=(e)=>{return e.replace(j,"")};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/00-table-channel-policy.ts",C={name:E(__filename),sql:(e)=>{return[n`
|
|
48
46
|
CREATE TABLE ${s(e.schema)}."channel_policy" (
|
|
49
47
|
"id" UUID NOT NULL DEFAULT GEN_RANDOM_UUID(),
|
|
50
48
|
"name" TEXT NOT NULL,
|
|
51
|
-
"max_size" INTEGER,
|
|
52
49
|
"max_concurrency" INTEGER,
|
|
53
50
|
"release_interval_ms" INTEGER,
|
|
54
51
|
"created_at" TIMESTAMP NOT NULL,
|
|
@@ -57,11 +54,10 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
57
54
|
`,n`
|
|
58
55
|
CREATE UNIQUE INDEX "channel_policy_name_ux"
|
|
59
56
|
ON ${s(e.schema)}."channel_policy" ("name");
|
|
60
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/01-table-channel-state.ts",U={name:
|
|
57
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/01-table-channel-state.ts",U={name:E(__filename),sql:(e)=>{return[n`
|
|
61
58
|
CREATE TABLE ${s(e.schema)}."channel_state" (
|
|
62
59
|
"id" UUID NOT NULL DEFAULT GEN_RANDOM_UUID(),
|
|
63
60
|
"name" TEXT NOT NULL,
|
|
64
|
-
"max_size" INTEGER,
|
|
65
61
|
"max_concurrency" INTEGER,
|
|
66
62
|
"release_interval_ms" INTEGER,
|
|
67
63
|
"current_size" INTEGER NOT NULL,
|
|
@@ -83,12 +79,11 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
83
79
|
"active_next_at" ASC
|
|
84
80
|
) WHERE "message_id" IS NOT NULL
|
|
85
81
|
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency");
|
|
86
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/02-table-message.ts",O={name:
|
|
82
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/02-table-message.ts",O={name:E(__filename),sql:(e)=>{return[n`
|
|
87
83
|
CREATE TABLE ${s(e.schema)}."message" (
|
|
88
84
|
"id" UUID NOT NULL,
|
|
89
85
|
"channel_name" TEXT NOT NULL,
|
|
90
86
|
"seq_no" BIGSERIAL NOT NULL,
|
|
91
|
-
"name" TEXT,
|
|
92
87
|
"content" BYTEA NOT NULL,
|
|
93
88
|
"state" BYTEA,
|
|
94
89
|
"lock_ms" BIGINT NOT NULL,
|
|
@@ -99,12 +94,6 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
99
94
|
"created_at" TIMESTAMP NOT NULL,
|
|
100
95
|
PRIMARY KEY ("id")
|
|
101
96
|
);
|
|
102
|
-
`,n`
|
|
103
|
-
CREATE UNIQUE INDEX "message_name_ux"
|
|
104
|
-
ON ${s(e.schema)}."message" (
|
|
105
|
-
"channel_name",
|
|
106
|
-
"name"
|
|
107
|
-
) WHERE "num_attempts" = 0
|
|
108
97
|
`,n`
|
|
109
98
|
CREATE INDEX "message_dequeue_ix"
|
|
110
99
|
ON ${s(e.schema)}."message" (
|
|
@@ -117,17 +106,14 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
117
106
|
ON ${s(e.schema)}."message" (
|
|
118
107
|
"unlock_at" ASC
|
|
119
108
|
) WHERE "is_locked";
|
|
120
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/03-function-message-create.ts",f={name:
|
|
109
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/03-function-message-create.ts",f={name:E(__filename),sql:(e)=>{return[n`
|
|
121
110
|
CREATE FUNCTION ${s(e.schema)}."message_create" (
|
|
122
111
|
p_id UUID,
|
|
123
112
|
p_channel_name TEXT,
|
|
124
|
-
p_name TEXT,
|
|
125
113
|
p_content BYTEA,
|
|
126
114
|
p_lock_ms BIGINT,
|
|
127
115
|
p_delay_ms BIGINT
|
|
128
|
-
) RETURNS
|
|
129
|
-
result_code INTEGER
|
|
130
|
-
) AS $$
|
|
116
|
+
) RETURNS VOID AS $$
|
|
131
117
|
DECLARE
|
|
132
118
|
v_now TIMESTAMP;
|
|
133
119
|
v_channel_policy RECORD;
|
|
@@ -136,8 +122,31 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
136
122
|
BEGIN
|
|
137
123
|
v_now := NOW();
|
|
138
124
|
|
|
125
|
+
INSERT INTO ${s(e.schema)}."message" (
|
|
126
|
+
"id",
|
|
127
|
+
"channel_name",
|
|
128
|
+
"content",
|
|
129
|
+
"lock_ms",
|
|
130
|
+
"is_locked",
|
|
131
|
+
"num_attempts",
|
|
132
|
+
"dequeue_at",
|
|
133
|
+
"created_at"
|
|
134
|
+
) VALUES (
|
|
135
|
+
p_id,
|
|
136
|
+
p_channel_name,
|
|
137
|
+
p_content,
|
|
138
|
+
p_lock_ms,
|
|
139
|
+
FALSE,
|
|
140
|
+
0,
|
|
141
|
+
v_now + INTERVAL '1 MILLISECOND' * p_delay_ms,
|
|
142
|
+
v_now
|
|
143
|
+
) RETURNING
|
|
144
|
+
"id",
|
|
145
|
+
"seq_no",
|
|
146
|
+
"dequeue_at"
|
|
147
|
+
INTO v_message;
|
|
148
|
+
|
|
139
149
|
SELECT
|
|
140
|
-
"channel_policy"."max_size",
|
|
141
150
|
"channel_policy"."max_concurrency",
|
|
142
151
|
"channel_policy"."release_interval_ms"
|
|
143
152
|
FROM ${s(e.schema)}."channel_policy"
|
|
@@ -147,9 +156,8 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
147
156
|
|
|
148
157
|
INSERT INTO ${s(e.schema)}."channel_state" (
|
|
149
158
|
"name",
|
|
150
|
-
"current_size",
|
|
151
159
|
"current_concurrency",
|
|
152
|
-
"
|
|
160
|
+
"current_size",
|
|
153
161
|
"max_concurrency",
|
|
154
162
|
"release_interval_ms",
|
|
155
163
|
"active_prev_at",
|
|
@@ -158,7 +166,6 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
158
166
|
p_channel_name,
|
|
159
167
|
0,
|
|
160
168
|
0,
|
|
161
|
-
v_channel_policy."max_size",
|
|
162
169
|
v_channel_policy."max_concurrency",
|
|
163
170
|
v_channel_policy."release_interval_ms",
|
|
164
171
|
v_now,
|
|
@@ -167,9 +174,8 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
167
174
|
DO UPDATE SET "name" = EXCLUDED."name"
|
|
168
175
|
RETURNING
|
|
169
176
|
"id",
|
|
170
|
-
"current_size",
|
|
171
177
|
"current_concurrency",
|
|
172
|
-
"
|
|
178
|
+
"current_size",
|
|
173
179
|
"max_concurrency",
|
|
174
180
|
"release_interval_ms",
|
|
175
181
|
"active_prev_at",
|
|
@@ -178,49 +184,6 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
178
184
|
"message_seq_no"
|
|
179
185
|
INTO v_channel_state;
|
|
180
186
|
|
|
181
|
-
IF v_channel_state."current_size" >= v_channel_policy."max_size" THEN
|
|
182
|
-
RETURN QUERY SELECT
|
|
183
|
-
${r(1)};
|
|
184
|
-
RETURN;
|
|
185
|
-
END IF;
|
|
186
|
-
|
|
187
|
-
INSERT INTO ${s(e.schema)}."message" (
|
|
188
|
-
"id",
|
|
189
|
-
"channel_name",
|
|
190
|
-
"name",
|
|
191
|
-
"content",
|
|
192
|
-
"lock_ms",
|
|
193
|
-
"is_locked",
|
|
194
|
-
"num_attempts",
|
|
195
|
-
"dequeue_at",
|
|
196
|
-
"created_at"
|
|
197
|
-
) VALUES (
|
|
198
|
-
p_id,
|
|
199
|
-
p_channel_name,
|
|
200
|
-
p_name,
|
|
201
|
-
p_content,
|
|
202
|
-
p_lock_ms,
|
|
203
|
-
FALSE,
|
|
204
|
-
0,
|
|
205
|
-
v_now + INTERVAL '1 MILLISECOND' * p_delay_ms,
|
|
206
|
-
v_now
|
|
207
|
-
) ON CONFLICT ("channel_name", "name")
|
|
208
|
-
WHERE "num_attempts" = 0
|
|
209
|
-
DO UPDATE SET
|
|
210
|
-
"channel_name" = EXCLUDED."channel_name",
|
|
211
|
-
"name" = EXCLUDED."name"
|
|
212
|
-
RETURNING
|
|
213
|
-
"id",
|
|
214
|
-
"seq_no",
|
|
215
|
-
"dequeue_at"
|
|
216
|
-
INTO v_message;
|
|
217
|
-
|
|
218
|
-
IF v_message."id" != p_id THEN
|
|
219
|
-
RETURN QUERY SELECT
|
|
220
|
-
${r(2)};
|
|
221
|
-
RETURN;
|
|
222
|
-
END IF;
|
|
223
|
-
|
|
224
187
|
IF
|
|
225
188
|
v_channel_state."message_id" IS NULL OR
|
|
226
189
|
v_message."dequeue_at" < v_channel_state."message_dequeue_at" OR
|
|
@@ -252,16 +215,11 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
252
215
|
)::TEXT
|
|
253
216
|
);
|
|
254
217
|
END IF;
|
|
255
|
-
|
|
256
|
-
RETURN QUERY SELECT
|
|
257
|
-
${r(0)};
|
|
258
|
-
RETURN;
|
|
259
218
|
END;
|
|
260
219
|
$$ LANGUAGE plpgsql;
|
|
261
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/04-function-message-dequeue.ts",
|
|
220
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/04-function-message-dequeue.ts",Z=(e)=>n`
|
|
262
221
|
SELECT
|
|
263
222
|
"message"."id",
|
|
264
|
-
"message"."name",
|
|
265
223
|
"message"."state",
|
|
266
224
|
"message"."content",
|
|
267
225
|
"message"."channel_name",
|
|
@@ -272,7 +230,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
272
230
|
WHERE "is_locked"
|
|
273
231
|
AND "unlock_at" <= ${e.now}
|
|
274
232
|
ORDER BY "unlock_at" ASC
|
|
275
|
-
`,
|
|
233
|
+
`,ee=(e)=>n`
|
|
276
234
|
SELECT
|
|
277
235
|
"channel_state"."id",
|
|
278
236
|
"channel_state"."name",
|
|
@@ -285,7 +243,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
285
243
|
WHERE "message_id" IS NOT NULL
|
|
286
244
|
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency")
|
|
287
245
|
ORDER BY "active_next_at" ASC
|
|
288
|
-
`,
|
|
246
|
+
`,te=(e)=>n`
|
|
289
247
|
SELECT
|
|
290
248
|
"message"."id",
|
|
291
249
|
"message"."dequeue_at",
|
|
@@ -294,7 +252,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
294
252
|
WHERE NOT "is_locked"
|
|
295
253
|
AND "channel_name" = ${e.channelName}
|
|
296
254
|
ORDER BY "dequeue_at" ASC, "seq_no" ASC
|
|
297
|
-
`,
|
|
255
|
+
`,F={name:E(__filename),sql:(e)=>{let t=Z({now:n`v_now`,schema:e.schema}),a=te({channelName:n`v_channel_state."name"`,schema:e.schema}),_=ee({schema:e.schema});return[n`
|
|
298
256
|
CREATE FUNCTION ${s(e.schema)}."message_dequeue" ()
|
|
299
257
|
RETURNS TABLE (
|
|
300
258
|
result_code INTEGER,
|
|
@@ -331,13 +289,12 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
331
289
|
'id', v_message_locked.id,
|
|
332
290
|
'is_unlocked', TRUE,
|
|
333
291
|
'channel_name', v_message_locked.channel_name,
|
|
334
|
-
'name', v_message_locked.name,
|
|
335
292
|
'num_attempts', v_message_locked.num_attempts + 1
|
|
336
293
|
);
|
|
337
294
|
RETURN;
|
|
338
295
|
END IF;
|
|
339
296
|
|
|
340
|
-
${
|
|
297
|
+
${_}
|
|
341
298
|
FOR UPDATE
|
|
342
299
|
SKIP LOCKED
|
|
343
300
|
LIMIT 1
|
|
@@ -365,7 +322,6 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
365
322
|
|
|
366
323
|
SELECT
|
|
367
324
|
"message"."id",
|
|
368
|
-
"message"."name",
|
|
369
325
|
"message"."channel_name",
|
|
370
326
|
"message"."content",
|
|
371
327
|
"message"."num_attempts",
|
|
@@ -413,13 +369,12 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
413
369
|
'id', v_message_dequeue.id,
|
|
414
370
|
'is_unlocked', FALSE,
|
|
415
371
|
'channel_name', v_message_dequeue.channel_name,
|
|
416
|
-
'name', v_message_dequeue.name,
|
|
417
372
|
'num_attempts', v_message_dequeue.num_attempts + 1
|
|
418
373
|
);
|
|
419
374
|
RETURN;
|
|
420
375
|
END;
|
|
421
376
|
$$ LANGUAGE plpgsql;
|
|
422
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/05-function-message-delete.ts",G={name:
|
|
377
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/05-function-message-delete.ts",G={name:E(__filename),sql:(e)=>{return[n`
|
|
423
378
|
CREATE FUNCTION ${s(e.schema)}."message_delete" (
|
|
424
379
|
p_id UUID,
|
|
425
380
|
p_num_attempts BIGINT
|
|
@@ -496,7 +451,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
496
451
|
RETURN;
|
|
497
452
|
END;
|
|
498
453
|
$$ LANGUAGE plpgsql;
|
|
499
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/06-function-message-defer.ts",
|
|
454
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/06-function-message-defer.ts",x={name:E(__filename),sql:(e)=>{return[n`
|
|
500
455
|
CREATE FUNCTION ${s(e.schema)}."message_defer" (
|
|
501
456
|
p_id UUID,
|
|
502
457
|
p_num_attempts BIGINT,
|
|
@@ -592,7 +547,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
592
547
|
RETURN;
|
|
593
548
|
END;
|
|
594
549
|
$$ LANGUAGE plpgsql;
|
|
595
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/07-function-message-heartbeat.ts",q={name:
|
|
550
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/07-function-message-heartbeat.ts",q={name:E(__filename),sql:(e)=>{return[n`
|
|
596
551
|
CREATE FUNCTION ${s(e.schema)}."message_heartbeat" (
|
|
597
552
|
p_id UUID,
|
|
598
553
|
p_num_attempts BIGINT
|
|
@@ -635,7 +590,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
635
590
|
RETURN;
|
|
636
591
|
END;
|
|
637
592
|
$$ LANGUAGE plpgsql;
|
|
638
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/08-function-channel-policy-clear.ts",$={name:
|
|
593
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/08-function-channel-policy-clear.ts",$={name:E(__filename),sql:(e)=>{return[n`
|
|
639
594
|
CREATE FUNCTION ${s(e.schema)}."channel_policy_clear" (
|
|
640
595
|
p_name TEXT
|
|
641
596
|
) RETURNS VOID AS $$
|
|
@@ -658,17 +613,15 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
658
613
|
WHERE "id" = v_channel_state."id";
|
|
659
614
|
ELSE
|
|
660
615
|
UPDATE ${s(e.schema)}."channel_state" SET
|
|
661
|
-
"max_size" = NULL,
|
|
662
616
|
"max_concurrency" = NULL,
|
|
663
617
|
"release_interval_ms" = NULL
|
|
664
618
|
WHERE "name" = p_name;
|
|
665
619
|
END IF;
|
|
666
620
|
END;
|
|
667
621
|
$$ LANGUAGE plpgsql;
|
|
668
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/09-function-channel-policy-set.ts",b={name:
|
|
622
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/09-function-channel-policy-set.ts",b={name:E(__filename),sql:(e)=>{return[n`
|
|
669
623
|
CREATE FUNCTION ${s(e.schema)}."channel_policy_set" (
|
|
670
624
|
p_name TEXT,
|
|
671
|
-
p_max_size INTEGER,
|
|
672
625
|
p_max_concurrency INTEGER,
|
|
673
626
|
p_release_interval_ms INTEGER
|
|
674
627
|
) RETURNS VOID AS $$
|
|
@@ -679,26 +632,22 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Q=(e)=
|
|
|
679
632
|
|
|
680
633
|
INSERT INTO ${s(e.schema)}."channel_policy" (
|
|
681
634
|
"name",
|
|
682
|
-
"max_size",
|
|
683
635
|
"max_concurrency",
|
|
684
636
|
"release_interval_ms",
|
|
685
637
|
"created_at"
|
|
686
638
|
) VALUES (
|
|
687
639
|
p_name,
|
|
688
|
-
p_max_size,
|
|
689
640
|
p_max_concurrency,
|
|
690
641
|
p_release_interval_ms,
|
|
691
642
|
v_now
|
|
692
643
|
) ON CONFLICT ("name") DO UPDATE SET
|
|
693
|
-
"max_size" = EXCLUDED."max_size",
|
|
694
644
|
"max_concurrency" = EXCLUDED."max_concurrency",
|
|
695
645
|
"release_interval_ms" = EXCLUDED."release_interval_ms";
|
|
696
646
|
|
|
697
647
|
UPDATE ${s(e.schema)}."channel_state" SET
|
|
698
|
-
"max_size" = p_max_size,
|
|
699
648
|
"max_concurrency" = p_max_concurrency,
|
|
700
649
|
"release_interval_ms" = p_release_interval_ms
|
|
701
650
|
WHERE "name" = p_name;
|
|
702
651
|
END;
|
|
703
652
|
$$ LANGUAGE plpgsql;
|
|
704
|
-
`]}};class
|
|
653
|
+
`]}};class g{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}create(e){let t=new l({schema:this.schema,channelName:this.channelName,content:e.content,lockMs:e.lockMs,delayMs:e.delayMs}),a=new Promise((_)=>{this.registerFn({sortKey:JSON.stringify([t.channelName,t.createdAt.toISOString()]),execute:(h)=>t.execute(h).then(()=>_())})});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 c({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,releaseIntervalMs:e.releaseIntervalMs});this.registerFn({sortKey:JSON.stringify([t.channelName,t.createdAt.toISOString()]),execute:async(a)=>{await t.execute(a)}})}clear(){let e=new o({schema:this.schema,channelName:this.channelName});this.registerFn({sortKey:JSON.stringify([e.channelName,e.createdAt.toISOString()]),execute:async(t)=>{await e.execute(t)}})}}class S{policy;message;constructor(e){this.message=new g(e),this.policy=new R(e)}}var se=(e,t)=>{return e.sortKey.localeCompare(t.sortKey)};class A{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(se))await a.execute(t)}}class p{schema;channelName;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.channelName=e.channelName}create(e){let t=this.adaptor(e.databaseClient);return new l({schema:this.schema,channelName:this.channelName,content:e.content,lockMs:e.lockMs,delayMs:e.delayMs}).execute(t)}}class D{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 c({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 y{policy;message;constructor(e){this.message=new p({schema:e.schema,adaptor:e.adaptor,channelName:e.channelName}),this.policy=new D({schema:e.schema,adaptor:e.adaptor,channelName:e.channelName})}}class M{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}).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 i({schema:this.schema}),a=this.adaptor(e.databaseClient),_=await t.execute(a);if(_.resultType==="MESSAGE_DEQUEUED")return{resultType:"MESSAGE_DEQUEUED",message:new M({schema:this.schema,adaptor:this.adaptor,id:_.message.id,channelName:_.message.channelName,isUnlocked:_.message.isUnlocked,content:_.message.content,state:_.message.state,numAttempts:_.message.numAttempts})};else return _}channel(e){return new y({adaptor:this.adaptor,schema:this.schema,channelName:e})}batch(){return new A({schema:this.schema,adaptor:this.adaptor})}migrations(e={}){return[C,U,O,f,F,G,x,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{P as queueEventDecode,B as Queue,T as MessageHeartbeatCommand,i as MessageDequeueCommand,u as MessageDeleteCommand,d as MessageDeferCommand,l as MessageCreateCommand,c as ChannelPolicySetCommand,o as ChannelPolicyClearCommand};
|