@roastery/terroir 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +226 -0
  3. package/dist/application-exception-Ck-CRA9W.d.cts +9 -0
  4. package/dist/application-exception-mi3iXk8r.d.ts +9 -0
  5. package/dist/chunk-EBPUXUYY.js +28 -0
  6. package/dist/chunk-N6MCTGZD.js +6 -0
  7. package/dist/chunk-UEZ4EF5Z.js +7 -0
  8. package/dist/chunk-WY3PDSMZ.js +27 -0
  9. package/dist/chunk-YBMFDZEW.js +53 -0
  10. package/dist/domain-exception-2mxDRlhr.d.ts +9 -0
  11. package/dist/domain-exception-BJknDTC7.d.cts +9 -0
  12. package/dist/exceptions/application/index.cjs +133 -0
  13. package/dist/exceptions/application/index.d.cts +6 -0
  14. package/dist/exceptions/application/index.d.ts +6 -0
  15. package/dist/exceptions/application/index.js +68 -0
  16. package/dist/exceptions/application/jwt/index.cjs +73 -0
  17. package/dist/exceptions/application/jwt/index.d.cts +20 -0
  18. package/dist/exceptions/application/jwt/index.d.ts +20 -0
  19. package/dist/exceptions/application/jwt/index.js +11 -0
  20. package/dist/{index.cjs → exceptions/core/index.cjs} +9 -8
  21. package/dist/exceptions/core/index.d.cts +11 -0
  22. package/dist/exceptions/core/index.d.ts +11 -0
  23. package/dist/exceptions/core/index.js +7 -0
  24. package/dist/exceptions/core/types/index.cjs +18 -0
  25. package/dist/exceptions/core/types/index.d.cts +3 -0
  26. package/dist/exceptions/core/types/index.d.ts +3 -0
  27. package/dist/exceptions/core/types/index.js +0 -0
  28. package/dist/exceptions/domain/index.cjs +86 -0
  29. package/dist/exceptions/domain/index.d.cts +5 -0
  30. package/dist/exceptions/domain/index.d.ts +5 -0
  31. package/dist/exceptions/domain/index.js +41 -0
  32. package/dist/exceptions/index.cjs +74 -0
  33. package/dist/exceptions/index.d.cts +4 -0
  34. package/dist/exceptions/index.d.ts +4 -0
  35. package/dist/exceptions/index.js +45 -0
  36. package/dist/exceptions/infra/index.cjs +158 -0
  37. package/dist/exceptions/infra/index.d.cts +5 -0
  38. package/dist/exceptions/infra/index.d.ts +5 -0
  39. package/dist/exceptions/infra/index.js +107 -0
  40. package/dist/exceptions/models/index.cjs +55 -0
  41. package/dist/exceptions/models/index.d.cts +6 -0
  42. package/dist/exceptions/models/index.d.ts +6 -0
  43. package/dist/exceptions/models/index.js +12 -0
  44. package/dist/exceptions/symbols/index.cjs +32 -0
  45. package/dist/exceptions/symbols/index.d.cts +3 -0
  46. package/dist/exceptions/symbols/index.d.ts +3 -0
  47. package/dist/exceptions/symbols/index.js +6 -0
  48. package/dist/exceptions/types/index.cjs +18 -0
  49. package/dist/exceptions/types/index.d.cts +30 -0
  50. package/dist/exceptions/types/index.d.ts +30 -0
  51. package/dist/exceptions/types/index.js +0 -0
  52. package/dist/index-0ZqtQ0BA.d.ts +89 -0
  53. package/dist/index-B_h1N1CO.d.cts +55 -0
  54. package/dist/index-C4-MCapS.d.ts +40 -0
  55. package/dist/index-CNApJ5kV.d.ts +35 -0
  56. package/dist/index-DaS_UsEv.d.cts +89 -0
  57. package/dist/index-E6KvVxtW.d.ts +55 -0
  58. package/dist/index-YFuBgYBS.d.cts +35 -0
  59. package/dist/index-g4_PChJX.d.cts +40 -0
  60. package/dist/infra-exception-1PUIDeP4.d.ts +9 -0
  61. package/dist/infra-exception-Dm1D9yrN.d.cts +9 -0
  62. package/dist/schema/formats/index.cjs +55 -0
  63. package/dist/schema/formats/index.d.cts +2 -0
  64. package/dist/schema/formats/index.d.ts +2 -0
  65. package/dist/schema/formats/index.js +1 -0
  66. package/dist/schema/index.cjs +193 -0
  67. package/dist/schema/index.d.cts +19 -0
  68. package/dist/schema/index.d.ts +19 -0
  69. package/dist/schema/index.js +113 -0
  70. package/package.json +61 -57
  71. package/dist/index.d.cts +0 -3
  72. package/dist/index.d.ts +0 -3
  73. package/dist/index.js +0 -5
