@milaboratories/pl-client 2.17.7 → 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 +8 -8
  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,120 +1,95 @@
1
- import fs__default from 'node:fs';
2
- import { plAddressToConfig } from './config.js';
3
- import canonicalize from 'canonicalize';
4
- import YAML from 'yaml';
5
- import * as os from 'node:os';
6
- import * as path from 'node:path';
7
- import { notEmpty } from '@milaboratories/ts-helpers';
8
- import { UnauthenticatedPlClient } from './unauth_client.js';
9
- import { PlClient } from './client.js';
10
- import { createHash } from 'node:crypto';
11
- import { inferAuthRefreshTime } from './auth.js';
1
+ import { plAddressToConfig } from "./config.js";
2
+ import { inferAuthRefreshTime } from "./auth.js";
3
+ import { PlClient } from "./client.js";
4
+ import { UnauthenticatedPlClient } from "./unauth_client.js";
5
+ import { notEmpty } from "@milaboratories/ts-helpers";
6
+ import { createHash } from "node:crypto";
7
+ import fs from "node:fs";
8
+ import canonicalize from "canonicalize";
9
+ import YAML from "yaml";
10
+ import * as os from "node:os";
11
+ import * as path from "node:path";
12
12
 
13
- const CONFIG_FILE_LOCAL_JSON = "pl.json";
14
- const CONFIG_FILE_USER_JSON = path.join(os.homedir(), ".pl.json");
15
- const CONFIG_FILE_LOCAL_YAML = "pl.yaml";
16
- const CONFIG_FILE_USER_YAML = path.join(os.homedir(), ".pl.yaml");
13
+ //#region src/core/default_client.ts
17
14
  const CONF_FILE_SEQUENCE = [
18
- CONFIG_FILE_LOCAL_JSON,
19
- CONFIG_FILE_LOCAL_YAML,
20
- CONFIG_FILE_USER_JSON,
21
- CONFIG_FILE_USER_YAML,
15
+ "pl.json",
16
+ "pl.yaml",
17
+ path.join(os.homedir(), ".pl.json"),
18
+ path.join(os.homedir(), ".pl.yaml")
22
19
  ];
23
20
  const AUTH_DATA_FILE = ".pl_auth.json";
24
21
  const FILE_CONFIG_OVERRIDE_FIELDS = [
25
- "grpcProxy",
26
- "httpProxy",
27
- "user",
28
- "password",
29
- "alternativeRoot",
30
- "defaultROTransactionTimeout",
31
- "defaultRWTransactionTimeout",
32
- "defaultRequestTimeout",
33
- "authTTLSeconds",
34
- "authMaxRefreshSeconds",
22
+ "grpcProxy",
23
+ "httpProxy",
24
+ "user",
25
+ "password",
26
+ "alternativeRoot",
27
+ "defaultROTransactionTimeout",
28
+ "defaultRWTransactionTimeout",
29
+ "defaultRequestTimeout",
30
+ "authTTLSeconds",
31
+ "authMaxRefreshSeconds"
35
32
  ];
36
33
  function tryGetFileConfig() {
37
- for (const confPath of CONF_FILE_SEQUENCE)
38
- if (fs__default.existsSync(confPath)) {
39
- const fileContent = fs__default.readFileSync(confPath, { encoding: "utf-8" });
40
- if (confPath.endsWith("json"))
41
- return [JSON.parse(fileContent), confPath];
42
- else
43
- return [YAML.parse(fileContent), confPath];
44
- }
45
- return undefined;
34
+ for (const confPath of CONF_FILE_SEQUENCE) if (fs.existsSync(confPath)) {
35
+ const fileContent = fs.readFileSync(confPath, { encoding: "utf-8" });
36
+ if (confPath.endsWith("json")) return [JSON.parse(fileContent), confPath];
37
+ else return [YAML.parse(fileContent), confPath];
38
+ }
46
39
  }
47
40
  function saveAuthInfoCallback(confHash, authMaxRefreshSeconds) {
48
- return (newAuthInfo) => {
49
- fs__default.writeFileSync(AUTH_DATA_FILE, Buffer.from(JSON.stringify({
50
- confHash,
51
- authInformation: newAuthInfo,
52
- expiration: inferAuthRefreshTime(newAuthInfo, authMaxRefreshSeconds),
53
- })), "utf8");
54
- };
41
+ return (newAuthInfo) => {
42
+ fs.writeFileSync(AUTH_DATA_FILE, Buffer.from(JSON.stringify({
43
+ confHash,
44
+ authInformation: newAuthInfo,
45
+ expiration: inferAuthRefreshTime(newAuthInfo, authMaxRefreshSeconds)
46
+ })), "utf8");
47
+ };
55
48
  }
56
49
  const cleanAuthInfoCallback = () => {
57
- fs__default.rmSync(AUTH_DATA_FILE);
50
+ fs.rmSync(AUTH_DATA_FILE);
58
51
  };
59
52
  /** Uses default algorithm to construct a pl client from the environment */
