ts-packages 5.0.0 → 5.1.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.
Files changed (245) hide show
  1. package/createTSPackage.mjs +201 -0
  2. package/package.json +4 -3
  3. package/packages/communication/core/README.md +345 -0
  4. package/packages/communication/core/dist/cjs/abstract/BaseCircuitBreaker.js +253 -0
  5. package/packages/communication/core/dist/cjs/abstract/BaseClient.js +298 -0
  6. package/packages/communication/core/dist/cjs/abstract/BaseCompressionManager.js +377 -0
  7. package/packages/communication/core/dist/cjs/abstract/BaseConnectionPool.js +543 -0
  8. package/packages/communication/core/dist/cjs/abstract/BaseInterceptor.js +235 -0
  9. package/packages/communication/core/dist/cjs/abstract/BaseLoadBalancer.js +269 -0
  10. package/packages/communication/core/dist/cjs/abstract/BaseProtocol.js +269 -0
  11. package/packages/communication/core/dist/cjs/abstract/BaseRetryStrategy.js +255 -0
  12. package/packages/communication/core/dist/cjs/abstract/BaseSerializer.js +341 -0
  13. package/packages/communication/core/dist/cjs/abstract/BaseServiceDiscoverer.js +254 -0
  14. package/packages/communication/core/dist/cjs/abstract/BaseTimeoutManager.js +295 -0
  15. package/packages/communication/core/dist/cjs/abstract/index.js +25 -0
  16. package/packages/communication/core/dist/cjs/errors/CircuitBreakerError.js +16 -0
  17. package/packages/communication/core/dist/cjs/errors/CommunicationError.js +15 -0
  18. package/packages/communication/core/dist/cjs/errors/ConnectionError.js +15 -0
  19. package/packages/communication/core/dist/cjs/errors/DiscoveryError.js +15 -0
  20. package/packages/communication/core/dist/cjs/errors/LoadBalancerError.js +15 -0
  21. package/packages/communication/core/dist/cjs/errors/ProtocolError.js +15 -0
  22. package/packages/communication/core/dist/cjs/errors/RetryError.js +16 -0
  23. package/packages/communication/core/dist/cjs/errors/SerializationError.js +15 -0
  24. package/packages/communication/core/dist/cjs/errors/ServiceUnavailableError.js +15 -0
  25. package/packages/communication/core/dist/cjs/errors/TimeoutError.js +16 -0
  26. package/packages/communication/core/dist/cjs/errors/communicationErrorCodes.js +35 -0
  27. package/packages/communication/core/dist/cjs/errors/index.js +31 -0
  28. package/packages/communication/core/dist/cjs/index.js +38 -0
  29. package/packages/communication/core/dist/cjs/interfaces/CircuitBreaker.interface.js +6 -0
  30. package/packages/communication/core/dist/cjs/interfaces/Client.interface.js +6 -0
  31. package/packages/communication/core/dist/cjs/interfaces/Compression.interface.js +6 -0
  32. package/packages/communication/core/dist/cjs/interfaces/ConnectionPool.interface.js +6 -0
  33. package/packages/communication/core/dist/cjs/interfaces/Interceptor.interface.js +6 -0
  34. package/packages/communication/core/dist/cjs/interfaces/LoadBalancer.interface.js +2 -0
  35. package/packages/communication/core/dist/cjs/interfaces/Protocol.interface.js +6 -0
  36. package/packages/communication/core/dist/cjs/interfaces/RetryStrategy.interface.js +6 -0
  37. package/packages/communication/core/dist/cjs/interfaces/Serializer.interface.js +2 -0
  38. package/packages/communication/core/dist/cjs/interfaces/ServiceDiscovery.interface.js +6 -0
  39. package/packages/communication/core/dist/cjs/interfaces/Timeout.interface.js +6 -0
  40. package/packages/communication/core/dist/cjs/interfaces/index.js +6 -0
  41. package/packages/communication/core/dist/cjs/types/config.js +6 -0
  42. package/packages/communication/core/dist/cjs/types/events.js +6 -0
  43. package/packages/communication/core/dist/cjs/types/index.js +6 -0
  44. package/packages/communication/core/dist/cjs/types/request.js +6 -0
  45. package/packages/communication/core/dist/cjs/types/response.js +6 -0
  46. package/packages/communication/core/dist/cjs/types/service.js +6 -0
  47. package/packages/communication/core/dist/cjs/utils.js +200 -0
  48. package/packages/communication/core/dist/esm/abstract/BaseCircuitBreaker.js +249 -0
  49. package/packages/communication/core/dist/esm/abstract/BaseClient.js +294 -0
  50. package/packages/communication/core/dist/esm/abstract/BaseCompressionManager.js +373 -0
  51. package/packages/communication/core/dist/esm/abstract/BaseConnectionPool.js +539 -0
  52. package/packages/communication/core/dist/esm/abstract/BaseInterceptor.js +231 -0
  53. package/packages/communication/core/dist/esm/abstract/BaseLoadBalancer.js +265 -0
  54. package/packages/communication/core/dist/esm/abstract/BaseProtocol.js +265 -0
  55. package/packages/communication/core/dist/esm/abstract/BaseRetryStrategy.js +251 -0
  56. package/packages/communication/core/dist/esm/abstract/BaseSerializer.js +337 -0
  57. package/packages/communication/core/dist/esm/abstract/BaseServiceDiscoverer.js +250 -0
  58. package/packages/communication/core/dist/esm/abstract/BaseTimeoutManager.js +291 -0
  59. package/packages/communication/core/dist/esm/abstract/index.js +11 -0
  60. package/packages/communication/core/dist/esm/errors/CircuitBreakerError.js +12 -0
  61. package/packages/communication/core/dist/esm/errors/CommunicationError.js +11 -0
  62. package/packages/communication/core/dist/esm/errors/ConnectionError.js +11 -0
  63. package/packages/communication/core/dist/esm/errors/DiscoveryError.js +11 -0
  64. package/packages/communication/core/dist/esm/errors/LoadBalancerError.js +11 -0
  65. package/packages/communication/core/dist/esm/errors/ProtocolError.js +11 -0
  66. package/packages/communication/core/dist/esm/errors/RetryError.js +12 -0
  67. package/packages/communication/core/dist/esm/errors/SerializationError.js +11 -0
  68. package/packages/communication/core/dist/esm/errors/ServiceUnavailableError.js +11 -0
  69. package/packages/communication/core/dist/esm/errors/TimeoutError.js +12 -0
  70. package/packages/communication/core/dist/esm/errors/communicationErrorCodes.js +32 -0
  71. package/packages/communication/core/dist/esm/errors/index.js +17 -0
  72. package/packages/communication/core/dist/esm/index.js +18 -0
  73. package/packages/communication/core/dist/esm/interfaces/CircuitBreaker.interface.js +5 -0
  74. package/packages/communication/core/dist/esm/interfaces/Client.interface.js +5 -0
  75. package/packages/communication/core/dist/esm/interfaces/Compression.interface.js +5 -0
  76. package/packages/communication/core/dist/esm/interfaces/ConnectionPool.interface.js +5 -0
  77. package/packages/communication/core/dist/esm/interfaces/Interceptor.interface.js +5 -0
  78. package/packages/communication/core/dist/esm/interfaces/LoadBalancer.interface.js +1 -0
  79. package/packages/communication/core/dist/esm/interfaces/Protocol.interface.js +5 -0
  80. package/packages/communication/core/dist/esm/interfaces/RetryStrategy.interface.js +5 -0
  81. package/packages/communication/core/dist/esm/interfaces/Serializer.interface.js +1 -0
  82. package/packages/communication/core/dist/esm/interfaces/ServiceDiscovery.interface.js +5 -0
  83. package/packages/communication/core/dist/esm/interfaces/Timeout.interface.js +5 -0
  84. package/packages/communication/core/dist/esm/interfaces/index.js +5 -0
  85. package/packages/communication/core/dist/esm/types/config.js +5 -0
  86. package/packages/communication/core/dist/esm/types/events.js +5 -0
  87. package/packages/communication/core/dist/esm/types/index.js +5 -0
  88. package/packages/communication/core/dist/esm/types/request.js +5 -0
  89. package/packages/communication/core/dist/esm/types/response.js +5 -0
  90. package/packages/communication/core/dist/esm/types/service.js +5 -0
  91. package/packages/communication/core/dist/esm/utils.js +193 -0
  92. package/packages/communication/core/dist/types/abstract/BaseCircuitBreaker.d.ts +167 -0
  93. package/packages/communication/core/dist/types/abstract/BaseClient.d.ts +197 -0
  94. package/packages/communication/core/dist/types/abstract/BaseCompressionManager.d.ts +180 -0
  95. package/packages/communication/core/dist/types/abstract/BaseConnectionPool.d.ts +210 -0
  96. package/packages/communication/core/dist/types/abstract/BaseInterceptor.d.ts +150 -0
  97. package/packages/communication/core/dist/types/abstract/BaseLoadBalancer.d.ts +167 -0
  98. package/packages/communication/core/dist/types/abstract/BaseProtocol.d.ts +163 -0
  99. package/packages/communication/core/dist/types/abstract/BaseRetryStrategy.d.ts +130 -0
  100. package/packages/communication/core/dist/types/abstract/BaseSerializer.d.ts +181 -0
  101. package/packages/communication/core/dist/types/abstract/BaseServiceDiscoverer.d.ts +161 -0
  102. package/packages/communication/core/dist/types/abstract/BaseTimeoutManager.d.ts +145 -0
  103. package/packages/communication/core/dist/types/abstract/index.d.ts +11 -0
  104. package/packages/communication/core/dist/types/errors/CircuitBreakerError.d.ts +8 -0
  105. package/packages/communication/core/dist/types/errors/CommunicationError.d.ts +10 -0
  106. package/packages/communication/core/dist/types/errors/ConnectionError.d.ts +9 -0
  107. package/packages/communication/core/dist/types/errors/DiscoveryError.d.ts +9 -0
  108. package/packages/communication/core/dist/types/errors/LoadBalancerError.d.ts +9 -0
  109. package/packages/communication/core/dist/types/errors/ProtocolError.d.ts +9 -0
  110. package/packages/communication/core/dist/types/errors/RetryError.d.ts +11 -0
  111. package/packages/communication/core/dist/types/errors/SerializationError.d.ts +9 -0
  112. package/packages/communication/core/dist/types/errors/ServiceUnavailableError.d.ts +12 -0
  113. package/packages/communication/core/dist/types/errors/TimeoutError.d.ts +11 -0
  114. package/packages/communication/core/dist/types/errors/communicationErrorCodes.d.ts +27 -0
  115. package/packages/communication/core/dist/types/errors/index.d.ts +11 -0
  116. package/packages/communication/core/dist/types/index.d.ts +13 -0
  117. package/packages/communication/core/dist/types/interfaces/CircuitBreaker.interface.d.ts +150 -0
  118. package/packages/communication/core/dist/types/interfaces/Client.interface.d.ts +153 -0
  119. package/packages/communication/core/dist/types/interfaces/Compression.interface.d.ts +190 -0
  120. package/packages/communication/core/dist/types/interfaces/ConnectionPool.interface.d.ts +191 -0
  121. package/packages/communication/core/dist/types/interfaces/Interceptor.interface.d.ts +220 -0
  122. package/packages/communication/core/dist/types/interfaces/LoadBalancer.interface.d.ts +153 -0
  123. package/packages/communication/core/dist/types/interfaces/Protocol.interface.d.ts +117 -0
  124. package/packages/communication/core/dist/types/interfaces/RetryStrategy.interface.d.ts +160 -0
  125. package/packages/communication/core/dist/types/interfaces/Serializer.interface.d.ts +176 -0
  126. package/packages/communication/core/dist/types/interfaces/ServiceDiscovery.interface.d.ts +189 -0
  127. package/packages/communication/core/dist/types/interfaces/Timeout.interface.d.ts +135 -0
  128. package/packages/communication/core/dist/types/interfaces/index.d.ts +15 -0
  129. package/packages/communication/core/dist/types/types/config.d.ts +540 -0
  130. package/packages/communication/core/dist/types/types/events.d.ts +204 -0
  131. package/packages/communication/core/dist/types/types/index.d.ts +9 -0
  132. package/packages/communication/core/dist/types/types/request.d.ts +143 -0
  133. package/packages/communication/core/dist/types/types/response.d.ts +155 -0
  134. package/packages/communication/core/dist/types/types/service.d.ts +279 -0
  135. package/packages/communication/core/dist/types/utils.d.ts +179 -0
  136. package/packages/communication/core/node_modules/.bin/rimraf +21 -0
  137. package/packages/communication/core/node_modules/.bin/tsc +21 -0
  138. package/packages/communication/core/node_modules/.bin/tsserver +21 -0
  139. package/packages/communication/core/package.json +90 -0
  140. package/packages/communication/core/src/abstract/BaseCircuitBreaker.ts +348 -0
  141. package/packages/communication/core/src/abstract/BaseClient.ts +437 -0
  142. package/packages/communication/core/src/abstract/BaseCompressionManager.ts +544 -0
  143. package/packages/communication/core/src/abstract/BaseConnectionPool.ts +700 -0
  144. package/packages/communication/core/src/abstract/BaseInterceptor.ts +351 -0
  145. package/packages/communication/core/src/abstract/BaseLoadBalancer.ts +387 -0
  146. package/packages/communication/core/src/abstract/BaseProtocol.ts +345 -0
  147. package/packages/communication/core/src/abstract/BaseRetryStrategy.ts +369 -0
  148. package/packages/communication/core/src/abstract/BaseSerializer.ts +505 -0
  149. package/packages/communication/core/src/abstract/BaseServiceDiscoverer.ts +345 -0
  150. package/packages/communication/core/src/abstract/BaseTimeoutManager.ts +379 -0
  151. package/packages/communication/core/src/abstract/index.ts +11 -0
  152. package/packages/communication/core/src/errors/CircuitBreakerError.ts +22 -0
  153. package/packages/communication/core/src/errors/CommunicationError.ts +20 -0
  154. package/packages/communication/core/src/errors/ConnectionError.ts +18 -0
  155. package/packages/communication/core/src/errors/DiscoveryError.ts +18 -0
  156. package/packages/communication/core/src/errors/LoadBalancerError.ts +18 -0
  157. package/packages/communication/core/src/errors/ProtocolError.ts +18 -0
  158. package/packages/communication/core/src/errors/RetryError.ts +22 -0
  159. package/packages/communication/core/src/errors/SerializationError.ts +18 -0
  160. package/packages/communication/core/src/errors/ServiceUnavailableError.ts +19 -0
  161. package/packages/communication/core/src/errors/TimeoutError.ts +22 -0
  162. package/packages/communication/core/src/errors/communicationErrorCodes.ts +40 -0
  163. package/packages/communication/core/src/errors/index.ts +20 -0
  164. package/packages/communication/core/src/index.ts +29 -0
  165. package/packages/communication/core/src/interfaces/CircuitBreaker.interface.ts +186 -0
  166. package/packages/communication/core/src/interfaces/Client.interface.ts +194 -0
  167. package/packages/communication/core/src/interfaces/Compression.interface.ts +249 -0
  168. package/packages/communication/core/src/interfaces/ConnectionPool.interface.ts +238 -0
  169. package/packages/communication/core/src/interfaces/Interceptor.interface.ts +288 -0
  170. package/packages/communication/core/src/interfaces/LoadBalancer.interface.ts +198 -0
  171. package/packages/communication/core/src/interfaces/Protocol.interface.ts +137 -0
  172. package/packages/communication/core/src/interfaces/RetryStrategy.interface.ts +207 -0
  173. package/packages/communication/core/src/interfaces/Serializer.interface.ts +230 -0
  174. package/packages/communication/core/src/interfaces/ServiceDiscovery.interface.ts +252 -0
  175. package/packages/communication/core/src/interfaces/Timeout.interface.ts +174 -0
  176. package/packages/communication/core/src/interfaces/index.ts +72 -0
  177. package/packages/communication/core/src/types/config.ts +757 -0
  178. package/packages/communication/core/src/types/events.ts +286 -0
  179. package/packages/communication/core/src/types/index.ts +89 -0
  180. package/packages/communication/core/src/types/request.ts +192 -0
  181. package/packages/communication/core/src/types/response.ts +211 -0
  182. package/packages/communication/core/src/types/service.ts +381 -0
  183. package/packages/communication/core/src/utils.ts +355 -0
  184. package/packages/communication/core/tsconfig.cjs.json +13 -0
  185. package/packages/communication/core/tsconfig.esm.json +12 -0
  186. package/packages/communication/core/tsconfig.json +17 -0
  187. package/packages/communication/core/tsconfig.types.json +16 -0
  188. package/packages/errors/output.txt +968 -0
  189. package/packages/server/README.md +123 -14
  190. package/packages/server/dist/cjs/index.d.ts +16 -10
  191. package/packages/server/dist/cjs/index.js +67 -76
  192. package/packages/server/dist/esm/index.d.ts +16 -10
  193. package/packages/server/dist/esm/index.js +21 -15
  194. package/packages/server/dist/types/index.d.ts +16 -10
  195. package/packages/server/package.json +22 -2
  196. package/packages/server/src/index.ts +22 -76
  197. package/packages/utils/README.md +228 -129
  198. package/packages/utils/dist/cjs/errors/CompressionError.js +19 -0
  199. package/packages/utils/dist/cjs/errors/ConnectionError.js +21 -0
  200. package/packages/utils/dist/cjs/errors/PoolError.js +20 -0
  201. package/packages/utils/dist/cjs/errors/TimeoutError.js +24 -0
  202. package/packages/utils/dist/cjs/errors/ValidationError.js +22 -0
  203. package/packages/utils/dist/cjs/errors/index.js +13 -0
  204. package/packages/utils/dist/cjs/index.js +2 -0
  205. package/packages/utils/dist/cjs/utils/compression.js +455 -0
  206. package/packages/utils/dist/cjs/utils/index.js +23 -2
  207. package/packages/utils/dist/cjs/utils/pool.js +375 -0
  208. package/packages/utils/dist/cjs/utils/timeout.js +133 -0
  209. package/packages/utils/dist/esm/errors/CompressionError.js +15 -0
  210. package/packages/utils/dist/esm/errors/ConnectionError.js +17 -0
  211. package/packages/utils/dist/esm/errors/PoolError.js +16 -0
  212. package/packages/utils/dist/esm/errors/TimeoutError.js +20 -0
  213. package/packages/utils/dist/esm/errors/ValidationError.js +18 -0
  214. package/packages/utils/dist/esm/errors/index.js +5 -0
  215. package/packages/utils/dist/esm/index.js +2 -0
  216. package/packages/utils/dist/esm/utils/compression.js +415 -0
  217. package/packages/utils/dist/esm/utils/index.js +13 -1
  218. package/packages/utils/dist/esm/utils/pool.js +370 -0
  219. package/packages/utils/dist/esm/utils/timeout.js +128 -0
  220. package/packages/utils/dist/types/errors/CompressionError.d.ts +8 -0
  221. package/packages/utils/dist/types/errors/ConnectionError.d.ts +9 -0
  222. package/packages/utils/dist/types/errors/PoolError.d.ts +8 -0
  223. package/packages/utils/dist/types/errors/TimeoutError.d.ts +12 -0
  224. package/packages/utils/dist/types/errors/ValidationError.d.ts +9 -0
  225. package/packages/utils/dist/types/errors/index.d.ts +5 -0
  226. package/packages/utils/dist/types/index.d.ts +1 -0
  227. package/packages/utils/dist/types/utils/compression.d.ts +164 -0
  228. package/packages/utils/dist/types/utils/index.d.ts +8 -0
  229. package/packages/utils/dist/types/utils/pool.d.ts +157 -0
  230. package/packages/utils/dist/types/utils/timeout.d.ts +64 -0
  231. package/packages/utils/package.json +7 -1
  232. package/packages/utils/src/errors/CompressionError.ts +25 -0
  233. package/packages/utils/src/errors/ConnectionError.ts +27 -0
  234. package/packages/utils/src/errors/PoolError.ts +25 -0
  235. package/packages/utils/src/errors/TimeoutError.ts +30 -0
  236. package/packages/utils/src/errors/ValidationError.ts +27 -0
  237. package/packages/utils/src/errors/index.ts +5 -0
  238. package/packages/utils/src/index.ts +3 -0
  239. package/packages/utils/src/utils/compression.ts +591 -0
  240. package/packages/utils/src/utils/index.ts +35 -1
  241. package/packages/utils/src/utils/pool.ts +512 -0
  242. package/packages/utils/src/utils/timeout.ts +186 -0
  243. package/pnpm-workspace.yaml +1 -0
  244. package/readme.md +24 -27
  245. package/packages/server/output.txt +0 -2634
