@qlever-llc/trellis 0.5.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 (118) hide show
  1. package/README.md +9 -0
  2. package/esm/_dnt.polyfills.d.ts +7 -0
  3. package/esm/_dnt.polyfills.d.ts.map +1 -0
  4. package/esm/_dnt.polyfills.js +1 -0
  5. package/esm/package.json +3 -0
  6. package/esm/trellis/browser.d.ts +11 -0
  7. package/esm/trellis/browser.d.ts.map +1 -0
  8. package/esm/trellis/browser.js +10 -0
  9. package/esm/trellis/client.d.ts +31 -0
  10. package/esm/trellis/client.d.ts.map +1 -0
  11. package/esm/trellis/client.js +13 -0
  12. package/esm/trellis/codec.d.ts +12 -0
  13. package/esm/trellis/codec.d.ts.map +1 -0
  14. package/esm/trellis/codec.js +60 -0
  15. package/esm/trellis/env.d.ts +2 -0
  16. package/esm/trellis/env.d.ts.map +1 -0
  17. package/esm/trellis/env.js +1 -0
  18. package/esm/trellis/errors/AuthError.d.ts +30 -0
  19. package/esm/trellis/errors/AuthError.d.ts.map +1 -0
  20. package/esm/trellis/errors/AuthError.js +65 -0
  21. package/esm/trellis/errors/KVError.d.ts +31 -0
  22. package/esm/trellis/errors/KVError.d.ts.map +1 -0
  23. package/esm/trellis/errors/KVError.js +46 -0
  24. package/esm/trellis/errors/RemoteError.d.ts +47 -0
  25. package/esm/trellis/errors/RemoteError.d.ts.map +1 -0
  26. package/esm/trellis/errors/RemoteError.js +80 -0
  27. package/esm/trellis/errors/TrellisError.d.ts +16 -0
  28. package/esm/trellis/errors/TrellisError.d.ts.map +1 -0
  29. package/esm/trellis/errors/TrellisError.js +15 -0
  30. package/esm/trellis/errors/ValidationError.d.ts +51 -0
  31. package/esm/trellis/errors/ValidationError.d.ts.map +1 -0
  32. package/esm/trellis/errors/ValidationError.js +77 -0
  33. package/esm/trellis/errors/index.d.ts +38 -0
  34. package/esm/trellis/errors/index.d.ts.map +1 -0
  35. package/esm/trellis/errors/index.js +26 -0
  36. package/esm/trellis/globals.d.ts +2 -0
  37. package/esm/trellis/globals.d.ts.map +1 -0
  38. package/esm/trellis/globals.js +8 -0
  39. package/esm/trellis/helpers.d.ts +12 -0
  40. package/esm/trellis/helpers.d.ts.map +1 -0
  41. package/esm/trellis/helpers.js +47 -0
  42. package/esm/trellis/index.d.ts +11 -0
  43. package/esm/trellis/index.d.ts.map +1 -0
  44. package/esm/trellis/index.js +6 -0
  45. package/esm/trellis/kv.d.ts +67 -0
  46. package/esm/trellis/kv.d.ts.map +1 -0
  47. package/esm/trellis/kv.js +326 -0
  48. package/esm/trellis/models/trellis/TrellisError.d.ts +43 -0
  49. package/esm/trellis/models/trellis/TrellisError.d.ts.map +1 -0
  50. package/esm/trellis/models/trellis/TrellisError.js +16 -0
  51. package/esm/trellis/tasks.d.ts +11 -0
  52. package/esm/trellis/tasks.d.ts.map +1 -0
  53. package/esm/trellis/tasks.js +41 -0
  54. package/esm/trellis/tracing.d.ts +5 -0
  55. package/esm/trellis/tracing.d.ts.map +1 -0
  56. package/esm/trellis/tracing.js +7 -0
  57. package/esm/trellis/trellis.d.ts +117 -0
  58. package/esm/trellis/trellis.d.ts.map +1 -0
  59. package/esm/trellis/trellis.js +710 -0
  60. package/package.json +49 -0
  61. package/script/_dnt.polyfills.d.ts +7 -0
  62. package/script/_dnt.polyfills.d.ts.map +1 -0
  63. package/script/_dnt.polyfills.js +2 -0
  64. package/script/package.json +3 -0
  65. package/script/trellis/browser.d.ts +11 -0
  66. package/script/trellis/browser.d.ts.map +1 -0
  67. package/script/trellis/browser.js +21 -0
  68. package/script/trellis/client.d.ts +31 -0
  69. package/script/trellis/client.d.ts.map +1 -0
  70. package/script/trellis/client.js +16 -0
  71. package/script/trellis/codec.d.ts +12 -0
  72. package/script/trellis/codec.d.ts.map +1 -0
  73. package/script/trellis/codec.js +66 -0
  74. package/script/trellis/env.d.ts +2 -0
  75. package/script/trellis/env.d.ts.map +1 -0
  76. package/script/trellis/env.js +5 -0
  77. package/script/trellis/errors/AuthError.d.ts +30 -0
  78. package/script/trellis/errors/AuthError.d.ts.map +1 -0
  79. package/script/trellis/errors/AuthError.js +72 -0
  80. package/script/trellis/errors/KVError.d.ts +31 -0
  81. package/script/trellis/errors/KVError.d.ts.map +1 -0
  82. package/script/trellis/errors/KVError.js +53 -0
  83. package/script/trellis/errors/RemoteError.d.ts +47 -0
  84. package/script/trellis/errors/RemoteError.d.ts.map +1 -0
  85. package/script/trellis/errors/RemoteError.js +87 -0
  86. package/script/trellis/errors/TrellisError.d.ts +16 -0
  87. package/script/trellis/errors/TrellisError.d.ts.map +1 -0
  88. package/script/trellis/errors/TrellisError.js +19 -0
  89. package/script/trellis/errors/ValidationError.d.ts +51 -0
  90. package/script/trellis/errors/ValidationError.d.ts.map +1 -0
  91. package/script/trellis/errors/ValidationError.js +84 -0
  92. package/script/trellis/errors/index.d.ts +38 -0
  93. package/script/trellis/errors/index.d.ts.map +1 -0
  94. package/script/trellis/errors/index.js +40 -0
  95. package/script/trellis/globals.d.ts +2 -0
  96. package/script/trellis/globals.d.ts.map +1 -0
  97. package/script/trellis/globals.js +11 -0
  98. package/script/trellis/helpers.d.ts +12 -0
  99. package/script/trellis/helpers.d.ts.map +1 -0
  100. package/script/trellis/helpers.js +54 -0
  101. package/script/trellis/index.d.ts +11 -0
  102. package/script/trellis/index.d.ts.map +1 -0
  103. package/script/trellis/index.js +24 -0
  104. package/script/trellis/kv.d.ts +67 -0
  105. package/script/trellis/kv.d.ts.map +1 -0
  106. package/script/trellis/kv.js +354 -0
  107. package/script/trellis/models/trellis/TrellisError.d.ts +43 -0
  108. package/script/trellis/models/trellis/TrellisError.d.ts.map +1 -0
  109. package/script/trellis/models/trellis/TrellisError.js +22 -0
  110. package/script/trellis/tasks.d.ts +11 -0
  111. package/script/trellis/tasks.d.ts.map +1 -0
  112. package/script/trellis/tasks.js +45 -0
  113. package/script/trellis/tracing.d.ts +5 -0
  114. package/script/trellis/tracing.d.ts.map +1 -0
  115. package/script/trellis/tracing.js +49 -0
  116. package/script/trellis/trellis.d.ts +117 -0
  117. package/script/trellis/trellis.d.ts.map +1 -0
  118. package/script/trellis/trellis.js +715 -0
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # @qlever-llc/trellis
2
+
3
+ JavaScript Trellis client runtime. Provides contract-driven client helpers and runtime error types.
4
+
5
+ ```typescript
6
+ const client = contract.createClient(nc, auth, opts);
7
+ ```
8
+
9
+ Server connection helpers live in `@qlever-llc/trellis-server` to keep this package browser-safe.
@@ -0,0 +1,7 @@
1
+ declare global {
2
+ interface Error {
3
+ cause?: unknown;
4
+ }
5
+ }
6
+ export {};
7
+ //# sourceMappingURL=_dnt.polyfills.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Browser-safe exports for @qlever-llc/trellis
3
+ */
4
+ import "../_dnt.polyfills.js";
5
+ export { Trellis } from "./trellis.js";
6
+ export type { TrellisAuth } from "./trellis.js";
7
+ export { TypedKV, TypedKVEntry } from "./kv.js";
8
+ export type { WatchEvent, WatchOptions } from "./kv.js";
9
+ export { AuthError, KVError, RemoteError, UnexpectedError, ValidationError, } from "./errors/index.js";
10
+ export type { TrellisErrorInstance } from "./errors/index.js";
11
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/trellis/browser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,sBAAsB,CAAC;AAE9B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAChD,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGxD,OAAO,EACL,SAAS,EACT,OAAO,EACP,WAAW,EACX,eAAe,EACf,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Browser-safe exports for @qlever-llc/trellis
3
+ */
4
+ // Core Trellis client class (browser-safe)
5
+ import "../_dnt.polyfills.js";
6
+ export { Trellis } from "./trellis.js";
7
+ // KV utilities (browser-safe)
8
+ export { TypedKV, TypedKVEntry } from "./kv.js";
9
+ // Error types (browser-safe)
10
+ export { AuthError, KVError, RemoteError, UnexpectedError, ValidationError, } from "./errors/index.js";
@@ -0,0 +1,31 @@
1
+ import type { NatsConnection } from "@nats-io/nats-core";
2
+ import type { TrellisAPI } from "@qlever-llc/trellis-contracts";
3
+ import type { Logger } from "pino";
4
+ import type { TrellisAuth } from "./trellis.js";
5
+ import { Trellis } from "./trellis.js";
6
+ type NoResponderRetryOpts = {
7
+ maxAttempts?: number;
8
+ baseDelayMs?: number;
9
+ };
10
+ export type ClientOpts = {
11
+ /**
12
+ * Logical name for this client instance (used for logs and consumer names).
13
+ * Defaults to "client".
14
+ */
15
+ name?: string;
16
+ log?: Logger;
17
+ timeout?: number;
18
+ stream?: string;
19
+ noResponderRetry?: NoResponderRetryOpts;
20
+ };
21
+ type ClientContract<TApi> = {
22
+ API: {
23
+ trellis: TApi;
24
+ };
25
+ };
26
+ /**
27
+ * Create a Trellis client typed from a contract module's derived outbound surface.
28
+ */
29
+ export declare function createClient<TApi extends TrellisAPI>(contract: ClientContract<TApi>, nats: NatsConnection, auth: TrellisAuth, opts?: ClientOpts): Trellis<TApi>;
30
+ export {};
31
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/trellis/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,KAAK,oBAAoB,GAAG;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,oBAAoB,CAAC;CACzC,CAAC;AAEF,KAAK,cAAc,CAAC,IAAI,IAAI;IAC1B,GAAG,EAAE;QACH,OAAO,EAAE,IAAI,CAAC;KACf,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,SAAS,UAAU,EAClD,QAAQ,EAAE,cAAc,CAAC,IAAI,CAAC,EAC9B,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,WAAW,EACjB,IAAI,CAAC,EAAE,UAAU,GAChB,OAAO,CAAC,IAAI,CAAC,CAaf"}
@@ -0,0 +1,13 @@
1
+ import { Trellis } from "./trellis.js";
2
+ /**
3
+ * Create a Trellis client typed from a contract module's derived outbound surface.
4
+ */
5
+ export function createClient(contract, nats, auth, opts) {
6
+ return new Trellis(opts?.name ?? "client", nats, auth, {
7
+ log: opts?.log,
8
+ timeout: opts?.timeout,
9
+ stream: opts?.stream,
10
+ noResponderRetry: opts?.noResponderRetry,
11
+ api: contract.API.trellis,
12
+ });
13
+ }
@@ -0,0 +1,12 @@
1
+ import { type InferSchemaType, type SchemaLike } from "@qlever-llc/trellis-contracts";
2
+ import { Result } from "@qlever-llc/trellis-result";
3
+ import type { StaticDecode, TSchema } from "typebox";
4
+ import { UnexpectedError, ValidationError } from "./errors/index.js";
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>, ValidationError | UnexpectedError>;
9
+ export declare function parseSchema<S extends SchemaLike>(schema: S, data: JsonValue): Result<InferSchemaType<S>, ValidationError | UnexpectedError>;
10
+ export declare function encode<T extends TSchema>(schema: T, data: unknown): Result<string, ValidationError | UnexpectedError>;
11
+ export declare function encodeSchema<S extends SchemaLike>(schema: S, data: unknown): Result<string, ValidationError | UnexpectedError>;
12
+ //# sourceMappingURL=codec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/trellis/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,UAAU,EAEhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAErE,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,EAAE,GACX;IACA,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B,CAAC;AAUJ,wBAAgB,KAAK,CAAC,CAAC,SAAS,OAAO,EACrC,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,SAAS,GACd,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,eAAe,GAAG,eAAe,CAAC,CAU5D;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,UAAU,EAC9C,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,SAAS,GACd,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,eAAe,GAAG,eAAe,CAAC,CAW/D;AAED,wBAAgB,MAAM,CAAC,CAAC,SAAS,OAAO,EACtC,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,OAAO,GACZ,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,CAAC,CAUnD;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,UAAU,EAC/C,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,OAAO,GACZ,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,CAAC,CAWnD"}
@@ -0,0 +1,60 @@
1
+ import { unwrapSchema, } from "@qlever-llc/trellis-contracts";
2
+ import { Result } from "@qlever-llc/trellis-result";
3
+ import { EncodeError, ParseError, Value } from "typebox/value";
4
+ import { UnexpectedError, ValidationError } from "./errors/index.js";
5
+ function parseWithSchema(schema, data) {
6
+ return Value.Parse(schema, data);
7
+ }
8
+ function encodeWithSchema(schema, data) {
9
+ return JSON.stringify(Value.Encode(schema, data));
10
+ }
11
+ export function parse(schema, data) {
12
+ try {
13
+ return Result.ok(parseWithSchema(schema, data));
14
+ }
15
+ catch (cause) {
16
+ if (cause instanceof ParseError) {
17
+ const errors = Value.Errors(schema, data);
18
+ return Result.err(new ValidationError({ errors, cause }));
19
+ }
20
+ return Result.err(new UnexpectedError({ cause }));
21
+ }
22
+ }
23
+ export function parseSchema(schema, data) {
24
+ const raw = unwrapSchema(schema);
25
+ try {
26
+ return Result.ok(parseWithSchema(raw, data));
27
+ }
28
+ catch (cause) {
29
+ if (cause instanceof ParseError) {
30
+ const errors = Value.Errors(raw, data);
31
+ return Result.err(new ValidationError({ errors, cause }));
32
+ }
33
+ return Result.err(new UnexpectedError({ cause }));
34
+ }
35
+ }
36
+ export function encode(schema, data) {
37
+ try {
38
+ return Result.ok(encodeWithSchema(schema, data));
39
+ }
40
+ catch (cause) {
41
+ if (cause instanceof EncodeError) {
42
+ const errors = Value.Errors(schema, data);
43
+ return Result.err(new ValidationError({ errors, cause }));
44
+ }
45
+ return Result.err(new UnexpectedError({ cause }));
46
+ }
47
+ }
48
+ export function encodeSchema(schema, data) {
49
+ const raw = unwrapSchema(schema);
50
+ try {
51
+ return Result.ok(encodeWithSchema(raw, data));
52
+ }
53
+ catch (cause) {
54
+ if (cause instanceof EncodeError) {
55
+ const errors = Value.Errors(raw, data);
56
+ return Result.err(new ValidationError({ errors, cause }));
57
+ }
58
+ return Result.err(new UnexpectedError({ cause }));
59
+ }
60
+ }
@@ -0,0 +1,2 @@
1
+ export { getEnv } from "@qlever-llc/trellis-telemetry";
2
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/trellis/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1 @@
1
+ export { getEnv } from "@qlever-llc/trellis-telemetry";
@@ -0,0 +1,30 @@
1
+ import Type, { type Static } from "typebox";
2
+ import { TrellisError } from "./TrellisError.js";
3
+ export declare const AuthErrorDataSchema: Type.TObject<{
4
+ id: Type.TString;
5
+ type: Type.TLiteral<"AuthError">;
6
+ message: Type.TString;
7
+ reason: Type.TUnion<[Type.TLiteral<"invalid_request">, Type.TLiteral<"missing_session_key">, Type.TLiteral<"missing_proof">, Type.TLiteral<"session_not_found">, Type.TLiteral<"session_expired">, Type.TLiteral<"invalid_signature">, Type.TLiteral<"user_not_found">, Type.TLiteral<"user_inactive">, Type.TLiteral<"unknown_service">, Type.TLiteral<"service_disabled">, Type.TLiteral<"iat_out_of_range">, Type.TLiteral<"invalid_binding_token">, Type.TLiteral<"session_corrupted">, Type.TLiteral<"session_already_bound">, Type.TLiteral<"authtoken_already_used">, Type.TLiteral<"oauth_session_key_mismatch">, Type.TLiteral<"service_role_on_user">, Type.TLiteral<"reply_subject_mismatch">, Type.TLiteral<"insufficient_permissions">, Type.TLiteral<"forbidden">]>;
8
+ context: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
9
+ traceId: Type.TOptional<Type.TString>;
10
+ }>;
11
+ export type AuthErrorData = Static<typeof AuthErrorDataSchema>;
12
+ /**
13
+ * Error for authentication and authorization failures.
14
+ */
15
+ export declare class AuthError extends TrellisError<AuthErrorData> {
16
+ readonly name: "AuthError";
17
+ readonly reason: AuthErrorData["reason"];
18
+ constructor(options: ErrorOptions & {
19
+ reason: AuthErrorData["reason"];
20
+ context?: Record<string, unknown>;
21
+ id?: string;
22
+ });
23
+ /**
24
+ * Serializes error to a plain object.
25
+ *
26
+ * @returns Plain object representation of the error
27
+ */
28
+ toSerializable(): AuthErrorData;
29
+ }
30
+ //# sourceMappingURL=AuthError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthError.d.ts","sourceRoot":"","sources":["../../../src/trellis/errors/AuthError.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,eAAO,MAAM,mBAAmB;;;;;;;EA4B9B,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAE/D;;GAEG;AACH,qBAAa,SAAU,SAAQ,YAAY,CAAC,aAAa,CAAC;IACxD,SAAkB,IAAI,cAAwB;IAC9C,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;gBAGvC,OAAO,EAAE,YAAY,GAAG;QACtB,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClC,EAAE,CAAC,EAAE,MAAM,CAAC;KACb;IAOH;;;;OAIG;IACM,cAAc,IAAI,aAAa;CAOzC"}
@@ -0,0 +1,65 @@
1
+ import Type from "typebox";
2
+ import { TrellisError } from "./TrellisError.js";
3
+ export const AuthErrorDataSchema = Type.Object({
4
+ id: Type.String(),
5
+ type: Type.Literal("AuthError"),
6
+ message: Type.String(),
7
+ reason: Type.Union([
8
+ Type.Literal("invalid_request"),
9
+ Type.Literal("missing_session_key"),
10
+ Type.Literal("missing_proof"),
11
+ Type.Literal("session_not_found"),
12
+ Type.Literal("session_expired"),
13
+ Type.Literal("invalid_signature"),
14
+ Type.Literal("user_not_found"),
15
+ Type.Literal("user_inactive"),
16
+ Type.Literal("unknown_service"),
17
+ Type.Literal("service_disabled"),
18
+ Type.Literal("iat_out_of_range"),
19
+ Type.Literal("invalid_binding_token"),
20
+ Type.Literal("session_corrupted"),
21
+ Type.Literal("session_already_bound"),
22
+ Type.Literal("authtoken_already_used"),
23
+ Type.Literal("oauth_session_key_mismatch"),
24
+ Type.Literal("service_role_on_user"),
25
+ Type.Literal("reply_subject_mismatch"),
26
+ Type.Literal("insufficient_permissions"),
27
+ Type.Literal("forbidden"),
28
+ ]),
29
+ context: Type.Optional(Type.Record(Type.String(), Type.Unknown())),
30
+ traceId: Type.Optional(Type.String()),
31
+ });
32
+ /**
33
+ * Error for authentication and authorization failures.
34
+ */
35
+ export class AuthError extends TrellisError {
36
+ constructor(options) {
37
+ const { reason, ...baseOptions } = options;
38
+ super(`Auth failed: ${reason}`, baseOptions);
39
+ Object.defineProperty(this, "name", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: "AuthError"
44
+ });
45
+ Object.defineProperty(this, "reason", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: void 0
50
+ });
51
+ this.reason = reason;
52
+ }
53
+ /**
54
+ * Serializes error to a plain object.
55
+ *
56
+ * @returns Plain object representation of the error
57
+ */
58
+ toSerializable() {
59
+ return {
60
+ ...this.baseSerializable(),
61
+ type: this.name,
62
+ reason: this.reason,
63
+ };
64
+ }
65
+ }
@@ -0,0 +1,31 @@
1
+ import Type, { type Static } from "typebox";
2
+ import { TrellisError } from "./TrellisError.js";
3
+ export declare const KVErrorDataSchema: Type.TObject<{
4
+ id: Type.TString;
5
+ type: Type.TLiteral<"KVError">;
6
+ message: Type.TString;
7
+ operation: Type.TOptional<Type.TString>;
8
+ context: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
9
+ traceId: Type.TOptional<Type.TString>;
10
+ }>;
11
+ export type KVErrorData = Static<typeof KVErrorDataSchema>;
12
+ /**
13
+ * Error for KV storage operations.
14
+ * Used when key-value store operations fail.
15
+ */
16
+ export declare class KVError extends TrellisError<KVErrorData> {
17
+ readonly name: "KVError";
18
+ readonly operation?: string;
19
+ constructor(options: ErrorOptions & {
20
+ operation?: string;
21
+ context?: Record<string, unknown>;
22
+ id?: string;
23
+ });
24
+ /**
25
+ * Serializes error to a plain object.
26
+ *
27
+ * @returns Plain object representation of the error
28
+ */
29
+ toSerializable(): KVErrorData;
30
+ }
31
+ //# sourceMappingURL=KVError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KVError.d.ts","sourceRoot":"","sources":["../../../src/trellis/errors/KVError.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,eAAO,MAAM,iBAAiB;;;;;;;EAO5B,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE3D;;;GAGG;AACH,qBAAa,OAAQ,SAAQ,YAAY,CAAC,WAAW,CAAC;IACpD,SAAkB,IAAI,YAAsB;IAC5C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;gBAG1B,OAAO,EAAE,YAAY,GAAG;QACtB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClC,EAAE,CAAC,EAAE,MAAM,CAAC;KACb;IAQH;;;;OAIG;IACM,cAAc,IAAI,WAAW;CAOvC"}
@@ -0,0 +1,46 @@
1
+ import Type from "typebox";
2
+ import { TrellisError } from "./TrellisError.js";
3
+ export const KVErrorDataSchema = Type.Object({
4
+ id: Type.String(),
5
+ type: Type.Literal("KVError"),
6
+ message: Type.String(),
7
+ operation: Type.Optional(Type.String()),
8
+ context: Type.Optional(Type.Record(Type.String(), Type.Unknown())),
9
+ traceId: Type.Optional(Type.String()),
10
+ });
11
+ /**
12
+ * Error for KV storage operations.
13
+ * Used when key-value store operations fail.
14
+ */
15
+ export class KVError extends TrellisError {
16
+ constructor(options) {
17
+ const { operation, ...baseOptions } = options;
18
+ const msg = `KV ${operation || ""} failed`;
19
+ super(msg, baseOptions);
20
+ Object.defineProperty(this, "name", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: "KVError"
25
+ });
26
+ Object.defineProperty(this, "operation", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: void 0
31
+ });
32
+ this.operation = operation;
33
+ }
34
+ /**
35
+ * Serializes error to a plain object.
36
+ *
37
+ * @returns Plain object representation of the error
38
+ */
39
+ toSerializable() {
40
+ return {
41
+ ...this.baseSerializable(),
42
+ type: this.name,
43
+ operation: this.operation,
44
+ };
45
+ }
46
+ }
@@ -0,0 +1,47 @@
1
+ import { Result, UnexpectedError } from "@qlever-llc/trellis-result";
2
+ import Type, { type Static } from "typebox";
3
+ import { ValidationError } from "./ValidationError.js";
4
+ import { TrellisError } from "./TrellisError.js";
5
+ import type { TrellisErrorData } from "../models/trellis/TrellisError.js";
6
+ export declare const RemoteErrorDataSchema: Type.TObject<{
7
+ id: Type.TString;
8
+ type: Type.TLiteral<"RemoteError">;
9
+ message: Type.TString;
10
+ remoteError: Type.TAny;
11
+ context: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
12
+ traceId: Type.TOptional<Type.TString>;
13
+ }>;
14
+ export type RemoteErrorData = Static<typeof RemoteErrorDataSchema>;
15
+ /**
16
+ * Error for wrapping errors received from remote Trellis services.
17
+ * This is the only error type with parseJSON/parseObject methods for deserializing remote errors.
18
+ */
19
+ export declare class RemoteError extends TrellisError<RemoteErrorData> {
20
+ readonly name: "RemoteError";
21
+ readonly remoteError: TrellisErrorData;
22
+ constructor(options: ErrorOptions & {
23
+ error: TrellisErrorData;
24
+ context?: Record<string, unknown>;
25
+ id?: string;
26
+ });
27
+ /**
28
+ * Serializes error to a plain object.
29
+ *
30
+ * @returns Plain object representation of the error
31
+ */
32
+ toSerializable(): RemoteErrorData;
33
+ /**
34
+ * Parses and validates a plain object as TrellisErrorData.
35
+ * Use this to deserialize errors received from remote services.
36
+ *
37
+ * @param obj - Plain object to validate
38
+ * @returns Result containing validated TrellisError or a ValidationError or UnexpectedError
39
+ */
40
+ static parse(data: unknown): Result<TrellisErrorData, ValidationError | UnexpectedError>;
41
+ /**
42
+ * Alias for parse() - parses JSON string or object as TrellisErrorData.
43
+ * @see parse
44
+ */
45
+ static parseJSON: typeof RemoteError.parse;
46
+ }
47
+ //# sourceMappingURL=RemoteError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RemoteError.d.ts","sourceRoot":"","sources":["../../../src/trellis/errors/RemoteError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,IAAI,EAAE,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAG1E,eAAO,MAAM,qBAAqB;;;;;;;EAOhC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEnE;;;GAGG;AACH,qBAAa,WAAY,SAAQ,YAAY,CAAC,eAAe,CAAC;IAC5D,SAAkB,IAAI,gBAA0B;IAChD,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAAC;gBAGrC,OAAO,EAAE,YAAY,GAAG;QACtB,KAAK,EAAE,gBAAgB,CAAC;QACxB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClC,EAAE,CAAC,EAAE,MAAM,CAAC;KACb;IAOH;;;;OAIG;IACM,cAAc,IAAI,eAAe;IAQ1C;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CACV,IAAI,EAAE,OAAO,GACZ,MAAM,CAAC,gBAAgB,EAAE,eAAe,GAAG,eAAe,CAAC;IAqB9D;;;OAGG;IACH,MAAM,CAAC,SAAS,2BAAqB;CACtC"}
@@ -0,0 +1,80 @@
1
+ import { Result } from "@qlever-llc/trellis-result";
2
+ import Type from "typebox";
3
+ import { ParseError, Value } from "typebox/value";
4
+ import { ValidationError } from "./ValidationError.js";
5
+ import { TrellisError } from "./TrellisError.js";
6
+ import { TrellisErrorDataSchema } from "../models/trellis/TrellisError.js";
7
+ export const RemoteErrorDataSchema = Type.Object({
8
+ id: Type.String(),
9
+ type: Type.Literal("RemoteError"),
10
+ message: Type.String(),
11
+ remoteError: Type.Any(),
12
+ context: Type.Optional(Type.Record(Type.String(), Type.Unknown())),
13
+ traceId: Type.Optional(Type.String()),
14
+ });
15
+ /**
16
+ * Error for wrapping errors received from remote Trellis services.
17
+ * This is the only error type with parseJSON/parseObject methods for deserializing remote errors.
18
+ */
19
+ export class RemoteError extends TrellisError {
20
+ constructor(options) {
21
+ const { error, ...baseOptions } = options;
22
+ super(`Remote error: ${error.message}`, baseOptions);
23
+ Object.defineProperty(this, "name", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: "RemoteError"
28
+ });
29
+ Object.defineProperty(this, "remoteError", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: void 0
34
+ });
35
+ this.remoteError = error;
36
+ }
37
+ /**
38
+ * Serializes error to a plain object.
39
+ *
40
+ * @returns Plain object representation of the error
41
+ */
42
+ toSerializable() {
43
+ return {
44
+ ...this.baseSerializable(),
45
+ type: this.name,
46
+ remoteError: this.remoteError,
47
+ };
48
+ }
49
+ /**
50
+ * Parses and validates a plain object as TrellisErrorData.
51
+ * Use this to deserialize errors received from remote services.
52
+ *
53
+ * @param obj - Plain object to validate
54
+ * @returns Result containing validated TrellisError or a ValidationError or UnexpectedError
55
+ */
56
+ static parse(data) {
57
+ return Result.try(() => typeof data === "string" ? JSON.parse(data) : data).andThen((obj) => {
58
+ const parseResult = Result.try(() => Value.Parse(TrellisErrorDataSchema, obj));
59
+ if (parseResult.isErr()) {
60
+ const cause = parseResult.error.cause;
61
+ if (cause instanceof ParseError) {
62
+ const errors = Value.Errors(TrellisErrorDataSchema, obj);
63
+ return Result.err(new ValidationError({ errors, cause }));
64
+ }
65
+ return Result.err(parseResult.error);
66
+ }
67
+ return Result.ok(parseResult.take());
68
+ });
69
+ }
70
+ }
71
+ /**
72
+ * Alias for parse() - parses JSON string or object as TrellisErrorData.
73
+ * @see parse
74
+ */
75
+ Object.defineProperty(RemoteError, "parseJSON", {
76
+ enumerable: true,
77
+ configurable: true,
78
+ writable: true,
79
+ value: RemoteError.parse
80
+ });
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Base class for all Trellis-specific errors.
3
+ * Extends BaseError and relies on the traceId getter being configured via initTracing.
4
+ */
5
+ import { BaseError, type BaseErrorSchema } from "@qlever-llc/trellis-result";
6
+ /**
7
+ * Abstract base class for Trellis errors.
8
+ * Trellis errors automatically include traceId when initTracing() has been called
9
+ * and a span is active in the current context.
10
+ *
11
+ * The traceId integration is configured by the tracing module's initTracing() function,
12
+ * which sets up BaseError.traceIdGetter to retrieve the traceId from the active span.
13
+ */
14
+ export declare abstract class TrellisError<TData extends BaseErrorSchema = BaseErrorSchema> extends BaseError<TData> {
15
+ }
16
+ //# sourceMappingURL=TrellisError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TrellisError.d.ts","sourceRoot":"","sources":["../../../src/trellis/errors/TrellisError.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtE;;;;;;;GAOG;AACH,8BAAsB,YAAY,CAChC,KAAK,SAAS,eAAe,GAAG,eAAe,CAC/C,SAAQ,SAAS,CAAC,KAAK,CAAC;CAGzB"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Base class for all Trellis-specific errors.
3
+ * Extends BaseError and relies on the traceId getter being configured via initTracing.
4
+ */
5
+ import { BaseError } from "@qlever-llc/trellis-result";
6
+ /**
7
+ * Abstract base class for Trellis errors.
8
+ * Trellis errors automatically include traceId when initTracing() has been called
9
+ * and a span is active in the current context.
10
+ *
11
+ * The traceId integration is configured by the tracing module's initTracing() function,
12
+ * which sets up BaseError.traceIdGetter to retrieve the traceId from the active span.
13
+ */
14
+ export class TrellisError extends BaseError {
15
+ }
@@ -0,0 +1,51 @@
1
+ import type { TLocalizedValidationError } from "typebox/error";
2
+ import Type, { type Static } from "typebox";
3
+ import { TrellisError } from "./TrellisError.js";
4
+ export type ValidationErrorInput = TLocalizedValidationError | {
5
+ path: string;
6
+ message: string;
7
+ };
8
+ /**
9
+ * Schema for validation issue in ValidationError.
10
+ */
11
+ export declare const ValidationIssueSchema: Type.TObject<{
12
+ path: Type.TString;
13
+ message: Type.TString;
14
+ }>;
15
+ export type ValidationIssue = Static<typeof ValidationIssueSchema>;
16
+ /**
17
+ * Schema for ValidationError serialization.
18
+ */
19
+ export declare const ValidationErrorDataSchema: Type.TObject<{
20
+ id: Type.TString;
21
+ type: Type.TLiteral<"ValidationError">;
22
+ message: Type.TString;
23
+ issues: Type.TArray<Type.TObject<{
24
+ path: Type.TString;
25
+ message: Type.TString;
26
+ }>>;
27
+ context: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
28
+ traceId: Type.TOptional<Type.TString>;
29
+ }>;
30
+ export type ValidationErrorData = Static<typeof ValidationErrorDataSchema>;
31
+ /**
32
+ * Error for data validation failures.
33
+ * Includes schema validation and missing required data.
34
+ */
35
+ export declare class ValidationError extends TrellisError<ValidationErrorData> {
36
+ #private;
37
+ readonly name: "ValidationError";
38
+ constructor(options: ErrorOptions & {
39
+ errors: Iterable<ValidationErrorInput>;
40
+ context?: Record<string, unknown>;
41
+ id?: string;
42
+ });
43
+ /**
44
+ * Serializes error to a plain object.
45
+ * Transforms internal errors array to issues array for serialization.
46
+ *
47
+ * @returns Plain object representation of the error
48
+ */
49
+ toSerializable(): ValidationErrorData;
50
+ }
51
+ //# sourceMappingURL=ValidationError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidationError.d.ts","sourceRoot":"","sources":["../../../src/trellis/errors/ValidationError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,IAAI,EAAE,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,MAAM,oBAAoB,GAC5B,yBAAyB,GACzB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAWtC;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;EAGhC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEnE;;GAEG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;EAOpC,CAAC;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE3E;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,YAAY,CAAC,mBAAmB,CAAC;;IACpE,SAAkB,IAAI,oBAA8B;gBAIlD,OAAO,EAAE,YAAY,GAAG;QACtB,MAAM,EAAE,QAAQ,CAAC,oBAAoB,CAAC,CAAC;QACvC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClC,EAAE,CAAC,EAAE,MAAM,CAAC;KACb;IAWH;;;;;OAKG;IACM,cAAc,IAAI,mBAAmB;CAU/C"}