@oatscenter/trellis 0.100.0-rc.1

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 (264) hide show
  1. package/README.md +59 -0
  2. package/auth/authorization/client_context.d.ts +61 -0
  3. package/auth/authorization/client_context.js +266 -0
  4. package/auth/authorization/nats_registry.d.ts +41 -0
  5. package/auth/authorization/nats_registry.js +283 -0
  6. package/auth/authorization/provider_cache.d.ts +90 -0
  7. package/auth/authorization/provider_cache.js +783 -0
  8. package/auth/authorization/refresh.d.ts +46 -0
  9. package/auth/authorization/refresh.js +246 -0
  10. package/auth/authorization/types.d.ts +207 -0
  11. package/auth/authorization/types.js +60 -0
  12. package/auth/authorization_context.d.ts +11 -0
  13. package/auth/authorization_context.js +10 -0
  14. package/auth/browser/flow_types.d.ts +84 -0
  15. package/auth/browser/flow_types.js +70 -0
  16. package/auth/browser/portal.d.ts +21 -0
  17. package/auth/browser/portal.js +307 -0
  18. package/auth/browser/storage.d.ts +26 -0
  19. package/auth/browser/storage.js +224 -0
  20. package/auth/browser.d.ts +11 -0
  21. package/auth/browser.js +10 -0
  22. package/auth/browser_recovery.d.ts +13 -0
  23. package/auth/browser_recovery.js +38 -0
  24. package/auth/device_activation.d.ts +134 -0
  25. package/auth/device_activation.js +376 -0
  26. package/auth/http_error.d.ts +12 -0
  27. package/auth/http_error.js +32 -0
  28. package/auth/keys.d.ts +5 -0
  29. package/auth/keys.js +63 -0
  30. package/auth/mod.d.ts +16 -0
  31. package/auth/mod.js +16 -0
  32. package/auth/proof.d.ts +31 -0
  33. package/auth/proof.js +95 -0
  34. package/auth/protocol_wasm/trellis_protocol_wasm.d.ts +138 -0
  35. package/auth/protocol_wasm/trellis_protocol_wasm.js +605 -0
  36. package/auth/protocol_wasm/trellis_protocol_wasm_bg.wasm +0 -0
  37. package/auth/protocol_wasm/trellis_protocol_wasm_bytes.d.ts +1 -0
  38. package/auth/protocol_wasm/trellis_protocol_wasm_bytes.js +2 -0
  39. package/auth/protocol_wasm.d.ts +179 -0
  40. package/auth/protocol_wasm.js +133 -0
  41. package/auth/session_auth.d.ts +30 -0
  42. package/auth/session_auth.js +77 -0
  43. package/auth/session_proof.d.ts +53 -0
  44. package/auth/session_proof.js +43 -0
  45. package/auth/time.d.ts +6 -0
  46. package/auth/time.js +7 -0
  47. package/auth/trellis_id.d.ts +1 -0
  48. package/auth/trellis_id.js +5 -0
  49. package/auth/utils.d.ts +10 -0
  50. package/auth/utils.js +69 -0
  51. package/auth.d.ts +1 -0
  52. package/auth.js +1 -0
  53. package/caller.d.ts +111 -0
  54. package/caller.js +85 -0
  55. package/client.d.ts +14 -0
  56. package/client.js +1 -0
  57. package/client_connect.d.ts +143 -0
  58. package/client_connect.js +1097 -0
  59. package/codec.d.ts +13 -0
  60. package/codec.js +192 -0
  61. package/connection.d.ts +107 -0
  62. package/connection.js +396 -0
  63. package/device/activation.d.ts +42 -0
  64. package/device/activation.js +319 -0
  65. package/device.d.ts +80 -0
  66. package/device.js +687 -0
  67. package/env.d.ts +2 -0
  68. package/env.js +10 -0
  69. package/errors/AuthError.d.ts +30 -0
  70. package/errors/AuthError.js +34 -0
  71. package/errors/KVError.d.ts +30 -0
  72. package/errors/KVError.js +36 -0
  73. package/errors/OperationLifecycleError.d.ts +110 -0
  74. package/errors/OperationLifecycleError.js +142 -0
  75. package/errors/RemoteError.d.ts +61 -0
  76. package/errors/RemoteError.js +72 -0
  77. package/errors/SchemaValidationError.d.ts +48 -0
  78. package/errors/SchemaValidationError.js +49 -0
  79. package/errors/StoreError.d.ts +21 -0
  80. package/errors/StoreError.js +31 -0
  81. package/errors/TransferError.d.ts +21 -0
  82. package/errors/TransferError.js +31 -0
  83. package/errors/TransportError.d.ts +29 -0
  84. package/errors/TransportError.js +33 -0
  85. package/errors/TrellisError.d.ts +15 -0
  86. package/errors/TrellisError.js +15 -0
  87. package/errors/ValidationError.d.ts +50 -0
  88. package/errors/ValidationError.js +59 -0
  89. package/errors/index.d.ts +254 -0
  90. package/errors/index.js +238 -0
  91. package/generated.d.ts +4 -0
  92. package/generated.js +3 -0
  93. package/generated_support.d.ts +120 -0
  94. package/generated_support.js +359 -0
  95. package/globals.d.ts +9 -0
  96. package/globals.js +16 -0
  97. package/health_transport.d.ts +18 -0
  98. package/health_transport.js +32 -0
  99. package/helpers.d.ts +11 -0
  100. package/helpers.js +53 -0
  101. package/index.d.ts +2 -0
  102. package/index.js +2 -0
  103. package/internal_sdk/generated/apis/auth/mod.d.ts +805 -0
  104. package/internal_sdk/generated/apis/auth/mod.js +958 -0
  105. package/internal_sdk/generated/apis/core/mod.d.ts +79 -0
  106. package/internal_sdk/generated/apis/core/mod.js +93 -0
  107. package/internal_sdk/generated/apis/events/mod.d.ts +224 -0
  108. package/internal_sdk/generated/apis/events/mod.js +313 -0
  109. package/internal_sdk/generated/apis/health/mod.d.ts +106 -0
  110. package/internal_sdk/generated/apis/health/mod.js +132 -0
  111. package/internal_sdk/generated/apis/index.d.ts +7 -0
  112. package/internal_sdk/generated/apis/index.js +8 -0
  113. package/internal_sdk/generated/apis/jobs/mod.d.ts +176 -0
  114. package/internal_sdk/generated/apis/jobs/mod.js +209 -0
  115. package/internal_sdk/generated/apis/state/mod.d.ts +104 -0
  116. package/internal_sdk/generated/apis/state/mod.js +139 -0
  117. package/internal_sdk/generated/index.d.ts +4 -0
  118. package/internal_sdk/generated/index.js +5 -0
  119. package/internal_sdk/generated/package.json +18 -0
  120. package/internal_sdk/generated/participants/cli/mod.d.ts +402 -0
  121. package/internal_sdk/generated/participants/cli/mod.js +460 -0
  122. package/internal_sdk/generated/participants/cli/types.d.ts +2 -0
  123. package/internal_sdk/generated/participants/cli/types.js +3 -0
  124. package/internal_sdk/generated/participants/console/mod.d.ts +489 -0
  125. package/internal_sdk/generated/participants/console/mod.js +579 -0
  126. package/internal_sdk/generated/participants/console/types.d.ts +2 -0
  127. package/internal_sdk/generated/participants/console/types.js +3 -0
  128. package/internal_sdk/generated/participants/eventsRuntime/mod.d.ts +64 -0
  129. package/internal_sdk/generated/participants/eventsRuntime/mod.js +42 -0
  130. package/internal_sdk/generated/participants/eventsRuntime/types.d.ts +2 -0
  131. package/internal_sdk/generated/participants/eventsRuntime/types.js +3 -0
  132. package/internal_sdk/generated/participants/healthRuntime/mod.d.ts +58 -0
  133. package/internal_sdk/generated/participants/healthRuntime/mod.js +36 -0
  134. package/internal_sdk/generated/participants/healthRuntime/types.d.ts +2 -0
  135. package/internal_sdk/generated/participants/healthRuntime/types.js +3 -0
  136. package/internal_sdk/generated/participants/index.d.ts +8 -0
  137. package/internal_sdk/generated/participants/index.js +9 -0
  138. package/internal_sdk/generated/participants/jobsRuntime/mod.d.ts +64 -0
  139. package/internal_sdk/generated/participants/jobsRuntime/mod.js +42 -0
  140. package/internal_sdk/generated/participants/jobsRuntime/types.d.ts +2 -0
  141. package/internal_sdk/generated/participants/jobsRuntime/types.js +3 -0
  142. package/internal_sdk/generated/participants/platform/mod.d.ts +164 -0
  143. package/internal_sdk/generated/participants/platform/mod.js +149 -0
  144. package/internal_sdk/generated/participants/platform/types.d.ts +7 -0
  145. package/internal_sdk/generated/participants/platform/types.js +5 -0
  146. package/internal_sdk/generated/participants/portal/mod.d.ts +131 -0
  147. package/internal_sdk/generated/participants/portal/mod.js +109 -0
  148. package/internal_sdk/generated/participants/portal/types.d.ts +2 -0
  149. package/internal_sdk/generated/participants/portal/types.js +3 -0
  150. package/internal_sdk/generated/types/_internal/p0.d.ts +13511 -0
  151. package/internal_sdk/generated/types/_internal/p0.js +6105 -0
  152. package/internal_sdk/generated/types/index.d.ts +2951 -0
  153. package/internal_sdk/generated/types/index.js +1477 -0
  154. package/jobs.d.ts +309 -0
  155. package/jobs.js +389 -0
  156. package/kv.d.ts +85 -0
  157. package/kv.js +330 -0
  158. package/operations.d.ts +189 -0
  159. package/operations.js +847 -0
  160. package/package.json +73 -0
  161. package/pagination.d.ts +25 -0
  162. package/pagination.js +117 -0
  163. package/participant.d.ts +6 -0
  164. package/participant.js +6 -0
  165. package/participant_runtime/api.d.ts +131 -0
  166. package/participant_runtime/api.js +42 -0
  167. package/participant_runtime/json.d.ts +16 -0
  168. package/participant_runtime/json.js +193 -0
  169. package/participant_runtime/metadata.d.ts +34 -0
  170. package/participant_runtime/metadata.js +4 -0
  171. package/participant_runtime/participant.d.ts +200 -0
  172. package/participant_runtime/participant.js +330 -0
  173. package/participant_runtime/schemas.d.ts +347 -0
  174. package/participant_runtime/schemas.js +211 -0
  175. package/participant_runtime/surface_names.d.ts +16 -0
  176. package/participant_runtime/surface_names.js +34 -0
  177. package/portable.d.ts +30 -0
  178. package/portable.js +14 -0
  179. package/provider.d.ts +69 -0
  180. package/provider.js +68 -0
  181. package/runtime_transport.d.ts +25 -0
  182. package/runtime_transport.js +48 -0
  183. package/service/mod.d.ts +14 -0
  184. package/service/mod.js +13 -0
  185. package/service/outbox_inbox.d.ts +259 -0
  186. package/service/outbox_inbox.js +908 -0
  187. package/service/runtime/bootstrap.d.ts +56 -0
  188. package/service/runtime/bootstrap.js +226 -0
  189. package/service/runtime/core.d.ts +46 -0
  190. package/service/runtime/core.js +1747 -0
  191. package/service/runtime/health.d.ts +97 -0
  192. package/service/runtime/health.js +153 -0
  193. package/service/runtime/health_schemas.d.ts +23 -0
  194. package/service/runtime/health_schemas.js +20 -0
  195. package/service/runtime/internal_jobs/active-job.d.ts +40 -0
  196. package/service/runtime/internal_jobs/active-job.js +91 -0
  197. package/service/runtime/internal_jobs/bindings.d.ts +40 -0
  198. package/service/runtime/internal_jobs/bindings.js +1 -0
  199. package/service/runtime/internal_jobs/cancellation-registry.d.ts +13 -0
  200. package/service/runtime/internal_jobs/cancellation-registry.js +55 -0
  201. package/service/runtime/internal_jobs/heartbeat.d.ts +33 -0
  202. package/service/runtime/internal_jobs/heartbeat.js +65 -0
  203. package/service/runtime/internal_jobs/job-manager.d.ts +126 -0
  204. package/service/runtime/internal_jobs/job-manager.js +821 -0
  205. package/service/runtime/internal_jobs/key-coordinator.d.ts +280 -0
  206. package/service/runtime/internal_jobs/key-coordinator.js +747 -0
  207. package/service/runtime/internal_jobs/projection.d.ts +3 -0
  208. package/service/runtime/internal_jobs/projection.js +42 -0
  209. package/service/runtime/internal_jobs/runtime-worker.d.ts +126 -0
  210. package/service/runtime/internal_jobs/runtime-worker.js +454 -0
  211. package/service/runtime/internal_jobs/types.d.ts +246 -0
  212. package/service/runtime/internal_jobs/types.js +163 -0
  213. package/service/runtime/logger.d.ts +2 -0
  214. package/service/runtime/logger.js +7 -0
  215. package/service/runtime/runtime.d.ts +16 -0
  216. package/service/runtime/runtime.js +1 -0
  217. package/service/runtime/service.d.ts +372 -0
  218. package/service/runtime/service.js +1896 -0
  219. package/service/runtime/transfer/download.d.ts +27 -0
  220. package/service/runtime/transfer/download.js +1 -0
  221. package/service/runtime/transfer/protocol.d.ts +15 -0
  222. package/service/runtime/transfer/protocol.js +46 -0
  223. package/service/runtime/transfer/queue.d.ts +18 -0
  224. package/service/runtime/transfer/queue.js +136 -0
  225. package/service/runtime/transfer/upload.d.ts +40 -0
  226. package/service/runtime/transfer/upload.js +27 -0
  227. package/service/runtime/transfer.d.ts +62 -0
  228. package/service/runtime/transfer.js +763 -0
  229. package/session.d.ts +862 -0
  230. package/session.js +3407 -0
  231. package/store.d.ts +71 -0
  232. package/store.js +412 -0
  233. package/store_entry.d.ts +20 -0
  234. package/store_entry.js +75 -0
  235. package/tasks.d.ts +10 -0
  236. package/tasks.js +28 -0
  237. package/telemetry/carrier.d.ts +8 -0
  238. package/telemetry/carrier.js +20 -0
  239. package/telemetry/core.d.ts +7 -0
  240. package/telemetry/core.js +14 -0
  241. package/telemetry/env.d.ts +2 -0
  242. package/telemetry/env.js +10 -0
  243. package/telemetry/init.d.ts +2 -0
  244. package/telemetry/init.js +7 -0
  245. package/telemetry/metrics.d.ts +81 -0
  246. package/telemetry/metrics.js +267 -0
  247. package/telemetry/mod.d.ts +13 -0
  248. package/telemetry/mod.js +8 -0
  249. package/telemetry/nats.d.ts +6 -0
  250. package/telemetry/nats.js +6 -0
  251. package/telemetry/result.d.ts +1 -0
  252. package/telemetry/result.js +18 -0
  253. package/telemetry/runtime.d.ts +1 -0
  254. package/telemetry/runtime.js +141 -0
  255. package/telemetry/trace.d.ts +4 -0
  256. package/telemetry/trace.js +26 -0
  257. package/telemetry/trellis.d.ts +1 -0
  258. package/telemetry/trellis.js +1 -0
  259. package/telemetry.d.ts +1 -0
  260. package/telemetry.js +1 -0
  261. package/transfer.d.ts +112 -0
  262. package/transfer.js +525 -0
  263. package/transfer_protocol.d.ts +1 -0
  264. package/transfer_protocol.js +13 -0
