@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
@@ -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"}
@@ -0,0 +1,84 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ var _ValidationError_normalizedErrors;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ValidationError = exports.ValidationErrorDataSchema = exports.ValidationIssueSchema = void 0;
19
+ const typebox_1 = __importDefault(require("typebox"));
20
+ const TrellisError_js_1 = require("./TrellisError.js");
21
+ function normalizeError(e) {
22
+ if ("schemaPath" in e) {
23
+ return { schemaPath: e.schemaPath, message: e.message ?? "Invalid value" };
24
+ }
25
+ return { schemaPath: e.path, message: e.message };
26
+ }
27
+ /**
28
+ * Schema for validation issue in ValidationError.
29
+ */
30
+ exports.ValidationIssueSchema = typebox_1.default.Object({
31
+ path: typebox_1.default.String(),
32
+ message: typebox_1.default.String(),
33
+ });
34
+ /**
35
+ * Schema for ValidationError serialization.
36
+ */
37
+ exports.ValidationErrorDataSchema = typebox_1.default.Object({
38
+ id: typebox_1.default.String(),
39
+ type: typebox_1.default.Literal("ValidationError"),
40
+ message: typebox_1.default.String(),
41
+ issues: typebox_1.default.Array(exports.ValidationIssueSchema),
42
+ context: typebox_1.default.Optional(typebox_1.default.Record(typebox_1.default.String(), typebox_1.default.Unknown())),
43
+ traceId: typebox_1.default.Optional(typebox_1.default.String()),
44
+ });
45
+ /**
46
+ * Error for data validation failures.
47
+ * Includes schema validation and missing required data.
48
+ */
49
+ class ValidationError extends TrellisError_js_1.TrellisError {
50
+ constructor(options) {
51
+ const { errors: rawErrors, ...baseOptions } = options;
52
+ const errors = [...rawErrors].map(normalizeError);
53
+ const msg = errors
54
+ .map((e) => `Validation failed. ${e.schemaPath}: ${e.message}.`)
55
+ .join("\n");
56
+ super(msg.length ? msg : "Data validation failed.", baseOptions);
57
+ Object.defineProperty(this, "name", {
58
+ enumerable: true,
59
+ configurable: true,
60
+ writable: true,
61
+ value: "ValidationError"
62
+ });
63
+ _ValidationError_normalizedErrors.set(this, void 0);
64
+ __classPrivateFieldSet(this, _ValidationError_normalizedErrors, errors, "f");
65
+ }
66
+ /**
67
+ * Serializes error to a plain object.
68
+ * Transforms internal errors array to issues array for serialization.
69
+ *
70
+ * @returns Plain object representation of the error
71
+ */
72
+ toSerializable() {
73
+ return {
74
+ ...this.baseSerializable(),
75
+ type: this.name,
76
+ issues: __classPrivateFieldGet(this, _ValidationError_normalizedErrors, "f").map((e) => ({
77
+ path: e.schemaPath,
78
+ message: e.message,
79
+ })),
80
+ };
81
+ }
82
+ }
83
+ exports.ValidationError = ValidationError;
84
+ _ValidationError_normalizedErrors = new WeakMap();
@@ -0,0 +1,38 @@
1
+ import { AuthError } from "./AuthError.js";
2
+ import { ValidationError } from "./ValidationError.js";
3
+ import { RemoteError } from "./RemoteError.js";
4
+ import { KVError } from "./KVError.js";
5
+ export { UnexpectedError } from "@qlever-llc/trellis-result";
6
+ export { TrellisError } from "./TrellisError.js";
7
+ export { AuthError } from "./AuthError.js";
8
+ export { ValidationError } from "./ValidationError.js";
9
+ export { RemoteError } from "./RemoteError.js";
10
+ export { KVError } from "./KVError.js";
11
+ export { type AuthErrorData, AuthErrorDataSchema } from "./AuthError.js";
12
+ export { type ValidationErrorData, ValidationErrorDataSchema, type ValidationIssue, ValidationIssueSchema, } from "./ValidationError.js";
13
+ export { type RemoteErrorData, RemoteErrorDataSchema } from "./RemoteError.js";
14
+ export { type KVErrorData, KVErrorDataSchema } from "./KVError.js";
15
+ /**
16
+ * Single source of truth for all Trellis errors.
17
+ * This object is used for compile-time type inference.
18
+ */
19
+ declare const TRELLIS_ERRORS: {
20
+ readonly UnexpectedError: any;
21
+ readonly AuthError: typeof AuthError;
22
+ readonly ValidationError: typeof ValidationError;
23
+ readonly RemoteError: typeof RemoteError;
24
+ readonly KVError: typeof KVError;
25
+ };
26
+ /**
27
+ * Compile-time mapping from error names to their instance types.
28
+ * Derived from TRELLIS_ERRORS to ensure types stay in sync with runtime.
29
+ */
30
+ export type TrellisErrorMap = {
31
+ [K in keyof typeof TRELLIS_ERRORS]: InstanceType<(typeof TRELLIS_ERRORS)[K]>;
32
+ };
33
+ export type TrellisErrorName = keyof TrellisErrorMap;
34
+ export type TrellisErrorInstance = TrellisErrorMap[TrellisErrorName];
35
+ export type MapErrorNamesToTypes<T extends readonly TrellisErrorName[]> = {
36
+ [K in keyof T]: T[K] extends TrellisErrorName ? TrellisErrorMap[T[K]] : never;
37
+ }[number];
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/trellis/errors/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,KAAK,aAAa,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EACL,KAAK,mBAAmB,EACxB,yBAAyB,EACzB,KAAK,eAAe,EACpB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,KAAK,eAAe,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,KAAK,WAAW,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEnE;;;GAGG;AACH,QAAA,MAAM,cAAc;;;;;;CAMV,CAAC;AAEX;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;KAC3B,CAAC,IAAI,MAAM,OAAO,cAAc,GAAG,YAAY,CAAC,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;CAC7E,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,MAAM,eAAe,CAAC;AACrD,MAAM,MAAM,oBAAoB,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAC;AACrE,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,SAAS,gBAAgB,EAAE,IAAI;KACvE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,gBAAgB,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK;CAC9E,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KVErrorDataSchema = exports.RemoteErrorDataSchema = exports.ValidationIssueSchema = exports.ValidationErrorDataSchema = exports.AuthErrorDataSchema = exports.KVError = exports.RemoteError = exports.ValidationError = exports.AuthError = exports.TrellisError = exports.UnexpectedError = void 0;
4
+ const trellis_result_1 = require("@qlever-llc/trellis-result");
5
+ const AuthError_js_1 = require("./AuthError.js");
6
+ const ValidationError_js_1 = require("./ValidationError.js");
7
+ const RemoteError_js_1 = require("./RemoteError.js");
8
+ const KVError_js_1 = require("./KVError.js");
9
+ var trellis_result_2 = require("@qlever-llc/trellis-result");
10
+ Object.defineProperty(exports, "UnexpectedError", { enumerable: true, get: function () { return trellis_result_2.UnexpectedError; } });
11
+ var TrellisError_js_1 = require("./TrellisError.js");
12
+ Object.defineProperty(exports, "TrellisError", { enumerable: true, get: function () { return TrellisError_js_1.TrellisError; } });
13
+ var AuthError_js_2 = require("./AuthError.js");
14
+ Object.defineProperty(exports, "AuthError", { enumerable: true, get: function () { return AuthError_js_2.AuthError; } });
15
+ var ValidationError_js_2 = require("./ValidationError.js");
16
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return ValidationError_js_2.ValidationError; } });
17
+ var RemoteError_js_2 = require("./RemoteError.js");
18
+ Object.defineProperty(exports, "RemoteError", { enumerable: true, get: function () { return RemoteError_js_2.RemoteError; } });
19
+ var KVError_js_2 = require("./KVError.js");
20
+ Object.defineProperty(exports, "KVError", { enumerable: true, get: function () { return KVError_js_2.KVError; } });
21
+ var AuthError_js_3 = require("./AuthError.js");
22
+ Object.defineProperty(exports, "AuthErrorDataSchema", { enumerable: true, get: function () { return AuthError_js_3.AuthErrorDataSchema; } });
23
+ var ValidationError_js_3 = require("./ValidationError.js");
24
+ Object.defineProperty(exports, "ValidationErrorDataSchema", { enumerable: true, get: function () { return ValidationError_js_3.ValidationErrorDataSchema; } });
25
+ Object.defineProperty(exports, "ValidationIssueSchema", { enumerable: true, get: function () { return ValidationError_js_3.ValidationIssueSchema; } });
26
+ var RemoteError_js_3 = require("./RemoteError.js");
27
+ Object.defineProperty(exports, "RemoteErrorDataSchema", { enumerable: true, get: function () { return RemoteError_js_3.RemoteErrorDataSchema; } });
28
+ var KVError_js_3 = require("./KVError.js");
29
+ Object.defineProperty(exports, "KVErrorDataSchema", { enumerable: true, get: function () { return KVError_js_3.KVErrorDataSchema; } });
30
+ /**
31
+ * Single source of truth for all Trellis errors.
32
+ * This object is used for compile-time type inference.
33
+ */
34
+ const TRELLIS_ERRORS = {
35
+ UnexpectedError: trellis_result_1.UnexpectedError,
36
+ AuthError: AuthError_js_1.AuthError,
37
+ ValidationError: ValidationError_js_1.ValidationError,
38
+ RemoteError: RemoteError_js_1.RemoteError,
39
+ KVError: KVError_js_1.KVError,
40
+ };
@@ -0,0 +1,2 @@
1
+ export declare const logger: import("pino").Logger<never, boolean>;
2
+ //# sourceMappingURL=globals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../../src/trellis/globals.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,MAAM,uCAGjB,CAAC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logger = void 0;
4
+ const pino_1 = require("pino");
5
+ const env_js_1 = require("./env.js");
6
+ // Support Deno and browser (+ Svelte's strict TS rules)
7
+ const level = (0, env_js_1.getEnv)("PINO_LEVEL") || "info";
8
+ exports.logger = (0, pino_1.pino)({
9
+ level,
10
+ base: { library: "@qlever-llc/trellis" },
11
+ });
@@ -0,0 +1,12 @@
1
+ import type { Paginated } from "@qlever-llc/trellis-contracts";
2
+ /**
3
+ * Compute the subject template from the message itself
4
+ */
5
+ export declare function template(template: string, data: Record<string, string | number | boolean>, opts?: {
6
+ allowWildcards: boolean;
7
+ }): string;
8
+ export declare function escapeNats(token: string): string;
9
+ export declare function escapeKvKey(key: string): string;
10
+ export declare function decodeSubject(token: string): string;
11
+ export declare function makePaginated(offset: number, limit: number, count: number): Paginated;
12
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/trellis/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAG/D;;GAEG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAC/C,IAAI,GAAE;IAAE,cAAc,EAAE,OAAO,CAAA;CAA8B,GAC5D,MAAM,CAWR;AAGD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAYhD;AAGD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAW/C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUnD;AAED,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,SAAS,CAQX"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.template = template;
4
+ exports.escapeNats = escapeNats;
5
+ exports.escapeKvKey = escapeKvKey;
6
+ exports.decodeSubject = decodeSubject;
7
+ exports.makePaginated = makePaginated;
8
+ const value_1 = require("typebox/value");
9
+ /**
10
+ * Compute the subject template from the message itself
11
+ */
12
+ function template(template, data, opts = { allowWildcards: false }) {
13
+ return template.replace(/\{([^}]+)\}/g, (_, key) => {
14
+ const token = value_1.Pointer.Get(data, key);
15
+ const v = token ? escapeNats(`${token}`) : "*";
16
+ if (!opts.allowWildcards && v === "*") {
17
+ throw new Error("All option templates must have values at runtime.");
18
+ }
19
+ return v;
20
+ });
21
+ }
22
+ const NATS_SUBJECT_TOKEN_FORBIDDEN = /[\u0000\s.*>~]/gu;
23
+ function escapeNats(token) {
24
+ const out = token.replace(NATS_SUBJECT_TOKEN_FORBIDDEN, (ch) => `~${ch.codePointAt(0).toString(16).toUpperCase()}~`);
25
+ // Protect start with $ due to NATS internal use of it
26
+ if (out.length === 0 || out.startsWith("$")) {
27
+ return `_${out}`;
28
+ }
29
+ return out;
30
+ }
31
+ const NATS_KV_KEY_FORBIDDEN = /[\u0000\s*>~]/gu;
32
+ function escapeKvKey(key) {
33
+ const out = key.replace(NATS_KV_KEY_FORBIDDEN, (ch) => `~${ch.codePointAt(0).toString(16).toUpperCase()}~`);
34
+ if (out.length === 0 || out.startsWith("$")) {
35
+ return `_${out}`;
36
+ }
37
+ return out;
38
+ }
39
+ function decodeSubject(token) {
40
+ const out = token.replace(/~([0-9A-F]{1,6})~/g, (_, hex) => String.fromCodePoint(Number.parseInt(hex, 16)));
41
+ if (out.startsWith("_$")) {
42
+ return out.slice(1);
43
+ }
44
+ return out;
45
+ }
46
+ function makePaginated(offset, limit, count) {
47
+ return {
48
+ count,
49
+ offset,
50
+ limit,
51
+ next: offset + limit >= count ? undefined : offset + limit,
52
+ prev: offset - limit <= 0 ? undefined : offset - limit,
53
+ };
54
+ }
@@ -0,0 +1,11 @@
1
+ import "../_dnt.polyfills.js";
2
+ export type { TrellisAPI } from "@qlever-llc/trellis-contracts";
3
+ export { err, isErr, isOk, ok, Result } from "@qlever-llc/trellis-result";
4
+ export type { ClientOpts } from "./client.js";
5
+ export { createClient } from "./client.js";
6
+ export type { TrellisErrorInstance } from "./errors/index.js";
7
+ export { AuthError, KVError, RemoteError, TrellisError, UnexpectedError, ValidationError, } from "./errors/index.js";
8
+ export { TypedKV } from "./kv.js";
9
+ export type { TrellisAuth, TrellisSigner } from "./trellis.js";
10
+ export { Trellis, TrellisServer } from "./trellis.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/trellis/index.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,YAAY,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAC1E,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EACL,SAAS,EACT,OAAO,EACP,WAAW,EACX,YAAY,EACZ,eAAe,EACf,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TrellisServer = exports.Trellis = exports.TypedKV = exports.ValidationError = exports.UnexpectedError = exports.TrellisError = exports.RemoteError = exports.KVError = exports.AuthError = exports.createClient = exports.Result = exports.ok = exports.isOk = exports.isErr = exports.err = void 0;
4
+ require("../_dnt.polyfills.js");
5
+ var trellis_result_1 = require("@qlever-llc/trellis-result");
6
+ Object.defineProperty(exports, "err", { enumerable: true, get: function () { return trellis_result_1.err; } });
7
+ Object.defineProperty(exports, "isErr", { enumerable: true, get: function () { return trellis_result_1.isErr; } });
8
+ Object.defineProperty(exports, "isOk", { enumerable: true, get: function () { return trellis_result_1.isOk; } });
9
+ Object.defineProperty(exports, "ok", { enumerable: true, get: function () { return trellis_result_1.ok; } });
10
+ Object.defineProperty(exports, "Result", { enumerable: true, get: function () { return trellis_result_1.Result; } });
11
+ var client_js_1 = require("./client.js");
12
+ Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_js_1.createClient; } });
13
+ var index_js_1 = require("./errors/index.js");
14
+ Object.defineProperty(exports, "AuthError", { enumerable: true, get: function () { return index_js_1.AuthError; } });
15
+ Object.defineProperty(exports, "KVError", { enumerable: true, get: function () { return index_js_1.KVError; } });
16
+ Object.defineProperty(exports, "RemoteError", { enumerable: true, get: function () { return index_js_1.RemoteError; } });
17
+ Object.defineProperty(exports, "TrellisError", { enumerable: true, get: function () { return index_js_1.TrellisError; } });
18
+ Object.defineProperty(exports, "UnexpectedError", { enumerable: true, get: function () { return index_js_1.UnexpectedError; } });
19
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return index_js_1.ValidationError; } });
20
+ var kv_js_1 = require("./kv.js");
21
+ Object.defineProperty(exports, "TypedKV", { enumerable: true, get: function () { return kv_js_1.TypedKV; } });
22
+ var trellis_js_1 = require("./trellis.js");
23
+ Object.defineProperty(exports, "Trellis", { enumerable: true, get: function () { return trellis_js_1.Trellis; } });
24
+ Object.defineProperty(exports, "TrellisServer", { enumerable: true, get: function () { return trellis_js_1.TrellisServer; } });
@@ -0,0 +1,67 @@
1
+ import { type KV, type KvEntry } from "@nats-io/kv";
2
+ import type { NatsConnection } from "@nats-io/nats-core/internal";
3
+ import { Result } from "@qlever-llc/trellis-result";
4
+ import type { StaticDecode, TSchema } from "typebox";
5
+ import { KVError, ValidationError } from "./errors/index.js";
6
+ /**
7
+ * Represents a watch event emitted when a KV entry changes.
8
+ */
9
+ export type WatchEvent<S extends TSchema> = {
10
+ /** The type of change: "update" for new/modified values, "delete" for deletions */
11
+ type: "update" | "delete";
12
+ /** The key that changed */
13
+ key: string;
14
+ /** The new value (only present for update events) */
15
+ value?: StaticDecode<S>;
16
+ /** The revision number of this change */
17
+ revision: number;
18
+ /** The timestamp when this change occurred */
19
+ timestamp: Date;
20
+ };
21
+ /**
22
+ * Options for the watch() method.
23
+ */
24
+ export type WatchOptions = {
25
+ /** If true, include delete events in the watch stream. Defaults to false. */
26
+ includeDeletes?: boolean;
27
+ };
28
+ export declare class TypedKV<S extends TSchema> {
29
+ readonly schema: S;
30
+ readonly kv: KV;
31
+ private constructor();
32
+ static open<S extends TSchema>(nats: NatsConnection, name: string, schema: S, options: {
33
+ history?: number;
34
+ ttl?: number;
35
+ bindOnly?: boolean;
36
+ maxValueBytes?: number;
37
+ }): Promise<Result<TypedKV<S>, KVError>>;
38
+ get(key: string): Promise<Result<TypedKVEntry<S>, KVError | ValidationError>>;
39
+ create(key: string, value: StaticDecode<S>): Promise<Result<void, KVError>>;
40
+ put(key: string, value: StaticDecode<S>): Promise<Result<void, KVError>>;
41
+ delete(key: string): Promise<Result<void, KVError>>;
42
+ keys(filter?: string | string[]): Promise<Result<AsyncIterable<string>, KVError>>;
43
+ status(): Promise<Result<{
44
+ values: number;
45
+ }, KVError>>;
46
+ }
47
+ export declare class TypedKVEntry<S extends TSchema> {
48
+ private schema;
49
+ private kv;
50
+ private entry;
51
+ readonly value: StaticDecode<S>;
52
+ constructor(schema: S, kv: KV, entry: KvEntry, value: StaticDecode<S>);
53
+ static create<S extends TSchema>(schema: S, kv: KV, entry: KvEntry): Promise<Result<TypedKVEntry<S>, ValidationError>>;
54
+ get key(): string;
55
+ /**
56
+ * Watch this KV entry for changes.
57
+ *
58
+ * @param callback - Function called when the entry changes
59
+ * @param opts - Watch options (e.g., includeDeletes)
60
+ * @returns A function to stop watching
61
+ */
62
+ watch(callback: (event: WatchEvent<S>) => void, opts?: WatchOptions): Promise<() => void>;
63
+ merge(value: Partial<StaticDecode<S>>, vcc?: boolean): Promise<Result<void, KVError | ValidationError>>;
64
+ put(value: StaticDecode<S>, vcc?: boolean): Promise<Result<void, KVError>>;
65
+ delete(vcc?: boolean): Promise<Result<void, KVError>>;
66
+ }
67
+ //# sourceMappingURL=kv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kv.d.ts","sourceRoot":"","sources":["../../src/trellis/kv.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,OAAO,EAAO,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAErD,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAqC7D;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,OAAO,IAAI;IAC1C,mFAAmF;IACnF,IAAI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