@@ -0,0 +1,55 @@
1
+ import { A as ApplicationException } from './application-exception-mi3iXk8r.js';
2
+ import { InvalidJWTException, UnableToSignPayloadException } from './exceptions/application/jwt/index.js';
3
+
4
+ declare class ResourceAlreadyExistsException extends ApplicationException {
5
+ source: string;
6
+ message: string;
7
+ readonly name = "Resource Already Exists";
8
+ constructor(source: string, message?: string);
9
+ }
10
+
11
+ declare class ResourceNotFoundException extends ApplicationException {
12
+ source: string;
13
+ message: string;
14
+ readonly name = "Resource Not Found";
15
+ constructor(source: string, message?: string);
16
+ }
17
+
18
+ declare class BadRequestException extends ApplicationException {
19
+ source: string;
20
+ message: string;
21
+ readonly name = "Bad Request";
22
+ constructor(source: string, message?: string);
23
+ }
24
+
25
+ declare class UnauthorizedException extends ApplicationException {
26
+ source: string;
27
+ message: string;
28
+ readonly name = "Unauthorized";
29
+ constructor(source: string, message?: string);
30
+ }
31
+
32
+ declare class InvalidOperationException extends ApplicationException {
33
+ source: string;
34
+ message: string;
35
+ readonly name = "Invalid Operation";
36
+ constructor(source: string, message?: string);
37
+ }
38
+
39
+ type ApplicationExceptions_BadRequestException = BadRequestException;
40
+ declare const ApplicationExceptions_BadRequestException: typeof BadRequestException;
41
+ declare const ApplicationExceptions_InvalidJWTException: typeof InvalidJWTException;
42
+ type ApplicationExceptions_InvalidOperationException = InvalidOperationException;
43
+ declare const ApplicationExceptions_InvalidOperationException: typeof InvalidOperationException;
44
+ type ApplicationExceptions_ResourceAlreadyExistsException = ResourceAlreadyExistsException;
45
+ declare const ApplicationExceptions_ResourceAlreadyExistsException: typeof ResourceAlreadyExistsException;
46
+ type ApplicationExceptions_ResourceNotFoundException = ResourceNotFoundException;
47
+ declare const ApplicationExceptions_ResourceNotFoundException: typeof ResourceNotFoundException;
48
+ declare const ApplicationExceptions_UnableToSignPayloadException: typeof UnableToSignPayloadException;
49
+ type ApplicationExceptions_UnauthorizedException = UnauthorizedException;
50
+ declare const ApplicationExceptions_UnauthorizedException: typeof UnauthorizedException;
51
+ declare namespace ApplicationExceptions {
52
+ export { ApplicationExceptions_BadRequestException as BadRequestException, ApplicationExceptions_InvalidJWTException as InvalidJWTException, ApplicationExceptions_InvalidOperationException as InvalidOperationException, ApplicationExceptions_ResourceAlreadyExistsException as ResourceAlreadyExistsException, ApplicationExceptions_ResourceNotFoundException as ResourceNotFoundException, ApplicationExceptions_UnableToSignPayloadException as UnableToSignPayloadException, ApplicationExceptions_UnauthorizedException as UnauthorizedException };
53
+ }
54
+
55
+ export { ApplicationExceptions as A, BadRequestException as B, InvalidOperationException as I, ResourceAlreadyExistsException as R, UnauthorizedException as U, ResourceNotFoundException as a };
@@ -0,0 +1,35 @@
1
+ import { D as DomainException } from './domain-exception-BJknDTC7.cjs';
2
+
3
+ declare class InvalidDomainDataException extends DomainException {
4
+ source: string;
5
+ message: string;
6
+ readonly name = "Invalid Domain Data";
7
+ constructor(source: string, message?: string);
8
+ }
9
+
10
+ declare class OperationFailedException extends DomainException {
11
+ source: string;
12
+ message: string;
13
+ readonly name = "Operation Failed";
14
+ constructor(source: string, message?: string);
15
+ }
16
+
17
+ declare class InvalidPropertyException extends DomainException {
18
+ readonly property: string;
19
+ readonly source: string;
20
+ readonly message: string;
21
+ readonly name = "Invalid Property";
22
+ constructor(property: string, source: string, message?: string);
23
+ }
24
+
25
+ type DomainExceptions_InvalidDomainDataException = InvalidDomainDataException;
26
+ declare const DomainExceptions_InvalidDomainDataException: typeof InvalidDomainDataException;
27
+ type DomainExceptions_InvalidPropertyException = InvalidPropertyException;
28
+ declare const DomainExceptions_InvalidPropertyException: typeof InvalidPropertyException;
29
+ type DomainExceptions_OperationFailedException = OperationFailedException;
30
+ declare const DomainExceptions_OperationFailedException: typeof OperationFailedException;
31
+ declare namespace DomainExceptions {
32
+ export { DomainExceptions_InvalidDomainDataException as InvalidDomainDataException, DomainExceptions_InvalidPropertyException as InvalidPropertyException, DomainExceptions_OperationFailedException as OperationFailedException };
33
+ }
34
+
35
+ export { DomainExceptions as D, InvalidDomainDataException as I, OperationFailedException as O, InvalidPropertyException as a };
@@ -0,0 +1,40 @@
1
+ import { CoreException } from './exceptions/core/index.cjs';
2
+ import { CoreExceptionType } from './exceptions/core/types/index.cjs';
3
+ import { ExceptionLayer } from './exceptions/symbols/index.cjs';
4
+
5
+ declare class InvalidEntityData extends CoreException {
6
+ message: string;
7
+ readonly [ExceptionLayer]: CoreExceptionType;
8
+ name: string;
9
+ source: string;
10
+ constructor(message?: string);
11
+ }
12
+
13
+ declare class InvalidObjectValueException extends CoreException {
14
+ objectValueName: string;
15
+ message: string;
16
+ readonly [ExceptionLayer]: CoreExceptionType;
17
+ readonly name = "Invalid Object Value";
18
+ source: string;
19
+ constructor(objectValueName: string, message?: string);
20
+ }
21
+
22
+ declare class UnknownException extends CoreException {
23
+ message: string;
24
+ readonly [ExceptionLayer]: CoreExceptionType;
25
+ name: string;
26
+ source: string;
27
+ constructor(message?: string);
28
+ }
29
+
30
+ type InternalErrors_InvalidEntityData = InvalidEntityData;
31
+ declare const InternalErrors_InvalidEntityData: typeof InvalidEntityData;
32
+ type InternalErrors_InvalidObjectValueException = InvalidObjectValueException;
33
+ declare const InternalErrors_InvalidObjectValueException: typeof InvalidObjectValueException;
34
+ type InternalErrors_UnknownException = UnknownException;
35
+ declare const InternalErrors_UnknownException: typeof UnknownException;
36
+ declare namespace InternalErrors {
37
+ export { InternalErrors_InvalidEntityData as InvalidEntityData, InternalErrors_InvalidObjectValueException as InvalidObjectValueException, InternalErrors_UnknownException as UnknownException };
38
+ }
39
+
40
+ export { InternalErrors as I, UnknownException as U, InvalidEntityData as a, InvalidObjectValueException as b };
@@ -0,0 +1,9 @@
1
+ import { ExceptionLayer } from './exceptions/symbols/index.js';
2
+ import { CoreException } from './exceptions/core/index.js';
3
+ import { CoreExceptionType } from './exceptions/core/types/index.js';
4
+
5
+ declare abstract class InfraException extends CoreException {
6
+ readonly [ExceptionLayer]: CoreExceptionType;
7
+ }
8
+
9
+ export { InfraException as I };
@@ -0,0 +1,9 @@
1
+ import { ExceptionLayer } from './exceptions/symbols/index.cjs';
2
+ import { CoreException } from './exceptions/core/index.cjs';
3
+ import { CoreExceptionType } from './exceptions/core/types/index.cjs';
4
+
5
+ declare abstract class InfraException extends CoreException {
6
+ readonly [ExceptionLayer]: CoreExceptionType;
7
+ }
8
+
9
+ export { InfraException as I };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ // src/schema/formats/date-time.ts
4
+ var import_typebox = require("@sinclair/typebox");
5
+ import_typebox.FormatRegistry.Set("date-time", (value) => {
6
+ return !Number.isNaN(Date.parse(value));
7
+ });
8
+
9
+ // src/schema/formats/url.ts
10
+ var import_typebox2 = require("@sinclair/typebox");
11
+ import_typebox2.FormatRegistry.Set("url", (value) => {
12
+ try {
13
+ const url = new URL(value);
14
+ return url.hostname.includes(".");
15
+ } catch {
16
+ return false;
17
+ }
18
+ });
19
+
20
+ // src/schema/formats/uuid.ts
21
+ var import_typebox3 = require("@sinclair/typebox");
22
+ var import_uuid = require("uuid");
23
+ import_typebox3.FormatRegistry.Set("uuid", (value) => (0, import_uuid.validate)(value) && (0, import_uuid.version)(value) === 7);
24
+
25
+ // src/schema/formats/slug.ts
26
+ var import_typebox4 = require("@sinclair/typebox");
27
+ var slugPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
28
+ import_typebox4.FormatRegistry.Set("slug", (value) => slugPattern.test(value));
29
+
30
+ // src/schema/formats/email.ts
31
+ var import_typebox5 = require("@sinclair/typebox");
32
+ var emailPattern = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/i;
33
+ import_typebox5.FormatRegistry.Set("email", (value) => emailPattern.test(value));
34
+
35
+ // src/schema/formats/json.ts
36
+ var import_typebox6 = require("@sinclair/typebox");
37
+ import_typebox6.FormatRegistry.Set("json", (value) => {
38
+ try {
39
+ JSON.parse(value);
40
+ return true;
41
+ } catch {
42
+ return false;
43
+ }
44
+ });
45
+
46
+ // src/schema/formats/simple-url.ts
47
+ var import_typebox7 = require("@sinclair/typebox");
48
+ import_typebox7.FormatRegistry.Set("simple-url", (value) => {
49
+ try {
50
+ new URL(value);
51
+ return true;
52
+ } catch {
53
+ return false;
54
+ }
55
+ });
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1 @@
1
+ import "../../chunk-YBMFDZEW.js";
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/schema/index.ts
21
+ var schema_exports = {};
22
+ __export(schema_exports, {
23
+ Schema: () => Schema,
24
+ SchemaManager: () => SchemaManager
25
+ });
26
+ module.exports = __toCommonJS(schema_exports);
27
+
28
+ // src/schema/formats/date-time.ts
29
+ var import_typebox = require("@sinclair/typebox");
30
+ import_typebox.FormatRegistry.Set("date-time", (value) => {
31
+ return !Number.isNaN(Date.parse(value));
32
+ });
33
+
34
+ // src/schema/formats/url.ts
35
+ var import_typebox2 = require("@sinclair/typebox");
36
+ import_typebox2.FormatRegistry.Set("url", (value) => {
37
+ try {
38
+ const url = new URL(value);
39
+ return url.hostname.includes(".");
40
+ } catch {
41
+ return false;
42
+ }
43
+ });
44
+
45
+ // src/schema/formats/uuid.ts
46
+ var import_typebox3 = require("@sinclair/typebox");
47
+ var import_uuid = require("uuid");
48
+ import_typebox3.FormatRegistry.Set("uuid", (value) => (0, import_uuid.validate)(value) && (0, import_uuid.version)(value) === 7);
49
+
50
+ // src/schema/formats/slug.ts
51
+ var import_typebox4 = require("@sinclair/typebox");
52
+ var slugPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
53
+ import_typebox4.FormatRegistry.Set("slug", (value) => slugPattern.test(value));
54
+
55
+ // src/schema/formats/email.ts
56
+ var import_typebox5 = require("@sinclair/typebox");
57
+ var emailPattern = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/i;
58
+ import_typebox5.FormatRegistry.Set("email", (value) => emailPattern.test(value));
59
+
60
+ // src/schema/formats/json.ts
61
+ var import_typebox6 = require("@sinclair/typebox");
62
+ import_typebox6.FormatRegistry.Set("json", (value) => {
63
+ try {
64
+ JSON.parse(value);
65
+ return true;
66
+ } catch {
67
+ return false;
68
+ }
69
+ });
70
+
71
+ // src/schema/formats/simple-url.ts
72
+ var import_typebox7 = require("@sinclair/typebox");
73
+ import_typebox7.FormatRegistry.Set("simple-url", (value) => {
74
+ try {
75
+ new URL(value);
76
+ return true;
77
+ } catch {
78
+ return false;
79
+ }
80
+ });
81
+
82
+ // src/schema/schema.ts
83
+ var import_value = require("@sinclair/typebox/value");
84
+ var import_compiler = require("@sinclair/typebox/compiler");
85
+ var Schema = class _Schema {
86
+ constructor(schema) {
87
+ this.schema = schema;
88
+ this.compiledSchema = import_compiler.TypeCompiler.Compile(this.schema);
89
+ }
90
+ compiledSchema;
91
+ static make(schema) {
92
+ return new _Schema(schema);
93
+ }
94
+ match(content) {
95
+ return this.compiledSchema.Check(content);
96
+ }
97
+ map(content) {
98
+ return import_value.Value.Clean(
99
+ this.schema,
100
+ import_value.Value.Cast(this.schema, import_value.Value.Convert(this.schema, content))
101
+ );
102
+ }
103
+ toString() {
104
+ return JSON.stringify(this.schema);
105
+ }
106
+ toJSON() {
107
+ return this.schema;
108
+ }
109
+ };
110
+
111
+ // src/schema/schema-manager.ts
112
+ var import_compiler2 = require("@sinclair/typebox/compiler");
113
+
114
+ // src/schema/utils/hydrate-schema.ts
115
+ var import_type = require("@sinclair/typebox/type");
116
+ function hydrateSchema(schema) {
117
+ if (typeof schema !== "object" || schema === null) return schema;
118
+ if (Array.isArray(schema)) return schema.map(hydrateSchema);
119
+ const newSchema = { ...schema };
120
+ if (newSchema.properties) {
121
+ for (const key in newSchema.properties) {
122
+ newSchema.properties[key] = hydrateSchema(newSchema.properties[key]);
123
+ }
124
+ }
125
+ if (newSchema.items) {
126
+ newSchema.items = hydrateSchema(newSchema.items);
127
+ }
128
+ if (newSchema.additionalProperties && typeof newSchema.additionalProperties === "object") {
129
+ newSchema.additionalProperties = hydrateSchema(
130
+ newSchema.additionalProperties
131
+ );
132
+ }
133
+ if (newSchema.anyOf) newSchema.anyOf = newSchema.anyOf.map(hydrateSchema);
134
+ if (newSchema.allOf) newSchema.allOf = newSchema.allOf.map(hydrateSchema);
135
+ if (newSchema.oneOf) newSchema.oneOf = newSchema.oneOf.map(hydrateSchema);
136
+ if (newSchema.not) newSchema.not = hydrateSchema(newSchema.not);
137
+ if (newSchema.type === "string") newSchema[import_type.Kind] = "String";
138
+ else if (newSchema.type === "number") newSchema[import_type.Kind] = "Number";
139
+ else if (newSchema.type === "integer") newSchema[import_type.Kind] = "Integer";
140
+ else if (newSchema.type === "boolean") newSchema[import_type.Kind] = "Boolean";
141
+ else if (newSchema.type === "array") newSchema[import_type.Kind] = "Array";
142
+ else if (newSchema.type === "object") newSchema[import_type.Kind] = "Object";
143
+ else if (newSchema.type === "null") newSchema[import_type.Kind] = "Null";
144
+ if (newSchema.anyOf) newSchema[import_type.Kind] = "Union";
145
+ if (newSchema.allOf) newSchema[import_type.Kind] = "Intersect";
146
+ if (newSchema.not) newSchema[import_type.Kind] = "Not";
147
+ if (newSchema.const !== void 0) newSchema[import_type.Kind] = "Literal";
148
+ if (newSchema.type === "array" && Array.isArray(newSchema.items)) {
149
+ newSchema[import_type.Kind] = "Tuple";
150
+ }
151
+ if (newSchema.type === "object" && newSchema.patternProperties && !newSchema.properties) {
152
+ newSchema[import_type.Kind] = "Record";
153
+ for (const key in newSchema.patternProperties) {
154
+ newSchema.patternProperties[key] = hydrateSchema(
155
+ newSchema.patternProperties[key]
156
+ );
157
+ }
158
+ } else if (newSchema.patternProperties) {
159
+ for (const key in newSchema.patternProperties) {
160
+ newSchema.patternProperties[key] = hydrateSchema(
161
+ newSchema.patternProperties[key]
162
+ );
163
+ }
164
+ }
165
+ if (Object.keys(newSchema).length === 0) {
166
+ newSchema[import_type.Kind] = "Any";
167
+ }
168
+ return newSchema;
169
+ }
170
+
171
+ // src/schema/schema-manager.ts
172
+ var SchemaManager = {
173
+ build(schema) {
174
+ const parsedSchema = JSON.parse(schema);
175
+ const hydrated = hydrateSchema(parsedSchema);
176
+ return new Schema(hydrated);
177
+ },
178
+ isSchema(schema) {
179
+ try {
180
+ if (typeof schema === "string") schema = JSON.parse(schema);
181
+ const hydrated = hydrateSchema(schema);
182
+ import_compiler2.TypeCompiler.Compile(hydrated);
183
+ return true;
184
+ } catch (_) {
185
+ return false;
186
+ }
187
+ }
188
+ };
189
+ // Annotate the CommonJS export names for ESM import in node:
190
+ 0 && (module.exports = {
191
+ Schema,
192
+ SchemaManager
193
+ });
@@ -0,0 +1,19 @@
1
+ import { TSchema, Static } from '@sinclair/typebox';
2
+
3
+ declare class Schema<SchemaType extends TSchema> {
4
+ private schema;
5
+ private compiledSchema;
6
+ constructor(schema: SchemaType);
7
+ static make<SchemaType extends TSchema>(schema: SchemaType): Schema<SchemaType>;
8
+ match(content: unknown): boolean;
9
+ map(content: unknown): Static<SchemaType>;
10
+ toString(): string;
11
+ toJSON(): typeof this.schema;
12
+ }
13
+
14
+ declare const SchemaManager: {
15
+ build<SchemaType extends TSchema>(schema: string): Schema<SchemaType>;
16
+ isSchema(schema: unknown): boolean;
17
+ };
18
+
19
+ export { Schema, SchemaManager };
@@ -0,0 +1,19 @@
1
+ import { TSchema, Static } from '@sinclair/typebox';
2
+
3
+ declare class Schema<SchemaType extends TSchema> {
4
+ private schema;
5
+ private compiledSchema;
6
+ constructor(schema: SchemaType);
7
+ static make<SchemaType extends TSchema>(schema: SchemaType): Schema<SchemaType>;
8
+ match(content: unknown): boolean;
9
+ map(content: unknown): Static<SchemaType>;
10
+ toString(): string;
11
+ toJSON(): typeof this.schema;
12
+ }
13
+
14
+ declare const SchemaManager: {
15
+ build<SchemaType extends TSchema>(schema: string): Schema<SchemaType>;
16
+ isSchema(schema: unknown): boolean;
17
+ };
18
+
19
+ export { Schema, SchemaManager };
@@ -0,0 +1,113 @@
1
+ import "../chunk-YBMFDZEW.js";
2
+
3
+ // src/schema/schema.ts
4
+ import { Value } from "@sinclair/typebox/value";
5
+ import { TypeCompiler } from "@sinclair/typebox/compiler";
6
+ var Schema = class _Schema {
7
+ constructor(schema) {
8
+ this.schema = schema;
9
+ this.compiledSchema = TypeCompiler.Compile(this.schema);
10
+ }
11
+ compiledSchema;
12
+ static make(schema) {
13
+ return new _Schema(schema);
14
+ }
15
+ match(content) {
16
+ return this.compiledSchema.Check(content);
17
+ }
18
+ map(content) {
19
+ return Value.Clean(
20
+ this.schema,
21
+ Value.Cast(this.schema, Value.Convert(this.schema, content))
22
+ );
23
+ }
24
+ toString() {
25
+ return JSON.stringify(this.schema);
26
+ }
27
+ toJSON() {
28
+ return this.schema;
29
+ }
30
+ };
31
+
32
+ // src/schema/schema-manager.ts
33
+ import { TypeCompiler as TypeCompiler2 } from "@sinclair/typebox/compiler";
34
+
35
+ // src/schema/utils/hydrate-schema.ts
36
+ import { Kind } from "@sinclair/typebox/type";
37
+ function hydrateSchema(schema) {
38
+ if (typeof schema !== "object" || schema === null) return schema;
39
+ if (Array.isArray(schema)) return schema.map(hydrateSchema);
40
+ const newSchema = { ...schema };
41
+ if (newSchema.properties) {
42
+ for (const key in newSchema.properties) {
43
+ newSchema.properties[key] = hydrateSchema(newSchema.properties[key]);
44
+ }
45
+ }
46
+ if (newSchema.items) {
47
+ newSchema.items = hydrateSchema(newSchema.items);
48
+ }
49
+ if (newSchema.additionalProperties && typeof newSchema.additionalProperties === "object") {
50
+ newSchema.additionalProperties = hydrateSchema(
51
+ newSchema.additionalProperties
52
+ );
53
+ }
54
+ if (newSchema.anyOf) newSchema.anyOf = newSchema.anyOf.map(hydrateSchema);
55
+ if (newSchema.allOf) newSchema.allOf = newSchema.allOf.map(hydrateSchema);
56
+ if (newSchema.oneOf) newSchema.oneOf = newSchema.oneOf.map(hydrateSchema);
57
+ if (newSchema.not) newSchema.not = hydrateSchema(newSchema.not);
58
+ if (newSchema.type === "string") newSchema[Kind] = "String";
59
+ else if (newSchema.type === "number") newSchema[Kind] = "Number";
60
+ else if (newSchema.type === "integer") newSchema[Kind] = "Integer";
61
+ else if (newSchema.type === "boolean") newSchema[Kind] = "Boolean";
62
+ else if (newSchema.type === "array") newSchema[Kind] = "Array";
63
+ else if (newSchema.type === "object") newSchema[Kind] = "Object";
64
+ else if (newSchema.type === "null") newSchema[Kind] = "Null";
65
+ if (newSchema.anyOf) newSchema[Kind] = "Union";
66
+ if (newSchema.allOf) newSchema[Kind] = "Intersect";
67
+ if (newSchema.not) newSchema[Kind] = "Not";
68
+ if (newSchema.const !== void 0) newSchema[Kind] = "Literal";
69
+ if (newSchema.type === "array" && Array.isArray(newSchema.items)) {
70
+ newSchema[Kind] = "Tuple";
71
+ }
72
+ if (newSchema.type === "object" && newSchema.patternProperties && !newSchema.properties) {
73
+ newSchema[Kind] = "Record";
74
+ for (const key in newSchema.patternProperties) {
75
+ newSchema.patternProperties[key] = hydrateSchema(
76
+ newSchema.patternProperties[key]
77
+ );
78
+ }
79
+ } else if (newSchema.patternProperties) {
80
+ for (const key in newSchema.patternProperties) {
81
+ newSchema.patternProperties[key] = hydrateSchema(
82
+ newSchema.patternProperties[key]
83
+ );
84
+ }
85
+ }
86
+ if (Object.keys(newSchema).length === 0) {
87
+ newSchema[Kind] = "Any";
88
+ }
89
+ return newSchema;
90
+ }
91
+
92
+ // src/schema/schema-manager.ts
93
+ var SchemaManager = {
94
+ build(schema) {
95
+ const parsedSchema = JSON.parse(schema);
96
+ const hydrated = hydrateSchema(parsedSchema);
97
+ return new Schema(hydrated);
98
+ },
99
+ isSchema(schema) {
100
+ try {
101
+ if (typeof schema === "string") schema = JSON.parse(schema);
102
+ const hydrated = hydrateSchema(schema);
103
+ TypeCompiler2.Compile(hydrated);
104
+ return true;
105
+ } catch (_) {
106
+ return false;
107
+ }
108
+ }
109
+ };
110
+ export {
111
+ Schema,
112
+ SchemaManager
113
+ };