@milaboratories/pl-client 2.17.6 → 2.17.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (274) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +43 -0
  2. package/dist/_virtual/_rolldown/runtime.js +18 -0
  3. package/dist/core/PromiseTracker.cjs +33 -33
  4. package/dist/core/PromiseTracker.cjs.map +1 -1
  5. package/dist/core/PromiseTracker.d.ts +10 -7
  6. package/dist/core/PromiseTracker.js +33 -31
  7. package/dist/core/PromiseTracker.js.map +1 -1
  8. package/dist/core/StatefulPromise.cjs +60 -61
  9. package/dist/core/StatefulPromise.cjs.map +1 -1
  10. package/dist/core/StatefulPromise.js +60 -60
  11. package/dist/core/StatefulPromise.js.map +1 -1
  12. package/dist/core/abstract_stream.d.ts +18 -15
  13. package/dist/core/advisory_locks.cjs +42 -49
  14. package/dist/core/advisory_locks.cjs.map +1 -1
  15. package/dist/core/advisory_locks.js +42 -48
  16. package/dist/core/advisory_locks.js.map +1 -1
  17. package/dist/core/auth.cjs +10 -15
  18. package/dist/core/auth.cjs.map +1 -1
  19. package/dist/core/auth.d.ts +7 -3
  20. package/dist/core/auth.js +10 -13
  21. package/dist/core/auth.js.map +1 -1
  22. package/dist/core/cache.d.ts +11 -7
  23. package/dist/core/client.cjs +255 -306
  24. package/dist/core/client.cjs.map +1 -1
  25. package/dist/core/client.d.ts +72 -68
  26. package/dist/core/client.js +253 -285
  27. package/dist/core/client.js.map +1 -1
  28. package/dist/core/config.cjs +81 -99
  29. package/dist/core/config.cjs.map +1 -1
  30. package/dist/core/config.d.ts +93 -90
  31. package/dist/core/config.js +81 -98
  32. package/dist/core/config.js.map +1 -1
  33. package/dist/core/default_client.cjs +84 -125
  34. package/dist/core/default_client.cjs.map +1 -1
  35. package/dist/core/default_client.d.ts +9 -6
  36. package/dist/core/default_client.js +78 -103
  37. package/dist/core/default_client.js.map +1 -1
  38. package/dist/core/driver.cjs +12 -16
  39. package/dist/core/driver.cjs.map +1 -1
  40. package/dist/core/driver.d.ts +18 -14
  41. package/dist/core/driver.js +12 -15
  42. package/dist/core/driver.js.map +1 -1
  43. package/dist/core/error_resource.cjs +5 -4
  44. package/dist/core/error_resource.cjs.map +1 -1
  45. package/dist/core/error_resource.js +5 -3
  46. package/dist/core/error_resource.js.map +1 -1
  47. package/dist/core/errors.cjs +104 -140
  48. package/dist/core/errors.cjs.map +1 -1
  49. package/dist/core/errors.d.ts +34 -30
  50. package/dist/core/errors.js +102 -137
  51. package/dist/core/errors.js.map +1 -1
  52. package/dist/core/final.cjs +63 -89
  53. package/dist/core/final.cjs.map +1 -1
  54. package/dist/core/final.d.ts +8 -4
  55. package/dist/core/final.js +63 -87
  56. package/dist/core/final.js.map +1 -1
  57. package/dist/core/ll_client.cjs +416 -521
  58. package/dist/core/ll_client.cjs.map +1 -1
  59. package/dist/core/ll_client.d.ts +100 -97
  60. package/dist/core/ll_client.js +415 -519
  61. package/dist/core/ll_client.js.map +1 -1
  62. package/dist/core/ll_transaction.cjs +206 -240
  63. package/dist/core/ll_transaction.cjs.map +1 -1
  64. package/dist/core/ll_transaction.d.ts +50 -52
  65. package/dist/core/ll_transaction.js +205 -238
  66. package/dist/core/ll_transaction.js.map +1 -1
  67. package/dist/core/stat.cjs +64 -63
  68. package/dist/core/stat.cjs.map +1 -1
  69. package/dist/core/stat.d.ts +35 -36
  70. package/dist/core/stat.js +64 -62
  71. package/dist/core/stat.js.map +1 -1
  72. package/dist/core/transaction.cjs +613 -650
  73. package/dist/core/transaction.cjs.map +1 -1
  74. package/dist/core/transaction.d.ts +165 -162
  75. package/dist/core/transaction.js +612 -648
  76. package/dist/core/transaction.js.map +1 -1
  77. package/dist/core/type_conversion.cjs +62 -83
  78. package/dist/core/type_conversion.cjs.map +1 -1
  79. package/dist/core/type_conversion.js +61 -81
  80. package/dist/core/type_conversion.js.map +1 -1
  81. package/dist/core/types.cjs +56 -86
  82. package/dist/core/types.cjs.map +1 -1
  83. package/dist/core/types.d.ts +63 -62
  84. package/dist/core/types.js +54 -83
  85. package/dist/core/types.js.map +1 -1
  86. package/dist/core/unauth_client.cjs +35 -41
  87. package/dist/core/unauth_client.cjs.map +1 -1
  88. package/dist/core/unauth_client.d.ts +18 -14
  89. package/dist/core/unauth_client.js +34 -39
  90. package/dist/core/unauth_client.js.map +1 -1
  91. package/dist/core/websocket_stream.cjs +277 -349
  92. package/dist/core/websocket_stream.cjs.map +1 -1
  93. package/dist/core/websocket_stream.js +275 -347
  94. package/dist/core/websocket_stream.js.map +1 -1
  95. package/dist/core/wire.d.ts +21 -17
  96. package/dist/helpers/pl.cjs +71 -73
  97. package/dist/helpers/pl.cjs.map +1 -1
  98. package/dist/helpers/pl.d.ts +40 -41
  99. package/dist/helpers/pl.js +66 -46
  100. package/dist/helpers/pl.js.map +1 -1
  101. package/dist/helpers/poll.cjs +99 -134
  102. package/dist/helpers/poll.cjs.map +1 -1
  103. package/dist/helpers/poll.d.ts +37 -34
  104. package/dist/helpers/poll.js +97 -113
  105. package/dist/helpers/poll.js.map +1 -1
  106. package/dist/helpers/retry_strategy.cjs +82 -87
  107. package/dist/helpers/retry_strategy.cjs.map +1 -1
  108. package/dist/helpers/retry_strategy.js +83 -86
  109. package/dist/helpers/retry_strategy.js.map +1 -1
  110. package/dist/helpers/tx_helpers.cjs +21 -20
  111. package/dist/helpers/tx_helpers.cjs.map +1 -1
  112. package/dist/helpers/tx_helpers.d.ts +11 -7
  113. package/dist/helpers/tx_helpers.js +20 -18
  114. package/dist/helpers/tx_helpers.js.map +1 -1
  115. package/dist/index.cjs +117 -106
  116. package/dist/index.d.ts +17 -17
  117. package/dist/index.js +17 -19
  118. package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.cjs +72 -66
  119. package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.cjs.map +1 -1
  120. package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.d.ts +35 -37
  121. package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.js +71 -64
  122. package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.js.map +1 -1
  123. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.cjs +12611 -12866
  124. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.cjs.map +1 -1
  125. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.cjs +226 -226
  126. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.cjs.map +1 -1
  127. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts +281 -330
  128. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.js +225 -224
  129. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.js.map +1 -1
  130. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts +2640 -4294
  131. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.js +12608 -12706
  132. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.js.map +1 -1
  133. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.cjs +1230 -1089
  134. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.cjs.map +1 -1
  135. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts +393 -420
  136. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.js +1228 -1083
  137. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.js.map +1 -1
  138. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.cjs +142 -143
  139. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.cjs.map +1 -1
  140. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts +62 -64
  141. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.js +140 -141
  142. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.js.map +1 -1
  143. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.cjs +572 -487
  144. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.cjs.map +1 -1
  145. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts +125 -228
  146. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.js +572 -485
  147. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.js.map +1 -1
  148. package/dist/proto-grpc/google/protobuf/any.cjs +131 -146
  149. package/dist/proto-grpc/google/protobuf/any.cjs.map +1 -1
  150. package/dist/proto-grpc/google/protobuf/any.d.ts +78 -84
  151. package/dist/proto-grpc/google/protobuf/any.js +130 -144
  152. package/dist/proto-grpc/google/protobuf/any.js.map +1 -1
  153. package/dist/proto-grpc/google/protobuf/duration.cjs +92 -100
  154. package/dist/proto-grpc/google/protobuf/duration.cjs.map +1 -1
  155. package/dist/proto-grpc/google/protobuf/duration.d.ts +38 -43
  156. package/dist/proto-grpc/google/protobuf/duration.js +91 -98
  157. package/dist/proto-grpc/google/protobuf/duration.js.map +1 -1
  158. package/dist/proto-grpc/google/protobuf/timestamp.cjs +117 -128
  159. package/dist/proto-grpc/google/protobuf/timestamp.cjs.map +1 -1
  160. package/dist/proto-grpc/google/protobuf/timestamp.d.ts +50 -55
  161. package/dist/proto-grpc/google/protobuf/timestamp.js +116 -126
  162. package/dist/proto-grpc/google/protobuf/timestamp.js.map +1 -1
  163. package/dist/proto-grpc/google/rpc/code.cjs +223 -238
  164. package/dist/proto-grpc/google/rpc/code.cjs.map +1 -1
  165. package/dist/proto-grpc/google/rpc/code.d.ts +209 -206
  166. package/dist/proto-grpc/google/rpc/code.js +221 -237
  167. package/dist/proto-grpc/google/rpc/code.js.map +1 -1
  168. package/dist/proto-rest/index.cjs +67 -66
  169. package/dist/proto-rest/index.cjs.map +1 -1
  170. package/dist/proto-rest/index.d.ts +24 -18
  171. package/dist/proto-rest/index.js +61 -65
  172. package/dist/proto-rest/index.js.map +1 -1
  173. package/dist/proto-rest/plapi.d.ts +1400 -1477
  174. package/dist/test/tcp-proxy.cjs +100 -126
  175. package/dist/test/tcp-proxy.cjs.map +1 -1
  176. package/dist/test/tcp-proxy.d.ts +17 -13
  177. package/dist/test/tcp-proxy.js +97 -104
  178. package/dist/test/tcp-proxy.js.map +1 -1
  179. package/dist/test/test_config.cjs +145 -194
  180. package/dist/test/test_config.cjs.map +1 -1
  181. package/dist/test/test_config.d.ts +34 -30
  182. package/dist/test/test_config.js +138 -166
  183. package/dist/test/test_config.js.map +1 -1
  184. package/dist/util/pl.cjs +4 -3
  185. package/dist/util/pl.cjs.map +1 -1
  186. package/dist/util/pl.js +4 -2
  187. package/dist/util/pl.js.map +1 -1
  188. package/dist/util/util.cjs +7 -10
  189. package/dist/util/util.cjs.map +1 -1
  190. package/dist/util/util.js +7 -9
  191. package/dist/util/util.js.map +1 -1
  192. package/package.json +10 -10
  193. package/src/core/transaction.ts +123 -133
  194. package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.cjs +0 -61
  195. package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.cjs.map +0 -1
  196. package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.js +0 -58
  197. package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.js.map +0 -1
  198. package/dist/core/PromiseTracker.d.ts.map +0 -1
  199. package/dist/core/StatefulPromise.d.ts +0 -39
  200. package/dist/core/StatefulPromise.d.ts.map +0 -1
  201. package/dist/core/abstract_stream.d.ts.map +0 -1
  202. package/dist/core/advisory_locks.d.ts +0 -10
  203. package/dist/core/advisory_locks.d.ts.map +0 -1
  204. package/dist/core/auth.d.ts.map +0 -1
  205. package/dist/core/cache.d.ts.map +0 -1
  206. package/dist/core/client.d.ts.map +0 -1
  207. package/dist/core/config.d.ts.map +0 -1
  208. package/dist/core/default_client.d.ts.map +0 -1
  209. package/dist/core/driver.d.ts.map +0 -1
  210. package/dist/core/error_resource.d.ts +0 -6
  211. package/dist/core/error_resource.d.ts.map +0 -1
  212. package/dist/core/errors.d.ts.map +0 -1
  213. package/dist/core/final.d.ts.map +0 -1
  214. package/dist/core/ll_client.d.ts.map +0 -1
  215. package/dist/core/ll_transaction.d.ts.map +0 -1
  216. package/dist/core/stat.d.ts.map +0 -1
  217. package/dist/core/transaction.d.ts.map +0 -1
  218. package/dist/core/type_conversion.d.ts +0 -8
  219. package/dist/core/type_conversion.d.ts.map +0 -1
  220. package/dist/core/types.d.ts.map +0 -1
  221. package/dist/core/unauth_client.d.ts.map +0 -1
  222. package/dist/core/websocket_stream.d.ts +0 -67
  223. package/dist/core/websocket_stream.d.ts.map +0 -1
  224. package/dist/core/wire.d.ts.map +0 -1
  225. package/dist/helpers/pl.d.ts.map +0 -1
  226. package/dist/helpers/poll.d.ts.map +0 -1
  227. package/dist/helpers/retry_strategy.d.ts +0 -24
  228. package/dist/helpers/retry_strategy.d.ts.map +0 -1
  229. package/dist/helpers/state_helpers.d.ts +0 -3
  230. package/dist/helpers/state_helpers.d.ts.map +0 -1
  231. package/dist/helpers/tx_helpers.d.ts.map +0 -1
  232. package/dist/index.cjs.map +0 -1
  233. package/dist/index.d.ts.map +0 -1
  234. package/dist/index.js.map +0 -1
  235. package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.d.ts.map +0 -1
  236. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts.map +0 -1
  237. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts.map +0 -1
  238. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts.map +0 -1
  239. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts.map +0 -1
  240. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts +0 -106
  241. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts.map +0 -1
  242. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts.map +0 -1
  243. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/ws-test.d.ts +0 -73
  244. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/ws-test.d.ts.map +0 -1
  245. package/dist/proto-grpc/google/api/http.d.ts +0 -456
  246. package/dist/proto-grpc/google/api/http.d.ts.map +0 -1
  247. package/dist/proto-grpc/google/protobuf/any.d.ts.map +0 -1
  248. package/dist/proto-grpc/google/protobuf/descriptor.d.ts +0 -2340
  249. package/dist/proto-grpc/google/protobuf/descriptor.d.ts.map +0 -1
  250. package/dist/proto-grpc/google/protobuf/duration.d.ts.map +0 -1
  251. package/dist/proto-grpc/google/protobuf/empty.d.ts +0 -32
  252. package/dist/proto-grpc/google/protobuf/empty.d.ts.map +0 -1
  253. package/dist/proto-grpc/google/protobuf/struct.d.ts +0 -187
  254. package/dist/proto-grpc/google/protobuf/struct.d.ts.map +0 -1
  255. package/dist/proto-grpc/google/protobuf/timestamp.d.ts.map +0 -1
  256. package/dist/proto-grpc/google/protobuf/wrappers.d.ts +0 -308
  257. package/dist/proto-grpc/google/protobuf/wrappers.d.ts.map +0 -1
  258. package/dist/proto-grpc/google/rpc/code.d.ts.map +0 -1
  259. package/dist/proto-grpc/google/rpc/error_details.d.ts +0 -654
  260. package/dist/proto-grpc/google/rpc/error_details.d.ts.map +0 -1
  261. package/dist/proto-grpc/google/rpc/http.d.ts +0 -121
  262. package/dist/proto-grpc/google/rpc/http.d.ts.map +0 -1
  263. package/dist/proto-grpc/google/rpc/status.d.ts +0 -55
  264. package/dist/proto-grpc/google/rpc/status.d.ts.map +0 -1
  265. package/dist/proto-rest/index.d.ts.map +0 -1
  266. package/dist/proto-rest/plapi.d.ts.map +0 -1
  267. package/dist/test/tcp-proxy.d.ts.map +0 -1
  268. package/dist/test/test_config.d.ts.map +0 -1
  269. package/dist/util/branding.d.ts +0 -7
  270. package/dist/util/branding.d.ts.map +0 -1
  271. package/dist/util/pl.d.ts +0 -9
  272. package/dist/util/pl.d.ts.map +0 -1
  273. package/dist/util/util.d.ts +0 -2
  274. package/dist/util/util.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../../src/core/types.ts"],"sourcesContent":["import { cachedDeserialize, notEmpty } from \"@milaboratories/ts-helpers\";\n\n// more details here: https://egghead.io/blog/using-branded-types-in-typescript\ndeclare const __resource_id_type__: unique symbol;\ntype BrandResourceId<B> = bigint & { [__resource_id_type__]: B };\n\n/** Global resource id */\nexport type ResourceId = BrandResourceId<\"global\">;\n\n/** Null resource id */\nexport type NullResourceId = BrandResourceId<\"null\">;\n\n/** Local resource id */\nexport type LocalResourceId = BrandResourceId<\"local\">;\n\n/** Any non-null resource id */\nexport type AnyResourceId = ResourceId | LocalResourceId;\n\n/** Any resource id */\nexport type OptionalResourceId = NullResourceId | ResourceId;\n\n/** All possible resource flavours */\nexport type OptionalAnyResourceId = NullResourceId | ResourceId | LocalResourceId;\n\nexport const NullResourceId = 0n as NullResourceId;\n\nexport function isNullResourceId(resourceId: bigint): resourceId is NullResourceId {\n return resourceId === NullResourceId;\n}\n\nexport function isNotNullResourceId(resourceId: OptionalResourceId): resourceId is ResourceId {\n return resourceId !== NullResourceId;\n}\n\nexport function ensureResourceIdNotNull(resourceId: OptionalResourceId): ResourceId {\n if (!isNotNullResourceId(resourceId)) throw new Error(\"null resource id\");\n return resourceId;\n}\n\nexport function isAnyResourceId(resourceId: bigint): resourceId is AnyResourceId {\n return resourceId !== 0n;\n}\n\n// see local / global resource logic below...\n\nexport type ResourceKind = \"Structural\" | \"Value\";\n\nexport type FieldType = \"Input\" | \"Output\" | \"Service\" | \"OTW\" | \"Dynamic\" | \"MTW\";\n\nexport type FutureFieldType = \"Output\" | \"Input\" | \"Service\";\n\nexport type FieldStatus = \"Empty\" | \"Assigned\" | \"Resolved\";\n\nexport interface ResourceType {\n readonly name: string;\n readonly version: string;\n}\n\nexport function resourceType(name: string, version: string): ResourceType {\n return { name, version };\n}\n\nexport function resourceTypeToString(rt: ResourceType): string {\n return `${rt.name}:${rt.version}`;\n}\n\nexport function resourceTypesEqual(type1: ResourceType, type2: ResourceType): boolean {\n return type1.name === type2.name && type1.version === type2.version;\n}\n\n/** Readonly fields here marks properties of resource that can't change according to pl's state machine. */\nexport type BasicResourceData = {\n readonly id: ResourceId;\n readonly originalResourceId: OptionalResourceId;\n\n readonly kind: ResourceKind;\n readonly type: ResourceType;\n\n readonly data?: Uint8Array;\n\n readonly error: OptionalResourceId;\n\n readonly inputsLocked: boolean;\n readonly outputsLocked: boolean;\n readonly resourceReady: boolean;\n\n /** This value is derived from resource state by the server and can be used as\n * a robust criteria to determine resource is in final state. */\n readonly final: boolean;\n};\n\nexport function extractBasicResourceData(rd: ResourceData): BasicResourceData {\n const {\n id,\n originalResourceId,\n kind,\n type,\n data,\n error,\n inputsLocked,\n outputsLocked,\n resourceReady,\n final,\n } = rd;\n return {\n id,\n originalResourceId,\n kind,\n type,\n data,\n error,\n inputsLocked,\n outputsLocked,\n resourceReady,\n final,\n };\n}\n\nexport const jsonToData = (data: unknown) => Buffer.from(JSON.stringify(data));\n\nexport const resDataToJson = (res: ResourceData) => cachedDeserialize(notEmpty(res.data));\n\nexport type ResourceData = BasicResourceData & {\n readonly fields: FieldData[];\n};\n\nexport function getField(r: ResourceData, name: string): FieldData {\n return notEmpty(r.fields.find((f) => f.name === name));\n}\n\nexport type FieldData = {\n readonly name: string;\n readonly type: FieldType;\n readonly status: FieldStatus;\n readonly value: OptionalResourceId;\n readonly error: OptionalResourceId;\n\n /** True if value the fields points to is in final state. */\n readonly valueIsFinal: boolean;\n};\n\n//\n// Local / Global ResourceId arithmetics\n//\n\n// Note: txId and other numerical values are made numbers but not bigint intentionally,\n// after implementing security model based on signed resource ids this will make\n// much more sense\n\nconst ResourceIdRootMask = 1n << 63n;\nconst ResourceIdLocalMask = 1n << 62n;\nconst NoFlagsIdMask = 0x3fffffffffffffffn;\nconst LocalResourceIdTxIdOffset = 24n;\nexport const MaxLocalId = 0xffffff;\nexport const MaxTxId = 0xffffffff;\n/** Mask valid after applying shift */\nconst TxIdMask = BigInt(MaxTxId);\nconst LocalIdMask = BigInt(MaxLocalId);\n\n// /** Basically removes embedded tx id */\n// const LocalIdCleanMask = 0xFF00000000FFFFFFn;\n\nexport function isRootResourceId(id: bigint) {\n return (id & ResourceIdRootMask) !== 0n;\n}\n\nexport function isLocalResourceId(id: bigint): id is LocalResourceId {\n return (id & ResourceIdLocalMask) !== 0n;\n}\n\nexport function createLocalResourceId(\n isRoot: boolean,\n localCounterValue: number,\n localTxId: number,\n): LocalResourceId {\n if (\n localCounterValue > MaxLocalId ||\n localTxId > MaxTxId ||\n localCounterValue < 0 ||\n localTxId <= 0\n )\n throw Error(\"wrong local id or tx id\");\n return ((isRoot ? ResourceIdRootMask : 0n) |\n ResourceIdLocalMask |\n BigInt(localCounterValue) |\n (BigInt(localTxId) << LocalResourceIdTxIdOffset)) as LocalResourceId;\n}\n\nexport function createGlobalResourceId(isRoot: boolean, unmaskedId: bigint): ResourceId {\n return ((isRoot ? ResourceIdRootMask : 0n) | unmaskedId) as ResourceId;\n}\n\nexport function extractTxId(localResourceId: LocalResourceId): number {\n return Number((localResourceId >> LocalResourceIdTxIdOffset) & TxIdMask);\n}\n\nexport function checkLocalityOfResourceId(resourceId: AnyResourceId, expectedTxId: number): void {\n if (!isLocalResourceId(resourceId)) return;\n if (extractTxId(resourceId) !== expectedTxId)\n throw Error(\n \"local id from another transaction, globalize id before leaking it from the transaction\",\n );\n}\n\nexport function resourceIdToString(resourceId: OptionalAnyResourceId): string {\n if (isNullResourceId(resourceId)) return \"XX:0x0\";\n if (isLocalResourceId(resourceId))\n return (\n (isRootResourceId(resourceId) ? \"R\" : \"N\") +\n \"L:0x\" +\n (LocalIdMask & resourceId).toString(16) +\n \"[0x\" +\n extractTxId(resourceId).toString(16) +\n \"]\"\n );\n else\n return (\n (isRootResourceId(resourceId) ? \"R\" : \"N\") +\n \"G:0x\" +\n (NoFlagsIdMask & resourceId).toString(16)\n );\n}\n\nconst resourceIdRegexp =\n /^(?:(?<xx>XX)|(?<rn>[XRN])(?<lg>[XLG])):0x(?<rid>[0-9a-fA-F]+)(?:\\[0x(?<txid>[0-9a-fA-F]+)])?$/;\n\nexport function resourceIdFromString(str: string): OptionalAnyResourceId | undefined {\n const match = str.match(resourceIdRegexp);\n if (match === null) return undefined;\n const { xx, rn, lg, rid, txid } = match.groups!;\n if (xx) return NullResourceId;\n if (lg === \"L\")\n return createLocalResourceId(rn === \"R\", Number.parseInt(rid, 16), Number.parseInt(txid, 16));\n else return createGlobalResourceId(rn === \"R\", BigInt(\"0x\" + rid));\n}\n\n/** Converts bigint to global resource id */\nexport function bigintToResourceId(resourceId: bigint): ResourceId {\n if (isLocalResourceId(resourceId))\n throw new Error(`Local resource id: ${resourceIdToString(resourceId)}`);\n if (isNullResourceId(resourceId)) throw new Error(`Null resource id.`);\n return resourceId as ResourceId;\n}\n\nexport function stringifyWithResourceId(object: unknown): string {\n return JSON.stringify(object, (key, value) =>\n typeof value === \"bigint\" ? resourceIdToString(value as OptionalAnyResourceId) : value,\n );\n}\n"],"names":[],"mappings":";;AAwBO,MAAM,cAAc,GAAG;AAExB,SAAU,gBAAgB,CAAC,UAAkB,EAAA;IACjD,OAAO,UAAU,KAAK,cAAc;AACtC;AAEM,SAAU,mBAAmB,CAAC,UAA8B,EAAA;IACh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,qBAAqB,CAAC,EAAE,KAAK,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;;AAC1F,QAAA,OAAO,sBAAsB,CAAC,EAAE,KAAK,GAAG,EAAE,MAAM,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC;AACpE;AAEA;AACM,SAAU,kBAAkB,CAAC,UAAkB,EAAA;IACnD,IAAI,iBAAiB,CAAC,UAAU,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,CAAA,mBAAA,EAAsB,kBAAkB,CAAC,UAAU,CAAC,CAAA,CAAE,CAAC;IACzE,IAAI,gBAAgB,CAAC,UAAU,CAAC;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,CAAA,iBAAA,CAAmB,CAAC;AACtE,IAAA,OAAO,UAAwB;AACjC;AAEM,SAAU,uBAAuB,CAAC,MAAe,EAAA;AACrD,IAAA,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,KACvC,OAAO,KAAK,KAAK,QAAQ,GAAG,kBAAkB,CAAC,KAA8B,CAAC,GAAG,KAAK,CACvF;AACH;;;;"}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../src/core/types.ts"],"sourcesContent":["import { cachedDeserialize, notEmpty } from \"@milaboratories/ts-helpers\";\n\n// more details here: https://egghead.io/blog/using-branded-types-in-typescript\ndeclare const __resource_id_type__: unique symbol;\ntype BrandResourceId<B> = bigint & { [__resource_id_type__]: B };\n\n/** Global resource id */\nexport type ResourceId = BrandResourceId<\"global\">;\n\n/** Null resource id */\nexport type NullResourceId = BrandResourceId<\"null\">;\n\n/** Local resource id */\nexport type LocalResourceId = BrandResourceId<\"local\">;\n\n/** Any non-null resource id */\nexport type AnyResourceId = ResourceId | LocalResourceId;\n\n/** Any resource id */\nexport type OptionalResourceId = NullResourceId | ResourceId;\n\n/** All possible resource flavours */\nexport type OptionalAnyResourceId = NullResourceId | ResourceId | LocalResourceId;\n\nexport const NullResourceId = 0n as NullResourceId;\n\nexport function isNullResourceId(resourceId: bigint): resourceId is NullResourceId {\n return resourceId === NullResourceId;\n}\n\nexport function isNotNullResourceId(resourceId: OptionalResourceId): resourceId is ResourceId {\n return resourceId !== NullResourceId;\n}\n\nexport function ensureResourceIdNotNull(resourceId: OptionalResourceId): ResourceId {\n if (!isNotNullResourceId(resourceId)) throw new Error(\"null resource id\");\n return resourceId;\n}\n\nexport function isAnyResourceId(resourceId: bigint): resourceId is AnyResourceId {\n return resourceId !== 0n;\n}\n\n// see local / global resource logic below...\n\nexport type ResourceKind = \"Structural\" | \"Value\";\n\nexport type FieldType = \"Input\" | \"Output\" | \"Service\" | \"OTW\" | \"Dynamic\" | \"MTW\";\n\nexport type FutureFieldType = \"Output\" | \"Input\" | \"Service\";\n\nexport type FieldStatus = \"Empty\" | \"Assigned\" | \"Resolved\";\n\nexport interface ResourceType {\n readonly name: string;\n readonly version: string;\n}\n\nexport function resourceType(name: string, version: string): ResourceType {\n return { name, version };\n}\n\nexport function resourceTypeToString(rt: ResourceType): string {\n return `${rt.name}:${rt.version}`;\n}\n\nexport function resourceTypesEqual(type1: ResourceType, type2: ResourceType): boolean {\n return type1.name === type2.name && type1.version === type2.version;\n}\n\n/** Readonly fields here marks properties of resource that can't change according to pl's state machine. */\nexport type BasicResourceData = {\n readonly id: ResourceId;\n readonly originalResourceId: OptionalResourceId;\n\n readonly kind: ResourceKind;\n readonly type: ResourceType;\n\n readonly data?: Uint8Array;\n\n readonly error: OptionalResourceId;\n\n readonly inputsLocked: boolean;\n readonly outputsLocked: boolean;\n readonly resourceReady: boolean;\n\n /** This value is derived from resource state by the server and can be used as\n * a robust criteria to determine resource is in final state. */\n readonly final: boolean;\n};\n\nexport function extractBasicResourceData(rd: ResourceData): BasicResourceData {\n const {\n id,\n originalResourceId,\n kind,\n type,\n data,\n error,\n inputsLocked,\n outputsLocked,\n resourceReady,\n final,\n } = rd;\n return {\n id,\n originalResourceId,\n kind,\n type,\n data,\n error,\n inputsLocked,\n outputsLocked,\n resourceReady,\n final,\n };\n}\n\nexport const jsonToData = (data: unknown) => Buffer.from(JSON.stringify(data));\n\nexport const resDataToJson = (res: ResourceData) => cachedDeserialize(notEmpty(res.data));\n\nexport type ResourceData = BasicResourceData & {\n readonly fields: FieldData[];\n};\n\nexport function getField(r: ResourceData, name: string): FieldData {\n return notEmpty(r.fields.find((f) => f.name === name));\n}\n\nexport type FieldData = {\n readonly name: string;\n readonly type: FieldType;\n readonly status: FieldStatus;\n readonly value: OptionalResourceId;\n readonly error: OptionalResourceId;\n\n /** True if value the fields points to is in final state. */\n readonly valueIsFinal: boolean;\n};\n\n//\n// Local / Global ResourceId arithmetics\n//\n\n// Note: txId and other numerical values are made numbers but not bigint intentionally,\n// after implementing security model based on signed resource ids this will make\n// much more sense\n\nconst ResourceIdRootMask = 1n << 63n;\nconst ResourceIdLocalMask = 1n << 62n;\nconst NoFlagsIdMask = 0x3fffffffffffffffn;\nconst LocalResourceIdTxIdOffset = 24n;\nexport const MaxLocalId = 0xffffff;\nexport const MaxTxId = 0xffffffff;\n/** Mask valid after applying shift */\nconst TxIdMask = BigInt(MaxTxId);\nconst LocalIdMask = BigInt(MaxLocalId);\n\n// /** Basically removes embedded tx id */\n// const LocalIdCleanMask = 0xFF00000000FFFFFFn;\n\nexport function isRootResourceId(id: bigint) {\n return (id & ResourceIdRootMask) !== 0n;\n}\n\nexport function isLocalResourceId(id: bigint): id is LocalResourceId {\n return (id & ResourceIdLocalMask) !== 0n;\n}\n\nexport function createLocalResourceId(\n isRoot: boolean,\n localCounterValue: number,\n localTxId: number,\n): LocalResourceId {\n if (\n localCounterValue > MaxLocalId ||\n localTxId > MaxTxId ||\n localCounterValue < 0 ||\n localTxId <= 0\n )\n throw Error(\"wrong local id or tx id\");\n return ((isRoot ? ResourceIdRootMask : 0n) |\n ResourceIdLocalMask |\n BigInt(localCounterValue) |\n (BigInt(localTxId) << LocalResourceIdTxIdOffset)) as LocalResourceId;\n}\n\nexport function createGlobalResourceId(isRoot: boolean, unmaskedId: bigint): ResourceId {\n return ((isRoot ? ResourceIdRootMask : 0n) | unmaskedId) as ResourceId;\n}\n\nexport function extractTxId(localResourceId: LocalResourceId): number {\n return Number((localResourceId >> LocalResourceIdTxIdOffset) & TxIdMask);\n}\n\nexport function checkLocalityOfResourceId(resourceId: AnyResourceId, expectedTxId: number): void {\n if (!isLocalResourceId(resourceId)) return;\n if (extractTxId(resourceId) !== expectedTxId)\n throw Error(\n \"local id from another transaction, globalize id before leaking it from the transaction\",\n );\n}\n\nexport function resourceIdToString(resourceId: OptionalAnyResourceId): string {\n if (isNullResourceId(resourceId)) return \"XX:0x0\";\n if (isLocalResourceId(resourceId))\n return (\n (isRootResourceId(resourceId) ? \"R\" : \"N\") +\n \"L:0x\" +\n (LocalIdMask & resourceId).toString(16) +\n \"[0x\" +\n extractTxId(resourceId).toString(16) +\n \"]\"\n );\n else\n return (\n (isRootResourceId(resourceId) ? \"R\" : \"N\") +\n \"G:0x\" +\n (NoFlagsIdMask & resourceId).toString(16)\n );\n}\n\nconst resourceIdRegexp =\n /^(?:(?<xx>XX)|(?<rn>[XRN])(?<lg>[XLG])):0x(?<rid>[0-9a-fA-F]+)(?:\\[0x(?<txid>[0-9a-fA-F]+)])?$/;\n\nexport function resourceIdFromString(str: string): OptionalAnyResourceId | undefined {\n const match = str.match(resourceIdRegexp);\n if (match === null) return undefined;\n const { xx, rn, lg, rid, txid } = match.groups!;\n if (xx) return NullResourceId;\n if (lg === \"L\")\n return createLocalResourceId(rn === \"R\", Number.parseInt(rid, 16), Number.parseInt(txid, 16));\n else return createGlobalResourceId(rn === \"R\", BigInt(\"0x\" + rid));\n}\n\n/** Converts bigint to global resource id */\nexport function bigintToResourceId(resourceId: bigint): ResourceId {\n if (isLocalResourceId(resourceId))\n throw new Error(`Local resource id: ${resourceIdToString(resourceId)}`);\n if (isNullResourceId(resourceId)) throw new Error(`Null resource id.`);\n return resourceId as ResourceId;\n}\n\nexport function stringifyWithResourceId(object: unknown): string {\n return JSON.stringify(object, (key, value) =>\n typeof value === \"bigint\" ? resourceIdToString(value as OptionalAnyResourceId) : value,\n );\n}\n"],"mappings":";;;AAwBA,MAAa,iBAAiB;AAE9B,SAAgB,iBAAiB,YAAkD;AACjF,QAAO,eAAe;;AAGxB,SAAgB,oBAAoB,YAA0D;AAC5F,QAAO,eAAe;;AAGxB,SAAgB,wBAAwB,YAA4C;AAClF,KAAI,CAAC,oBAAoB,WAAW,CAAE,OAAM,IAAI,MAAM,mBAAmB;AACzE,QAAO;;AAGT,SAAgB,gBAAgB,YAAiD;AAC/E,QAAO,eAAe;;AAkBxB,SAAgB,aAAa,MAAc,SAA+B;AACxE,QAAO;EAAE;EAAM;EAAS;;AAG1B,SAAgB,qBAAqB,IAA0B;AAC7D,QAAO,GAAG,GAAG,KAAK,GAAG,GAAG;;AAG1B,SAAgB,mBAAmB,OAAqB,OAA8B;AACpF,QAAO,MAAM,SAAS,MAAM,QAAQ,MAAM,YAAY,MAAM;;AAwB9D,SAAgB,yBAAyB,IAAqC;CAC5E,MAAM,EACJ,IACA,oBACA,MACA,MACA,MACA,OACA,cACA,eACA,eACA,UACE;AACJ,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD;;AAGH,MAAa,cAAc,SAAkB,OAAO,KAAK,KAAK,UAAU,KAAK,CAAC;AAE9E,MAAa,iBAAiB,QAAsB,kBAAkB,SAAS,IAAI,KAAK,CAAC;AAMzF,SAAgB,SAAS,GAAiB,MAAyB;AACjE,QAAO,SAAS,EAAE,OAAO,MAAM,MAAM,EAAE,SAAS,KAAK,CAAC;;AAsBxD,MAAM,qBAAqB,MAAM;AACjC,MAAM,sBAAsB,MAAM;AAClC,MAAM,gBAAgB;AACtB,MAAM,4BAA4B;AAClC,MAAa,aAAa;AAC1B,MAAa,UAAU;;AAEvB,MAAM,WAAW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AAC;KAC1F,QAAO,uBAAuB,OAAO,KAAK,OAAO,OAAO,IAAI,CAAC;;;AAIpE,SAAgB,mBAAmB,YAAgC;AACjE,KAAI,kBAAkB,WAAW,CAC/B,OAAM,IAAI,MAAM,sBAAsB,mBAAmB,WAAW,GAAG;AACzE,KAAI,iBAAiB,WAAW,CAAE,OAAM,IAAI,MAAM,oBAAoB;AACtE,QAAO;;AAGT,SAAgB,wBAAwB,QAAyB;AAC/D,QAAO,KAAK,UAAU,SAAS,KAAK,UAClC,OAAO,UAAU,WAAW,mBAAmB,MAA+B,GAAG,MAClF"}
