@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,240 @@
|
|
|
1
|
+
import { ContractBuilder } from "./contract-builder";
|
|
2
|
+
import { parsePathTemplate } from "./path-template";
|
|
3
|
+
import { STANDARD_ERROR_RESPONSE_SCHEMA } from "./types";
|
|
4
|
+
import { generateContractName } from "./utils";
|
|
5
|
+
function joinPathPrefix(prefix, path) {
|
|
6
|
+
const segments = [
|
|
7
|
+
...prefix.split("/").filter(Boolean),
|
|
8
|
+
...path.split("/").filter(Boolean),
|
|
9
|
+
];
|
|
10
|
+
return `/${segments.join("/")}`;
|
|
11
|
+
}
|
|
12
|
+
function responsesFromErrors(errors) {
|
|
13
|
+
const responses = {};
|
|
14
|
+
for (const error of Object.values(errors)) {
|
|
15
|
+
responses[error.status] = STANDARD_ERROR_RESPONSE_SCHEMA;
|
|
16
|
+
}
|
|
17
|
+
return responses;
|
|
18
|
+
}
|
|
19
|
+
function assertNoResponseStatusConflicts(current, next) {
|
|
20
|
+
const currentStatuses = new Set(Object.keys(current));
|
|
21
|
+
const conflicts = Object.keys(next).filter((status) => currentStatuses.has(status));
|
|
22
|
+
if (conflicts.length) {
|
|
23
|
+
throw new Error(`.errors() cannot declare status ${conflicts.join(", ")} because a response schema for that status already exists. Use .responses() without .errors() when you need a custom error response body.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function assertNoCatalogErrorStatusConflicts(metadata, next) {
|
|
27
|
+
const errors = metadata.errors;
|
|
28
|
+
if (typeof errors !== "object" || errors === null)
|
|
29
|
+
return;
|
|
30
|
+
const errorStatuses = new Set(Object.values(errors)
|
|
31
|
+
.map((error) => typeof error === "object" &&
|
|
32
|
+
error !== null &&
|
|
33
|
+
typeof error.status === "number"
|
|
34
|
+
? String(error.status)
|
|
35
|
+
: undefined)
|
|
36
|
+
.filter((status) => status !== undefined));
|
|
37
|
+
const conflicts = Object.keys(next).filter((status) => errorStatuses.has(status));
|
|
38
|
+
if (conflicts.length) {
|
|
39
|
+
throw new Error(`.responses() cannot declare status ${conflicts.join(", ")} because that status is already declared by .errors(). Use .responses() without .errors() when you need a custom error response body.`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* ContractGroup is a feature-scoped factory for creating related contracts
|
|
44
|
+
* with shared configuration. Immutable — each method returns a new instance.
|
|
45
|
+
*/
|
|
46
|
+
export class ContractGroup {
|
|
47
|
+
_namespace;
|
|
48
|
+
_meta;
|
|
49
|
+
_responses;
|
|
50
|
+
_headers;
|
|
51
|
+
_pathPrefix;
|
|
52
|
+
constructor(state = {}) {
|
|
53
|
+
this._namespace = state.namespace ?? "";
|
|
54
|
+
this._meta = state.meta ?? {};
|
|
55
|
+
this._responses = state.responses ?? {};
|
|
56
|
+
this._headers = state.headers ?? null;
|
|
57
|
+
this._pathPrefix = state.pathPrefix ?? "";
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Set the namespace for all contracts created from this group
|
|
61
|
+
*/
|
|
62
|
+
namespace(ns) {
|
|
63
|
+
return new ContractGroup({
|
|
64
|
+
namespace: ns,
|
|
65
|
+
meta: this._meta,
|
|
66
|
+
responses: this._responses,
|
|
67
|
+
headers: this._headers,
|
|
68
|
+
pathPrefix: this._pathPrefix,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Add a path prefix to all contracts created from this group.
|
|
73
|
+
*
|
|
74
|
+
* Prefixes compose immutably, so `prefix("/api").prefix("/v1")`
|
|
75
|
+
* produces paths under `/api/v1`.
|
|
76
|
+
*/
|
|
77
|
+
prefix(pathPrefix) {
|
|
78
|
+
parsePathTemplate(pathPrefix);
|
|
79
|
+
const nextPrefix = joinPathPrefix(this._pathPrefix, pathPrefix);
|
|
80
|
+
const normalizedPrefix = nextPrefix === "/" ? "" : nextPrefix;
|
|
81
|
+
return new ContractGroup({
|
|
82
|
+
namespace: this._namespace,
|
|
83
|
+
meta: this._meta,
|
|
84
|
+
responses: this._responses,
|
|
85
|
+
headers: this._headers,
|
|
86
|
+
pathPrefix: normalizedPrefix,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Set shared metadata for all contracts created from this group
|
|
91
|
+
*/
|
|
92
|
+
meta(meta) {
|
|
93
|
+
return new ContractGroup({
|
|
94
|
+
namespace: this._namespace,
|
|
95
|
+
meta: { ...this._meta, ...meta },
|
|
96
|
+
responses: this._responses,
|
|
97
|
+
headers: this._headers,
|
|
98
|
+
pathPrefix: this._pathPrefix,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Set shared response schemas for all contracts created from this group.
|
|
103
|
+
* Typically used for shared error responses (e.g. 401, 403, 500).
|
|
104
|
+
*/
|
|
105
|
+
responses(responseSchemas) {
|
|
106
|
+
assertNoCatalogErrorStatusConflicts(this._meta, responseSchemas);
|
|
107
|
+
return new ContractGroup({
|
|
108
|
+
namespace: this._namespace,
|
|
109
|
+
meta: this._meta,
|
|
110
|
+
responses: { ...this._responses, ...responseSchemas },
|
|
111
|
+
headers: this._headers,
|
|
112
|
+
pathPrefix: this._pathPrefix,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Set shared route-owned application errors for all contracts in the group.
|
|
117
|
+
*/
|
|
118
|
+
errors(errorDefs) {
|
|
119
|
+
const errorResponses = responsesFromErrors(errorDefs);
|
|
120
|
+
assertNoResponseStatusConflicts(this._responses, errorResponses);
|
|
121
|
+
return new ContractGroup({
|
|
122
|
+
namespace: this._namespace,
|
|
123
|
+
meta: {
|
|
124
|
+
...this._meta,
|
|
125
|
+
errors: errorDefs,
|
|
126
|
+
},
|
|
127
|
+
responses: { ...this._responses, ...errorResponses },
|
|
128
|
+
headers: this._headers,
|
|
129
|
+
pathPrefix: this._pathPrefix,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Add shared request header schema for all contracts created from this group.
|
|
134
|
+
*/
|
|
135
|
+
headers(schema) {
|
|
136
|
+
const existingHeaders = this._headers
|
|
137
|
+
? Array.isArray(this._headers)
|
|
138
|
+
? this._headers
|
|
139
|
+
: [this._headers]
|
|
140
|
+
: [];
|
|
141
|
+
return new ContractGroup({
|
|
142
|
+
namespace: this._namespace,
|
|
143
|
+
meta: this._meta,
|
|
144
|
+
responses: this._responses,
|
|
145
|
+
headers: [
|
|
146
|
+
...existingHeaders,
|
|
147
|
+
schema,
|
|
148
|
+
],
|
|
149
|
+
pathPrefix: this._pathPrefix,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Create a GET contract
|
|
154
|
+
*/
|
|
155
|
+
get(path, name) {
|
|
156
|
+
return this.createBuilder("GET", path, name);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Create a POST contract
|
|
160
|
+
*/
|
|
161
|
+
post(path, name) {
|
|
162
|
+
return this.createBuilder("POST", path, name);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Create a PUT contract
|
|
166
|
+
*/
|
|
167
|
+
put(path, name) {
|
|
168
|
+
return this.createBuilder("PUT", path, name);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Create a PATCH contract
|
|
172
|
+
*/
|
|
173
|
+
patch(path, name) {
|
|
174
|
+
return this.createBuilder("PATCH", path, name);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Create a DELETE contract
|
|
178
|
+
*/
|
|
179
|
+
delete(path, name) {
|
|
180
|
+
return this.createBuilder("DELETE", path, name);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Create a HEAD contract
|
|
184
|
+
*/
|
|
185
|
+
head(path, name) {
|
|
186
|
+
return this.createBuilder("HEAD", path, name);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Create a OPTIONS contract
|
|
190
|
+
*/
|
|
191
|
+
options(path, name) {
|
|
192
|
+
return this.createBuilder("OPTIONS", path, name);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Internal helper to create a contract builder with shared config
|
|
196
|
+
*/
|
|
197
|
+
createBuilder(method, path, name) {
|
|
198
|
+
parsePathTemplate(path);
|
|
199
|
+
const fullPath = (this._pathPrefix ? joinPathPrefix(this._pathPrefix, path) : path);
|
|
200
|
+
parsePathTemplate(fullPath);
|
|
201
|
+
const contractName = name || generateContractName(method, fullPath);
|
|
202
|
+
const fullName = this._namespace
|
|
203
|
+
? `${this._namespace}.${contractName}`
|
|
204
|
+
: contractName;
|
|
205
|
+
return new ContractBuilder({
|
|
206
|
+
kind: "http",
|
|
207
|
+
name: fullName,
|
|
208
|
+
namespace: this._namespace || undefined,
|
|
209
|
+
localName: contractName,
|
|
210
|
+
method,
|
|
211
|
+
path: fullPath,
|
|
212
|
+
pathParams: null,
|
|
213
|
+
query: null,
|
|
214
|
+
headers: this._headers,
|
|
215
|
+
body: null,
|
|
216
|
+
responses: { ...this._responses },
|
|
217
|
+
metadata: { ...this._meta },
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Create a new ContractGroup for grouping related contracts with shared configuration.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* const todos = createContractGroup()
|
|
227
|
+
* .namespace("todos")
|
|
228
|
+
* .prefix("/api/todos")
|
|
229
|
+
* .meta({ auth: "required" })
|
|
230
|
+
* .responses({
|
|
231
|
+
* 401: z.object({ message: z.literal("Unauthorized") }),
|
|
232
|
+
* });
|
|
233
|
+
*
|
|
234
|
+
* const getTodo = todos.get("/:id")...
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
export function createContractGroup() {
|
|
238
|
+
return new ContractGroup();
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=contract-group.js.map
|
|
@@ -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e,EACf,IAAW,EACX,IAAa;QAWb,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACxB,MAAM,QAAQ,GAAG,CACf,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAChC,CAAC;QACnC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAC5B,MAAM,YAAY,GAAG,IAAI,IAAI,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QACpE,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU;YAC9B,CAAC,CAAC,GAAG,IAAI,CAAC,UAAU,IAAI,YAAY,EAAE;YACtC,CAAC,CAAC,YAAY,CAAC;QAEjB,OAAO,IAAI,eAAe,CAAC;YACzB,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,QAAQ;YACd,SAAS,EAAE,IAAI,CAAC,UAAU,IAAI,SAAS;YACvC,SAAS,EAAE,YAAY;YACvB,MAAM;YACN,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,IAAI;YAChB,KAAK,EAAE,IAAI;YACX,OAAO,EAAE,IAAI,CAAC,QAAQ;YACtB,IAAI,EAAE,IAAI;YACV,SAAS,EAAE,EAAE,GAAG,IAAI,CAAC,UAAU,EAAiC;YAChE,QAAQ,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,EAA4B;SACtD,CAAC,CAAC;IACL,CAAC;CACF;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,mBAAmB;IAMjC,OAAO,IAAI,aAAa,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { HttpContractConfig } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* A type that represents either a raw HttpContractConfig
|
|
4
|
+
* or a contract-like object with a .config property (e.g., ContractBuilder)
|
|
5
|
+
*/
|
|
6
|
+
export type ContractLike = HttpContractConfig | {
|
|
7
|
+
config: HttpContractConfig;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Resolves a ContractLike to its underlying HttpContractConfig
|
|
11
|
+
*/
|
|
12
|
+
export type ResolveContract<T> = T extends {
|
|
13
|
+
config: infer C;
|
|
14
|
+
} ? C extends HttpContractConfig ? C : never : T extends HttpContractConfig ? T : never;
|
|
15
|
+
/**
|
|
16
|
+
* Helper function to resolve a ContractLike to its underlying HttpContractConfig
|
|
17
|
+
* @param c - The contract-like object to resolve
|
|
18
|
+
* @returns The underlying HttpContractConfig
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveContract<T extends ContractLike>(c: T): ResolveContract<T>;
|
|
21
|
+
//# sourceMappingURL=contract-like.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-like.d.ts","sourceRoot":"","sources":["../../src/contracts/contract-like.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,kBAAkB,GAAG;IAAE,MAAM,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAE/E;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAC1D,CAAC,SAAS,kBAAkB,GAC1B,CAAC,GACD,KAAK,GACP,CAAC,SAAS,kBAAkB,GAC1B,CAAC,GACD,KAAK,CAAC;AAEZ;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,YAAY,EACpD,CAAC,EAAE,CAAC,GACH,eAAe,CAAC,CAAC,CAAC,CAEpB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper function to resolve a ContractLike to its underlying HttpContractConfig
|
|
3
|
+
* @param c - The contract-like object to resolve
|
|
4
|
+
* @returns The underlying HttpContractConfig
|
|
5
|
+
*/
|
|
6
|
+
export function resolveContract(c) {
|
|
7
|
+
return ("config" in c ? c.config : c);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=contract-like.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-like.js","sourceRoot":"","sources":["../../src/contracts/contract-like.ts"],"names":[],"mappings":"AAmBA;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,CAAI;IAEJ,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAuB,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @beignet/core/contracts
|
|
3
|
+
*
|
|
4
|
+
* HTTP contract definitions and builders for Beignet.
|
|
5
|
+
*/
|
|
6
|
+
export type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
7
|
+
export { ContractBuilder, type CreateContractOptions, createContract, } from "./contract-builder";
|
|
8
|
+
export { ContractGroup, createContractGroup } from "./contract-group";
|
|
9
|
+
export { type ContractLike, type ResolveContract, resolveContract, } from "./contract-like";
|
|
10
|
+
export type { OpenAPIOperationMeta } from "./openapi-meta";
|
|
11
|
+
export { type ParsedPathTemplate, type PathTemplateSegment, parsePathTemplate, } from "./path-template";
|
|
12
|
+
export type { RateLimitMeta, RateLimitScope } from "./rate-limit";
|
|
13
|
+
export type { AnyContract, BodyHttpMethod, ContractErrorDefinition, ContractErrorResponses, ContractHeaderSchemas, ContractMeta, ContractResponseSchema, ContractResponses, HttpContractConfig, HttpMethod, InferHeaderSchemaInput, InferHeaderSchemaOutput, InferInput, InferOutput, ResponsesFromErrorDefinitions, StandardErrorResponseBody, StandardErrorResponseSchema, StandardSchema, } from "./types";
|
|
14
|
+
export { BEIGNET_ERROR_OWNER_HEADER, BODY_HTTP_METHODS, getContractHeaderSchemas, methodSupportsRequestBody, STANDARD_ERROR_RESPONSE_SCHEMA, } from "./types";
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,EACL,eAAe,EACf,KAAK,qBAAqB,EAC1B,cAAc,GACf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAClE,YAAY,EACV,WAAW,EACX,cAAc,EACd,uBAAuB,EACvB,sBAAsB,EACtB,qBAAqB,EACrB,YAAY,EACZ,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,UAAU,EACV,sBAAsB,EACtB,uBAAuB,EACvB,UAAU,EACV,WAAW,EACX,6BAA6B,EAC7B,yBAAyB,EACzB,2BAA2B,EAC3B,cAAc,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,0BAA0B,EAC1B,iBAAiB,EACjB,wBAAwB,EACxB,yBAAyB,EACzB,8BAA8B,GAC/B,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @beignet/core/contracts
|
|
3
|
+
*
|
|
4
|
+
* HTTP contract definitions and builders for Beignet.
|
|
5
|
+
*/
|
|
6
|
+
export { ContractBuilder, createContract, } from "./contract-builder";
|
|
7
|
+
export { ContractGroup, createContractGroup } from "./contract-group";
|
|
8
|
+
export { resolveContract, } from "./contract-like";
|
|
9
|
+
export { parsePathTemplate, } from "./path-template";
|
|
10
|
+
export { BEIGNET_ERROR_OWNER_HEADER, BODY_HTTP_METHODS, getContractHeaderSchemas, methodSupportsRequestBody, STANDARD_ERROR_RESPONSE_SCHEMA, } from "./types";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EACL,eAAe,EAEf,cAAc,GACf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAGL,eAAe,GAChB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAGL,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAsBzB,OAAO,EACL,0BAA0B,EAC1B,iBAAiB,EACjB,wBAAwB,EACxB,yBAAyB,EACzB,8BAA8B,GAC/B,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAPI operation-level metadata for HTTP contracts
|
|
3
|
+
*/
|
|
4
|
+
export type OpenAPIOperationMeta = {
|
|
5
|
+
/** A brief summary of the operation */
|
|
6
|
+
summary?: string;
|
|
7
|
+
/** A detailed description of the operation */
|
|
8
|
+
description?: string;
|
|
9
|
+
/** Tags for grouping operations */
|
|
10
|
+
tags?: string[];
|
|
11
|
+
/** Marks the operation as deprecated */
|
|
12
|
+
deprecated?: boolean;
|
|
13
|
+
/** External documentation reference */
|
|
14
|
+
externalDocs?: {
|
|
15
|
+
description?: string;
|
|
16
|
+
url: string;
|
|
17
|
+
};
|
|
18
|
+
/** Override for operationId (default is contract.name) */
|
|
19
|
+
operationId?: string;
|
|
20
|
+
/** Per-operation security requirements */
|
|
21
|
+
security?: Array<Record<string, string[]>>;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=openapi-meta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-meta.d.ts","sourceRoot":"","sources":["../../src/contracts/openapi-meta.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mCAAmC;IACnC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,wCAAwC;IACxC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,uCAAuC;IACvC,YAAY,CAAC,EAAE;QACb,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,0DAA0D;IAC1D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;CAC5C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-meta.js","sourceRoot":"","sources":["../../src/contracts/openapi-meta.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type PathTemplateSegment = {
|
|
2
|
+
kind: "static";
|
|
3
|
+
value: string;
|
|
4
|
+
} | {
|
|
5
|
+
kind: "dynamic";
|
|
6
|
+
name: string;
|
|
7
|
+
raw: string;
|
|
8
|
+
};
|
|
9
|
+
export interface ParsedPathTemplate {
|
|
10
|
+
keys: string[];
|
|
11
|
+
segments: PathTemplateSegment[];
|
|
12
|
+
normalizedPath: string;
|
|
13
|
+
shapeKey: string;
|
|
14
|
+
openApiPath: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function parsePathTemplate(path: string): ParsedPathTemplate;
|
|
17
|
+
//# sourceMappingURL=path-template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-template.d.ts","sourceRoot":"","sources":["../../src/contracts/path-template.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAC3B;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,QAAQ,EAAE,mBAAmB,EAAE,CAAC;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB;AAmCD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CA6ClE"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const PARAM_NAME = "[A-Za-z0-9_-]+";
|
|
2
|
+
const COLON_PARAM = new RegExp(`^:(${PARAM_NAME})$`);
|
|
3
|
+
const BRACKET_PARAM = new RegExp(`^\\[(${PARAM_NAME})\\]$`);
|
|
4
|
+
function createPathTemplateError(path, segment) {
|
|
5
|
+
return new Error(`Unsupported path template segment "${segment}" in "${path}". ` +
|
|
6
|
+
"Use single-segment params like :id or [id]. Catch-all and partial-segment params are not supported.");
|
|
7
|
+
}
|
|
8
|
+
function parsePathSegment(path, segment) {
|
|
9
|
+
const colonMatch = segment.match(COLON_PARAM);
|
|
10
|
+
if (colonMatch) {
|
|
11
|
+
return { kind: "dynamic", name: colonMatch[1], raw: segment };
|
|
12
|
+
}
|
|
13
|
+
const bracketMatch = segment.match(BRACKET_PARAM);
|
|
14
|
+
if (bracketMatch) {
|
|
15
|
+
return { kind: "dynamic", name: bracketMatch[1], raw: segment };
|
|
16
|
+
}
|
|
17
|
+
if (segment.startsWith(":") ||
|
|
18
|
+
segment.startsWith("[") ||
|
|
19
|
+
segment.endsWith("]")) {
|
|
20
|
+
throw createPathTemplateError(path, segment);
|
|
21
|
+
}
|
|
22
|
+
return { kind: "static", value: segment };
|
|
23
|
+
}
|
|
24
|
+
export function parsePathTemplate(path) {
|
|
25
|
+
if (!path.startsWith("/")) {
|
|
26
|
+
throw new Error(`Invalid path template "${path}". Paths must start with "/".`);
|
|
27
|
+
}
|
|
28
|
+
const segments = path
|
|
29
|
+
.split("/")
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.map((segment) => parsePathSegment(path, segment));
|
|
32
|
+
const keys = segments
|
|
33
|
+
.filter((segment) => segment.kind === "dynamic")
|
|
34
|
+
.map((segment) => segment.name);
|
|
35
|
+
const duplicateKeys = keys.filter((key, index) => keys.indexOf(key) !== index);
|
|
36
|
+
if (duplicateKeys.length) {
|
|
37
|
+
throw new Error(`Invalid path template "${path}". Path parameter names must be unique; duplicate parameter "${duplicateKeys[0]}" was found.`);
|
|
38
|
+
}
|
|
39
|
+
const normalizedPath = `/${segments
|
|
40
|
+
.map((segment) => segment.kind === "static" ? segment.value : `:${segment.name}`)
|
|
41
|
+
.join("/")}`;
|
|
42
|
+
const shapeKey = `/${segments
|
|
43
|
+
.map((segment) => (segment.kind === "static" ? segment.value : ":"))
|
|
44
|
+
.join("/")}`;
|
|
45
|
+
const openApiPath = `/${segments
|
|
46
|
+
.map((segment) => segment.kind === "static" ? segment.value : `{${segment.name}}`)
|
|
47
|
+
.join("/")}`;
|
|
48
|
+
return { keys, segments, normalizedPath, shapeKey, openApiPath };
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=path-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-template.js","sourceRoot":"","sources":["../../src/contracts/path-template.ts"],"names":[],"mappings":"AAYA,MAAM,UAAU,GAAG,gBAAgB,CAAC;AAC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AC7B,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CACf,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,GAAG,CAChE;SACA,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IAEf,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rate limit scope for identifying the rate limit key.
|
|
3
|
+
*
|
|
4
|
+
* - "user": keyed by authenticated user id
|
|
5
|
+
* - "ip": keyed by client IP
|
|
6
|
+
* - "global": single global key
|
|
7
|
+
*/
|
|
8
|
+
export type RateLimitScope = "user" | "ip" | "global";
|
|
9
|
+
/**
|
|
10
|
+
* Rate limit configuration for a contract.
|
|
11
|
+
*
|
|
12
|
+
* This type is used in contract metadata to configure rate limiting behavior.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const getTodoContract = c
|
|
17
|
+
* .get("/api/todos/:id", "getTodo")
|
|
18
|
+
* .pathParams(z.object({ id: z.string() }))
|
|
19
|
+
* .meta({
|
|
20
|
+
* auth: "required",
|
|
21
|
+
* rateLimit: {
|
|
22
|
+
* max: 60,
|
|
23
|
+
* windowSec: 60,
|
|
24
|
+
* scope: "user",
|
|
25
|
+
* },
|
|
26
|
+
* })
|
|
27
|
+
* .responses({ 200: z.object({ id: z.string(), name: z.string() }) });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export interface RateLimitMeta {
|
|
31
|
+
/**
|
|
32
|
+
* Maximum number of allowed hits within the window.
|
|
33
|
+
*/
|
|
34
|
+
max: number;
|
|
35
|
+
/**
|
|
36
|
+
* Length of the window in seconds.
|
|
37
|
+
*/
|
|
38
|
+
windowSec: number;
|
|
39
|
+
/**
|
|
40
|
+
* Scope for identifying the rate limit key.
|
|
41
|
+
*
|
|
42
|
+
* - "user": keyed by authenticated user id
|
|
43
|
+
* - "ip": keyed by client IP
|
|
44
|
+
* - "global": single global key
|
|
45
|
+
*
|
|
46
|
+
* Default: "global".
|
|
47
|
+
*/
|
|
48
|
+
scope?: RateLimitScope;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=rate-limit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../src/contracts/rate-limit.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,cAAc,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit.js","sourceRoot":"","sources":["../../src/contracts/rate-limit.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
import type { OpenAPIOperationMeta } from "./openapi-meta";
|
|
3
|
+
import type { RateLimitMeta } from "./rate-limit";
|
|
4
|
+
/**
|
|
5
|
+
* Any Standard Schema validator type
|
|
6
|
+
* Replaces ZodTypeAny to support all Standard Schema compatible libraries
|
|
7
|
+
*/
|
|
8
|
+
export type StandardSchema = StandardSchemaV1<unknown, unknown>;
|
|
9
|
+
export type ContractResponseSchema = StandardSchema | null;
|
|
10
|
+
export type ContractResponses = Partial<Record<number, ContractResponseSchema>>;
|
|
11
|
+
export type StandardErrorResponseBody = {
|
|
12
|
+
code: string;
|
|
13
|
+
message: string;
|
|
14
|
+
details?: unknown;
|
|
15
|
+
requestId?: string;
|
|
16
|
+
};
|
|
17
|
+
export type StandardErrorResponseSchema = StandardSchemaV1<unknown, StandardErrorResponseBody>;
|
|
18
|
+
export type ContractErrorDefinition = {
|
|
19
|
+
code: string;
|
|
20
|
+
status: number;
|
|
21
|
+
message: string;
|
|
22
|
+
details?: StandardSchema;
|
|
23
|
+
};
|
|
24
|
+
export type ContractErrorResponses = Record<string, ContractErrorDefinition>;
|
|
25
|
+
export type ResponsesFromErrorDefinitions<T extends ContractErrorResponses> = {
|
|
26
|
+
[K in keyof T as T[K]["status"]]: StandardErrorResponseSchema;
|
|
27
|
+
};
|
|
28
|
+
export type ContractHeaderSchemas = StandardSchema | readonly StandardSchema[] | null;
|
|
29
|
+
export declare const BEIGNET_ERROR_OWNER_HEADER = "x-beignet-error-owner";
|
|
30
|
+
export type InferHeaderSchemaInput<T extends ContractHeaderSchemas | undefined> = T extends readonly StandardSchemaV1[] ? UnionToIntersection<InferInput<T[number]>> : T extends StandardSchemaV1 ? InferInput<T> : undefined;
|
|
31
|
+
export type InferHeaderSchemaOutput<T extends ContractHeaderSchemas | undefined> = T extends readonly StandardSchemaV1[] ? UnionToIntersection<InferOutput<T[number]>> : T extends StandardSchemaV1 ? InferOutput<T> : undefined;
|
|
32
|
+
type UnionToIntersection<T> = (T extends unknown ? (value: T) => void : never) extends (value: infer I) => void ? I : never;
|
|
33
|
+
/**
|
|
34
|
+
* Infer the output type from a Standard Schema
|
|
35
|
+
*/
|
|
36
|
+
export type InferOutput<T extends StandardSchemaV1> = StandardSchemaV1.InferOutput<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Infer the input type from a Standard Schema
|
|
39
|
+
*/
|
|
40
|
+
export type InferInput<T extends StandardSchemaV1> = StandardSchemaV1.InferInput<T>;
|
|
41
|
+
/**
|
|
42
|
+
* HTTP methods supported by contracts
|
|
43
|
+
*/
|
|
44
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
|
|
45
|
+
export type BodyHttpMethod = Extract<HttpMethod, "POST" | "PUT" | "PATCH">;
|
|
46
|
+
export declare const BODY_HTTP_METHODS: readonly ["POST", "PUT", "PATCH"];
|
|
47
|
+
export declare function methodSupportsRequestBody(method: HttpMethod): method is BodyHttpMethod;
|
|
48
|
+
export declare const STANDARD_ERROR_RESPONSE_SCHEMA: StandardErrorResponseSchema;
|
|
49
|
+
/**
|
|
50
|
+
* Contract metadata - freeform object for policies, auth, etc.
|
|
51
|
+
* May include an optional openapi namespace for OpenAPI-specific metadata,
|
|
52
|
+
* and an optional rateLimit namespace for rate limiting configuration.
|
|
53
|
+
*/
|
|
54
|
+
export type ContractMeta = {
|
|
55
|
+
openapi?: OpenAPIOperationMeta;
|
|
56
|
+
/**
|
|
57
|
+
* Optional rate limit configuration for this contract.
|
|
58
|
+
*
|
|
59
|
+
* If absent, no rate limiting is applied.
|
|
60
|
+
*/
|
|
61
|
+
rateLimit?: RateLimitMeta;
|
|
62
|
+
[namespace: string]: unknown;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* HTTP contract configuration
|
|
66
|
+
*/
|
|
67
|
+
export type HttpContractConfig<TMethod extends HttpMethod = HttpMethod, TPathParams extends StandardSchema | null = StandardSchema | null, TQuery extends StandardSchema | null = StandardSchema | null, TBody extends StandardSchema | null = StandardSchema | null, TResponses extends ContractResponses = ContractResponses, TMeta extends ContractMeta = ContractMeta, TPath extends string = string, THeaders extends ContractHeaderSchemas = ContractHeaderSchemas> = {
|
|
68
|
+
kind: "http";
|
|
69
|
+
/**
|
|
70
|
+
* Fully qualified contract name. Contracts created from a namespaced
|
|
71
|
+
* ContractGroup use `${namespace}.${localName}`.
|
|
72
|
+
*/
|
|
73
|
+
name: string;
|
|
74
|
+
/**
|
|
75
|
+
* Optional resource namespace for contracts created from a ContractGroup.
|
|
76
|
+
*/
|
|
77
|
+
namespace?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Contract name without the resource namespace.
|
|
80
|
+
*/
|
|
81
|
+
localName?: string;
|
|
82
|
+
method: TMethod;
|
|
83
|
+
path: TPath;
|
|
84
|
+
pathParams: TPathParams;
|
|
85
|
+
query: TQuery;
|
|
86
|
+
headers?: THeaders;
|
|
87
|
+
body: TBody;
|
|
88
|
+
responses: TResponses;
|
|
89
|
+
metadata: TMeta;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Any contract type
|
|
93
|
+
*/
|
|
94
|
+
export type AnyContract = HttpContractConfig;
|
|
95
|
+
export declare function getContractHeaderSchemas(headers: ContractHeaderSchemas | undefined): readonly StandardSchema[];
|
|
96
|
+
export {};
|
|
97
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/contracts/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAEhE,MAAM,MAAM,sBAAsB,GAAG,cAAc,GAAG,IAAI,CAAC;AAC3D,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAC;AAChF,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AACF,MAAM,MAAM,2BAA2B,GAAG,gBAAgB,CACxD,OAAO,EACP,yBAAyB,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