@grest-ts/asyncapi 0.0.24
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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/src/AsyncApiTypes.d.ts +111 -0
- package/dist/src/AsyncApiTypes.d.ts.map +1 -0
- package/dist/src/AsyncApiTypes.js +6 -0
- package/dist/src/AsyncApiTypes.js.map +1 -0
- package/dist/src/GGAsyncApiDocs.d.ts +73 -0
- package/dist/src/GGAsyncApiDocs.d.ts.map +1 -0
- package/dist/src/GGAsyncApiDocs.js +125 -0
- package/dist/src/GGAsyncApiDocs.js.map +1 -0
- package/dist/src/index-node.d.ts +7 -0
- package/dist/src/index-node.d.ts.map +1 -0
- package/dist/src/index-node.js +5 -0
- package/dist/src/index-node.js.map +1 -0
- package/dist/src/toAsyncApi.d.ts +27 -0
- package/dist/src/toAsyncApi.d.ts.map +1 -0
- package/dist/src/toAsyncApi.js +301 -0
- package/dist/src/toAsyncApi.js.map +1 -0
- package/dist/src/tsconfig.json +17 -0
- package/dist/tsconfig.publish.tsbuildinfo +1 -0
- package/package.json +57 -0
- package/src/AsyncApiTypes.ts +120 -0
- package/src/GGAsyncApiDocs.ts +167 -0
- package/src/index-node.ts +7 -0
- package/src/toAsyncApi.ts +380 -0
- package/src/tsconfig.json +17 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Grest Games OÜ
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<!-- GREST-TS-BANNER-START -->
|
|
2
|
+
> Part of the [grest-ts](https://github.com/grest-ts/grest-ts) framework.
|
|
3
|
+
> [Documentation](https://github.com/grest-ts/grest-ts#readme) | [All packages](https://github.com/grest-ts/grest-ts#package-reference)
|
|
4
|
+
<!-- GREST-TS-BANNER-END -->
|
|
5
|
+
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal AsyncAPI 3.0 type definitions.
|
|
3
|
+
* Only the subset used by @grest-ts/asyncapi — enough for correct spec generation.
|
|
4
|
+
*/
|
|
5
|
+
export interface AsyncAPIDocument {
|
|
6
|
+
asyncapi: "3.0.0";
|
|
7
|
+
info: InfoObject;
|
|
8
|
+
servers?: Record<string, ServerObject>;
|
|
9
|
+
channels: Record<string, ChannelObject>;
|
|
10
|
+
operations: Record<string, OperationObject>;
|
|
11
|
+
components?: ComponentsObject;
|
|
12
|
+
}
|
|
13
|
+
export interface InfoObject {
|
|
14
|
+
title: string;
|
|
15
|
+
version: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ServerObject {
|
|
19
|
+
host: string;
|
|
20
|
+
protocol: "ws" | "wss" | "http" | "https";
|
|
21
|
+
description?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ChannelObject {
|
|
24
|
+
address: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
title?: string;
|
|
27
|
+
messages?: Record<string, MessageObject | ReferenceObject>;
|
|
28
|
+
bindings?: ChannelBindingsObject;
|
|
29
|
+
}
|
|
30
|
+
export interface ChannelBindingsObject {
|
|
31
|
+
ws?: WsChannelBinding;
|
|
32
|
+
}
|
|
33
|
+
export interface WsChannelBinding {
|
|
34
|
+
method?: "GET" | "POST";
|
|
35
|
+
headers?: SchemaObject;
|
|
36
|
+
bindingVersion?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface OperationObject {
|
|
39
|
+
action: "send" | "receive";
|
|
40
|
+
channel: ReferenceObject;
|
|
41
|
+
title?: string;
|
|
42
|
+
summary?: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
messages?: ReferenceObject[];
|
|
45
|
+
reply?: OperationReplyObject;
|
|
46
|
+
security?: SecurityRequirementObject[];
|
|
47
|
+
}
|
|
48
|
+
export interface OperationReplyObject {
|
|
49
|
+
channel?: ReferenceObject;
|
|
50
|
+
messages?: ReferenceObject[];
|
|
51
|
+
}
|
|
52
|
+
export interface MessageObject {
|
|
53
|
+
name?: string;
|
|
54
|
+
title?: string;
|
|
55
|
+
summary?: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
payload?: SchemaObject | ReferenceObject;
|
|
58
|
+
headers?: SchemaObject;
|
|
59
|
+
contentType?: string;
|
|
60
|
+
}
|
|
61
|
+
export interface ComponentsObject {
|
|
62
|
+
schemas?: Record<string, SchemaObject>;
|
|
63
|
+
messages?: Record<string, MessageObject>;
|
|
64
|
+
securitySchemes?: Record<string, SecuritySchemeObject>;
|
|
65
|
+
}
|
|
66
|
+
export interface SchemaObject {
|
|
67
|
+
type?: string | string[];
|
|
68
|
+
properties?: Record<string, SchemaObject | ReferenceObject>;
|
|
69
|
+
required?: string[];
|
|
70
|
+
additionalProperties?: boolean | SchemaObject;
|
|
71
|
+
items?: SchemaObject | ReferenceObject;
|
|
72
|
+
prefixItems?: (SchemaObject | ReferenceObject)[];
|
|
73
|
+
oneOf?: (SchemaObject | ReferenceObject)[];
|
|
74
|
+
anyOf?: (SchemaObject | ReferenceObject)[];
|
|
75
|
+
allOf?: (SchemaObject | ReferenceObject)[];
|
|
76
|
+
enum?: unknown[];
|
|
77
|
+
const?: unknown;
|
|
78
|
+
format?: string;
|
|
79
|
+
title?: string;
|
|
80
|
+
description?: string;
|
|
81
|
+
example?: unknown;
|
|
82
|
+
examples?: unknown[];
|
|
83
|
+
deprecated?: boolean;
|
|
84
|
+
default?: unknown;
|
|
85
|
+
minimum?: number;
|
|
86
|
+
maximum?: number;
|
|
87
|
+
minLength?: number;
|
|
88
|
+
maxLength?: number;
|
|
89
|
+
pattern?: string;
|
|
90
|
+
minItems?: number;
|
|
91
|
+
maxItems?: number;
|
|
92
|
+
discriminator?: {
|
|
93
|
+
propertyName: string;
|
|
94
|
+
};
|
|
95
|
+
[key: string]: unknown;
|
|
96
|
+
}
|
|
97
|
+
export interface ReferenceObject {
|
|
98
|
+
$ref: string;
|
|
99
|
+
}
|
|
100
|
+
export interface SecuritySchemeObject {
|
|
101
|
+
type: "http" | "apiKey" | "userPassword" | "X509" | "symmetricEncryption" | "asymmetricEncryption" | "plain" | "scramSha256" | "scramSha512" | "gssapi" | "oauth2" | "openIdConnect";
|
|
102
|
+
scheme?: string;
|
|
103
|
+
description?: string;
|
|
104
|
+
name?: string;
|
|
105
|
+
in?: "user" | "password" | "query" | "header" | "cookie";
|
|
106
|
+
}
|
|
107
|
+
/** AsyncAPI 3.0 security: [{$ref: "#/components/securitySchemes/Name"}] */
|
|
108
|
+
export type SecurityRequirementObject = ReferenceObject | {
|
|
109
|
+
[name: string]: string[];
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=A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,GAAG,aAAa,GAAG,QAAQ,GAAG,QAAQ,GAAG,eAAe,CAAC;IACrL,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;CAC5D;AAED,2EAA2E;AAC3E,MAAM,MAAM,yBAAyB,GAAG,eAAe,GAAG;IAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AsyncApiTypes.js","sourceRoot":"","sources":["../../src/AsyncApiTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { GGWebSocketSchema } from "@grest-ts/websocket";
|
|
2
|
+
import { GGHttpServer } from "@grest-ts/http";
|
|
3
|
+
import type { AsyncAPIDocument } from "./AsyncApiTypes";
|
|
4
|
+
import { ToAsyncApiOptions } from "./toAsyncApi";
|
|
5
|
+
export interface GGAsyncApiDocsOptions extends ToAsyncApiOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Path where the JSON spec is served.
|
|
8
|
+
* e.g. "/asyncapi.json"
|
|
9
|
+
*/
|
|
10
|
+
specPath: string;
|
|
11
|
+
/**
|
|
12
|
+
* Path where the AsyncAPI Studio UI is served.
|
|
13
|
+
* e.g. "/asyncapi-docs"
|
|
14
|
+
*/
|
|
15
|
+
docsPath: string;
|
|
16
|
+
/**
|
|
17
|
+
* If true, build spec immediately on construction.
|
|
18
|
+
* @default false (lazy on first request)
|
|
19
|
+
*/
|
|
20
|
+
eager?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Explicit schema list. When provided, overrides server.registeredWebSocketSchemas.
|
|
23
|
+
*/
|
|
24
|
+
schemas?: GGWebSocketSchema<any, any, any, any, any>[];
|
|
25
|
+
/**
|
|
26
|
+
* The HTTP server to register the docs routes on.
|
|
27
|
+
* When omitted, uses the default GGHttpServer from the locator — the same
|
|
28
|
+
* fallback as MyApi.register().
|
|
29
|
+
*/
|
|
30
|
+
http?: GGHttpServer;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Serves GET /asyncapi.json and GET /asyncapi-docs (AsyncAPI Studio UI)
|
|
34
|
+
* for all WebSocket schemas registered on a GGHttpServer.
|
|
35
|
+
*
|
|
36
|
+
* Schemas are collected automatically from server.registeredWebSocketSchemas,
|
|
37
|
+
* or can be provided explicitly via options.schemas.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* // Mirrors MyApi.register() exactly — uses locator default when http is omitted:
|
|
41
|
+
* GGAsyncApiDocs.register({
|
|
42
|
+
* title: "My Service Events",
|
|
43
|
+
* version: "1.0.0",
|
|
44
|
+
* specPath: "/asyncapi.json",
|
|
45
|
+
* docsPath: "/asyncapi-docs"
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* // With explicit server (same as MyApi.register(impl, {http: server})):
|
|
50
|
+
* GGAsyncApiDocs.register({
|
|
51
|
+
* title: "My Service Events",
|
|
52
|
+
* specPath: "/asyncapi.json",
|
|
53
|
+
* docsPath: "/asyncapi-docs",
|
|
54
|
+
* http: server
|
|
55
|
+
* });
|
|
56
|
+
*/
|
|
57
|
+
export declare class GGAsyncApiDocs {
|
|
58
|
+
private readonly server;
|
|
59
|
+
private readonly options;
|
|
60
|
+
private _spec;
|
|
61
|
+
/**
|
|
62
|
+
* Register AsyncAPI docs routes on an HTTP server.
|
|
63
|
+
* Mirrors the MyApi.register() pattern exactly:
|
|
64
|
+
* - options.http — explicit server (optional)
|
|
65
|
+
* - when absent, uses the default GGHttpServer from the locator
|
|
66
|
+
*/
|
|
67
|
+
static register(options: GGAsyncApiDocsOptions): void;
|
|
68
|
+
constructor(server: GGHttpServer, options: GGAsyncApiDocsOptions);
|
|
69
|
+
private buildSpec;
|
|
70
|
+
getSpec(): AsyncAPIDocument;
|
|
71
|
+
registerWith(server: GGHttpServer): this;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=GGAsyncApiDocs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GGAsyncApiDocs.d.ts","sourceRoot":"","sources":["../../src/GGAsyncApiDocs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAC,YAAY,EAAiB,MAAM,gBAAgB,CAAC;AAE5D,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAa,iBAAiB,EAAC,MAAM,cAAc,CAAC;AAE3D,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC5D;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;OAEG;IACH,OAAO,CAAC,EAAE,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IAEvD;;;;OAIG;IACH,IAAI,CAAC,EAAE,YAAY,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,cAAc;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;IAChD,OAAO,CAAC,KAAK,CAA+B;IAE5C;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI;gBAMzC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,qBAAqB;IAShE,OAAO,CAAC,SAAS;IAMV,OAAO,IAAI,gBAAgB;IAI3B,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;CAgClD"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { GG_HTTP_SERVER } from "@grest-ts/http";
|
|
2
|
+
import { GGLocator } from "@grest-ts/locator";
|
|
3
|
+
import { toAsyncApi } from "./toAsyncApi.js";
|
|
4
|
+
/**
|
|
5
|
+
* Serves GET /asyncapi.json and GET /asyncapi-docs (AsyncAPI Studio UI)
|
|
6
|
+
* for all WebSocket schemas registered on a GGHttpServer.
|
|
7
|
+
*
|
|
8
|
+
* Schemas are collected automatically from server.registeredWebSocketSchemas,
|
|
9
|
+
* or can be provided explicitly via options.schemas.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Mirrors MyApi.register() exactly — uses locator default when http is omitted:
|
|
13
|
+
* GGAsyncApiDocs.register({
|
|
14
|
+
* title: "My Service Events",
|
|
15
|
+
* version: "1.0.0",
|
|
16
|
+
* specPath: "/asyncapi.json",
|
|
17
|
+
* docsPath: "/asyncapi-docs"
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // With explicit server (same as MyApi.register(impl, {http: server})):
|
|
22
|
+
* GGAsyncApiDocs.register({
|
|
23
|
+
* title: "My Service Events",
|
|
24
|
+
* specPath: "/asyncapi.json",
|
|
25
|
+
* docsPath: "/asyncapi-docs",
|
|
26
|
+
* http: server
|
|
27
|
+
* });
|
|
28
|
+
*/
|
|
29
|
+
export class GGAsyncApiDocs {
|
|
30
|
+
server;
|
|
31
|
+
options;
|
|
32
|
+
_spec;
|
|
33
|
+
/**
|
|
34
|
+
* Register AsyncAPI docs routes on an HTTP server.
|
|
35
|
+
* Mirrors the MyApi.register() pattern exactly:
|
|
36
|
+
* - options.http — explicit server (optional)
|
|
37
|
+
* - when absent, uses the default GGHttpServer from the locator
|
|
38
|
+
*/
|
|
39
|
+
static register(options) {
|
|
40
|
+
const server = options.http ?? GGLocator.getScope().get(GG_HTTP_SERVER);
|
|
41
|
+
if (!server)
|
|
42
|
+
throw new Error("GGAsyncApiDocs.register: no HTTP server found. Pass options.http or create a GGHttpServer first.");
|
|
43
|
+
new GGAsyncApiDocs(server, options);
|
|
44
|
+
}
|
|
45
|
+
constructor(server, options) {
|
|
46
|
+
this.server = server;
|
|
47
|
+
this.options = options;
|
|
48
|
+
if (options.eager) {
|
|
49
|
+
this._spec = this.buildSpec();
|
|
50
|
+
}
|
|
51
|
+
this.registerWith(server);
|
|
52
|
+
}
|
|
53
|
+
buildSpec() {
|
|
54
|
+
const schemas = this.options.schemas
|
|
55
|
+
?? this.server.registeredWebSocketSchemas;
|
|
56
|
+
return toAsyncApi(schemas, this.options);
|
|
57
|
+
}
|
|
58
|
+
getSpec() {
|
|
59
|
+
return this._spec ??= this.buildSpec();
|
|
60
|
+
}
|
|
61
|
+
registerWith(server) {
|
|
62
|
+
const specPath = this.options.specPath;
|
|
63
|
+
const docsPath = this.options.docsPath;
|
|
64
|
+
server.registerRoute("GET", specPath, async (_req, res) => {
|
|
65
|
+
const spec = this.getSpec();
|
|
66
|
+
const body = JSON.stringify(spec, null, 2);
|
|
67
|
+
res.writeHead(200, {
|
|
68
|
+
"Content-Type": "application/json",
|
|
69
|
+
"Content-Length": Buffer.byteLength(body)
|
|
70
|
+
});
|
|
71
|
+
res.end(body);
|
|
72
|
+
});
|
|
73
|
+
// AsyncAPI Studio HTML — served for docsPath and all sub-paths so that
|
|
74
|
+
// sidebar deep-links (e.g. /asyncapi-docs/ChatApi_send_foo) stay on the
|
|
75
|
+
// same page instead of opening a new tab or returning 404.
|
|
76
|
+
const serveStudio = async (_req, res) => {
|
|
77
|
+
const spec = this.getSpec();
|
|
78
|
+
const html = buildAsyncApiStudioHtml(spec);
|
|
79
|
+
res.writeHead(200, {
|
|
80
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
81
|
+
"Content-Length": Buffer.byteLength(html)
|
|
82
|
+
});
|
|
83
|
+
res.end(html);
|
|
84
|
+
};
|
|
85
|
+
server.registerRoute("GET", docsPath, serveStudio);
|
|
86
|
+
// Wildcard for deep-link navigation within the studio
|
|
87
|
+
server.registerRoute("GET", docsPath + "/*", serveStudio);
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Build the AsyncAPI Studio HTML page with the spec embedded as inline JSON.
|
|
93
|
+
*
|
|
94
|
+
* The spec is passed directly as the schema object (not wrapped in {url:...} or
|
|
95
|
+
* {source:...}) — this is the correct API for inline document rendering and
|
|
96
|
+
* avoids both external fetches and internal $ref resolution failures.
|
|
97
|
+
*
|
|
98
|
+
* The wildcard route (docsPath/*) is registered alongside docsPath so that
|
|
99
|
+
* sidebar deep-links stay on the same page instead of opening a new tab.
|
|
100
|
+
*/
|
|
101
|
+
function buildAsyncApiStudioHtml(spec) {
|
|
102
|
+
// Pass the document directly as schema — AsyncApiStandalone accepts the plain object
|
|
103
|
+
const specJson = JSON.stringify(spec);
|
|
104
|
+
return `<!DOCTYPE html>
|
|
105
|
+
<html lang="en">
|
|
106
|
+
<head>
|
|
107
|
+
<meta charset="UTF-8" />
|
|
108
|
+
<title>AsyncAPI Docs</title>
|
|
109
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
110
|
+
<link rel="icon" href="https://www.asyncapi.com/favicon.ico" />
|
|
111
|
+
<link rel="stylesheet" href="https://unpkg.com/@asyncapi/react-component@latest/styles/default.min.css">
|
|
112
|
+
</head>
|
|
113
|
+
<body>
|
|
114
|
+
<div id="asyncapi"></div>
|
|
115
|
+
<script src="https://unpkg.com/@asyncapi/react-component@latest/browser/standalone/index.js"></script>
|
|
116
|
+
<script>
|
|
117
|
+
AsyncApiStandalone.render(
|
|
118
|
+
{schema: ${specJson}, config: {show: {sidebar: true}}},
|
|
119
|
+
document.getElementById('asyncapi')
|
|
120
|
+
);
|
|
121
|
+
</script>
|
|
122
|
+
</body>
|
|
123
|
+
</html>`;
|
|
124
|
+
}
|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AC,aAAa,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC;QAE1D,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAED;;;;;;;;;GASG;AACH,SAAS,uBAAuB,CAAC,IAAsB;IACnD,qFAAqF;IACrF,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACtC,OAAO;;;;;;;;;;;;;;eAcI,QAAQ;;;;;QAKf,CAAC;AACT,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { toAsyncApi } from "./toAsyncApi";
|
|
2
|
+
export type { ToAsyncApiOptions } from "./toAsyncApi";
|
|
3
|
+
export { GGAsyncApiDocs } from "./GGAsyncApiDocs";
|
|
4
|
+
export type { GGAsyncApiDocsOptions } from "./GGAsyncApiDocs";
|
|
5
|
+
export { GGAsyncApiDocs as GGAsyncApiServer } from "./GGAsyncApiDocs";
|
|
6
|
+
export type { GGAsyncApiDocsOptions as GGAsyncApiServerOptions } from "./GGAsyncApiDocs";
|
|
7
|
+
//# sourceMappingURL=index-node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-node.d.ts","sourceRoot":"","sources":["../../src/index-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,YAAY,EAAC,iBAAiB,EAAC,MAAM,cAAc,CAAC;AACpD,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,YAAY,EAAC,qBAAqB,EAAC,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAAC,cAAc,IAAI,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AACpE,YAAY,EAAC,qBAAqB,IAAI,uBAAuB,EAAC,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-node.js","sourceRoot":"","sources":["../../src/index-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAExC,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD,8BAA8B;AAC9B,OAAO,EAAC,cAAc,IAAI,gBAAgB,EAAC,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { GGWebSocketSchema } from "@grest-ts/websocket";
|
|
2
|
+
import type { AsyncAPIDocument } from "./AsyncApiTypes";
|
|
3
|
+
export interface ToAsyncApiOptions {
|
|
4
|
+
title?: string;
|
|
5
|
+
version?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
servers?: Record<string, {
|
|
8
|
+
host: string;
|
|
9
|
+
protocol: "ws" | "wss";
|
|
10
|
+
description?: string;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Convert a list of GGWebSocketSchema instances to an AsyncAPI 3.0 document.
|
|
15
|
+
*
|
|
16
|
+
* Message patterns:
|
|
17
|
+
* - clientToServer with success/errors: request/response (action:send + reply)
|
|
18
|
+
* - clientToServer without success/errors: fire-and-forget (action:send, no reply)
|
|
19
|
+
* - serverToClient with input: server push (action:receive, no reply)
|
|
20
|
+
* - serverToClient with success/errors: server-initiated request (action:receive + reply)
|
|
21
|
+
*
|
|
22
|
+
* All patterns are symmetric: reply.messages lists ALL possible response messages
|
|
23
|
+
* (success + each error type), correctly modelling that both parties can receive
|
|
24
|
+
* any of them.
|
|
25
|
+
*/
|
|
26
|
+
export declare function toAsyncApi(schemas: GGWebSocketSchema<any, any, any, any, any>[], options?: ToAsyncApiOptions, serverPort?: number): AsyncAPIDocument;
|
|
27
|
+
//# sourceMappingURL=toAsyncApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toAsyncApi.d.ts","sourceRoot":"","sources":["../../src/toAsyncApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAG3D,OAAO,KAAK,EACR,gBAAgB,EAGnB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,iBAAiB;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,IAAI,GAAG,KAAK,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC,CAAC;CAC1F;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CACtB,OAAO,EAAE,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,EACrD,OAAO,GAAE,iBAAsB,EAC/B,UAAU,CAAC,EAAE,MAAM,GACpB,gBAAgB,CAwKlB"}
|