@hotmeshio/hotmesh 0.3.32 → 0.4.1

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 (207) hide show
  1. package/README.md +128 -823
  2. package/build/index.d.ts +9 -9
  3. package/build/index.js +10 -10
  4. package/build/modules/enums.d.ts +23 -23
  5. package/build/modules/enums.js +26 -26
  6. package/build/modules/errors.d.ts +16 -16
  7. package/build/modules/errors.js +28 -28
  8. package/build/modules/key.js +190 -1
  9. package/build/modules/utils.js +374 -1
  10. package/build/package.json +22 -21
  11. package/build/services/activities/activity.js +549 -1
  12. package/build/services/activities/await.js +114 -1
  13. package/build/services/activities/cycle.js +112 -1
  14. package/build/services/activities/hook.js +168 -1
  15. package/build/services/activities/index.js +20 -1
  16. package/build/services/activities/interrupt.js +158 -1
  17. package/build/services/activities/signal.js +134 -1
  18. package/build/services/activities/trigger.js +246 -1
  19. package/build/services/activities/worker.js +106 -1
  20. package/build/services/collator/index.js +293 -1
  21. package/build/services/compiler/deployer.js +488 -1
  22. package/build/services/compiler/index.js +112 -1
  23. package/build/services/compiler/validator.js +147 -1
  24. package/build/services/engine/index.js +761 -1
  25. package/build/services/exporter/index.js +126 -1
  26. package/build/services/hotmesh/index.d.ts +160 -17
  27. package/build/services/hotmesh/index.js +160 -17
  28. package/build/services/mapper/index.js +81 -1
  29. package/build/services/{meshflow → memflow}/client.d.ts +3 -3
  30. package/build/services/{meshflow → memflow}/client.js +17 -16
  31. package/build/services/{meshflow → memflow}/connection.d.ts +2 -2
  32. package/build/services/{meshflow → memflow}/connection.js +1 -1
  33. package/build/services/memflow/context.d.ts +143 -0
  34. package/build/services/memflow/context.js +299 -0
  35. package/build/services/{meshflow → memflow}/exporter.d.ts +6 -6
  36. package/build/services/memflow/exporter.js +215 -0
  37. package/build/services/{meshflow → memflow}/handle.d.ts +4 -4
  38. package/build/services/{meshflow → memflow}/handle.js +2 -2
  39. package/build/services/{meshflow → memflow}/index.d.ts +18 -13
  40. package/build/services/{meshflow → memflow}/index.js +26 -21
  41. package/build/services/{meshflow → memflow}/schemas/factory.d.ts +4 -4
  42. package/build/services/{meshflow → memflow}/schemas/factory.js +5 -5
  43. package/build/services/{meshflow → memflow}/search.d.ts +1 -1
  44. package/build/services/{meshflow → memflow}/search.js +4 -4
  45. package/build/services/{meshflow → memflow}/worker.d.ts +5 -5
  46. package/build/services/{meshflow → memflow}/worker.js +24 -24
  47. package/build/services/memflow/workflow/common.d.ts +20 -0
  48. package/build/services/memflow/workflow/common.js +47 -0
  49. package/build/services/memflow/workflow/contextMethods.d.ts +14 -0
  50. package/build/services/memflow/workflow/contextMethods.js +33 -0
  51. package/build/services/{meshflow → memflow}/workflow/execChild.js +12 -12
  52. package/build/services/memflow/workflow/execHook.d.ts +65 -0
  53. package/build/services/memflow/workflow/execHook.js +73 -0
  54. package/build/services/{meshflow → memflow}/workflow/hook.js +19 -3
  55. package/build/services/{meshflow → memflow}/workflow/index.d.ts +7 -3
  56. package/build/services/{meshflow → memflow}/workflow/index.js +7 -3
  57. package/build/services/{meshflow → memflow}/workflow/proxyActivities.d.ts +2 -2
  58. package/build/services/{meshflow → memflow}/workflow/proxyActivities.js +8 -8
  59. package/build/services/{meshflow → memflow}/workflow/sleepFor.js +2 -2
  60. package/build/services/{meshflow → memflow}/workflow/waitFor.js +2 -2
  61. package/build/services/meshdata/index.d.ts +24 -24
  62. package/build/services/meshdata/index.js +40 -40
  63. package/build/services/pipe/functions/array.js +74 -1
  64. package/build/services/pipe/functions/bitwise.js +24 -1
  65. package/build/services/pipe/functions/conditional.js +36 -1
  66. package/build/services/pipe/functions/cron.js +40 -1
  67. package/build/services/pipe/functions/date.js +171 -1
  68. package/build/services/pipe/functions/index.js +30 -1
  69. package/build/services/pipe/functions/json.js +12 -1
  70. package/build/services/pipe/functions/logical.js +12 -1
  71. package/build/services/pipe/functions/math.js +184 -1
  72. package/build/services/pipe/functions/number.js +60 -1
  73. package/build/services/pipe/functions/object.js +81 -1
  74. package/build/services/pipe/functions/string.js +69 -1
  75. package/build/services/pipe/functions/symbol.js +33 -1
  76. package/build/services/pipe/functions/unary.js +18 -1
  77. package/build/services/pipe/index.js +242 -1
  78. package/build/services/quorum/index.js +263 -1
  79. package/build/services/reporter/index.js +348 -1
  80. package/build/services/router/config/index.d.ts +11 -0
  81. package/build/services/router/config/index.js +36 -0
  82. package/build/services/router/consumption/index.d.ts +34 -0
  83. package/build/services/router/consumption/index.js +395 -0
  84. package/build/services/router/error-handling/index.d.ts +8 -0
  85. package/build/services/router/error-handling/index.js +98 -0
  86. package/build/services/router/index.d.ts +13 -16
  87. package/build/services/router/index.js +121 -1
  88. package/build/services/router/lifecycle/index.d.ts +27 -0
  89. package/build/services/router/lifecycle/index.js +80 -0
  90. package/build/services/router/telemetry/index.d.ts +11 -0
  91. package/build/services/router/telemetry/index.js +32 -0
  92. package/build/services/router/throttling/index.d.ts +23 -0
  93. package/build/services/router/throttling/index.js +76 -0
  94. package/build/services/search/index.d.ts +2 -1
  95. package/build/services/search/providers/postgres/postgres.d.ts +2 -1
  96. package/build/services/search/providers/postgres/postgres.js +149 -1
  97. package/build/services/search/providers/redis/ioredis.d.ts +1 -0
  98. package/build/services/search/providers/redis/ioredis.js +121 -1
  99. package/build/services/search/providers/redis/redis.d.ts +1 -0
  100. package/build/services/search/providers/redis/redis.js +134 -1
  101. package/build/services/serializer/index.js +282 -1
  102. package/build/services/store/providers/postgres/kvsql.d.ts +1 -1
  103. package/build/services/store/providers/postgres/kvsql.js +198 -1
  104. package/build/services/store/providers/postgres/kvtables.js +441 -1
  105. package/build/services/store/providers/postgres/kvtransaction.js +248 -1
  106. package/build/services/store/providers/postgres/kvtypes/hash.d.ts +1 -1
  107. package/build/services/store/providers/postgres/kvtypes/hash.js +1287 -1
  108. package/build/services/store/providers/postgres/kvtypes/list.js +194 -1
  109. package/build/services/store/providers/postgres/kvtypes/string.js +115 -1
  110. package/build/services/store/providers/postgres/kvtypes/zset.js +214 -1
  111. package/build/services/store/providers/postgres/postgres.js +1036 -1
  112. package/build/services/store/providers/redis/_base.js +980 -1
  113. package/build/services/store/providers/redis/ioredis.js +180 -1
  114. package/build/services/store/providers/redis/redis.js +199 -1
  115. package/build/services/store/providers/store-initializable.js +2 -1
  116. package/build/services/stream/index.d.ts +5 -0
  117. package/build/services/stream/providers/nats/nats.d.ts +1 -0
  118. package/build/services/stream/providers/nats/nats.js +225 -1
  119. package/build/services/stream/providers/postgres/kvtables.d.ts +1 -0
  120. package/build/services/stream/providers/postgres/kvtables.js +146 -1
  121. package/build/services/stream/providers/postgres/postgres.d.ts +19 -0
  122. package/build/services/stream/providers/postgres/postgres.js +519 -1
  123. package/build/services/stream/providers/redis/ioredis.d.ts +1 -0
  124. package/build/services/stream/providers/redis/ioredis.js +272 -1
  125. package/build/services/stream/providers/redis/redis.d.ts +1 -0
  126. package/build/services/stream/providers/redis/redis.js +305 -1
  127. package/build/services/stream/providers/stream-initializable.js +2 -1
  128. package/build/services/sub/providers/nats/nats.js +105 -1
  129. package/build/services/sub/providers/postgres/postgres.js +92 -1
  130. package/build/services/sub/providers/redis/ioredis.js +81 -1
  131. package/build/services/sub/providers/redis/redis.js +72 -1
  132. package/build/services/task/index.js +206 -1
  133. package/build/services/telemetry/index.js +306 -1
  134. package/build/services/worker/index.js +197 -1
  135. package/build/types/error.d.ts +5 -5
  136. package/build/types/exporter.d.ts +1 -1
  137. package/build/types/index.d.ts +3 -3
  138. package/build/types/manifest.d.ts +2 -2
  139. package/build/types/{meshflow.d.ts → memflow.d.ts} +15 -15
  140. package/build/types/meshdata.d.ts +3 -3
  141. package/build/types/postgres.d.ts +7 -0
  142. package/build/types/stream.d.ts +3 -0
  143. package/index.ts +11 -11
  144. package/package.json +22 -21
  145. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  146. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  147. package/build/services/meshflow/exporter.js +0 -1
  148. package/build/services/meshflow/workflow/common.d.ts +0 -18
  149. package/build/services/meshflow/workflow/common.js +0 -45
  150. package/typedoc.json +0 -46
  151. package/types/activity.ts +0 -268
  152. package/types/app.ts +0 -20
  153. package/types/async.ts +0 -6
  154. package/types/cache.ts +0 -1
  155. package/types/collator.ts +0 -9
  156. package/types/error.ts +0 -56
  157. package/types/exporter.ts +0 -102
  158. package/types/hook.ts +0 -44
  159. package/types/hotmesh.ts +0 -314
  160. package/types/index.ts +0 -306
  161. package/types/job.ts +0 -233
  162. package/types/logger.ts +0 -8
  163. package/types/manifest.ts +0 -70
  164. package/types/map.ts +0 -5
  165. package/types/meshcall.ts +0 -235
  166. package/types/meshdata.ts +0 -278
  167. package/types/meshflow.ts +0 -645
  168. package/types/ms.d.ts +0 -7
  169. package/types/nats.ts +0 -270
  170. package/types/pipe.ts +0 -90
  171. package/types/postgres.ts +0 -105
  172. package/types/provider.ts +0 -161
  173. package/types/quorum.ts +0 -167
  174. package/types/redis.ts +0 -404
  175. package/types/serializer.ts +0 -40
  176. package/types/stats.ts +0 -117
  177. package/types/stream.ts +0 -227
  178. package/types/task.ts +0 -7
  179. package/types/telemetry.ts +0 -16
  180. package/types/transition.ts +0 -20
  181. /package/build/services/{meshflow → memflow}/workflow/all.d.ts +0 -0
  182. /package/build/services/{meshflow → memflow}/workflow/all.js +0 -0
  183. /package/build/services/{meshflow → memflow}/workflow/context.d.ts +0 -0
  184. /package/build/services/{meshflow → memflow}/workflow/context.js +0 -0
  185. /package/build/services/{meshflow → memflow}/workflow/didRun.d.ts +0 -0
  186. /package/build/services/{meshflow → memflow}/workflow/didRun.js +0 -0
  187. /package/build/services/{meshflow → memflow}/workflow/emit.d.ts +0 -0
  188. /package/build/services/{meshflow → memflow}/workflow/emit.js +0 -0
  189. /package/build/services/{meshflow → memflow}/workflow/enrich.d.ts +0 -0
  190. /package/build/services/{meshflow → memflow}/workflow/enrich.js +0 -0
  191. /package/build/services/{meshflow → memflow}/workflow/execChild.d.ts +0 -0
  192. /package/build/services/{meshflow → memflow}/workflow/hook.d.ts +0 -0
  193. /package/build/services/{meshflow → memflow}/workflow/interrupt.d.ts +0 -0
  194. /package/build/services/{meshflow → memflow}/workflow/interrupt.js +0 -0
  195. /package/build/services/{meshflow → memflow}/workflow/isSideEffectAllowed.d.ts +0 -0
  196. /package/build/services/{meshflow → memflow}/workflow/isSideEffectAllowed.js +0 -0
  197. /package/build/services/{meshflow → memflow}/workflow/random.d.ts +0 -0
  198. /package/build/services/{meshflow → memflow}/workflow/random.js +0 -0
  199. /package/build/services/{meshflow → memflow}/workflow/searchMethods.d.ts +0 -0
  200. /package/build/services/{meshflow → memflow}/workflow/searchMethods.js +0 -0
  201. /package/build/services/{meshflow → memflow}/workflow/signal.d.ts +0 -0
  202. /package/build/services/{meshflow → memflow}/workflow/signal.js +0 -0
  203. /package/build/services/{meshflow → memflow}/workflow/sleepFor.d.ts +0 -0
  204. /package/build/services/{meshflow → memflow}/workflow/trace.d.ts +0 -0
  205. /package/build/services/{meshflow → memflow}/workflow/trace.js +0 -0
  206. /package/build/services/{meshflow → memflow}/workflow/waitFor.d.ts +0 -0
  207. /package/build/types/{meshflow.js → memflow.js} +0 -0
