lonnymq 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +22 -20
- package/dist/index.d.ts +0 -5
- package/dist/index.js +24 -22
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var{defineProperty:
|
|
1
|
+
var{defineProperty:R,getOwnPropertyNames:X,getOwnPropertyDescriptor:V}=Object,K=Object.prototype.hasOwnProperty;var f=new WeakMap,Q=(e)=>{var n=f.get(e),_;if(n)return n;if(n=R({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")X(e).map((c)=>!K.call(n,c)&&R(n,c,{get:()=>e[c],enumerable:!(_=V(e,c))||_.enumerable}));return f.set(e,n),n};var Y=(e,n)=>{for(var _ in n)R(e,_,{get:n[_],enumerable:!0,configurable:!0,set:(c)=>n[_]=()=>c})};var Ee={};Y(Ee,{Queue:()=>U,MessageDequeueCommand:()=>u,MessageDeleteCommand:()=>h,MessageDeferCommand:()=>N,MessageCreateCommand:()=>m,ChannelPolicySetCommand:()=>o,ChannelPolicyClearCommand:()=>r});module.exports=Q(Ee);var s=(e)=>({nodeType:"VALUE",value:e}),t=(e)=>({nodeType:"REF",value:e}),j=(e)=>({nodeType:"RAW",value:e}),Z=(e)=>{return`'${e.replace(/'/g,"''")}'`},ee=(e)=>{if(e===null)return"NULL";else if(typeof e==="string")return Z(e);else if(typeof e==="number")return e.toString();else if(typeof e==="boolean")return e?"TRUE":"FALSE";else if(e instanceof Date)return`'${e.toISOString()}'`;else if(typeof e==="bigint")return e.toString();else throw new Error(`Unsupported value type: ${typeof e}`)},ne=(e)=>{return`"${e.replace(/"/g,'""')}"`},te=(e)=>{if(e.nodeType==="VALUE")return ee(e.value);else if(e.nodeType==="REF")return ne(e.value);else if(e.nodeType==="RAW")return e.value;else throw new Error("Unsupported SQL node type")};var a=(e,...n)=>{let _=[];for(let c=0;c<e.length;c+=1)if(_.push(e[c]),c<n.length)_.push(te(n[c]));return j(_.join(""))};class r{schema;channelName;createdAt;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.createdAt=new Date}sortKeyGet(){return JSON.stringify([this.channelName,null,this.createdAt.toISOString()])}async execute(e){await e.query(a`
|
|
2
2
|
SELECT 1 FROM ${t(this.schema)}."channel_policy_clear"(
|
|
3
3
|
${s(this.channelName)}
|
|
4
4
|
)
|
|
@@ -9,7 +9,7 @@ var{defineProperty:S,getOwnPropertyNames:K,getOwnPropertyDescriptor:Q}=Object,Y=
|
|
|
9
9
|
${s(this.maxConcurrency)}::INTEGER,
|
|
10
10
|
${s(this.releaseIntervalMs)}::INTEGER
|
|
11
11
|
)
|
|
12
|
-
`.value)}}var
|
|
12
|
+
`.value)}}var S=(e)=>{return e*1000},_e=(e)=>{return S(e*60)},p=(e)=>{return _e(e*60)};var q=require("node:crypto");class C{value;constructor(e){this.value=e}toString(e){return q.createHash("sha256").update(e).update(this.value).digest("base64").replace(/=/g,"")}}var T=new C("WAKE"),$=!1,d=S(0),F=p(1);var g=require("path"),__filename="/home/runner/work/lonnymq/lonnymq/src/core/path.ts",se=g.dirname(g.dirname(__filename)),ae=new RegExp(`^${se}/`),E=(e)=>{return e.replace(ae,"")};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/04-function-message-create.ts";var M={name:E(__filename),sql:(e)=>{return[a`
|
|
13
13
|
CREATE FUNCTION ${t(e.schema)}."message_create" (
|
|
14
14
|
p_channel_name TEXT,
|
|
15
15
|
p_name TEXT,
|
|
@@ -24,7 +24,7 @@ var{defineProperty:S,getOwnPropertyNames:K,getOwnPropertyDescriptor:Q}=Object,Y=
|
|
|
24
24
|
v_message RECORD;
|
|
25
25
|
v_message_next_dequeue_after TIMESTAMP;
|
|
26
26
|
BEGIN
|
|
27
|
-
v_now := NOW()
|
|
27
|
+
v_now := NOW();
|
|
28
28
|
|
|
29
29
|
SELECT
|
|
30
30
|
"max_size",
|
|
@@ -86,7 +86,8 @@ var{defineProperty:S,getOwnPropertyNames:K,getOwnPropertyDescriptor:Q}=Object,Y=
|
|
|
86
86
|
) ON CONFLICT ("channel_name", "name")
|
|
87
87
|
WHERE "num_attempts" = 0
|
|
88
88
|
DO UPDATE SET
|
|
89
|
-
"
|
|
89
|
+
"channel_name" = EXCLUDED."channel_name",
|
|
90
|
+
"name" = EXCLUDED."name"
|
|
90
91
|
RETURNING
|
|
91
92
|
"id",
|
|
92
93
|
"xmax",
|
|
@@ -107,7 +108,7 @@ var{defineProperty:S,getOwnPropertyNames:K,getOwnPropertyDescriptor:Q}=Object,Y=
|
|
|
107
108
|
UPDATE ${t(e.schema)}."channel_state" SET
|
|
108
109
|
"current_size" = v_channel_state."current_size" + 1,
|
|
109
110
|
"message_next_id" = v_message."id",
|
|
110
|
-
"message_next_dequeue_after" = v_message."dequeue_after"
|
|
111
|
+
"message_next_dequeue_after" = GREATEST(v_now, v_message."dequeue_after")
|
|
111
112
|
WHERE "id" = v_channel_state."id";
|
|
112
113
|
ELSE
|
|
113
114
|
UPDATE ${t(e.schema)}."channel_state" SET
|
|
@@ -123,7 +124,7 @@ var{defineProperty:S,getOwnPropertyNames:K,getOwnPropertyDescriptor:Q}=Object,Y=
|
|
|
123
124
|
);
|
|
124
125
|
END;
|
|
125
126
|
$$ LANGUAGE plpgsql;
|
|
126
|
-
`]}};class
|
|
127
|
+
`]}};class m{schema;channelName;name;content;lockMs;delayMs;createdAt;constructor(e){let n=e.name??null,_=e.lockMs===void 0?F:Math.max(0,e.lockMs),c=e.delayMs===void 0?d:e.delayMs;this.schema=e.schema,this.channelName=e.channelName,this.content=e.content,this.name=n,this.lockMs=_,this.delayMs=c,this.createdAt=new Date}async execute(e){let n=await e.query(a`
|
|
127
128
|
SELECT ${t(this.schema)}."message_create"(
|
|
128
129
|
${s(this.channelName)},
|
|
129
130
|
${s(this.name)},
|
|
@@ -131,7 +132,7 @@ var{defineProperty:S,getOwnPropertyNames:K,getOwnPropertyDescriptor:Q}=Object,Y=
|
|
|
131
132
|
${s(this.lockMs)}::INTEGER,
|
|
132
133
|
${s(this.delayMs)}::INTEGER
|
|
133
134
|
) AS "result"
|
|
134
|
-
`.value).then((_)=>_.rows[0].result);if(n.result_code===1)return{resultType:"MESSAGE_DROPPED"};else if(n.result_code===2)return{resultType:"MESSAGE_DEDUPLICATED",id:BigInt(n.id)};else if(n.result_code===0)return{resultType:"MESSAGE_CREATED",id:BigInt(n.id)};else throw new Error("Unexpected result")}}var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/05-function-message-dequeue.ts";var
|
|
135
|
+
`.value).then((_)=>_.rows[0].result);if(n.result_code===1)return{resultType:"MESSAGE_DROPPED"};else if(n.result_code===2)return{resultType:"MESSAGE_DEDUPLICATED",id:BigInt(n.id)};else if(n.result_code===0)return{resultType:"MESSAGE_CREATED",id:BigInt(n.id)};else throw new Error("Unexpected result")}}var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/05-function-message-dequeue.ts";var G={name:E(__filename),sql:(e)=>{return[a`
|
|
135
136
|
CREATE FUNCTION ${t(e.schema)}."message_dequeue" ()
|
|
136
137
|
RETURNS JSONB AS $$
|
|
137
138
|
DECLARE
|
|
@@ -240,7 +241,7 @@ var{defineProperty:S,getOwnPropertyNames:K,getOwnPropertyDescriptor:Q}=Object,Y=
|
|
|
240
241
|
FROM ${t(e.schema)}."message"
|
|
241
242
|
WHERE NOT "is_locked"
|
|
242
243
|
AND "channel_name" = v_message_dequeue."channel_name"
|
|
243
|
-
ORDER BY "dequeue_after" ASC
|
|
244
|
+
ORDER BY "dequeue_after" ASC, "id" ASC
|
|
244
245
|
LIMIT 1
|
|
245
246
|
INTO v_message_next_dequeue;
|
|
246
247
|
|
|
@@ -277,7 +278,7 @@ var{defineProperty:S,getOwnPropertyNames:K,getOwnPropertyDescriptor:Q}=Object,Y=
|
|
|
277
278
|
$$ LANGUAGE plpgsql;
|
|
278
279
|
`]}};class u{schema;constructor(e){this.schema=e.schema}async execute(e){let n=await e.query(a`
|
|
279
280
|
SELECT ${t(this.schema)}."message_dequeue"() AS "result"
|
|
280
|
-
`.value).then((_)=>_.rows[0].result);if(n.result_code===0)return{resultType:"MESSAGE_NOT_AVAILABLE",retryMs:n.retry_ms};else if(n.result_code===1)return{resultType:"MESSAGE_DEQUEUED",message:{id:BigInt(n.id),channelName:n.channel_name,name:n.name,content:n.content,dequeueNonce:n.dequeue_nonce,state:n.state,numAttempts:n.num_attempts}};else throw new Error("Unexpected dequeue result")}}var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/06-function-message-delete.ts";var
|
|
281
|
+
`.value).then((_)=>_.rows[0].result);if(n.result_code===0)return{resultType:"MESSAGE_NOT_AVAILABLE",retryMs:n.retry_ms};else if(n.result_code===1)return{resultType:"MESSAGE_DEQUEUED",message:{id:BigInt(n.id),channelName:n.channel_name,name:n.name,content:n.content,dequeueNonce:n.dequeue_nonce,state:n.state,numAttempts:n.num_attempts}};else throw new Error("Unexpected dequeue result")}}var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/06-function-message-delete.ts";var B={name:E(__filename),sql:(e)=>{return[a`
|
|
281
282
|
CREATE FUNCTION ${t(e.schema)}."message_delete" (
|
|
282
283
|
p_id BIGINT,
|
|
283
284
|
p_dequeue_nonce UUID
|
|
@@ -345,7 +346,7 @@ var{defineProperty:S,getOwnPropertyNames:K,getOwnPropertyDescriptor:Q}=Object,Y=
|
|
|
345
346
|
SELECT ${t(this.schema)}."message_delete"( ${s(this.id)},
|
|
346
347
|
${s(this.dequeueNonce)}
|
|
347
348
|
) AS "result"
|
|
348
|
-
`.value).then((_)=>_.rows[0].result);if(n.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(n.result_code===1)return{resultType:"STATE_INVALID"};else if(n.result_code===2)return{resultType:"MESSAGE_DELETED"};else throw new Error("Unexpected result")}}var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/07-function-message-defer.ts";var
|
|
349
|
+
`.value).then((_)=>_.rows[0].result);if(n.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(n.result_code===1)return{resultType:"STATE_INVALID"};else if(n.result_code===2)return{resultType:"MESSAGE_DELETED"};else throw new Error("Unexpected result")}}var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/07-function-message-defer.ts";var P={name:E(__filename),sql:(e)=>{return[a`
|
|
349
350
|
CREATE FUNCTION ${t(e.schema)}."message_defer" (
|
|
350
351
|
p_id BIGINT,
|
|
351
352
|
p_dequeue_nonce UUID,
|
|
@@ -416,16 +417,16 @@ var{defineProperty:S,getOwnPropertyNames:K,getOwnPropertyDescriptor:Q}=Object,Y=
|
|
|
416
417
|
);
|
|
417
418
|
END;
|
|
418
419
|
$$ LANGUAGE plpgsql;
|
|
419
|
-
`]}};class N{schema;id;dequeueNonce;delayMs;state;constructor(e){let n
|
|
420
|
+
`]}};class N{schema;id;dequeueNonce;delayMs;state;constructor(e){let n=e.delayMs===void 0?d:e.delayMs;this.schema=e.schema,this.id=e.id,this.dequeueNonce=e.dequeueNonce,this.delayMs=n,this.state=e.state??null}async execute(e){let n=await e.query(a`
|
|
420
421
|
SELECT ${t(this.schema)}."message_defer"(
|
|
421
422
|
${s(this.id)},
|
|
422
423
|
${s(this.dequeueNonce)},
|
|
423
424
|
${s(this.delayMs)},
|
|
424
425
|
${s(this.state)}
|
|
425
426
|
) AS "result"
|
|
426
|
-
`.value).then((_)=>_.rows[0].result);if(n.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(n.result_code===1)return{resultType:"STATE_INVALID"};else if(n.result_code===2)return{resultType:"MESSAGE_DEFERRED"};else throw new Error("Unexpected result")}}var
|
|
427
|
+
`.value).then((_)=>_.rows[0].result);if(n.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(n.result_code===1)return{resultType:"STATE_INVALID"};else if(n.result_code===2)return{resultType:"MESSAGE_DEFERRED"};else throw new Error("Unexpected result")}}var H=(e)=>{let n=e.split(`
|
|
427
428
|
`),_=Number.MAX_SAFE_INTEGER;for(let c of n){if(c.trim().length===0)continue;let l=c.search(/\S/);_=Math.min(_,l)}return n.map((c)=>c.slice(_)).join(`
|
|
428
|
-
`).trim()};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/00-table-channel-policy.ts",
|
|
429
|
+
`).trim()};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/00-table-channel-policy.ts",b={name:E(__filename),sql:(e)=>{return[a`
|
|
429
430
|
CREATE TABLE ${t(e.schema)}."channel_policy" (
|
|
430
431
|
"id" BIGSERIAL NOT NULL,
|
|
431
432
|
"name" TEXT NOT NULL,
|
|
@@ -437,7 +438,7 @@ var{defineProperty:S,getOwnPropertyNames:K,getOwnPropertyDescriptor:Q}=Object,Y=
|
|
|
437
438
|
`,a`
|
|
438
439
|
CREATE UNIQUE INDEX "channel_policy_name_ux"
|
|
439
440
|
ON ${t(e.schema)}."channel_policy" ("name");
|
|
440
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/01-table-channel-state.ts",
|
|
441
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/01-table-channel-state.ts",k={name:E(__filename),sql:(e)=>{return[a`
|
|
441
442
|
CREATE TABLE ${t(e.schema)}."channel_state" (
|
|
442
443
|
"id" BIGSERIAL NOT NULL,
|
|
443
444
|
"name" TEXT NOT NULL,
|
|
@@ -459,7 +460,7 @@ var{defineProperty:S,getOwnPropertyNames:K,getOwnPropertyDescriptor:Q}=Object,Y=
|
|
|
459
460
|
"message_next_dequeue_after" ASC
|
|
460
461
|
) WHERE "message_next_id" IS NOT NULL
|
|
461
462
|
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency");
|
|
462
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/02-table-message.ts",
|
|
463
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/02-table-message.ts",z={name:E(__filename),sql:(e)=>{return[a`
|
|
463
464
|
CREATE TABLE ${t(e.schema)}."message" (
|
|
464
465
|
"id" BIGSERIAL NOT NULL,
|
|
465
466
|
"channel_name" TEXT NOT NULL,
|
|
@@ -483,14 +484,15 @@ var{defineProperty:S,getOwnPropertyNames:K,getOwnPropertyDescriptor:Q}=Object,Y=
|
|
|
483
484
|
CREATE INDEX "message_dequeue_ix"
|
|
484
485
|
ON ${t(e.schema)}."message" (
|
|
485
486
|
"channel_name",
|
|
486
|
-
"dequeue_after" ASC
|
|
487
|
+
"dequeue_after" ASC,
|
|
488
|
+
"id" ASC
|
|
487
489
|
) WHERE NOT "is_locked";
|
|
488
490
|
`,a`
|
|
489
491
|
CREATE INDEX "message_locked_dequeue_ix"
|
|
490
492
|
ON ${t(e.schema)}."message" (
|
|
491
493
|
"dequeue_after" ASC
|
|
492
494
|
) WHERE "is_locked";
|
|
493
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/03-function-wake.ts",
|
|
495
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/03-function-wake.ts",w={name:E(__filename),sql:(e)=>{let n=T.toString(e.schema);return[a`
|
|
494
496
|
CREATE FUNCTION ${t(e.schema)}."wake" (
|
|
495
497
|
p_delay_ms INTEGER
|
|
496
498
|
) RETURNS VOID AS $$
|
|
@@ -500,7 +502,7 @@ var{defineProperty:S,getOwnPropertyNames:K,getOwnPropertyDescriptor:Q}=Object,Y=
|
|
|
500
502
|
END IF;
|
|
501
503
|
END;
|
|
502
504
|
$$ LANGUAGE plpgsql;
|
|
503
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/08-function-channel-policy-set.ts",
|
|
505
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/08-function-channel-policy-set.ts",W={name:E(__filename),sql:(e)=>{return[a`
|
|
504
506
|
CREATE FUNCTION ${t(e.schema)}."channel_policy_set" (
|
|
505
507
|
p_name TEXT,
|
|
506
508
|
p_max_size INTEGER,
|
|
@@ -532,7 +534,7 @@ var{defineProperty:S,getOwnPropertyNames:K,getOwnPropertyDescriptor:Q}=Object,Y=
|
|
|
532
534
|
PERFORM ${t(e.schema)}."wake"(0);
|
|
533
535
|
END;
|
|
534
536
|
$$ LANGUAGE plpgsql;
|
|
535
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/09-function-channel-policy-clear.ts",
|
|
537
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/09-function-channel-policy-clear.ts",J={name:E(__filename),sql:(e)=>{return[a`
|
|
536
538
|
CREATE FUNCTION ${t(e.schema)}."channel_policy_clear" (
|
|
537
539
|
p_name TEXT
|
|
538
540
|
) RETURNS VOID AS $$
|
|
@@ -564,4 +566,4 @@ var{defineProperty:S,getOwnPropertyNames:K,getOwnPropertyDescriptor:Q}=Object,Y=
|
|
|
564
566
|
PERFORM ${t(e.schema)}."wake"(0);
|
|
565
567
|
END;
|
|
566
568
|
$$ LANGUAGE plpgsql;
|
|
567
|
-
`]}};class
|
|
569
|
+
`]}};class i{value;isSet;constructor(){this.isSet=!1,this.value=null}get(){return this.isSet?{resultType:"RESULT_SET",value:this.value}:{resultType:"RESULT_NOT_SET"}}set(e){this.isSet=!0,this.value=e}}class I{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}create(e){let n=new m({schema:this.schema,channelName:this.channelName,name:e.name,content:e.content,lockMs:e.lockMs,delayMs:e.delayMs}),_=new i;return this.registerFn({sortKey:JSON.stringify([n.channelName,n.name,n.createdAt.toISOString()]),execute:(c)=>n.execute(c).then((l)=>_.set(l))}),_}}class O{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}set(e){let n=new o({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,maxSize:e.maxSize,releaseIntervalMs:e.releaseIntervalMs}),_=new i;return this.registerFn({sortKey:JSON.stringify([n.channelName,null,n.createdAt.toISOString()]),execute:(c)=>n.execute(c).then((l)=>_.set(l))}),_}clear(){let e=new r({schema:this.schema,channelName:this.channelName}),n=new i;return this.registerFn({sortKey:JSON.stringify([e.channelName,null,e.createdAt.toISOString()]),execute:(_)=>e.execute(_).then((c)=>n.set(c))}),n}}class A{policy;message;constructor(e){this.message=new I(e),this.policy=new O(e)}}var ce=(e,n)=>{return e.sortKey.localeCompare(n.sortKey)};class L{commands;schema;constructor(e){this.commands=[],this.schema=e.schema}channel(e){return new A({schema:this.schema,channelName:e,registerFn:(n)=>{this.commands.push(n)}})}async execute(e){for(let n of this.commands.sort(ce))await n.execute(e.databaseClient)}}class v{schema;channelName;constructor(e){this.schema=e.schema,this.channelName=e.channelName}async create(e){return new m({schema:this.schema,channelName:this.channelName,name:e.name,content:e.content,lockMs:e.lockMs,delayMs:e.delayMs}).execute(e.databaseClient)}}class D{schema;channelName;constructor(e){this.schema=e.schema,this.channelName=e.channelName}set(e){return new o({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,maxSize:e.maxSize,releaseIntervalMs:e.releaseIntervalMs}).execute(e.databaseClient)}clear(e){return new r({schema:this.schema,channelName:this.channelName}).execute(e.databaseClient)}}class y{policy;message;constructor(e){this.message=new v({schema:e.schema,channelName:e.channelName}),this.policy=new D({schema:e.schema,channelName:e.channelName})}}class x{schema;id;channelName;name;content;dequeueNonce;state;numAttempts;constructor(e){this.schema=e.schema,this.id=e.id,this.channelName=e.channelName,this.dequeueNonce=e.dequeueNonce,this.name=e.name,this.content=e.content,this.state=e.state,this.numAttempts=e.numAttempts}async defer(e){return new N({schema:this.schema,id:this.id,dequeueNonce:this.dequeueNonce,delayMs:e.delayMs,state:e.state}).execute(e.databaseClient)}async delete(e){return new h({schema:this.schema,id:this.id,dequeueNonce:this.dequeueNonce}).execute(e.databaseClient)}}class U{schema;constructor(e){this.schema=e}async dequeue(e){let _=await new u({schema:this.schema}).execute(e.databaseClient);if(_.resultType==="MESSAGE_DEQUEUED")return{resultType:"MESSAGE_DEQUEUED",message:new x({schema:this.schema,id:_.message.id,dequeueNonce:_.message.dequeueNonce,channelName:_.message.channelName,name:_.message.name,content:_.message.content,state:_.message.state,numAttempts:_.message.numAttempts})};else return _}channel(e){return new y({schema:this.schema,channelName:e})}batch(){return new L({schema:this.schema})}migrations(e){return[b,k,z,w,M,G,B,P,W,J].map((n)=>({name:n.name,sql:n.sql({schema:this.schema,useWake:e.useWake??$}).map((_)=>H(_.value))})).sort((n,_)=>n.name.localeCompare(_.name))}wakeChannel(){return T.toString(this.schema)}}
|
package/dist/index.d.ts
CHANGED
|
@@ -74,7 +74,6 @@ export declare class MessageCreateCommand {
|
|
|
74
74
|
content: string;
|
|
75
75
|
lockMs?: number;
|
|
76
76
|
delayMs?: number;
|
|
77
|
-
priority?: boolean;
|
|
78
77
|
});
|
|
79
78
|
execute(databaseClient: DatabaseClient): Promise<MessageCreateCommandResult>;
|
|
80
79
|
}
|
|
@@ -145,7 +144,6 @@ export declare class MessageDeferCommand {
|
|
|
145
144
|
dequeueNonce: string;
|
|
146
145
|
delayMs?: number;
|
|
147
146
|
state?: string | null;
|
|
148
|
-
priority?: boolean;
|
|
149
147
|
});
|
|
150
148
|
execute(databaseClient: DatabaseClient): Promise<MessageDeferCommandResult>;
|
|
151
149
|
}
|
|
@@ -163,7 +161,6 @@ export declare class QueueBatchChannelMessage {
|
|
|
163
161
|
lockMs?: number;
|
|
164
162
|
content: string;
|
|
165
163
|
delayMs?: number;
|
|
166
|
-
priority?: boolean;
|
|
167
164
|
}): Deferred<MessageCreateCommandResult>;
|
|
168
165
|
}
|
|
169
166
|
export declare class QueueBatchChannelPolicy {
|
|
@@ -220,7 +217,6 @@ export declare class QueueChannelMessage {
|
|
|
220
217
|
lockMs?: number;
|
|
221
218
|
content: string;
|
|
222
219
|
delayMs?: number;
|
|
223
|
-
priority?: boolean;
|
|
224
220
|
}): Promise<MessageCreateCommandResult>;
|
|
225
221
|
}
|
|
226
222
|
export declare class QueueChannelPolicy {
|
|
@@ -270,7 +266,6 @@ export declare class QueueMessage {
|
|
|
270
266
|
defer(params: {
|
|
271
267
|
databaseClient: DatabaseClient;
|
|
272
268
|
delayMs?: number;
|
|
273
|
-
priority?: boolean;
|
|
274
269
|
state?: string;
|
|
275
270
|
}): Promise<MessageDeferCommandResult>;
|
|
276
271
|
delete(params: {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),
|
|
1
|
+
var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),w=(e)=>({nodeType:"RAW",value:e}),W=(e)=>{return`'${e.replace(/'/g,"''")}'`},J=(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}`)},X=(e)=>{return`"${e.replace(/"/g,'""')}"`},V=(e)=>{if(e.nodeType==="VALUE")return J(e.value);else if(e.nodeType==="REF")return X(e.value);else if(e.nodeType==="RAW")return e.value;else throw new Error("Unsupported SQL node type")};var a=(e,...t)=>{let _=[];for(let c=0;c<e.length;c+=1)if(_.push(e[c]),c<t.length)_.push(V(t[c]));return w(_.join(""))};class r{schema;channelName;createdAt;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.createdAt=new Date}sortKeyGet(){return JSON.stringify([this.channelName,null,this.createdAt.toISOString()])}async execute(e){await e.query(a`
|
|
2
2
|
SELECT 1 FROM ${n(this.schema)}."channel_policy_clear"(
|
|
3
3
|
${s(this.channelName)}
|
|
4
4
|
)
|
|
@@ -9,7 +9,7 @@ var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),J=(e)=
|
|
|
9
9
|
${s(this.maxConcurrency)}::INTEGER,
|
|
10
10
|
${s(this.releaseIntervalMs)}::INTEGER
|
|
11
11
|
)
|
|
12
|
-
`.value)}}var
|
|
12
|
+
`.value)}}var R=(e)=>{return e*1000},K=(e)=>{return R(e*60)},y=(e)=>{return K(e*60)};import{createHash as Q}from"node:crypto";class x{value;constructor(e){this.value=e}toString(e){return Q("sha256").update(e).update(this.value).digest("base64").replace(/=/g,"")}}var u=new x("WAKE"),U=!1,h=R(0),f=y(1);import{dirname as p}from"path";var __filename="/home/runner/work/lonnymq/lonnymq/src/core/path.ts",Y=p(p(__filename)),j=new RegExp(`^${Y}/`),E=(e)=>{return e.replace(j,"")};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/04-function-message-create.ts";var q={name:E(__filename),sql:(e)=>{return[a`
|
|
13
13
|
CREATE FUNCTION ${n(e.schema)}."message_create" (
|
|
14
14
|
p_channel_name TEXT,
|
|
15
15
|
p_name TEXT,
|
|
@@ -24,7 +24,7 @@ var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),J=(e)=
|
|
|
24
24
|
v_message RECORD;
|
|
25
25
|
v_message_next_dequeue_after TIMESTAMP;
|
|
26
26
|
BEGIN
|
|
27
|
-
v_now := NOW()
|
|
27
|
+
v_now := NOW();
|
|
28
28
|
|
|
29
29
|
SELECT
|
|
30
30
|
"max_size",
|
|
@@ -86,7 +86,8 @@ var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),J=(e)=
|
|
|
86
86
|
) ON CONFLICT ("channel_name", "name")
|
|
87
87
|
WHERE "num_attempts" = 0
|
|
88
88
|
DO UPDATE SET
|
|
89
|
-
"
|
|
89
|
+
"channel_name" = EXCLUDED."channel_name",
|
|
90
|
+
"name" = EXCLUDED."name"
|
|
90
91
|
RETURNING
|
|
91
92
|
"id",
|
|
92
93
|
"xmax",
|
|
@@ -107,7 +108,7 @@ var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),J=(e)=
|
|
|
107
108
|
UPDATE ${n(e.schema)}."channel_state" SET
|
|
108
109
|
"current_size" = v_channel_state."current_size" + 1,
|
|
109
110
|
"message_next_id" = v_message."id",
|
|
110
|
-
"message_next_dequeue_after" = v_message."dequeue_after"
|
|
111
|
+
"message_next_dequeue_after" = GREATEST(v_now, v_message."dequeue_after")
|
|
111
112
|
WHERE "id" = v_channel_state."id";
|
|
112
113
|
ELSE
|
|
113
114
|
UPDATE ${n(e.schema)}."channel_state" SET
|
|
@@ -123,7 +124,7 @@ var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),J=(e)=
|
|
|
123
124
|
);
|
|
124
125
|
END;
|
|
125
126
|
$$ LANGUAGE plpgsql;
|
|
126
|
-
`]}};class
|
|
127
|
+
`]}};class m{schema;channelName;name;content;lockMs;delayMs;createdAt;constructor(e){let t=e.name??null,_=e.lockMs===void 0?f:Math.max(0,e.lockMs),c=e.delayMs===void 0?h:e.delayMs;this.schema=e.schema,this.channelName=e.channelName,this.content=e.content,this.name=t,this.lockMs=_,this.delayMs=c,this.createdAt=new Date}async execute(e){let t=await e.query(a`
|
|
127
128
|
SELECT ${n(this.schema)}."message_create"(
|
|
128
129
|
${s(this.channelName)},
|
|
129
130
|
${s(this.name)},
|
|
@@ -131,7 +132,7 @@ var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),J=(e)=
|
|
|
131
132
|
${s(this.lockMs)}::INTEGER,
|
|
132
133
|
${s(this.delayMs)}::INTEGER
|
|
133
134
|
) AS "result"
|
|
134
|
-
`.value).then((_)=>_.rows[0].result);if(t.result_code===1)return{resultType:"MESSAGE_DROPPED"};else if(t.result_code===2)return{resultType:"MESSAGE_DEDUPLICATED",id:BigInt(t.id)};else if(t.result_code===0)return{resultType:"MESSAGE_CREATED",id:BigInt(t.id)};else throw new Error("Unexpected result")}}var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/05-function-message-dequeue.ts";var
|
|
135
|
+
`.value).then((_)=>_.rows[0].result);if(t.result_code===1)return{resultType:"MESSAGE_DROPPED"};else if(t.result_code===2)return{resultType:"MESSAGE_DEDUPLICATED",id:BigInt(t.id)};else if(t.result_code===0)return{resultType:"MESSAGE_CREATED",id:BigInt(t.id)};else throw new Error("Unexpected result")}}var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/05-function-message-dequeue.ts";var C={name:E(__filename),sql:(e)=>{return[a`
|
|
135
136
|
CREATE FUNCTION ${n(e.schema)}."message_dequeue" ()
|
|
136
137
|
RETURNS JSONB AS $$
|
|
137
138
|
DECLARE
|
|
@@ -240,7 +241,7 @@ var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),J=(e)=
|
|
|
240
241
|
FROM ${n(e.schema)}."message"
|
|
241
242
|
WHERE NOT "is_locked"
|
|
242
243
|
AND "channel_name" = v_message_dequeue."channel_name"
|
|
243
|
-
ORDER BY "dequeue_after" ASC
|
|
244
|
+
ORDER BY "dequeue_after" ASC, "id" ASC
|
|
244
245
|
LIMIT 1
|
|
245
246
|
INTO v_message_next_dequeue;
|
|
246
247
|
|
|
@@ -275,9 +276,9 @@ var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),J=(e)=
|
|
|
275
276
|
);
|
|
276
277
|
END;
|
|
277
278
|
$$ LANGUAGE plpgsql;
|
|
278
|
-
`]}};class
|
|
279
|
+
`]}};class N{schema;constructor(e){this.schema=e.schema}async execute(e){let t=await e.query(a`
|
|
279
280
|
SELECT ${n(this.schema)}."message_dequeue"() AS "result"
|
|
280
|
-
`.value).then((_)=>_.rows[0].result);if(t.result_code===0)return{resultType:"MESSAGE_NOT_AVAILABLE",retryMs:t.retry_ms};else if(t.result_code===1)return{resultType:"MESSAGE_DEQUEUED",message:{id:BigInt(t.id),channelName:t.channel_name,name:t.name,content:t.content,dequeueNonce:t.dequeue_nonce,state:t.state,numAttempts:t.num_attempts}};else throw new Error("Unexpected dequeue result")}}var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/06-function-message-delete.ts";var
|
|
281
|
+
`.value).then((_)=>_.rows[0].result);if(t.result_code===0)return{resultType:"MESSAGE_NOT_AVAILABLE",retryMs:t.retry_ms};else if(t.result_code===1)return{resultType:"MESSAGE_DEQUEUED",message:{id:BigInt(t.id),channelName:t.channel_name,name:t.name,content:t.content,dequeueNonce:t.dequeue_nonce,state:t.state,numAttempts:t.num_attempts}};else throw new Error("Unexpected dequeue result")}}var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/06-function-message-delete.ts";var $={name:E(__filename),sql:(e)=>{return[a`
|
|
281
282
|
CREATE FUNCTION ${n(e.schema)}."message_delete" (
|
|
282
283
|
p_id BIGINT,
|
|
283
284
|
p_dequeue_nonce UUID
|
|
@@ -341,11 +342,11 @@ var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),J=(e)=
|
|
|
341
342
|
);
|
|
342
343
|
END;
|
|
343
344
|
$$ LANGUAGE plpgsql;
|
|
344
|
-
`]}};class
|
|
345
|
+
`]}};class T{schema;id;dequeueNonce;constructor(e){this.schema=e.schema,this.id=e.id,this.dequeueNonce=e.dequeueNonce}async execute(e){let t=await e.query(a`
|
|
345
346
|
SELECT ${n(this.schema)}."message_delete"( ${s(this.id)},
|
|
346
347
|
${s(this.dequeueNonce)}
|
|
347
348
|
) AS "result"
|
|
348
|
-
`.value).then((_)=>_.rows[0].result);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")}}var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/07-function-message-defer.ts";var
|
|
349
|
+
`.value).then((_)=>_.rows[0].result);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")}}var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/07-function-message-defer.ts";var F={name:E(__filename),sql:(e)=>{return[a`
|
|
349
350
|
CREATE FUNCTION ${n(e.schema)}."message_defer" (
|
|
350
351
|
p_id BIGINT,
|
|
351
352
|
p_dequeue_nonce UUID,
|
|
@@ -416,16 +417,16 @@ var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),J=(e)=
|
|
|
416
417
|
);
|
|
417
418
|
END;
|
|
418
419
|
$$ LANGUAGE plpgsql;
|
|
419
|
-
`]}};class
|
|
420
|
+
`]}};class d{schema;id;dequeueNonce;delayMs;state;constructor(e){let t=e.delayMs===void 0?h:e.delayMs;this.schema=e.schema,this.id=e.id,this.dequeueNonce=e.dequeueNonce,this.delayMs=t,this.state=e.state??null}async execute(e){let t=await e.query(a`
|
|
420
421
|
SELECT ${n(this.schema)}."message_defer"(
|
|
421
422
|
${s(this.id)},
|
|
422
423
|
${s(this.dequeueNonce)},
|
|
423
424
|
${s(this.delayMs)},
|
|
424
425
|
${s(this.state)}
|
|
425
426
|
) AS "result"
|
|
426
|
-
`.value).then((_)=>_.rows[0].result);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")}}var
|
|
427
|
+
`.value).then((_)=>_.rows[0].result);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")}}var M=(e)=>{let t=e.split(`
|
|
427
428
|
`),_=Number.MAX_SAFE_INTEGER;for(let c of t){if(c.trim().length===0)continue;let l=c.search(/\S/);_=Math.min(_,l)}return t.map((c)=>c.slice(_)).join(`
|
|
428
|
-
`).trim()};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/00-table-channel-policy.ts",
|
|
429
|
+
`).trim()};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/00-table-channel-policy.ts",G={name:E(__filename),sql:(e)=>{return[a`
|
|
429
430
|
CREATE TABLE ${n(e.schema)}."channel_policy" (
|
|
430
431
|
"id" BIGSERIAL NOT NULL,
|
|
431
432
|
"name" TEXT NOT NULL,
|
|
@@ -437,7 +438,7 @@ var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),J=(e)=
|
|
|
437
438
|
`,a`
|
|
438
439
|
CREATE UNIQUE INDEX "channel_policy_name_ux"
|
|
439
440
|
ON ${n(e.schema)}."channel_policy" ("name");
|
|
440
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/01-table-channel-state.ts",
|
|
441
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/01-table-channel-state.ts",B={name:E(__filename),sql:(e)=>{return[a`
|
|
441
442
|
CREATE TABLE ${n(e.schema)}."channel_state" (
|
|
442
443
|
"id" BIGSERIAL NOT NULL,
|
|
443
444
|
"name" TEXT NOT NULL,
|
|
@@ -459,7 +460,7 @@ var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),J=(e)=
|
|
|
459
460
|
"message_next_dequeue_after" ASC
|
|
460
461
|
) WHERE "message_next_id" IS NOT NULL
|
|
461
462
|
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency");
|
|
462
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/02-table-message.ts",
|
|
463
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/02-table-message.ts",P={name:E(__filename),sql:(e)=>{return[a`
|
|
463
464
|
CREATE TABLE ${n(e.schema)}."message" (
|
|
464
465
|
"id" BIGSERIAL NOT NULL,
|
|
465
466
|
"channel_name" TEXT NOT NULL,
|
|
@@ -483,14 +484,15 @@ var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),J=(e)=
|
|
|
483
484
|
CREATE INDEX "message_dequeue_ix"
|
|
484
485
|
ON ${n(e.schema)}."message" (
|
|
485
486
|
"channel_name",
|
|
486
|
-
"dequeue_after" ASC
|
|
487
|
+
"dequeue_after" ASC,
|
|
488
|
+
"id" ASC
|
|
487
489
|
) WHERE NOT "is_locked";
|
|
488
490
|
`,a`
|
|
489
491
|
CREATE INDEX "message_locked_dequeue_ix"
|
|
490
492
|
ON ${n(e.schema)}."message" (
|
|
491
493
|
"dequeue_after" ASC
|
|
492
494
|
) WHERE "is_locked";
|
|
493
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/03-function-wake.ts",
|
|
495
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/03-function-wake.ts",H={name:E(__filename),sql:(e)=>{let t=u.toString(e.schema);return[a`
|
|
494
496
|
CREATE FUNCTION ${n(e.schema)}."wake" (
|
|
495
497
|
p_delay_ms INTEGER
|
|
496
498
|
) RETURNS VOID AS $$
|
|
@@ -500,7 +502,7 @@ var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),J=(e)=
|
|
|
500
502
|
END IF;
|
|
501
503
|
END;
|
|
502
504
|
$$ LANGUAGE plpgsql;
|
|
503
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/08-function-channel-policy-set.ts",
|
|
505
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/08-function-channel-policy-set.ts",b={name:E(__filename),sql:(e)=>{return[a`
|
|
504
506
|
CREATE FUNCTION ${n(e.schema)}."channel_policy_set" (
|
|
505
507
|
p_name TEXT,
|
|
506
508
|
p_max_size INTEGER,
|
|
@@ -532,7 +534,7 @@ var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),J=(e)=
|
|
|
532
534
|
PERFORM ${n(e.schema)}."wake"(0);
|
|
533
535
|
END;
|
|
534
536
|
$$ LANGUAGE plpgsql;
|
|
535
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/09-function-channel-policy-clear.ts",
|
|
537
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/09-function-channel-policy-clear.ts",k={name:E(__filename),sql:(e)=>{return[a`
|
|
536
538
|
CREATE FUNCTION ${n(e.schema)}."channel_policy_clear" (
|
|
537
539
|
p_name TEXT
|
|
538
540
|
) RETURNS VOID AS $$
|
|
@@ -564,4 +566,4 @@ var s=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),J=(e)=
|
|
|
564
566
|
PERFORM ${n(e.schema)}."wake"(0);
|
|
565
567
|
END;
|
|
566
568
|
$$ LANGUAGE plpgsql;
|
|
567
|
-
`]}};class
|
|
569
|
+
`]}};class i{value;isSet;constructor(){this.isSet=!1,this.value=null}get(){return this.isSet?{resultType:"RESULT_SET",value:this.value}:{resultType:"RESULT_NOT_SET"}}set(e){this.isSet=!0,this.value=e}}class S{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}create(e){let t=new m({schema:this.schema,channelName:this.channelName,name:e.name,content:e.content,lockMs:e.lockMs,delayMs:e.delayMs}),_=new i;return this.registerFn({sortKey:JSON.stringify([t.channelName,t.name,t.createdAt.toISOString()]),execute:(c)=>t.execute(c).then((l)=>_.set(l))}),_}}class g{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}set(e){let t=new o({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,maxSize:e.maxSize,releaseIntervalMs:e.releaseIntervalMs}),_=new i;return this.registerFn({sortKey:JSON.stringify([t.channelName,null,t.createdAt.toISOString()]),execute:(c)=>t.execute(c).then((l)=>_.set(l))}),_}clear(){let e=new r({schema:this.schema,channelName:this.channelName}),t=new i;return this.registerFn({sortKey:JSON.stringify([e.channelName,null,e.createdAt.toISOString()]),execute:(_)=>e.execute(_).then((c)=>t.set(c))}),t}}class I{policy;message;constructor(e){this.message=new S(e),this.policy=new g(e)}}var Z=(e,t)=>{return e.sortKey.localeCompare(t.sortKey)};class O{commands;schema;constructor(e){this.commands=[],this.schema=e.schema}channel(e){return new I({schema:this.schema,channelName:e,registerFn:(t)=>{this.commands.push(t)}})}async execute(e){for(let t of this.commands.sort(Z))await t.execute(e.databaseClient)}}class A{schema;channelName;constructor(e){this.schema=e.schema,this.channelName=e.channelName}async create(e){return new m({schema:this.schema,channelName:this.channelName,name:e.name,content:e.content,lockMs:e.lockMs,delayMs:e.delayMs}).execute(e.databaseClient)}}class L{schema;channelName;constructor(e){this.schema=e.schema,this.channelName=e.channelName}set(e){return new o({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,maxSize:e.maxSize,releaseIntervalMs:e.releaseIntervalMs}).execute(e.databaseClient)}clear(e){return new r({schema:this.schema,channelName:this.channelName}).execute(e.databaseClient)}}class v{policy;message;constructor(e){this.message=new A({schema:e.schema,channelName:e.channelName}),this.policy=new L({schema:e.schema,channelName:e.channelName})}}class D{schema;id;channelName;name;content;dequeueNonce;state;numAttempts;constructor(e){this.schema=e.schema,this.id=e.id,this.channelName=e.channelName,this.dequeueNonce=e.dequeueNonce,this.name=e.name,this.content=e.content,this.state=e.state,this.numAttempts=e.numAttempts}async defer(e){return new d({schema:this.schema,id:this.id,dequeueNonce:this.dequeueNonce,delayMs:e.delayMs,state:e.state}).execute(e.databaseClient)}async delete(e){return new T({schema:this.schema,id:this.id,dequeueNonce:this.dequeueNonce}).execute(e.databaseClient)}}class z{schema;constructor(e){this.schema=e}async dequeue(e){let _=await new N({schema:this.schema}).execute(e.databaseClient);if(_.resultType==="MESSAGE_DEQUEUED")return{resultType:"MESSAGE_DEQUEUED",message:new D({schema:this.schema,id:_.message.id,dequeueNonce:_.message.dequeueNonce,channelName:_.message.channelName,name:_.message.name,content:_.message.content,state:_.message.state,numAttempts:_.message.numAttempts})};else return _}channel(e){return new v({schema:this.schema,channelName:e})}batch(){return new O({schema:this.schema})}migrations(e){return[G,B,P,H,q,C,$,F,b,k].map((t)=>({name:t.name,sql:t.sql({schema:this.schema,useWake:e.useWake??U}).map((_)=>M(_.value))})).sort((t,_)=>t.name.localeCompare(_.name))}wakeChannel(){return u.toString(this.schema)}}export{z as Queue,N as MessageDequeueCommand,T as MessageDeleteCommand,d as MessageDeferCommand,m as MessageCreateCommand,o as ChannelPolicySetCommand,r as ChannelPolicyClearCommand};
|