@@ -0,0 +1,201 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'fs'
3
+ import path from 'path'
4
+
5
+ const fullPkgName = process.argv[2]
6
+
7
+ if (!fullPkgName) {
8
+ console.error('❌ Please provide a package name')
9
+ console.error('👉 Example: node create-ts-package.mjs @naman_deep_singh/utils')
10
+ process.exit(1)
11
+ }
12
+
13
+ /**
14
+ * @scope/pkg -> pkg
15
+ * pkg -> pkg
16
+ */
17
+ let pkgFolder = fullPkgName.includes('/')
18
+ ? fullPkgName.split('/').pop()
19
+ : fullPkgName
20
+
21
+ if (pkgFolder.includes('-')) {
22
+ pkgFolder = pkgFolder.split('-').pop()
23
+ }
24
+
25
+ const rootDir = path.join(process.cwd(), pkgFolder)
26
+ const srcDir = path.join(rootDir, 'src')
27
+
28
+ /* -----------------------------
29
+ * package.json
30
+ * ---------------------------- */
31
+ const packageJson = {
32
+ name: fullPkgName,
33
+ version: '1.0.0',
34
+ description: `${fullPkgName} package`,
35
+ type: 'module',
36
+ main: './dist/cjs/index.js',
37
+ module: './dist/esm/index.js',
38
+ types: './dist/types/index.d.ts',
39
+ exports: {
40
+ '.': {
41
+ "import": "./dist/esm/index.js",
42
+ "require": "./dist/cjs/index.js",
43
+ "types": "./dist/types/index.d.ts"
44
+ }
45
+ },
46
+ sideEffects: false,
47
+ files: ['dist', 'README.md'],
48
+ scripts: {
49
+ build: 'pnpm run build:types && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json',
50
+ 'build:types': 'tsc -p tsconfig.types.json',
51
+ clean: 'rimraf dist',
52
+ prepublishOnly: 'npm run clean && npm run build',
53
+ 'clean:js': 'find src -type f -name "*.js" -delete',
54
+ },
55
+ keywords: [],
56
+ author: 'Naman Deep Singh',
57
+ license: 'ISC',
58
+ packageManager: 'pnpm@10.20.0',
59
+ devDependencies: {
60
+ rimraf: '^5.0.5',
61
+ typescript: '^5.9.3',
62
+ },
63
+ dependencies: {
64
+ '@types/node': '^25.0.1',
65
+ },
66
+ publishConfig: {
67
+ access: 'public',
68
+ },
69
+ }
70
+
71
+ /* -----------------------------
72
+ * README.md
73
+ * ---------------------------- */
74
+ const readme = `# ${fullPkgName}
75
+
76
+ > Generated TypeScript package
77
+
78
+ ## Installation
79
+
80
+ \`\`\`sh
81
+ npm install ${fullPkgName}
82
+ \`\`\`
83
+
84
+ ## Usage
85
+
86
+ \`\`\`ts
87
+ import '${fullPkgName}'
88
+ \`\`\`
89
+ `
90
+
91
+ /* -----------------------------
92
+ * src/index.ts
93
+ * ---------------------------- */
94
+ const indexTs = `console.log('📦 ${fullPkgName} loaded')\n`
95
+
96
+ /* -----------------------------
97
+ * TS Configs
98
+ * ---------------------------- */
99
+ const tsConfigs = {
100
+ 'tsconfig.types.json': {
101
+ compilerOptions: {
102
+ target: 'ES2020',
103
+ module: 'NodeNext',
104
+ moduleResolution: 'NodeNext',
105
+ strict: true,
106
+ esModuleInterop: true,
107
+ skipLibCheck: false,
108
+ declaration: true,
109
+ emitDeclarationOnly: true,
110
+ outDir: 'dist/types',
111
+ },
112
+ include: ['src'],
113
+ },
114
+
115
+ 'tsconfig.cjs.json': {
116
+ compilerOptions: {
117
+ target: 'ES2020',
118
+ module: 'CommonJS',
119
+ moduleResolution: 'Node',
120
+ strict: true,
121
+ esModuleInterop: true,
122
+ outDir: 'dist/cjs',
123
+ },
124
+ include: ['src'],
125
+ },
126
+
127
+ 'tsconfig.esm.json': {
128
+ compilerOptions: {
129
+ target: 'ES2020',
130
+ module: 'ESNext',
131
+ moduleResolution: 'Bundler',
132
+ strict: true,
133
+ outDir: 'dist/esm',
134
+ },
135
+ include: ['src'],
136
+ },
137
+
138
+ 'tsconfig.json': {
139
+ compilerOptions: {
140
+ target: 'ES2020',
141
+ module: 'ESNext',
142
+ moduleResolution: 'Bundler',
143
+ strict: true,
144
+ esModuleInterop: true,
145
+ skipLibCheck: true,
146
+ },
147
+ include: ['src'],
148
+ exclude: ['dist', 'node_modules'],
149
+ },
150
+ }
151
+
152
+ /* -----------------------------
153
+ * Create folders
154
+ * ---------------------------- */
155
+ if (!fs.existsSync(rootDir)) {
156
+ fs.mkdirSync(rootDir, { recursive: true })
157
+ console.log(`📁 Created ${pkgFolder}/`)
158
+ }
159
+
160
+ if (!fs.existsSync(srcDir)) {
161
+ fs.mkdirSync(srcDir, { recursive: true })
162
+ console.log('📁 Created src/')
163
+ }
164
+
165
+ /* -----------------------------
166
+ * Write base files
167
+ * ---------------------------- */
168
+ const baseFiles = [
169
+ { name: 'package.json', content: JSON.stringify(packageJson, null, 2) },
170
+ { name: 'README.md', content: readme },
171
+ { name: 'src/index.ts', content: indexTs },
172
+ ]
173
+
174
+ for (const file of baseFiles) {
175
+ const filePath = path.join(rootDir, file.name)
176
+
177
+ if (fs.existsSync(filePath)) {
178
+ console.log(`⏭️ ${pkgFolder}/${file.name} already exists, skipping`)
179
+ continue
180
+ }
181
+
182
+ fs.writeFileSync(filePath, file.content, 'utf8')
183
+ console.log(`✅ Created ${pkgFolder}/${file.name}`)
184
+ }
185
+
186
+ /* -----------------------------
187
+ * Write TS configs
188
+ * ---------------------------- */
189
+ for (const [file, config] of Object.entries(tsConfigs)) {
190
+ const filePath = path.join(rootDir, file)
191
+
192
+ if (fs.existsSync(filePath)) {
193
+ console.log(`⏭️ ${pkgFolder}/${file} already exists, skipping`)
194
+ continue
195
+ }
196
+
197
+ fs.writeFileSync(filePath, JSON.stringify(config, null, 2), 'utf8')
198
+ console.log(`✅ Created ${pkgFolder}/${file}`)
199
+ }
200
+
201
+ console.log('🎉 TypeScript package scaffold complete')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-packages",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -14,13 +14,14 @@
14
14
  "scripts": {
15
15
  "test": "echo \"Error: no test specified\" && exit 1",
16
16
  "publish-cache-pkg": "pnpm --filter ./packages/cache build && pnpm --filter ./packages/cache publish",
17
+ "publish-communication-core-pkg": "pnpm --filter ./packages/communication/core build && pnpm --filter ./packages/communication/core publish",
17
18
  "publish-error-pkg": "pnpm --filter ./packages/errors build && pnpm --filter ./packages/errors publish",
18
19
  "publish-utils-pkg": "pnpm --filter ./packages/utils build && pnpm --filter ./packages/utils publish",
19
20
  "publish-response-pkg": "pnpm --filter ./packages/http-response build && pnpm --filter ./packages/http-response publish",
20
21
  "publish-server-pkg": "pnpm --filter ./packages/server build && pnpm --filter ./packages/server publish",
21
22
  "publish-security-pkg": "pnpm --filter ./packages/security build && pnpm --filter ./packages/security publish",
22
- "build": "pnpm --filter ./packages/cache build && pnpm --filter ./packages/errors build && pnpm --filter ./packages/utils build && pnpm --filter ./packages/http-response build && pnpm --filter ./packages/server build && pnpm --filter ./packages/security build",
23
- "publish-all-pkg": "pnpm publish-server-pkg && pnpm publish-response-pkg && pnpm publish-error-pkg && pnpm publish-utils-pkg && pnpm publish-security-pkg && pnpm publish-cache-pkg",
23
+ "build": "pnpm --filter ./packages/cache build && pnpm --filter ./packages/communication/core build && pnpm --filter ./packages/errors build && pnpm --filter ./packages/utils build && pnpm --filter ./packages/http-response build && pnpm --filter ./packages/server build && pnpm --filter ./packages/security build",
24
+ "publish-all-pkg": "pnpm publish-server-pkg && pnpm publish-response-pkg && pnpm publish-error-pkg && pnpm publish-utils-pkg && pnpm publish-security-pkg && pnpm publish-cache-pkg && pnpm publish-communication-core-pkg",
24
25
  "clear-cache": "pnpm store prune",
25
26
  "organize": "biome check packages/*/src --write",
26
27
  "organize-imports": "biome check packages/*/src --write",
@@ -0,0 +1,345 @@
1
+ # @naman_deep_singh/communication-core
2
+
3
+ > Core interfaces and abstract classes for building a comprehensive service-to-service communication layer in TypeScript
4
+
5
+ ## Overview
6
+
7
+ This package provides the foundational interfaces, abstract base classes, types, and utilities needed to build a complete microservices communication ecosystem. It serves as the architectural foundation for 5 specialized subpackages that handle different aspects of service communication.
8
+
9
+ ## Features
10
+
11
+ - 🔌 **Protocol Abstraction**: Unified interface for HTTP, gRPC, WebSocket protocols
12
+ - 🛡️ **Resilience Patterns**: Circuit breaker and retry strategy interfaces
13
+ - 🔍 **Service Discovery**: Dynamic service location and health monitoring
14
+ - ⚖️ **Load Balancing**: Traffic distribution strategies
15
+ - 🎯 **Unified Client**: Composable client that orchestrates all components
16
+ - 🔧 **Connection Pooling**: Built-in connection management with health checks
17
+ - 📊 **Observability**: Metrics, events, and health monitoring
18
+ - 🚦 **Interceptors**: Request/response middleware system
19
+ - ⚡ **TypeScript First**: Full type safety with strict import/export patterns
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install @naman_deep_singh/communication-core
25
+ ```
26
+
27
+ ## Core Interfaces
28
+
29
+ ### Communication Protocols
30
+ - **`IProtocol`**: Base interface for all communication protocols
31
+ - **`IConnectionPool`**: Connection pooling and lifecycle management
32
+ - **`IInterceptor`**: Request/response middleware
33
+
34
+ ### Resilience & Reliability
35
+ - **`ICircuitBreaker`**: Circuit breaker pattern for fault tolerance
36
+ - **`IRetryStrategy`**: Configurable retry mechanisms with backoff
37
+
38
+ ### Service Discovery & Load Balancing
39
+ - **`IServiceDiscoverer`**: Dynamic service instance discovery
40
+ - **`ILoadBalanceStrategy`**: Traffic distribution algorithms
41
+
42
+ ### Client Orchestration
43
+ - **`IClient`**: Main client interface that composes all components
44
+ - **`IClientFactory`**: Factory for creating and managing client instances
45
+
46
+ ## Abstract Base Classes
47
+
48
+ These classes provide common functionality and enforce consistent patterns:
49
+
50
+ ### Protocol Layer
51
+ - **`BaseProtocol`**: Common protocol functionality (connection pooling, metrics, error handling)
52
+ - **`BaseConnectionPool`**: Connection lifecycle, health checks, and resource management
53
+
54
+ ### Service Discovery
55
+ - **`BaseServiceDiscoverer`**: Caching, health monitoring, and event-driven updates
56
+
57
+ ## Type System
58
+
59
+ ### Core Types
60
+ - **`Request/Response`**: Standardized request/response objects
61
+ - **`ServiceInstance`**: Service endpoint representation
62
+ - **`ClientConfig`**: Comprehensive client configuration
63
+ - **`ConnectionPoolConfig`**: Connection pool settings
64
+
65
+ ### Configuration Types
66
+ - **`ProtocolConfig`**: Protocol-specific settings
67
+ - **`CircuitBreakerConfig`**: Circuit breaker thresholds and timeouts
68
+ - **`RetryConfig`**: Retry policies and backoff strategies
69
+ - **`LoadBalancerConfig`**: Load balancing algorithms and weights
70
+
71
+ ### Error Handling
72
+ - **`CommunicationError`**: Base error class with error codes and context
73
+ - **`ConnectionError`**: Connection-specific errors
74
+ - **`TimeoutError`**: Request timeout errors
75
+ - **`ServiceUnavailableError`**: Service discovery errors
76
+
77
+ ## Subpackage Architecture
78
+
79
+ This core package enables building 5 specialized subpackages:
80
+
81
+ ### 1. **@naman_deep_singh/communication-protocols**
82
+
83
+ **Purpose**: Protocol-specific implementations (HTTP, gRPC, WebSocket)
84
+
85
+ ```
86
+ communication-protocols/
87
+ ├── src/
88
+ │ ├── http/
89
+ │ │ ├── HttpProtocol.ts # extends BaseProtocol
90
+ │ │ ├── HttpConnectionPool.ts # extends BaseConnectionPool
91
+ │ │ └── HttpInterceptor.ts # implements IInterceptor
92
+ │ ├── grpc/
93
+ │ │ ├── GrpcProtocol.ts # extends BaseProtocol
94
+ │ │ ├── GrpcConnectionPool.ts # extends BaseConnectionPool
95
+ │ │ └── GrpcInterceptor.ts # implements IInterceptor
96
+ │ ├── websocket/
97
+ │ │ ├── WebSocketProtocol.ts # extends BaseProtocol
98
+ │ │ ├── WebSocketConnectionPool.ts
99
+ │ │ └── WebSocketInterceptor.ts
100
+ │ └── index.ts
101
+ ├── package.json
102
+ └── README.md
103
+ ```
104
+
105
+ **Key Dependencies**: `axios`, `@grpc/grpc-js`, `ws`
106
+
107
+ **Usage**:
108
+ ```typescript
109
+ import { HttpProtocol } from '@naman_deep_singh/communication-protocols/http';
110
+ import { GrpcProtocol } from '@naman_deep_singh/communication-protocols/grpc';
111
+ ```
112
+
113
+ ### 2. **@naman_deep_singh/communication-resilience**
114
+
115
+ **Purpose**: Fault tolerance patterns (Circuit Breaker, Retry Strategies)
116
+
117
+ ```
118
+ communication-resilience/
119
+ ├── src/
120
+ │ ├── circuit-breaker/
121
+ │ │ ├── CircuitBreakerImpl.ts # implements ICircuitBreaker
122
+ │ │ ├── CircuitBreakerState.ts # State management
123
+ │ │ └── CircuitBreakerMetrics.ts # Failure tracking
124
+ │ ├── retry/
125
+ │ │ ├── ExponentialBackoffRetry.ts # implements IRetryStrategy
126
+ │ │ ├── LinearBackoffRetry.ts # implements IRetryStrategy
127
+ │ │ ├── FixedDelayRetry.ts # implements IRetryStrategy
128
+ │ │ └── JitterRetry.ts # implements IRetryStrategy
129
+ │ ├── policies/
130
+ │ │ ├── RetryPolicy.ts
131
+ │ │ └── CircuitBreakerPolicy.ts
132
+ │ └── index.ts
133
+ ├── package.json
134
+ └── README.md
135
+ ```
136
+
137
+ **Usage**:
138
+ ```typescript
139
+ import { CircuitBreakerImpl } from '@naman_deep_singh/communication-resilience/circuit-breaker';
140
+ import { ExponentialBackoffRetry } from '@naman_deep_singh/communication-resilience/retry';
141
+ ```
142
+
143
+ ### 3. **@naman_deep_singh/communication-discovery**
144
+
145
+ **Purpose**: Service discovery implementations (Consul, etcd, Kubernetes)
146
+
147
+ ```
148
+ communication-discovery/
149
+ ├── src/
150
+ │ ├── consul/
151
+ │ │ ├── ConsulServiceDiscoverer.ts # extends BaseServiceDiscoverer
152
+ │ │ ├── ConsulHealthChecker.ts
153
+ │ │ └── ConsulWatcher.ts
154
+ │ ├── etcd/
155
+ │ │ ├── EtcdServiceDiscoverer.ts # extends BaseServiceDiscoverer
156
+ │ │ ├── EtcdHealthChecker.ts
157
+ │ │ └── EtcdWatcher.ts
158
+ │ ├── kubernetes/
159
+ │ │ ├── K8sServiceDiscoverer.ts # extends BaseServiceDiscoverer
160
+ │ │ ├── K8sHealthChecker.ts
161
+ │ │ └── K8sWatcher.ts
162
+ │ ├── static/
163
+ │ │ └── StaticServiceDiscoverer.ts # For testing/development
164
+ │ └── index.ts
165
+ ├── package.json
166
+ └── README.md
167
+ ```
168
+
169
+ **Key Dependencies**: `consul`, `etcd3`, `@kubernetes/client-node`
170
+
171
+ **Usage**:
172
+ ```typescript
173
+ import { ConsulServiceDiscoverer } from '@naman_deep_singh/communication-discovery/consul';
174
+ import { K8sServiceDiscoverer } from '@naman_deep_singh/communication-discovery/kubernetes';
175
+ ```
176
+
177
+ ### 4. **@naman_deep_singh/communication-load-balancing**
178
+
179
+ **Purpose**: Load balancing strategies for traffic distribution
180
+
181
+ ```
182
+ communication-load-balancing/
183
+ ├── src/
184
+ │ ├── strategies/
185
+ │ │ ├── RoundRobinStrategy.ts # implements ILoadBalanceStrategy
186
+ │ │ ├── WeightedRoundRobinStrategy.ts # implements ILoadBalanceStrategy
187
+ │ │ ├── LeastConnectionsStrategy.ts # implements ILoadBalanceStrategy
188
+ │ │ ├── RandomStrategy.ts # implements ILoadBalanceStrategy
189
+ │ │ └── ConsistentHashStrategy.ts # implements ILoadBalanceStrategy
190
+ │ ├── health/
191
+ │ │ ├── HealthAwareLoadBalancer.ts
192
+ │ │ └── HealthScorer.ts
193
+ │ ├── metrics/
194
+ │ │ ├── LoadBalancerMetrics.ts
195
+ │ │ └── ConnectionTracker.ts
196
+ │ └── index.ts
197
+ ├── package.json
198
+ └── README.md
199
+ ```
200
+
201
+ **Usage**:
202
+ ```typescript
203
+ import { RoundRobinStrategy } from '@naman_deep_singh/communication-load-balancing/strategies';
204
+ import { WeightedRoundRobinStrategy } from '@naman_deep_singh/communication-load-balancing/strategies';
205
+ ```
206
+
207
+ ### 5. **@naman_deep_singh/communication-client**
208
+
209
+ **Purpose**: Unified client that orchestrates all components
210
+
211
+ ```
212
+ communication-client/
213
+ ├── src/
214
+ │ ├── client/
215
+ │ │ ├── CommunicationClient.ts # implements IClient
216
+ │ │ ├── ClientFactory.ts # implements IClientFactory
217
+ │ │ └── ClientBuilder.ts # Fluent builder pattern
218
+ │ ├── pipeline/
219
+ │ │ ├── RequestPipeline.ts
220
+ │ │ ├── ResponsePipeline.ts
221
+ │ │ └── InterceptorChain.ts
222
+ │ ├── middleware/
223
+ │ │ ├── LoggingInterceptor.ts
224
+ │ │ ├── MetricsInterceptor.ts
225
+ │ │ ├── TracingInterceptor.ts
226
+ │ │ └── AuthInterceptor.ts
227
+ │ ├── events/
228
+ │ │ ├── ClientEventEmitter.ts
229
+ │ │ └── ClientEvents.ts
230
+ │ └── index.ts
231
+ ├── package.json
232
+ └── README.md
233
+ ```
234
+
235
+ **Usage**:
236
+ ```typescript
237
+ import { CommunicationClient, ClientBuilder } from '@naman_deep_singh/communication-client';
238
+
239
+ // Fluent builder pattern
240
+ const client = new ClientBuilder()
241
+ .withProtocol(new HttpProtocol())
242
+ .withServiceDiscovery(new ConsulServiceDiscoverer(consulConfig))
243
+ .withLoadBalancer(new RoundRobinStrategy())
244
+ .withCircuitBreaker(new CircuitBreakerImpl(cbConfig))
245
+ .withRetryStrategy(new ExponentialBackoffRetry(retryConfig))
246
+ .build('user-service');
247
+ ```
248
+
249
+ ## Development Roadmap
250
+
251
+ ### Phase 1: Protocols Foundation (Week 1-2)
252
+ - Implement `HttpProtocol` with connection pooling
253
+ - Add basic interceptor support
254
+ - Create comprehensive tests
255
+
256
+ ### Phase 2: Resilience Layer (Week 3)
257
+ - Implement `CircuitBreakerImpl` with state management
258
+ - Add `ExponentialBackoffRetry` strategy
259
+ - Integration testing with HTTP protocol
260
+
261
+ ### Phase 3: Service Discovery (Week 4)
262
+ - Implement `ConsulServiceDiscoverer`
263
+ - Add health checking and caching
264
+ - Event-driven service updates
265
+
266
+ ### Phase 4: Load Balancing (Week 5)
267
+ - Implement `RoundRobinStrategy`
268
+ - Add health-aware load balancing
269
+ - Performance benchmarking
270
+
271
+ ### Phase 5: Client Orchestration (Week 6)
272
+ - Create unified `CommunicationClient`
273
+ - Implement request pipeline
274
+ - End-to-end integration testing
275
+
276
+ ## Usage Example
277
+
278
+ ```typescript
279
+ import {
280
+ IClient,
281
+ IProtocol,
282
+ IServiceDiscoverer,
283
+ ILoadBalanceStrategy,
284
+ ICircuitBreaker,
285
+ IRetryStrategy
286
+ } from '@naman_deep_singh/communication-core';
287
+
288
+ // This core package provides the contracts
289
+ // Implementations come from subpackages:
290
+
291
+ // From communication-protocols
292
+ const protocol: IProtocol = new HttpProtocol({
293
+ timeout: 5000,
294
+ maxConnections: 100
295
+ });
296
+
297
+ // From communication-discovery
298
+ const discovery: IServiceDiscoverer = new ConsulServiceDiscoverer({
299
+ host: 'localhost',
300
+ port: 8500
301
+ });
302
+
303
+ // From communication-load-balancing
304
+ const loadBalancer: ILoadBalanceStrategy = new RoundRobinStrategy();
305
+
306
+ // From communication-resilience
307
+ const circuitBreaker: ICircuitBreaker = new CircuitBreakerImpl({
308
+ failureThreshold: 5,
309
+ timeout: 60000
310
+ });
311
+
312
+ // From communication-client
313
+ const client: IClient = new CommunicationClient({
314
+ serviceName: 'user-service',
315
+ protocol,
316
+ serviceDiscoverer: discovery,
317
+ loadBalancer,
318
+ circuitBreaker
319
+ });
320
+
321
+ // Make requests
322
+ const response = await client.call('/users/123');
323
+ ```
324
+
325
+ ## Key Benefits
326
+
327
+ - **🔧 Modular Architecture**: Use only the components you need
328
+ - **🔄 Consistent Patterns**: All implementations follow the same interfaces
329
+ - **🧪 Easy Testing**: Mock interfaces for comprehensive unit testing
330
+ - **📈 Extensible**: Add new protocols/strategies without breaking changes
331
+ - **⚡ Performance**: Built-in connection pooling and caching
332
+ - **🛡️ Reliable**: Circuit breakers and retry mechanisms
333
+ - **📊 Observable**: Built-in metrics and event system
334
+
335
+ ## Contributing
336
+
337
+ This package follows strict TypeScript patterns:
338
+ - No wildcard exports (except root index)
339
+ - Type keyword for all type imports
340
+ - .js extensions in imports
341
+ - Barrel exports in all directories
342
+
343
+ ## License
344
+
345
+ MIT