@qlever-llc/trellis 0.6.0 → 0.7.0-rc.2
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 +22 -2
- package/esm/contracts/mod.d.ts.map +1 -1
- package/esm/contracts/mod.js +30 -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/activity/contract.d.ts +1 -1
- package/esm/trellis/_sdk/activity/contract.d.ts.map +1 -1
- package/esm/trellis/_sdk/activity/contract.js +2 -2
- package/esm/trellis/_sdk/activity/types.d.ts +1 -1
- package/esm/trellis/_sdk/activity/types.js +1 -1
- 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 +8 -3
- 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 +22 -2
- package/script/contracts/mod.d.ts.map +1 -1
- package/script/contracts/mod.js +32 -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/activity/contract.d.ts +1 -1
- package/script/trellis/_sdk/activity/contract.d.ts.map +1 -1
- package/script/trellis/_sdk/activity/contract.js +2 -2
- package/script/trellis/_sdk/activity/types.d.ts +1 -1
- package/script/trellis/_sdk/activity/types.js +1 -1
- 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
package/esm/server/service.js
CHANGED
|
@@ -9,12 +9,18 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
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
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _KVHandle_nc;
|
|
13
|
-
import
|
|
12
|
+
var _KVHandle_nc, _StoreHandle_nc;
|
|
13
|
+
import * as dntShim from "../_dnt.shims.js";
|
|
14
|
+
import { jwtAuthenticator, } from "@nats-io/nats-core";
|
|
15
|
+
import { Trellis, TypedKV, TypedStore, } from "@qlever-llc/trellis";
|
|
14
16
|
import { TrellisServer } from "@qlever-llc/trellis/server/runtime";
|
|
15
|
-
import { createAuth } from "@qlever-llc/trellis/auth";
|
|
17
|
+
import { createAuth, SentinelCredsSchema, } from "@qlever-llc/trellis/auth";
|
|
18
|
+
import { ContractResourceBindingsSchema, } from "@qlever-llc/trellis/contracts";
|
|
16
19
|
import { isErr } from "@qlever-llc/result";
|
|
20
|
+
import { Type } from "typebox";
|
|
21
|
+
import { Value } from "typebox/value";
|
|
17
22
|
import { mountStandardHealthRpc } from "./health_rpc.js";
|
|
23
|
+
import { ServiceTransfer } from "./transfer.js";
|
|
18
24
|
function getErrorCauseMessage(error) {
|
|
19
25
|
if (error && typeof error === "object") {
|
|
20
26
|
const context = error.context;
|
|
@@ -31,6 +37,64 @@ function bootstrapContractStateError(args) {
|
|
|
31
37
|
const cause = args.cause ? ` Underlying error: ${getErrorCauseMessage(args.cause)}` : "";
|
|
32
38
|
return new Error(base + cause);
|
|
33
39
|
}
|
|
40
|
+
function runtimeImport(specifier) {
|
|
41
|
+
const load = new Function("specifier", "return import(specifier);");
|
|
42
|
+
return load(specifier);
|
|
43
|
+
}
|
|
44
|
+
async function loadDefaultServiceRuntimeDeps() {
|
|
45
|
+
if ("Deno" in dntShim.dntGlobalThis) {
|
|
46
|
+
const mod = await runtimeImport("@nats-io/transport-deno");
|
|
47
|
+
return { connect: mod.connect };
|
|
48
|
+
}
|
|
49
|
+
const mod = await runtimeImport("@nats-io/transport-node");
|
|
50
|
+
return { connect: mod.connect };
|
|
51
|
+
}
|
|
52
|
+
const ServiceBootstrapReadySchema = Type.Object({
|
|
53
|
+
status: Type.Literal("ready"),
|
|
54
|
+
connectInfo: Type.Object({
|
|
55
|
+
sessionKey: Type.String({ minLength: 1 }),
|
|
56
|
+
contractId: Type.String({ minLength: 1 }),
|
|
57
|
+
contractDigest: Type.String({ minLength: 1 }),
|
|
58
|
+
transport: Type.Object({
|
|
59
|
+
natsServers: Type.Array(Type.String({ minLength: 1 }), { minItems: 1 }),
|
|
60
|
+
sentinel: SentinelCredsSchema,
|
|
61
|
+
}, { additionalProperties: false }),
|
|
62
|
+
auth: Type.Object({
|
|
63
|
+
mode: Type.Literal("service_identity"),
|
|
64
|
+
iatSkewSeconds: Type.Integer({ minimum: 1 }),
|
|
65
|
+
}, { additionalProperties: false }),
|
|
66
|
+
}, { additionalProperties: false }),
|
|
67
|
+
binding: Type.Object({
|
|
68
|
+
contractId: Type.String({ minLength: 1 }),
|
|
69
|
+
digest: Type.String({ minLength: 1 }),
|
|
70
|
+
resources: ContractResourceBindingsSchema,
|
|
71
|
+
}, { additionalProperties: false }),
|
|
72
|
+
}, { additionalProperties: true });
|
|
73
|
+
const ServiceBootstrapFailureSchema = Type.Object({
|
|
74
|
+
reason: Type.String({ minLength: 1 }),
|
|
75
|
+
}, { additionalProperties: true });
|
|
76
|
+
async function fetchServiceBootstrapInfo(args) {
|
|
77
|
+
const iat = Math.floor(Date.now() / 1_000);
|
|
78
|
+
const response = await fetch(new URL("/bootstrap/service", args.trellisUrl), {
|
|
79
|
+
method: "POST",
|
|
80
|
+
headers: { "Content-Type": "application/json" },
|
|
81
|
+
body: JSON.stringify({
|
|
82
|
+
sessionKey: args.auth.sessionKey,
|
|
83
|
+
contractId: args.contractId,
|
|
84
|
+
contractDigest: args.contractDigest,
|
|
85
|
+
iat,
|
|
86
|
+
sig: await args.auth.natsConnectSigForIat(iat),
|
|
87
|
+
}),
|
|
88
|
+
});
|
|
89
|
+
const payload = await response.json();
|
|
90
|
+
if (!response.ok) {
|
|
91
|
+
if (Value.Check(ServiceBootstrapFailureSchema, payload)) {
|
|
92
|
+
throw new Error(`Service bootstrap failed: ${payload.reason}`);
|
|
93
|
+
}
|
|
94
|
+
throw new Error(`Service bootstrap failed with HTTP ${response.status}`);
|
|
95
|
+
}
|
|
96
|
+
return Value.Parse(ServiceBootstrapReadySchema, payload);
|
|
97
|
+
}
|
|
34
98
|
export class KVHandle {
|
|
35
99
|
constructor(nc, binding) {
|
|
36
100
|
Object.defineProperty(this, "binding", {
|
|
@@ -53,6 +117,53 @@ export class KVHandle {
|
|
|
53
117
|
}
|
|
54
118
|
}
|
|
55
119
|
_KVHandle_nc = new WeakMap();
|
|
120
|
+
export class StoreHandle {
|
|
121
|
+
constructor(nc, binding) {
|
|
122
|
+
Object.defineProperty(this, "binding", {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
configurable: true,
|
|
125
|
+
writable: true,
|
|
126
|
+
value: void 0
|
|
127
|
+
});
|
|
128
|
+
_StoreHandle_nc.set(this, void 0);
|
|
129
|
+
__classPrivateFieldSet(this, _StoreHandle_nc, nc, "f");
|
|
130
|
+
this.binding = binding;
|
|
131
|
+
}
|
|
132
|
+
open() {
|
|
133
|
+
return TypedStore.open(__classPrivateFieldGet(this, _StoreHandle_nc, "f"), this.binding.name, {
|
|
134
|
+
ttlMs: this.binding.ttlMs,
|
|
135
|
+
maxObjectBytes: this.binding.maxObjectBytes,
|
|
136
|
+
maxTotalBytes: this.binding.maxTotalBytes,
|
|
137
|
+
bindOnly: true,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
_StoreHandle_nc = new WeakMap();
|
|
142
|
+
async function createConnectedService(args) {
|
|
143
|
+
const runtimeApi = (args.server.trellisApi ?? args.server.api);
|
|
144
|
+
const server = TrellisServer.create(args.name, args.nc, { sessionKey: args.auth.sessionKey, sign: args.auth.sign }, {
|
|
145
|
+
log: args.server.log,
|
|
146
|
+
timeout: args.server.timeout,
|
|
147
|
+
stream: args.server.stream,
|
|
148
|
+
noResponderRetry: args.server.noResponderRetry,
|
|
149
|
+
api: runtimeApi,
|
|
150
|
+
version: args.server.version,
|
|
151
|
+
});
|
|
152
|
+
const outbound = new Trellis(args.name, args.nc, { sessionKey: args.auth.sessionKey, sign: args.auth.sign }, {
|
|
153
|
+
log: args.server.log,
|
|
154
|
+
timeout: args.server.timeout,
|
|
155
|
+
stream: args.server.stream,
|
|
156
|
+
noResponderRetry: args.server.noResponderRetry,
|
|
157
|
+
api: runtimeApi,
|
|
158
|
+
});
|
|
159
|
+
const trellis = Object.assign(outbound, {
|
|
160
|
+
mount: server.mount.bind(server),
|
|
161
|
+
});
|
|
162
|
+
await mountStandardHealthRpc(server, {
|
|
163
|
+
checks: args.server.healthChecks,
|
|
164
|
+
});
|
|
165
|
+
return new TrellisService(args.name, args.auth, args.nc, server, trellis, args.bindings);
|
|
166
|
+
}
|
|
56
167
|
export class TrellisService {
|
|
57
168
|
constructor(name, auth, nc, server, trellis, bindings) {
|
|
58
169
|
Object.defineProperty(this, "name", {
|
|
@@ -91,12 +202,24 @@ export class TrellisService {
|
|
|
91
202
|
writable: true,
|
|
92
203
|
value: void 0
|
|
93
204
|
});
|
|
205
|
+
Object.defineProperty(this, "transfer", {
|
|
206
|
+
enumerable: true,
|
|
207
|
+
configurable: true,
|
|
208
|
+
writable: true,
|
|
209
|
+
value: void 0
|
|
210
|
+
});
|
|
94
211
|
Object.defineProperty(this, "kv", {
|
|
95
212
|
enumerable: true,
|
|
96
213
|
configurable: true,
|
|
97
214
|
writable: true,
|
|
98
215
|
value: void 0
|
|
99
216
|
});
|
|
217
|
+
Object.defineProperty(this, "store", {
|
|
218
|
+
enumerable: true,
|
|
219
|
+
configurable: true,
|
|
220
|
+
writable: true,
|
|
221
|
+
value: void 0
|
|
222
|
+
});
|
|
100
223
|
Object.defineProperty(this, "streams", {
|
|
101
224
|
enumerable: true,
|
|
102
225
|
configurable: true,
|
|
@@ -116,10 +239,48 @@ export class TrellisService {
|
|
|
116
239
|
this.operations = server.operations;
|
|
117
240
|
this.trellis = trellis;
|
|
118
241
|
this.kv = Object.fromEntries(Object.entries(bindings.kv).map(([alias, binding]) => [alias, new KVHandle(nc, binding)]));
|
|
242
|
+
this.store = Object.fromEntries(Object.entries(bindings.store).map(([alias, binding]) => [alias, new StoreHandle(nc, binding)]));
|
|
243
|
+
this.transfer = new ServiceTransfer({
|
|
244
|
+
name,
|
|
245
|
+
nc,
|
|
246
|
+
auth,
|
|
247
|
+
stores: this.store,
|
|
248
|
+
});
|
|
119
249
|
this.streams = bindings.streams;
|
|
120
250
|
this.jobs = bindings.jobs;
|
|
121
251
|
}
|
|
122
|
-
static async connect(
|
|
252
|
+
static async connect(args, deps) {
|
|
253
|
+
const runtimeDeps = {
|
|
254
|
+
...(await loadDefaultServiceRuntimeDeps()),
|
|
255
|
+
...deps,
|
|
256
|
+
};
|
|
257
|
+
const auth = await createAuth({ sessionKeySeed: args.sessionKeySeed });
|
|
258
|
+
const bootstrap = await fetchServiceBootstrapInfo({
|
|
259
|
+
trellisUrl: args.trellisUrl,
|
|
260
|
+
contractId: args.contract.CONTRACT_ID,
|
|
261
|
+
contractDigest: args.contract.CONTRACT_DIGEST,
|
|
262
|
+
auth,
|
|
263
|
+
});
|
|
264
|
+
const { token, inboxPrefix } = await auth.natsConnectOptions();
|
|
265
|
+
const nc = await runtimeDeps.connect({
|
|
266
|
+
servers: bootstrap.connectInfo.transport.natsServers,
|
|
267
|
+
token,
|
|
268
|
+
inboxPrefix,
|
|
269
|
+
authenticator: jwtAuthenticator(bootstrap.connectInfo.transport.sentinel.jwt, new TextEncoder().encode(bootstrap.connectInfo.transport.sentinel.seed)),
|
|
270
|
+
});
|
|
271
|
+
return await createConnectedService({
|
|
272
|
+
name: args.name,
|
|
273
|
+
auth,
|
|
274
|
+
nc,
|
|
275
|
+
server: {
|
|
276
|
+
...(args.server ?? {}),
|
|
277
|
+
api: args.contract.API.owned,
|
|
278
|
+
trellisApi: args.contract.API.trellis,
|
|
279
|
+
},
|
|
280
|
+
bindings: bootstrap.binding.resources,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
static async connectInternal(name, opts, deps) {
|
|
123
284
|
const connectFn = deps.connect;
|
|
124
285
|
const readFileSync = deps.readFileSync;
|
|
125
286
|
const credsAuthenticator = deps.credsAuthenticator;
|
|
@@ -154,30 +315,21 @@ export class TrellisService {
|
|
|
154
315
|
authenticator,
|
|
155
316
|
...(opts.nats.options ?? {}),
|
|
156
317
|
});
|
|
157
|
-
|
|
158
|
-
const server = TrellisServer.create(name, nc, { sessionKey: auth.sessionKey, sign: auth.sign }, {
|
|
159
|
-
log: opts.server.log,
|
|
160
|
-
timeout: opts.server.timeout,
|
|
161
|
-
stream: opts.server.stream,
|
|
162
|
-
noResponderRetry: opts.server.noResponderRetry,
|
|
163
|
-
api: runtimeApi,
|
|
164
|
-
version: opts.server.version,
|
|
165
|
-
});
|
|
166
|
-
const outbound = new Trellis(name, nc, { sessionKey: auth.sessionKey, sign: auth.sign }, {
|
|
167
|
-
log: opts.server.log,
|
|
168
|
-
timeout: opts.server.timeout,
|
|
169
|
-
stream: opts.server.stream,
|
|
170
|
-
noResponderRetry: opts.server.noResponderRetry,
|
|
171
|
-
api: runtimeApi,
|
|
172
|
-
});
|
|
173
|
-
const trellis = Object.assign(outbound, {
|
|
174
|
-
mount: server.mount.bind(server),
|
|
175
|
-
});
|
|
176
|
-
await mountStandardHealthRpc(server, {
|
|
177
|
-
checks: opts.server.healthChecks,
|
|
178
|
-
});
|
|
179
|
-
let bindings = { kv: {}, streams: {} };
|
|
318
|
+
let bindings = { kv: {}, store: {}, streams: {} };
|
|
180
319
|
if (opts.contractId && opts.contractDigest) {
|
|
320
|
+
const runtimeApi = (opts.server.trellisApi ?? opts.server.api);
|
|
321
|
+
const outbound = new Trellis(name, nc, { sessionKey: auth.sessionKey, sign: auth.sign }, {
|
|
322
|
+
log: opts.server.log,
|
|
323
|
+
timeout: opts.server.timeout,
|
|
324
|
+
stream: opts.server.stream,
|
|
325
|
+
noResponderRetry: opts.server.noResponderRetry,
|
|
326
|
+
api: runtimeApi,
|
|
327
|
+
});
|
|
328
|
+
const trellis = Object.assign(outbound, {
|
|
329
|
+
mount: () => {
|
|
330
|
+
throw new Error("mount is unavailable during internal bootstrap probing");
|
|
331
|
+
},
|
|
332
|
+
});
|
|
181
333
|
const bootstrapRequest = trellis.request.bind(trellis);
|
|
182
334
|
const catalogResult = await bootstrapRequest("Trellis.Catalog", {});
|
|
183
335
|
const catalogValue = catalogResult.take();
|
|
@@ -222,13 +374,21 @@ export class TrellisService {
|
|
|
222
374
|
}
|
|
223
375
|
bindings = {
|
|
224
376
|
kv: resolved.binding?.resources?.kv ?? {},
|
|
377
|
+
store: resolved.binding?.resources?.store ?? {},
|
|
225
378
|
streams: resolved.binding?.resources?.streams ?? {},
|
|
226
379
|
...(resolved.binding?.resources?.jobs ? { jobs: resolved.binding.resources.jobs } : {}),
|
|
227
380
|
};
|
|
228
381
|
}
|
|
229
|
-
return
|
|
382
|
+
return await createConnectedService({
|
|
383
|
+
name,
|
|
384
|
+
auth,
|
|
385
|
+
nc,
|
|
386
|
+
server: opts.server,
|
|
387
|
+
bindings,
|
|
388
|
+
});
|
|
230
389
|
}
|
|
231
390
|
async stop() {
|
|
391
|
+
await this.transfer.stop();
|
|
232
392
|
await this.server.stop();
|
|
233
393
|
}
|
|
234
394
|
request(method, input, opts) {
|
|
@@ -241,16 +401,3 @@ export class TrellisService {
|
|
|
241
401
|
return this.server.operation(operation);
|
|
242
402
|
}
|
|
243
403
|
}
|
|
244
|
-
export function connectService(contract, name, opts, deps) {
|
|
245
|
-
const connectOpts = {
|
|
246
|
-
...opts,
|
|
247
|
-
contractId: contract.CONTRACT_ID,
|
|
248
|
-
contractDigest: contract.CONTRACT_DIGEST,
|
|
249
|
-
server: {
|
|
250
|
-
...opts.server,
|
|
251
|
-
api: contract.API.owned,
|
|
252
|
-
trellisApi: contract.API.trellis,
|
|
253
|
-
},
|
|
254
|
-
};
|
|
255
|
-
return TrellisService.connect(name, connectOpts, deps);
|
|
256
|
-
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Result as ResultType } from "@qlever-llc/result";
|
|
2
|
+
import { type NatsConnection } from "@nats-io/nats-core";
|
|
3
|
+
import type { TrellisAuth } from "../trellis/trellis.js";
|
|
4
|
+
import type { StoreError } from "../trellis/errors/StoreError.js";
|
|
5
|
+
import { TransferError } from "../trellis/errors/TransferError.js";
|
|
6
|
+
import { TypedStore } from "../trellis/store.js";
|
|
7
|
+
import type { DownloadTransferGrant, UploadTransferGrant } from "../trellis/transfer.js";
|
|
8
|
+
export type TransferStoreHandle = {
|
|
9
|
+
open(): Promise<ResultType<TypedStore, StoreError>>;
|
|
10
|
+
};
|
|
11
|
+
export type InitiateUploadArgs = {
|
|
12
|
+
sessionKey: string;
|
|
13
|
+
store: string;
|
|
14
|
+
key: string;
|
|
15
|
+
expiresInMs: number;
|
|
16
|
+
maxBytes?: number;
|
|
17
|
+
contentType?: string;
|
|
18
|
+
metadata?: Record<string, string>;
|
|
19
|
+
};
|
|
20
|
+
export type InitiateDownloadArgs = {
|
|
21
|
+
sessionKey: string;
|
|
22
|
+
store: string;
|
|
23
|
+
key: string;
|
|
24
|
+
expiresInMs: number;
|
|
25
|
+
};
|
|
26
|
+
type ServiceTransferOpts = {
|
|
27
|
+
name: string;
|
|
28
|
+
nc: NatsConnection;
|
|
29
|
+
auth: TrellisAuth;
|
|
30
|
+
stores: Record<string, TransferStoreHandle>;
|
|
31
|
+
chunkBytes?: number;
|
|
32
|
+
};
|
|
33
|
+
export declare class ServiceTransfer {
|
|
34
|
+
#private;
|
|
35
|
+
constructor(opts: ServiceTransferOpts);
|
|
36
|
+
initiateUpload(args: InitiateUploadArgs): Promise<ResultType<UploadTransferGrant, TransferError>>;
|
|
37
|
+
initiateDownload(args: InitiateDownloadArgs): Promise<ResultType<DownloadTransferGrant, TransferError>>;
|
|
38
|
+
stop(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=transfer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer.d.ts","sourceRoot":"","sources":["../../src/server/transfer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,MAAM,IAAI,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAoC,KAAK,cAAc,EAAqB,MAAM,oBAAoB,CAAC;AAG9G,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAkB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EACV,qBAAqB,EAErB,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAShC,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;CACrD,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,cAAc,CAAC;IACnB,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAoJF,qBAAa,eAAe;;gBASd,IAAI,EAAE,mBAAmB;IAQ/B,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC,mBAAmB,EAAE,aAAa,CAAC,CAAC;IAsDjG,gBAAgB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC,qBAAqB,EAAE,aAAa,CAAC,CAAC;IA8CvG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAiN5B"}
|