@@ -1 +1,198 @@
1
- 'use strict';const s=b;(function(c,d){const r=b,e=c();while(!![]){try{const f=parseInt(r(0xc1))/0x1*(-parseInt(r(0xd3))/0x2)+parseInt(r(0xae))/0x3+parseInt(r(0xe0))/0x4*(parseInt(r(0xdd))/0x5)+-parseInt(r(0x8a))/0x6+parseInt(r(0x7e))/0x7*(-parseInt(r(0xb4))/0x8)+-parseInt(r(0xc8))/0x9*(parseInt(r(0x9f))/0xa)+parseInt(r(0x9d))/0xb;if(f===d)break;else e['push'](e['shift']());}catch(g){e['push'](e['shift']());}}}(a,0x8faf8));Object[s(0xbc)](exports,s(0xe3),{'value':!0x0}),exports['KVSQL']=void 0x0;const key_1=require(s(0x96)),kvtransaction_1=require('./kvtransaction'),string_1=require('./kvtypes/string'),hash_1=require(s(0xb6)),list_1=require(s(0xca)),zset_1=require(s(0x97));function b(c,d){const e=a();return b=function(f,g){f=f-0x6c;let h=e[f];return h;},b(c,d);}function a(){const E=['transact','hdel','resolveEntityType','getMulti','zrange','endsWith','hscan','\x0a\x20\x20\x20\x20\x20\x20','mintKey','200LsAcDn','\x0a\x20\x20\x20\x20\x20\x20\x20\x20SELECT\x20FROM\x20','replace','11608xkNDtu','_hincrbyfloat','lmove','__esModule','string','rows','public.hotmesh_applications','_hset','lpop','_set',']\x20for\x20key\x20[','lpush','applications','stats','namespace','_hget','set','tableForKey','Unknown\x20entity\x20type\x20abbreviation:\x20','hgetall','Unknown\x20stats\x20type\x20[','_zrem','78337wAuuqy','join','test','resolve','zset','.expiry\x20IS\x20NULL\x20OR\x20','\x20!==\x20','appId','_lpush','_scan','table_name','expire','593436WROddT','_lpop',':processed','slice','split','zrangebyscore_withscores','.expired_at\x20IS\x20NULL\x20OR\x20','isStatusOnly','safeName','_rpush','list','hset','../../../../modules/key','./kvtypes/zset','setnx','zrangebyscore','hashModule','rpush','_zrank','35473053nZgndH','appendExpiryClause','10OFZJpk','exec','stringModule','lrange','appendJobExpiryClause','length','zadd','query','public.hotmesh_connections','_zrangebyscore_withscores','hash','zrank','HMNS','KVTransaction','_zadd','1561233gComgy','hmget','scan','hget','sorted_set','_get','696jnoaHM','.expiry\x20>\x20NOW())\x0a\x20\x20\x20\x20','./kvtypes/hash','_del','rename','hincrbyfloat','unknown_entity','KeyService','defineProperty','zscore','_exists','_zscore','_expire','2TgzCtb','get','KVSQL','del','\x0a\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20id\x20=\x20$1\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20(expired_at\x20IS\x20NULL\x20OR\x20expired_at\x20>\x20NOW())\x0a\x20\x20\x20\x20\x20\x20\x20\x20LIMIT\x201;\x0a\x20\x20\x20\x20\x20\x20','_zrange','zrem','9614619ZYAhov','setnxex','./kvtypes/list','pgClient','exists','_rename','_zrangebyscore','_hscan','jobs','hsetnx','_lrange','1131964rRRdua'];a=function(){return E;};return a();}class KVSQL{constructor(c,d,f){const t=s;this['set']=(...g)=>this[t(0x6c)][t(0x78)](...g),this[t(0x71)]=(...g)=>this[t(0x6c)]['_set'](...g),this[t(0xc2)]=(...g)=>this[t(0x6c)][t(0xc2)](...g),this[t(0xb3)]=(...g)=>this[t(0x6c)][t(0xb3)](...g),this[t(0xc4)]=(...g)=>this[t(0x6c)][t(0xc4)](...g),this[t(0xb7)]=(...g)=>this[t(0x6c)][t(0xb7)](...g),this['setnx']=(...g)=>this[t(0x6c)][t(0x98)](...g),this[t(0xc9)]=(...g)=>this[t(0x6c)][t(0xc9)](...g),this[t(0x95)]=(...g)=>this[t(0xa9)][t(0x95)](...g),this[t(0x6f)]=(...g)=>this[t(0xa9)][t(0x6f)](...g),this[t(0xd1)]=(...g)=>this[t(0xa9)][t(0xd1)](...g),this[t(0xb1)]=(...g)=>this[t(0xa9)][t(0xb1)](...g),this[t(0x77)]=(...g)=>this[t(0xa9)][t(0x77)](...g),this['hdel']=(...g)=>this['hash'][t(0xd5)](...g),this['_hdel']=(...g)=>this[t(0xa9)]['_hdel'](...g),this[t(0xaf)]=(...g)=>this[t(0xa9)][t(0xaf)](...g),this['_hmget']=(...g)=>this['hash']['_hmget'](...g),this[t(0x7b)]=(...g)=>this['hash'][t(0x7b)](...g),this[t(0xb9)]=(...g)=>this[t(0xa9)]['hincrbyfloat'](...g),this[t(0xe1)]=(...g)=>this[t(0xa9)]['_hincrbyfloat'](...g),this[t(0xda)]=(...g)=>this[t(0xa9)][t(0xda)](...g),this[t(0xcf)]=(...g)=>this[t(0xa9)][t(0xcf)](...g),this[t(0x89)]=(...g)=>this[t(0xa9)][t(0x89)](...g),this[t(0xc0)]=(...g)=>this[t(0xa9)]['_expire'](...g),this['scan']=(...g)=>this[t(0xa9)][t(0xb0)](...g),this[t(0x87)]=(...g)=>this[t(0xa9)][t(0x87)](...g),this[t(0xa2)]=(...g)=>this[t(0x94)][t(0xa2)](...g),this[t(0xd2)]=(...g)=>this['list'][t(0xd2)](...g),this[t(0x9b)]=(...g)=>this[t(0x94)][t(0x9b)](...g),this[t(0x93)]=(...g)=>this['list'][t(0x93)](...g),this[t(0x73)]=(...g)=>this[t(0x94)][t(0x73)](...g),this[t(0x86)]=(...g)=>this[t(0x94)][t(0x86)](...g),this['lpop']=(...g)=>this[t(0x94)][t(0x70)](...g),this[t(0x8b)]=(...g)=>this['list'][t(0x8b)](...g),this['lmove']=(...g)=>this[t(0x94)][t(0xe2)](...g),this['_lmove']=(...g)=>this['list']['_lmove'](...g),this[t(0xb8)]=(...g)=>this[t(0x94)][t(0xb8)](...g),this[t(0xcd)]=(...g)=>this['list']['_rename'](...g),this[t(0xa5)]=(...g)=>this[t(0x82)][t(0xa5)](...g),this[t(0xad)]=(...g)=>this[t(0x82)][t(0xad)](...g),this[t(0xd8)]=(...g)=>this[t(0x82)][t(0xd8)](...g),this[t(0xc6)]=(...g)=>this['zset'][t(0xc6)](...g),this['zrangebyscore']=(...g)=>this[t(0x82)][t(0x99)](...g),this['_zrangebyscore']=(...g)=>this['zset'][t(0xce)](...g),this['zrangebyscore_withscores']=(...g)=>this[t(0x82)][t(0x8f)](...g),this[t(0xa8)]=(...g)=>this[t(0x82)][t(0xa8)](...g),this[t(0xc7)]=(...g)=>this['zset']['zrem'](...g),this['_zrem']=(...g)=>this[t(0x82)][t(0x7d)](...g),this[t(0xaa)]=(...g)=>this[t(0x82)]['zrank'](...g),this[t(0x9c)]=(...g)=>this[t(0x82)][t(0x9c)](...g),this[t(0xbd)]=(...g)=>this[t(0x82)][t(0xbd)](...g),this[t(0xbf)]=(...g)=>this[t(0x82)][t(0xbf)](...g),this[t(0xcb)]=c,this[t(0x76)]=d,this[t(0x85)]=f,this[t(0xa9)]=(0x0,hash_1[t(0x9a)])(this),this['list']=(0x0,list_1['listModule'])(this),this[t(0x82)]=(0x0,zset_1['zsetModule'])(this),this['string']=(0x0,string_1[t(0xa1)])(this);}[s(0x91)](c){const u=s;return 0x1===c[u(0xa4)]&&':'===c[0x0];}[s(0x9e)](c,d){const v=s;return v(0xdb)+c+'\x0a\x20\x20\x20\x20\x20\x20AND\x20('+d+v(0x83)+d+v(0xb5);}[s(0xa3)](c,d){const w=s;return w(0xdb)+c+'\x0a\x20\x20\x20\x20\x20\x20AND\x20('+d+w(0x90)+d+'.expired_at\x20>\x20NOW())\x0a\x20\x20\x20\x20';}[s(0xd7)](){const x=s;return new kvtransaction_1[(x(0xac))](this);}[s(0xd4)](){const y=s;return new kvtransaction_1[(y(0xac))](this);}[s(0xa0)](...c){const z=s;return Promise[z(0x81)]([]);}[s(0xdc)](c,d){return'';}[s(0x79)](c,d){const A=s;if(c===key_1[A(0xab)])return A(0xa7);const [f,g,j,...k]=c[A(0x8e)](':');if('a'===g)return'public.hotmesh_applications';const l=k?.['length']?k[A(0x7f)](':'):'',m=key_1[A(0xbb)][A(0xd6)](j,l);if(this['safeName'](this[A(0x85)])!==this[A(0x92)](g))throw new Error('App\x20ID\x20mismatch:\x20'+this[A(0x85)]+A(0x84)+g);const p=this[A(0x92)](g);if(A(0x75)===m){let q;if(A(0xb2)===d)q='stats_ordered';else{if(A(0x94)===d||c[A(0xd9)](A(0x8c)))q='stats_indexed';else{if(A(0xa9)!==d&&!/:\d$/[A(0x80)](c))throw new Error(A(0x7c)+d+A(0x72)+c+']');q='stats_counted';}}return p+'.'+q;}if(A(0xba)===m)throw new Error(A(0x7a)+j);return A(0x74)===m?A(0x6e):p+'.'+m;}[s(0x92)](c,d=''){const B=s;if(!c)return'connections';let f=c['trim']()['toLowerCase']();return f=f['replace'](/[^a-z0-9]+/g,'_'),d&&(f=d+'_'+f),f[B(0xa4)]>0x3f&&(f=f[B(0x8d)](0x0,0x3f)),f=f[B(0xdf)](/_+$/g,''),f||(f='connections'),f;}async[s(0xcc)](c){const C=s,{sql:d,params:f}=this[C(0xbe)](c),g=await this[C(0xcb)][C(0xa6)](d,f);return g[C(0x6d)]['length']?g[C(0x6d)][0x0][C(0x88)]:0x0;}[s(0xbe)](c){const D=s,d=this[D(0x79)](c);let f;return f=d['endsWith'](D(0xd0))?D(0xde)+d+D(0xc5):D(0xde)+d+'\x0a\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20key\x20=\x20$1\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20(expiry\x20IS\x20NULL\x20OR\x20expiry\x20>\x20NOW())\x0a\x20\x20\x20\x20\x20\x20\x20\x20LIMIT\x201;\x0a\x20\x20\x20\x20\x20\x20',{'sql':f,'params':[c]};}}exports[s(0xc3)]=KVSQL;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KVSQL = void 0;
4
+ const key_1 = require("../../../../modules/key");
5
+ const kvtransaction_1 = require("./kvtransaction");
6
+ const string_1 = require("./kvtypes/string");
7
+ const hash_1 = require("./kvtypes/hash");
8
+ const list_1 = require("./kvtypes/list");
9
+ const zset_1 = require("./kvtypes/zset");
10
+ /**
11
+ * KVSQL is a class that provides a set of methods to interact with a Postgres database.
12
+ * It is used to interact with the database in a key-value manner.
13
+ */
14
+ class KVSQL {
15
+ constructor(pgClient, namespace, appId) {
16
+ // String Commands
17
+ this.set = (...args) => this.string.set(...args);
18
+ this._set = (...args) => this.string._set(...args);
19
+ this.get = (...args) => this.string.get(...args);
20
+ this._get = (...args) => this.string._get(...args);
21
+ this.del = (...args) => this.string.del(...args);
22
+ this._del = (...args) => this.string._del(...args);
23
+ this.setnx = (...args) => this.string.setnx(...args);
24
+ this.setnxex = (...args) => this.string.setnxex(...args);
25
+ // Hash Commands
26
+ this.hset = (...args) => this.hash.hset(...args);
27
+ this._hset = (...args) => this.hash._hset(...args);
28
+ this.hsetnx = (...args) => this.hash.hsetnx(...args);
29
+ this.hget = (...args) => this.hash.hget(...args);
30
+ this._hget = (...args) => this.hash._hget(...args);
31
+ this.hdel = (...args) => this.hash.hdel(...args);
32
+ this._hdel = (...args) => this.hash._hdel(...args);
33
+ this.hmget = (...args) => this.hash.hmget(...args);
34
+ this._hmget = (...args) => this.hash._hmget(...args);
35
+ this.hgetall = (...args) => this.hash.hgetall(...args);
36
+ this.hincrbyfloat = (...args) => this.hash.hincrbyfloat(...args);
37
+ this._hincrbyfloat = (...args) => this.hash._hincrbyfloat(...args);
38
+ this.hscan = (...args) => this.hash.hscan(...args);
39
+ this._hscan = (...args) => this.hash._hscan(...args);
40
+ this.expire = (...args) => this.hash.expire(...args);
41
+ this._expire = (...args) => this.hash._expire(...args);
42
+ this.scan = (...args) => this.hash.scan(...args);
43
+ this._scan = (...args) => this.hash._scan(...args);
44
+ // List Commands
45
+ this.lrange = (...args) => this.list.lrange(...args);
46
+ this._lrange = (...args) => this.list._lrange(...args);
47
+ this.rpush = (...args) => this.list.rpush(...args);
48
+ this._rpush = (...args) => this.list._rpush(...args);
49
+ this.lpush = (...args) => this.list.lpush(...args);
50
+ this._lpush = (...args) => this.list._lpush(...args);
51
+ this.lpop = (...args) => this.list.lpop(...args);
52
+ this._lpop = (...args) => this.list._lpop(...args);
53
+ this.lmove = (...args) => this.list.lmove(...args);
54
+ this._lmove = (...args) => this.list._lmove(...args);
55
+ this.rename = (...args) => this.list.rename(...args);
56
+ this._rename = (...args) => this.list._rename(...args);
57
+ // Sorted Set Commands
58
+ this.zadd = (...args) => this.zset.zadd(...args);
59
+ this._zadd = (...args) => this.zset._zadd(...args);
60
+ this.zrange = (...args) => this.zset.zrange(...args);
61
+ this._zrange = (...args) => this.zset._zrange(...args);
62
+ this.zrangebyscore = (...args) => this.zset.zrangebyscore(...args);
63
+ this._zrangebyscore = (...args) => this.zset._zrangebyscore(...args);
64
+ this.zrangebyscore_withscores = (...args) => this.zset.zrangebyscore_withscores(...args);
65
+ this._zrangebyscore_withscores = (...args) => this.zset._zrangebyscore_withscores(...args);
66
+ this.zrem = (...args) => this.zset.zrem(...args);
67
+ this._zrem = (...args) => this.zset._zrem(...args);
68
+ this.zrank = (...args) => this.zset.zrank(...args);
69
+ this._zrank = (...args) => this.zset._zrank(...args);
70
+ this.zscore = (...args) => this.zset.zscore(...args);
71
+ this._zscore = (...args) => this.zset._zscore(...args);
72
+ this.pgClient = pgClient;
73
+ this.namespace = namespace;
74
+ this.appId = appId;
75
+ this.hash = (0, hash_1.hashModule)(this);
76
+ this.list = (0, list_1.listModule)(this);
77
+ this.zset = (0, zset_1.zsetModule)(this);
78
+ this.string = (0, string_1.stringModule)(this);
79
+ }
80
+ isStatusOnly(fields) {
81
+ return fields.length === 1 && fields[0] === ':';
82
+ }
83
+ appendExpiryClause(baseQuery, tableAlias) {
84
+ return `
85
+ ${baseQuery}
86
+ AND (${tableAlias}.expiry IS NULL OR ${tableAlias}.expiry > NOW())
87
+ `;
88
+ }
89
+ appendJobExpiryClause(baseQuery, tableAlias) {
90
+ return `
91
+ ${baseQuery}
92
+ AND (${tableAlias}.expired_at IS NULL OR ${tableAlias}.expired_at > NOW())
93
+ `;
94
+ }
95
+ getMulti() {
96
+ return new kvtransaction_1.KVTransaction(this);
97
+ }
98
+ transact() {
99
+ return new kvtransaction_1.KVTransaction(this);
100
+ }
101
+ exec(...args) {
102
+ return Promise.resolve([]);
103
+ }
104
+ mintKey(type, params) {
105
+ //no-op
106
+ return '';
107
+ }
108
+ /**
109
+ * Resolves the table name when provided a key
110
+ */
111
+ tableForKey(key, stats_type) {
112
+ if (key === key_1.HMNS) {
113
+ return 'public.hotmesh_connections';
114
+ }
115
+ const [_, appName, abbrev, ...rest] = key.split(':');
116
+ if (appName === 'a') {
117
+ return 'public.hotmesh_applications';
118
+ }
119
+ const id = rest?.length ? rest.join(':') : '';
120
+ const entity = key_1.KeyService.resolveEntityType(abbrev, id);
121
+ if (this.safeName(this.appId) !== this.safeName(appName)) {
122
+ throw new Error(`App ID mismatch: ${this.appId} !== ${appName}`);
123
+ }
124
+ const schemaName = this.safeName(appName);
125
+ if (entity === 'stats') {
126
+ let tableName;
127
+ if (stats_type === 'sorted_set') {
128
+ tableName = 'stats_ordered';
129
+ }
130
+ else if (stats_type === 'list' || key.endsWith(':processed')) {
131
+ tableName = 'stats_indexed';
132
+ }
133
+ else if (stats_type === 'hash' || /:\d$/.test(key)) {
134
+ tableName = 'stats_counted';
135
+ }
136
+ else {
137
+ throw new Error(`Unknown stats type [${stats_type}] for key [${key}]`);
138
+ }
139
+ return `${schemaName}.${tableName}`;
140
+ }
141
+ if (entity === 'unknown_entity') {
142
+ throw new Error(`Unknown entity type abbreviation: ${abbrev}`);
143
+ }
144
+ else if (entity === 'applications') {
145
+ return 'public.hotmesh_applications';
146
+ }
147
+ else {
148
+ return `${schemaName}.${entity}`;
149
+ }
150
+ }
151
+ safeName(input, prefix = '') {
152
+ if (!input) {
153
+ return 'connections';
154
+ }
155
+ let tableName = input.trim().toLowerCase();
156
+ tableName = tableName.replace(/[^a-z0-9]+/g, '_');
157
+ if (prefix) {
158
+ tableName = `${prefix}_${tableName}`;
159
+ }
160
+ if (tableName.length > 63) {
161
+ tableName = tableName.slice(0, 63);
162
+ }
163
+ tableName = tableName.replace(/_+$/g, '');
164
+ if (!tableName) {
165
+ tableName = 'connections';
166
+ }
167
+ return tableName;
168
+ }
169
+ async exists(key) {
170
+ const { sql, params } = this._exists(key);
171
+ const res = await this.pgClient.query(sql, params);
172
+ return res.rows.length ? res.rows[0].table_name : 0;
173
+ }
174
+ _exists(key) {
175
+ const tableName = this.tableForKey(key);
176
+ const isJobsTable = tableName.endsWith('jobs');
177
+ let sql;
178
+ if (isJobsTable) {
179
+ sql = `
180
+ SELECT FROM ${tableName}
181
+ WHERE id = $1
182
+ AND (expired_at IS NULL OR expired_at > NOW())
183
+ LIMIT 1;
184
+ `;
185
+ }
186
+ else {
187
+ sql = `
188
+ SELECT FROM ${tableName}
189
+ WHERE key = $1
190
+ AND (expiry IS NULL OR expiry > NOW())
191
+ LIMIT 1;
192
+ `;
193
+ }
194
+ const params = [key];
195
+ return { sql, params };
196
+ }
197
+ }
198
+ exports.KVSQL = KVSQL;