@@ -1,45 +1,39 @@
1
- 'use strict';
2
-
3
- var ll_client = require('./ll_client.cjs');
4
- var tsHelpers = require('@milaboratories/ts-helpers');
5
- var errors = require('./errors.cjs');
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ const require_errors = require('./errors.cjs');
3
+ const require_ll_client = require('./ll_client.cjs');
4
+ let _milaboratories_ts_helpers = require("@milaboratories/ts-helpers");
6
5
 
6
+ //#region src/core/unauth_client.ts
7
7
  /** Primarily used for initial authentication (login) */
8
- class UnauthenticatedPlClient {
9
- ll;
10
- constructor(ll) {
11
- this.ll = ll;
12
- }
13
- static async build(configOrAddress, ops) {
14
- const ll = await ll_client.LLPlClient.build(configOrAddress, ops);
15
- return new UnauthenticatedPlClient(ll);
16
- }
17
- async ping() {
18
- return await this.ll.ping();
19
- }
20
- async authMethods() {
21
- return await this.ll.authMethods();
22
- }
23
- async requireAuth() {
24
- return (await this.authMethods()).methods.length > 0;
25
- }
26
- async login(user, password) {
27
- try {
28
- const token = await this.ll.getJwtToken(BigInt(this.ll.conf.authTTLSeconds), {
29
- authorization: "Basic " + Buffer.from(user + ":" + password).toString("base64"),
30
- });
31
- const jwtToken = tsHelpers.notEmpty(token);
32
- if (jwtToken === "")
33
- throw new Error("empty token");
34
- return { jwtToken };
35
- }
36
- catch (e) {
37
- if (e.code === "UNAUTHENTICATED")
38
- throw new errors.UnauthenticatedError(e.message);
39
- throw new Error(e);
40
- }
41
- }
42
- }
8
+ var UnauthenticatedPlClient = class UnauthenticatedPlClient {
9
+ ll;
10
+ constructor(ll) {
11
+ this.ll = ll;
12
+ }
13
+ static async build(configOrAddress, ops) {
14
+ return new UnauthenticatedPlClient(await require_ll_client.LLPlClient.build(configOrAddress, ops));
15
+ }
16
+ async ping() {
17
+ return await this.ll.ping();
18
+ }
19
+ async authMethods() {
20
+ return await this.ll.authMethods();
21
+ }
22
+ async requireAuth() {
23
+ return (await this.authMethods()).methods.length > 0;
24
+ }
25
+ async login(user, password) {
26
+ try {
27
+ const jwtToken = (0, _milaboratories_ts_helpers.notEmpty)(await this.ll.getJwtToken(BigInt(this.ll.conf.authTTLSeconds), { authorization: "Basic " + Buffer.from(user + ":" + password).toString("base64") }));
28
+ if (jwtToken === "") throw new Error("empty token");
29
+ return { jwtToken };
30
+ } catch (e) {
31
+ if (e.code === "UNAUTHENTICATED") throw new require_errors.UnauthenticatedError(e.message);
32
+ throw new Error(e);
33
+ }
34
+ }
35
+ };
43
36
 
