@innet/server 2.0.0-alpha.23 → 2.0.0-alpha.25
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/handler/handler.d.ts +5 -5
- package/handler/handler.es6.js +3 -3
- package/handler/handler.js +3 -3
- package/hooks/index.d.ts +1 -0
- package/hooks/index.es6.js +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useClientIp/useClientIp.d.ts +1 -1
- package/hooks/useEndpoint/useEndpoint.d.ts +1 -1
- package/hooks/useSchemaType/useSchemaType.d.ts +3 -3
- package/hooks/useSchemaType/useSchemaType.es6.js +5 -5
- package/hooks/useSchemaType/useSchemaType.js +5 -5
- package/hooks/useServer/useServer.d.ts +1 -1
- package/hooks/useServerPort/index.d.ts +1 -0
- package/hooks/useServerPort/index.es6.js +1 -0
- package/hooks/useServerPort/index.js +10 -0
- package/hooks/useServerPort/useServerPort.d.ts +3 -0
- package/hooks/useServerPort/useServerPort.es6.js +14 -0
- package/hooks/useServerPort/useServerPort.js +19 -0
- package/index.es6.js +1 -0
- package/index.js +3 -0
- package/package.json +1 -1
- package/plugins/main/api/api.d.ts +10 -10
- package/plugins/main/api/api.es6.js +7 -7
- package/plugins/main/api/api.js +7 -7
- package/plugins/main/contact/contact.d.ts +2 -2
- package/plugins/main/endpoint/endpoint.d.ts +15 -15
- package/plugins/main/endpoint/endpoint.es6.js +3 -3
- package/plugins/main/endpoint/endpoint.js +3 -3
- package/plugins/main/host/host.d.ts +5 -5
- package/plugins/main/license/license.d.ts +5 -5
- package/plugins/main/param/param.d.ts +11 -11
- package/plugins/main/param/param.es6.js +3 -3
- package/plugins/main/param/param.js +3 -3
- package/plugins/main/response/response.d.ts +1 -1
- package/plugins/main/response/response.es6.js +2 -2
- package/plugins/main/response/response.js +2 -2
- package/plugins/main/server/server.d.ts +4 -4
- package/plugins/main/server/server.es6.js +9 -7
- package/plugins/main/server/server.js +9 -7
- package/plugins/main/tag/tag.d.ts +2 -2
- package/plugins/main/tag/tag.es6.js +1 -1
- package/plugins/main/tag/tag.js +1 -1
- package/plugins/main/variable/variable.d.ts +5 -5
- package/plugins/main/variable/variable.es6.js +3 -1
- package/plugins/main/variable/variable.js +3 -1
- package/plugins/request/cms/cms.es6.js +2 -2
- package/plugins/request/cms/cms.js +2 -2
- package/plugins/request/error/error.d.ts +40 -40
- package/plugins/request/error/error.es6.js +42 -42
- package/plugins/request/error/error.js +42 -42
- package/plugins/request/file/file.es6.js +2 -3
- package/plugins/request/file/file.js +2 -3
- package/plugins/request/header/header.es6.js +1 -1
- package/plugins/request/header/header.js +1 -1
- package/plugins/request/proxy/proxy.d.ts +2 -2
- package/plugins/request/proxy/proxy.es6.js +2 -2
- package/plugins/request/proxy/proxy.js +2 -2
- package/plugins/request/redirect/redirect.d.ts +7 -7
- package/plugins/request/redirect/redirect.es6.js +7 -7
- package/plugins/request/redirect/redirect.js +7 -7
- package/plugins/request/success/success.d.ts +6 -6
- package/plugins/request/success/success.es6.js +8 -8
- package/plugins/request/success/success.js +8 -8
- package/plugins/schema/binary/binary.d.ts +3 -3
- package/plugins/schema/date/date.d.ts +1 -1
- package/plugins/schema/date/date.es6.js +3 -3
- package/plugins/schema/date/date.js +3 -3
- package/plugins/schema/field/field.es6.js +1 -1
- package/plugins/schema/field/field.js +1 -1
- package/plugins/schema/integer/integer.d.ts +3 -3
- package/plugins/schema/integer/integer.es6.js +1 -1
- package/plugins/schema/integer/integer.js +1 -1
- package/plugins/schema/number/number.d.ts +2 -2
- package/plugins/schema/number/number.es6.js +1 -1
- package/plugins/schema/number/number.js +1 -1
- package/plugins/schema/string/string.d.ts +2 -2
- package/plugins/schema/string/string.es6.js +1 -1
- package/plugins/schema/string/string.js +1 -1
- package/plugins/utils/dts/dts.d.ts +1 -1
- package/plugins/utils/dts/dts.es6.js +1 -1
- package/plugins/utils/dts/dts.js +1 -1
- package/plugins/utils/env/env.d.ts +1 -1
- package/plugins/utils/env/env.es6.js +1 -1
- package/plugins/utils/env/env.js +1 -1
- package/plugins/utils/protection/protection.d.ts +3 -3
- package/plugins/utils/protection/protection.es6.js +3 -3
- package/plugins/utils/protection/protection.js +3 -3
- package/plugins/utils/swagger/swagger.es6.js +1 -1
- package/plugins/utils/swagger/swagger.js +1 -1
- package/types.d.ts +13 -13
- package/utils/FileData/Bin.d.ts +13 -13
- package/utils/FileData/Bin.es6.js +2 -2
- package/utils/FileData/Bin.js +2 -2
- package/utils/action/Action.d.ts +12 -12
- package/utils/action/Action.es6.js +80 -80
- package/utils/action/Action.js +79 -79
- package/utils/dateFormat/dateFormat.d.ts +1 -1
- package/utils/dateFormat/dateFormat.es6.js +1 -1
- package/utils/dateFormat/dateFormat.js +1 -1
- package/utils/generateTypes/generateTypes.es6.js +3 -3
- package/utils/generateTypes/generateTypes.js +3 -3
- package/utils/getOrAdd/getOrAdd.d.ts +1 -1
- package/utils/httpOnStart/httpOnStart.d.ts +1 -1
- package/utils/httpOnStart/httpOnStart.es6.js +1 -1
- package/utils/httpOnStart/httpOnStart.js +1 -1
- package/utils/rules/binaryAccept/binaryAccept.es6.js +2 -2
- package/utils/rules/binaryAccept/binaryAccept.js +2 -2
- package/utils/rules/dateTo/dateTo.d.ts +1 -1
- package/utils/rules/helpers.d.ts +1 -1
- package/utils/rules/int/int.es6.js +2 -2
- package/utils/rules/int/int.js +2 -2
- package/utils/rules/max/max.d.ts +1 -1
- package/utils/rules/max/max.es6.js +3 -3
- package/utils/rules/max/max.js +3 -3
- package/utils/rules/maxBin/maxBin.es6.js +2 -2
- package/utils/rules/maxBin/maxBin.js +2 -2
- package/utils/rules/maxDate/maxDate.es6.js +1 -1
- package/utils/rules/maxDate/maxDate.js +1 -1
- package/utils/rules/maxLength/maxLength.es6.js +2 -2
- package/utils/rules/maxLength/maxLength.js +2 -2
- package/utils/rules/min/min.d.ts +1 -1
- package/utils/rules/min/min.es6.js +3 -3
- package/utils/rules/min/min.js +3 -3
- package/utils/rules/minBin/minBin.es6.js +2 -2
- package/utils/rules/minBin/minBin.js +2 -2
- package/utils/rules/minDate/minDate.es6.js +1 -1
- package/utils/rules/minDate/minDate.js +1 -1
- package/utils/rules/minLength/minLength.es6.js +2 -2
- package/utils/rules/minLength/minLength.js +2 -2
- package/utils/rules/pattern/pattern.d.ts +1 -1
- package/utils/rules/pattern/pattern.es6.js +2 -1
- package/utils/rules/pattern/pattern.js +2 -1
package/handler/handler.d.ts
CHANGED
|
@@ -35,12 +35,12 @@ export declare const JSXPlugins: {
|
|
|
35
35
|
redirect: import("innet").HandlerPlugin;
|
|
36
36
|
response: import("innet").HandlerPlugin;
|
|
37
37
|
return: import("innet").HandlerPlugin;
|
|
38
|
+
server: import("innet").HandlerPlugin;
|
|
38
39
|
slot: typeof slot;
|
|
39
40
|
slots: typeof slots;
|
|
40
|
-
server: import("innet").HandlerPlugin;
|
|
41
|
-
swagger: import("innet").HandlerPlugin;
|
|
42
41
|
string: import("innet").HandlerPlugin;
|
|
43
42
|
success: import("innet").HandlerPlugin;
|
|
43
|
+
swagger: import("innet").HandlerPlugin;
|
|
44
44
|
tag: import("innet").HandlerPlugin;
|
|
45
45
|
tuple: import("innet").HandlerPlugin;
|
|
46
46
|
uuid: import("innet").HandlerPlugin;
|
|
@@ -84,14 +84,14 @@ declare global {
|
|
|
84
84
|
protection: ProtectionProps;
|
|
85
85
|
proxy: ProxyProps;
|
|
86
86
|
redirect: RedirectProps;
|
|
87
|
-
return: ReturnProps;
|
|
88
87
|
response: ResponseProps;
|
|
88
|
+
return: ReturnProps;
|
|
89
|
+
server: ServerProps;
|
|
89
90
|
slot: SlotProps;
|
|
90
91
|
slots: SlotsProps;
|
|
91
|
-
server: ServerProps;
|
|
92
|
-
swagger: SwaggerProps;
|
|
93
92
|
string: StringProps;
|
|
94
93
|
success: SuccessProps;
|
|
94
|
+
swagger: SwaggerProps;
|
|
95
95
|
tag: TagProps;
|
|
96
96
|
tuple: TupleProps;
|
|
97
97
|
uuid: UuidProps;
|
package/handler/handler.es6.js
CHANGED
|
@@ -34,9 +34,9 @@ import { redirect } from '../plugins/request/redirect/redirect.es6.js';
|
|
|
34
34
|
import { response } from '../plugins/main/response/response.es6.js';
|
|
35
35
|
import { returnPlugin } from '../plugins/main/return/return.es6.js';
|
|
36
36
|
import { server } from '../plugins/main/server/server.es6.js';
|
|
37
|
-
import { swagger } from '../plugins/utils/swagger/swagger.es6.js';
|
|
38
37
|
import { string } from '../plugins/schema/string/string.es6.js';
|
|
39
38
|
import { success } from '../plugins/request/success/success.es6.js';
|
|
39
|
+
import { swagger } from '../plugins/utils/swagger/swagger.es6.js';
|
|
40
40
|
import { tag } from '../plugins/main/tag/tag.es6.js';
|
|
41
41
|
import { tuple } from '../plugins/schema/tuple/tuple.es6.js';
|
|
42
42
|
import { uuid } from '../plugins/schema/uuid/uuid.es6.js';
|
|
@@ -80,12 +80,12 @@ const JSXPlugins = {
|
|
|
80
80
|
redirect,
|
|
81
81
|
response,
|
|
82
82
|
return: returnPlugin,
|
|
83
|
+
server,
|
|
83
84
|
slot,
|
|
84
85
|
slots,
|
|
85
|
-
server,
|
|
86
|
-
swagger,
|
|
87
86
|
string,
|
|
88
87
|
success,
|
|
88
|
+
swagger,
|
|
89
89
|
tag,
|
|
90
90
|
tuple,
|
|
91
91
|
uuid,
|
package/handler/handler.js
CHANGED
|
@@ -38,9 +38,9 @@ var redirect = require('../plugins/request/redirect/redirect.js');
|
|
|
38
38
|
var response = require('../plugins/main/response/response.js');
|
|
39
39
|
var _return = require('../plugins/main/return/return.js');
|
|
40
40
|
var server = require('../plugins/main/server/server.js');
|
|
41
|
-
var swagger = require('../plugins/utils/swagger/swagger.js');
|
|
42
41
|
var string = require('../plugins/schema/string/string.js');
|
|
43
42
|
var success = require('../plugins/request/success/success.js');
|
|
43
|
+
var swagger = require('../plugins/utils/swagger/swagger.js');
|
|
44
44
|
var tag = require('../plugins/main/tag/tag.js');
|
|
45
45
|
var tuple = require('../plugins/schema/tuple/tuple.js');
|
|
46
46
|
var uuid = require('../plugins/schema/uuid/uuid.js');
|
|
@@ -84,12 +84,12 @@ const JSXPlugins = {
|
|
|
84
84
|
redirect: redirect.redirect,
|
|
85
85
|
response: response.response,
|
|
86
86
|
return: _return.returnPlugin,
|
|
87
|
+
server: server.server,
|
|
87
88
|
slot: jsx.slot,
|
|
88
89
|
slots: jsx.slots,
|
|
89
|
-
server: server.server,
|
|
90
|
-
swagger: swagger.swagger,
|
|
91
90
|
string: string.string,
|
|
92
91
|
success: success.success,
|
|
92
|
+
swagger: swagger.swagger,
|
|
93
93
|
tag: tag.tag,
|
|
94
94
|
tuple: tuple.tuple,
|
|
95
95
|
uuid: uuid.uuid,
|
package/hooks/index.d.ts
CHANGED
package/hooks/index.es6.js
CHANGED
package/hooks/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useClientIp():
|
|
1
|
+
export declare function useClientIp(): null | string;
|
|
@@ -2,9 +2,9 @@ import { Context } from '@innet/jsx';
|
|
|
2
2
|
import { type EndpointProps } from '../../plugins';
|
|
3
3
|
import type { Endpoint, OperationObject } from '../../types';
|
|
4
4
|
export interface EndpointContext {
|
|
5
|
+
endpoint: Endpoint;
|
|
5
6
|
operation: OperationObject;
|
|
6
7
|
props: EndpointProps;
|
|
7
|
-
endpoint: Endpoint;
|
|
8
8
|
}
|
|
9
9
|
export declare const endpointContext: Context<EndpointContext, EndpointContext | undefined>;
|
|
10
10
|
export declare function useEndpoint(): EndpointContext;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ObjectType, type SchemaObject, type ValuesSchemaProps } from '../../types';
|
|
2
|
-
export type SchemaType =
|
|
3
|
-
type TypeMap<T extends SchemaType> = T extends '
|
|
4
|
-
export declare function useSchemaType<T extends SchemaType>(type: T, {
|
|
2
|
+
export type SchemaType = 'any' | ObjectType;
|
|
3
|
+
type TypeMap<T extends SchemaType> = T extends 'integer' | 'number' ? number : T extends 'string' ? string : T extends 'object' ? object : T extends 'array' ? any[] : T extends 'boolean' ? boolean : T extends 'null' ? null : T extends 'any' ? any : unknown;
|
|
4
|
+
export declare function useSchemaType<T extends SchemaType>(type: T, { example, examples, ref, values, ...options }?: ValuesSchemaProps<TypeMap<T>> | undefined): SchemaObject | undefined;
|
|
5
5
|
export {};
|
|
@@ -6,7 +6,7 @@ import { useNewSchema } from '../useNewSchema/useNewSchema.es6.js';
|
|
|
6
6
|
|
|
7
7
|
function useSchemaType(type, _a = {}) {
|
|
8
8
|
var _b;
|
|
9
|
-
var {
|
|
9
|
+
var { example, examples, ref, values } = _a, options = __rest(_a, ["example", "examples", "ref", "values"]);
|
|
10
10
|
if (ref) {
|
|
11
11
|
const { docs } = useApi();
|
|
12
12
|
if (!docs.components) {
|
|
@@ -21,11 +21,11 @@ function useSchemaType(type, _a = {}) {
|
|
|
21
21
|
if ((_b = docs.components.schemas) === null || _b === void 0 ? void 0 : _b[ref]) {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
return (docs.components.schemas[ref] = Object.assign(Object.assign({}, options), { example,
|
|
25
|
-
examples, type: type === 'any' ? undefined : type
|
|
24
|
+
return (docs.components.schemas[ref] = Object.assign(Object.assign({}, options), { enum: values, example,
|
|
25
|
+
examples, type: type === 'any' ? undefined : type }));
|
|
26
26
|
}
|
|
27
|
-
return useNewSchema(Object.assign(Object.assign({}, options), { example,
|
|
28
|
-
examples,
|
|
27
|
+
return useNewSchema(Object.assign(Object.assign({}, options), { enum: values, example,
|
|
28
|
+
examples, type: type === 'any' ? undefined : type }));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export { useSchemaType };
|
|
@@ -10,7 +10,7 @@ var useNewSchema = require('../useNewSchema/useNewSchema.js');
|
|
|
10
10
|
|
|
11
11
|
function useSchemaType(type, _a = {}) {
|
|
12
12
|
var _b;
|
|
13
|
-
var {
|
|
13
|
+
var { example, examples, ref, values } = _a, options = tslib.__rest(_a, ["example", "examples", "ref", "values"]);
|
|
14
14
|
if (ref) {
|
|
15
15
|
const { docs } = useApi.useApi();
|
|
16
16
|
if (!docs.components) {
|
|
@@ -25,11 +25,11 @@ function useSchemaType(type, _a = {}) {
|
|
|
25
25
|
if ((_b = docs.components.schemas) === null || _b === void 0 ? void 0 : _b[ref]) {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
return (docs.components.schemas[ref] = Object.assign(Object.assign({}, options), { example,
|
|
29
|
-
examples, type: type === 'any' ? undefined : type
|
|
28
|
+
return (docs.components.schemas[ref] = Object.assign(Object.assign({}, options), { enum: values, example,
|
|
29
|
+
examples, type: type === 'any' ? undefined : type }));
|
|
30
30
|
}
|
|
31
|
-
return useNewSchema.useNewSchema(Object.assign(Object.assign({}, options), { example,
|
|
32
|
-
examples,
|
|
31
|
+
return useNewSchema.useNewSchema(Object.assign(Object.assign({}, options), { enum: values, example,
|
|
32
|
+
examples, type: type === 'any' ? undefined : type }));
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
exports.useSchemaType = useSchemaType;
|
|
@@ -5,8 +5,8 @@ import { type Server as HttpServer } from 'http';
|
|
|
5
5
|
import { type Server as HttpsServer } from 'https';
|
|
6
6
|
export type ServerPlugin = () => any;
|
|
7
7
|
export interface ServerContext {
|
|
8
|
-
server: HttpServer | HttpsServer;
|
|
9
8
|
port: number;
|
|
9
|
+
server: HttpServer | HttpsServer;
|
|
10
10
|
}
|
|
11
11
|
export declare const serverContext: Context<ServerContext, ServerContext | undefined>;
|
|
12
12
|
export declare function useServer(): ServerContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useServerPort';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { serverPortContext, useServerPort } from './useServerPort.es6.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Context, useContext } from '@innet/jsx';
|
|
2
|
+
import '../useThrow/index.es6.js';
|
|
3
|
+
import { useThrow } from '../useThrow/useThrow.es6.js';
|
|
4
|
+
|
|
5
|
+
const serverPortContext = new Context();
|
|
6
|
+
function useServerPort() {
|
|
7
|
+
const port = useContext(serverPortContext);
|
|
8
|
+
if (!port) {
|
|
9
|
+
useThrow('{type} MUST BE in <server>');
|
|
10
|
+
}
|
|
11
|
+
return port;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { serverPortContext, useServerPort };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var jsx = require('@innet/jsx');
|
|
6
|
+
require('../useThrow/index.js');
|
|
7
|
+
var useThrow = require('../useThrow/useThrow.js');
|
|
8
|
+
|
|
9
|
+
const serverPortContext = new jsx.Context();
|
|
10
|
+
function useServerPort() {
|
|
11
|
+
const port = jsx.useContext(serverPortContext);
|
|
12
|
+
if (!port) {
|
|
13
|
+
useThrow.useThrow('{type} MUST BE in <server>');
|
|
14
|
+
}
|
|
15
|
+
return port;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.serverPortContext = serverPortContext;
|
|
19
|
+
exports.useServerPort = useServerPort;
|
package/index.es6.js
CHANGED
|
@@ -113,3 +113,4 @@ export { useServerPlugin } from './hooks/useServerPlugin/useServerPlugin.es6.js'
|
|
|
113
113
|
export { useClientIp } from './hooks/useClientIp/useClientIp.es6.js';
|
|
114
114
|
export { serverPlugins, useServerPlugins } from './hooks/useServerPlugins/useServerPlugins.es6.js';
|
|
115
115
|
export { objectSchemaContext, useObjectSchemaContext } from './hooks/useObjectSchemaContext/useObjectSchemaContext.es6.js';
|
|
116
|
+
export { serverPortContext, useServerPort } from './hooks/useServerPort/useServerPort.es6.js';
|
package/index.js
CHANGED
|
@@ -117,6 +117,7 @@ var useServerPlugin = require('./hooks/useServerPlugin/useServerPlugin.js');
|
|
|
117
117
|
var useClientIp = require('./hooks/useClientIp/useClientIp.js');
|
|
118
118
|
var useServerPlugins = require('./hooks/useServerPlugins/useServerPlugins.js');
|
|
119
119
|
var useObjectSchemaContext = require('./hooks/useObjectSchemaContext/useObjectSchemaContext.js');
|
|
120
|
+
var useServerPort = require('./hooks/useServerPort/useServerPort.js');
|
|
120
121
|
|
|
121
122
|
|
|
122
123
|
|
|
@@ -259,3 +260,5 @@ exports.serverPlugins = useServerPlugins.serverPlugins;
|
|
|
259
260
|
exports.useServerPlugins = useServerPlugins.useServerPlugins;
|
|
260
261
|
exports.objectSchemaContext = useObjectSchemaContext.objectSchemaContext;
|
|
261
262
|
exports.useObjectSchemaContext = useObjectSchemaContext.useObjectSchemaContext;
|
|
263
|
+
exports.serverPortContext = useServerPort.serverPortContext;
|
|
264
|
+
exports.useServerPort = useServerPort.useServerPort;
|
package/package.json
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
export interface ApiProps {
|
|
3
|
+
/** A description of the API. [CommonMark syntax](https://spec.commonmark.or.org) MAY be used for rich text representation. */
|
|
4
|
+
description?: string;
|
|
5
|
+
exclude?: RegExp;
|
|
6
|
+
include?: RegExp;
|
|
7
|
+
/** URL path prefix scopes the API. */
|
|
8
|
+
prefix?: string;
|
|
9
|
+
/** A short summary of the API. */
|
|
10
|
+
summary?: string;
|
|
11
|
+
/** A URL to the Terms of Service for the API. This MUST be in the form of a URL. */
|
|
12
|
+
termsOfService?: string;
|
|
3
13
|
/** The title of the API. */
|
|
4
14
|
title?: string;
|
|
5
15
|
/**
|
|
@@ -10,15 +20,5 @@ export interface ApiProps {
|
|
|
10
20
|
* @default: 0.0.0
|
|
11
21
|
* */
|
|
12
22
|
version?: string;
|
|
13
|
-
/** A short summary of the API. */
|
|
14
|
-
summary?: string;
|
|
15
|
-
/** A description of the API. [CommonMark syntax](https://spec.commonmark.or.org) MAY be used for rich text representation. */
|
|
16
|
-
description?: string;
|
|
17
|
-
/** A URL to the Terms of Service for the API. This MUST be in the form of a URL. */
|
|
18
|
-
termsOfService?: string;
|
|
19
|
-
/** URL path prefix scopes the API. */
|
|
20
|
-
prefix?: string;
|
|
21
|
-
include?: RegExp;
|
|
22
|
-
exclude?: RegExp;
|
|
23
23
|
}
|
|
24
24
|
export declare const api: HandlerPlugin;
|
|
@@ -13,13 +13,13 @@ import { paramsContext } from '../../../hooks/useParams/useParams.es6.js';
|
|
|
13
13
|
|
|
14
14
|
const api = () => {
|
|
15
15
|
const handler = useNewHandler();
|
|
16
|
-
const { props = {},
|
|
17
|
-
const { prefix = '', title = '',
|
|
18
|
-
const info = Object.assign(Object.assign({}, rest), {
|
|
16
|
+
const { children, props = {}, } = useApp();
|
|
17
|
+
const { exclude, include, prefix = '', title = '', version = process.env.INNET_API_VERSION || '0.0.0' } = props, rest = __rest(props, ["exclude", "include", "prefix", "title", "version"]);
|
|
18
|
+
const info = Object.assign(Object.assign({}, rest), { title, version });
|
|
19
19
|
const endpoints = {};
|
|
20
20
|
const docs = {
|
|
21
|
-
openapi: '3.1.0',
|
|
22
21
|
info,
|
|
22
|
+
openapi: '3.1.0',
|
|
23
23
|
paths: {},
|
|
24
24
|
};
|
|
25
25
|
const plugins = new Set();
|
|
@@ -45,7 +45,7 @@ const api = () => {
|
|
|
45
45
|
const actionHandler = useNewHandler();
|
|
46
46
|
const path = action.parsedUrl.path;
|
|
47
47
|
const url = path.endsWith('/') ? path.slice(0, -1) : path;
|
|
48
|
-
const { req, res } = action;
|
|
48
|
+
const { req, res, } = action;
|
|
49
49
|
if (url === (prefix || '')) {
|
|
50
50
|
res.setHeader('Content-Type', 'application/json');
|
|
51
51
|
res.write(JSONString(docs));
|
|
@@ -87,8 +87,8 @@ const api = () => {
|
|
|
87
87
|
if (e instanceof RulesError) {
|
|
88
88
|
res.statusCode = 400;
|
|
89
89
|
res.write(JSONString({
|
|
90
|
-
error: 'requestValidation',
|
|
91
90
|
data: Object.assign(Object.assign({}, e.data), { in: key }),
|
|
91
|
+
error: 'requestValidation',
|
|
92
92
|
}));
|
|
93
93
|
res.end();
|
|
94
94
|
}
|
|
@@ -96,8 +96,8 @@ const api = () => {
|
|
|
96
96
|
console.error(e);
|
|
97
97
|
res.statusCode = 500;
|
|
98
98
|
res.write(JSONString({
|
|
99
|
-
error: 'unknown',
|
|
100
99
|
data: { in: key },
|
|
100
|
+
error: 'unknown',
|
|
101
101
|
}));
|
|
102
102
|
res.end();
|
|
103
103
|
}
|
package/plugins/main/api/api.js
CHANGED
|
@@ -21,13 +21,13 @@ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
|
21
21
|
|
|
22
22
|
const api = () => {
|
|
23
23
|
const handler = innet.useNewHandler();
|
|
24
|
-
const { props = {},
|
|
25
|
-
const { prefix = '', title = '',
|
|
26
|
-
const info = Object.assign(Object.assign({}, rest), {
|
|
24
|
+
const { children, props = {}, } = innet.useApp();
|
|
25
|
+
const { exclude, include, prefix = '', title = '', version = process.env.INNET_API_VERSION || '0.0.0' } = props, rest = tslib.__rest(props, ["exclude", "include", "prefix", "title", "version"]);
|
|
26
|
+
const info = Object.assign(Object.assign({}, rest), { title, version });
|
|
27
27
|
const endpoints = {};
|
|
28
28
|
const docs = {
|
|
29
|
-
openapi: '3.1.0',
|
|
30
29
|
info,
|
|
30
|
+
openapi: '3.1.0',
|
|
31
31
|
paths: {},
|
|
32
32
|
};
|
|
33
33
|
const plugins = new Set();
|
|
@@ -53,7 +53,7 @@ const api = () => {
|
|
|
53
53
|
const actionHandler = innet.useNewHandler();
|
|
54
54
|
const path = action.parsedUrl.path;
|
|
55
55
|
const url = path.endsWith('/') ? path.slice(0, -1) : path;
|
|
56
|
-
const { req, res } = action;
|
|
56
|
+
const { req, res, } = action;
|
|
57
57
|
if (url === (prefix || '')) {
|
|
58
58
|
res.setHeader('Content-Type', 'application/json');
|
|
59
59
|
res.write(JSONString.JSONString(docs));
|
|
@@ -95,8 +95,8 @@ const api = () => {
|
|
|
95
95
|
if (e instanceof helpers.RulesError) {
|
|
96
96
|
res.statusCode = 400;
|
|
97
97
|
res.write(JSONString.JSONString({
|
|
98
|
-
error: 'requestValidation',
|
|
99
98
|
data: Object.assign(Object.assign({}, e.data), { in: key }),
|
|
99
|
+
error: 'requestValidation',
|
|
100
100
|
}));
|
|
101
101
|
res.end();
|
|
102
102
|
}
|
|
@@ -104,8 +104,8 @@ const api = () => {
|
|
|
104
104
|
console.error(e);
|
|
105
105
|
res.statusCode = 500;
|
|
106
106
|
res.write(JSONString.JSONString({
|
|
107
|
-
error: 'unknown',
|
|
108
107
|
data: { in: key },
|
|
108
|
+
error: 'unknown',
|
|
109
109
|
}));
|
|
110
110
|
res.end();
|
|
111
111
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
export interface ContactProps {
|
|
3
|
+
/** The email address of the contact person/organization. This MUST be in the form of an email address. */
|
|
4
|
+
email?: string;
|
|
3
5
|
/** The identifying name of the contact person/organization. */
|
|
4
6
|
name?: string;
|
|
5
7
|
/** The URL pointing to the contact information. This MUST be in the form of a URL. */
|
|
6
8
|
url?: string;
|
|
7
|
-
/** The email address of the contact person/organization. This MUST be in the form of an email address. */
|
|
8
|
-
email?: string;
|
|
9
9
|
}
|
|
10
10
|
export declare const contact: HandlerPlugin;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
import { type EndpointsMethods } from '../../../types';
|
|
3
3
|
export interface EndpointProps {
|
|
4
|
+
/**
|
|
5
|
+
* Declares this operation to be deprecated.
|
|
6
|
+
* Consumers SHOULD refrain from usage of the declared operation.
|
|
7
|
+
* Default value is false.
|
|
8
|
+
* */
|
|
9
|
+
deprecated?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* An optional, string description, intended to apply to all operations in this path.
|
|
12
|
+
* [CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text representation.
|
|
13
|
+
* */
|
|
14
|
+
description?: string;
|
|
4
15
|
/**
|
|
5
16
|
* A method of the endpoint.
|
|
6
17
|
* */
|
|
@@ -13,25 +24,14 @@ export interface EndpointProps {
|
|
|
13
24
|
* Templated paths with the same hierarchy but different templated names MUST NOT exist as they are identical.
|
|
14
25
|
* */
|
|
15
26
|
path: string;
|
|
16
|
-
/**
|
|
17
|
-
* An optional, string summary, intended to apply to all operations in this path.
|
|
18
|
-
* */
|
|
19
|
-
summary?: string;
|
|
20
|
-
/**
|
|
21
|
-
* An optional, string description, intended to apply to all operations in this path.
|
|
22
|
-
* [CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text representation.
|
|
23
|
-
* */
|
|
24
|
-
description?: string;
|
|
25
|
-
/**
|
|
26
|
-
* Declares this operation to be deprecated.
|
|
27
|
-
* Consumers SHOULD refrain from usage of the declared operation.
|
|
28
|
-
* Default value is false.
|
|
29
|
-
* */
|
|
30
|
-
deprecated?: boolean;
|
|
31
27
|
/**
|
|
32
28
|
* Declares this operation to make an endpoint private.
|
|
33
29
|
* That means the endpoint should not be described and will not be shown in the Open API documentation.
|
|
34
30
|
* */
|
|
35
31
|
private?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* An optional, string summary, intended to apply to all operations in this path.
|
|
34
|
+
* */
|
|
35
|
+
summary?: string;
|
|
36
36
|
}
|
|
37
37
|
export declare const endpoint: HandlerPlugin;
|
|
@@ -11,9 +11,9 @@ import { serverPlugins } from '../../../hooks/useServerPlugins/useServerPlugins.
|
|
|
11
11
|
const endpoint = () => {
|
|
12
12
|
const handler = useNewHandler();
|
|
13
13
|
const tag = useTag();
|
|
14
|
-
const { docs, endpoints } = useApi();
|
|
14
|
+
const { docs, endpoints, } = useApi();
|
|
15
15
|
const props = useProps();
|
|
16
|
-
const {
|
|
16
|
+
const { deprecated, description, method, path, private: privateMode, summary, } = props;
|
|
17
17
|
const children = useChildren();
|
|
18
18
|
const { paths } = docs;
|
|
19
19
|
if (!paths)
|
|
@@ -48,7 +48,7 @@ const endpoint = () => {
|
|
|
48
48
|
// @ts-expect-error: it's always an object
|
|
49
49
|
const endpoint = getEndpoint(path, endpoints[method]);
|
|
50
50
|
// @ts-expect-error: it's always an object
|
|
51
|
-
endpointContext.set(handler, { operation, props
|
|
51
|
+
endpointContext.set(handler, { endpoint, operation, props });
|
|
52
52
|
// @ts-expect-error: it's always an object
|
|
53
53
|
serverPlugins.set(handler, endpoint.plugins);
|
|
54
54
|
innet(children, handler);
|
|
@@ -19,9 +19,9 @@ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
|
19
19
|
const endpoint = () => {
|
|
20
20
|
const handler = innet.useNewHandler();
|
|
21
21
|
const tag = useTag.useTag();
|
|
22
|
-
const { docs, endpoints } = useApi.useApi();
|
|
22
|
+
const { docs, endpoints, } = useApi.useApi();
|
|
23
23
|
const props = jsx.useProps();
|
|
24
|
-
const {
|
|
24
|
+
const { deprecated, description, method, path, private: privateMode, summary, } = props;
|
|
25
25
|
const children = jsx.useChildren();
|
|
26
26
|
const { paths } = docs;
|
|
27
27
|
if (!paths)
|
|
@@ -56,7 +56,7 @@ const endpoint = () => {
|
|
|
56
56
|
// @ts-expect-error: it's always an object
|
|
57
57
|
const endpoint = getEndpoint.getEndpoint(path, endpoints[method]);
|
|
58
58
|
// @ts-expect-error: it's always an object
|
|
59
|
-
useEndpoint.endpointContext.set(handler, { operation, props
|
|
59
|
+
useEndpoint.endpointContext.set(handler, { endpoint, operation, props });
|
|
60
60
|
// @ts-expect-error: it's always an object
|
|
61
61
|
useServerPlugins.serverPlugins.set(handler, endpoint.plugins);
|
|
62
62
|
innet__default["default"](children, handler);
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
export interface HostProps {
|
|
3
|
+
/**
|
|
4
|
+
* An optional string describing the host designated by the URL.
|
|
5
|
+
* [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
|
|
6
|
+
* */
|
|
7
|
+
description?: string;
|
|
3
8
|
/**
|
|
4
9
|
* A URL to the target host.
|
|
5
10
|
* This URL supports Server Variables and MAY be relative,
|
|
@@ -7,10 +12,5 @@ export interface HostProps {
|
|
|
7
12
|
* Variable substitutions will be made when a variable is named in {brackets}.
|
|
8
13
|
* */
|
|
9
14
|
url: string;
|
|
10
|
-
/**
|
|
11
|
-
* An optional string describing the host designated by the URL.
|
|
12
|
-
* [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
|
|
13
|
-
* */
|
|
14
|
-
description?: string;
|
|
15
15
|
}
|
|
16
16
|
export declare const host: HandlerPlugin;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
export interface LicenseProps {
|
|
3
|
-
/**
|
|
4
|
-
* The license name used for the API.
|
|
5
|
-
* @example: Apache 2.0
|
|
6
|
-
* */
|
|
7
|
-
name: string;
|
|
8
3
|
/**
|
|
9
4
|
* An [SPDX](https://spdx.org/spdx-specification-21-web-version#h.jxpfx0ykyb60) license expression for the API.
|
|
10
5
|
* The `identifier` field is mutually exclusive of the `url` field.
|
|
11
6
|
* @example: Apache-2.0
|
|
12
7
|
* */
|
|
13
8
|
identifier?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The license name used for the API.
|
|
11
|
+
* @example: Apache 2.0
|
|
12
|
+
* */
|
|
13
|
+
name: string;
|
|
14
14
|
/**
|
|
15
15
|
* A URL to the license used for the API.
|
|
16
16
|
* This MUST be in the form of a URL.
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
import { type InParam } from '../../../types';
|
|
3
3
|
export interface ParamProps {
|
|
4
|
+
/**
|
|
5
|
+
* Specifies that a parameter is deprecated and SHOULD be transitioned out of usage.
|
|
6
|
+
* Default value is `false`.
|
|
7
|
+
* */
|
|
8
|
+
deprecated?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* A brief description of the parameter.
|
|
11
|
+
* This could contain examples of use.
|
|
12
|
+
* [CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text representation.
|
|
13
|
+
* */
|
|
14
|
+
description?: string;
|
|
4
15
|
/**
|
|
5
16
|
* The location of the parameter.
|
|
6
17
|
* Possible values are "query", "header", "path" or "cookie".
|
|
@@ -14,22 +25,11 @@ export interface ParamProps {
|
|
|
14
25
|
* - For all other cases, the `name` corresponds to the parameter name used by the `in` property.
|
|
15
26
|
* */
|
|
16
27
|
name: string;
|
|
17
|
-
/**
|
|
18
|
-
* A brief description of the parameter.
|
|
19
|
-
* This could contain examples of use.
|
|
20
|
-
* [CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text representation.
|
|
21
|
-
* */
|
|
22
|
-
description?: string;
|
|
23
28
|
/**
|
|
24
29
|
* Determines whether this parameter is mandatory.
|
|
25
30
|
* If the parameter location is "path", this property is `true` and its value MUST be `true`.
|
|
26
31
|
* Otherwise, the property MAY be included and its default value is `false`.
|
|
27
32
|
* */
|
|
28
33
|
required?: boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Specifies that a parameter is deprecated and SHOULD be transitioned out of usage.
|
|
31
|
-
* Default value is `false`.
|
|
32
|
-
* */
|
|
33
|
-
deprecated?: boolean;
|
|
34
34
|
}
|
|
35
35
|
export declare const param: HandlerPlugin;
|
|
@@ -13,14 +13,14 @@ import { required } from '../../../utils/rules/required/required.es6.js';
|
|
|
13
13
|
import { oneOf } from '../../../utils/rules/oneOf/oneOf.es6.js';
|
|
14
14
|
|
|
15
15
|
const inMap = {
|
|
16
|
-
query: 'search',
|
|
17
|
-
path: 'path',
|
|
18
16
|
cookie: 'cookie',
|
|
19
17
|
header: 'header',
|
|
18
|
+
path: 'path',
|
|
19
|
+
query: 'search',
|
|
20
20
|
};
|
|
21
21
|
const param = () => {
|
|
22
22
|
var _a;
|
|
23
|
-
const { operation,
|
|
23
|
+
const { endpoint, operation, } = useEndpoint();
|
|
24
24
|
if (!operation.parameters) {
|
|
25
25
|
operation.parameters = [];
|
|
26
26
|
}
|
|
@@ -21,14 +21,14 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
21
21
|
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
22
22
|
|
|
23
23
|
const inMap = {
|
|
24
|
-
query: 'search',
|
|
25
|
-
path: 'path',
|
|
26
24
|
cookie: 'cookie',
|
|
27
25
|
header: 'header',
|
|
26
|
+
path: 'path',
|
|
27
|
+
query: 'search',
|
|
28
28
|
};
|
|
29
29
|
const param = () => {
|
|
30
30
|
var _a;
|
|
31
|
-
const { operation,
|
|
31
|
+
const { endpoint, operation, } = useEndpoint.useEndpoint();
|
|
32
32
|
if (!operation.parameters) {
|
|
33
33
|
operation.parameters = [];
|
|
34
34
|
}
|