@qlever-llc/trellis 0.6.1 → 0.7.0-rc.3

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 (244) hide show
  1. package/README.md +6 -2
  2. package/esm/auth/device_activation.d.ts +194 -0
  3. package/esm/auth/device_activation.d.ts.map +1 -0
  4. package/esm/auth/{workload_activation.js → device_activation.js} +85 -60
  5. package/esm/auth/mod.d.ts +2 -2
  6. package/esm/auth/mod.d.ts.map +1 -1
  7. package/esm/auth/mod.js +2 -2
  8. package/esm/auth/protocol.d.ts +175 -72
  9. package/esm/auth/protocol.d.ts.map +1 -1
  10. package/esm/auth/protocol.js +126 -78
  11. package/esm/contracts/mod.d.ts +19 -3
  12. package/esm/contracts/mod.d.ts.map +1 -1
  13. package/esm/contracts/mod.js +28 -4
  14. package/esm/contracts/protocol.d.ts +34 -0
  15. package/esm/contracts/protocol.d.ts.map +1 -1
  16. package/esm/contracts/protocol.js +15 -0
  17. package/esm/server/deno.d.ts +1 -6
  18. package/esm/server/deno.d.ts.map +1 -1
  19. package/esm/server/deno.js +1 -16
  20. package/esm/server/mod.d.ts +3 -2
  21. package/esm/server/mod.d.ts.map +1 -1
  22. package/esm/server/mod.js +2 -2
  23. package/esm/server/node.d.ts +1 -6
  24. package/esm/server/node.d.ts.map +1 -1
  25. package/esm/server/node.js +1 -16
  26. package/esm/server/service.d.ts +32 -10
  27. package/esm/server/service.d.ts.map +1 -1
  28. package/esm/server/service.js +188 -41
  29. package/esm/server/transfer.d.ts +41 -0
  30. package/esm/server/transfer.d.ts.map +1 -0
  31. package/esm/server/transfer.js +418 -0
  32. package/esm/telemetry/init.d.ts +4 -0
  33. package/esm/telemetry/init.d.ts.map +1 -0
  34. package/esm/telemetry/init.js +7 -0
  35. package/esm/telemetry/mod.d.ts +1 -2
  36. package/esm/telemetry/mod.d.ts.map +1 -1
  37. package/esm/telemetry/mod.js +1 -2
  38. package/esm/telemetry/runtime.d.ts.map +1 -1
  39. package/esm/telemetry/runtime.js +9 -5
  40. package/esm/telemetry/trellis.d.ts +0 -1
  41. package/esm/telemetry/trellis.d.ts.map +1 -1
  42. package/esm/telemetry/trellis.js +0 -6
  43. package/esm/trellis/_sdk/auth/api.d.ts.map +1 -1
  44. package/esm/trellis/_sdk/auth/api.js +132 -110
  45. package/esm/trellis/_sdk/auth/contract.d.ts +1 -1
  46. package/esm/trellis/_sdk/auth/contract.d.ts.map +1 -1
  47. package/esm/trellis/_sdk/auth/contract.js +2 -2
  48. package/esm/trellis/_sdk/auth/schemas.d.ts +4212 -3069
  49. package/esm/trellis/_sdk/auth/schemas.d.ts.map +1 -1
  50. package/esm/trellis/_sdk/auth/schemas.js +144 -125
  51. package/esm/trellis/_sdk/auth/types.d.ts +417 -267
  52. package/esm/trellis/_sdk/auth/types.d.ts.map +1 -1
  53. package/esm/trellis/_sdk/auth/types.js +1 -1
  54. package/esm/trellis/_sdk/core/contract.d.ts +1 -1
  55. package/esm/trellis/_sdk/core/contract.d.ts.map +1 -1
  56. package/esm/trellis/_sdk/core/contract.js +2 -2
  57. package/esm/trellis/_sdk/core/schemas.d.ts +122 -0
  58. package/esm/trellis/_sdk/core/schemas.d.ts.map +1 -1
  59. package/esm/trellis/_sdk/core/schemas.js +4 -4
  60. package/esm/trellis/_sdk/core/types.d.ts +18 -1
  61. package/esm/trellis/_sdk/core/types.d.ts.map +1 -1
  62. package/esm/trellis/_sdk/core/types.js +1 -1
  63. package/esm/trellis/_sdk/state/_dnt.polyfills.d.ts +12 -0
  64. package/esm/trellis/_sdk/state/_dnt.polyfills.d.ts.map +1 -0
  65. package/esm/trellis/_sdk/state/_dnt.polyfills.js +15 -0
  66. package/esm/trellis/_sdk/state/api.d.ts +10 -0
  67. package/esm/trellis/_sdk/state/api.d.ts.map +1 -0
  68. package/esm/trellis/_sdk/state/api.js +71 -0
  69. package/esm/trellis/_sdk/state/contract.d.ts +8 -0
  70. package/esm/trellis/_sdk/state/contract.d.ts.map +1 -0
  71. package/esm/trellis/_sdk/state/contract.js +59 -0
  72. package/esm/trellis/_sdk/state/mod.d.ts +7 -0
  73. package/esm/trellis/_sdk/state/mod.d.ts.map +1 -0
  74. package/esm/trellis/_sdk/state/mod.js +5 -0
  75. package/esm/trellis/_sdk/state/package.json +3 -0
  76. package/esm/trellis/_sdk/state/schemas.d.ts +1437 -0
  77. package/esm/trellis/_sdk/state/schemas.d.ts.map +1 -0
  78. package/esm/trellis/_sdk/state/schemas.js +62 -0
  79. package/esm/trellis/_sdk/state/types.d.ts +206 -0
  80. package/esm/trellis/_sdk/state/types.d.ts.map +1 -0
  81. package/esm/trellis/_sdk/state/types.js +3 -0
  82. package/esm/trellis/client_connect.d.ts +53 -0
  83. package/esm/trellis/client_connect.d.ts.map +1 -0
  84. package/esm/trellis/client_connect.js +300 -0
  85. package/esm/trellis/contract.d.ts +1 -7
  86. package/esm/trellis/contract.d.ts.map +1 -1
  87. package/esm/trellis/contract.js +1 -12
  88. package/esm/trellis/device.d.ts +41 -0
  89. package/esm/trellis/device.d.ts.map +1 -0
  90. package/esm/trellis/device.js +209 -0
  91. package/esm/trellis/errors/AuthError.d.ts +1 -1
  92. package/esm/trellis/errors/AuthError.js +9 -9
  93. package/esm/trellis/errors/StoreError.d.ts +22 -0
  94. package/esm/trellis/errors/StoreError.d.ts.map +1 -0
  95. package/esm/trellis/errors/StoreError.js +41 -0
  96. package/esm/trellis/errors/TransferError.d.ts +22 -0
  97. package/esm/trellis/errors/TransferError.d.ts.map +1 -0
  98. package/esm/trellis/errors/TransferError.js +41 -0
  99. package/esm/trellis/errors/index.d.ts +8 -0
  100. package/esm/trellis/errors/index.d.ts.map +1 -1
  101. package/esm/trellis/errors/index.js +8 -0
  102. package/esm/trellis/index.d.ts +10 -4
  103. package/esm/trellis/index.d.ts.map +1 -1
  104. package/esm/trellis/index.js +6 -4
  105. package/esm/trellis/kv.d.ts +2 -0
  106. package/esm/trellis/kv.d.ts.map +1 -1
  107. package/esm/trellis/kv.js +6 -0
  108. package/esm/trellis/models/trellis/TrellisError.d.ts +15 -1
  109. package/esm/trellis/models/trellis/TrellisError.d.ts.map +1 -1
  110. package/esm/trellis/models/trellis/TrellisError.js +4 -0
  111. package/esm/trellis/runtime_transport.d.ts +12 -0
  112. package/esm/trellis/runtime_transport.d.ts.map +1 -0
  113. package/esm/trellis/runtime_transport.js +35 -0
  114. package/esm/trellis/sdk/state.d.ts +4 -0
  115. package/esm/trellis/sdk/state.d.ts.map +1 -0
  116. package/esm/trellis/sdk/state.js +3 -0
  117. package/esm/trellis/store.d.ts +51 -0
  118. package/esm/trellis/store.d.ts.map +1 -0
  119. package/esm/trellis/store.js +310 -0
  120. package/esm/trellis/tracing.js +1 -1
  121. package/esm/trellis/transfer.d.ts +118 -0
  122. package/esm/trellis/transfer.d.ts.map +1 -0
  123. package/esm/trellis/transfer.js +357 -0
  124. package/esm/trellis/trellis.d.ts +3 -0
  125. package/esm/trellis/trellis.d.ts.map +1 -1
  126. package/esm/trellis/trellis.js +48 -17
  127. package/package.json +7 -2
  128. package/script/auth/device_activation.d.ts +194 -0
  129. package/script/auth/device_activation.d.ts.map +1 -0
  130. package/script/auth/{workload_activation.js → device_activation.js} +99 -74
  131. package/script/auth/mod.d.ts +2 -2
  132. package/script/auth/mod.d.ts.map +1 -1
  133. package/script/auth/mod.js +84 -76
  134. package/script/auth/protocol.d.ts +175 -72
  135. package/script/auth/protocol.d.ts.map +1 -1
  136. package/script/auth/protocol.js +129 -81
  137. package/script/contracts/mod.d.ts +19 -3
  138. package/script/contracts/mod.d.ts.map +1 -1
  139. package/script/contracts/mod.js +30 -4
  140. package/script/contracts/protocol.d.ts +34 -0
  141. package/script/contracts/protocol.d.ts.map +1 -1
  142. package/script/contracts/protocol.js +16 -1
  143. package/script/telemetry/init.d.ts +4 -0
  144. package/script/telemetry/init.d.ts.map +1 -0
  145. package/script/telemetry/init.js +11 -0
  146. package/script/telemetry/mod.d.ts +1 -2
  147. package/script/telemetry/mod.d.ts.map +1 -1
  148. package/script/telemetry/mod.js +1 -4
  149. package/script/telemetry/runtime.d.ts.map +1 -1
  150. package/script/telemetry/runtime.js +9 -28
  151. package/script/telemetry/trellis.d.ts +0 -1
  152. package/script/telemetry/trellis.d.ts.map +1 -1
  153. package/script/telemetry/trellis.js +0 -7
  154. package/script/trellis/_sdk/auth/api.d.ts.map +1 -1
  155. package/script/trellis/_sdk/auth/api.js +132 -110
  156. package/script/trellis/_sdk/auth/contract.d.ts +1 -1
  157. package/script/trellis/_sdk/auth/contract.d.ts.map +1 -1
  158. package/script/trellis/_sdk/auth/contract.js +2 -2
  159. package/script/trellis/_sdk/auth/schemas.d.ts +4212 -3069
  160. package/script/trellis/_sdk/auth/schemas.d.ts.map +1 -1
  161. package/script/trellis/_sdk/auth/schemas.js +144 -125
  162. package/script/trellis/_sdk/auth/types.d.ts +417 -267
  163. package/script/trellis/_sdk/auth/types.d.ts.map +1 -1
  164. package/script/trellis/_sdk/auth/types.js +1 -1
  165. package/script/trellis/_sdk/core/contract.d.ts +1 -1
  166. package/script/trellis/_sdk/core/contract.d.ts.map +1 -1
  167. package/script/trellis/_sdk/core/contract.js +2 -2
  168. package/script/trellis/_sdk/core/schemas.d.ts +122 -0
  169. package/script/trellis/_sdk/core/schemas.d.ts.map +1 -1
  170. package/script/trellis/_sdk/core/schemas.js +4 -4
  171. package/script/trellis/_sdk/core/types.d.ts +18 -1
  172. package/script/trellis/_sdk/core/types.d.ts.map +1 -1
  173. package/script/trellis/_sdk/core/types.js +1 -1
  174. package/script/trellis/_sdk/state/_dnt.polyfills.d.ts +12 -0
  175. package/script/trellis/_sdk/state/_dnt.polyfills.d.ts.map +1 -0
  176. package/script/trellis/_sdk/state/_dnt.polyfills.js +16 -0
  177. package/script/trellis/_sdk/state/api.d.ts +10 -0
  178. package/script/trellis/_sdk/state/api.d.ts.map +1 -0
  179. package/script/trellis/_sdk/state/api.js +74 -0
  180. package/script/trellis/_sdk/state/contract.d.ts +8 -0
  181. package/script/trellis/_sdk/state/contract.d.ts.map +1 -0
  182. package/script/trellis/_sdk/state/contract.js +62 -0
  183. package/script/trellis/_sdk/state/mod.d.ts +7 -0
  184. package/script/trellis/_sdk/state/mod.d.ts.map +1 -0
  185. package/script/trellis/_sdk/state/mod.js +30 -0
  186. package/script/trellis/_sdk/state/package.json +3 -0
  187. package/script/trellis/_sdk/state/schemas.d.ts +1437 -0
  188. package/script/trellis/_sdk/state/schemas.d.ts.map +1 -0
  189. package/script/trellis/_sdk/state/schemas.js +65 -0
  190. package/script/trellis/_sdk/state/types.d.ts +206 -0
  191. package/script/trellis/_sdk/state/types.d.ts.map +1 -0
  192. package/script/trellis/_sdk/state/types.js +6 -0
  193. package/script/trellis/client_connect.d.ts +53 -0
  194. package/script/trellis/client_connect.d.ts.map +1 -0
  195. package/script/trellis/client_connect.js +304 -0
  196. package/script/trellis/contract.d.ts +1 -7
  197. package/script/trellis/contract.d.ts.map +1 -1
  198. package/script/trellis/contract.js +1 -12
  199. package/script/trellis/device.d.ts +41 -0
  200. package/script/trellis/device.d.ts.map +1 -0
  201. package/script/trellis/device.js +213 -0
  202. package/script/trellis/errors/AuthError.d.ts +1 -1
  203. package/script/trellis/errors/AuthError.js +9 -9
  204. package/script/trellis/errors/StoreError.d.ts +22 -0
  205. package/script/trellis/errors/StoreError.d.ts.map +1 -0
  206. package/script/trellis/errors/StoreError.js +48 -0
  207. package/script/trellis/errors/TransferError.d.ts +22 -0
  208. package/script/trellis/errors/TransferError.d.ts.map +1 -0
  209. package/script/trellis/errors/TransferError.js +48 -0
  210. package/script/trellis/errors/index.d.ts +8 -0
  211. package/script/trellis/errors/index.d.ts.map +1 -1
  212. package/script/trellis/errors/index.js +13 -1
  213. package/script/trellis/index.d.ts +10 -4
  214. package/script/trellis/index.d.ts.map +1 -1
  215. package/script/trellis/index.js +17 -6
  216. package/script/trellis/kv.d.ts +2 -0
  217. package/script/trellis/kv.d.ts.map +1 -1
  218. package/script/trellis/kv.js +6 -0
  219. package/script/trellis/models/trellis/TrellisError.d.ts +15 -1
  220. package/script/trellis/models/trellis/TrellisError.d.ts.map +1 -1
  221. package/script/trellis/models/trellis/TrellisError.js +4 -0
  222. package/script/trellis/runtime_transport.d.ts +12 -0
  223. package/script/trellis/runtime_transport.d.ts.map +1 -0
  224. package/script/trellis/runtime_transport.js +37 -0
  225. package/script/trellis/store.d.ts +51 -0
  226. package/script/trellis/store.d.ts.map +1 -0
  227. package/script/trellis/store.js +316 -0
  228. package/script/trellis/tracing.js +1 -1
  229. package/script/trellis/transfer.d.ts +118 -0
  230. package/script/trellis/transfer.d.ts.map +1 -0
  231. package/script/trellis/transfer.js +367 -0
  232. package/script/trellis/trellis.d.ts +3 -0
  233. package/script/trellis/trellis.d.ts.map +1 -1
  234. package/script/trellis/trellis.js +48 -17
  235. package/esm/auth/workload_activation.d.ts +0 -192
  236. package/esm/auth/workload_activation.d.ts.map +0 -1
  237. package/esm/trellis/workload.d.ts +0 -45
  238. package/esm/trellis/workload.d.ts.map +0 -1
  239. package/esm/trellis/workload.js +0 -144
  240. package/script/auth/workload_activation.d.ts +0 -192
  241. package/script/auth/workload_activation.d.ts.map +0 -1
  242. package/script/trellis/workload.d.ts +0 -45
  243. package/script/trellis/workload.d.ts.map +0 -1
  244. package/script/trellis/workload.js +0 -172
