samanbayaka 0.0.3 → 0.0.8
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/bash/sbk.sh +1 -1
- package/commit-hash.mjs +1 -0
- package/config/broker.mjs +1 -1
- package/gateway.mjs +2 -5
- package/helper/utility/node-argv.mjs +1 -1
- package/index.mjs +25 -39
- package/package.json +9 -5
- package/.gitlab-ci.yml +0 -33
- package/pnpm-workspace.yaml +0 -2
package/bash/sbk.sh
CHANGED
package/commit-hash.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const COMMIT_HASH = 'cbe6bca';
|
package/config/broker.mjs
CHANGED
package/gateway.mjs
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
/*index.mjs*/
|
|
2
|
-
import path from "path"
|
|
3
|
-
import url from "url"
|
|
4
|
-
|
|
5
2
|
import ApiGateway from "moleculer-web"
|
|
6
3
|
import OpenApi from "moleculer-auto-openapi"
|
|
7
4
|
import cookieParser from "cookie-parser"
|
|
8
5
|
import helmet from "helmet"
|
|
9
6
|
import compression from "compression"
|
|
10
7
|
|
|
11
|
-
import
|
|
8
|
+
import sbk from "./index.mjs"
|
|
12
9
|
import {
|
|
13
10
|
getConfig,
|
|
14
11
|
assetPath
|
|
@@ -18,7 +15,7 @@ import {formatApiGwErrors} from '#hUti/format-errors.mjs'
|
|
|
18
15
|
const CONFIG = await getConfig('server')
|
|
19
16
|
|
|
20
17
|
|
|
21
|
-
await sbk
|
|
18
|
+
await sbk.msgBus({
|
|
22
19
|
name: "gateway",
|
|
23
20
|
mixins: [
|
|
24
21
|
ApiGateway,
|
|
@@ -22,7 +22,7 @@ export const serviceName = argv.find(el => /^[a-z0-9]+(-[a-z0-9]+)*$/i.test(el))
|
|
|
22
22
|
*/
|
|
23
23
|
if (serviceName === undefined) {
|
|
24
24
|
console.error("Error: Service name is missing.")
|
|
25
|
-
console.log("Please run
|
|
25
|
+
console.log("Please run the command:\n $NODE_ENV=<prod/test/dev> node index.mjs <service name>")
|
|
26
26
|
process.exit(1)
|
|
27
27
|
}
|
|
28
28
|
|
package/index.mjs
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
/*index.mjs*/
|
|
2
|
-
import path from "path"
|
|
3
|
-
import url from "url"
|
|
4
|
-
import fs from "fs"
|
|
5
|
-
|
|
6
2
|
import { ServiceBroker } from "moleculer"
|
|
7
|
-
import { execSync } from "child_process"
|
|
8
3
|
|
|
4
|
+
import {COMMIT_HASH} from "./commit-hash.mjs"
|
|
9
5
|
import {
|
|
10
6
|
isReplEnabled,
|
|
11
7
|
isHotReloadEnabled,
|
|
@@ -19,17 +15,11 @@ import {
|
|
|
19
15
|
} from '#hFil/esm-loading.mjs'
|
|
20
16
|
import AjvValidator from "#hVal/AjvValidator.mjs"
|
|
21
17
|
|
|
18
|
+
|
|
22
19
|
const BROKER_CONFIG = await getConfig('broker')
|
|
23
20
|
const NATS_CONFIG = await getConfig('nats')
|
|
24
21
|
const LOGGER_CONFIG = await getConfig('logger')
|
|
25
22
|
|
|
26
|
-
/**
|
|
27
|
-
* Last git commit hash in short form
|
|
28
|
-
*/
|
|
29
|
-
const gitCommitHs = execSync("git rev-parse --short HEAD")
|
|
30
|
-
.toString()
|
|
31
|
-
.trim()
|
|
32
|
-
|
|
33
23
|
|
|
34
24
|
/**
|
|
35
25
|
* Moleculer srvice broker configurations
|
|
@@ -38,9 +28,7 @@ const gitCommitHs = execSync("git rev-parse --short HEAD")
|
|
|
38
28
|
const broker = new ServiceBroker({
|
|
39
29
|
...{
|
|
40
30
|
...BROKER_CONFIG,
|
|
41
|
-
|
|
42
|
-
namespace: `${BROKER_CONFIG.namespace}-${gitCommitHs}`
|
|
43
|
-
}
|
|
31
|
+
namespace: `sbk-${process.env.NODE_ENV}-${COMMIT_HASH}`
|
|
44
32
|
},
|
|
45
33
|
...{
|
|
46
34
|
nodeID: nodeUid,
|
|
@@ -52,35 +40,33 @@ const broker = new ServiceBroker({
|
|
|
52
40
|
})
|
|
53
41
|
|
|
54
42
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// */
|
|
58
|
-
// await loadServices(broker)
|
|
43
|
+
export default {
|
|
44
|
+
msgBus: async (schema) => {
|
|
59
45
|
|
|
46
|
+
if (serviceName != schema.name) {
|
|
47
|
+
await broker.stop()
|
|
48
|
+
broker.logger.error('❖ SBK', "Service name and configuration do not match.")
|
|
49
|
+
process.exit(0)
|
|
50
|
+
return
|
|
51
|
+
}
|
|
60
52
|
|
|
61
|
-
|
|
62
|
-
// * Start broker with repl mode
|
|
63
|
-
// */
|
|
64
|
-
// if(isReplEnabled){
|
|
65
|
-
// broker.start().then(() => broker.repl())
|
|
66
|
-
// }
|
|
67
|
-
// else{
|
|
68
|
-
// broker.start()
|
|
69
|
-
// }
|
|
53
|
+
broker.createService(schema)
|
|
70
54
|
|
|
71
|
-
|
|
72
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Start broker with repl mode
|
|
57
|
+
*/
|
|
58
|
+
if(isReplEnabled){
|
|
59
|
+
broker.start().then(() => broker.repl())
|
|
60
|
+
}
|
|
61
|
+
else{
|
|
62
|
+
broker.start()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
},
|
|
66
|
+
eventBus: {
|
|
73
67
|
|
|
74
|
-
/**
|
|
75
|
-
* Start broker with repl mode
|
|
76
|
-
*/
|
|
77
|
-
if(isReplEnabled){
|
|
78
|
-
broker.start().then(() => broker.repl())
|
|
79
|
-
}
|
|
80
|
-
else{
|
|
81
|
-
broker.start()
|
|
82
68
|
}
|
|
83
|
-
}
|
|
69
|
+
}
|
|
84
70
|
|
|
85
71
|
|
|
86
72
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "samanbayaka",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Moleculer Gateway service with kafka transporter",
|
|
5
5
|
"homepage": "https://gitlab.com/dalal.suvendu/samanbayaka#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"main": "index.mjs",
|
|
23
23
|
"scripts": {
|
|
24
24
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
25
|
-
"start": "node index.mjs service_name"
|
|
25
|
+
"start": "NODE_ENV=dev node index.mjs service_name",
|
|
26
|
+
"prepare": "[ -d .git ] && husky install || true"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
29
|
"ajv": "^8.18.0",
|
|
@@ -31,13 +32,16 @@
|
|
|
31
32
|
"cookie-parser": "^1.4.7",
|
|
32
33
|
"helmet": "^8.1.0",
|
|
33
34
|
"kafkajs": "^2.2.4",
|
|
34
|
-
"moleculer": "
|
|
35
|
+
"moleculer": "0.15.0",
|
|
35
36
|
"moleculer-auto-openapi": "^1.1.7",
|
|
36
|
-
"moleculer-repl": "^0.
|
|
37
|
-
"moleculer-web": "^0.
|
|
37
|
+
"moleculer-repl": "^0.8.0",
|
|
38
|
+
"moleculer-web": "^0.11.0",
|
|
38
39
|
"msgpack5": "^6.0.2",
|
|
39
40
|
"nats": "^2.29.3",
|
|
40
41
|
"pnpm": "^10.32.1",
|
|
41
42
|
"swagger-stats": "^0.99.7"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"husky": "^9.1.7"
|
|
42
46
|
}
|
|
43
47
|
}
|
package/.gitlab-ci.yml
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
image: node:22
|
|
2
|
-
|
|
3
|
-
stages:
|
|
4
|
-
- install
|
|
5
|
-
- publish
|
|
6
|
-
|
|
7
|
-
cache:
|
|
8
|
-
paths:
|
|
9
|
-
- .pnpm-store
|
|
10
|
-
|
|
11
|
-
before_script:
|
|
12
|
-
- npm install -g pnpm
|
|
13
|
-
|
|
14
|
-
install:
|
|
15
|
-
stage: install
|
|
16
|
-
script:
|
|
17
|
-
# Install dependencies
|
|
18
|
-
- pnpm install --frozen-lockfile
|
|
19
|
-
|
|
20
|
-
publish:
|
|
21
|
-
stage: publish
|
|
22
|
-
script:
|
|
23
|
-
# Authenticate to npm
|
|
24
|
-
- echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
|
|
25
|
-
|
|
26
|
-
# Increase version in package.json
|
|
27
|
-
# - npm version patch --no-git-tag-version
|
|
28
|
-
|
|
29
|
-
# Publish package
|
|
30
|
-
- npm publish --access public
|
|
31
|
-
|
|
32
|
-
only:
|
|
33
|
-
- main
|
package/pnpm-workspace.yaml
DELETED