60
53
  async function defaultPlClient() {
61
- let config = undefined;
62
- if (process.env.PL_ADDRESS !== undefined) {
63
- config = plAddressToConfig(process.env.PL_ADDRESS);
64
- }
65
- else {
66
- const fromFile = tryGetFileConfig();
67
- if (fromFile !== undefined) {
68
- const [fileConfig, configPath] = fromFile;
69
- const address = notEmpty(fileConfig.address, `no pl address in file: ${configPath}`);
70
- config = plAddressToConfig(address);
71
- // applying overrides
72
- for (const field of FILE_CONFIG_OVERRIDE_FIELDS)
73
- if (fileConfig[field] !== undefined)
74
- config[field] = fileConfig[field];
75
- }
76
- }
77
- if (config === undefined)
78
- throw new Error("Can't find configuration to create default platform client.");
79
- if (process.env.PL_USER !== undefined)
80
- config.user = process.env.PL_USER;
81
- if (process.env.PL_PASSWORD !== undefined)
82
- config.user = process.env.PL_PASSWORD;
83
- const confHash = createHash("sha256")
84
- .update(Buffer.from(canonicalize(config)))
85
- .digest("base64");
86
- let authInformation = undefined;
87
- // try recover auth information from cache
88
- if (fs__default.existsSync(AUTH_DATA_FILE)) {
89
- const cache = JSON.parse(fs__default.readFileSync(AUTH_DATA_FILE, { encoding: "utf-8" }));
90
- if (cache.confHash === confHash && cache.expiration > Date.now())
91
- authInformation = cache.authInformation;
92
- }
93
- if (authInformation === undefined) {
94
- const client = await UnauthenticatedPlClient.build(config);
95
- if (await client.requireAuth()) {
96
- if (config.user === undefined || config.password === undefined)
97
- throw new Error(`No auth information for found to authenticate with PL server.`);
98
- authInformation = await client.login(config.user, config.password);
99
- }
100
- else {
101
- // No authorization is required
102
- authInformation = {};
103
- }
104
- // saving cache
105
- fs__default.writeFileSync(AUTH_DATA_FILE, Buffer.from(JSON.stringify({
106
- confHash,
107
- authInformation,
108
- expiration: inferAuthRefreshTime(authInformation, config.authMaxRefreshSeconds),
109
- })), "utf8");
110
- }
111
- return await PlClient.init(config, {
112
- authInformation,
113
- onUpdate: (_newAuthInfo) => saveAuthInfoCallback(confHash, config.authMaxRefreshSeconds),
114
- onUpdateError: cleanAuthInfoCallback,
115
- onAuthError: cleanAuthInfoCallback,
116
- });
54
+ let config = void 0;
55
+ if (process.env.PL_ADDRESS !== void 0) config = plAddressToConfig(process.env.PL_ADDRESS);
56
+ else {
57
+ const fromFile = tryGetFileConfig();
58
+ if (fromFile !== void 0) {
59
+ const [fileConfig, configPath] = fromFile;
60
+ config = plAddressToConfig(notEmpty(fileConfig.address, `no pl address in file: ${configPath}`));
61
+ for (const field of FILE_CONFIG_OVERRIDE_FIELDS) if (fileConfig[field] !== void 0) config[field] = fileConfig[field];
62
+ }
63
+ }
64
+ if (config === void 0) throw new Error("Can't find configuration to create default platform client.");
65
+ if (process.env.PL_USER !== void 0) config.user = process.env.PL_USER;
66
+ if (process.env.PL_PASSWORD !== void 0) config.user = process.env.PL_PASSWORD;
67
+ const confHash = createHash("sha256").update(Buffer.from(canonicalize(config))).digest("base64");
68
+ let authInformation = void 0;
69
+ if (fs.existsSync(AUTH_DATA_FILE)) {
70
+ const cache = JSON.parse(fs.readFileSync(AUTH_DATA_FILE, { encoding: "utf-8" }));
71
+ if (cache.confHash === confHash && cache.expiration > Date.now()) authInformation = cache.authInformation;
72
+ }
73
+ if (authInformation === void 0) {
74
+ const client = await UnauthenticatedPlClient.build(config);
75
+ if (await client.requireAuth()) {
76
+ if (config.user === void 0 || config.password === void 0) throw new Error(`No auth information for found to authenticate with PL server.`);
77
+ authInformation = await client.login(config.user, config.password);
78
+ } else authInformation = {};
79
+ fs.writeFileSync(AUTH_DATA_FILE, Buffer.from(JSON.stringify({
80
+ confHash,
81
+ authInformation,
82
+ expiration: inferAuthRefreshTime(authInformation, config.authMaxRefreshSeconds)
83
+ })), "utf8");
84
+ }
85
+ return await PlClient.init(config, {
86
+ authInformation,
87
+ onUpdate: (_newAuthInfo) => saveAuthInfoCallback(confHash, config.authMaxRefreshSeconds),
88
+ onUpdateError: cleanAuthInfoCallback,
89
+ onAuthError: cleanAuthInfoCallback
90
+ });
117
91
  }
118
92
 
93
+ //#endregion
119
94
  export { defaultPlClient, tryGetFileConfig };