37
+ //#endregion
44
38
  exports.UnauthenticatedPlClient = UnauthenticatedPlClient;
45
- //# sourceMappingURL=unauth_client.cjs.map
39
+ //# sourceMappingURL=unauth_client.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"unauth_client.cjs","sources":["../../src/core/unauth_client.ts"],"sourcesContent":["import type { AuthInformation, PlClientConfig } from \"./config\";\nimport type {\n AuthAPI_ListMethods_Response,\n MaintenanceAPI_Ping_Response,\n} from \"../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api\";\nimport { LLPlClient } from \"./ll_client\";\nimport { type MiLogger, notEmpty } from \"@milaboratories/ts-helpers\";\nimport { UnauthenticatedError } from \"./errors\";\n\n/** Primarily used for initial authentication (login) */\nexport class UnauthenticatedPlClient {\n public readonly ll: LLPlClient;\n\n private constructor(ll: LLPlClient) {\n this.ll = ll;\n }\n\n public static async build(\n configOrAddress: PlClientConfig | string,\n ops?: { logger?: MiLogger },\n ): Promise<UnauthenticatedPlClient> {\n const ll = await LLPlClient.build(configOrAddress, ops);\n return new UnauthenticatedPlClient(ll);\n }\n\n public async ping(): Promise<MaintenanceAPI_Ping_Response> {\n return await this.ll.ping();\n }\n\n public async authMethods(): Promise<AuthAPI_ListMethods_Response> {\n return await this.ll.authMethods();\n }\n\n public async requireAuth(): Promise<boolean> {\n return (await this.authMethods()).methods.length > 0;\n }\n\n public async login(user: string, password: string): Promise<AuthInformation> {\n try {\n const token = await this.ll.getJwtToken(BigInt(this.ll.conf.authTTLSeconds), {\n authorization: \"Basic \" + Buffer.from(user + \":\" + password).toString(\"base64\"),\n });\n const jwtToken = notEmpty(token);\n if (jwtToken === \"\") throw new Error(\"empty token\");\n return { jwtToken };\n } catch (e: any) {\n if (e.code === \"UNAUTHENTICATED\") throw new UnauthenticatedError(e.message);\n throw new Error(e);\n }\n }\n}\n"],"names":["LLPlClient","notEmpty","UnauthenticatedError"],"mappings":";;;;;;AASA;MACa,uBAAuB,CAAA;AAClB,IAAA,EAAE;AAElB,IAAA,WAAA,CAAoB,EAAc,EAAA;AAChC,QAAA,IAAI,CAAC,EAAE,GAAG,EAAE;IACd;AAEO,IAAA,aAAa,KAAK,CACvB,eAAwC,EACxC,GAA2B,EAAA;QAE3B,MAAM,EAAE,GAAG,MAAMA,oBAAU,CAAC,KAAK,CAAC,eAAe,EAAE,GAAG,CAAC;AACvD,QAAA,OAAO,IAAI,uBAAuB,CAAC,EAAE,CAAC;IACxC;AAEO,IAAA,MAAM,IAAI,GAAA;AACf,QAAA,OAAO,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE;IAC7B;AAEO,IAAA,MAAM,WAAW,GAAA;AACtB,QAAA,OAAO,MAAM,IAAI,CAAC,EAAE,CAAC,WAAW,EAAE;IACpC;AAEO,IAAA,MAAM,WAAW,GAAA;AACtB,QAAA,OAAO,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC;IACtD;AAEO,IAAA,MAAM,KAAK,CAAC,IAAY,EAAE,QAAgB,EAAA;AAC/C,QAAA,IAAI;AACF,YAAA,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;AAC3E,gBAAA,aAAa,EAAE,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,GAAG,GAAG,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAChF,aAAA,CAAC;AACF,YAAA,MAAM,QAAQ,GAAGC,kBAAQ,CAAC,KAAK,CAAC;YAChC,IAAI,QAAQ,KAAK,EAAE;AAAE,gBAAA,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC;YACnD,OAAO,EAAE,QAAQ,EAAE;QACrB;QAAE,OAAO,CAAM,EAAE;AACf,YAAA,IAAI,CAAC,CAAC,IAAI,KAAK,iBAAiB;AAAE,gBAAA,MAAM,IAAIC,2BAAoB,CAAC,CAAC,CAAC,OAAO,CAAC;AAC3E,YAAA,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC;QACpB;IACF;AACD;;;;"}
1
+ {"version":3,"file":"unauth_client.cjs","names":["LLPlClient","UnauthenticatedError"],"sources":["../../src/core/unauth_client.ts"],"sourcesContent":["import type { AuthInformation, PlClientConfig } from \"./config\";\nimport type {\n AuthAPI_ListMethods_Response,\n MaintenanceAPI_Ping_Response,\n} from \"../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api\";\nimport { LLPlClient } from \"./ll_client\";\nimport { type MiLogger, notEmpty } from \"@milaboratories/ts-helpers\";\nimport { UnauthenticatedError } from \"./errors\";\n\n/** Primarily used for initial authentication (login) */\nexport class UnauthenticatedPlClient {\n public readonly ll: LLPlClient;\n\n private constructor(ll: LLPlClient) {\n this.ll = ll;\n }\n\n public static async build(\n configOrAddress: PlClientConfig | string,\n ops?: { logger?: MiLogger },\n ): Promise<UnauthenticatedPlClient> {\n const ll = await LLPlClient.build(configOrAddress, ops);\n return new UnauthenticatedPlClient(ll);\n }\n\n public async ping(): Promise<MaintenanceAPI_Ping_Response> {\n return await this.ll.ping();\n }\n\n public async authMethods(): Promise<AuthAPI_ListMethods_Response> {\n return await this.ll.authMethods();\n }\n\n public async requireAuth(): Promise<boolean> {\n return (await this.authMethods()).methods.length > 0;\n }\n\n public async login(user: string, password: string): Promise<AuthInformation> {\n try {\n const token = await this.ll.getJwtToken(BigInt(this.ll.conf.authTTLSeconds), {\n authorization: \"Basic \" + Buffer.from(user + \":\" + password).toString(\"base64\"),\n });\n const jwtToken = notEmpty(token);\n if (jwtToken === \"\") throw new Error(\"empty token\");\n return { jwtToken };\n } catch (e: any) {\n if (e.code === \"UNAUTHENTICATED\") throw new UnauthenticatedError(e.message);\n throw new Error(e);\n }\n }\n}\n"],"mappings":";;;;;;;AAUA,IAAa,0BAAb,MAAa,wBAAwB;CACnC,AAAgB;CAEhB,AAAQ,YAAY,IAAgB;AAClC,OAAK,KAAK;;CAGZ,aAAoB,MAClB,iBACA,KACkC;AAElC,SAAO,IAAI,wBADA,MAAMA,6BAAW,MAAM,iBAAiB,IAAI,CACjB;;CAGxC,MAAa,OAA8C;AACzD,SAAO,MAAM,KAAK,GAAG,MAAM;;CAG7B,MAAa,cAAqD;AAChE,SAAO,MAAM,KAAK,GAAG,aAAa;;CAGpC,MAAa,cAAgC;AAC3C,UAAQ,MAAM,KAAK,aAAa,EAAE,QAAQ,SAAS;;CAGrD,MAAa,MAAM,MAAc,UAA4C;AAC3E,MAAI;GAIF,MAAM,oDAHQ,MAAM,KAAK,GAAG,YAAY,OAAO,KAAK,GAAG,KAAK,eAAe,EAAE,EAC3E,eAAe,WAAW,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC,SAAS,SAAS,EAChF,CAAC,CAC8B;AAChC,OAAI,aAAa,GAAI,OAAM,IAAI,MAAM,cAAc;AACnD,UAAO,EAAE,UAAU;WACZ,GAAQ;AACf,OAAI,EAAE,SAAS,kBAAmB,OAAM,IAAIC,oCAAqB,EAAE,QAAQ;AAC3E,SAAM,IAAI,MAAM,EAAE"}
@@ -1,17 +1,21 @@
1
- import type { AuthInformation, PlClientConfig } from "./config";
2
- import type { AuthAPI_ListMethods_Response, MaintenanceAPI_Ping_Response } from "../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api";
3
- import { LLPlClient } from "./ll_client";
4
- import { type MiLogger } from "@milaboratories/ts-helpers";
1
+ import { AuthAPI_ListMethods_Response, MaintenanceAPI_Ping_Response } from "../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.js";
2
+ import { AuthInformation, PlClientConfig } from "./config.js";
3
+ import { LLPlClient } from "./ll_client.js";
4
+ import { MiLogger } from "@milaboratories/ts-helpers";
5
+
6
+ //#region src/core/unauth_client.d.ts
5
7
  /** Primarily used for initial authentication (login) */
