@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.
- package/README.md +6 -2
- package/esm/auth/device_activation.d.ts +194 -0
- package/esm/auth/device_activation.d.ts.map +1 -0
- package/esm/auth/{workload_activation.js → device_activation.js} +85 -60
- package/esm/auth/mod.d.ts +2 -2
- package/esm/auth/mod.d.ts.map +1 -1
- package/esm/auth/mod.js +2 -2
- package/esm/auth/protocol.d.ts +175 -72
- package/esm/auth/protocol.d.ts.map +1 -1
- package/esm/auth/protocol.js +126 -78
- package/esm/contracts/mod.d.ts +19 -3
- package/esm/contracts/mod.d.ts.map +1 -1
- package/esm/contracts/mod.js +28 -4
- package/esm/contracts/protocol.d.ts +34 -0
- package/esm/contracts/protocol.d.ts.map +1 -1
- package/esm/contracts/protocol.js +15 -0
- package/esm/server/deno.d.ts +1 -6
- package/esm/server/deno.d.ts.map +1 -1
- package/esm/server/deno.js +1 -16
- package/esm/server/mod.d.ts +3 -2
- package/esm/server/mod.d.ts.map +1 -1
- package/esm/server/mod.js +2 -2
- package/esm/server/node.d.ts +1 -6
- package/esm/server/node.d.ts.map +1 -1
- package/esm/server/node.js +1 -16
- package/esm/server/service.d.ts +32 -10
- package/esm/server/service.d.ts.map +1 -1
- package/esm/server/service.js +188 -41
- package/esm/server/transfer.d.ts +41 -0
- package/esm/server/transfer.d.ts.map +1 -0
- package/esm/server/transfer.js +418 -0
- package/esm/telemetry/init.d.ts +4 -0
- package/esm/telemetry/init.d.ts.map +1 -0
- package/esm/telemetry/init.js +7 -0
- package/esm/telemetry/mod.d.ts +1 -2
- package/esm/telemetry/mod.d.ts.map +1 -1
- package/esm/telemetry/mod.js +1 -2
- package/esm/telemetry/runtime.d.ts.map +1 -1
- package/esm/telemetry/runtime.js +9 -5
- package/esm/telemetry/trellis.d.ts +0 -1
- package/esm/telemetry/trellis.d.ts.map +1 -1
- package/esm/telemetry/trellis.js +0 -6
- package/esm/trellis/_sdk/auth/api.d.ts.map +1 -1
- package/esm/trellis/_sdk/auth/api.js +132 -110
- package/esm/trellis/_sdk/auth/contract.d.ts +1 -1
- package/esm/trellis/_sdk/auth/contract.d.ts.map +1 -1
- package/esm/trellis/_sdk/auth/contract.js +2 -2
- package/esm/trellis/_sdk/auth/schemas.d.ts +4212 -3069
- package/esm/trellis/_sdk/auth/schemas.d.ts.map +1 -1
- package/esm/trellis/_sdk/auth/schemas.js +144 -125
- package/esm/trellis/_sdk/auth/types.d.ts +417 -267
- package/esm/trellis/_sdk/auth/types.d.ts.map +1 -1
- package/esm/trellis/_sdk/auth/types.js +1 -1
- package/esm/trellis/_sdk/core/contract.d.ts +1 -1
- package/esm/trellis/_sdk/core/contract.d.ts.map +1 -1
- package/esm/trellis/_sdk/core/contract.js +2 -2
- package/esm/trellis/_sdk/core/schemas.d.ts +122 -0
- package/esm/trellis/_sdk/core/schemas.d.ts.map +1 -1
- package/esm/trellis/_sdk/core/schemas.js +4 -4
- package/esm/trellis/_sdk/core/types.d.ts +18 -1
- package/esm/trellis/_sdk/core/types.d.ts.map +1 -1
- package/esm/trellis/_sdk/core/types.js +1 -1
- package/esm/trellis/_sdk/state/_dnt.polyfills.d.ts +12 -0
- package/esm/trellis/_sdk/state/_dnt.polyfills.d.ts.map +1 -0
- package/esm/trellis/_sdk/state/_dnt.polyfills.js +15 -0
- package/esm/trellis/_sdk/state/api.d.ts +10 -0
- package/esm/trellis/_sdk/state/api.d.ts.map +1 -0
- package/esm/trellis/_sdk/state/api.js +71 -0
- package/esm/trellis/_sdk/state/contract.d.ts +8 -0
- package/esm/trellis/_sdk/state/contract.d.ts.map +1 -0
- package/esm/trellis/_sdk/state/contract.js +59 -0
- package/esm/trellis/_sdk/state/mod.d.ts +7 -0
- package/esm/trellis/_sdk/state/mod.d.ts.map +1 -0
- package/esm/trellis/_sdk/state/mod.js +5 -0
- package/esm/trellis/_sdk/state/package.json +3 -0
- package/esm/trellis/_sdk/state/schemas.d.ts +1437 -0
- package/esm/trellis/_sdk/state/schemas.d.ts.map +1 -0
- package/esm/trellis/_sdk/state/schemas.js +62 -0
- package/esm/trellis/_sdk/state/types.d.ts +206 -0
- package/esm/trellis/_sdk/state/types.d.ts.map +1 -0
- package/esm/trellis/_sdk/state/types.js +3 -0
- package/esm/trellis/client_connect.d.ts +53 -0
- package/esm/trellis/client_connect.d.ts.map +1 -0
- package/esm/trellis/client_connect.js +300 -0
- package/esm/trellis/contract.d.ts +1 -7
- package/esm/trellis/contract.d.ts.map +1 -1
- package/esm/trellis/contract.js +1 -12
- package/esm/trellis/device.d.ts +41 -0
- package/esm/trellis/device.d.ts.map +1 -0
- package/esm/trellis/device.js +209 -0
- package/esm/trellis/errors/AuthError.d.ts +1 -1
- package/esm/trellis/errors/AuthError.js +9 -9
- package/esm/trellis/errors/StoreError.d.ts +22 -0
- package/esm/trellis/errors/StoreError.d.ts.map +1 -0
- package/esm/trellis/errors/StoreError.js +41 -0
- package/esm/trellis/errors/TransferError.d.ts +22 -0
- package/esm/trellis/errors/TransferError.d.ts.map +1 -0
- package/esm/trellis/errors/TransferError.js +41 -0
- package/esm/trellis/errors/index.d.ts +8 -0
- package/esm/trellis/errors/index.d.ts.map +1 -1
- package/esm/trellis/errors/index.js +8 -0
- package/esm/trellis/index.d.ts +10 -4
- package/esm/trellis/index.d.ts.map +1 -1
- package/esm/trellis/index.js +6 -4
- package/esm/trellis/kv.d.ts +2 -0
- package/esm/trellis/kv.d.ts.map +1 -1
- package/esm/trellis/kv.js +6 -0
- package/esm/trellis/models/trellis/TrellisError.d.ts +15 -1
- package/esm/trellis/models/trellis/TrellisError.d.ts.map +1 -1
- package/esm/trellis/models/trellis/TrellisError.js +4 -0
- package/esm/trellis/runtime_transport.d.ts +12 -0
- package/esm/trellis/runtime_transport.d.ts.map +1 -0
- package/esm/trellis/runtime_transport.js +35 -0
- package/esm/trellis/sdk/state.d.ts +4 -0
- package/esm/trellis/sdk/state.d.ts.map +1 -0
- package/esm/trellis/sdk/state.js +3 -0
- package/esm/trellis/store.d.ts +51 -0
- package/esm/trellis/store.d.ts.map +1 -0
- package/esm/trellis/store.js +310 -0
- package/esm/trellis/tracing.js +1 -1
- package/esm/trellis/transfer.d.ts +118 -0
- package/esm/trellis/transfer.d.ts.map +1 -0
- package/esm/trellis/transfer.js +357 -0
- package/esm/trellis/trellis.d.ts +3 -0
- package/esm/trellis/trellis.d.ts.map +1 -1
- package/esm/trellis/trellis.js +48 -17
- package/package.json +7 -2
- package/script/auth/device_activation.d.ts +194 -0
- package/script/auth/device_activation.d.ts.map +1 -0
- package/script/auth/{workload_activation.js → device_activation.js} +99 -74
- package/script/auth/mod.d.ts +2 -2
- package/script/auth/mod.d.ts.map +1 -1
- package/script/auth/mod.js +84 -76
- package/script/auth/protocol.d.ts +175 -72
- package/script/auth/protocol.d.ts.map +1 -1
- package/script/auth/protocol.js +129 -81
- package/script/contracts/mod.d.ts +19 -3
- package/script/contracts/mod.d.ts.map +1 -1
- package/script/contracts/mod.js +30 -4
- package/script/contracts/protocol.d.ts +34 -0
- package/script/contracts/protocol.d.ts.map +1 -1
- package/script/contracts/protocol.js +16 -1
- package/script/telemetry/init.d.ts +4 -0
- package/script/telemetry/init.d.ts.map +1 -0
- package/script/telemetry/init.js +11 -0
- package/script/telemetry/mod.d.ts +1 -2
- package/script/telemetry/mod.d.ts.map +1 -1
- package/script/telemetry/mod.js +1 -4
- package/script/telemetry/runtime.d.ts.map +1 -1
- package/script/telemetry/runtime.js +9 -28
- package/script/telemetry/trellis.d.ts +0 -1
- package/script/telemetry/trellis.d.ts.map +1 -1
- package/script/telemetry/trellis.js +0 -7
- package/script/trellis/_sdk/auth/api.d.ts.map +1 -1
- package/script/trellis/_sdk/auth/api.js +132 -110
- package/script/trellis/_sdk/auth/contract.d.ts +1 -1
- package/script/trellis/_sdk/auth/contract.d.ts.map +1 -1
- package/script/trellis/_sdk/auth/contract.js +2 -2
- package/script/trellis/_sdk/auth/schemas.d.ts +4212 -3069
- package/script/trellis/_sdk/auth/schemas.d.ts.map +1 -1
- package/script/trellis/_sdk/auth/schemas.js +144 -125
- package/script/trellis/_sdk/auth/types.d.ts +417 -267
- package/script/trellis/_sdk/auth/types.d.ts.map +1 -1
- package/script/trellis/_sdk/auth/types.js +1 -1
- package/script/trellis/_sdk/core/contract.d.ts +1 -1
- package/script/trellis/_sdk/core/contract.d.ts.map +1 -1
- package/script/trellis/_sdk/core/contract.js +2 -2
- package/script/trellis/_sdk/core/schemas.d.ts +122 -0
- package/script/trellis/_sdk/core/schemas.d.ts.map +1 -1
- package/script/trellis/_sdk/core/schemas.js +4 -4
- package/script/trellis/_sdk/core/types.d.ts +18 -1
- package/script/trellis/_sdk/core/types.d.ts.map +1 -1
- package/script/trellis/_sdk/core/types.js +1 -1
- package/script/trellis/_sdk/state/_dnt.polyfills.d.ts +12 -0
- package/script/trellis/_sdk/state/_dnt.polyfills.d.ts.map +1 -0
- package/script/trellis/_sdk/state/_dnt.polyfills.js +16 -0
- package/script/trellis/_sdk/state/api.d.ts +10 -0
- package/script/trellis/_sdk/state/api.d.ts.map +1 -0
- package/script/trellis/_sdk/state/api.js +74 -0
- package/script/trellis/_sdk/state/contract.d.ts +8 -0
- package/script/trellis/_sdk/state/contract.d.ts.map +1 -0
- package/script/trellis/_sdk/state/contract.js +62 -0
- package/script/trellis/_sdk/state/mod.d.ts +7 -0
- package/script/trellis/_sdk/state/mod.d.ts.map +1 -0
- package/script/trellis/_sdk/state/mod.js +30 -0
- package/script/trellis/_sdk/state/package.json +3 -0
- package/script/trellis/_sdk/state/schemas.d.ts +1437 -0
- package/script/trellis/_sdk/state/schemas.d.ts.map +1 -0
- package/script/trellis/_sdk/state/schemas.js +65 -0
- package/script/trellis/_sdk/state/types.d.ts +206 -0
- package/script/trellis/_sdk/state/types.d.ts.map +1 -0
- package/script/trellis/_sdk/state/types.js +6 -0
- package/script/trellis/client_connect.d.ts +53 -0
- package/script/trellis/client_connect.d.ts.map +1 -0
- package/script/trellis/client_connect.js +304 -0
- package/script/trellis/contract.d.ts +1 -7
- package/script/trellis/contract.d.ts.map +1 -1
- package/script/trellis/contract.js +1 -12
- package/script/trellis/device.d.ts +41 -0
- package/script/trellis/device.d.ts.map +1 -0
- package/script/trellis/device.js +213 -0
- package/script/trellis/errors/AuthError.d.ts +1 -1
- package/script/trellis/errors/AuthError.js +9 -9
- package/script/trellis/errors/StoreError.d.ts +22 -0
- package/script/trellis/errors/StoreError.d.ts.map +1 -0
- package/script/trellis/errors/StoreError.js +48 -0
- package/script/trellis/errors/TransferError.d.ts +22 -0
- package/script/trellis/errors/TransferError.d.ts.map +1 -0
- package/script/trellis/errors/TransferError.js +48 -0
- package/script/trellis/errors/index.d.ts +8 -0
- package/script/trellis/errors/index.d.ts.map +1 -1
- package/script/trellis/errors/index.js +13 -1
- package/script/trellis/index.d.ts +10 -4
- package/script/trellis/index.d.ts.map +1 -1
- package/script/trellis/index.js +17 -6
- package/script/trellis/kv.d.ts +2 -0
- package/script/trellis/kv.d.ts.map +1 -1
- package/script/trellis/kv.js +6 -0
- package/script/trellis/models/trellis/TrellisError.d.ts +15 -1
- package/script/trellis/models/trellis/TrellisError.d.ts.map +1 -1
- package/script/trellis/models/trellis/TrellisError.js +4 -0
- package/script/trellis/runtime_transport.d.ts +12 -0
- package/script/trellis/runtime_transport.d.ts.map +1 -0
- package/script/trellis/runtime_transport.js +37 -0
- package/script/trellis/store.d.ts +51 -0
- package/script/trellis/store.d.ts.map +1 -0
- package/script/trellis/store.js +316 -0
- package/script/trellis/tracing.js +1 -1
- package/script/trellis/transfer.d.ts +118 -0
- package/script/trellis/transfer.d.ts.map +1 -0
- package/script/trellis/transfer.js +367 -0
- package/script/trellis/trellis.d.ts +3 -0
- package/script/trellis/trellis.d.ts.map +1 -1
- package/script/trellis/trellis.js +48 -17
- package/esm/auth/workload_activation.d.ts +0 -192
- package/esm/auth/workload_activation.d.ts.map +0 -1
- package/esm/trellis/workload.d.ts +0 -45
- package/esm/trellis/workload.d.ts.map +0 -1
- package/esm/trellis/workload.js +0 -144
- package/script/auth/workload_activation.d.ts +0 -192
- package/script/auth/workload_activation.d.ts.map +0 -1
- package/script/trellis/workload.d.ts +0 -45
- package/script/trellis/workload.d.ts.map +0 -1
- 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/
|
|
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":"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"}
|