@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,310 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ 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");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ 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");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _TypedStore_instances, _TypedStore_store, _TypedStore_options, _TypedStore_putInternal, _TypedStoreEntry_store;
13
+ import { Objm } from "@nats-io/obj";
14
+ import { Result } from "@qlever-llc/result";
15
+ import { StoreError } from "./errors/index.js";
16
+ const INTERNAL_CONTENT_TYPE_METADATA_KEY = "__trellis_content_type";
17
+ function metadataWithContentType(options) {
18
+ if (!options?.metadata && !options?.contentType) {
19
+ return undefined;
20
+ }
21
+ return {
22
+ ...(options?.metadata ?? {}),
23
+ ...(options?.contentType ? { [INTERNAL_CONTENT_TYPE_METADATA_KEY]: options.contentType } : {}),
24
+ };
25
+ }
26
+ function storeInfoFromObjectInfo(info) {
27
+ const { [INTERNAL_CONTENT_TYPE_METADATA_KEY]: contentType, ...metadata } = info.metadata ?? {};
28
+ return {
29
+ key: info.name,
30
+ size: info.size,
31
+ updatedAt: info.mtime,
32
+ ...(info.digest ? { digest: info.digest } : {}),
33
+ ...(contentType ? { contentType } : {}),
34
+ metadata,
35
+ };
36
+ }
37
+ function streamFromBytes(data) {
38
+ return new ReadableStream({
39
+ start(controller) {
40
+ controller.enqueue(data);
41
+ controller.close();
42
+ },
43
+ });
44
+ }
45
+ function streamFromAsyncIterable(iterable) {
46
+ const iterator = iterable[Symbol.asyncIterator]();
47
+ return new ReadableStream({
48
+ async pull(controller) {
49
+ const next = await iterator.next();
50
+ if (next.done) {
51
+ controller.close();
52
+ return;
53
+ }
54
+ controller.enqueue(next.value);
55
+ },
56
+ async cancel(reason) {
57
+ await iterator.return?.(reason);
58
+ },
59
+ });
60
+ }
61
+ function enforceMaxObjectBytes(stream, maxObjectBytes) {
62
+ if (maxObjectBytes === undefined) {
63
+ return stream;
64
+ }
65
+ const reader = stream.getReader();
66
+ let totalBytes = 0;
67
+ return new ReadableStream({
68
+ async pull(controller) {
69
+ const next = await reader.read();
70
+ if (next.done) {
71
+ controller.close();
72
+ return;
73
+ }
74
+ totalBytes += next.value.length;
75
+ if (totalBytes > maxObjectBytes) {
76
+ controller.error(new StoreError({
77
+ operation: "put",
78
+ context: {
79
+ reason: "max_object_bytes_exceeded",
80
+ maxObjectBytes,
81
+ attemptedBytes: totalBytes,
82
+ },
83
+ }));
84
+ await reader.cancel();
85
+ return;
86
+ }
87
+ controller.enqueue(next.value);
88
+ },
89
+ async cancel(reason) {
90
+ await reader.cancel(reason);
91
+ },
92
+ });
93
+ }
94
+ async function bytesFromStream(stream) {
95
+ const reader = stream.getReader();
96
+ const chunks = [];
97
+ let totalLength = 0;
98
+ while (true) {
99
+ const next = await reader.read();
100
+ if (next.done) {
101
+ break;
102
+ }
103
+ chunks.push(next.value);
104
+ totalLength += next.value.length;
105
+ }
106
+ const merged = new Uint8Array(totalLength);
107
+ let offset = 0;
108
+ for (const chunk of chunks) {
109
+ merged.set(chunk, offset);
110
+ offset += chunk.length;
111
+ }
112
+ return merged;
113
+ }
114
+ function streamFromBody(body) {
115
+ return body instanceof ReadableStream ? body : streamFromAsyncIterable(body);
116
+ }
117
+ async function unwrapObjectInfo(store, key) {
118
+ try {
119
+ const info = await store.info(key);
120
+ if (info === null || info.deleted) {
121
+ return Result.err(new StoreError({ operation: "get", context: { key, reason: "not_found" } }));
122
+ }
123
+ return Result.ok(info);
124
+ }
125
+ catch (cause) {
126
+ return Result.err(new StoreError({ operation: "get", cause, context: { key } }));
127
+ }
128
+ }
129
+ export class TypedStore {
130
+ constructor(store, options) {
131
+ _TypedStore_instances.add(this);
132
+ _TypedStore_store.set(this, void 0);
133
+ _TypedStore_options.set(this, void 0);
134
+ __classPrivateFieldSet(this, _TypedStore_store, store, "f");
135
+ __classPrivateFieldSet(this, _TypedStore_options, {
136
+ ttlMs: options.ttlMs ?? 0,
137
+ ...(options.maxObjectBytes !== undefined ? { maxObjectBytes: options.maxObjectBytes } : {}),
138
+ ...(options.maxTotalBytes !== undefined ? { maxTotalBytes: options.maxTotalBytes } : {}),
139
+ ...(options.bindOnly !== undefined ? { bindOnly: options.bindOnly } : {}),
140
+ }, "f");
141
+ }
142
+ static async open(nats, name, options = {}) {
143
+ try {
144
+ const objm = new Objm(nats);
145
+ const store = options.bindOnly
146
+ ? await objm.open(name)
147
+ : await objm.create(name, {
148
+ ...(options.ttlMs && options.ttlMs > 0 ? { ttl: options.ttlMs * 1_000_000 } : {}),
149
+ ...(options.maxTotalBytes !== undefined ? { max_bytes: options.maxTotalBytes } : {}),
150
+ });
151
+ return Result.ok(new TypedStore(store, options));
152
+ }
153
+ catch (cause) {
154
+ return Result.err(new StoreError({ operation: "open", cause, context: { name } }));
155
+ }
156
+ }
157
+ async create(key, body, options) {
158
+ const existing = await unwrapObjectInfo(__classPrivateFieldGet(this, _TypedStore_store, "f"), key);
159
+ if (existing.isOk()) {
160
+ return Result.err(new StoreError({ operation: "create", context: { key, reason: "already_exists" } }));
161
+ }
162
+ return __classPrivateFieldGet(this, _TypedStore_instances, "m", _TypedStore_putInternal).call(this, "create", key, body, options);
163
+ }
164
+ async put(key, body, options) {
165
+ return __classPrivateFieldGet(this, _TypedStore_instances, "m", _TypedStore_putInternal).call(this, "put", key, body, options);
166
+ }
167
+ async get(key) {
168
+ const info = await unwrapObjectInfo(__classPrivateFieldGet(this, _TypedStore_store, "f"), key);
169
+ return info.map((objectInfo) => new TypedStoreEntry(__classPrivateFieldGet(this, _TypedStore_store, "f"), storeInfoFromObjectInfo(objectInfo)));
170
+ }
171
+ async delete(key) {
172
+ try {
173
+ await __classPrivateFieldGet(this, _TypedStore_store, "f").delete(key);
174
+ return Result.ok(undefined);
175
+ }
176
+ catch (cause) {
177
+ return Result.err(new StoreError({ operation: "delete", cause, context: { key } }));
178
+ }
179
+ }
180
+ async list(prefix = "") {
181
+ try {
182
+ const objects = await __classPrivateFieldGet(this, _TypedStore_store, "f").list();
183
+ const filtered = objects
184
+ .filter((info) => !info.deleted && info.name.startsWith(prefix))
185
+ .map(storeInfoFromObjectInfo);
186
+ async function* iterate() {
187
+ for (const info of filtered) {
188
+ yield info;
189
+ }
190
+ }
191
+ return Result.ok(iterate());
192
+ }
193
+ catch (cause) {
194
+ return Result.err(new StoreError({ operation: "list", cause, context: { prefix } }));
195
+ }
196
+ }
197
+ async status() {
198
+ try {
199
+ const status = await __classPrivateFieldGet(this, _TypedStore_store, "f").status();
200
+ return Result.ok(storeStatusFromObjectStoreStatus(status, __classPrivateFieldGet(this, _TypedStore_options, "f")));
201
+ }
202
+ catch (cause) {
203
+ return Result.err(new StoreError({ operation: "status", cause }));
204
+ }
205
+ }
206
+ }
207
+ _TypedStore_store = new WeakMap(), _TypedStore_options = new WeakMap(), _TypedStore_instances = new WeakSet(), _TypedStore_putInternal = async function _TypedStore_putInternal(operation, key, body, options) {
208
+ try {
209
+ const metadata = metadataWithContentType(options);
210
+ if (body instanceof Uint8Array) {
211
+ if (__classPrivateFieldGet(this, _TypedStore_options, "f").maxObjectBytes !== undefined && body.length > __classPrivateFieldGet(this, _TypedStore_options, "f").maxObjectBytes) {
212
+ return Result.err(new StoreError({
213
+ operation,
214
+ context: {
215
+ key,
216
+ reason: "max_object_bytes_exceeded",
217
+ maxObjectBytes: __classPrivateFieldGet(this, _TypedStore_options, "f").maxObjectBytes,
218
+ attemptedBytes: body.length,
219
+ },
220
+ }));
221
+ }
222
+ await __classPrivateFieldGet(this, _TypedStore_store, "f").putBlob({ name: key, ...(metadata ? { metadata } : {}) }, body);
223
+ return Result.ok(undefined);
224
+ }
225
+ const limitedStream = enforceMaxObjectBytes(streamFromBody(body), __classPrivateFieldGet(this, _TypedStore_options, "f").maxObjectBytes);
226
+ await __classPrivateFieldGet(this, _TypedStore_store, "f").put({ name: key, ...(metadata ? { metadata } : {}) }, limitedStream);
227
+ return Result.ok(undefined);
228
+ }
229
+ catch (cause) {
230
+ return Result.err(new StoreError({ operation, cause, context: { key } }));
231
+ }
232
+ };
233
+ function storeStatusFromObjectStoreStatus(status, options) {
234
+ return {
235
+ size: status.size,
236
+ sealed: status.sealed,
237
+ ttlMs: status.ttl > 0 ? Math.floor(status.ttl / 1_000_000) : options.ttlMs,
238
+ ...(options.maxObjectBytes !== undefined ? { maxObjectBytes: options.maxObjectBytes } : {}),
239
+ ...(options.maxTotalBytes !== undefined ? { maxTotalBytes: options.maxTotalBytes } : {}),
240
+ };
241
+ }
242
+ export class TypedStoreEntry {
243
+ constructor(store, info) {
244
+ Object.defineProperty(this, "key", {
245
+ enumerable: true,
246
+ configurable: true,
247
+ writable: true,
248
+ value: void 0
249
+ });
250
+ Object.defineProperty(this, "info", {
251
+ enumerable: true,
252
+ configurable: true,
253
+ writable: true,
254
+ value: void 0
255
+ });
256
+ _TypedStoreEntry_store.set(this, void 0);
257
+ __classPrivateFieldSet(this, _TypedStoreEntry_store, store, "f");
258
+ this.key = info.key;
259
+ this.info = info;
260
+ }
261
+ async stream() {
262
+ try {
263
+ const result = await __classPrivateFieldGet(this, _TypedStoreEntry_store, "f").get(this.key);
264
+ if (result === null) {
265
+ return Result.err(new StoreError({ operation: "stream", context: { key: this.key, reason: "not_found" } }));
266
+ }
267
+ return Result.ok(streamWithErrorCheck(result));
268
+ }
269
+ catch (cause) {
270
+ return Result.err(new StoreError({ operation: "stream", cause, context: { key: this.key } }));
271
+ }
272
+ }
273
+ async bytes() {
274
+ try {
275
+ const bytes = await __classPrivateFieldGet(this, _TypedStoreEntry_store, "f").getBlob(this.key);
276
+ if (bytes === null) {
277
+ return Result.err(new StoreError({ operation: "bytes", context: { key: this.key, reason: "not_found" } }));
278
+ }
279
+ return Result.ok(bytes);
280
+ }
281
+ catch (cause) {
282
+ return Result.err(new StoreError({ operation: "bytes", cause, context: { key: this.key } }));
283
+ }
284
+ }
285
+ }
286
+ _TypedStoreEntry_store = new WeakMap();
287
+ function streamWithErrorCheck(result) {
288
+ const reader = result.data.getReader();
289
+ return new ReadableStream({
290
+ async pull(controller) {
291
+ const next = await reader.read();
292
+ if (next.done) {
293
+ const error = await result.error;
294
+ if (error) {
295
+ controller.error(error);
296
+ return;
297
+ }
298
+ controller.close();
299
+ return;
300
+ }
301
+ controller.enqueue(next.value);
302
+ },
303
+ async cancel(reason) {
304
+ await reader.cancel(reason);
305
+ },
306
+ });
307
+ }
308
+ export async function bytesFromStoreStream(stream) {
309
+ return bytesFromStream(stream);
310
+ }
@@ -3,5 +3,5 @@
3
3
  import "../_dnt.polyfills.js";
4
4
  export { configureErrorTraceId, context, createMapCarrier, createNatsHeaderCarrier, extractTraceContext, getActiveSpan, getTrellisTracer as getTracer, injectTraceContext, SpanKind, SpanStatusCode, startClientSpan, startServerSpan, trace, withSpan, withSpanAsync } from "../telemetry/mod.js";
5
5
  export function initTracing(serviceName) {
6
- void import("../telemetry/mod.js").then((mod) => mod.initTracing(serviceName));
6
+ void import("../telemetry/init.js").then((mod) => mod.initTracing(serviceName));
7
7
  }
@@ -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.js";
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":["../../src/trellis/transfer.ts"],"names":[],"mappings":"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"}