samanbayaka 0.0.2 → 0.0.7

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.
@@ -0,0 +1,9 @@
1
+ # 1. Bump patch version without creating git tag
2
+ npm version patch --no-git-tag-version
3
+
4
+ # 2. Write the latest short git commit hash to commit-hash.mjs
5
+ SHORT_HASH=$(git rev-parse --short HEAD)
6
+ echo "export const COMMIT_HASH = '$SHORT_HASH';" > commit-hash.mjs
7
+
8
+ # 3. Stage the changed files for commit
9
+ git add package.json commit-hash.mjs
package/bash/sbk.sh CHANGED
@@ -7,5 +7,5 @@
7
7
  ##Configurations files path
8
8
  $export SBK_CONFIG_PATH="/usr/local/etc/your_folder"
9
9
 
10
- ##web service port 8760-8769
10
+ ##web server port 8760-8769
11
11
  $export SBK_PORT=8765
@@ -0,0 +1 @@
1
+ export const COMMIT_HASH = '0aa5891';
package/config/broker.mjs CHANGED
@@ -4,7 +4,7 @@ export default Object.freeze({
4
4
  /**
5
5
  * Namespace of nodes to segment your nodes on the same network
6
6
  */
7
- namespace: "prod",
7
+ namespace: "sbk",
8
8
 
9
9
  /**
10
10
  * Timeouts
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 {sbk} from "./index.mjs"
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 ('nats', {
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 one of the following commands:\n $node your_file.mjs <service_name> -h (for hot reloading)\n $node your_file.mjs <service_name> --hot (for hot reloading)\n or \n $node your_file.mjs <service_name>")
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
- // * Loads modules asynchronously
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
- export const sbk = async (sBus, schema)=>{
72
- broker.createService(schema)
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.2",
3
+ "version": "0.0.7",
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",
@@ -39,5 +40,8 @@
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/package.json.bk DELETED
@@ -1,32 +0,0 @@
1
- {
2
- "name": "samanbayaka-gateway",
3
- "version": "0.0.1",
4
- "description": "Moleculer Gateway service with kafka transporter",
5
- "homepage": "https://gitlab.com/dalal.suvendu/samanbayaka#readme",
6
- "bugs": {
7
- "url": "https://gitlab.com/dalal.suvendu/samanbayaka/issues"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://gitlab.com/dalal.suvendu/samanbayaka.git"
12
- },
13
- "license": "ISC",
14
- "author": "dalal.suvendu",
15
- "type": "module",
16
- "main": "index.mjs",
17
- "scripts": {
18
- "test": "echo \"Error: no test specified\" && exit 1",
19
- "start": "node index.mjs service_name"
20
- },
21
- "dependencies": {
22
- "chokidar": "^4.0.3",
23
- "cookie-parser": "^1.4.7",
24
- "helmet": "^8.1.0",
25
- "kafkajs": "^2.2.4",
26
- "moleculer": "^0.14.35",
27
- "moleculer-auto-openapi": "^1.1.6",
28
- "moleculer-repl": "^0.7.4",
29
- "moleculer-web": "^0.10.8",
30
- "swagger-stats": "^0.99.7"
31
- }
32
- }
@@ -1,2 +0,0 @@
1
- onlyBuiltDependencies:
2
- - es5-ext
Binary file