120
- //# sourceMappingURL=default_client.js.map
95
+ //# sourceMappingURL=default_client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"default_client.js","sources":["../../src/core/default_client.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { AuthInformation, PlClientConfig } from \"./config\";\nimport { plAddressToConfig } from \"./config\";\nimport canonicalize from \"canonicalize\";\nimport YAML from \"yaml\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport { UnauthenticatedPlClient } from \"./unauth_client\";\nimport { PlClient } from \"./client\";\nimport { createHash } from \"node:crypto\";\nimport { inferAuthRefreshTime } from \"./auth\";\n\nconst CONFIG_FILE_LOCAL_JSON = \"pl.json\";\nconst CONFIG_FILE_USER_JSON = path.join(os.homedir(), \".pl.json\");\nconst CONFIG_FILE_LOCAL_YAML = \"pl.yaml\";\nconst CONFIG_FILE_USER_YAML = path.join(os.homedir(), \".pl.yaml\");\nconst CONF_FILE_SEQUENCE = [\n CONFIG_FILE_LOCAL_JSON,\n CONFIG_FILE_LOCAL_YAML,\n CONFIG_FILE_USER_JSON,\n CONFIG_FILE_USER_YAML,\n];\n\nconst AUTH_DATA_FILE = \".pl_auth.json\";\n\ntype FileConfigOverrideFields =\n | \"grpcProxy\"\n | \"httpProxy\"\n | \"user\"\n | \"password\"\n | \"alternativeRoot\"\n | \"defaultROTransactionTimeout\"\n | \"defaultRWTransactionTimeout\"\n | \"defaultRequestTimeout\"\n | \"authTTLSeconds\"\n | \"authMaxRefreshSeconds\";\nconst FILE_CONFIG_OVERRIDE_FIELDS: FileConfigOverrideFields[] = [\n \"grpcProxy\",\n \"httpProxy\",\n \"user\",\n \"password\",\n \"alternativeRoot\",\n \"defaultROTransactionTimeout\",\n \"defaultRWTransactionTimeout\",\n \"defaultRequestTimeout\",\n \"authTTLSeconds\",\n \"authMaxRefreshSeconds\",\n];\n\ntype PlConfigFile = {\n address: string;\n} & Partial<Pick<PlClientConfig, FileConfigOverrideFields>>;\n\ninterface AuthCache {\n /** To check if config changed */\n confHash: string;\n expiration: number;\n authInformation: AuthInformation;\n}\n\nexport function tryGetFileConfig(): [PlConfigFile, string] | undefined {\n for (const confPath of CONF_FILE_SEQUENCE)\n if (fs.existsSync(confPath)) {\n const fileContent = fs.readFileSync(confPath, { encoding: \"utf-8\" });\n if (confPath.endsWith(\"json\")) return [JSON.parse(fileContent) as PlConfigFile, confPath];\n else return [YAML.parse(fileContent) as PlConfigFile, confPath];\n }\n return undefined;\n}\n\nfunction saveAuthInfoCallback(\n confHash: string,\n authMaxRefreshSeconds: number,\n): (newAuthInfo: AuthInformation) => void {\n return (newAuthInfo) => {\n fs.writeFileSync(\n AUTH_DATA_FILE,\n Buffer.from(\n JSON.stringify({\n confHash,\n authInformation: newAuthInfo,\n expiration: inferAuthRefreshTime(newAuthInfo, authMaxRefreshSeconds),\n } as AuthCache),\n ),\n \"utf8\",\n );\n };\n}\n\nconst cleanAuthInfoCallback = () => {\n fs.rmSync(AUTH_DATA_FILE);\n};\n\n/** Uses default algorithm to construct a pl client from the environment */\nexport async function defaultPlClient(): Promise<PlClient> {\n let config: PlClientConfig | undefined = undefined;\n if (process.env.PL_ADDRESS !== undefined) {\n config = plAddressToConfig(process.env.PL_ADDRESS);\n } else {\n const fromFile = tryGetFileConfig();\n if (fromFile !== undefined) {\n const [fileConfig, configPath] = fromFile;\n const address = notEmpty(fileConfig.address, `no pl address in file: ${configPath}`);\n config = plAddressToConfig(address);\n // applying overrides\n for (const field of FILE_CONFIG_OVERRIDE_FIELDS)\n if (fileConfig[field] !== undefined) (config as any)[field] = fileConfig[field];\n }\n }\n\n if (config === undefined)\n throw new Error(\"Can't find configuration to create default platform client.\");\n\n if (process.env.PL_USER !== undefined) config.user = process.env.PL_USER;\n\n if (process.env.PL_PASSWORD !== undefined) config.user = process.env.PL_PASSWORD;\n\n const confHash = createHash(\"sha256\")\n .update(Buffer.from(canonicalize(config)!))\n .digest(\"base64\");\n\n let authInformation: AuthInformation | undefined = undefined;\n\n // try recover auth information from cache\n if (fs.existsSync(AUTH_DATA_FILE)) {\n const cache: AuthCache = JSON.parse(fs.readFileSync(AUTH_DATA_FILE, { encoding: \"utf-8\" }));\n if (cache.confHash === confHash && cache.expiration > Date.now())\n authInformation = cache.authInformation;\n }\n\n if (authInformation === undefined) {\n const client = await UnauthenticatedPlClient.build(config);\n\n if (await client.requireAuth()) {\n if (config.user === undefined || config.password === undefined)\n throw new Error(`No auth information for found to authenticate with PL server.`);\n authInformation = await client.login(config.user, config.password);\n } else {\n // No authorization is required\n authInformation = {};\n }\n\n // saving cache\n fs.writeFileSync(\n AUTH_DATA_FILE,\n Buffer.from(\n JSON.stringify({\n confHash,\n authInformation,\n expiration: inferAuthRefreshTime(authInformation, config.authMaxRefreshSeconds),\n } as AuthCache),\n ),\n \"utf8\",\n );\n }\n\n return await PlClient.init(config, {\n authInformation,\n onUpdate: (_newAuthInfo) => saveAuthInfoCallback(confHash, config.authMaxRefreshSeconds),\n onUpdateError: cleanAuthInfoCallback,\n onAuthError: cleanAuthInfoCallback,\n });\n}\n"],"names":["fs"],"mappings":";;;;;;;;;;;;AAaA,MAAM,sBAAsB,GAAG,SAAS;AACxC,MAAM,qBAAqB,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,UAAU,CAAC;AACjE,MAAM,sBAAsB,GAAG,SAAS;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,CAAC;AACxF,QAAA,aAAa,EAAE,qBAAqB;AACpC,QAAA,WAAW,EAAE,qBAAqB;AACnC,KAAA,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"default_client.js","names":[],"sources":["../../src/core/default_client.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { AuthInformation, PlClientConfig } from \"./config\";\nimport { plAddressToConfig } from \"./config\";\nimport canonicalize from \"canonicalize\";\nimport YAML from \"yaml\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport { UnauthenticatedPlClient } from \"./unauth_client\";\nimport { PlClient } from \"./client\";\nimport { createHash } from \"node:crypto\";\nimport { inferAuthRefreshTime } from \"./auth\";\n\nconst CONFIG_FILE_LOCAL_JSON = \"pl.json\";\nconst CONFIG_FILE_USER_JSON = path.join(os.homedir(), \".pl.json\");\nconst CONFIG_FILE_LOCAL_YAML = \"pl.yaml\";\nconst CONFIG_FILE_USER_YAML = path.join(os.homedir(), \".pl.yaml\");\nconst CONF_FILE_SEQUENCE = [\n CONFIG_FILE_LOCAL_JSON,\n CONFIG_FILE_LOCAL_YAML,\n CONFIG_FILE_USER_JSON,\n CONFIG_FILE_USER_YAML,\n];\n\nconst AUTH_DATA_FILE = \".pl_auth.json\";\n\ntype FileConfigOverrideFields =\n | \"grpcProxy\"\n | \"httpProxy\"\n | \"user\"\n | \"password\"\n | \"alternativeRoot\"\n | \"defaultROTransactionTimeout\"\n | \"defaultRWTransactionTimeout\"\n | \"defaultRequestTimeout\"\n | \"authTTLSeconds\"\n | \"authMaxRefreshSeconds\";\nconst FILE_CONFIG_OVERRIDE_FIELDS: FileConfigOverrideFields[] = [\n \"grpcProxy\",\n \"httpProxy\",\n \"user\",\n \"password\",\n \"alternativeRoot\",\n \"defaultROTransactionTimeout\",\n \"defaultRWTransactionTimeout\",\n \"defaultRequestTimeout\",\n \"authTTLSeconds\",\n \"authMaxRefreshSeconds\",\n];\n\ntype PlConfigFile = {\n address: string;\n} & Partial<Pick<PlClientConfig, FileConfigOverrideFields>>;\n\ninterface AuthCache {\n /** To check if config changed */\n confHash: string;\n expiration: number;\n authInformation: AuthInformation;\n}\n\nexport function tryGetFileConfig(): [PlConfigFile, string] | undefined {\n for (const confPath of CONF_FILE_SEQUENCE)\n if (fs.existsSync(confPath)) {\n const fileContent = fs.readFileSync(confPath, { encoding: \"utf-8\" });\n if (confPath.endsWith(\"json\")) return [JSON.parse(fileContent) as PlConfigFile, confPath];\n else return [YAML.parse(fileContent) as PlConfigFile, confPath];\n }\n return undefined;\n}\n\nfunction saveAuthInfoCallback(\n confHash: string,\n authMaxRefreshSeconds: number,\n): (newAuthInfo: AuthInformation) => void {\n return (newAuthInfo) => {\n fs.writeFileSync(\n AUTH_DATA_FILE,\n Buffer.from(\n JSON.stringify({\n confHash,\n authInformation: newAuthInfo,\n expiration: inferAuthRefreshTime(newAuthInfo, authMaxRefreshSeconds),\n } as AuthCache),\n ),\n \"utf8\",\n );\n };\n}\n\nconst cleanAuthInfoCallback = () => {\n fs.rmSync(AUTH_DATA_FILE);\n};\n\n/** Uses default algorithm to construct a pl client from the environment */\nexport async function defaultPlClient(): Promise<PlClient> {\n let config: PlClientConfig | undefined = undefined;\n if (process.env.PL_ADDRESS !== undefined) {\n config = plAddressToConfig(process.env.PL_ADDRESS);\n } else {\n const fromFile = tryGetFileConfig();\n if (fromFile !== undefined) {\n const [fileConfig, configPath] = fromFile;\n const address = notEmpty(fileConfig.address, `no pl address in file: ${configPath}`);\n config = plAddressToConfig(address);\n // applying overrides\n for (const field of FILE_CONFIG_OVERRIDE_FIELDS)\n if (fileConfig[field] !== undefined) (config as any)[field] = fileConfig[field];\n }\n }\n\n if (config === undefined)\n throw new Error(\"Can't find configuration to create default platform client.\");\n\n if (process.env.PL_USER !== undefined) config.user = process.env.PL_USER;\n\n if (process.env.PL_PASSWORD !== undefined) config.user = process.env.PL_PASSWORD;\n\n const confHash = createHash(\"sha256\")\n .update(Buffer.from(canonicalize(config)!))\n .digest(\"base64\");\n\n let authInformation: AuthInformation | undefined = undefined;\n\n // try recover auth information from cache\n if (fs.existsSync(AUTH_DATA_FILE)) {\n const cache: AuthCache = JSON.parse(fs.readFileSync(AUTH_DATA_FILE, { encoding: \"utf-8\" }));\n if (cache.confHash === confHash && cache.expiration > Date.now())\n authInformation = cache.authInformation;\n }\n\n if (authInformation === undefined) {\n const client = await UnauthenticatedPlClient.build(config);\n\n if (await client.requireAuth()) {\n if (config.user === undefined || config.password === undefined)\n throw new Error(`No auth information for found to authenticate with PL server.`);\n authInformation = await client.login(config.user, config.password);\n } else {\n // No authorization is required\n authInformation = {};\n }\n\n // saving cache\n fs.writeFileSync(\n AUTH_DATA_FILE,\n Buffer.from(\n JSON.stringify({\n confHash,\n authInformation,\n expiration: inferAuthRefreshTime(authInformation, config.authMaxRefreshSeconds),\n } as AuthCache),\n ),\n \"utf8\",\n );\n }\n\n return await PlClient.init(config, {\n authInformation,\n onUpdate: (_newAuthInfo) => saveAuthInfoCallback(confHash, config.authMaxRefreshSeconds),\n onUpdateError: cleanAuthInfoCallback,\n onAuthError: cleanAuthInfoCallback,\n });\n}\n"],"mappings":";;;;;;;;;;;;;AAiBA,MAAM,qBAAqB;CAJI;CAEA;CADD,KAAK,KAAK,GAAG,SAAS,EAAE,WAAW;CAEnC,KAAK,KAAK,GAAG,SAAS,EAAE,WAAW;CAMhE;AAED,MAAM,iBAAiB;AAavB,MAAM,8BAA0D;CAC9D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAaD,SAAgB,mBAAuD;AACrE,MAAK,MAAM,YAAY,mBACrB,KAAI,GAAG,WAAW,SAAS,EAAE;EAC3B,MAAM,cAAc,GAAG,aAAa,UAAU,EAAE,UAAU,SAAS,CAAC;AACpE,MAAI,SAAS,SAAS,OAAO,CAAE,QAAO,CAAC,KAAK,MAAM,YAAY,EAAkB,SAAS;MACpF,QAAO,CAAC,KAAK,MAAM,YAAY,EAAkB,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nD,OAAM,IAAI,MAAM,gEAAgE;AAClF,qBAAkB,MAAM,OAAO,MAAM,OAAO,MAAM,OAAO,SAAS;QAGlE,mBAAkB,EAAE;AAItB,KAAG,cACD,gBACA,OAAO,KACL,KAAK,UAAU;GACb;GACA;GACA,YAAY,qBAAqB,iBAAiB,OAAO,sBAAsB;GAChF,CAAc,CAChB,EACD,OACD;;AAGH,QAAO,MAAM,SAAS,KAAK,QAAQ;EACjC;EACA,WAAW,iBAAiB,qBAAqB,UAAU,OAAO,sBAAsB;EACxF,eAAe;EACf,aAAa;EACd,CAAC"}
@@ -1,25 +1,21 @@
1
- 'use strict';
2
1
 
