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