@@ -0,0 +1,316 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _TypedStore_instances, _TypedStore_store, _TypedStore_options, _TypedStore_putInternal, _TypedStoreEntry_store;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.TypedStoreEntry = exports.TypedStore = void 0;
16
+ exports.bytesFromStoreStream = bytesFromStoreStream;
17
+ const obj_1 = require("@nats-io/obj");
18
+ const result_1 = require("@qlever-llc/result");
19
+ const index_ts_1 = require("./errors/index.ts");
20
+ const INTERNAL_CONTENT_TYPE_METADATA_KEY = "__trellis_content_type";
21
+ function metadataWithContentType(options) {
22
+ if (!options?.metadata && !options?.contentType) {
23
+ return undefined;
24
+ }
25
+ return {
26
+ ...(options?.metadata ?? {}),
27
+ ...(options?.contentType ? { [INTERNAL_CONTENT_TYPE_METADATA_KEY]: options.contentType } : {}),
28
+ };
29
+ }
30
+ function storeInfoFromObjectInfo(info) {
31
+ const { [INTERNAL_CONTENT_TYPE_METADATA_KEY]: contentType, ...metadata } = info.metadata ?? {};
32
+ return {
33
+ key: info.name,
34
+ size: info.size,
35
+ updatedAt: info.mtime,
36
+ ...(info.digest ? { digest: info.digest } : {}),
37
+ ...(contentType ? { contentType } : {}),
38
+ metadata,
39
+ };
40
+ }
41
+ function streamFromBytes(data) {
42
+ return new ReadableStream({
43
+ start(controller) {
44
+ controller.enqueue(data);
45
+ controller.close();
46
+ },
47
+ });
48
+ }
49
+ function streamFromAsyncIterable(iterable) {
50
+ const iterator = iterable[Symbol.asyncIterator]();
51
+ return new ReadableStream({
52
+ async pull(controller) {
53
+ const next = await iterator.next();
54
+ if (next.done) {
55
+ controller.close();
56
+ return;
57
+ }
58
+ controller.enqueue(next.value);
59
+ },
60
+ async cancel(reason) {
61
+ await iterator.return?.(reason);
62
+ },
63
+ });
64
+ }
65
+ function enforceMaxObjectBytes(stream, maxObjectBytes) {
66
+ if (maxObjectBytes === undefined) {
67
+ return stream;
68
+ }
69
+ const reader = stream.getReader();
70
+ let totalBytes = 0;
71
+ return new ReadableStream({
72
+ async pull(controller) {
73
+ const next = await reader.read();
74
+ if (next.done) {
75
+ controller.close();
76
+ return;
77
+ }
78
+ totalBytes += next.value.length;
79
+ if (totalBytes > maxObjectBytes) {
80
+ controller.error(new index_ts_1.StoreError({
81
+ operation: "put",
82
+ context: {
83
+ reason: "max_object_bytes_exceeded",
84
+ maxObjectBytes,
85
+ attemptedBytes: totalBytes,
86
+ },
87
+ }));
88
+ await reader.cancel();
89
+ return;
90
+ }
91
+ controller.enqueue(next.value);
92
+ },
93
+ async cancel(reason) {
94
+ await reader.cancel(reason);
95
+ },
96
+ });
97
+ }
98
+ async function bytesFromStream(stream) {
99
+ const reader = stream.getReader();
100
+ const chunks = [];
101
+ let totalLength = 0;
102
+ while (true) {
103
+ const next = await reader.read();
104
+ if (next.done) {
105
+ break;
106
+ }
107
+ chunks.push(next.value);
108
+ totalLength += next.value.length;
109
+ }
110
+ const merged = new Uint8Array(totalLength);
111
+ let offset = 0;
112
+ for (const chunk of chunks) {
113
+ merged.set(chunk, offset);
114
+ offset += chunk.length;
115
+ }
116
+ return merged;
117
+ }
118
+ function streamFromBody(body) {
119
+ return body instanceof ReadableStream ? body : streamFromAsyncIterable(body);
120
+ }
121
+ async function unwrapObjectInfo(store, key) {
122
+ try {
123
+ const info = await store.info(key);
124
+ if (info === null || info.deleted) {
125
+ return result_1.Result.err(new index_ts_1.StoreError({ operation: "get", context: { key, reason: "not_found" } }));
126
+ }
127
+ return result_1.Result.ok(info);
128
+ }
129
+ catch (cause) {
130
+ return result_1.Result.err(new index_ts_1.StoreError({ operation: "get", cause, context: { key } }));
131
+ }
132
+ }
133
+ class TypedStore {
134
+ constructor(store, options) {
135
+ _TypedStore_instances.add(this);
136
+ _TypedStore_store.set(this, void 0);
137
+ _TypedStore_options.set(this, void 0);
138
+ __classPrivateFieldSet(this, _TypedStore_store, store, "f");
139
+ __classPrivateFieldSet(this, _TypedStore_options, {
140
+ ttlMs: options.ttlMs ?? 0,
141
+ ...(options.maxObjectBytes !== undefined ? { maxObjectBytes: options.maxObjectBytes } : {}),
142
+ ...(options.maxTotalBytes !== undefined ? { maxTotalBytes: options.maxTotalBytes } : {}),
143
+ ...(options.bindOnly !== undefined ? { bindOnly: options.bindOnly } : {}),
144
+ }, "f");
145
+ }
146
+ static async open(nats, name, options = {}) {
147
+ try {
148
+ const objm = new obj_1.Objm(nats);
149
+ const store = options.bindOnly
150
+ ? await objm.open(name)
151
+ : await objm.create(name, {
152
+ ...(options.ttlMs && options.ttlMs > 0 ? { ttl: options.ttlMs * 1_000_000 } : {}),
153
+ ...(options.maxTotalBytes !== undefined ? { max_bytes: options.maxTotalBytes } : {}),
154
+ });
155
+ return result_1.Result.ok(new TypedStore(store, options));
156
+ }
157
+ catch (cause) {
158
+ return result_1.Result.err(new index_ts_1.StoreError({ operation: "open", cause, context: { name } }));
159
+ }
160
+ }
161
+ async create(key, body, options) {
162
+ const existing = await unwrapObjectInfo(__classPrivateFieldGet(this, _TypedStore_store, "f"), key);
163
+ if (existing.isOk()) {
164
+ return result_1.Result.err(new index_ts_1.StoreError({ operation: "create", context: { key, reason: "already_exists" } }));
165
+ }
166
+ return __classPrivateFieldGet(this, _TypedStore_instances, "m", _TypedStore_putInternal).call(this, "create", key, body, options);
167
+ }
168
+ async put(key, body, options) {
169
+ return __classPrivateFieldGet(this, _TypedStore_instances, "m", _TypedStore_putInternal).call(this, "put", key, body, options);
170
+ }
171
+ async get(key) {
172
+ const info = await unwrapObjectInfo(__classPrivateFieldGet(this, _TypedStore_store, "f"), key);
173
+ return info.map((objectInfo) => new TypedStoreEntry(__classPrivateFieldGet(this, _TypedStore_store, "f"), storeInfoFromObjectInfo(objectInfo)));
174
+ }
175
+ async delete(key) {
176
+ try {
177
+ await __classPrivateFieldGet(this, _TypedStore_store, "f").delete(key);
178
+ return result_1.Result.ok(undefined);
179
+ }
180
+ catch (cause) {
181
+ return result_1.Result.err(new index_ts_1.StoreError({ operation: "delete", cause, context: { key } }));
182
+ }
183
+ }
184
+ async list(prefix = "") {
185
+ try {
186
+ const objects = await __classPrivateFieldGet(this, _TypedStore_store, "f").list();
187
+ const filtered = objects
188
+ .filter((info) => !info.deleted && info.name.startsWith(prefix))
189
+ .map(storeInfoFromObjectInfo);
190
+ async function* iterate() {
191
+ for (const info of filtered) {
192
+ yield info;
193
+ }
194
+ }
195
+ return result_1.Result.ok(iterate());
196
+ }
197
+ catch (cause) {
198
+ return result_1.Result.err(new index_ts_1.StoreError({ operation: "list", cause, context: { prefix } }));
199
+ }
200
+ }
201
+ async status() {
202
+ try {
203
+ const status = await __classPrivateFieldGet(this, _TypedStore_store, "f").status();
204
+ return result_1.Result.ok(storeStatusFromObjectStoreStatus(status, __classPrivateFieldGet(this, _TypedStore_options, "f")));
205
+ }
206
+ catch (cause) {
207
+ return result_1.Result.err(new index_ts_1.StoreError({ operation: "status", cause }));
208
+ }
209
+ }
210
+ }
211
+ exports.TypedStore = TypedStore;
212
+ _TypedStore_store = new WeakMap(), _TypedStore_options = new WeakMap(), _TypedStore_instances = new WeakSet(), _TypedStore_putInternal = async function _TypedStore_putInternal(operation, key, body, options) {
213
+ try {
214
+ const metadata = metadataWithContentType(options);
215
+ if (body instanceof Uint8Array) {
216
+ if (__classPrivateFieldGet(this, _TypedStore_options, "f").maxObjectBytes !== undefined && body.length > __classPrivateFieldGet(this, _TypedStore_options, "f").maxObjectBytes) {
217
+ return result_1.Result.err(new index_ts_1.StoreError({
218
+ operation,
219
+ context: {
220
+ key,
221
+ reason: "max_object_bytes_exceeded",
222
+ maxObjectBytes: __classPrivateFieldGet(this, _TypedStore_options, "f").maxObjectBytes,
223
+ attemptedBytes: body.length,
224
+ },
225
+ }));
226
+ }
227
+ await __classPrivateFieldGet(this, _TypedStore_store, "f").putBlob({ name: key, ...(metadata ? { metadata } : {}) }, body);
228
+ return result_1.Result.ok(undefined);
229
+ }
230
+ const limitedStream = enforceMaxObjectBytes(streamFromBody(body), __classPrivateFieldGet(this, _TypedStore_options, "f").maxObjectBytes);
231
+ await __classPrivateFieldGet(this, _TypedStore_store, "f").put({ name: key, ...(metadata ? { metadata } : {}) }, limitedStream);
232
+ return result_1.Result.ok(undefined);
233
+ }
234
+ catch (cause) {
235
+ return result_1.Result.err(new index_ts_1.StoreError({ operation, cause, context: { key } }));
236
+ }
237
+ };
238
+ function storeStatusFromObjectStoreStatus(status, options) {
239
+ return {
240
+ size: status.size,
241
+ sealed: status.sealed,
242
+ ttlMs: status.ttl > 0 ? Math.floor(status.ttl / 1_000_000) : options.ttlMs,
243
+ ...(options.maxObjectBytes !== undefined ? { maxObjectBytes: options.maxObjectBytes } : {}),
244
+ ...(options.maxTotalBytes !== undefined ? { maxTotalBytes: options.maxTotalBytes } : {}),
245
+ };
246
+ }
247
+ class TypedStoreEntry {
248
+ constructor(store, info) {
249
+ Object.defineProperty(this, "key", {
250
+ enumerable: true,
251
+ configurable: true,
252
+ writable: true,
253
+ value: void 0
254
+ });
255
+ Object.defineProperty(this, "info", {
256
+ enumerable: true,
257
+ configurable: true,
258
+ writable: true,
259
+ value: void 0
260
+ });
261
+ _TypedStoreEntry_store.set(this, void 0);
262
+ __classPrivateFieldSet(this, _TypedStoreEntry_store, store, "f");
263
+ this.key = info.key;
264
+ this.info = info;
265
+ }
266
+ async stream() {
267
+ try {
268
+ const result = await __classPrivateFieldGet(this, _TypedStoreEntry_store, "f").get(this.key);
269
+ if (result === null) {
270
+ return result_1.Result.err(new index_ts_1.StoreError({ operation: "stream", context: { key: this.key, reason: "not_found" } }));
271
+ }
272
+ return result_1.Result.ok(streamWithErrorCheck(result));
273
+ }
274
+ catch (cause) {
275
+ return result_1.Result.err(new index_ts_1.StoreError({ operation: "stream", cause, context: { key: this.key } }));
276
+ }
277
+ }
278
+ async bytes() {
279
+ try {
280
+ const bytes = await __classPrivateFieldGet(this, _TypedStoreEntry_store, "f").getBlob(this.key);
281
+ if (bytes === null) {
282
+ return result_1.Result.err(new index_ts_1.StoreError({ operation: "bytes", context: { key: this.key, reason: "not_found" } }));
283
+ }
284
+ return result_1.Result.ok(bytes);
285
+ }
286
+ catch (cause) {
287
+ return result_1.Result.err(new index_ts_1.StoreError({ operation: "bytes", cause, context: { key: this.key } }));
288
+ }
289
+ }
290
+ }
291
+ exports.TypedStoreEntry = TypedStoreEntry;
292
+ _TypedStoreEntry_store = new WeakMap();
293
+ function streamWithErrorCheck(result) {
294
+ const reader = result.data.getReader();
295
+ return new ReadableStream({
296
+ async pull(controller) {
297
+ const next = await reader.read();
298
+ if (next.done) {
299
+ const error = await result.error;
300
+ if (error) {
301
+ controller.error(error);
302
+ return;
303
+ }
304
+ controller.close();
305
+ return;
306
+ }
307
+ controller.enqueue(next.value);
308
+ },
309
+ async cancel(reason) {
310
+ await reader.cancel(reason);
311
+ },
312
+ });
313
+ }
314
+ async function bytesFromStoreStream(stream) {
315
+ return bytesFromStream(stream);
316
+ }
@@ -42,5 +42,5 @@ Object.defineProperty(exports, "trace", { enumerable: true, get: function () { r
42
42
  Object.defineProperty(exports, "withSpan", { enumerable: true, get: function () { return mod_ts_1.withSpan; } });
43
43
  Object.defineProperty(exports, "withSpanAsync", { enumerable: true, get: function () { return mod_ts_1.withSpanAsync; } });
44
44
  function initTracing(serviceName) {
45
- void Promise.resolve().then(() => __importStar(require("../telemetry/mod.ts"))).then((mod) => mod.initTracing(serviceName));
45
+ void Promise.resolve().then(() => __importStar(require("../telemetry/init.ts"))).then((mod) => mod.initTracing(serviceName));
46
46
  }
@@ -0,0 +1,118 @@
1
+ import { type Result as ResultType } from "@qlever-llc/result";
2
+ import { type MsgHdrs, type NatsConnection } from "@nats-io/nats-core";
3
+ import Type, { type Static } from "typebox";
4
+ import { TransferError } from "./errors/TransferError.ts";
5
+ export declare const FileInfoSchema: Type.TObject<{
6
+ key: Type.TString;
7
+ size: Type.TInteger;
8
+ updatedAt: Type.TString;
9
+ digest: Type.TOptional<Type.TString>;
10
+ contentType: Type.TOptional<Type.TString>;
11
+ metadata: Type.TRecord<"^.*$", Type.TString>;
12
+ }>;
13
+ export type FileInfo = Static<typeof FileInfoSchema>;
14
+ export declare const UploadTransferGrantSchema: Type.TIntersect<[Type.TObject<{
15
+ type: Type.TLiteral<"TransferGrant">;
16
+ service: Type.TString;
17
+ sessionKey: Type.TString;
18
+ transferId: Type.TString;
19
+ subject: Type.TString;
20
+ expiresAt: Type.TString;
21
+ chunkBytes: Type.TInteger;
22
+ }>, Type.TObject<{
23
+ kind: Type.TLiteral<"upload">;
24
+ maxBytes: Type.TOptional<Type.TInteger>;
25
+ contentType: Type.TOptional<Type.TString>;
26
+ metadata: Type.TOptional<Type.TRecord<"^.*$", Type.TString>>;
27
+ }>]>;
28
+ export declare const DownloadTransferGrantSchema: Type.TIntersect<[Type.TObject<{
29
+ type: Type.TLiteral<"TransferGrant">;
30
+ service: Type.TString;
31
+ sessionKey: Type.TString;
32
+ transferId: Type.TString;
33
+ subject: Type.TString;
34
+ expiresAt: Type.TString;
35
+ chunkBytes: Type.TInteger;
36
+ }>, Type.TObject<{
37
+ kind: Type.TLiteral<"download">;
38
+ info: Type.TObject<{
39
+ key: Type.TString;
40
+ size: Type.TInteger;
41
+ updatedAt: Type.TString;
42
+ digest: Type.TOptional<Type.TString>;
43
+ contentType: Type.TOptional<Type.TString>;
44
+ metadata: Type.TRecord<"^.*$", Type.TString>;
45
+ }>;
46
+ }>]>;
47
+ export declare const TransferGrantSchema: Type.TUnion<[Type.TIntersect<[Type.TObject<{
48
+ type: Type.TLiteral<"TransferGrant">;
49
+ service: Type.TString;
50
+ sessionKey: Type.TString;
51
+ transferId: Type.TString;
52
+ subject: Type.TString;
53
+ expiresAt: Type.TString;
54
+ chunkBytes: Type.TInteger;
55
+ }>, Type.TObject<{
56
+ kind: Type.TLiteral<"upload">;
57
+ maxBytes: Type.TOptional<Type.TInteger>;
58
+ contentType: Type.TOptional<Type.TString>;
59
+ metadata: Type.TOptional<Type.TRecord<"^.*$", Type.TString>>;
60
+ }>]>, Type.TIntersect<[Type.TObject<{
61
+ type: Type.TLiteral<"TransferGrant">;
62
+ service: Type.TString;
63
+ sessionKey: Type.TString;
64
+ transferId: Type.TString;
65
+ subject: Type.TString;
66
+ expiresAt: Type.TString;
67
+ chunkBytes: Type.TInteger;
68
+ }>, Type.TObject<{
69
+ kind: Type.TLiteral<"download">;
70
+ info: Type.TObject<{
71
+ key: Type.TString;
72
+ size: Type.TInteger;
73
+ updatedAt: Type.TString;
74
+ digest: Type.TOptional<Type.TString>;
75
+ contentType: Type.TOptional<Type.TString>;
76
+ metadata: Type.TRecord<"^.*$", Type.TString>;
77
+ }>;
78
+ }>]>]>;
79
+ export type UploadTransferGrant = Static<typeof UploadTransferGrantSchema>;
80
+ export type DownloadTransferGrant = Static<typeof DownloadTransferGrantSchema>;
81
+ export type TransferGrant = Static<typeof TransferGrantSchema>;
82
+ export type TransferBody = Uint8Array | ArrayBuffer | ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>;
83
+ type TrellisTransferAuth = {
84
+ sessionKey: string;
85
+ sign(data: Uint8Array): Promise<Uint8Array> | Uint8Array;
86
+ };
87
+ declare class BaseTransferHandle {
88
+ #private;
89
+ protected constructor(nc: NatsConnection, auth: TrellisTransferAuth, timeoutMs: number);
90
+ protected get nc(): NatsConnection;
91
+ protected get auth(): TrellisTransferAuth;
92
+ protected get timeoutMs(): number;
93
+ protected validateGrant(grant: TransferGrant, operation: string): ResultType<void, TransferError>;
94
+ protected buildHeaders(subject: string, payload: Uint8Array, seq?: number, eof?: boolean): Promise<MsgHdrs>;
95
+ }
96
+ export declare class UploadTransferHandle extends BaseTransferHandle {
97
+ #private;
98
+ constructor(nc: NatsConnection, auth: TrellisTransferAuth, timeoutMs: number, grant: UploadTransferGrant);
99
+ put(body: TransferBody): Promise<ResultType<FileInfo, TransferError>>;
100
+ }
101
+ export declare class DownloadTransferHandle extends BaseTransferHandle {
102
+ #private;
103
+ constructor(nc: NatsConnection, auth: TrellisTransferAuth, timeoutMs: number, grant: DownloadTransferGrant);
104
+ getBytes(): Promise<ResultType<Uint8Array, TransferError>>;
105
+ }
106
+ export type TransferHandle = UploadTransferHandle | DownloadTransferHandle;
107
+ export declare function createTransferHandle(nc: NatsConnection, auth: TrellisTransferAuth, timeoutMs: number, grant: UploadTransferGrant): UploadTransferHandle;
108
+ export declare function createTransferHandle(nc: NatsConnection, auth: TrellisTransferAuth, timeoutMs: number, grant: DownloadTransferGrant): DownloadTransferHandle;
109
+ export declare function createTransferHandle(nc: NatsConnection, auth: TrellisTransferAuth, timeoutMs: number, grant: TransferGrant): TransferHandle;
110
+ export declare function verifyTransferMessage(args: {
111
+ expectedSessionKey: string;
112
+ subject: string;
113
+ payload: Uint8Array;
114
+ proof?: string | null;
115
+ sessionKey?: string | null;
116
+ }): Promise<boolean>;
117
+ export {};
118
+ //# sourceMappingURL=transfer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transfer.d.ts","sourceRoot":"","sources":["../../../transfer.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,MAAM,IAAI,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EAAiD,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACtH,OAAO,IAAI,EAAE,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAK1D,eAAO,MAAM,cAAc;;;;;;;EAOQ,CAAC;AAEpC,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC;AAYrD,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;IAQpC,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;IAMtC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;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