@schemavaults/openapi-operations 0.1.8 → 0.2.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 +41 -0
- package/dist/adapters/nextjs.d.ts +18 -4
- package/dist/adapters/nextjs.js +18 -4
- package/dist/adapters/nextjs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/operation.d.ts +6 -0
- package/dist/operation.js +8 -0
- package/dist/operation.js.map +1 -1
- package/dist/runtime/create-operations-app-factory.d.ts +67 -0
- package/dist/runtime/create-operations-app-factory.js +67 -0
- package/dist/runtime/create-operations-app-factory.js.map +1 -0
- package/dist/runtime/create-operations-app.d.ts +2 -1
- package/dist/runtime/create-operations-app.js.map +1 -1
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -147,6 +147,47 @@ export const { GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS } = toNextRouteHandl
|
|
|
147
147
|
export default toVercelHandler(app);
|
|
148
148
|
```
|
|
149
149
|
|
|
150
|
+
### One route file per operation
|
|
151
|
+
|
|
152
|
+
A catch-all is not required. To give every operation its own Next.js `route.ts`
|
|
153
|
+
(or Vercel function file) while still serving one OpenAPI document that lists all of
|
|
154
|
+
them, bind the shared runtime configuration and the full operation catalogue once with
|
|
155
|
+
`createOperationsAppFactory()` and build a small app per route file from it:
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
// src/lib/api/app.ts
|
|
159
|
+
import { createOperationsAppFactory, operationHttpMethods, toNextRouteHandlers } from "@schemavaults/openapi-operations";
|
|
160
|
+
|
|
161
|
+
export const operations = [getApp, health]; // the catalogue buildOpenApiDocument() is given
|
|
162
|
+
export const api = createOperationsAppFactory<{ dbh: Kysely<AuthDatabase> }, UserData>({
|
|
163
|
+
operations,
|
|
164
|
+
authResolvers,
|
|
165
|
+
context: async () => ({ dbh: await getDbh() }),
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// app/api/apps/[app_id]/route.ts (Next.js segment [app_id] ↔ OpenAPI {app_id})
|
|
169
|
+
export const runtime = "nodejs";
|
|
170
|
+
export const { GET } = toNextRouteHandlers(api.app([getApp]), operationHttpMethods([getApp]));
|
|
171
|
+
|
|
172
|
+
// app/api/health/route.ts
|
|
173
|
+
export const { GET } = toNextRouteHandlers(api.app([health]), operationHttpMethods([health]));
|
|
174
|
+
|
|
175
|
+
// app/api/openapi.json/route.ts
|
|
176
|
+
export const { GET } = toNextRouteHandlers(
|
|
177
|
+
api.openApiDocumentApp({ path: "/api/openapi.json", document: openApiDocument }),
|
|
178
|
+
["get"],
|
|
179
|
+
);
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Each app routes on the full request pathname, so no `basePath` is needed and the
|
|
183
|
+
dynamic segment is parsed by the app itself (Next.js' `params` are never read).
|
|
184
|
+
`operationHttpMethods()` exports only the methods the operations declare, leaving 405s
|
|
185
|
+
for the rest to Next.js. The factory validates the whole catalogue up front (unique
|
|
186
|
+
operations, a resolver for every scheme) and `api.app()` throws for an operation that
|
|
187
|
+
is not in it, so a route file cannot serve something the document does not describe.
|
|
188
|
+
The reverse (a documented operation with no route file) is a file-layout question;
|
|
189
|
+
the example resource server in this repository checks it with a small `bun test`.
|
|
190
|
+
|
|
150
191
|
Per request the app: resolves the context, tries each accepted scheme's resolver in
|
|
151
192
|
order (401 + `WWW-Authenticate` if none yields a principal), enforces the route guard
|
|
152
193
|
(403), required scopes (403 `insufficient_scope`), organization membership (403), then
|
|
@@ -5,8 +5,8 @@ export type NextRouteHandlers<TMethods extends HttpMethod = HttpMethod> = {
|
|
|
5
5
|
readonly [M in TMethods as Uppercase<M>]: NextRouteHandler;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
|
-
* Next.js App Router route-handler exports for the operations app.
|
|
9
|
-
*
|
|
8
|
+
* Next.js App Router route-handler exports for the operations app. Either
|
|
9
|
+
* mount one app from a catch-all route so it serves every operation:
|
|
10
10
|
*
|
|
11
11
|
* ```ts
|
|
12
12
|
* // app/api/[[...route]]/route.ts
|
|
@@ -14,7 +14,21 @@ export type NextRouteHandlers<TMethods extends HttpMethod = HttpMethod> = {
|
|
|
14
14
|
* export const { GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS } = toNextRouteHandlers(app);
|
|
15
15
|
* ```
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* or give each operation its own `route.ts` at the matching Next.js path
|
|
18
|
+
* (`app/api/apps/[app_id]/route.ts` for `/api/apps/{app_id}`) and mount an
|
|
19
|
+
* app built for just that operation, via `createOperationsAppFactory()`,
|
|
20
|
+
* exporting only the methods it declares so Next.js answers 405 for the
|
|
21
|
+
* rest:
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* // app/api/apps/[app_id]/route.ts
|
|
25
|
+
* export const { GET } = toNextRouteHandlers(api.app([getApp]), operationHttpMethods([getApp]));
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* The app receives the raw request, so it routes on the full pathname
|
|
29
|
+
* regardless of which route file it is exported from; no `basePath` is
|
|
30
|
+
* needed for per-route mounting. Pass `methods` to only export a subset
|
|
31
|
+
* (e.g. when a route file coexists with hand-written handlers for other
|
|
32
|
+
* methods).
|
|
19
33
|
*/
|
|
20
34
|
export declare function toNextRouteHandlers<const TMethods extends readonly HttpMethod[] = typeof HTTP_METHODS>(app: Hono, methods?: TMethods): NextRouteHandlers<TMethods[number]>;
|
package/dist/adapters/nextjs.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { handle } from "hono/vercel";
|
|
2
2
|
import { HTTP_METHODS } from "../http-method";
|
|
3
3
|
/**
|
|
4
|
-
* Next.js App Router route-handler exports for the operations app.
|
|
5
|
-
*
|
|
4
|
+
* Next.js App Router route-handler exports for the operations app. Either
|
|
5
|
+
* mount one app from a catch-all route so it serves every operation:
|
|
6
6
|
*
|
|
7
7
|
* ```ts
|
|
8
8
|
* // app/api/[[...route]]/route.ts
|
|
@@ -10,8 +10,22 @@ import { HTTP_METHODS } from "../http-method";
|
|
|
10
10
|
* export const { GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS } = toNextRouteHandlers(app);
|
|
11
11
|
* ```
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* or give each operation its own `route.ts` at the matching Next.js path
|
|
14
|
+
* (`app/api/apps/[app_id]/route.ts` for `/api/apps/{app_id}`) and mount an
|
|
15
|
+
* app built for just that operation, via `createOperationsAppFactory()`,
|
|
16
|
+
* exporting only the methods it declares so Next.js answers 405 for the
|
|
17
|
+
* rest:
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* // app/api/apps/[app_id]/route.ts
|
|
21
|
+
* export const { GET } = toNextRouteHandlers(api.app([getApp]), operationHttpMethods([getApp]));
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* The app receives the raw request, so it routes on the full pathname
|
|
25
|
+
* regardless of which route file it is exported from; no `basePath` is
|
|
26
|
+
* needed for per-route mounting. Pass `methods` to only export a subset
|
|
27
|
+
* (e.g. when a route file coexists with hand-written handlers for other
|
|
28
|
+
* methods).
|
|
15
29
|
*/
|
|
16
30
|
export function toNextRouteHandlers(app, methods = HTTP_METHODS) {
|
|
17
31
|
const handler = handle(app);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextjs.js","sourceRoot":"","sources":["../../src/adapters/nextjs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAmB,MAAM,gBAAgB,CAAC;AAQ/D
|
|
1
|
+
{"version":3,"file":"nextjs.js","sourceRoot":"","sources":["../../src/adapters/nextjs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAmB,MAAM,gBAAgB,CAAC;AAQ/D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAAS,EACT,UAAoB,YAAmC;IAEvD,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5B,MAAM,QAAQ,GAAqC,EAAE,CAAC;IACtD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,GAAG,OAAO,CAAC;IAC3C,CAAC;IACD,OAAO,QAA+C,CAAC;AACzD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { HTTP_METHODS, HTTP_METHODS_WITH_REQUEST_BODY, isHttpMethod } from "./ht
|
|
|
4
4
|
export type { HttpMethod } from "./http-method";
|
|
5
5
|
export { defineAuthScheme, publicAccess, requireAuth, isPublicOperationAuth, ROUTE_GUARD_TYPES, schemaVaultsAccessTokenBearerScheme, schemaVaultsAccessTokenCookieScheme, schemaVaultsRefreshTokenCookieScheme, oidcClientSecretBasicScheme, oidcClientSecretPostScheme, apiKeyHeaderScheme, } from "./auth-scheme";
|
|
6
6
|
export type { AuthSchemeDefinition, AuthRequirements, OperationAuth, PublicOperationAuth, RequiredOperationAuth, OrganizationRoleRequirement, RouteGuardType, } from "./auth-scheme";
|
|
7
|
-
export { defineOperation, createOperationDefiner, defineOperationGroup, defaultOperationId, assertUniqueOperations, } from "./operation";
|
|
7
|
+
export { defineOperation, createOperationDefiner, defineOperationGroup, defaultOperationId, assertUniqueOperations, operationHttpMethods, } from "./operation";
|
|
8
8
|
export type { AnyOperationDefinition, AuthPrincipal, EmptyResponseStatusOf, InferBody, InferParsed, OperationDefiner, OperationDefinition, OperationGroup, OperationHandlerContext, OperationHandlerResult, OperationInput, OperationRequestDefinition, RequestBodyContentType, RequestBodyDefinition, ResponseBodyOf, ResponseDefinition, ResponseStatusOf, ResponsesDefinition, } from "./operation";
|
|
9
9
|
export { buildOpenApiDocument, collectAuthSchemes, toRouteConfig, toSecuritySchemeComponent, } from "./openapi/build-openapi-document";
|
|
10
10
|
export type { BuildOpenApiDocumentOptions } from "./openapi/build-openapi-document";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { z } from "./zod-openapi";
|
|
2
2
|
export { HTTP_METHODS, HTTP_METHODS_WITH_REQUEST_BODY, isHttpMethod } from "./http-method";
|
|
3
3
|
export { defineAuthScheme, publicAccess, requireAuth, isPublicOperationAuth, ROUTE_GUARD_TYPES, schemaVaultsAccessTokenBearerScheme, schemaVaultsAccessTokenCookieScheme, schemaVaultsRefreshTokenCookieScheme, oidcClientSecretBasicScheme, oidcClientSecretPostScheme, apiKeyHeaderScheme, } from "./auth-scheme";
|
|
4
|
-
export { defineOperation, createOperationDefiner, defineOperationGroup, defaultOperationId, assertUniqueOperations, } from "./operation";
|
|
4
|
+
export { defineOperation, createOperationDefiner, defineOperationGroup, defaultOperationId, assertUniqueOperations, operationHttpMethods, } from "./operation";
|
|
5
5
|
export { buildOpenApiDocument, collectAuthSchemes, toRouteConfig, toSecuritySchemeComponent, } from "./openapi/build-openapi-document";
|
|
6
6
|
export { SCHEMAVAULTS_AUTH_EXTENSION, SCHEMAVAULTS_SCHEME_TITLE_EXTENSION, SCHEMAVAULTS_SCHEME_CHALLENGE_EXTENSION, toSchemaVaultsAuthExtension, isSchemaVaultsAuthExtension, } from "./openapi/extensions";
|
|
7
7
|
export { extractPathParameterNames, openApiPathToHonoPath, honoPathToOpenApiPath, isOpenApiPath, } from "./openapi/path-format";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAG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AAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/operation.d.ts
CHANGED
|
@@ -165,4 +165,10 @@ export interface OperationGroup {
|
|
|
165
165
|
* `createOperationsApp` like any other operation list.
|
|
166
166
|
*/
|
|
167
167
|
export declare function defineOperationGroup(group: OperationGroup): AnyOperationDefinition[];
|
|
168
|
+
/**
|
|
169
|
+
* Distinct HTTP methods declared by the given operations, in declaration
|
|
170
|
+
* order. Hands `toNextRouteHandlers()` exactly the methods a route file
|
|
171
|
+
* should export, so Next.js answers 405 for the others itself.
|
|
172
|
+
*/
|
|
173
|
+
export declare function operationHttpMethods(operations: readonly AnyOperationDefinition[]): HttpMethod[];
|
|
168
174
|
export declare function assertUniqueOperations(operations: readonly AnyOperationDefinition[]): void;
|
package/dist/operation.js
CHANGED
|
@@ -93,6 +93,14 @@ export function defineOperationGroup(group) {
|
|
|
93
93
|
return Object.freeze({ ...operation, path, tags });
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Distinct HTTP methods declared by the given operations, in declaration
|
|
98
|
+
* order. Hands `toNextRouteHandlers()` exactly the methods a route file
|
|
99
|
+
* should export, so Next.js answers 405 for the others itself.
|
|
100
|
+
*/
|
|
101
|
+
export function operationHttpMethods(operations) {
|
|
102
|
+
return Array.from(new Set(operations.map((operation) => operation.method)));
|
|
103
|
+
}
|
|
96
104
|
export function assertUniqueOperations(operations) {
|
|
97
105
|
const ids = new Set();
|
|
98
106
|
const routes = new Set();
|
package/dist/operation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation.js","sourceRoot":"","sources":["../src/operation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,8BAA8B,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE9F,OAAO,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM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AAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,UAA6C;IAClF,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IACjC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,SAAS,CAAC,0BAA0B,SAAS,CAAC,WAAW,GAAG,CAAC,CAAC;QAC1E,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAC/B,MAAM,KAAK,GAAG,GAAG,SAAS,CAAC,MAAM,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC;QACtD,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,SAAS,CAAC,mBAAmB,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAChE,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Hono } from "hono";
|
|
2
|
+
import type { AnyOperationDefinition } from "../operation";
|
|
3
|
+
import { type CreateOperationsAppOptions, type OpenApiDocumentRouteOptions } from "./create-operations-app";
|
|
4
|
+
import { type AuthResolvers } from "./resolve-auth";
|
|
5
|
+
export interface CreateOperationsAppFactoryOptions<TContext = unknown, TUser = unknown> {
|
|
6
|
+
/**
|
|
7
|
+
* Every operation the API exposes: the catalogue `buildOpenApiDocument()`
|
|
8
|
+
* is given. Apps built by the factory may only serve operations from it,
|
|
9
|
+
* so a route file cannot mount an operation the document does not list.
|
|
10
|
+
*/
|
|
11
|
+
readonly operations: readonly AnyOperationDefinition[];
|
|
12
|
+
/** Credential resolvers keyed by auth scheme name, shared by every app. */
|
|
13
|
+
readonly authResolvers?: AuthResolvers<TUser>;
|
|
14
|
+
/** Builds the per-request context handed to handlers as `ctx.context`. */
|
|
15
|
+
readonly context?: CreateOperationsAppOptions<TContext, TUser>["context"];
|
|
16
|
+
/** Called for unexpected (non-OperationError) failures before the 500 is sent. */
|
|
17
|
+
readonly onError?: CreateOperationsAppOptions<TContext, TUser>["onError"];
|
|
18
|
+
}
|
|
19
|
+
/** Per-app options a factory caller may still set. */
|
|
20
|
+
export type OperationsAppFactoryAppOptions<TContext = unknown, TUser = unknown> = Pick<CreateOperationsAppOptions<TContext, TUser>, "basePath" | "configure" | "openapi">;
|
|
21
|
+
export interface OperationsAppFactory<TContext = unknown, TUser = unknown> {
|
|
22
|
+
/** The full catalogue the factory was created with. */
|
|
23
|
+
readonly operations: readonly AnyOperationDefinition[];
|
|
24
|
+
/** The shared resolvers every app built by the factory authenticates with. */
|
|
25
|
+
readonly authResolvers: AuthResolvers<TUser>;
|
|
26
|
+
/**
|
|
27
|
+
* Builds a Hono app serving the given operations (default: the whole
|
|
28
|
+
* catalogue) with the shared resolvers / context / error reporting.
|
|
29
|
+
* Throws when an operation is not part of the catalogue.
|
|
30
|
+
*/
|
|
31
|
+
app(operations?: readonly AnyOperationDefinition[], options?: OperationsAppFactoryAppOptions<TContext, TUser>): Hono;
|
|
32
|
+
/** Builds a Hono app that only serves the OpenAPI document. */
|
|
33
|
+
openApiDocumentApp(openapi: OpenApiDocumentRouteOptions, options?: Omit<OperationsAppFactoryAppOptions<TContext, TUser>, "openapi">): Hono;
|
|
34
|
+
/** Throws unless every given operation is part of the catalogue. */
|
|
35
|
+
assertRegistered(operations: readonly AnyOperationDefinition[]): void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Binds the shared runtime configuration (auth resolvers, per-request
|
|
39
|
+
* context, error reporting) and the full operation catalogue once, so many
|
|
40
|
+
* small apps can be built from it: one per Next.js `route.ts` / Vercel
|
|
41
|
+
* function file, each serving only the operation(s) at its path, while a
|
|
42
|
+
* single OpenAPI document generated from the same catalogue still describes
|
|
43
|
+
* all of them.
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* // src/lib/api/app.ts
|
|
47
|
+
* export const api = createOperationsAppFactory<Ctx, UserData>({
|
|
48
|
+
* operations, // the same list buildOpenApiDocument() is given
|
|
49
|
+
* authResolvers,
|
|
50
|
+
* context: () => ({ ... }),
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* // app/api/health/route.ts
|
|
54
|
+
* export const { GET } = toNextRouteHandlers(api.app([health]), operationHttpMethods([health]));
|
|
55
|
+
*
|
|
56
|
+
* // app/api/openapi.json/route.ts
|
|
57
|
+
* export const { GET } = toNextRouteHandlers(
|
|
58
|
+
* api.openApiDocumentApp({ path: "/api/openapi.json", document }),
|
|
59
|
+
* ["get"],
|
|
60
|
+
* );
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* Every app validates against the whole catalogue up front: duplicate
|
|
64
|
+
* operations or a scheme without a resolver fail at module load of the
|
|
65
|
+
* first route rather than when the affected route is first hit.
|
|
66
|
+
*/
|
|
67
|
+
export declare function createOperationsAppFactory<TContext = unknown, TUser = unknown>(options: CreateOperationsAppFactoryOptions<TContext, TUser>): OperationsAppFactory<TContext, TUser>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { assertUniqueOperations } from "../operation";
|
|
2
|
+
import { createOperationsApp, } from "./create-operations-app";
|
|
3
|
+
import { assertResolversForOperations } from "./resolve-auth";
|
|
4
|
+
/**
|
|
5
|
+
* Binds the shared runtime configuration (auth resolvers, per-request
|
|
6
|
+
* context, error reporting) and the full operation catalogue once, so many
|
|
7
|
+
* small apps can be built from it: one per Next.js `route.ts` / Vercel
|
|
8
|
+
* function file, each serving only the operation(s) at its path, while a
|
|
9
|
+
* single OpenAPI document generated from the same catalogue still describes
|
|
10
|
+
* all of them.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* // src/lib/api/app.ts
|
|
14
|
+
* export const api = createOperationsAppFactory<Ctx, UserData>({
|
|
15
|
+
* operations, // the same list buildOpenApiDocument() is given
|
|
16
|
+
* authResolvers,
|
|
17
|
+
* context: () => ({ ... }),
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // app/api/health/route.ts
|
|
21
|
+
* export const { GET } = toNextRouteHandlers(api.app([health]), operationHttpMethods([health]));
|
|
22
|
+
*
|
|
23
|
+
* // app/api/openapi.json/route.ts
|
|
24
|
+
* export const { GET } = toNextRouteHandlers(
|
|
25
|
+
* api.openApiDocumentApp({ path: "/api/openapi.json", document }),
|
|
26
|
+
* ["get"],
|
|
27
|
+
* );
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* Every app validates against the whole catalogue up front: duplicate
|
|
31
|
+
* operations or a scheme without a resolver fail at module load of the
|
|
32
|
+
* first route rather than when the affected route is first hit.
|
|
33
|
+
*/
|
|
34
|
+
export function createOperationsAppFactory(options) {
|
|
35
|
+
const catalogue = Object.freeze([...options.operations]);
|
|
36
|
+
assertUniqueOperations(catalogue);
|
|
37
|
+
const resolvers = options.authResolvers ?? {};
|
|
38
|
+
assertResolversForOperations(catalogue, resolvers);
|
|
39
|
+
const registered = new Set(catalogue);
|
|
40
|
+
const assertRegistered = (operations) => {
|
|
41
|
+
for (const operation of operations) {
|
|
42
|
+
if (!registered.has(operation)) {
|
|
43
|
+
throw new TypeError(`${operation.method.toUpperCase()} ${operation.path} (${operation.operationId}) is not part of the operations catalogue this factory was created with, so it would be served without appearing in the OpenAPI document`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const app = (operations = catalogue, appOptions = {}) => {
|
|
48
|
+
assertRegistered(operations);
|
|
49
|
+
return createOperationsApp({
|
|
50
|
+
operations,
|
|
51
|
+
authResolvers: resolvers,
|
|
52
|
+
context: options.context,
|
|
53
|
+
onError: options.onError,
|
|
54
|
+
basePath: appOptions.basePath,
|
|
55
|
+
configure: appOptions.configure,
|
|
56
|
+
openapi: appOptions.openapi,
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
operations: catalogue,
|
|
61
|
+
authResolvers: resolvers,
|
|
62
|
+
app,
|
|
63
|
+
openApiDocumentApp: (openapi, appOptions = {}) => app([], { ...appOptions, openapi }),
|
|
64
|
+
assertRegistered,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=create-operations-app-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-operations-app-factory.js","sourceRoot":"","sources":["../../src/runtime/create-operations-app-factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EACL,mBAAmB,GAGpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,4BAA4B,EAAsB,MAAM,gBAAgB,CAAC;AA8ClF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,0BAA0B,CACxC,OAA2D;IAE3D,MAAM,SAAS,GAAsC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IAC5F,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAClC,MAAM,SAAS,GAAyB,OAAO,CAAC,aAAa,IAAI,EAAE,CAAC;IACpE,4BAA4B,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IACnD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAyB,SAAS,CAAC,CAAC;IAE9D,MAAM,gBAAgB,GAAG,CAAC,UAA6C,EAAQ,EAAE;QAC/E,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC/B,MAAM,IAAI,SAAS,CACjB,GAAG,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC,WAAW,0IAA0I,CACxN,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,GAAG,GAAiD,CACxD,UAAU,GAAG,SAAS,EACtB,UAAU,GAAG,EAAE,EACf,EAAE;QACF,gBAAgB,CAAC,UAAU,CAAC,CAAC;QAC7B,OAAO,mBAAmB,CAAkB;YAC1C,UAAU;YACV,aAAa,EAAE,SAAS;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,QAAQ,EAAE,UAAU,CAAC,QAAQ;YAC7B,SAAS,EAAE,UAAU,CAAC,SAAS;YAC/B,OAAO,EAAE,UAAU,CAAC,OAAO;SAC5B,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO;QACL,UAAU,EAAE,SAAS;QACrB,aAAa,EAAE,SAAS;QACxB,GAAG;QACH,kBAAkB,EAAE,CAAC,OAAO,EAAE,UAAU,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,GAAG,UAAU,EAAE,OAAO,EAAE,CAAC;QACrF,gBAAgB;KACjB,CAAC;AACJ,CAAC"}
|
|
@@ -18,7 +18,8 @@ export interface CreateOperationsAppOptions<TContext = unknown, TUser = unknown>
|
|
|
18
18
|
* Prefix stripped by the deployment before routing (e.g. `/api` when the
|
|
19
19
|
* app is mounted from `app/api/[[...route]]/route.ts`). Operation paths
|
|
20
20
|
* stay absolute in the OpenAPI document; leave unset to route on them
|
|
21
|
-
* verbatim.
|
|
21
|
+
* verbatim (Next.js route handlers and Vercel functions receive the full
|
|
22
|
+
* request URL, so they never need it).
|
|
22
23
|
*/
|
|
23
24
|
readonly basePath?: string;
|
|
24
25
|
/** Credential resolvers keyed by auth scheme name. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-operations-app.js","sourceRoot":"","sources":["../../src/runtime/create-operations-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAgB,MAAM,MAAM,CAAC;AAG1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,4BAA4B,EAAE,WAAW,EAAsB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-operations-app.js","sourceRoot":"","sources":["../../src/runtime/create-operations-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAgB,MAAM,MAAM,CAAC;AAG1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,4BAA4B,EAAE,WAAW,EAAsB,MAAM,gBAAgB,CAAC;AA+C/F,SAAS,mBAAmB,CAC1B,CAAU,EACV,SAAiC,EACjC,SAA+E,EAC/E,IAAa,EACb,OAAgB;IAEhB,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/E,MAAM,cAAc,GAAG,CAAC,MAAc,EAAQ,EAAE;QAC9C,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAClC,MAAM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AAM,GAAG,GAAG,mBAAmB,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;gBACxE,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBAC5C,IAAI,CAAC,CAAC,MAAM,YAAY,QAAQ,CAAC,EAAE,CAAC;oBAClC,MAAM,IAAI,SAAS,CACjB,GAAG,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,SAAS,CAAC,IAAI,4DAA4D,CAChH,CAAC;gBACJ,CAAC;gBACD,OAAO,MAAM,CAAC;YAChB,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACxB,IAAI,KAAK,YAAY,cAAc;oBAAE,OAAO,KAAK,CAAC,UAAU,EAAE,CAAC;gBAC/D,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;oBACpB,IAAI,CAAC;wBACH,MAAM,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;oBAClC,CAAC;oBAAC,MAAM,CAAC;wBACP,8CAA8C;oBAChD,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,KAAK,CACX,wBAAwB,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,SAAS,CAAC,IAAI,UAAU,EAClF,KAAK,CACN,CAAC;gBACJ,CAAC;gBACD,OAAO,YAAY,CAAC,GAAG,EAAE;oBACvB,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,qBAAqB,CAAC,QAAQ;oBACrC,OAAO,EAAE,uBAAuB;iBACjC,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { createOperationsApp } from "./create-operations-app";
|
|
2
2
|
export type { CreateOperationsAppOptions, OpenApiDocumentRouteOptions, } from "./create-operations-app";
|
|
3
|
+
export { createOperationsAppFactory } from "./create-operations-app-factory";
|
|
4
|
+
export type { CreateOperationsAppFactoryOptions, OperationsAppFactory, OperationsAppFactoryAppOptions, } from "./create-operations-app-factory";
|
|
3
5
|
export { OperationError, OPERATION_ERROR_CODES, jsonResponse } from "./errors";
|
|
4
6
|
export type { OperationErrorBody, OperationValidationIssue } from "./errors";
|
|
5
7
|
export { resolveAuth, grantedScopes, missingScopes } from "./resolve-auth";
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createOperationsApp } from "./create-operations-app";
|
|
2
|
+
export { createOperationsAppFactory } from "./create-operations-app-factory";
|
|
2
3
|
export { OperationError, OPERATION_ERROR_CODES, jsonResponse } from "./errors";
|
|
3
4
|
export { resolveAuth, grantedScopes, missingScopes } from "./resolve-auth";
|
|
4
5
|
export { validateRequest, queryToObject, headersToObject, readRequestBody } from "./validate-request";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAK9D,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE/E,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAK9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAM7E,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE/E,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schemavaults/openapi-operations",
|
|
3
3
|
"description": "Define OpenAPI-representable HTTP operations (zod schemas + auth schemes + handlers) and serve them as Hono apps on Vercel functions / Next.js route handlers",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"private": false,
|
|
7
7
|
"repository": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"types": "dist/index.d.ts",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@asteasolutions/zod-to-openapi": "9.1.0",
|
|
18
|
-
"@schemavaults/auth-common": "0.
|
|
18
|
+
"@schemavaults/auth-common": "0.28.0",
|
|
19
19
|
"hono": "4.13.7",
|
|
20
20
|
"openapi3-ts": "4.6.1",
|
|
21
21
|
"zod": "4.4.3"
|