3
- // addRTypeToMetadata adds a metadata with resource type
4
- // for every RPC call. It is necessary for the platform core
5
- // to proxy the call to the proper controller.
2
+ //#region src/core/driver.ts
6
3
  function addRTypeToMetadata(rType, options) {
7
- options = options ?? {};
8
- options.meta = options.meta ?? {};
9
- options.meta["resourceType"] = `${rType.name}:${rType.version}`;
10
- return options;
4
+ options = options ?? {};
5
+ options.meta = options.meta ?? {};
6
+ options.meta["resourceType"] = `${rType.name}:${rType.version}`;
7
+ return options;
11
8
  }
12
9
  /**
13
- * addRTypeToHeaders adds a header that helps to route request to the right resource and controller.
14
- * Without this header, API router on server side cannot route request to proper controller in internal
15
- * RPC proxy.
16
- */
10
+ * addRTypeToHeaders adds a header that helps to route request to the right resource and controller.
11
+ * Without this header, API router on server side cannot route request to proper controller in internal
12
+ * RPC proxy.
13
+ */
17
14
  function createRTypeRoutingHeader(rType) {
18
- return {
19
- resourceType: `${rType.name}:${rType.version}`,
20
- };
15
+ return { resourceType: `${rType.name}:${rType.version}` };
21
16
  }
