@bitspacerlabs/rabbit-relay 0.5.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/.github/workflows/deploy.yml +66 -0
- package/.vscode/settings.json +3 -0
- package/LICENSE +21 -0
- package/README.md +90 -0
- package/assets/logo.svg +154 -0
- package/dist/cjs/config.d.ts +5 -0
- package/dist/cjs/config.js +120 -0
- package/dist/cjs/eventFactories.d.ts +31 -0
- package/dist/cjs/eventFactories.js +54 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +20 -0
- package/dist/cjs/pluginManager.d.ts +13 -0
- package/dist/cjs/pluginManager.js +27 -0
- package/dist/cjs/rabbitmqBroker.d.ts +62 -0
- package/dist/cjs/rabbitmqBroker.js +403 -0
- package/dist/cjs/utils/dedupe.d.ts +12 -0
- package/dist/cjs/utils/dedupe.js +56 -0
- package/dist/esm/config.d.ts +5 -0
- package/dist/esm/config.js +120 -0
- package/dist/esm/eventFactories.d.ts +31 -0
- package/dist/esm/eventFactories.js +54 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/pluginManager.d.ts +13 -0
- package/dist/esm/pluginManager.js +27 -0
- package/dist/esm/rabbitmqBroker.d.ts +62 -0
- package/dist/esm/rabbitmqBroker.js +403 -0
- package/dist/esm/utils/dedupe.d.ts +12 -0
- package/dist/esm/utils/dedupe.js +56 -0
- package/package.json +63 -0
- package/release.sh +106 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeMemoryDedupe = makeMemoryDedupe;
|
|
4
|
+
function makeMemoryDedupe(opts = {}) {
|
|
5
|
+
var _a, _b, _c, _d, _e;
|
|
6
|
+
const ttl = Number((_b = (_a = process.env.DEDUPE_TTL_MS) !== null && _a !== void 0 ? _a : opts.ttlMs) !== null && _b !== void 0 ? _b : 10 * 60 * 1000);
|
|
7
|
+
const max = Number((_d = (_c = process.env.DEDUPE_MAX_KEYS) !== null && _c !== void 0 ? _c : opts.maxKeys) !== null && _d !== void 0 ? _d : 100000);
|
|
8
|
+
const keyOf = (_e = opts.keyOf) !== null && _e !== void 0 ? _e : ((e) => {
|
|
9
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
10
|
+
return (_f = (_c = (_a = e === null || e === void 0 ? void 0 : e.id) !== null && _a !== void 0 ? _a : (_b = e === null || e === void 0 ? void 0 : e.meta) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : (_e = (_d = e === null || e === void 0 ? void 0 : e.meta) === null || _d === void 0 ? void 0 : _d.headers) === null || _e === void 0 ? void 0 : _e.messageId) !== null && _f !== void 0 ? _f : (_g = e === null || e === void 0 ? void 0 : e.meta) === null || _g === void 0 ? void 0 : _g.corrId;
|
|
11
|
+
});
|
|
12
|
+
const map = new Map();
|
|
13
|
+
function gc(now = Date.now()) {
|
|
14
|
+
// TTL cleanup
|
|
15
|
+
for (const [k, exp] of map) {
|
|
16
|
+
if (exp <= now)
|
|
17
|
+
map.delete(k);
|
|
18
|
+
}
|
|
19
|
+
// Size guard (simple LRU-ish by expiration)
|
|
20
|
+
if (map.size > max) {
|
|
21
|
+
const arr = [...map.entries()].sort((a, b) => a[1] - b[1]); // means oldest first
|
|
22
|
+
const toRemove = map.size - max;
|
|
23
|
+
for (let i = 0; i < toRemove; i++)
|
|
24
|
+
map.delete(arr[i][0]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function remember(id) {
|
|
28
|
+
const now = Date.now();
|
|
29
|
+
gc(now);
|
|
30
|
+
map.set(id, now + ttl);
|
|
31
|
+
}
|
|
32
|
+
function seen(id) {
|
|
33
|
+
const exp = map.get(id);
|
|
34
|
+
const now = Date.now();
|
|
35
|
+
if (exp && exp > now)
|
|
36
|
+
return true;
|
|
37
|
+
if (exp)
|
|
38
|
+
map.delete(id);
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
seen,
|
|
43
|
+
checkAndRemember(e) {
|
|
44
|
+
const id = typeof e === "string" ? e : keyOf(e);
|
|
45
|
+
if (!id)
|
|
46
|
+
return true; // nothing to de-dupe on -> treat as new one
|
|
47
|
+
if (seen(id))
|
|
48
|
+
return false;
|
|
49
|
+
remember(id);
|
|
50
|
+
return true;
|
|
51
|
+
},
|
|
52
|
+
size() {
|
|
53
|
+
return map.size;
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bitspacerlabs/rabbit-relay",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "A RabbitMQ-based event framework",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "./dist/cjs/index.js",
|
|
7
|
+
"module": "./dist/esm/index.js",
|
|
8
|
+
"types": "./dist/cjs/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"require": "./dist/cjs/index.js",
|
|
19
|
+
"import": "./dist/esm/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./dedupe": {
|
|
22
|
+
"require": "./dist/cjs/utils/dedupe.js",
|
|
23
|
+
"import": "./dist/esm/utils/dedupe.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "npm run build:cjs && npm run build:esm",
|
|
28
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
29
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
30
|
+
"prepublishOnly": "npm run build",
|
|
31
|
+
"docs:dev": "vitepress dev docs",
|
|
32
|
+
"docs:build": "vitepress build docs",
|
|
33
|
+
"docs:preview": "vitepress preview docs"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"rabbitmq",
|
|
37
|
+
"rabbit-relay",
|
|
38
|
+
"amqplib",
|
|
39
|
+
"amqp",
|
|
40
|
+
"events",
|
|
41
|
+
"messaging"
|
|
42
|
+
],
|
|
43
|
+
"author": "BitSpacer Labs",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/bitspacerlabs/rabbit-relay.git"
|
|
47
|
+
},
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/bitspacerlabs/rabbit-relay/issues"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://github.com/bitspacerlabs/rabbit-relay#readme",
|
|
52
|
+
"license": "MIT",
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"amqplib": "^0.10.5",
|
|
55
|
+
"uuid": "^11.1.0"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@types/amqplib": "^0.10.8",
|
|
59
|
+
"ts-node-dev": "^2.0.0",
|
|
60
|
+
"typescript": "^5.8.3",
|
|
61
|
+
"vitepress": "^2.0.0-alpha.12"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/release.sh
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
REGISTRY_URL="http://localhost:4873"
|
|
5
|
+
PKG_NAME="rabbit-relay"
|
|
6
|
+
TMP_DIR="/tmp/rr-test"
|
|
7
|
+
|
|
8
|
+
ts() {
|
|
9
|
+
date +"%Y-%m-%d %H:%M:%S"
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
log() {
|
|
13
|
+
echo "[$(ts)] $*"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
section() {
|
|
17
|
+
echo
|
|
18
|
+
echo "============================================================"
|
|
19
|
+
echo "[$(ts)] $*"
|
|
20
|
+
echo "============================================================"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
section "1. Build (clean & deterministic)"
|
|
24
|
+
|
|
25
|
+
log "Removing dist/"
|
|
26
|
+
rm -rf dist
|
|
27
|
+
|
|
28
|
+
log "Running build"
|
|
29
|
+
npm run build
|
|
30
|
+
|
|
31
|
+
log "Verifying build output"
|
|
32
|
+
ls -d dist/cjs dist/esm
|
|
33
|
+
|
|
34
|
+
section "2. Runtime Tests"
|
|
35
|
+
|
|
36
|
+
log "Testing CommonJS build"
|
|
37
|
+
node -e "
|
|
38
|
+
const { RabbitMQBroker } = require('./dist/cjs');
|
|
39
|
+
if (typeof RabbitMQBroker !== 'function') {
|
|
40
|
+
throw new Error('CJS export invalid');
|
|
41
|
+
}
|
|
42
|
+
console.log('CJS OK');
|
|
43
|
+
"
|
|
44
|
+
|
|
45
|
+
log "Testing ESM build"
|
|
46
|
+
node --input-type=module -e "
|
|
47
|
+
import { RabbitMQBroker } from './dist/esm/index.js';
|
|
48
|
+
if (typeof RabbitMQBroker !== 'function') {
|
|
49
|
+
throw new Error('ESM export invalid');
|
|
50
|
+
}
|
|
51
|
+
console.log('ESM OK');
|
|
52
|
+
"
|
|
53
|
+
|
|
54
|
+
section "3. Inspect package contents (npm pack)"
|
|
55
|
+
|
|
56
|
+
log "Running npm pack"
|
|
57
|
+
TARBALL=$(npm pack | tail -n 1)
|
|
58
|
+
|
|
59
|
+
log "Created tarball: $TARBALL"
|
|
60
|
+
|
|
61
|
+
log "Inspecting tarball contents"
|
|
62
|
+
tar -tf "$TARBALL"
|
|
63
|
+
|
|
64
|
+
log "Validating tarball does NOT contain forbidden paths"
|
|
65
|
+
if tar -tf "$TARBALL" | grep -E '^(docs/|examples/|lib/|\.vitepress/)'; then
|
|
66
|
+
echo
|
|
67
|
+
echo "orbidden files detected in package!"
|
|
68
|
+
exit 1
|
|
69
|
+
fi
|
|
70
|
+
|
|
71
|
+
log "Tarball content OK"
|
|
72
|
+
|
|
73
|
+
section "4. Publish to private registry"
|
|
74
|
+
|
|
75
|
+
log "Publishing to $REGISTRY_URL"
|
|
76
|
+
npm publish --registry "$REGISTRY_URL"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
section "5. Verify as consumer"
|
|
80
|
+
|
|
81
|
+
log "Preparing clean consumer test directory"
|
|
82
|
+
rm -rf "$TMP_DIR"
|
|
83
|
+
mkdir -p "$TMP_DIR"
|
|
84
|
+
cd "$TMP_DIR"
|
|
85
|
+
|
|
86
|
+
log "Initializing test package"
|
|
87
|
+
npm init -y >/dev/null
|
|
88
|
+
|
|
89
|
+
log "Installing $PKG_NAME from private registry"
|
|
90
|
+
npm install "$PKG_NAME" --registry "$REGISTRY_URL"
|
|
91
|
+
|
|
92
|
+
log "Testing CommonJS consumer"
|
|
93
|
+
node -e "
|
|
94
|
+
const { RabbitMQBroker } = require('$PKG_NAME');
|
|
95
|
+
console.log('Installed CJS OK:', RabbitMQBroker.name);
|
|
96
|
+
"
|
|
97
|
+
|
|
98
|
+
log "Testing ESM consumer"
|
|
99
|
+
node --input-type=module -e "
|
|
100
|
+
import { RabbitMQBroker } from '$PKG_NAME';
|
|
101
|
+
console.log('Installed ESM OK:', RabbitMQBroker.name);
|
|
102
|
+
"
|
|
103
|
+
|
|
104
|
+
section "Release completed successfully"
|
|
105
|
+
|
|
106
|
+
log "Package $PKG_NAME published and verified from $REGISTRY_URL"
|