@lokalise/api-contracts 6.5.0 → 6.5.2
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/dist/contractBuilder.d.ts +2 -0
- package/dist/contractBuilder.js.map +1 -1
- package/dist/rest/restContractBuilder.d.ts +6 -4
- package/dist/rest/restContractBuilder.js +5 -18
- package/dist/rest/restContractBuilder.js.map +1 -1
- package/dist/sse/sseContractBuilders.d.ts +4 -2
- package/dist/sse/sseContractBuilders.js +4 -4
- package/dist/sse/sseContractBuilders.js.map +1 -1
- package/package.json +1 -1
|
@@ -29,6 +29,7 @@ import type { SSEEventSchemas } from './sse/sseTypes.ts';
|
|
|
29
29
|
* ```typescript
|
|
30
30
|
* // REST GET route
|
|
31
31
|
* const getUsers = buildContract({
|
|
32
|
+
* method: 'get',
|
|
32
33
|
* successResponseBodySchema: z.array(userSchema),
|
|
33
34
|
* pathResolver: () => '/api/users',
|
|
34
35
|
* })
|
|
@@ -50,6 +51,7 @@ import type { SSEEventSchemas } from './sse/sseTypes.ts';
|
|
|
50
51
|
*
|
|
51
52
|
* // SSE-only streaming endpoint
|
|
52
53
|
* const notifications = buildContract({
|
|
54
|
+
* method: 'get',
|
|
53
55
|
* pathResolver: () => '/api/notifications/stream',
|
|
54
56
|
* requestPathParamsSchema: z.object({}),
|
|
55
57
|
* requestQuerySchema: z.object({}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contractBuilder.js","sourceRoot":"","sources":["../src/contractBuilder.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,iBAAiB,GAIlB,MAAM,+BAA+B,CAAA;AAEtC,OAAO,EACL,gBAAgB,GAKjB,MAAM,8BAA8B,CAAA;
|
|
1
|
+
{"version":3,"file":"contractBuilder.js","sourceRoot":"","sources":["../src/contractBuilder.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,iBAAiB,GAIlB,MAAM,+BAA+B,CAAA;AAEtC,OAAO,EACL,gBAAgB,GAKjB,MAAM,8BAA8B,CAAA;AAuTrC,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E,MAAM,UAAU,aAAa;AAC3B,wEAAwE;AACxE,MAAW;IAGX,MAAM,YAAY,GAChB,wBAAwB,IAAI,MAAM,IAAI,MAAM,CAAC,sBAAsB,KAAK,SAAS,CAAA;IAEnF,IAAI,YAAY,EAAE,CAAC;QACjB,mCAAmC;QACnC,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAA;IACjC,CAAC;IAED,oCAAoC;IACpC,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAA;AAClC,CAAC"}
|
|
@@ -3,10 +3,10 @@ import type { CommonRouteDefinition, DeleteRouteDefinition, GetRouteDefinition,
|
|
|
3
3
|
import type { HttpStatusCode } from '../HttpStatusCodes.ts';
|
|
4
4
|
/**
|
|
5
5
|
* Configuration for building a GET route.
|
|
6
|
-
* GET routes have no request body and
|
|
6
|
+
* GET routes have no request body and require method: 'get'.
|
|
7
7
|
*/
|
|
8
8
|
export type GetContractConfig<SuccessResponseBodySchema extends z.Schema | undefined = undefined, PathParamsSchema extends z.Schema | undefined = undefined, RequestQuerySchema extends z.Schema | undefined = undefined, RequestHeaderSchema extends z.Schema | undefined = undefined, ResponseHeaderSchema extends z.Schema | undefined = undefined, IsNonJSONResponseExpected extends boolean = false, IsEmptyResponseExpected extends boolean = false, ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined = undefined> = Omit<CommonRouteDefinition<SuccessResponseBodySchema, PathParamsSchema, RequestQuerySchema, RequestHeaderSchema, ResponseHeaderSchema, IsNonJSONResponseExpected, IsEmptyResponseExpected, ResponseSchemasByStatusCode>, 'method'> & {
|
|
9
|
-
method
|
|
9
|
+
method: 'get';
|
|
10
10
|
requestBodySchema?: never;
|
|
11
11
|
/** Discriminator to distinguish from SSE contracts in buildContract */
|
|
12
12
|
serverSentEventSchemas?: never;
|
|
@@ -41,20 +41,22 @@ export type PayloadContractConfig<RequestBodySchema extends z.Schema | undefined
|
|
|
41
41
|
*
|
|
42
42
|
* | `method` | `requestBodySchema` | Result |
|
|
43
43
|
* |----------|---------------------|--------|
|
|
44
|
-
* |
|
|
44
|
+
* | `'get'` | ❌ | GET route |
|
|
45
45
|
* | `'delete'` | ❌ | DELETE route |
|
|
46
46
|
* | `'post'`/`'put'`/`'patch'` | ✅ | Payload route |
|
|
47
47
|
*
|
|
48
48
|
* @example
|
|
49
49
|
* ```typescript
|
|
50
|
-
* // GET route - method is
|
|
50
|
+
* // GET route - method: 'get' is required
|
|
51
51
|
* const getUsers = buildRestContract({
|
|
52
|
+
* method: 'get',
|
|
52
53
|
* pathResolver: () => '/api/users',
|
|
53
54
|
* successResponseBodySchema: z.array(userSchema),
|
|
54
55
|
* })
|
|
55
56
|
*
|
|
56
57
|
* // GET route with path params
|
|
57
58
|
* const getUser = buildRestContract({
|
|
59
|
+
* method: 'get',
|
|
58
60
|
* pathResolver: (params) => `/api/users/${params.userId}`,
|
|
59
61
|
* requestPathParamsSchema: z.object({ userId: z.string() }),
|
|
60
62
|
* successResponseBodySchema: userSchema,
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
// Implementation
|
|
2
2
|
export function buildRestContract(config) {
|
|
3
|
-
const method = config
|
|
4
|
-
const hasBody = 'requestBodySchema' in config && config.requestBodySchema !== undefined;
|
|
5
|
-
// Determine default for isEmptyResponseExpected based on route type
|
|
6
|
-
const isDeleteRoute = method === 'delete';
|
|
7
|
-
const defaultIsEmptyResponseExpected = isDeleteRoute;
|
|
3
|
+
const { method } = config;
|
|
8
4
|
const baseFields = {
|
|
9
|
-
isEmptyResponseExpected: config.isEmptyResponseExpected ??
|
|
5
|
+
isEmptyResponseExpected: config.isEmptyResponseExpected ?? method === 'delete',
|
|
10
6
|
isNonJSONResponseExpected: config.isNonJSONResponseExpected ?? false,
|
|
11
7
|
pathResolver: config.pathResolver,
|
|
12
8
|
requestHeaderSchema: config.requestHeaderSchema,
|
|
@@ -20,26 +16,17 @@ export function buildRestContract(config) {
|
|
|
20
16
|
metadata: config.metadata,
|
|
21
17
|
tags: config.tags,
|
|
22
18
|
};
|
|
23
|
-
if (
|
|
24
|
-
// Payload route (POST/PUT/PATCH)
|
|
19
|
+
if (method === 'post' || method === 'put' || method === 'patch') {
|
|
25
20
|
return {
|
|
26
21
|
...baseFields,
|
|
27
|
-
method
|
|
22
|
+
method,
|
|
28
23
|
// biome-ignore lint/suspicious/noExplicitAny: Type assertion needed for config union
|
|
29
24
|
requestBodySchema: config.requestBodySchema,
|
|
30
25
|
};
|
|
31
26
|
}
|
|
32
|
-
if (isDeleteRoute) {
|
|
33
|
-
// DELETE route
|
|
34
|
-
return {
|
|
35
|
-
...baseFields,
|
|
36
|
-
method: 'delete',
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
// GET route (default)
|
|
40
27
|
return {
|
|
41
28
|
...baseFields,
|
|
42
|
-
method
|
|
29
|
+
method,
|
|
43
30
|
};
|
|
44
31
|
}
|
|
45
32
|
//# sourceMappingURL=restContractBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restContractBuilder.js","sourceRoot":"","sources":["../../src/rest/restContractBuilder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"restContractBuilder.js","sourceRoot":"","sources":["../../src/rest/restContractBuilder.ts"],"names":[],"mappings":"AAiSA,iBAAiB;AACjB,MAAM,UAAU,iBAAiB,CAC/B,MAKsE;IAGtE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IAEzB,MAAM,UAAU,GAAG;QACjB,uBAAuB,EAAE,MAAM,CAAC,uBAAuB,IAAI,MAAM,KAAK,QAAQ;QAC9E,yBAAyB,EAAE,MAAM,CAAC,yBAAyB,IAAI,KAAK;QACpE,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;QAC/C,oBAAoB,EAAE,MAAM,CAAC,oBAAoB;QACjD,uBAAuB,EAAE,MAAM,CAAC,uBAAuB;QACvD,kBAAkB,EAAE,MAAM,CAAC,kBAAkB;QAC7C,yBAAyB,EAAE,MAAM,CAAC,yBAAyB;QAC3D,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,2BAA2B,EAAE,MAAM,CAAC,2BAA2B;QAC/D,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,IAAI,EAAE,MAAM,CAAC,IAAI;KAClB,CAAA;IAED,IAAI,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK,KAAK,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;QAChE,OAAO;YACL,GAAG,UAAU;YACb,MAAM;YACN,qFAAqF;YACrF,iBAAiB,EAAG,MAAqC,CAAC,iBAAiB;SAC5E,CAAA;IACH,CAAC;IAED,OAAO;QACL,GAAG,UAAU;QACb,MAAM;KACP,CAAA;AACH,CAAC"}
|
|
@@ -9,6 +9,7 @@ import type { SSEEventSchemas } from './sseTypes.ts';
|
|
|
9
9
|
* Forbids requestBodySchema for GET variants.
|
|
10
10
|
*/
|
|
11
11
|
export type SSEGetContractConfig<Params extends z.ZodTypeAny, Query extends z.ZodTypeAny, RequestHeaders extends z.ZodTypeAny, Events extends SSEEventSchemas, ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.ZodTypeAny>> | undefined = undefined> = {
|
|
12
|
+
method: 'get';
|
|
12
13
|
pathResolver: RoutePathResolver<z.infer<Params>>;
|
|
13
14
|
requestPathParamsSchema: Params;
|
|
14
15
|
requestQuerySchema: Query;
|
|
@@ -36,7 +37,7 @@ export type SSEGetContractConfig<Params extends z.ZodTypeAny, Query extends z.Zo
|
|
|
36
37
|
* Requires requestBodySchema for payload variants.
|
|
37
38
|
*/
|
|
38
39
|
export type SSEPayloadContractConfig<Params extends z.ZodTypeAny, Query extends z.ZodTypeAny, RequestHeaders extends z.ZodTypeAny, Body extends z.ZodTypeAny, Events extends SSEEventSchemas, ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.ZodTypeAny>> | undefined = undefined> = {
|
|
39
|
-
method
|
|
40
|
+
method: 'post' | 'put' | 'patch';
|
|
40
41
|
pathResolver: RoutePathResolver<z.infer<Params>>;
|
|
41
42
|
requestPathParamsSchema: Params;
|
|
42
43
|
requestQuerySchema: Query;
|
|
@@ -64,6 +65,7 @@ export type SSEPayloadContractConfig<Params extends z.ZodTypeAny, Query extends
|
|
|
64
65
|
* Requires successResponseBodySchema, forbids requestBodySchema.
|
|
65
66
|
*/
|
|
66
67
|
export type DualModeGetContractConfig<Params extends z.ZodTypeAny, Query extends z.ZodTypeAny, RequestHeaders extends z.ZodTypeAny, JsonResponse extends z.ZodTypeAny, Events extends SSEEventSchemas, ResponseHeaders extends z.ZodTypeAny | undefined = undefined, ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.ZodTypeAny>> | undefined = undefined> = {
|
|
68
|
+
method: 'get';
|
|
67
69
|
pathResolver: RoutePathResolver<z.infer<Params>>;
|
|
68
70
|
requestPathParamsSchema: Params;
|
|
69
71
|
requestQuerySchema: Query;
|
|
@@ -104,7 +106,7 @@ export type DualModeGetContractConfig<Params extends z.ZodTypeAny, Query extends
|
|
|
104
106
|
* Requires both requestBodySchema and successResponseBodySchema.
|
|
105
107
|
*/
|
|
106
108
|
export type DualModePayloadContractConfig<Params extends z.ZodTypeAny, Query extends z.ZodTypeAny, RequestHeaders extends z.ZodTypeAny, Body extends z.ZodTypeAny, JsonResponse extends z.ZodTypeAny, Events extends SSEEventSchemas, ResponseHeaders extends z.ZodTypeAny | undefined = undefined, ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.ZodTypeAny>> | undefined = undefined> = {
|
|
107
|
-
method
|
|
109
|
+
method: 'post' | 'put' | 'patch';
|
|
108
110
|
pathResolver: RoutePathResolver<z.infer<Params>>;
|
|
109
111
|
requestPathParamsSchema: Params;
|
|
110
112
|
requestQuerySchema: Query;
|
|
@@ -65,8 +65,8 @@ function buildBaseFields(config, hasBody) {
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
// Helper to determine method
|
|
68
|
-
function determineMethod(config
|
|
69
|
-
return
|
|
68
|
+
function determineMethod(config) {
|
|
69
|
+
return config.method;
|
|
70
70
|
}
|
|
71
71
|
// Implementation
|
|
72
72
|
export function buildSseContract(config) {
|
|
@@ -77,7 +77,7 @@ export function buildSseContract(config) {
|
|
|
77
77
|
// Dual-mode contract
|
|
78
78
|
return {
|
|
79
79
|
...base,
|
|
80
|
-
method: determineMethod(config
|
|
80
|
+
method: determineMethod(config),
|
|
81
81
|
successResponseBodySchema: config
|
|
82
82
|
.successResponseBodySchema,
|
|
83
83
|
responseHeaderSchema: config.responseHeaderSchema,
|
|
@@ -89,7 +89,7 @@ export function buildSseContract(config) {
|
|
|
89
89
|
// SSE-only contract
|
|
90
90
|
return {
|
|
91
91
|
...base,
|
|
92
|
-
method: determineMethod(config
|
|
92
|
+
method: determineMethod(config),
|
|
93
93
|
responseBodySchemasByStatusCode: config
|
|
94
94
|
.responseBodySchemasByStatusCode,
|
|
95
95
|
isSSE: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sseContractBuilders.js","sourceRoot":"","sources":["../../src/sse/sseContractBuilders.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sseContractBuilders.js","sourceRoot":"","sources":["../../src/sse/sseContractBuilders.ts"],"names":[],"mappings":"AA2LA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAEH,uCAAuC;AACvC,gEAAgE;AAChE,SAAS,eAAe,CAAC,MAAW,EAAE,OAAgB;IACpD,OAAO;QACL,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,uBAAuB,EAAE,MAAM,CAAC,uBAAuB;QACvD,kBAAkB,EAAE,MAAM,CAAC,kBAAkB;QAC7C,mBAAmB,EAAE,MAAM,CAA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