22
17
 
18
+ //#endregion
23
19
  exports.addRTypeToMetadata = addRTypeToMetadata;
24
20
  exports.createRTypeRoutingHeader = createRTypeRoutingHeader;
25
- //# sourceMappingURL=driver.cjs.map
21
+ //# sourceMappingURL=driver.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"driver.cjs","sources":["../../src/core/driver.ts"],"sourcesContent":["import type { PlClient } from \"./client\";\nimport type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type { Dispatcher } from \"undici\";\nimport type { ResourceType } from \"./types\";\nimport type { WireClientProviderFactory } from \"./wire\";\n\n/** Drivers must implement this interface */\nexport interface PlDriver {\n close(): void;\n}\n\n/** Definition to use driver via {@link PlClient} */\nexport interface PlDriverDefinition<Drv extends PlDriver> {\n /** Used as key to only once instantiate specific drivers */\n readonly name: string;\n\n /** Initialization routine, will be executed only once for each driver in a specific client */\n init(pl: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher): Drv;\n}\n\n// addRTypeToMetadata adds a metadata with resource type\n// for every RPC call. It is necessary for the platform core\n// to proxy the call to the proper controller.\nexport function addRTypeToMetadata(rType: ResourceType, options?: RpcOptions) {\n options = options ?? {};\n options.meta = options.meta ?? {};\n options.meta[\"resourceType\"] = `${rType.name}:${rType.version}`;\n\n return options;\n}\n\n/**\n * addRTypeToHeaders adds a header that helps to route request to the right resource and controller.\n * Without this header, API router on server side cannot route request to proper controller in internal\n * RPC proxy.\n */\nexport function createRTypeRoutingHeader(rType: ResourceType): Record<string, string> {\n return {\n resourceType: `${rType.name}:${rType.version}`,\n };\n}\n"],"names":[],"mappings":";;AAoBA;AACA;AACA;AACM,SAAU,kBAAkB,CAAC,KAAmB,EAAE,OAAoB,EAAA;AAC1E,IAAA,OAAO,GAAG,OAAO,IAAI,EAAE;IACvB,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,EAAE;AACjC,IAAA,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAA,EAAG,KAAK,CAAC,IAAI,CAAA,CAAA,EAAI,KAAK,CAAC,OAAO,EAAE;AAE/D,IAAA,OAAO,OAAO;AAChB;AAEA;;;;AAIG;AACG,SAAU,wBAAwB,CAAC,KAAmB,EAAA;IAC1D,OAAO;QACL,YAAY,EAAE,GAAG,KAAK,CAAC,IAAI,CAAA,CAAA,EAAI,KAAK,CAAC,OAAO,CAAA,CAAE;KAC/C;AACH;;;;;"}
1
+ {"version":3,"file":"driver.cjs","names":[],"sources":["../../src/core/driver.ts"],"sourcesContent":["import type { PlClient } from \"./client\";\nimport type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type { Dispatcher } from \"undici\";\nimport type { ResourceType } from \"./types\";\nimport type { WireClientProviderFactory } from \"./wire\";\n\n/** Drivers must implement this interface */\nexport interface PlDriver {\n close(): void;\n}\n\n/** Definition to use driver via {@link PlClient} */\nexport interface PlDriverDefinition<Drv extends PlDriver> {\n /** Used as key to only once instantiate specific drivers */\n readonly name: string;\n\n /** Initialization routine, will be executed only once for each driver in a specific client */\n init(pl: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher): Drv;\n}\n\n// addRTypeToMetadata adds a metadata with resource type\n// for every RPC call. It is necessary for the platform core\n// to proxy the call to the proper controller.\nexport function addRTypeToMetadata(rType: ResourceType, options?: RpcOptions) {\n options = options ?? {};\n options.meta = options.meta ?? {};\n options.meta[\"resourceType\"] = `${rType.name}:${rType.version}`;\n\n return options;\n}\n\n/**\n * addRTypeToHeaders adds a header that helps to route request to the right resource and controller.\n * Without this header, API router on server side cannot route request to proper controller in internal\n * RPC proxy.\n */\nexport function createRTypeRoutingHeader(rType: ResourceType): Record<string, string> {\n return {\n resourceType: `${rType.name}:${rType.version}`,\n };\n}\n"],"mappings":";;AAuBA,SAAgB,mBAAmB,OAAqB,SAAsB;AAC5E,WAAU,WAAW,EAAE;AACvB,SAAQ,OAAO,QAAQ,QAAQ,EAAE;AACjC,SAAQ,KAAK,kBAAkB,GAAG,MAAM,KAAK,GAAG,MAAM;AAEtD,QAAO;;;;;;;AAQT,SAAgB,yBAAyB,OAA6C;AACpF,QAAO,EACL,cAAc,GAAG,MAAM,KAAK,GAAG,MAAM,WACtC"}
@@ -1,24 +1,28 @@
1
- import type { PlClient } from "./client";
2
- import type { RpcOptions } from "@protobuf-ts/runtime-rpc";
3
- import type { Dispatcher } from "undici";
4
- import type { ResourceType } from "./types";
5
- import type { WireClientProviderFactory } from "./wire";
1
+ import { ResourceType } from "./types.js";
2
+ import { WireClientProviderFactory } from "./wire.js";
3
+ import { PlClient } from "./client.js";
4
+ import { RpcOptions } from "@protobuf-ts/runtime-rpc";
5
+ import { Dispatcher } from "undici";
6
+
7
+ //#region src/core/driver.d.ts
6
8
  /** Drivers must implement this interface */