package/codec.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { type InferSchemaType, type SchemaLike } from "./participant.ts";
2
+ import { Result } from "@oatscenter/result";
3
+ import type { StaticDecode, TSchema } from "typebox";
4
+ import { SchemaValidationError, UnexpectedError, ValidationError } from "./errors/index.ts";
5
+ export type JsonValue = string | number | boolean | null | JsonValue[] | {
6
+ [key: string]: JsonValue;
7
+ };
8
+ export declare function parse<T extends TSchema>(schema: T, data: JsonValue): Result<StaticDecode<T>, SchemaValidationError | ValidationError | UnexpectedError>;
9
+ export declare function parseSchema<S extends SchemaLike>(schema: S, data: JsonValue): Result<InferSchemaType<S>, SchemaValidationError | ValidationError | UnexpectedError>;
10
+ /** Parses unknown JSON-compatible data with an arbitrary Trellis schema. */
11
+ export declare function parseUnknownSchema(schema: SchemaLike, data: JsonValue): Result<unknown, SchemaValidationError | ValidationError | UnexpectedError>;
12
+ export declare function encode<T extends TSchema>(schema: T, data: unknown): Result<string, SchemaValidationError | ValidationError | UnexpectedError>;
13
+ export declare function encodeSchema(schema: SchemaLike, data: unknown): Result<string, SchemaValidationError | ValidationError | UnexpectedError>;
package/codec.js ADDED
@@ -0,0 +1,192 @@
1
+ import { unwrapSchema, } from "./participant.js";
2
+ import { Result } from "@oatscenter/result";
3
+ import { EncodeError, ParseError, Value } from "typebox/value";
4
+ import { SchemaValidationError, UnexpectedError, ValidationError, } from "./errors/index.js";
5
+ const X_TRELLIS_VALIDATION = "x-trellis-validation";
6
+ function readTrellisValidationExtension(schema) {
7
+ if (schema === null || schema === undefined || typeof schema !== "object") {
8
+ return undefined;
9
+ }
10
+ const ext = schema[X_TRELLIS_VALIDATION];
11
+ if (ext === null || ext === undefined || typeof ext !== "object") {
12
+ return undefined;
13
+ }
14
+ return ext;
15
+ }
16
+ function resolveSchemaNode(root, schemaPath) {
17
+ if (!schemaPath.startsWith("#/")) {
18
+ if (schemaPath === "#")
19
+ return root;
20
+ return undefined;
21
+ }
22
+ const parts = schemaPath.slice(2).split("/").map(decodeURIComponent);
23
+ let current = root;
24
+ for (const part of parts) {
25
+ if (current === null || current === undefined || typeof current !== "object") {
26
+ return undefined;
27
+ }
28
+ current = current[part];
29
+ }
30
+ return current;
31
+ }
32
+ function resolveRequiredErrorNode(root, error) {
33
+ const params = error.params;
34
+ const missingProperty = (params?.missingProperty ??
35
+ params?.requiredProperties?.[0]);
36
+ if (!missingProperty)
37
+ return undefined;
38
+ const objNode = resolveSchemaNode(root, error.schemaPath);
39
+ if (!objNode || typeof objNode !== "object")
40
+ return undefined;
41
+ const properties = objNode.properties;
42
+ if (!properties || typeof properties !== "object")
43
+ return undefined;
44
+ return properties[missingProperty];
45
+ }
46
+ const ALLOWED_HINT_KEYWORDS = new Set([
47
+ "required",
48
+ "minItems",
49
+ "maxItems",
50
+ "minLength",
51
+ "maxLength",
52
+ "minimum",
53
+ "maximum",
54
+ "exclusiveMinimum",
55
+ "exclusiveMaximum",
56
+ "pattern",
57
+ "format",
58
+ "enum",
59
+ "const",
60
+ ]);
61
+ function keywordAllowsHint(keyword) {
62
+ return ALLOWED_HINT_KEYWORDS.has(keyword);
63
+ }
64
+ function typeboxIssueToPath(error) {
65
+ if (error.keyword === "required") {
66
+ const params = error.params;
67
+ const missingProperty = (params?.missingProperty ??
68
+ params?.requiredProperties?.[0]);
69
+ if (missingProperty) {
70
+ return error.instancePath
71
+ ? `${error.instancePath}/${missingProperty}`
72
+ : `/${missingProperty}`;
73
+ }
74
+ }
75
+ return error.instancePath || error.schemaPath;
76
+ }
77
+ function collectValidationIssues(root, errors) {
78
+ const annotated = [];
79
+ const unannotated = [];
80
+ for (const error of [...errors]) {
81
+ const schemaNode = error.keyword === "required"
82
+ ? resolveRequiredErrorNode(root, error)
83
+ : resolveSchemaNode(root, error.schemaPath);
84
+ const extension = schemaNode !== undefined
85
+ ? readTrellisValidationExtension(schemaNode)
86
+ : undefined;
87
+ if (extension !== undefined &&
88
+ keywordAllowsHint(error.keyword) &&
89
+ extension.issues?.[error.keyword] !== undefined) {
90
+ const hint = extension.issues[error.keyword];
91
+ if (hint.code !== undefined) {
92
+ annotated.push({
93
+ path: typeboxIssueToPath(error),
94
+ schemaPath: error.schemaPath,
95
+ keyword: error.keyword,
96
+ code: hint.code,
97
+ message: hint.message || error.message,
98
+ label: hint.label ?? extension.label,
99
+ note: hint.note ?? extension.note,
100
+ i18nKey: hint.i18nKey,
101
+ severity: hint.severity ?? "error",
102
+ params: error.params,
103
+ });
104
+ continue;
105
+ }
106
+ }
107
+ unannotated.push(error);
108
+ }
109
+ return { annotated, unannotated };
110
+ }
111
+ function buildValidationError(schema, data, errors, cause) {
112
+ const { annotated, unannotated } = collectValidationIssues(schema, errors);
113
+ if (annotated.length > 0 && unannotated.length === 0) {
114
+ return new SchemaValidationError({ issues: annotated, cause });
115
+ }
116
+ return new ValidationError({
117
+ errors: unannotated.length > 0
118
+ ? unannotated
119
+ : annotated.map((i) => ({ path: i.path, message: i.message })),
120
+ cause,
121
+ });
122
+ }
123
+ function parseWithSchema(schema, data) {
124
+ return Value.Parse(schema, data);
125
+ }
126
+ function encodeWithSchema(schema, data) {
127
+ return JSON.stringify(Value.Encode(schema, data), (_key, value) => typeof value === "bigint" ? value.toString() : value);
128
+ }
129
+ export function parse(schema, data) {
130
+ try {
131
+ return Result.ok(parseWithSchema(schema, data));
132
+ }
133
+ catch (cause) {
134
+ if (cause instanceof ParseError) {
135
+ const errors = Value.Errors(schema, data);
136
+ return Result.err(buildValidationError(schema, data, errors, cause));
137
+ }
138
+ return Result.err(new UnexpectedError({ cause }));
139
+ }
140
+ }
141
+ export function parseSchema(schema, data) {
142
+ const raw = unwrapSchema(schema);
143
+ try {
144
+ return Result.ok(parseWithSchema(raw, data));
145
+ }
146
+ catch (cause) {
147
+ if (cause instanceof ParseError) {
148
+ const errors = Value.Errors(raw, data);
149
+ return Result.err(buildValidationError(raw, data, errors, cause));
150
+ }
151
+ return Result.err(new UnexpectedError({ cause }));
152
+ }
153
+ }
154
+ /** Parses unknown JSON-compatible data with an arbitrary Trellis schema. */
155
+ export function parseUnknownSchema(schema, data) {
156
+ const raw = unwrapSchema(schema);
157
+ try {
158
+ return Result.ok(parseWithSchema(raw, data));
159
+ }
160
+ catch (cause) {
161
+ if (cause instanceof ParseError) {
162
+ const errors = Value.Errors(raw, data);
163
+ return Result.err(buildValidationError(raw, data, errors, cause));
164
+ }
165
+ return Result.err(new UnexpectedError({ cause }));
166
+ }
167
+ }
168
+ export function encode(schema, data) {
169
+ try {
170
+ return Result.ok(encodeWithSchema(schema, data));
171
+ }
172
+ catch (cause) {
173
+ if (cause instanceof EncodeError) {
174
+ const errors = Value.Errors(schema, data);
175
+ return Result.err(buildValidationError(schema, data, errors, cause));
176
+ }
177
+ return Result.err(new UnexpectedError({ cause }));
178
+ }
179
+ }
180
+ export function encodeSchema(schema, data) {
181
+ const raw = unwrapSchema(schema);
182
+ try {
183
+ return Result.ok(encodeWithSchema(raw, data));
184
+ }
185
+ catch (cause) {
186
+ if (cause instanceof EncodeError) {
187
+ const errors = Value.Errors(raw, data);
188
+ return Result.err(buildValidationError(raw, data, errors, cause));
189
+ }
190
+ return Result.err(new UnexpectedError({ cause }));
191
+ }
192
+ }
@@ -0,0 +1,107 @@
1
+ import type { NatsConnection } from "@nats-io/nats-core";
2
+ import { type LoggerLike } from "./globals.ts";
3
+ /** Identifies the Trellis runtime that owns a connection. */
4
+ export type TrellisConnectionKind = "client" | "device" | "service";
5
+ /** Framework-neutral lifecycle phase for an observed Trellis transport. */
6
+ export type TrellisConnectionPhase = "connected" | "disconnected" | "reconnecting" | "error" | "closed";
7
+ /** Diagnostic metadata copied from the underlying transport without exposing raw handles. */
8
+ export type TrellisConnectionTransportMetadata = {
9
+ readonly name?: string;
10
+ readonly event?: string;
11
+ readonly server?: string;
12
+ readonly data?: unknown;
13
+ readonly error?: unknown;
14
+ };
15
+ /** Current framework-neutral connection status. */
16
+ export type TrellisConnectionStatus = {
17
+ readonly kind: TrellisConnectionKind;
18
+ readonly phase: TrellisConnectionPhase;
19
+ readonly observedAt: Date;
20
+ readonly transport?: TrellisConnectionTransportMetadata;
21
+ };
22
+ /** Receives connection status changes. */
23
+ export type TrellisConnectionStatusListener = (status: TrellisConnectionStatus) => void;
24
+ /** Narrow transport shape used by Trellis connection lifecycle observation. */
25
+ export type TrellisConnectionStatusTransport = {
26
+ status?: () => AsyncIterable<unknown>;
27
+ closed: () => Promise<void | Error>;
28
+ close: () => Promise<void>;
29
+ isClosed?: () => boolean;
30
+ getServer?: () => string | undefined;
31
+ };
32
+ /** Options for constructing a manually controlled Trellis connection lifecycle. */
33
+ export type TrellisConnectionOptions = {
34
+ kind: TrellisConnectionKind;
35
+ initialStatus?: TrellisConnectionStatus;
36
+ availability?: TrellisAvailability;
37
+ close?: () => Promise<void>;
38
+ stopObserving?: () => void | Promise<void>;
39
+ log?: LoggerLike | false;
40
+ };
41
+ /** Options for observing a transport-backed Trellis connection lifecycle. */
42
+ export type ObserveTrellisConnectionOptions = {
43
+ kind: TrellisConnectionKind;
44
+ transport: TrellisConnectionStatusTransport;
45
+ transportName?: string;
46
+ log?: LoggerLike | false;
47
+ lifecycleLog?: TrellisConnectionLifecycleLogOptions;
48
+ availability?: TrellisAvailability;
49
+ onTransportEvent?: (event: unknown) => void;
50
+ };
51
+ /** Options for observing a NATS-backed Trellis connection lifecycle. */
52
+ export type ObserveNatsTrellisConnectionOptions = {
53
+ kind: TrellisConnectionKind;
54
+ nc: NatsConnection;
55
+ log?: LoggerLike | false;
56
+ lifecycleLog?: TrellisConnectionLifecycleLogOptions;
57
+ availability?: TrellisAvailability;
58
+ onTransportEvent?: (event: unknown) => void;
59
+ };
60
+ /** Options for logging transport lifecycle events with Trellis runtime context. */
61
+ export type TrellisConnectionLifecycleLogOptions = {
62
+ log: LoggerLike;
63
+ context: Record<string, unknown>;
64
+ };
65
+ /** Immutable installed availability for optional participant surfaces. */
66
+ export type TrellisAvailability = Readonly<{
67
+ capabilities: Readonly<Record<string, boolean>>;
68
+ resources: Readonly<Record<string, boolean>>;
69
+ }>;
70
+ declare const installAvailability: unique symbol;
71
+ /**
72
+ * Framework-neutral Trellis connection lifecycle handle.
73
+ *
74
+ * The class stores the latest transport-neutral status, delivers it immediately
75
+ * to subscribers, and owns lifecycle cleanup without exposing raw transport
76
+ * handles to framework adapters.
77
+ */
78
+ export declare class TrellisConnection {
79
+ #private;
80
+ /** Creates a Trellis connection lifecycle handle. */
81
+ constructor(options: TrellisConnectionOptions);
82
+ /** Returns the latest observed connection status. */
83
+ get status(): TrellisConnectionStatus;
84
+ /** Returns the current immutable installed availability snapshot. */
85
+ availability(): TrellisAvailability;
86
+ /** Yields the current availability and each subsequent installed replacement. */
87
+ watchAvailability(): AsyncIterable<TrellisAvailability>;
88
+ [installAvailability](availability: TrellisAvailability): void;
89
+ /**
90
+ * Subscribes to status changes and immediately delivers the current status.
91
+ *
92
+ * The returned function removes the listener. Calling it more than once is
93
+ * safe.
94
+ */
95
+ subscribe(listener: TrellisConnectionStatusListener): () => void;
96
+ /** Stops status observation without closing the underlying transport. */
97
+ stopObserving(): void;
98
+ /** Closes the underlying transport and publishes a terminal closed status. */
99
+ close(): Promise<void>;
100
+ /** Publishes a new status to all active listeners. */
101
+ setStatus(status: TrellisConnectionStatus): void;
102
+ }
103
+ /** Observes a narrow transport status stream as a Trellis connection lifecycle. */
104
+ export declare function observeTrellisConnection(options: ObserveTrellisConnectionOptions): TrellisConnection;
105
+ /** Observes a NATS connection without exposing the raw NATS handle publicly. */
106
+ export declare function observeNatsTrellisConnection(options: ObserveNatsTrellisConnectionOptions): TrellisConnection;
107
+ export {};