yedra 0.12.4 → 0.12.6
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/routing/path.d.ts +1 -2
- package/dist/routing/path.js +3 -4
- package/dist/routing/rest.js +1 -14
- package/dist/routing/websocket.js +36 -2
- package/dist/util/docs.d.ts +8 -0
- package/dist/util/docs.js +20 -0
- package/package.json +3 -3
package/dist/routing/path.d.ts
CHANGED
|
@@ -14,8 +14,7 @@ export declare class Path {
|
|
|
14
14
|
*/
|
|
15
15
|
constructor(path: string);
|
|
16
16
|
/**
|
|
17
|
-
* Prepends this path with another path.
|
|
18
|
-
* `new Path(prefix + path.toString()).
|
|
17
|
+
* Prepends this path with another path.
|
|
19
18
|
* @param prefix - The prefix to prepend.
|
|
20
19
|
* @returns The prefixed path.
|
|
21
20
|
*/
|
package/dist/routing/path.js
CHANGED
|
@@ -34,13 +34,12 @@ export class Path {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
-
* Prepends this path with another path.
|
|
38
|
-
* `new Path(prefix + path.toString()).
|
|
37
|
+
* Prepends this path with another path.
|
|
39
38
|
* @param prefix - The prefix to prepend.
|
|
40
39
|
* @returns The prefixed path.
|
|
41
40
|
*/
|
|
42
41
|
withPrefix(prefix) {
|
|
43
|
-
return new Path(prefix
|
|
42
|
+
return new Path(`${prefix}/${this.expected.join('/')}`);
|
|
44
43
|
}
|
|
45
44
|
/**
|
|
46
45
|
* Returns the path as a string. The segments are joined with `/`, and the
|
|
@@ -48,7 +47,7 @@ export class Path {
|
|
|
48
47
|
* @returns The path as a string.
|
|
49
48
|
*/
|
|
50
49
|
toString() {
|
|
51
|
-
return `/${this.expected.join('/')}`;
|
|
50
|
+
return `/${this.expected.map((segment) => (segment.startsWith(':') ? `{${segment.substring(1)}}` : segment)).join('/')}`;
|
|
52
51
|
}
|
|
53
52
|
/**
|
|
54
53
|
* Match this API path to a string. If the string matches the path, this
|
package/dist/routing/rest.js
CHANGED
|
@@ -2,6 +2,7 @@ import { ValidationError } from '../validation/error.js';
|
|
|
2
2
|
import { NoneBody, none } from '../validation/none.js';
|
|
3
3
|
import { object } from '../validation/object.js';
|
|
4
4
|
import { BadRequestError } from './errors.js';
|
|
5
|
+
import { paramDocs } from '../util/docs.js';
|
|
5
6
|
class RestEndpoint {
|
|
6
7
|
constructor(method, options) {
|
|
7
8
|
this._method = method;
|
|
@@ -116,17 +117,3 @@ export class Delete extends RestEndpoint {
|
|
|
116
117
|
super('DELETE', { req: none(), ...options });
|
|
117
118
|
}
|
|
118
119
|
}
|
|
119
|
-
const paramDocs = (params, position) => {
|
|
120
|
-
const result = [];
|
|
121
|
-
for (const name in params) {
|
|
122
|
-
const docs = params[name].documentation();
|
|
123
|
-
result.push({
|
|
124
|
-
name,
|
|
125
|
-
in: position,
|
|
126
|
-
description: 'description' in docs ? docs.description : undefined,
|
|
127
|
-
required: !params[name].isOptional(),
|
|
128
|
-
schema: docs,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
return result;
|
|
132
|
-
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ValidationError } from '../validation/error.js';
|
|
2
2
|
import { object } from '../validation/object.js';
|
|
3
3
|
import { BadRequestError } from './errors.js';
|
|
4
|
+
import { paramDocs } from '../util/docs.js';
|
|
4
5
|
export class WebSocketHandler {
|
|
5
6
|
constructor(open) {
|
|
6
7
|
this.messageCbs = [];
|
|
@@ -95,7 +96,40 @@ export class Ws {
|
|
|
95
96
|
return undefined;
|
|
96
97
|
}
|
|
97
98
|
documentation() {
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
const parameters = [
|
|
100
|
+
...paramDocs(this.options.params, 'path'),
|
|
101
|
+
...paramDocs(this.options.query, 'query'),
|
|
102
|
+
];
|
|
103
|
+
return {
|
|
104
|
+
tags: [this.options.category],
|
|
105
|
+
summary: this.options.summary,
|
|
106
|
+
description: this.options.description,
|
|
107
|
+
parameters,
|
|
108
|
+
responses: {
|
|
109
|
+
'101': {
|
|
110
|
+
description: 'Switching to WebSocket',
|
|
111
|
+
},
|
|
112
|
+
'400': {
|
|
113
|
+
description: 'Upgrading to WebSocket failed',
|
|
114
|
+
content: {
|
|
115
|
+
'application/json': {
|
|
116
|
+
schema: {
|
|
117
|
+
type: 'object',
|
|
118
|
+
properties: {
|
|
119
|
+
status: {
|
|
120
|
+
type: 'number',
|
|
121
|
+
example: 400,
|
|
122
|
+
},
|
|
123
|
+
errorMessage: {
|
|
124
|
+
type: 'string',
|
|
125
|
+
example: 'Upgrading to WebSocket failed.',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
};
|
|
100
134
|
}
|
|
101
135
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Schema } from '../validation/schema.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generate OpenAPI documentation for parameters.
|
|
4
|
+
* @param params - Record of parameters.
|
|
5
|
+
* @param position - The position of the parameter, e.g. `path`, `query`, `header`. This is passed directly to OpenAPI.
|
|
6
|
+
* @returns A list of parameter documentations in OpenAPI format.
|
|
7
|
+
*/
|
|
8
|
+
export declare const paramDocs: <Params extends Record<string, Schema<unknown>>>(params: Params, position: string) => object[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate OpenAPI documentation for parameters.
|
|
3
|
+
* @param params - Record of parameters.
|
|
4
|
+
* @param position - The position of the parameter, e.g. `path`, `query`, `header`. This is passed directly to OpenAPI.
|
|
5
|
+
* @returns A list of parameter documentations in OpenAPI format.
|
|
6
|
+
*/
|
|
7
|
+
export const paramDocs = (params, position) => {
|
|
8
|
+
const result = [];
|
|
9
|
+
for (const name in params) {
|
|
10
|
+
const docs = params[name].documentation();
|
|
11
|
+
result.push({
|
|
12
|
+
name,
|
|
13
|
+
in: position,
|
|
14
|
+
description: 'description' in docs ? docs.description : undefined,
|
|
15
|
+
required: !params[name].isOptional(),
|
|
16
|
+
schema: docs,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yedra",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.6",
|
|
4
4
|
"repository": "github:0codekit/yedra",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"devDependencies": {
|
|
7
|
-
"@biomejs/biome": "^1.9.
|
|
7
|
+
"@biomejs/biome": "^1.9.3",
|
|
8
8
|
"@types/bun": "^1.1.10",
|
|
9
|
-
"@types/node": "^22.
|
|
9
|
+
"@types/node": "^22.7.4",
|
|
10
10
|
"@types/uuid": "^10.0.0",
|
|
11
11
|
"typescript": "^5.6.2"
|
|
12
12
|
},
|