7
- export interface PlDriver {
8
- close(): void;
9
+ interface PlDriver {
10
+ close(): void;
9
11
  }
10
12
  /** Definition to use driver via {@link PlClient} */
11
- export interface PlDriverDefinition<Drv extends PlDriver> {
12
- /** Used as key to only once instantiate specific drivers */
13
- readonly name: string;
14
- /** Initialization routine, will be executed only once for each driver in a specific client */
15
- init(pl: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher): Drv;
13
+ interface PlDriverDefinition<Drv extends PlDriver> {
14
+ /** Used as key to only once instantiate specific drivers */
15
+ readonly name: string;
16
+ /** Initialization routine, will be executed only once for each driver in a specific client */
17
+ init(pl: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher): Drv;
16
18
  }
17
- export declare function addRTypeToMetadata(rType: ResourceType, options?: RpcOptions): RpcOptions;
19
+ declare function addRTypeToMetadata(rType: ResourceType, options?: RpcOptions): RpcOptions;
18
20
  /**
19
21
  * addRTypeToHeaders adds a header that helps to route request to the right resource and controller.
20
22
  * Without this header, API router on server side cannot route request to proper controller in internal
21
23
  * RPC proxy.
22
24
  */
23
- export declare function createRTypeRoutingHeader(rType: ResourceType): Record<string, string>;
25
+ declare function createRTypeRoutingHeader(rType: ResourceType): Record<string, string>;
26
+ //#endregion
27
+ export { PlDriver, PlDriverDefinition, addRTypeToMetadata, createRTypeRoutingHeader };
24
28
  //# sourceMappingURL=driver.d.ts.map
@@ -1,22 +1,19 @@
1
- // addRTypeToMetadata adds a metadata with resource type
2
- // for every RPC call. It is necessary for the platform core
3
- // to proxy the call to the proper controller.
1
+ //#region src/core/driver.ts
4
2
  function addRTypeToMetadata(rType, options) {
5
- options = options ?? {};
6
- options.meta = options.meta ?? {};
7
- options.meta["resourceType"] = `${rType.name}:${rType.version}`;
8
- return options;
3
+ options = options ?? {};
4
+ options.meta = options.meta ?? {};
5
+ options.meta["resourceType"] = `${rType.name}:${rType.version}`;
6
+ return options;
9
7
  }
10
8
  /**
11
- * addRTypeToHeaders adds a header that helps to route request to the right resource and controller.
12
- * Without this header, API router on server side cannot route request to proper controller in internal
13
- * RPC proxy.
14
- */
9
+ * addRTypeToHeaders adds a header that helps to route request to the right resource and controller.
10
+ * Without this header, API router on server side cannot route request to proper controller in internal
11
+ * RPC proxy.
12
+ */
15
13
  function createRTypeRoutingHeader(rType) {
16
- return {
17
- resourceType: `${rType.name}:${rType.version}`,
18
- };
14
+ return { resourceType: `${rType.name}:${rType.version}` };
19
15
  }
20
16
 
17
+ //#endregion
21
18
  export { addRTypeToMetadata, createRTypeRoutingHeader };
22
- //# sourceMappingURL=driver.js.map
19
+ //# sourceMappingURL=driver.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"driver.js","sources":["../../src/core/driver.ts"],"sourcesContent":["import type { PlClient } from \"./client\";\nimport type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type { Dispatcher } from \"undici\";\nimport type { ResourceType } from \"./types\";\nimport type { WireClientProviderFactory } from \"./wire\";\n\n/** Drivers must implement this interface */\nexport interface PlDriver {\n close(): void;\n}\n\n/** Definition to use driver via {@link PlClient} */\nexport interface PlDriverDefinition<Drv extends PlDriver> {\n /** Used as key to only once instantiate specific drivers */\n readonly name: string;\n\n /** Initialization routine, will be executed only once for each driver in a specific client */\n init(pl: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher): Drv;\n}\n\n// addRTypeToMetadata adds a metadata with resource type\n// for every RPC call. It is necessary for the platform core\n// to proxy the call to the proper controller.\nexport function addRTypeToMetadata(rType: ResourceType, options?: RpcOptions) {\n options = options ?? {};\n options.meta = options.meta ?? {};\n options.meta[\"resourceType\"] = `${rType.name}:${rType.version}`;\n\n return options;\n}\n\n/**\n * addRTypeToHeaders adds a header that helps to route request to the right resource and controller.\n * Without this header, API router on server side cannot route request to proper controller in internal\n * RPC proxy.\n */\nexport function createRTypeRoutingHeader(rType: ResourceType): Record<string, string> {\n return {\n resourceType: `${rType.name}:${rType.version}`,\n };\n}\n"],"names":[],"mappings":"AAoBA;AACA;AACA;AACM,SAAU,kBAAkB,CAAC,KAAmB,EAAE,OAAoB,EAAA;AAC1E,IAAA,OAAO,GAAG,OAAO,IAAI,EAAE;IACvB,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,EAAE;AACjC,IAAA,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAA,EAAG,KAAK,CAAC,IAAI,CAAA,CAAA,EAAI,KAAK,CAAC,OAAO,EAAE;AAE/D,IAAA,OAAO,OAAO;AAChB;AAEA;;;;AAIG;AACG,SAAU,wBAAwB,CAAC,KAAmB,EAAA;IAC1D,OAAO;QACL,YAAY,EAAE,GAAG,KAAK,CAAC,IAAI,CAAA,CAAA,EAAI,KAAK,CAAC,OAAO,CAAA,CAAE;KAC/C;AACH;;;;"}
1
+ {"version":3,"file":"driver.js","names":[],"sources":["../../src/core/driver.ts"],"sourcesContent":["import type { PlClient } from \"./client\";\nimport type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type { Dispatcher } from \"undici\";\nimport type { ResourceType } from \"./types\";\nimport type { WireClientProviderFactory } from \"./wire\";\n\n/** Drivers must implement this interface */\nexport interface PlDriver {\n close(): void;\n}\n\n/** Definition to use driver via {@link PlClient} */\nexport interface PlDriverDefinition<Drv extends PlDriver> {\n /** Used as key to only once instantiate specific drivers */\n readonly name: string;\n\n /** Initialization routine, will be executed only once for each driver in a specific client */\n init(pl: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher): Drv;\n}\n\n// addRTypeToMetadata adds a metadata with resource type\n// for every RPC call. It is necessary for the platform core\n// to proxy the call to the proper controller.\nexport function addRTypeToMetadata(rType: ResourceType, options?: RpcOptions) {\n options = options ?? {};\n options.meta = options.meta ?? {};\n options.meta[\"resourceType\"] = `${rType.name}:${rType.version}`;\n\n return options;\n}\n\n/**\n * addRTypeToHeaders adds a header that helps to route request to the right resource and controller.\n * Without this header, API router on server side cannot route request to proper controller in internal\n * RPC proxy.\n */\nexport function createRTypeRoutingHeader(rType: ResourceType): Record<string, string> {\n return {\n resourceType: `${rType.name}:${rType.version}`,\n };\n}\n"],"mappings":";AAuBA,SAAgB,mBAAmB,OAAqB,SAAsB;AAC5E,WAAU,WAAW,EAAE;AACvB,SAAQ,OAAO,QAAQ,QAAQ,EAAE;AACjC,SAAQ,KAAK,kBAAkB,GAAG,MAAM,KAAK,GAAG,MAAM;AAEtD,QAAO;;;;;;;AAQT,SAAgB,yBAAyB,OAA6C;AACpF,QAAO,EACL,cAAc,GAAG,MAAM,KAAK,GAAG,MAAM,WACtC"}
@@ -1,9 +1,10 @@
1
- 'use strict';
2
1
 
2
+ //#region src/core/error_resource.ts
3
3
  const ErrorResourceType = {
4
- name: "json/resourceError",
5
- version: "1",
4
+ name: "json/resourceError",
5
+ version: "1"
6
6
  };
7
7
 
8
+ //#endregion
8
9
  exports.ErrorResourceType = ErrorResourceType;
9
- //# sourceMappingURL=error_resource.cjs.map
10
+ //# sourceMappingURL=error_resource.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"error_resource.cjs","sources":["../../src/core/error_resource.ts"],"sourcesContent":["import type { ResourceType } from \"./types\";\n\nexport type ErrorResourceData = {\n message: string;\n};\n\nexport const ErrorResourceType: ResourceType = {\n name: \"json/resourceError\",\n version: \"1\",\n};\n"],"names":[],"mappings":";;AAMO,MAAM,iBAAiB,GAAiB;AAC7C,IAAA,IAAI,EAAE,oBAAoB;AAC1B,IAAA,OAAO,EAAE,GAAG;;;;;"}
1
+ {"version":3,"file":"error_resource.cjs","names":[],"sources":["../../src/core/error_resource.ts"],"sourcesContent":["import type { ResourceType } from \"./types\";\n\nexport type ErrorResourceData = {\n message: string;\n};\n\nexport const ErrorResourceType: ResourceType = {\n name: \"json/resourceError\",\n version: \"1\",\n};\n"],"mappings":";;AAMA,MAAa,oBAAkC;CAC7C,MAAM;CACN,SAAS;CACV"}
@@ -1,7 +1,9 @@
1
+ //#region src/core/error_resource.ts
1
2
  const ErrorResourceType = {
2
- name: "json/resourceError",
3
- version: "1",
3
+ name: "json/resourceError",
4
+ version: "1"
4
5
  };
5
6
 
7
+ //#endregion
6
8
  export { ErrorResourceType };
7
- //# sourceMappingURL=error_resource.js.map
9
+ //# sourceMappingURL=error_resource.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error_resource.js","sources":["../../src/core/error_resource.ts"],"sourcesContent":["import type { ResourceType } from \"./types\";\n\nexport type ErrorResourceData = {\n message: string;\n};\n\nexport const ErrorResourceType: ResourceType = {\n name: \"json/resourceError\",\n version: \"1\",\n};\n"],"names":[],"mappings":"AAMO,MAAM,iBAAiB,GAAiB;AAC7C,IAAA,IAAI,EAAE,oBAAoB;AAC1B,IAAA,OAAO,EAAE,GAAG;;;;;"}
1
+ {"version":3,"file":"error_resource.js","names":[],"sources":["../../src/core/error_resource.ts"],"sourcesContent":["import type { ResourceType } from \"./types\";\n\nexport type ErrorResourceData = {\n message: string;\n};\n\nexport const ErrorResourceType: ResourceType = {\n name: \"json/resourceError\",\n version: \"1\",\n};\n"],"mappings":";AAMA,MAAa,oBAAkC;CAC7C,MAAM;CACN,SAAS;CACV"}