@ez4/local-queue 0.22.0
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/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/main.cjs +21 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.mjs +18 -0
- package/dist/provider/emulator.d.ts +12 -0
- package/dist/provider/register.d.ts +1 -0
- package/dist/service/client.d.ts +4 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Silas B.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/main.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var a=(e,t)=>c(e,"name",{value:t,configurable:!0});var q=(e,t)=>{for(var r in t)c(e,r,{get:t[r],enumerable:!0})},x=(e,t,r,s)=>{if(t&&
|
|
2
|
+
typeof t=="object"||typeof t=="function")for(let o of E(t))!M.call(e,o)&&o!==r&&
|
|
3
|
+
c(e,o,{get:()=>t[o],enumerable:!(s=w(t,o))||s.enumerable});return e};var C=e=>x(c({},"__esModule",{value:!0}),e);var O={};q(O,{registerTriggers:()=>T});module.exports=C(O);var h=require("@ez4/project/library");var i=require("@ez4/local-common"),p=require("@ez4/utils"),d=require("@ez4/project/library"),
|
|
4
|
+
f=require("@ez4/queue/utils");var l=require("@ez4/queue/utils"),g=require("@ez4/project/library");var S=a((e,t,r)=>{let s=(0,g.getServiceName)(e,r),o=`http://${r.host}/${s}`;return new class{async sendMessage(n){
|
|
5
|
+
let u=await(0,l.getJsonStringMessage)(n,t);if(!(await fetch(o,{method:"POST",body:u,
|
|
6
|
+
headers:{"content-type":"application/json"}})).ok)throw new Error(`Queue ${e} is\
|
|
7
|
+
n't available.`)}async receiveMessage(){throw new Error("Receive message isn't s\
|
|
8
|
+
upported yet.")}}},"createQueueClient");var y=a((e,t,r)=>{let{name:s,schema:o}=e;return{type:"Queue",name:s,identifier:(0,d.getServiceName)(
|
|
9
|
+
s,t),clientHandler:a(()=>S(s,o,t),"clientHandler"),requestHandler:a(n=>R(e,r,n),
|
|
10
|
+
"requestHandler")}},"registerQueueServices"),R=a(async(e,t,r)=>{if(r.method!=="P\
|
|
11
|
+
OST"||r.path!=="/"||!r.body)throw new Error("Unsupported queue request.");let s=(0,p.getRandomInteger)(
|
|
12
|
+
0,e.subscriptions.length-1),o=e.subscriptions[s];return await z(e,t,o,r.body),{status:204}},
|
|
13
|
+
"handleQueueMessage"),z=a(async(e,t,r,s)=>{let o=await(0,i.createModule)({listener:r.
|
|
14
|
+
listener,handler:r.handler}),n=e.services&&t.makeClients(e.services),u={requestId:(0,p.getRandomUUID)()};
|
|
15
|
+
try{await(0,i.onBegin)(o,n,u);let m=JSON.parse(s.toString()),b=await(0,f.getJsonMessage)(
|
|
16
|
+
m,e.schema);Object.assign(u,{message:b}),await(0,i.onReady)(o,n,u),await o.handler(
|
|
17
|
+
u,n)}catch(m){await(0,i.onError)(o,n,u,m)}finally{await(0,i.onEnd)(o,n,u)}},"pro\
|
|
18
|
+
cessLambdaMessage");var Q=require("@ez4/queue/library");var v=!1,T=a(()=>{v||((0,h.createTrigger)("@ez4/local-queue",{"emulator:getServi\
|
|
19
|
+
ces":a(({service:e,options:t,context:r})=>(0,Q.isQueueService)(e)?y(e,t,r):null,
|
|
20
|
+
"emulator:getServices")}),v=!0)},"registerTriggers");0&&(module.exports={registerTriggers});
|
|
21
|
+
//# sourceMappingURL=main.cjs.map
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './provider/register.js';
|
package/dist/main.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var g=Object.defineProperty;var s=(e,r)=>g(e,"name",{value:r,configurable:!0});import{createTrigger as C}from"@ez4/project/library";import{createModule as f,onBegin as y,onEnd as v,onError as h,onReady as Q}from"@ez4/local-common";
|
|
2
|
+
import{getRandomInteger as b,getRandomUUID as w}from"@ez4/utils";import{getServiceName as E}from"@ez4/project/library";
|
|
3
|
+
import{getJsonMessage as M}from"@ez4/queue/utils";import{getJsonStringMessage as S}from"@ez4/queue/utils";import{getServiceName as d}from"@ez4/project/library";var m=s((e,r,t)=>{let a=d(e,t),o=`http://${t.host}/${a}`;return new class{async sendMessage(i){
|
|
4
|
+
let n=await S(i,r);if(!(await fetch(o,{method:"POST",body:n,headers:{"content-ty\
|
|
5
|
+
pe":"application/json"}})).ok)throw new Error(`Queue ${e} isn't available.`)}async receiveMessage(){
|
|
6
|
+
throw new Error("Receive message isn't supported yet.")}}},"createQueueClient");var c=s((e,r,t)=>{let{name:a,schema:o}=e;return{type:"Queue",name:a,identifier:E(
|
|
7
|
+
a,r),clientHandler:s(()=>m(a,o,r),"clientHandler"),requestHandler:s(i=>q(e,t,i),
|
|
8
|
+
"requestHandler")}},"registerQueueServices"),q=s(async(e,r,t)=>{if(t.method!=="P\
|
|
9
|
+
OST"||t.path!=="/"||!t.body)throw new Error("Unsupported queue request.");let a=b(
|
|
10
|
+
0,e.subscriptions.length-1),o=e.subscriptions[a];return await x(e,r,o,t.body),{status:204}},
|
|
11
|
+
"handleQueueMessage"),x=s(async(e,r,t,a)=>{let o=await f({listener:t.listener,handler:t.
|
|
12
|
+
handler}),i=e.services&&r.makeClients(e.services),n={requestId:w()};try{await y(
|
|
13
|
+
o,i,n);let u=JSON.parse(a.toString()),l=await M(u,e.schema);Object.assign(n,{message:l}),
|
|
14
|
+
await Q(o,i,n),await o.handler(n,i)}catch(u){await h(o,i,n,u)}finally{await v(o,
|
|
15
|
+
i,n)}},"processLambdaMessage");import{isQueueService as R}from"@ez4/queue/library";var p=!1,F=s(()=>{p||(C("@ez4/local-queue",{"emulator:getServices":s(({service:e,
|
|
16
|
+
options:r,context:t})=>R(e)?c(e,r,t):null,"emulator:getServices")}),p=!0)},"regi\
|
|
17
|
+
sterTriggers");export{F as registerTriggers};
|
|
18
|
+
//# sourceMappingURL=main.mjs.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EmulateServiceContext, EmulatorServiceRequest, ServeOptions } from '@ez4/project/library';
|
|
2
|
+
import type { QueueService } from '@ez4/queue/library';
|
|
3
|
+
import type { Queue } from '@ez4/queue';
|
|
4
|
+
export declare const registerQueueServices: (service: QueueService, options: ServeOptions, context: EmulateServiceContext) => {
|
|
5
|
+
type: string;
|
|
6
|
+
name: string;
|
|
7
|
+
identifier: string;
|
|
8
|
+
clientHandler: () => import("@ez4/queue").Client<Queue.Service<any>>;
|
|
9
|
+
requestHandler: (request: EmulatorServiceRequest) => Promise<{
|
|
10
|
+
status: number;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const registerTriggers: () => void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Client, Queue } from '@ez4/queue';
|
|
2
|
+
import type { ServeOptions } from '@ez4/project/library';
|
|
3
|
+
import type { MessageSchema } from '@ez4/queue/utils';
|
|
4
|
+
export declare const createQueueClient: <T extends Queue.Service<any>>(serviceName: string, messageSchema: MessageSchema, serveOptions: ServeOptions) => Client<T>;
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ez4/local-queue",
|
|
3
|
+
"description": "EZ4: Local queue emulator",
|
|
4
|
+
"version": "0.22.0",
|
|
5
|
+
"author": "Silas B.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"ez4",
|
|
10
|
+
"ez4-local"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/sbalmt/ez4.git",
|
|
15
|
+
"directory": "providers/local/local-queue"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=22.7"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/main.d.ts",
|
|
23
|
+
"require": "./dist/main.cjs",
|
|
24
|
+
"import": "./dist/main.mjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"workspaces": [
|
|
28
|
+
"packages/*",
|
|
29
|
+
"providers/local/*"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"clean": "rm -f *.tsbuildinfo && rm -rf dist/*",
|
|
33
|
+
"build": "tsc -p tsconfig.json && node tools/bundler.mjs",
|
|
34
|
+
"test": "npm run test:types && node --test --import ../../../tools/tsnode.mjs test/*.spec.ts",
|
|
35
|
+
"test:only": "npm run test:types && node --test-only --test --import ../../../tools/tsnode.mjs test/*.spec.ts",
|
|
36
|
+
"test:types": "npm run build && tsc -p tsconfig.test.json",
|
|
37
|
+
"local:publish": "npm run build && npm run clean:registry && npm publish --registry http://localhost:4873",
|
|
38
|
+
"clean:registry": "rm -rf ../../../.registry/@ez4/local-queue",
|
|
39
|
+
"live:publish": "npm run test && npm publish --access public"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@ez4/common": "^0.22.0",
|
|
43
|
+
"@ez4/local-common": "^0.22.0",
|
|
44
|
+
"@ez4/project": "^0.22.0",
|
|
45
|
+
"@ez4/queue": "^0.22.0",
|
|
46
|
+
"@ez4/utils": "^0.22.0"
|
|
47
|
+
}
|
|
48
|
+
}
|