@kontract/adonis 0.1.0
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/README.md +507 -0
- package/dist/adapters/controller-registrar.d.ts +313 -0
- package/dist/adapters/controller-registrar.d.ts.map +1 -0
- package/dist/adapters/controller-registrar.js +324 -0
- package/dist/adapters/controller-registrar.js.map +1 -0
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +2 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/route-registrar.d.ts +53 -0
- package/dist/adapters/route-registrar.d.ts.map +1 -0
- package/dist/adapters/route-registrar.js +139 -0
- package/dist/adapters/route-registrar.js.map +1 -0
- package/dist/adapters/router.d.ts +37 -0
- package/dist/adapters/router.d.ts.map +1 -0
- package/dist/adapters/router.js +129 -0
- package/dist/adapters/router.js.map +1 -0
- package/dist/builder/index.d.ts +2 -0
- package/dist/builder/index.d.ts.map +1 -0
- package/dist/builder/index.js +3 -0
- package/dist/builder/index.js.map +1 -0
- package/dist/builder/openapi-builder.d.ts +100 -0
- package/dist/builder/openapi-builder.d.ts.map +1 -0
- package/dist/builder/openapi-builder.js +388 -0
- package/dist/builder/openapi-builder.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/serializers/index.d.ts +2 -0
- package/dist/serializers/index.d.ts.map +1 -0
- package/dist/serializers/index.js +2 -0
- package/dist/serializers/index.js.map +1 -0
- package/dist/serializers/lucid.d.ts +100 -0
- package/dist/serializers/lucid.d.ts.map +1 -0
- package/dist/serializers/lucid.js +114 -0
- package/dist/serializers/lucid.js.map +1 -0
- package/dist/validation/ajv.d.ts +42 -0
- package/dist/validation/ajv.d.ts.map +1 -0
- package/dist/validation/ajv.js +170 -0
- package/dist/validation/ajv.js.map +1 -0
- package/dist/validation/index.d.ts +2 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +3 -0
- package/dist/validation/index.js.map +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { getApiMetadata, getEndpointMetadata, getRegisteredControllers, } from '@blog/openapi-decorators';
|
|
2
|
+
/**
|
|
3
|
+
* Builds an OpenAPI specification from registered @Api and @Endpoint decorators.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const builder = new OpenApiBuilder({
|
|
8
|
+
* title: 'My API',
|
|
9
|
+
* description: 'API description',
|
|
10
|
+
* version: '1.0.0',
|
|
11
|
+
* servers: [{ url: 'http://localhost:3333', description: 'Development' }],
|
|
12
|
+
* })
|
|
13
|
+
*
|
|
14
|
+
* const spec = builder.build()
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export class OpenApiBuilder {
|
|
18
|
+
document;
|
|
19
|
+
schemas = new Map();
|
|
20
|
+
tags = new Map();
|
|
21
|
+
securitySchemeName;
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.securitySchemeName = options.securityScheme?.name ?? 'BearerAuth';
|
|
24
|
+
const securitySchemes = {
|
|
25
|
+
[this.securitySchemeName]: options.securityScheme ?? {
|
|
26
|
+
type: 'http',
|
|
27
|
+
scheme: 'bearer',
|
|
28
|
+
bearerFormat: 'JWT',
|
|
29
|
+
description: 'Access token obtained from /api/v1/auth/login',
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
this.document = {
|
|
33
|
+
openapi: options.openapiVersion ?? '3.1.0',
|
|
34
|
+
info: {
|
|
35
|
+
title: options.title,
|
|
36
|
+
description: options.description,
|
|
37
|
+
version: options.version,
|
|
38
|
+
},
|
|
39
|
+
servers: options.servers,
|
|
40
|
+
tags: [],
|
|
41
|
+
paths: {},
|
|
42
|
+
components: {
|
|
43
|
+
schemas: {},
|
|
44
|
+
securitySchemes: securitySchemes,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Build the OpenAPI document from registered decorators.
|
|
50
|
+
*/
|
|
51
|
+
build() {
|
|
52
|
+
const controllers = getRegisteredControllers();
|
|
53
|
+
for (const controller of controllers) {
|
|
54
|
+
const apiMeta = getApiMetadata(controller);
|
|
55
|
+
const endpoints = getEndpointMetadata(controller);
|
|
56
|
+
if (!apiMeta)
|
|
57
|
+
continue;
|
|
58
|
+
// Register tag
|
|
59
|
+
this.tags.set(apiMeta.tag, apiMeta.description);
|
|
60
|
+
// Process endpoints
|
|
61
|
+
for (const endpoint of endpoints) {
|
|
62
|
+
this.processEndpoint(apiMeta, endpoint);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Finalize tags
|
|
66
|
+
this.document.tags = Array.from(this.tags.entries())
|
|
67
|
+
.map(([name, description]) => ({ name, ...(description && { description }) }))
|
|
68
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
69
|
+
// Finalize schemas
|
|
70
|
+
for (const [name, schema] of this.schemas) {
|
|
71
|
+
this.document.components.schemas[name] = this.toJsonSchema(schema);
|
|
72
|
+
}
|
|
73
|
+
return this.document;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Process a single endpoint and add it to the document.
|
|
77
|
+
*/
|
|
78
|
+
processEndpoint(apiMeta, endpoint) {
|
|
79
|
+
// Convert path params (:id) to OpenAPI format ({id})
|
|
80
|
+
const openApiPath = endpoint.path.replace(/:(\w+)/g, '{$1}');
|
|
81
|
+
if (!this.document.paths[openApiPath]) {
|
|
82
|
+
this.document.paths[openApiPath] = {};
|
|
83
|
+
}
|
|
84
|
+
// Build operation object incrementally
|
|
85
|
+
const operation = {
|
|
86
|
+
tags: [apiMeta.tag],
|
|
87
|
+
summary: endpoint.summary,
|
|
88
|
+
operationId: endpoint.operationId ?? this.generateOperationId(endpoint),
|
|
89
|
+
};
|
|
90
|
+
if (endpoint.description) {
|
|
91
|
+
operation.description = endpoint.description;
|
|
92
|
+
}
|
|
93
|
+
if (endpoint.deprecated) {
|
|
94
|
+
operation.deprecated = true;
|
|
95
|
+
}
|
|
96
|
+
// Security
|
|
97
|
+
if (endpoint.auth === 'required') {
|
|
98
|
+
operation.security = [{ [this.securitySchemeName]: [] }];
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
operation.security = [];
|
|
102
|
+
}
|
|
103
|
+
// Parameters
|
|
104
|
+
const parameters = this.buildParameters(endpoint);
|
|
105
|
+
if (parameters.length > 0) {
|
|
106
|
+
operation.parameters = parameters;
|
|
107
|
+
}
|
|
108
|
+
// Request body
|
|
109
|
+
if (endpoint.file) {
|
|
110
|
+
operation.requestBody = this.buildFileRequestBody(endpoint);
|
|
111
|
+
}
|
|
112
|
+
else if (endpoint.body) {
|
|
113
|
+
const schemaName = this.registerSchema(endpoint.body);
|
|
114
|
+
const bodyDescription = endpoint.body
|
|
115
|
+
.description;
|
|
116
|
+
operation.requestBody = {
|
|
117
|
+
required: true,
|
|
118
|
+
...(bodyDescription && { description: bodyDescription }),
|
|
119
|
+
content: {
|
|
120
|
+
'application/json': {
|
|
121
|
+
schema: { $ref: `#/components/schemas/${schemaName}` },
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
// Responses (required field)
|
|
127
|
+
operation.responses = this.buildResponses(endpoint);
|
|
128
|
+
this.document.paths[openApiPath][endpoint.method] = operation;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Build file upload request body.
|
|
132
|
+
*/
|
|
133
|
+
buildFileRequestBody(endpoint) {
|
|
134
|
+
const file = endpoint.file;
|
|
135
|
+
const fileSchema = file.multiple
|
|
136
|
+
? {
|
|
137
|
+
type: 'array',
|
|
138
|
+
items: { type: 'string', format: 'binary' },
|
|
139
|
+
description: file.description ?? 'Files to upload',
|
|
140
|
+
}
|
|
141
|
+
: {
|
|
142
|
+
type: 'string',
|
|
143
|
+
format: 'binary',
|
|
144
|
+
description: file.description ?? 'File to upload',
|
|
145
|
+
};
|
|
146
|
+
const schema = {
|
|
147
|
+
type: 'object',
|
|
148
|
+
required: [file.fieldName],
|
|
149
|
+
properties: {
|
|
150
|
+
[file.fieldName]: fileSchema,
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
// Merge with body schema if present
|
|
154
|
+
if (endpoint.body?.properties) {
|
|
155
|
+
const bodyProps = endpoint.body.properties;
|
|
156
|
+
const schemaProps = schema.properties;
|
|
157
|
+
for (const [name, propSchema] of Object.entries(bodyProps)) {
|
|
158
|
+
schemaProps[name] = this.toJsonSchema(propSchema);
|
|
159
|
+
}
|
|
160
|
+
if (endpoint.body.required) {
|
|
161
|
+
const schemaRequired = schema.required;
|
|
162
|
+
for (const field of endpoint.body.required) {
|
|
163
|
+
if (!schemaRequired.includes(field)) {
|
|
164
|
+
schemaRequired.push(field);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
required: true,
|
|
171
|
+
description: file.description ?? 'File upload',
|
|
172
|
+
content: {
|
|
173
|
+
'multipart/form-data': { schema },
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Build parameters from endpoint metadata.
|
|
179
|
+
*/
|
|
180
|
+
buildParameters(endpoint) {
|
|
181
|
+
const parameters = [];
|
|
182
|
+
// Extract path parameter names from URL
|
|
183
|
+
const pathParamNames = new Set();
|
|
184
|
+
const pathParamRegex = /:(\w+)/g;
|
|
185
|
+
let match;
|
|
186
|
+
while ((match = pathParamRegex.exec(endpoint.path)) !== null) {
|
|
187
|
+
pathParamNames.add(match[1]);
|
|
188
|
+
}
|
|
189
|
+
// Path parameters from schema
|
|
190
|
+
if (endpoint.params) {
|
|
191
|
+
parameters.push(...this.schemaToParameters(endpoint.params, 'path'));
|
|
192
|
+
if (endpoint.params.properties) {
|
|
193
|
+
for (const name of Object.keys(endpoint.params.properties)) {
|
|
194
|
+
pathParamNames.delete(name);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// Add remaining path parameters
|
|
199
|
+
for (const name of pathParamNames) {
|
|
200
|
+
parameters.push({
|
|
201
|
+
name,
|
|
202
|
+
in: 'path',
|
|
203
|
+
required: true,
|
|
204
|
+
description: `The ${name} parameter`,
|
|
205
|
+
schema: { type: 'string' },
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
// Query parameters
|
|
209
|
+
if (endpoint.query) {
|
|
210
|
+
parameters.push(...this.schemaToParameters(endpoint.query, 'query'));
|
|
211
|
+
}
|
|
212
|
+
return parameters;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Convert a TypeBox schema to OpenAPI parameters.
|
|
216
|
+
*/
|
|
217
|
+
schemaToParameters(schema, location) {
|
|
218
|
+
const parameters = [];
|
|
219
|
+
if (schema.type !== 'object' || !schema.properties) {
|
|
220
|
+
return parameters;
|
|
221
|
+
}
|
|
222
|
+
const required = new Set(schema.required ?? []);
|
|
223
|
+
for (const [name, propSchema] of Object.entries(schema.properties)) {
|
|
224
|
+
const prop = propSchema;
|
|
225
|
+
parameters.push({
|
|
226
|
+
name,
|
|
227
|
+
in: location,
|
|
228
|
+
required: location === 'path' ? true : required.has(name),
|
|
229
|
+
...(prop.description && { description: prop.description }),
|
|
230
|
+
schema: this.toJsonSchema(prop),
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
return parameters;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Build responses from endpoint metadata.
|
|
237
|
+
*/
|
|
238
|
+
buildResponses(endpoint) {
|
|
239
|
+
const responses = {};
|
|
240
|
+
for (const [status, response] of Object.entries(endpoint.responses)) {
|
|
241
|
+
if (response.schema === null) {
|
|
242
|
+
responses[status] = {
|
|
243
|
+
description: response.description ?? this.defaultDescription(Number(status)),
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
const schemaName = this.registerSchema(response.schema);
|
|
248
|
+
responses[status] = {
|
|
249
|
+
description: response.description ?? this.defaultDescription(Number(status)),
|
|
250
|
+
content: {
|
|
251
|
+
'application/json': {
|
|
252
|
+
schema: { $ref: `#/components/schemas/${schemaName}` },
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// Auto-add 401 for auth required endpoints
|
|
259
|
+
if (endpoint.auth === 'required' && !responses['401']) {
|
|
260
|
+
responses['401'] = {
|
|
261
|
+
description: 'Unauthorized - authentication required',
|
|
262
|
+
content: {
|
|
263
|
+
'application/json': {
|
|
264
|
+
schema: {
|
|
265
|
+
type: 'object',
|
|
266
|
+
properties: {
|
|
267
|
+
message: { type: 'string', description: 'Error message' },
|
|
268
|
+
},
|
|
269
|
+
required: ['message'],
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
return responses;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Register a schema and return its name.
|
|
279
|
+
*/
|
|
280
|
+
registerSchema(schema) {
|
|
281
|
+
const name = schema.$id ?? schema.title ?? `Schema${this.schemas.size + 1}`;
|
|
282
|
+
if (!this.schemas.has(name)) {
|
|
283
|
+
this.schemas.set(name, schema);
|
|
284
|
+
this.extractNestedSchemas(schema);
|
|
285
|
+
}
|
|
286
|
+
return name;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Extract and register nested schemas with $id.
|
|
290
|
+
*/
|
|
291
|
+
extractNestedSchemas(schema) {
|
|
292
|
+
if (!schema || typeof schema !== 'object')
|
|
293
|
+
return;
|
|
294
|
+
if (Array.isArray(schema)) {
|
|
295
|
+
schema.forEach((item) => this.extractNestedSchemas(item));
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const record = schema;
|
|
299
|
+
if (record.$id && typeof record.$id === 'string') {
|
|
300
|
+
if (!this.schemas.has(record.$id)) {
|
|
301
|
+
this.schemas.set(record.$id, schema);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
for (const value of Object.values(record)) {
|
|
305
|
+
this.extractNestedSchemas(value);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Convert TypeBox schema to JSON Schema (for OpenAPI).
|
|
310
|
+
*/
|
|
311
|
+
toJsonSchema(schema) {
|
|
312
|
+
const result = JSON.parse(JSON.stringify(schema));
|
|
313
|
+
return this.removeTypeBoxProps(result);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Remove TypeBox-specific properties from schema.
|
|
317
|
+
*/
|
|
318
|
+
removeTypeBoxProps(obj) {
|
|
319
|
+
if (obj === null || typeof obj !== 'object') {
|
|
320
|
+
return obj;
|
|
321
|
+
}
|
|
322
|
+
if (Array.isArray(obj)) {
|
|
323
|
+
return obj.map((item) => this.removeTypeBoxProps(item));
|
|
324
|
+
}
|
|
325
|
+
const record = obj;
|
|
326
|
+
const result = {};
|
|
327
|
+
const isSchemaDefinition = 'type' in record
|
|
328
|
+
|| 'anyOf' in record
|
|
329
|
+
|| 'oneOf' in record
|
|
330
|
+
|| 'allOf' in record;
|
|
331
|
+
for (const [key, value] of Object.entries(record)) {
|
|
332
|
+
// Skip $id (TypeBox schema identifier)
|
|
333
|
+
if (key === '$id')
|
|
334
|
+
continue;
|
|
335
|
+
// Skip errorMessage in schema definitions
|
|
336
|
+
if (key === 'errorMessage' && isSchemaDefinition)
|
|
337
|
+
continue;
|
|
338
|
+
result[key] = this.removeTypeBoxProps(value);
|
|
339
|
+
}
|
|
340
|
+
return result;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Generate an operation ID from endpoint metadata.
|
|
344
|
+
*/
|
|
345
|
+
generateOperationId(endpoint) {
|
|
346
|
+
const { method, path, methodName } = endpoint;
|
|
347
|
+
const genericNames = ['index', 'show', 'store', 'update', 'destroy'];
|
|
348
|
+
if (!genericNames.includes(methodName)) {
|
|
349
|
+
return methodName;
|
|
350
|
+
}
|
|
351
|
+
const segments = path
|
|
352
|
+
.replace(/^\/api\/v\d+\//, '')
|
|
353
|
+
.replace(/:/g, '')
|
|
354
|
+
.split('/')
|
|
355
|
+
.filter(Boolean);
|
|
356
|
+
const resource = segments[0] ?? 'resource';
|
|
357
|
+
const hasId = segments.includes('id');
|
|
358
|
+
const prefixes = {
|
|
359
|
+
get: hasId ? 'get' : 'list',
|
|
360
|
+
post: 'create',
|
|
361
|
+
put: 'update',
|
|
362
|
+
patch: 'patch',
|
|
363
|
+
delete: 'delete',
|
|
364
|
+
};
|
|
365
|
+
const prefix = prefixes[method] ?? method;
|
|
366
|
+
const singular = resource.replace(/s$/, '');
|
|
367
|
+
const name = hasId ? singular : resource;
|
|
368
|
+
return `${prefix}${name.charAt(0).toUpperCase() + name.slice(1)}`;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Get default description for a status code.
|
|
372
|
+
*/
|
|
373
|
+
defaultDescription(status) {
|
|
374
|
+
const descriptions = {
|
|
375
|
+
200: 'Successful response',
|
|
376
|
+
201: 'Resource created',
|
|
377
|
+
204: 'No content',
|
|
378
|
+
400: 'Bad request',
|
|
379
|
+
401: 'Unauthorized',
|
|
380
|
+
403: 'Forbidden',
|
|
381
|
+
404: 'Not found',
|
|
382
|
+
422: 'Validation error',
|
|
383
|
+
500: 'Internal server error',
|
|
384
|
+
};
|
|
385
|
+
return descriptions[status] ?? 'Response';
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
//# sourceMappingURL=openapi-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-builder.js","sourceRoot":"","sources":["../../src/builder/openapi-builder.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,wBAAwB,GAUzB,MAAM,0BAA0B,CAAA;AA4BjC;;;;;;;;;;;;;;GAcG;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C,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAA;QAExC,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;IACnE,CAAC;IAED;;OAEG;IACK,kBAAkB,CAAC,MAAc;QACvC,MAAM,YAAY,GAA2B;YAC3C,GAAG,EAAE,qBAAqB;YAC1B,GAAG,EAAE,kBAAkB;YACvB,GAAG,EAAE,YAAY;YACjB,GAAG,EAAE,aAAa;YAClB,GAAG,EAAE,cAAc;YACnB,GAAG,EAAE,WAAW;YAChB,GAAG,EAAE,WAAW;YAChB,GAAG,EAAE,kBAAkB;YACvB,GAAG,EAAE,uBAAuB;SAC7B,CAAA;QACD,OAAO,YAAY,CAAC,MAAM,CAAC,IAAI,UAAU,CAAA;IAC3C,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* kontract-adonis
|
|
3
|
+
*
|
|
4
|
+
* AdonisJS adapter for kontract.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // Using Elysia-style route builders (recommended)
|
|
9
|
+
* import { get, post, Type, registerController, defineController } from '@kontract/adonis'
|
|
10
|
+
*
|
|
11
|
+
* const getUser = get('/api/v1/users/:id',
|
|
12
|
+
* async ({ params, reply, error }) => {
|
|
13
|
+
* const user = await User.find(params.id)
|
|
14
|
+
* if (!user) return error.notFound('User not found')
|
|
15
|
+
* return reply.ok(user.serialize())
|
|
16
|
+
* },
|
|
17
|
+
* {
|
|
18
|
+
* params: Type.Object({ id: Type.String() }),
|
|
19
|
+
* responses: {
|
|
20
|
+
* 200: { schema: UserResponse },
|
|
21
|
+
* 404: { schema: ApiError },
|
|
22
|
+
* },
|
|
23
|
+
* }
|
|
24
|
+
* )
|
|
25
|
+
*
|
|
26
|
+
* const usersController = defineController({ tag: 'Users' }, { getUser })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export { Type, type Static } from '@sinclair/typebox';
|
|
30
|
+
export { binary, defineConfig, getConfig, defineController, ok, created, accepted, noContent, badRequest, unauthorized, forbidden, notFound, conflict, unprocessableEntity, tooManyRequests, internalServerError, serviceUnavailable, apiError, type ApiResponse, type BinaryResponse, type EndpointMetadata, type ApiMetadata, } from 'kontract';
|
|
31
|
+
export { registerController, registerControllers, get, post, put, patch, del, type RegisterControllerOptions, type AdonisHandlerContext, type AdonisRouteHandler, type AdonisRouteConfig, type AdonisRouteDefinition, type GetRouteOptions, type BodyRouteOptions, } from './adapters/controller-registrar.js';
|
|
32
|
+
export { createAjvValidator, validate, stripNestedIds, getDefaultValidator, resetDefaultValidator, AjvValidationError, type AjvValidatorOptions, } from './validation/index.js';
|
|
33
|
+
export { OpenApiBuilder, type OpenApiBuilderOptions } from './builder/index.js';
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAGH,OAAO,EAAE,IAAI,EAAE,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAGrD,OAAO,EACL,MAAM,EACN,YAAY,EACZ,SAAS,EACT,gBAAgB,EAEhB,EAAE,EACF,OAAO,EACP,QAAQ,EACR,SAAS,EACT,UAAU,EACV,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,QAAQ,EACR,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,WAAW,GACjB,MAAM,UAAU,CAAA;AAKjB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EAEnB,GAAG,EACH,IAAI,EACJ,GAAG,EACH,KAAK,EACL,GAAG,EACH,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACtB,MAAM,oCAAoC,CAAA;AAG3C,OAAO,EACL,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,KAAK,mBAAmB,GACzB,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* kontract-adonis
|
|
3
|
+
*
|
|
4
|
+
* AdonisJS adapter for kontract.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // Using Elysia-style route builders (recommended)
|
|
9
|
+
* import { get, post, Type, registerController, defineController } from '@kontract/adonis'
|
|
10
|
+
*
|
|
11
|
+
* const getUser = get('/api/v1/users/:id',
|
|
12
|
+
* async ({ params, reply, error }) => {
|
|
13
|
+
* const user = await User.find(params.id)
|
|
14
|
+
* if (!user) return error.notFound('User not found')
|
|
15
|
+
* return reply.ok(user.serialize())
|
|
16
|
+
* },
|
|
17
|
+
* {
|
|
18
|
+
* params: Type.Object({ id: Type.String() }),
|
|
19
|
+
* responses: {
|
|
20
|
+
* 200: { schema: UserResponse },
|
|
21
|
+
* 404: { schema: ApiError },
|
|
22
|
+
* },
|
|
23
|
+
* }
|
|
24
|
+
* )
|
|
25
|
+
*
|
|
26
|
+
* const usersController = defineController({ tag: 'Users' }, { getUser })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
// ============ TypeBox re-exports for schema definitions ============
|
|
30
|
+
export { Type } from '@sinclair/typebox';
|
|
31
|
+
// Re-export core helpers and types from kontract
|
|
32
|
+
export { binary, defineConfig, getConfig, defineController,
|
|
33
|
+
// Response helpers
|
|
34
|
+
ok, created, accepted, noContent, badRequest, unauthorized, forbidden, notFound, conflict, unprocessableEntity, tooManyRequests, internalServerError, serviceUnavailable, apiError, } from 'kontract';
|
|
35
|
+
// ============ Adapters ============
|
|
36
|
+
// Response helpers (reply.*, error.*) are provided via the handler context
|
|
37
|
+
// and pre-typed based on the route's responses config.
|
|
38
|
+
export { registerController, registerControllers,
|
|
39
|
+
// Elysia-style route builders (method as function name)
|
|
40
|
+
get, post, put, patch, del, } from './adapters/controller-registrar.js';
|
|
41
|
+
// ============ Validation ============
|
|
42
|
+
export { createAjvValidator, validate, stripNestedIds, getDefaultValidator, resetDefaultValidator, AjvValidationError, } from './validation/index.js';
|
|
43
|
+
// ============ Builder ============
|
|
44
|
+
export { OpenApiBuilder } from './builder/index.js';
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,sEAAsE;AACtE,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAA;AAErD,iDAAiD;AACjD,OAAO,EACL,MAAM,EACN,YAAY,EACZ,SAAS,EACT,gBAAgB;AAChB,mBAAmB;AACnB,EAAE,EACF,OAAO,EACP,QAAQ,EACR,SAAS,EACT,UAAU,EACV,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,QAAQ,GAKT,MAAM,UAAU,CAAA;AAEjB,qCAAqC;AACrC,2EAA2E;AAC3E,uDAAuD;AACvD,OAAO,EACL,kBAAkB,EAClB,mBAAmB;AACnB,wDAAwD;AACxD,GAAG,EACH,IAAI,EACJ,GAAG,EACH,KAAK,EACL,GAAG,GAQJ,MAAM,oCAAoC,CAAA;AAE3C,uCAAuC;AACvC,OAAO,EACL,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,GAEnB,MAAM,uBAAuB,CAAA;AAE9B,oCAAoC;AACpC,OAAO,EAAE,cAAc,EAA8B,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { isLucidModel, isTypedModel, isPaginator, hasSerialize, serializeTypedModel, serializeLucidModel, serializePaginator, typedModelSerializer, lucidModelSerializer, paginatorSerializer, serializableSerializer, lucidSerializers, type SerializableModel, type ResponseModel, type PaginatorLike, } from './lucid.js';
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/serializers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACtB,gBAAgB,EAChB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,aAAa,GACnB,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { isLucidModel, isTypedModel, isPaginator, hasSerialize, serializeTypedModel, serializeLucidModel, serializePaginator, typedModelSerializer, lucidModelSerializer, paginatorSerializer, serializableSerializer, lucidSerializers, } from './lucid.js';
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/serializers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACtB,gBAAgB,GAIjB,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for Lucid-like models with serialize method.
|
|
3
|
+
*/
|
|
4
|
+
export interface SerializableModel {
|
|
5
|
+
serialize(): Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Interface for models with toResponse() method.
|
|
9
|
+
* This matches the TypedModel pattern from the blog-api.
|
|
10
|
+
*/
|
|
11
|
+
export interface ResponseModel {
|
|
12
|
+
toResponse(): unknown;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Interface for Lucid-like paginators.
|
|
16
|
+
*/
|
|
17
|
+
export interface PaginatorLike {
|
|
18
|
+
all(): unknown[];
|
|
19
|
+
total: number;
|
|
20
|
+
perPage: number;
|
|
21
|
+
currentPage: number;
|
|
22
|
+
lastPage: number;
|
|
23
|
+
firstPage: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Check if a value is a Lucid model (has serialize method).
|
|
27
|
+
*/
|
|
28
|
+
export declare function isLucidModel(value: unknown): value is SerializableModel;
|
|
29
|
+
/**
|
|
30
|
+
* Check if a value is a TypedModel (has toResponse method).
|
|
31
|
+
*/
|
|
32
|
+
export declare function isTypedModel(value: unknown): value is ResponseModel;
|
|
33
|
+
/**
|
|
34
|
+
* Check if a value is a Lucid paginator.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isPaginator(value: unknown): value is PaginatorLike;
|
|
37
|
+
/**
|
|
38
|
+
* Serializer for TypedModel instances.
|
|
39
|
+
* Calls toResponse() to get the API response format.
|
|
40
|
+
*/
|
|
41
|
+
export declare function serializeTypedModel(model: ResponseModel): unknown;
|
|
42
|
+
/**
|
|
43
|
+
* Serializer for generic Lucid models.
|
|
44
|
+
* Calls serialize() to get the model data.
|
|
45
|
+
*/
|
|
46
|
+
export declare function serializeLucidModel(model: SerializableModel): unknown;
|
|
47
|
+
/**
|
|
48
|
+
* Serializer for Lucid paginators.
|
|
49
|
+
* Converts to standard paginated response format.
|
|
50
|
+
*/
|
|
51
|
+
export declare function serializePaginator(paginator: PaginatorLike): unknown;
|
|
52
|
+
/**
|
|
53
|
+
* Check if a value has a serialize() method (like VersionRecord).
|
|
54
|
+
*/
|
|
55
|
+
export declare function hasSerialize(value: unknown): value is {
|
|
56
|
+
serialize: () => Record<string, unknown>;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Serializer registration objects for use with defineConfig().
|
|
60
|
+
*/
|
|
61
|
+
export declare const typedModelSerializer: {
|
|
62
|
+
check: typeof isTypedModel;
|
|
63
|
+
serialize: typeof serializeTypedModel;
|
|
64
|
+
priority: number;
|
|
65
|
+
};
|
|
66
|
+
export declare const lucidModelSerializer: {
|
|
67
|
+
check: typeof isLucidModel;
|
|
68
|
+
serialize: typeof serializeLucidModel;
|
|
69
|
+
priority: number;
|
|
70
|
+
};
|
|
71
|
+
export declare const paginatorSerializer: {
|
|
72
|
+
check: typeof isPaginator;
|
|
73
|
+
serialize: typeof serializePaginator;
|
|
74
|
+
priority: number;
|
|
75
|
+
};
|
|
76
|
+
export declare const serializableSerializer: {
|
|
77
|
+
check: typeof hasSerialize;
|
|
78
|
+
serialize: (obj: {
|
|
79
|
+
serialize: () => unknown;
|
|
80
|
+
}) => unknown;
|
|
81
|
+
priority: number;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* All Lucid-related serializers.
|
|
85
|
+
* Register these with defineConfig() to enable automatic model serialization.
|
|
86
|
+
*/
|
|
87
|
+
export declare const lucidSerializers: ({
|
|
88
|
+
check: typeof isTypedModel;
|
|
89
|
+
serialize: typeof serializeTypedModel;
|
|
90
|
+
priority: number;
|
|
91
|
+
} | {
|
|
92
|
+
check: typeof isLucidModel;
|
|
93
|
+
serialize: typeof serializeLucidModel;
|
|
94
|
+
priority: number;
|
|
95
|
+
} | {
|
|
96
|
+
check: typeof isPaginator;
|
|
97
|
+
serialize: typeof serializePaginator;
|
|
98
|
+
priority: number;
|
|
99
|
+
})[];
|
|
100
|
+
//# sourceMappingURL=lucid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lucid.d.ts","sourceRoot":"","sources":["../../src/serializers/lucid.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACrC;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,UAAU,IAAI,OAAO,CAAA;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,GAAG,IAAI,OAAO,EAAE,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,iBAAiB,CAOvE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAOnE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAUlE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAEjE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAErE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,aAAa,GAAG,OAAO,CAsBpE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI;IAAE,SAAS,EAAE,MA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