6
- export declare class UnauthenticatedPlClient {
7
- readonly ll: LLPlClient;
8
- private constructor();
9
- static build(configOrAddress: PlClientConfig | string, ops?: {
10
- logger?: MiLogger;
11
- }): Promise<UnauthenticatedPlClient>;
12
- ping(): Promise<MaintenanceAPI_Ping_Response>;
13
- authMethods(): Promise<AuthAPI_ListMethods_Response>;
14
- requireAuth(): Promise<boolean>;
15
- login(user: string, password: string): Promise<AuthInformation>;
8
+ declare class UnauthenticatedPlClient {
9
+ readonly ll: LLPlClient;
10
+ private constructor();
11
+ static build(configOrAddress: PlClientConfig | string, ops?: {
12
+ logger?: MiLogger;
13
+ }): Promise<UnauthenticatedPlClient>;
14
+ ping(): Promise<MaintenanceAPI_Ping_Response>;
15
+ authMethods(): Promise<AuthAPI_ListMethods_Response>;
16
+ requireAuth(): Promise<boolean>;
17
+ login(user: string, password: string): Promise<AuthInformation>;
16
18
  }
19
+ //#endregion
20
+ export { UnauthenticatedPlClient };
17
21
  //# sourceMappingURL=unauth_client.d.ts.map
@@ -1,43 +1,38 @@
1
- import { LLPlClient } from './ll_client.js';
2
- import { notEmpty } from '@milaboratories/ts-helpers';
3
- import { UnauthenticatedError } from './errors.js';
1
+ import { UnauthenticatedError } from "./errors.js";
2
+ import { LLPlClient } from "./ll_client.js";
3
+ import { notEmpty } from "@milaboratories/ts-helpers";
4
4
 
5
+ //#region src/core/unauth_client.ts
5
6
  /** Primarily used for initial authentication (login) */
6
- class UnauthenticatedPlClient {
7
- ll;
8
- constructor(ll) {
9
- this.ll = ll;
10
- }
11
- static async build(configOrAddress, ops) {
12
- const ll = await LLPlClient.build(configOrAddress, ops);
13
- return new UnauthenticatedPlClient(ll);
14
- }
15
- async ping() {
16
- return await this.ll.ping();
17
- }
18
- async authMethods() {
19
- return await this.ll.authMethods();
20
- }
21
- async requireAuth() {
22
- return (await this.authMethods()).methods.length > 0;
23
- }
24
- async login(user, password) {
25
- try {
26
- const token = await this.ll.getJwtToken(BigInt(this.ll.conf.authTTLSeconds), {
27
- authorization: "Basic " + Buffer.from(user + ":" + password).toString("base64"),
28
- });
29
- const jwtToken = notEmpty(token);
30
- if (jwtToken === "")
31
- throw new Error("empty token");
32
- return { jwtToken };
33
- }
34
- catch (e) {
35
- if (e.code === "UNAUTHENTICATED")
36
- throw new UnauthenticatedError(e.message);
37
- throw new Error(e);
38
- }
39
- }
40
- }
7
+ var UnauthenticatedPlClient = class UnauthenticatedPlClient {
8
+ ll;
9
+ constructor(ll) {
10
+ this.ll = ll;
11
+ }
12
+ static async build(configOrAddress, ops) {
13
+ return new UnauthenticatedPlClient(await LLPlClient.build(configOrAddress, ops));
14
+ }
15
+ async ping() {
16
+ return await this.ll.ping();
17
+ }
18
+ async authMethods() {
19
+ return await this.ll.authMethods();
20
+ }
21
+ async requireAuth() {
22
+ return (await this.authMethods()).methods.length > 0;
23
+ }
24
+ async login(user, password) {
25
+ try {
26
+ const jwtToken = notEmpty(await this.ll.getJwtToken(BigInt(this.ll.conf.authTTLSeconds), { authorization: "Basic " + Buffer.from(user + ":" + password).toString("base64") }));
27
+ if (jwtToken === "") throw new Error("empty token");
28
+ return { jwtToken };
29
+ } catch (e) {
30
+ if (e.code === "UNAUTHENTICATED") throw new UnauthenticatedError(e.message);
31
+ throw new Error(e);
32
+ }
33
+ }
34
+ };
41
35
 
36
+ //#endregion
42
37
  export { UnauthenticatedPlClient };
43
- //# sourceMappingURL=unauth_client.js.map
38
+ //# sourceMappingURL=unauth_client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"unauth_client.js","sources":["../../src/core/unauth_client.ts"],"sourcesContent":["import type { AuthInformation, PlClientConfig } from \"./config\";\nimport type {\n AuthAPI_ListMethods_Response,\n MaintenanceAPI_Ping_Response,\n} from \"../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api\";\nimport { LLPlClient } from \"./ll_client\";\nimport { type MiLogger, notEmpty } from \"@milaboratories/ts-helpers\";\nimport { UnauthenticatedError } from \"./errors\";\n\n/** Primarily used for initial authentication (login) */\nexport class UnauthenticatedPlClient {\n public readonly ll: LLPlClient;\n\n private constructor(ll: LLPlClient) {\n this.ll = ll;\n }\n\n public static async build(\n configOrAddress: PlClientConfig | string,\n ops?: { logger?: MiLogger },\n ): Promise<UnauthenticatedPlClient> {\n const ll = await LLPlClient.build(configOrAddress, ops);\n return new UnauthenticatedPlClient(ll);\n }\n\n public async ping(): Promise<MaintenanceAPI_Ping_Response> {\n return await this.ll.ping();\n }\n\n public async authMethods(): Promise<AuthAPI_ListMethods_Response> {\n return await this.ll.authMethods();\n }\n\n public async requireAuth(): Promise<boolean> {\n return (await this.authMethods()).methods.length > 0;\n }\n\n public async login(user: string, password: string): Promise<AuthInformation> {\n try {\n const token = await this.ll.getJwtToken(BigInt(this.ll.conf.authTTLSeconds), {\n authorization: \"Basic \" + Buffer.from(user + \":\" + password).toString(\"base64\"),\n });\n const jwtToken = notEmpty(token);\n if (jwtToken === \"\") throw new Error(\"empty token\");\n return { jwtToken };\n } catch (e: any) {\n if (e.code === \"UNAUTHENTICATED\") throw new UnauthenticatedError(e.message);\n thro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,EAAE;AACf,YAAA,IAAI,CAAC,CAAC,IAAI,KAAK,iBAAiB;AAAE,gBAAA,MAAM,IAAI,oBAAoB,CAAC,CAAC,CAAC,OAAO,CAAC;AAC3E,YAAA,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC;QACpB;IACF;AACD;;;;"}
1
+ {"version":3,"file":"unauth_client.js","names":[],"sources":["../../src/core/unauth_client.ts"],"sourcesContent":["import type { AuthInformation, PlClientConfig } from \"./config\";\nimport type {\n AuthAPI_ListMethods_Response,\n MaintenanceAPI_Ping_Response,\n} from \"../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api\";\nimport { LLPlClient } from \"./ll_client\";\nimport { type MiLogger, notEmpty } from \"@milaboratories/ts-helpers\";\nimport { UnauthenticatedError } from \"./errors\";\n\n/** Primarily used for initial authentication (login) */\nexport class UnauthenticatedPlClient {\n public readonly ll: LLPlClient;\n\n private constructor(ll: LLPlClient) {\n this.ll = ll;\n }\n\n public static async build(\n configOrAddress: PlClientConfig | string,\n ops?: { logger?: MiLogger },\n ): Promise<UnauthenticatedPlClient> {\n const ll = await LLPlClient.build(configOrAddress, ops);\n return new UnauthenticatedPlClient(ll);\n }\n\n public async ping(): Promise<MaintenanceAPI_Ping_Response> {\n return await this.ll.ping();\n }\n\n public async authMethods(): Promise<AuthAPI_ListMethods_Response> {\n return await this.ll.authMethods();\n }\n\n public async requireAuth(): Promise<boolean> {\n return (await this.authMethods()).methods.length > 0;\n }\n\n public async login(user: string, password: string): Promise<AuthInformation> {\n try {\n const token = await this.ll.getJwtToken(BigInt(this.ll.conf.authTTLSeconds), {\n authorization: \"Basic \" + Buffer.from(user + \":\" + password).toString(\"base64\"),\n });\n const jwtToken = notEmpty(token);\n if (jwtToken === \"\") throw new Error(\"empty token\");\n return { jwtToken };\n } catch (e: any) {\n if (e.code === \"UNAUTHENTICATED\") throw new UnauthenticatedError(e.message);\n throw new Error(e);\n }\n }\n}\n"],"mappings":";;;;;;AAUA,IAAa,0BAAb,MAAa,wBAAwB;CACnC,AAAgB;CAEhB,AAAQ,YAAY,IAAgB;AAClC,OAAK,KAAK;;CAGZ,aAAoB,MAClB,iBACA,KACkC;AAElC,SAAO,IAAI,wBADA,MAAM,WAAW,MAAM,iBAAiB,IAAI,CACjB;;CAGxC,MAAa,OAA8C;AACzD,SAAO,MAAM,KAAK,GAAG,MAAM;;CAG7B,MAAa,cAAqD;AAChE,SAAO,MAAM,KAAK,GAAG,aAAa;;CAGpC,MAAa,cAAgC;AAC3C,UAAQ,MAAM,KAAK,aAAa,EAAE,QAAQ,SAAS;;CAGrD,MAAa,MAAM,MAAc,UAA4C;AAC3E,MAAI;GAIF,MAAM,WAAW,SAHH,MAAM,KAAK,GAAG,YAAY,OAAO,KAAK,GAAG,KAAK,eAAe,EAAE,EAC3E,eAAe,WAAW,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC,SAAS,SAAS,EAChF,CAAC,CAC8B;AAChC,OAAI,aAAa,GAAI,OAAM,IAAI,MAAM,cAAc;AACnD,UAAO,EAAE,UAAU;WACZ,GAAQ;AACf,OAAI,EAAE,SAAS,kBAAmB,OAAM,IAAI,qBAAqB,EAAE,QAAQ;AAC3E,SAAM,IAAI,MAAM,EAAE"}