@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.
@@ -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;AAqTrC,+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"}
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 the method is inferred automatically.
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?: never;
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
- * | omitted/undefined | ❌ | GET route |
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 inferred automatically
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.method;
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 ?? defaultIsEmptyResponseExpected,
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 (hasBody) {
24
- // Payload route (POST/PUT/PATCH)
19
+ if (method === 'post' || method === 'put' || method === 'patch') {
25
20
  return {
26
21
  ...baseFields,
27
- method: 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: 'get',
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":"AA+RA,iBAAiB;AACjB,MAAM,UAAU,iBAAiB,CAC/B,MAKsE;IAGtE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;IAC5B,MAAM,OAAO,GAAG,mBAAmB,IAAI,MAAM,IAAI,MAAM,CAAC,iBAAiB,KAAK,SAAS,CAAA;IAEvF,oEAAoE;IACpE,MAAM,aAAa,GAAG,MAAM,KAAK,QAAQ,CAAA;IACzC,MAAM,8BAA8B,GAAG,aAAa,CAAA;IAEpD,MAAM,UAAU,GAAG;QACjB,uBAAuB,EAAE,MAAM,CAAC,uBAAuB,IAAI,8BAA8B;QACzF,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,OAAO,EAAE,CAAC;QACZ,iCAAiC;QACjC,OAAO;YACL,GAAG,UAAU;YACb,MAAM,EAAE,MAAk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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?: 'post' | 'put' | 'patch';
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?: 'post' | 'put' | 'patch';
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, hasBody, defaultMethod) {
69
- return hasBody ? (config.method ?? defaultMethod) : 'get';
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, hasBody, 'post'),
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, hasBody, 'post'),
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/sseCont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