@beignet/core 0.0.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.
- package/CHANGELOG.md +5 -0
- package/README.md +288 -0
- package/dist/application/index.d.ts +260 -0
- package/dist/application/index.d.ts.map +1 -0
- package/dist/application/index.js +324 -0
- package/dist/application/index.js.map +1 -0
- package/dist/client/client.d.ts +241 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +531 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/index.d.ts +10 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +8 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +139 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +2 -0
- package/dist/client/types.js.map +1 -0
- package/dist/config/index.d.ts +122 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +216 -0
- package/dist/config/index.js.map +1 -0
- package/dist/contracts/contract-builder.d.ts +121 -0
- package/dist/contracts/contract-builder.d.ts.map +1 -0
- package/dist/contracts/contract-builder.js +346 -0
- package/dist/contracts/contract-builder.js.map +1 -0
- package/dist/contracts/contract-group.d.ts +106 -0
- package/dist/contracts/contract-group.d.ts.map +1 -0
- package/dist/contracts/contract-group.js +240 -0
- package/dist/contracts/contract-group.js.map +1 -0
- package/dist/contracts/contract-like.d.ts +21 -0
- package/dist/contracts/contract-like.d.ts.map +1 -0
- package/dist/contracts/contract-like.js +9 -0
- package/dist/contracts/contract-like.js.map +1 -0
- package/dist/contracts/index.d.ts +15 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +11 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/contracts/openapi-meta.d.ts +23 -0
- package/dist/contracts/openapi-meta.d.ts.map +1 -0
- package/dist/contracts/openapi-meta.js +2 -0
- package/dist/contracts/openapi-meta.js.map +1 -0
- package/dist/contracts/path-template.d.ts +17 -0
- package/dist/contracts/path-template.d.ts.map +1 -0
- package/dist/contracts/path-template.js +50 -0
- package/dist/contracts/path-template.js.map +1 -0
- package/dist/contracts/rate-limit.d.ts +50 -0
- package/dist/contracts/rate-limit.d.ts.map +1 -0
- package/dist/contracts/rate-limit.js +2 -0
- package/dist/contracts/rate-limit.js.map +1 -0
- package/dist/contracts/types.d.ts +97 -0
- package/dist/contracts/types.d.ts.map +1 -0
- package/dist/contracts/types.js +54 -0
- package/dist/contracts/types.js.map +1 -0
- package/dist/contracts/utils.d.ts +3 -0
- package/dist/contracts/utils.d.ts.map +1 -0
- package/dist/contracts/utils.js +44 -0
- package/dist/contracts/utils.js.map +1 -0
- package/dist/domain/entity.d.ts +87 -0
- package/dist/domain/entity.d.ts.map +1 -0
- package/dist/domain/entity.js +155 -0
- package/dist/domain/entity.js.map +1 -0
- package/dist/domain/events.d.ts +41 -0
- package/dist/domain/events.d.ts.map +1 -0
- package/dist/domain/events.js +21 -0
- package/dist/domain/events.js.map +1 -0
- package/dist/domain/index.d.ts +14 -0
- package/dist/domain/index.d.ts.map +1 -0
- package/dist/domain/index.js +14 -0
- package/dist/domain/index.js.map +1 -0
- package/dist/domain/value-object.d.ts +60 -0
- package/dist/domain/value-object.d.ts.map +1 -0
- package/dist/domain/value-object.js +87 -0
- package/dist/domain/value-object.js.map +1 -0
- package/dist/errors/catalog.d.ts +71 -0
- package/dist/errors/catalog.d.ts.map +1 -0
- package/dist/errors/catalog.js +71 -0
- package/dist/errors/catalog.js.map +1 -0
- package/dist/errors/http.d.ts +77 -0
- package/dist/errors/http.d.ts.map +1 -0
- package/dist/errors/http.js +74 -0
- package/dist/errors/http.js.map +1 -0
- package/dist/errors/index.d.ts +10 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +14 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/response.d.ts +26 -0
- package/dist/errors/response.d.ts.map +1 -0
- package/dist/errors/response.js +34 -0
- package/dist/errors/response.js.map +1 -0
- package/dist/errors/validation.d.ts +18 -0
- package/dist/errors/validation.d.ts.map +1 -0
- package/dist/errors/validation.js +21 -0
- package/dist/errors/validation.js.map +1 -0
- package/dist/events/index.d.ts +58 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +102 -0
- package/dist/events/index.js.map +1 -0
- package/dist/jobs/index.d.ts +56 -0
- package/dist/jobs/index.d.ts.map +1 -0
- package/dist/jobs/index.js +89 -0
- package/dist/jobs/index.js.map +1 -0
- package/dist/mail/index.d.ts +75 -0
- package/dist/mail/index.d.ts.map +1 -0
- package/dist/mail/index.js +84 -0
- package/dist/mail/index.js.map +1 -0
- package/dist/openapi/index.d.ts +207 -0
- package/dist/openapi/index.d.ts.map +1 -0
- package/dist/openapi/index.js +449 -0
- package/dist/openapi/index.js.map +1 -0
- package/dist/openapi/schema-introspector.d.ts +38 -0
- package/dist/openapi/schema-introspector.d.ts.map +1 -0
- package/dist/openapi/schema-introspector.js +67 -0
- package/dist/openapi/schema-introspector.js.map +1 -0
- package/dist/ports/audit.d.ts +58 -0
- package/dist/ports/audit.d.ts.map +1 -0
- package/dist/ports/audit.js +74 -0
- package/dist/ports/audit.js.map +1 -0
- package/dist/ports/auth.d.ts +23 -0
- package/dist/ports/auth.d.ts.map +1 -0
- package/dist/ports/auth.js +31 -0
- package/dist/ports/auth.js.map +1 -0
- package/dist/ports/builder.d.ts +61 -0
- package/dist/ports/builder.d.ts.map +1 -0
- package/dist/ports/builder.js +48 -0
- package/dist/ports/builder.js.map +1 -0
- package/dist/ports/cache.d.ts +15 -0
- package/dist/ports/cache.d.ts.map +1 -0
- package/dist/ports/cache.js +57 -0
- package/dist/ports/cache.js.map +1 -0
- package/dist/ports/clock.d.ts +10 -0
- package/dist/ports/clock.d.ts.map +1 -0
- package/dist/ports/clock.js +21 -0
- package/dist/ports/clock.js.map +1 -0
- package/dist/ports/events.d.ts +71 -0
- package/dist/ports/events.d.ts.map +1 -0
- package/dist/ports/events.js +2 -0
- package/dist/ports/events.js.map +1 -0
- package/dist/ports/id-generator.d.ts +12 -0
- package/dist/ports/id-generator.d.ts.map +1 -0
- package/dist/ports/id-generator.js +22 -0
- package/dist/ports/id-generator.js.map +1 -0
- package/dist/ports/index.d.ts +98 -0
- package/dist/ports/index.d.ts.map +1 -0
- package/dist/ports/index.js +67 -0
- package/dist/ports/index.js.map +1 -0
- package/dist/ports/logger.d.ts +22 -0
- package/dist/ports/logger.d.ts.map +1 -0
- package/dist/ports/logger.js +34 -0
- package/dist/ports/logger.js.map +1 -0
- package/dist/ports/mailer.d.ts +6 -0
- package/dist/ports/mailer.d.ts.map +1 -0
- package/dist/ports/mailer.js +2 -0
- package/dist/ports/mailer.js.map +1 -0
- package/dist/ports/policy.d.ts +53 -0
- package/dist/ports/policy.d.ts.map +1 -0
- package/dist/ports/policy.js +81 -0
- package/dist/ports/policy.js.map +1 -0
- package/dist/ports/rate-limit.d.ts +41 -0
- package/dist/ports/rate-limit.d.ts.map +1 -0
- package/dist/ports/rate-limit.js +37 -0
- package/dist/ports/rate-limit.js.map +1 -0
- package/dist/ports/redaction.d.ts +26 -0
- package/dist/ports/redaction.d.ts.map +1 -0
- package/dist/ports/redaction.js +126 -0
- package/dist/ports/redaction.js.map +1 -0
- package/dist/ports/schedules.d.ts +9 -0
- package/dist/ports/schedules.d.ts.map +1 -0
- package/dist/ports/schedules.js +2 -0
- package/dist/ports/schedules.js.map +1 -0
- package/dist/ports/storage.d.ts +47 -0
- package/dist/ports/storage.d.ts.map +1 -0
- package/dist/ports/storage.js +185 -0
- package/dist/ports/storage.js.map +1 -0
- package/dist/ports/testing.d.ts +73 -0
- package/dist/ports/testing.d.ts.map +1 -0
- package/dist/ports/testing.js +105 -0
- package/dist/ports/testing.js.map +1 -0
- package/dist/ports/unit-of-work.d.ts +56 -0
- package/dist/ports/unit-of-work.d.ts.map +1 -0
- package/dist/ports/unit-of-work.js +64 -0
- package/dist/ports/unit-of-work.js.map +1 -0
- package/dist/providers/index.d.ts +8 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +8 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/instrumentation.d.ts +91 -0
- package/dist/providers/instrumentation.d.ts.map +1 -0
- package/dist/providers/instrumentation.js +93 -0
- package/dist/providers/instrumentation.js.map +1 -0
- package/dist/providers/provider.d.ts +146 -0
- package/dist/providers/provider.d.ts.map +1 -0
- package/dist/providers/provider.js +31 -0
- package/dist/providers/provider.js.map +1 -0
- package/dist/schedules/index.d.ts +105 -0
- package/dist/schedules/index.d.ts.map +1 -0
- package/dist/schedules/index.js +178 -0
- package/dist/schedules/index.js.map +1 -0
- package/dist/server/contract-like.d.ts +5 -0
- package/dist/server/contract-like.d.ts.map +1 -0
- package/dist/server/contract-like.js +5 -0
- package/dist/server/contract-like.js.map +1 -0
- package/dist/server/health.d.ts +41 -0
- package/dist/server/health.d.ts.map +1 -0
- package/dist/server/health.js +46 -0
- package/dist/server/health.js.map +1 -0
- package/dist/server/hooks/auth.d.ts +42 -0
- package/dist/server/hooks/auth.d.ts.map +1 -0
- package/dist/server/hooks/auth.js +61 -0
- package/dist/server/hooks/auth.js.map +1 -0
- package/dist/server/hooks/cors.d.ts +13 -0
- package/dist/server/hooks/cors.d.ts.map +1 -0
- package/dist/server/hooks/cors.js +70 -0
- package/dist/server/hooks/cors.js.map +1 -0
- package/dist/server/hooks/errors.d.ts +66 -0
- package/dist/server/hooks/errors.d.ts.map +1 -0
- package/dist/server/hooks/errors.js +83 -0
- package/dist/server/hooks/errors.js.map +1 -0
- package/dist/server/hooks/index.d.ts +12 -0
- package/dist/server/hooks/index.d.ts.map +1 -0
- package/dist/server/hooks/index.js +12 -0
- package/dist/server/hooks/index.js.map +1 -0
- package/dist/server/hooks/logging.d.ts +33 -0
- package/dist/server/hooks/logging.d.ts.map +1 -0
- package/dist/server/hooks/logging.js +90 -0
- package/dist/server/hooks/logging.js.map +1 -0
- package/dist/server/hooks/rate-limit.d.ts +29 -0
- package/dist/server/hooks/rate-limit.d.ts.map +1 -0
- package/dist/server/hooks/rate-limit.js +93 -0
- package/dist/server/hooks/rate-limit.js.map +1 -0
- package/dist/server/hooks/utils.d.ts +9 -0
- package/dist/server/hooks/utils.d.ts.map +1 -0
- package/dist/server/hooks/utils.js +16 -0
- package/dist/server/hooks/utils.js.map +1 -0
- package/dist/server/hooks.d.ts +2 -0
- package/dist/server/hooks.d.ts.map +1 -0
- package/dist/server/hooks.js +2 -0
- package/dist/server/hooks.js.map +1 -0
- package/dist/server/http.d.ts +124 -0
- package/dist/server/http.d.ts.map +1 -0
- package/dist/server/http.js +2 -0
- package/dist/server/http.js.map +1 -0
- package/dist/server/index.d.ts +19 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +15 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/openapi.d.ts +32 -0
- package/dist/server/openapi.d.ts.map +1 -0
- package/dist/server/openapi.js +43 -0
- package/dist/server/openapi.js.map +1 -0
- package/dist/server/providers/index.d.ts +4 -0
- package/dist/server/providers/index.d.ts.map +1 -0
- package/dist/server/providers/index.js +4 -0
- package/dist/server/providers/index.js.map +1 -0
- package/dist/server/providers/loadProviderConfig.d.ts +7 -0
- package/dist/server/providers/loadProviderConfig.d.ts.map +1 -0
- package/dist/server/providers/loadProviderConfig.js +42 -0
- package/dist/server/providers/loadProviderConfig.js.map +1 -0
- package/dist/server/server.d.ts +86 -0
- package/dist/server/server.d.ts.map +1 -0
- package/dist/server/server.js +1031 -0
- package/dist/server/server.js.map +1 -0
- package/dist/server/types.d.ts +3 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server/types.js +3 -0
- package/dist/server/types.js.map +1 -0
- package/package.json +129 -0
- package/src/application/index.ts +747 -0
- package/src/client/client.ts +1105 -0
- package/src/client/index.ts +45 -0
- package/src/client/types.ts +305 -0
- package/src/config/index.ts +497 -0
- package/src/contracts/contract-builder.ts +583 -0
- package/src/contracts/contract-group.ts +502 -0
- package/src/contracts/contract-like.ts +29 -0
- package/src/contracts/index.ts +53 -0
- package/src/contracts/openapi-meta.ts +22 -0
- package/src/contracts/path-template.ts +91 -0
- package/src/contracts/rate-limit.ts +50 -0
- package/src/contracts/types.ts +207 -0
- package/src/contracts/utils.ts +56 -0
- package/src/domain/entity.ts +256 -0
- package/src/domain/events.ts +52 -0
- package/src/domain/index.ts +18 -0
- package/src/domain/value-object.ts +135 -0
- package/src/errors/catalog.ts +149 -0
- package/src/errors/http.ts +80 -0
- package/src/errors/index.ts +28 -0
- package/src/errors/response.ts +54 -0
- package/src/errors/validation.ts +35 -0
- package/src/events/index.ts +246 -0
- package/src/jobs/index.ts +211 -0
- package/src/mail/index.ts +177 -0
- package/src/openapi/index.ts +865 -0
- package/src/openapi/schema-introspector.ts +107 -0
- package/src/ports/audit.ts +176 -0
- package/src/ports/auth.ts +76 -0
- package/src/ports/builder.ts +97 -0
- package/src/ports/cache.ts +94 -0
- package/src/ports/clock.ts +34 -0
- package/src/ports/events.ts +100 -0
- package/src/ports/id-generator.ts +36 -0
- package/src/ports/index.ts +221 -0
- package/src/ports/logger.ts +67 -0
- package/src/ports/policy.ts +242 -0
- package/src/ports/rate-limit.ts +91 -0
- package/src/ports/redaction.ts +199 -0
- package/src/ports/storage.ts +282 -0
- package/src/ports/testing.ts +234 -0
- package/src/ports/unit-of-work.ts +134 -0
- package/src/providers/index.ts +40 -0
- package/src/providers/instrumentation.ts +248 -0
- package/src/providers/provider.ts +191 -0
- package/src/schedules/index.ts +442 -0
- package/src/server/contract-like.ts +8 -0
- package/src/server/health.ts +82 -0
- package/src/server/hooks/auth.ts +147 -0
- package/src/server/hooks/cors.ts +87 -0
- package/src/server/hooks/errors.ts +126 -0
- package/src/server/hooks/index.ts +43 -0
- package/src/server/hooks/logging.ts +121 -0
- package/src/server/hooks/rate-limit.ts +171 -0
- package/src/server/hooks/utils.ts +16 -0
- package/src/server/hooks.ts +1 -0
- package/src/server/http.ts +189 -0
- package/src/server/index.ts +35 -0
- package/src/server/openapi.ts +72 -0
- package/src/server/providers/index.ts +3 -0
- package/src/server/providers/loadProviderConfig.ts +72 -0
- package/src/server/server.ts +1521 -0
- package/src/server/types.ts +2 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error catalog and AppError definitions for Beignet
|
|
3
|
+
*/
|
|
4
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
|
+
type ErrorDetailsSchema = StandardSchemaV1<unknown, unknown>;
|
|
6
|
+
declare const APP_ERROR_BRAND: unique symbol;
|
|
7
|
+
/**
|
|
8
|
+
* Definition of a single error in the catalog
|
|
9
|
+
*/
|
|
10
|
+
export interface ErrorDef<TDetails extends ErrorDetailsSchema | undefined = ErrorDetailsSchema | undefined> {
|
|
11
|
+
/** Unique, stable code used across layers (e.g. "TODO_NOT_FOUND") */
|
|
12
|
+
code: string;
|
|
13
|
+
/** HTTP status code (e.g. 404, 401, 409, 422, 500, etc.) */
|
|
14
|
+
status: number;
|
|
15
|
+
/** Default human-readable message */
|
|
16
|
+
message: string;
|
|
17
|
+
/** Optional schema for the structured details value */
|
|
18
|
+
details?: TDetails;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A mapping of keys to error definitions.
|
|
22
|
+
* Keys can be friendly identifiers, e.g. "TodoNotFound".
|
|
23
|
+
*/
|
|
24
|
+
export type ErrorCatalog = Record<string, ErrorDef>;
|
|
25
|
+
export type InferErrorDetails<TDef extends ErrorDef> = TDef extends {
|
|
26
|
+
details: ErrorDetailsSchema;
|
|
27
|
+
} ? StandardSchemaV1.InferInput<TDef["details"]> : unknown;
|
|
28
|
+
/**
|
|
29
|
+
* Type-preserving helper to define an error catalog.
|
|
30
|
+
*/
|
|
31
|
+
export declare function defineErrors<const T extends ErrorCatalog>(defs: T): T;
|
|
32
|
+
/**
|
|
33
|
+
* Application error class that domain & application code can throw.
|
|
34
|
+
* Contains the error definition from the catalog and optional structured details.
|
|
35
|
+
*/
|
|
36
|
+
export declare class AppError<TDef extends ErrorDef = ErrorDef> extends Error {
|
|
37
|
+
readonly [APP_ERROR_BRAND] = true;
|
|
38
|
+
/** The error definition from the catalog */
|
|
39
|
+
readonly def: TDef;
|
|
40
|
+
/** Optional structured details (for debugging, UI, etc.) */
|
|
41
|
+
readonly details?: InferErrorDetails<TDef>;
|
|
42
|
+
constructor(def: TDef, details?: InferErrorDetails<TDef>, overrideMessage?: string, options?: {
|
|
43
|
+
cause?: unknown;
|
|
44
|
+
});
|
|
45
|
+
get code(): string;
|
|
46
|
+
get status(): number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Callable helper for creating AppErrors from a catalog.
|
|
50
|
+
*/
|
|
51
|
+
export type AppErrorCreator<TCatalog extends ErrorCatalog> = {
|
|
52
|
+
catalog: TCatalog;
|
|
53
|
+
/**
|
|
54
|
+
* Create an AppError from a catalog key.
|
|
55
|
+
*/
|
|
56
|
+
<Key extends keyof TCatalog>(key: Key, options?: {
|
|
57
|
+
cause?: unknown;
|
|
58
|
+
details?: InferErrorDetails<TCatalog[Key]>;
|
|
59
|
+
message?: string;
|
|
60
|
+
}): AppError<TCatalog[Key]>;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Create a callable AppError helper bound to a specific catalog.
|
|
64
|
+
*/
|
|
65
|
+
export declare function createAppError<const T extends ErrorCatalog>(catalog: T): AppErrorCreator<T>;
|
|
66
|
+
/**
|
|
67
|
+
* Type guard to check if an unknown error is an AppError
|
|
68
|
+
*/
|
|
69
|
+
export declare function isAppError(err: unknown): err is AppError<ErrorDef>;
|
|
70
|
+
export {};
|
|
71
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/errors/catalog.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,KAAK,kBAAkB,GAAG,gBAAg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,IAAI,MAAM,CAEjB;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;CACF;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,QAAQ,SAAS,YAAY,IAAI;IAC3D,OAAO,EAAE,QAAQ,CAAC;IAClB;;OAEG;IACH,CAAC,GAAG,SAAS,MAAM,QAAQ,EACzB,GAAG,EAAE,GAAG,EACR,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,OAAO,CAAC,EAAE,iBAAiB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;QAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GACA,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,CAAC,CAAC,SAAS,YAAY,EACzD,OAAO,EAAE,CAAC,GACT,eAAe,CAAC,CAAC,CAAC,CAyBpB;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAiBlE"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error catalog and AppError definitions for Beignet
|
|
3
|
+
*/
|
|
4
|
+
const APP_ERROR_BRAND = Symbol.for("beignet.AppError");
|
|
5
|
+
/**
|
|
6
|
+
* Type-preserving helper to define an error catalog.
|
|
7
|
+
*/
|
|
8
|
+
export function defineErrors(defs) {
|
|
9
|
+
return defs;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Application error class that domain & application code can throw.
|
|
13
|
+
* Contains the error definition from the catalog and optional structured details.
|
|
14
|
+
*/
|
|
15
|
+
export class AppError extends Error {
|
|
16
|
+
[APP_ERROR_BRAND] = true;
|
|
17
|
+
/** The error definition from the catalog */
|
|
18
|
+
def;
|
|
19
|
+
/** Optional structured details (for debugging, UI, etc.) */
|
|
20
|
+
details;
|
|
21
|
+
constructor(def, details, overrideMessage, options) {
|
|
22
|
+
super(overrideMessage ?? def.message, { cause: options?.cause });
|
|
23
|
+
this.name = "AppError";
|
|
24
|
+
this.def = def;
|
|
25
|
+
this.details = details;
|
|
26
|
+
}
|
|
27
|
+
get code() {
|
|
28
|
+
return this.def.code;
|
|
29
|
+
}
|
|
30
|
+
get status() {
|
|
31
|
+
return this.def.status;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create a callable AppError helper bound to a specific catalog.
|
|
36
|
+
*/
|
|
37
|
+
export function createAppError(catalog) {
|
|
38
|
+
const appError = ((key, options) => {
|
|
39
|
+
const def = catalog[key];
|
|
40
|
+
if (!def) {
|
|
41
|
+
throw new Error(`Unknown error catalog key: ${String(key)}`);
|
|
42
|
+
}
|
|
43
|
+
return new AppError(def, options?.details, options?.message, {
|
|
44
|
+
cause: options?.cause,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
appError.catalog = catalog;
|
|
48
|
+
return appError;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Type guard to check if an unknown error is an AppError
|
|
52
|
+
*/
|
|
53
|
+
export function isAppError(err) {
|
|
54
|
+
if (err instanceof AppError)
|
|
55
|
+
return true;
|
|
56
|
+
if (typeof err !== "object" || err === null)
|
|
57
|
+
return false;
|
|
58
|
+
const value = err;
|
|
59
|
+
if (value[APP_ERROR_BRAND] === true)
|
|
60
|
+
return true;
|
|
61
|
+
if (value.name !== "AppError")
|
|
62
|
+
return false;
|
|
63
|
+
const def = value.def;
|
|
64
|
+
if (typeof def !== "object" || def === null)
|
|
65
|
+
return false;
|
|
66
|
+
const errorDef = def;
|
|
67
|
+
return (typeof errorDef.code === "string" &&
|
|
68
|
+
typeof errorDef.status === "number" &&
|
|
69
|
+
typeof errorDef.message === "string");
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|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OAAO,EAAE,OAAO,EAChB;YACE,KAAK,EAAE,OAAO,EAAE,KAAK;SACtB,CACF,CAAC;IACJ,CAAC,CAAuB,CAAC;IAEzB,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,GAAY;IACrC,IAAI,GAAG,YAAY,QAAQ;QAAE,OAAO,IAAI,CAAC;IACzC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAE1D,MAAM,KAAK,GAAG,GAAmC,CAAC;IAClD,IAAI,KAAK,CAAC,eAAe,CAAC,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACjD,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU;QAAE,OAAO,KAAK,CAAC;IAE5C,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;IACtB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAE1D,MAAM,QAAQ,GAAG,GAA8B,CAAC;IAChD,OAAO,CACL,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ;QACjC,OAAO,QAAQ,CAAC,MAAM,KAAK,QAAQ;QACnC,OAAO,QAAQ,CAAC,OAAO,KAAK,QAAQ,CACrC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard HTTP error catalog
|
|
3
|
+
*
|
|
4
|
+
* A base catalog of common HTTP-related errors that apps can reuse and extend.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A base catalog of common HTTP-related errors.
|
|
8
|
+
*
|
|
9
|
+
* Apps can spread this into their own error catalog:
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { defineErrors } from "@beignet/core/errors";
|
|
14
|
+
* import { httpErrors } from "@beignet/core/errors/http";
|
|
15
|
+
*
|
|
16
|
+
* export const errors = defineErrors({
|
|
17
|
+
* ...httpErrors,
|
|
18
|
+
* TodoNotFound: {
|
|
19
|
+
* code: "TODO_NOT_FOUND",
|
|
20
|
+
* status: 404,
|
|
21
|
+
* message: "Todo not found",
|
|
22
|
+
* },
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const httpErrors: {
|
|
27
|
+
readonly BadRequest: {
|
|
28
|
+
readonly code: "BAD_REQUEST";
|
|
29
|
+
readonly status: 400;
|
|
30
|
+
readonly message: "Bad request";
|
|
31
|
+
};
|
|
32
|
+
readonly Unauthorized: {
|
|
33
|
+
readonly code: "UNAUTHORIZED";
|
|
34
|
+
readonly status: 401;
|
|
35
|
+
readonly message: "Unauthorized";
|
|
36
|
+
};
|
|
37
|
+
readonly Forbidden: {
|
|
38
|
+
readonly code: "FORBIDDEN";
|
|
39
|
+
readonly status: 403;
|
|
40
|
+
readonly message: "Forbidden";
|
|
41
|
+
};
|
|
42
|
+
readonly NotFound: {
|
|
43
|
+
readonly code: "NOT_FOUND";
|
|
44
|
+
readonly status: 404;
|
|
45
|
+
readonly message: "Resource not found";
|
|
46
|
+
};
|
|
47
|
+
readonly Conflict: {
|
|
48
|
+
readonly code: "CONFLICT";
|
|
49
|
+
readonly status: 409;
|
|
50
|
+
readonly message: "Conflict";
|
|
51
|
+
};
|
|
52
|
+
readonly TooManyRequests: {
|
|
53
|
+
readonly code: "TOO_MANY_REQUESTS";
|
|
54
|
+
readonly status: 429;
|
|
55
|
+
readonly message: "Too many requests";
|
|
56
|
+
};
|
|
57
|
+
readonly UnprocessableEntity: {
|
|
58
|
+
readonly code: "UNPROCESSABLE_ENTITY";
|
|
59
|
+
readonly status: 422;
|
|
60
|
+
readonly message: "Unprocessable entity";
|
|
61
|
+
};
|
|
62
|
+
readonly ValidationError: {
|
|
63
|
+
readonly code: "VALIDATION_ERROR";
|
|
64
|
+
readonly status: 422;
|
|
65
|
+
readonly message: "Validation failed";
|
|
66
|
+
};
|
|
67
|
+
readonly InternalServerError: {
|
|
68
|
+
readonly code: "INTERNAL_SERVER_ERROR";
|
|
69
|
+
readonly status: 500;
|
|
70
|
+
readonly message: "Internal server error";
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Type of the default HTTP error catalog.
|
|
75
|
+
*/
|
|
76
|
+
export type HttpErrorCatalog = typeof httpErrors;
|
|
77
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/errors/http.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8CrB,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,UAAU,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard HTTP error catalog
|
|
3
|
+
*
|
|
4
|
+
* A base catalog of common HTTP-related errors that apps can reuse and extend.
|
|
5
|
+
*/
|
|
6
|
+
import { defineErrors } from "./catalog";
|
|
7
|
+
/**
|
|
8
|
+
* A base catalog of common HTTP-related errors.
|
|
9
|
+
*
|
|
10
|
+
* Apps can spread this into their own error catalog:
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { defineErrors } from "@beignet/core/errors";
|
|
15
|
+
* import { httpErrors } from "@beignet/core/errors/http";
|
|
16
|
+
*
|
|
17
|
+
* export const errors = defineErrors({
|
|
18
|
+
* ...httpErrors,
|
|
19
|
+
* TodoNotFound: {
|
|
20
|
+
* code: "TODO_NOT_FOUND",
|
|
21
|
+
* status: 404,
|
|
22
|
+
* message: "Todo not found",
|
|
23
|
+
* },
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const httpErrors = defineErrors({
|
|
28
|
+
BadRequest: {
|
|
29
|
+
code: "BAD_REQUEST",
|
|
30
|
+
status: 400,
|
|
31
|
+
message: "Bad request",
|
|
32
|
+
},
|
|
33
|
+
Unauthorized: {
|
|
34
|
+
code: "UNAUTHORIZED",
|
|
35
|
+
status: 401,
|
|
36
|
+
message: "Unauthorized",
|
|
37
|
+
},
|
|
38
|
+
Forbidden: {
|
|
39
|
+
code: "FORBIDDEN",
|
|
40
|
+
status: 403,
|
|
41
|
+
message: "Forbidden",
|
|
42
|
+
},
|
|
43
|
+
NotFound: {
|
|
44
|
+
code: "NOT_FOUND",
|
|
45
|
+
status: 404,
|
|
46
|
+
message: "Resource not found",
|
|
47
|
+
},
|
|
48
|
+
Conflict: {
|
|
49
|
+
code: "CONFLICT",
|
|
50
|
+
status: 409,
|
|
51
|
+
message: "Conflict",
|
|
52
|
+
},
|
|
53
|
+
TooManyRequests: {
|
|
54
|
+
code: "TOO_MANY_REQUESTS",
|
|
55
|
+
status: 429,
|
|
56
|
+
message: "Too many requests",
|
|
57
|
+
},
|
|
58
|
+
UnprocessableEntity: {
|
|
59
|
+
code: "UNPROCESSABLE_ENTITY",
|
|
60
|
+
status: 422,
|
|
61
|
+
message: "Unprocessable entity",
|
|
62
|
+
},
|
|
63
|
+
ValidationError: {
|
|
64
|
+
code: "VALIDATION_ERROR",
|
|
65
|
+
status: 422,
|
|
66
|
+
message: "Validation failed",
|
|
67
|
+
},
|
|
68
|
+
InternalServerError: {
|
|
69
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
70
|
+
status: 500,
|
|
71
|
+
message: "Internal server error",
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/errors/http.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC;IACrC,UAAU,EAAE;QACV,IAAI,EAAE,aAAa;QACnB,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,aAAa;KACvB;IACD,YAAY,EAAE;QACZ,IAAI,EAAE,cAAc;QACpB,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,cAAc;KACxB;IACD,SAAS,EAAE;QACT,IAAI,EAAE,WAAW;QACjB,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,WAAW;KACrB;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,WAAW;QACjB,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,oBAAoB;KAC9B;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,UAAU;QAChB,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,UAAU;KACpB;IACD,eAAe,EAAE;QACf,IAAI,EAAE,mBAAmB;QACzB,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,mBAAmB;KAC7B;IACD,mBAAmB,EAAE;QACnB,IAAI,EAAE,sBAAsB;QAC5B,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,sBAAsB;KAChC;IACD,eAAe,EAAE;QACf,IAAI,EAAE,kBAAkB;QACxB,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,mBAAmB;KAC7B;IACD,mBAAmB,EAAE;QACnB,IAAI,EAAE,uBAAuB;QAC7B,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,uBAAuB;KACjC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @beignet/core/errors
|
|
3
|
+
*
|
|
4
|
+
* Error catalog and error handling utilities for Beignet
|
|
5
|
+
*/
|
|
6
|
+
export { AppError, type AppErrorCreator, createAppError, defineErrors, type ErrorCatalog, type ErrorDef, type InferErrorDetails, isAppError, } from "./catalog";
|
|
7
|
+
export { type HttpErrorCatalog, httpErrors } from "./http";
|
|
8
|
+
export { createErrorResponseBody, type ErrorResponseBody, isErrorResponseBody, toErrorResponseBody, } from "./response";
|
|
9
|
+
export { SchemaValidationError, type ValidationIssue } from "./validation";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,QAAQ,EACR,KAAK,eAAe,EACpB,cAAc,EACd,YAAY,EACZ,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,iBAAiB,EACtB,UAAU,GACX,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,KAAK,gBAAgB,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAE3D,OAAO,EACL,uBAAuB,EACvB,KAAK,iBAAiB,EACtB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @beignet/core/errors
|
|
3
|
+
*
|
|
4
|
+
* Error catalog and error handling utilities for Beignet
|
|
5
|
+
*/
|
|
6
|
+
// Error catalog and AppError
|
|
7
|
+
export { AppError, createAppError, defineErrors, isAppError, } from "./catalog";
|
|
8
|
+
// HTTP error helpers
|
|
9
|
+
export { httpErrors } from "./http";
|
|
10
|
+
// Error response utilities
|
|
11
|
+
export { createErrorResponseBody, isErrorResponseBody, toErrorResponseBody, } from "./response";
|
|
12
|
+
// Schema validation error (shared across client/core/server)
|
|
13
|
+
export { SchemaValidationError } from "./validation";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,6BAA6B;AAC7B,OAAO,EACL,QAAQ,EAER,cAAc,EACd,YAAY,EAIZ,UAAU,GACX,MAAM,WAAW,CAAC;AACnB,qBAAqB;AACrB,OAAO,EAAyB,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC3D,2BAA2B;AAC3B,OAAO,EACL,uBAAuB,EAEvB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AACpB,6DAA6D;AAC7D,OAAO,EAAE,qBAAqB,EAAwB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard error response schema and utilities for Beignet
|
|
3
|
+
*/
|
|
4
|
+
import type { AppError, ErrorDef } from "./catalog";
|
|
5
|
+
/**
|
|
6
|
+
* Standard error response body structure
|
|
7
|
+
*/
|
|
8
|
+
export interface ErrorResponseBody {
|
|
9
|
+
code: string;
|
|
10
|
+
message: string;
|
|
11
|
+
details?: unknown;
|
|
12
|
+
requestId?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a standard error response body.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createErrorResponseBody(args: ErrorResponseBody): ErrorResponseBody;
|
|
18
|
+
/**
|
|
19
|
+
* Check whether a value is a standard error response body.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isErrorResponseBody(value: unknown): value is ErrorResponseBody;
|
|
22
|
+
/**
|
|
23
|
+
* Convert an AppError to a standard error response body
|
|
24
|
+
*/
|
|
25
|
+
export declare function toErrorResponseBody(err: AppError<ErrorDef>): ErrorResponseBody;
|
|
26
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/errors/response.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,iBAAiB,GACtB,iBAAiB,CAOnB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,iBAAiB,CAK5B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,QAAQ,CAAC,QAAQ,CAAC,GACtB,iBAAiB,CAMnB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard error response schema and utilities for Beignet
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Create a standard error response body.
|
|
6
|
+
*/
|
|
7
|
+
export function createErrorResponseBody(args) {
|
|
8
|
+
return {
|
|
9
|
+
code: args.code,
|
|
10
|
+
message: args.message,
|
|
11
|
+
...(args.details !== undefined ? { details: args.details } : {}),
|
|
12
|
+
...(args.requestId !== undefined ? { requestId: args.requestId } : {}),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Check whether a value is a standard error response body.
|
|
17
|
+
*/
|
|
18
|
+
export function isErrorResponseBody(value) {
|
|
19
|
+
if (typeof value !== "object" || value === null)
|
|
20
|
+
return false;
|
|
21
|
+
const body = value;
|
|
22
|
+
return typeof body.code === "string" && typeof body.message === "string";
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Convert an AppError to a standard error response body
|
|
26
|
+
*/
|
|
27
|
+
export function toErrorResponseBody(err) {
|
|
28
|
+
return createErrorResponseBody({
|
|
29
|
+
code: err.code,
|
|
30
|
+
message: err.message,
|
|
31
|
+
details: err.details,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../src/errors/response.ts"],"names":[],"mappings":"AAAA;;GAEG;AAcH;;GAEG;AACH,MAAM,UAAU,uBAAuB,CACrC,IAAuB;IAEvB,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,GAAG,CAAC,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAChE,GAAG,CAAC,IAAI,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvE,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAc;IAEd,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAE9D,MAAM,IAAI,GAAG,KAAgC,CAAC;IAC9C,OAAO,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,CAAC;AAC3E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAAuB;IAEvB,OAAO,uBAAuB,CAAC;QAC7B,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,OAAO,EAAE,GAAG,CAAC,OAAO;KACrB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
/**
|
|
3
|
+
* Normalized validation issue with simplified path
|
|
4
|
+
*/
|
|
5
|
+
export interface ValidationIssue {
|
|
6
|
+
path?: (string | number)[];
|
|
7
|
+
message: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Error thrown when Standard Schema validation fails.
|
|
11
|
+
* Shared across client and server packages so `instanceof` checks work
|
|
12
|
+
* regardless of which package threw the error.
|
|
13
|
+
*/
|
|
14
|
+
export declare class SchemaValidationError extends Error {
|
|
15
|
+
readonly issues: ReadonlyArray<ValidationIssue>;
|
|
16
|
+
constructor(rawIssues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/errors/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;gBAEpC,SAAS,EAAE,aAAa,CAAC,gBAAgB,CAAC,KAAK,CAAC;CAgB7D"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when Standard Schema validation fails.
|
|
3
|
+
* Shared across client and server packages so `instanceof` checks work
|
|
4
|
+
* regardless of which package threw the error.
|
|
5
|
+
*/
|
|
6
|
+
export class SchemaValidationError extends Error {
|
|
7
|
+
issues;
|
|
8
|
+
constructor(rawIssues) {
|
|
9
|
+
const issues = rawIssues.map((i) => ({
|
|
10
|
+
path: i.path?.map((p) => (typeof p === "object" ? p.key : p)),
|
|
11
|
+
message: i.message,
|
|
12
|
+
}));
|
|
13
|
+
const message = issues
|
|
14
|
+
.map((i) => i.path?.length ? `${i.path.join(".")}: ${i.message}` : i.message)
|
|
15
|
+
.join("; ");
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = "SchemaValidationError";
|
|
18
|
+
this.issues = issues;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/errors/validation.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IACrC,MAAM,CAAiC;IAEhD,YAAY,SAAgD;QAC1D,MAAM,MAAM,GAAsB,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACtD,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAE/C;YACb,OAAO,EAAE,CAAC,CAAC,OAAO;SACnB,CAAC,CAAC,CAAC;QACJ,MAAM,OAAO,GAAG,MAAM;aACnB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACT,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CACjE;aACA,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
export type StandardSchema = StandardSchemaV1<unknown, unknown>;
|
|
3
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
4
|
+
export type InferSchemaOutput<T extends StandardSchemaV1> = StandardSchemaV1.InferOutput<T>;
|
|
5
|
+
export interface EventPayloadDef<Name extends string = string, Payload extends StandardSchema = StandardSchema> {
|
|
6
|
+
readonly name: Name;
|
|
7
|
+
readonly payload: Payload;
|
|
8
|
+
readonly description?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface EventDef<Name extends string = string, Payload extends StandardSchema = StandardSchema> extends EventPayloadDef<Name, Payload> {
|
|
11
|
+
readonly kind: "event";
|
|
12
|
+
}
|
|
13
|
+
export type InferEventPayload<E extends EventPayloadDef> = E["payload"] extends StandardSchemaV1<unknown, infer Output> ? Output : never;
|
|
14
|
+
export interface DefineEventOptions<Payload extends StandardSchema> {
|
|
15
|
+
payload: Payload;
|
|
16
|
+
description?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ListenerHandleArgs<E extends EventDef, Ctx> {
|
|
19
|
+
event: E;
|
|
20
|
+
payload: InferEventPayload<E>;
|
|
21
|
+
ctx: Ctx;
|
|
22
|
+
}
|
|
23
|
+
export interface ListenerDef<E extends EventDef = EventDef, Ctx = unknown, Name extends string = string> {
|
|
24
|
+
readonly kind: "listener";
|
|
25
|
+
readonly name: Name;
|
|
26
|
+
readonly event: E;
|
|
27
|
+
handle(args: ListenerHandleArgs<E, Ctx>): MaybePromise<void>;
|
|
28
|
+
}
|
|
29
|
+
export interface DefineListenerOptions<E extends EventDef, Ctx, Name extends string> {
|
|
30
|
+
name: Name;
|
|
31
|
+
handle(args: ListenerHandleArgs<E, Ctx>): MaybePromise<void>;
|
|
32
|
+
}
|
|
33
|
+
export interface EventBusLike {
|
|
34
|
+
publish<E extends EventPayloadDef>(event: E, payload: InferEventPayload<E>): MaybePromise<void>;
|
|
35
|
+
subscribe<E extends EventPayloadDef>(event: E, handler: (payload: InferEventPayload<E>) => MaybePromise<void>): () => void;
|
|
36
|
+
}
|
|
37
|
+
export interface RegisterListenersOptions<Ctx> {
|
|
38
|
+
ctx?: Ctx | (() => MaybePromise<Ctx>);
|
|
39
|
+
onError?: (error: unknown, listener: ListenerDef<EventDef, Ctx>) => void;
|
|
40
|
+
}
|
|
41
|
+
export interface EventHandlers<Ctx> {
|
|
42
|
+
defineListener<E extends EventDef, Name extends string = string>(event: E, options: DefineListenerOptions<E, Ctx, Name>): ListenerDef<E, Ctx, Name>;
|
|
43
|
+
registerListeners(eventBus: EventBusLike, listeners: readonly ListenerDef<EventDef, Ctx>[], options?: RegisterListenersOptions<Ctx>): () => void;
|
|
44
|
+
}
|
|
45
|
+
export declare class EventValidationError extends Error {
|
|
46
|
+
readonly issues: readonly StandardSchemaV1.Issue[];
|
|
47
|
+
constructor(args: {
|
|
48
|
+
name: string;
|
|
49
|
+
issues: readonly StandardSchemaV1.Issue[];
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export declare function defineEvent<Name extends string, Payload extends StandardSchema>(name: Name, options: DefineEventOptions<Payload>): EventDef<Name, Payload>;
|
|
53
|
+
export declare function defineListener<E extends EventDef, Ctx = unknown, Name extends string = string>(event: E, options: DefineListenerOptions<E, Ctx, Name>): ListenerDef<E, Ctx, Name>;
|
|
54
|
+
export declare function parseEventPayload<E extends EventPayloadDef>(event: E, payload: unknown): Promise<InferEventPayload<E>>;
|
|
55
|
+
export declare function publishEvent<E extends EventPayloadDef>(eventBus: EventBusLike, event: E, payload: InferEventPayload<E>): Promise<void>;
|
|
56
|
+
export declare function registerListeners<Ctx>(eventBus: EventBusLike, listeners: readonly ListenerDef<EventDef, Ctx>[], options?: RegisterListenersOptions<Ctx>): () => void;
|
|
57
|
+
export declare function createEventHandlers<Ctx>(): EventHandlers<Ctx>;
|
|
58
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
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OAAO,EAAE,OAAO,GACf,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAI/B;AAED,wBAAsB,YAAY,CAAC,CAAC,SAAS,eAAe,EAC1D,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC5B,OAAO,CAAC,IAAI,CAAC,CAGf;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EACnC,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,SAAS,WAAW,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,EAChD,OAAO,GAAE,wBAAwB,CAAC,GAAG,CAAM,GAC1C,MAAM,IAAI,CAsBZ;AAED,wBAAgB,mBAAmB,CAAC,GAAG,KAAK,aAAa,CAAC,GAAG,CAAC,CAiB7D"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export class EventValidationError extends Error {
|
|
2
|
+
issues;
|
|
3
|
+
constructor(args) {
|
|
4
|
+
super(`Event "${args.name}" payload validation failed: ${formatIssues(args.issues)}`);
|
|
5
|
+
this.name = "EventValidationError";
|
|
6
|
+
this.issues = args.issues;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function formatPath(path) {
|
|
10
|
+
if (!path?.length)
|
|
11
|
+
return "";
|
|
12
|
+
return path
|
|
13
|
+
.map((segment) => typeof segment === "object" && segment !== null && "key" in segment
|
|
14
|
+
? String(segment.key)
|
|
15
|
+
: String(segment))
|
|
16
|
+
.join(".");
|
|
17
|
+
}
|
|
18
|
+
function formatIssues(issues) {
|
|
19
|
+
return issues
|
|
20
|
+
.map((issue) => {
|
|
21
|
+
const path = formatPath(issue.path);
|
|
22
|
+
return path ? `${path}: ${issue.message}` : issue.message;
|
|
23
|
+
})
|
|
24
|
+
.join("; ");
|
|
25
|
+
}
|
|
26
|
+
async function parsePayload(schema, input, args) {
|
|
27
|
+
const result = await schema["~standard"].validate(input);
|
|
28
|
+
if (result.issues?.length) {
|
|
29
|
+
throw new EventValidationError({
|
|
30
|
+
name: args.name,
|
|
31
|
+
issues: result.issues,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if ("value" in result) {
|
|
35
|
+
return result.value;
|
|
36
|
+
}
|
|
37
|
+
throw new Error("Invalid Standard Schema result: missing value");
|
|
38
|
+
}
|
|
39
|
+
async function resolveCtx(ctx) {
|
|
40
|
+
if (typeof ctx === "function") {
|
|
41
|
+
return ctx();
|
|
42
|
+
}
|
|
43
|
+
return ctx;
|
|
44
|
+
}
|
|
45
|
+
export function defineEvent(name, options) {
|
|
46
|
+
return {
|
|
47
|
+
kind: "event",
|
|
48
|
+
name,
|
|
49
|
+
payload: options.payload,
|
|
50
|
+
description: options.description,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function defineListener(event, options) {
|
|
54
|
+
return {
|
|
55
|
+
kind: "listener",
|
|
56
|
+
name: options.name,
|
|
57
|
+
event,
|
|
58
|
+
handle: options.handle,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export async function parseEventPayload(event, payload) {
|
|
62
|
+
return (await parsePayload(event.payload, payload, {
|
|
63
|
+
name: event.name,
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
export async function publishEvent(eventBus, event, payload) {
|
|
67
|
+
const parsed = await parseEventPayload(event, payload);
|
|
68
|
+
await eventBus.publish(event, parsed);
|
|
69
|
+
}
|
|
70
|
+
export function registerListeners(eventBus, listeners, options = {}) {
|
|
71
|
+
const unsubscribes = listeners.map((listener) => eventBus.subscribe(listener.event, async (rawPayload) => {
|
|
72
|
+
try {
|
|
73
|
+
const payload = await parseEventPayload(listener.event, rawPayload);
|
|
74
|
+
await listener.handle({
|
|
75
|
+
event: listener.event,
|
|
76
|
+
payload,
|
|
77
|
+
ctx: await resolveCtx(options.ctx),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
options.onError?.(error, listener);
|
|
82
|
+
if (!options.onError)
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}));
|
|
86
|
+
return () => {
|
|
87
|
+
for (const unsubscribe of [...unsubscribes].reverse()) {
|
|
88
|
+
unsubscribe();
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export function createEventHandlers() {
|
|
93
|
+
return {
|
|
94
|
+
defineListener(event, options) {
|
|
95
|
+
return defineListener(event, options);
|
|
96
|
+
},
|
|
97
|
+
registerListeners(eventBus, listeners, options = {}) {
|
|
98
|
+
return registerListeners(eventBus, listeners, options);
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAuFA,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IACpC,MAAM,CAAoC;IAEnD,YAAY,IAGX;QACC,KAAK,CACH,UAAU,IAAI,CAAC,IAAI,gCAAgC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAC/E,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC5B,CAAC;CACF;AAED,SAAS,UAAU,CAAC,IAAoC;IACtD,IAAI,CAAC,IAAI,EAAE,MAAM;QAAE,OAAO,EAAE,CAAC;IAE7B,OAAO,IAAI;SACR,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CACf,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAI,KAAK,IAAI,OAAO;QACjE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC;QACrB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CACpB;SACA,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,SAAS,YAAY,CAA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