@hypequery/serve 0.0.2 → 0.0.4
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 +201 -0
- package/package.json +10 -10
- package/dist/adapters/fetch.d.ts +0 -3
- package/dist/adapters/fetch.d.ts.map +0 -1
- package/dist/adapters/fetch.js +0 -26
- package/dist/adapters/node.d.ts +0 -8
- package/dist/adapters/node.d.ts.map +0 -1
- package/dist/adapters/node.js +0 -105
- package/dist/adapters/utils.d.ts +0 -39
- package/dist/adapters/utils.d.ts.map +0 -1
- package/dist/adapters/utils.js +0 -114
- package/dist/adapters/vercel.d.ts +0 -7
- package/dist/adapters/vercel.d.ts.map +0 -1
- package/dist/adapters/vercel.js +0 -13
- package/dist/auth.d.ts +0 -14
- package/dist/auth.d.ts.map +0 -1
- package/dist/auth.js +0 -37
- package/dist/client-config.d.ts +0 -44
- package/dist/client-config.d.ts.map +0 -1
- package/dist/client-config.js +0 -53
- package/dist/dev.d.ts +0 -9
- package/dist/dev.d.ts.map +0 -1
- package/dist/dev.js +0 -24
- package/dist/docs-ui.d.ts +0 -3
- package/dist/docs-ui.d.ts.map +0 -1
- package/dist/docs-ui.js +0 -34
- package/dist/endpoint.d.ts +0 -5
- package/dist/endpoint.d.ts.map +0 -1
- package/dist/endpoint.js +0 -59
- package/dist/index.d.ts +0 -13
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -12
- package/dist/openapi.d.ts +0 -3
- package/dist/openapi.d.ts.map +0 -1
- package/dist/openapi.js +0 -189
- package/dist/queries.d.ts +0 -3
- package/dist/queries.d.ts.map +0 -1
- package/dist/queries.js +0 -1
- package/dist/query.d.ts +0 -4
- package/dist/query.d.ts.map +0 -1
- package/dist/query.js +0 -1
- package/dist/router.d.ts +0 -13
- package/dist/router.d.ts.map +0 -1
- package/dist/router.js +0 -56
- package/dist/sdk-generator.d.ts +0 -7
- package/dist/sdk-generator.d.ts.map +0 -1
- package/dist/sdk-generator.js +0 -143
- package/dist/server.d.ts +0 -9
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -584
- package/dist/tenant.d.ts +0 -35
- package/dist/tenant.d.ts.map +0 -1
- package/dist/tenant.js +0 -49
- package/dist/type-tests/builder.test-d.d.ts +0 -13
- package/dist/type-tests/builder.test-d.d.ts.map +0 -1
- package/dist/type-tests/builder.test-d.js +0 -20
- package/dist/types.d.ts +0 -373
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -1
package/dist/client-config.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { ServeBuilder, HttpMethod, AuthContext } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Configuration for a single query's client-side behavior
|
|
4
|
-
*/
|
|
5
|
-
export interface QueryClientConfig {
|
|
6
|
-
method: HttpMethod;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Map of query names to their client configurations
|
|
10
|
-
*/
|
|
11
|
-
export type ApiClientConfig = Record<string, QueryClientConfig>;
|
|
12
|
-
/**
|
|
13
|
-
* Extract serializable client configuration from a ServeBuilder.
|
|
14
|
-
* This generates a runtime object that can be used client-side to configure
|
|
15
|
-
* HTTP methods and paths for each query.
|
|
16
|
-
*
|
|
17
|
-
* Prioritizes route-level method configuration over endpoint defaults.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* // Server-side (e.g., in api/config/route.ts)
|
|
21
|
-
* import { api } from '@/analytics/queries';
|
|
22
|
-
* import { extractClientConfig } from '@hypequery/serve';
|
|
23
|
-
*
|
|
24
|
-
* export async function GET() {
|
|
25
|
-
* return Response.json(extractClientConfig(api));
|
|
26
|
-
* }
|
|
27
|
-
*
|
|
28
|
-
* // Client-side
|
|
29
|
-
* const config = await fetch('/api/config').then(r => r.json());
|
|
30
|
-
* createHooks<Api>({ baseUrl: '/api/hypequery', config });
|
|
31
|
-
*/
|
|
32
|
-
export declare function extractClientConfig<TQueries extends Record<string, any>, TContext extends Record<string, unknown>, TAuth extends AuthContext>(api: ServeBuilder<TQueries, TContext, TAuth>): ApiClientConfig;
|
|
33
|
-
/**
|
|
34
|
-
* Type-safe helper to manually define client configuration.
|
|
35
|
-
* Use this when you can't access the api object client-side.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* const config = defineClientConfig({
|
|
39
|
-
* hello: { method: 'GET' },
|
|
40
|
-
* createUser: { method: 'POST' },
|
|
41
|
-
* });
|
|
42
|
-
*/
|
|
43
|
-
export declare function defineClientConfig<T extends ApiClientConfig>(config: T): T;
|
|
44
|
-
//# sourceMappingURL=client-config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client-config.d.ts","sourceRoot":"","sources":["../src/client-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,UAAU,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACpC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,KAAK,SAAS,WAAW,EACzB,GAAG,EAAE,YAAY,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,eAAe,CAoB/D;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,eAAe,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAE1E"}
|
package/dist/client-config.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extract serializable client configuration from a ServeBuilder.
|
|
3
|
-
* This generates a runtime object that can be used client-side to configure
|
|
4
|
-
* HTTP methods and paths for each query.
|
|
5
|
-
*
|
|
6
|
-
* Prioritizes route-level method configuration over endpoint defaults.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* // Server-side (e.g., in api/config/route.ts)
|
|
10
|
-
* import { api } from '@/analytics/queries';
|
|
11
|
-
* import { extractClientConfig } from '@hypequery/serve';
|
|
12
|
-
*
|
|
13
|
-
* export async function GET() {
|
|
14
|
-
* return Response.json(extractClientConfig(api));
|
|
15
|
-
* }
|
|
16
|
-
*
|
|
17
|
-
* // Client-side
|
|
18
|
-
* const config = await fetch('/api/config').then(r => r.json());
|
|
19
|
-
* createHooks<Api>({ baseUrl: '/api/hypequery', config });
|
|
20
|
-
*/
|
|
21
|
-
export function extractClientConfig(api) {
|
|
22
|
-
const config = {};
|
|
23
|
-
// Prefer route-level config if available
|
|
24
|
-
if (api._routeConfig) {
|
|
25
|
-
for (const [key, routeConfig] of Object.entries(api._routeConfig)) {
|
|
26
|
-
config[key] = {
|
|
27
|
-
method: routeConfig.method,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
// Fallback to endpoint method
|
|
33
|
-
for (const [key, endpoint] of Object.entries(api.queries)) {
|
|
34
|
-
config[key] = {
|
|
35
|
-
method: endpoint.method,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return config;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Type-safe helper to manually define client configuration.
|
|
43
|
-
* Use this when you can't access the api object client-side.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* const config = defineClientConfig({
|
|
47
|
-
* hello: { method: 'GET' },
|
|
48
|
-
* createUser: { method: 'POST' },
|
|
49
|
-
* });
|
|
50
|
-
*/
|
|
51
|
-
export function defineClientConfig(config) {
|
|
52
|
-
return config;
|
|
53
|
-
}
|
package/dist/dev.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ServeBuilder, StartServerOptions } from "./types.js";
|
|
2
|
-
export interface ServeDevOptions extends StartServerOptions {
|
|
3
|
-
logger?: (message: string) => void;
|
|
4
|
-
}
|
|
5
|
-
export declare const serveDev: <TQueries extends Record<string, any>, TAuth extends Record<string, unknown>>(api: ServeBuilder<TQueries, TAuth>, options?: ServeDevOptions) => Promise<{
|
|
6
|
-
server: import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
|
|
7
|
-
stop: () => Promise<void>;
|
|
8
|
-
}>;
|
|
9
|
-
//# sourceMappingURL=dev.d.ts.map
|
package/dist/dev.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../src/dev.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEnE,MAAM,WAAW,eAAgB,SAAQ,kBAAkB;IACzD,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAMD,eAAO,MAAM,QAAQ,GACnB,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACpC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAErC,KAAK,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,EAClC,UAAS,eAAoB;;;EAwB9B,CAAC"}
|
package/dist/dev.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { startNodeServer } from "./adapters/node.js";
|
|
2
|
-
const defaultLogger = (message) => {
|
|
3
|
-
console.log(message);
|
|
4
|
-
};
|
|
5
|
-
export const serveDev = async (api, options = {}) => {
|
|
6
|
-
const port = options.port ?? Number(process.env.PORT ?? 4000);
|
|
7
|
-
const hostname = options.hostname ?? "localhost";
|
|
8
|
-
const logger = options.logger ?? defaultLogger;
|
|
9
|
-
const server = await startNodeServer(api.handler, {
|
|
10
|
-
...options,
|
|
11
|
-
hostname,
|
|
12
|
-
port,
|
|
13
|
-
quiet: true,
|
|
14
|
-
});
|
|
15
|
-
if (!options.quiet) {
|
|
16
|
-
const address = server.server.address();
|
|
17
|
-
const display = typeof address === "object" && address
|
|
18
|
-
? `${address.address}:${address.port}`
|
|
19
|
-
: `${hostname}:${port}`;
|
|
20
|
-
logger(`hypequery dev server running at http://${display}`);
|
|
21
|
-
logger(`Docs available at http://${display}/docs`);
|
|
22
|
-
}
|
|
23
|
-
return server;
|
|
24
|
-
};
|
package/dist/docs-ui.d.ts
DELETED
package/dist/docs-ui.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"docs-ui.d.ts","sourceRoot":"","sources":["../src/docs-ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAO9C,eAAO,MAAM,aAAa,GAAI,YAAY,MAAM,EAAE,UAAU,WAAW,WAgCtE,CAAC"}
|
package/dist/docs-ui.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
const REDOC_CDN = "https://cdn.jsdelivr.net/npm/redoc@latest/bundles/redoc.standalone.js";
|
|
2
|
-
const sanitize = (value, fallback = "") => (value ?? fallback).replace(/</g, "<").replace(/>/g, ">");
|
|
3
|
-
export const buildDocsHtml = (openapiUrl, options) => {
|
|
4
|
-
const title = sanitize(options?.title, "hypequery");
|
|
5
|
-
const subtitle = sanitize(options?.subtitle);
|
|
6
|
-
const darkClass = options?.darkMode ? "hq-docs--dark" : "";
|
|
7
|
-
return `<!DOCTYPE html>
|
|
8
|
-
<html lang="en">
|
|
9
|
-
<head>
|
|
10
|
-
<meta charset="utf-8" />
|
|
11
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
12
|
-
<title>${title}</title>
|
|
13
|
-
<style>
|
|
14
|
-
body, html { margin: 0; padding: 0; height: 100%; font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
|
|
15
|
-
.hq-docs { display: flex; flex-direction: column; height: 100%; }
|
|
16
|
-
.hq-docs__header { padding: 1.25rem 1.5rem; border-bottom: 1px solid rgba(0,0,0,0.08); }
|
|
17
|
-
.hq-docs--dark .hq-docs__header { border-color: rgba(255,255,255,0.12); }
|
|
18
|
-
.hq-docs__title { margin: 0; font-size: 1.25rem; }
|
|
19
|
-
.hq-docs__subtitle { margin: 0.25rem 0 0; color: #555; }
|
|
20
|
-
.hq-docs--dark { background: #0f1115; color: #f8f8f2; }
|
|
21
|
-
.hq-docs--dark .hq-docs__subtitle { color: #b4b6c2; }
|
|
22
|
-
redoc { flex: 1; }
|
|
23
|
-
</style>
|
|
24
|
-
</head>
|
|
25
|
-
<body class="hq-docs ${darkClass}">
|
|
26
|
-
<header class="hq-docs__header">
|
|
27
|
-
<h1 class="hq-docs__title">${title}</h1>
|
|
28
|
-
${subtitle ? `<p class="hq-docs__subtitle">${subtitle}</p>` : ""}
|
|
29
|
-
</header>
|
|
30
|
-
<redoc spec-url="${openapiUrl}"></redoc>
|
|
31
|
-
<script src="${REDOC_CDN}"></script>
|
|
32
|
-
</body>
|
|
33
|
-
</html>`;
|
|
34
|
-
};
|
package/dist/endpoint.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { AuthContext, ServeEndpoint, ServeQueryConfig } from "./types.js";
|
|
2
|
-
type EndpointFromDefinition<TDefinition extends ServeQueryConfig<any, any, TContext, TAuth, any>, TContext extends Record<string, unknown>, TAuth extends AuthContext> = TDefinition extends ServeQueryConfig<infer TInputSchema, infer TOutputSchema, TContext, TAuth, infer TResult> ? ServeEndpoint<TInputSchema, TOutputSchema, TContext, TAuth, TResult> : ServeEndpoint<any, any, TContext, TAuth>;
|
|
3
|
-
export declare const createEndpoint: <TContext extends Record<string, unknown>, TAuth extends AuthContext, TDefinition extends ServeQueryConfig<any, any, TContext, TAuth, any>>(key: string, definition: TDefinition) => EndpointFromDefinition<TDefinition, TContext, TAuth>;
|
|
4
|
-
export {};
|
|
5
|
-
//# sourceMappingURL=endpoint.d.ts.map
|
package/dist/endpoint.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../src/endpoint.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,WAAW,EAUX,aAAa,EACb,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAIpB,KAAK,sBAAsB,CACzB,WAAW,SAAS,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,CAAC,EACpE,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,KAAK,SAAS,WAAW,IACvB,WAAW,SAAS,gBAAgB,CACtC,MAAM,YAAY,EAClB,MAAM,aAAa,EACnB,QAAQ,EACR,KAAK,EACL,MAAM,OAAO,CACd,GACG,aAAa,CAAC,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,GACpE,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;AA8B7C,eAAO,MAAM,cAAc,GACzB,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,KAAK,SAAS,WAAW,EACzB,WAAW,SAAS,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,CAAC,EAEpE,KAAK,MAAM,EACX,YAAY,WAAW,KACtB,sBAAsB,CAAC,WAAW,EAAE,QAAQ,EAAE,KAAK,CAsDrD,CAAC"}
|
package/dist/endpoint.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
const fallbackSchema = z.any();
|
|
3
|
-
const resolveQueryRunner = (query) => {
|
|
4
|
-
if (!query) {
|
|
5
|
-
return null;
|
|
6
|
-
}
|
|
7
|
-
const fn = typeof query === "function"
|
|
8
|
-
? query
|
|
9
|
-
: typeof query === "object" && typeof query.run === "function"
|
|
10
|
-
? query.run.bind(query)
|
|
11
|
-
: null;
|
|
12
|
-
if (!fn) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
return async (args) => {
|
|
16
|
-
return fn(args);
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export const createEndpoint = (key, definition) => {
|
|
20
|
-
const method = definition.method ?? "GET";
|
|
21
|
-
const metadata = {
|
|
22
|
-
path: "",
|
|
23
|
-
method: method,
|
|
24
|
-
name: definition.name ?? definition.summary ?? key,
|
|
25
|
-
summary: definition.summary,
|
|
26
|
-
description: definition.description,
|
|
27
|
-
tags: definition.tags ?? [],
|
|
28
|
-
requiresAuth: definition.auth ? true : undefined,
|
|
29
|
-
deprecated: undefined,
|
|
30
|
-
visibility: "public",
|
|
31
|
-
custom: definition.custom,
|
|
32
|
-
};
|
|
33
|
-
const runner = resolveQueryRunner(definition.query);
|
|
34
|
-
const handler = async (ctx) => {
|
|
35
|
-
if (!runner) {
|
|
36
|
-
throw new Error(`Endpoint "${key}" is missing an executable query`);
|
|
37
|
-
}
|
|
38
|
-
return runner({
|
|
39
|
-
input: ctx.input,
|
|
40
|
-
ctx: ctx,
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
const outputSchema = (definition.outputSchema ?? fallbackSchema);
|
|
44
|
-
const inputSchema = definition.inputSchema;
|
|
45
|
-
return {
|
|
46
|
-
key,
|
|
47
|
-
method,
|
|
48
|
-
inputSchema,
|
|
49
|
-
outputSchema,
|
|
50
|
-
handler,
|
|
51
|
-
query: definition.query,
|
|
52
|
-
middlewares: definition.middlewares ?? [],
|
|
53
|
-
auth: definition.auth ?? null,
|
|
54
|
-
tenant: definition.tenant,
|
|
55
|
-
metadata,
|
|
56
|
-
cacheTtlMs: definition.cacheTtlMs ?? null,
|
|
57
|
-
defaultHeaders: undefined,
|
|
58
|
-
};
|
|
59
|
-
};
|
package/dist/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export * from "./types.js";
|
|
2
|
-
export * from "./server.js";
|
|
3
|
-
export * from "./router.js";
|
|
4
|
-
export * from "./endpoint.js";
|
|
5
|
-
export * from "./openapi.js";
|
|
6
|
-
export * from "./docs-ui.js";
|
|
7
|
-
export * from "./auth.js";
|
|
8
|
-
export * from "./client-config.js";
|
|
9
|
-
export * from "./adapters/node.js";
|
|
10
|
-
export * from "./adapters/fetch.js";
|
|
11
|
-
export * from "./adapters/vercel.js";
|
|
12
|
-
export * from "./dev.js";
|
|
13
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,UAAU,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from "./types.js";
|
|
2
|
-
export * from "./server.js";
|
|
3
|
-
export * from "./router.js";
|
|
4
|
-
export * from "./endpoint.js";
|
|
5
|
-
export * from "./openapi.js";
|
|
6
|
-
export * from "./docs-ui.js";
|
|
7
|
-
export * from "./auth.js";
|
|
8
|
-
export * from "./client-config.js";
|
|
9
|
-
export * from "./adapters/node.js";
|
|
10
|
-
export * from "./adapters/fetch.js";
|
|
11
|
-
export * from "./adapters/vercel.js";
|
|
12
|
-
export * from "./dev.js";
|
package/dist/openapi.d.ts
DELETED
package/dist/openapi.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../src/openapi.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAqLjF,eAAO,MAAM,oBAAoB,GAC/B,WAAW,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,EAC9C,UAAU,cAAc,KACvB,eAyCF,CAAC"}
|
package/dist/openapi.js
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
|
-
const ERROR_SCHEMA = {
|
|
3
|
-
type: "object",
|
|
4
|
-
properties: {
|
|
5
|
-
error: {
|
|
6
|
-
type: "object",
|
|
7
|
-
properties: {
|
|
8
|
-
type: { type: "string" },
|
|
9
|
-
message: { type: "string" },
|
|
10
|
-
details: { type: "object" },
|
|
11
|
-
},
|
|
12
|
-
required: ["type", "message"],
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
required: ["error"],
|
|
16
|
-
};
|
|
17
|
-
const dereferenceSchema = (schema) => {
|
|
18
|
-
if (!schema || typeof schema !== "object") {
|
|
19
|
-
return schema;
|
|
20
|
-
}
|
|
21
|
-
if (schema.$ref && schema.definitions) {
|
|
22
|
-
const refKey = String(schema.$ref).split("/").pop();
|
|
23
|
-
if (refKey && schema.definitions[refKey]) {
|
|
24
|
-
return schema.definitions[refKey];
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return schema;
|
|
28
|
-
};
|
|
29
|
-
const removeDefinitions = (schema) => {
|
|
30
|
-
if (!schema || typeof schema !== "object") {
|
|
31
|
-
return schema;
|
|
32
|
-
}
|
|
33
|
-
// Handle arrays
|
|
34
|
-
if (Array.isArray(schema)) {
|
|
35
|
-
return schema.map(item => removeDefinitions(item));
|
|
36
|
-
}
|
|
37
|
-
// If this schema has a $ref and definitions, inline the definition
|
|
38
|
-
if (schema.$ref && schema.definitions) {
|
|
39
|
-
const refKey = String(schema.$ref).split("/").pop();
|
|
40
|
-
if (refKey && schema.definitions[refKey]) {
|
|
41
|
-
const resolved = schema.definitions[refKey];
|
|
42
|
-
delete schema.$ref;
|
|
43
|
-
delete schema.definitions;
|
|
44
|
-
return removeDefinitions({ ...schema, ...resolved });
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
// Remove definitions property if it exists
|
|
48
|
-
const { definitions: _definitions, $ref: _ref, ...rest } = schema;
|
|
49
|
-
// Recursively clean nested objects and arrays
|
|
50
|
-
const result = {};
|
|
51
|
-
for (const [key, value] of Object.entries(rest)) {
|
|
52
|
-
if (Array.isArray(value)) {
|
|
53
|
-
result[key] = value.map(item => typeof item === "object" && item !== null ? removeDefinitions(item) : item);
|
|
54
|
-
}
|
|
55
|
-
else if (typeof value === "object" && value !== null) {
|
|
56
|
-
result[key] = removeDefinitions(value);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
result[key] = value;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return result;
|
|
63
|
-
};
|
|
64
|
-
const toJsonSchema = (schema, name) => {
|
|
65
|
-
if (!schema) {
|
|
66
|
-
return { type: "object" };
|
|
67
|
-
}
|
|
68
|
-
const jsonSchema = zodToJsonSchema(schema, {
|
|
69
|
-
target: "openApi3",
|
|
70
|
-
name,
|
|
71
|
-
$refStrategy: "none",
|
|
72
|
-
});
|
|
73
|
-
return removeDefinitions(jsonSchema);
|
|
74
|
-
};
|
|
75
|
-
const toQueryParameters = (schema, name) => {
|
|
76
|
-
if (!schema) {
|
|
77
|
-
return [];
|
|
78
|
-
}
|
|
79
|
-
const jsonSchema = dereferenceSchema(toJsonSchema(schema, name));
|
|
80
|
-
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
81
|
-
return [];
|
|
82
|
-
}
|
|
83
|
-
const schemaType = jsonSchema.type;
|
|
84
|
-
const isObjectType = schemaType === "object" || (Array.isArray(schemaType) && schemaType.includes("object"));
|
|
85
|
-
if (!isObjectType || typeof jsonSchema.properties !== "object") {
|
|
86
|
-
return [];
|
|
87
|
-
}
|
|
88
|
-
const properties = jsonSchema.properties;
|
|
89
|
-
const requiredSet = new Set(Array.isArray(jsonSchema.required) ? jsonSchema.required : []);
|
|
90
|
-
return Object.entries(properties).map(([key, value]) => ({
|
|
91
|
-
name: key,
|
|
92
|
-
in: "query",
|
|
93
|
-
required: requiredSet.has(key),
|
|
94
|
-
schema: value,
|
|
95
|
-
}));
|
|
96
|
-
};
|
|
97
|
-
const toOperation = (endpoint, nameSuffix) => {
|
|
98
|
-
const operation = {
|
|
99
|
-
operationId: endpoint.key,
|
|
100
|
-
summary: endpoint.metadata.summary,
|
|
101
|
-
description: endpoint.metadata.description,
|
|
102
|
-
tags: endpoint.metadata.tags.length ? endpoint.metadata.tags : undefined,
|
|
103
|
-
responses: {
|
|
104
|
-
200: {
|
|
105
|
-
description: "Successful response",
|
|
106
|
-
content: {
|
|
107
|
-
"application/json": {
|
|
108
|
-
schema: toJsonSchema(endpoint.outputSchema, `${endpoint.key}${nameSuffix}`),
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
default: {
|
|
113
|
-
description: "Error response",
|
|
114
|
-
content: {
|
|
115
|
-
"application/json": {
|
|
116
|
-
schema: ERROR_SCHEMA,
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
const queryParameters = endpoint.method === "GET"
|
|
123
|
-
? toQueryParameters(endpoint.inputSchema, `${endpoint.key}Query`)
|
|
124
|
-
: [];
|
|
125
|
-
if (queryParameters.length > 0) {
|
|
126
|
-
operation.parameters = queryParameters;
|
|
127
|
-
}
|
|
128
|
-
else if (endpoint.inputSchema) {
|
|
129
|
-
operation.requestBody = {
|
|
130
|
-
required: true,
|
|
131
|
-
content: {
|
|
132
|
-
"application/json": {
|
|
133
|
-
schema: toJsonSchema(endpoint.inputSchema, `${endpoint.key}Request`),
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
if (endpoint.metadata.requiresAuth) {
|
|
139
|
-
operation.security = [{ ApiKeyAuth: [] }];
|
|
140
|
-
}
|
|
141
|
-
return operation;
|
|
142
|
-
};
|
|
143
|
-
const normalizeInfo = (options) => {
|
|
144
|
-
const info = options?.info;
|
|
145
|
-
return {
|
|
146
|
-
title: info?.title ?? "hypequery API",
|
|
147
|
-
version: options?.version ?? "1.0.0",
|
|
148
|
-
description: info?.description,
|
|
149
|
-
termsOfService: info?.termsOfService,
|
|
150
|
-
contact: info?.contact,
|
|
151
|
-
license: info?.license,
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
export const buildOpenApiDocument = (endpoints, options) => {
|
|
155
|
-
var _a;
|
|
156
|
-
const document = {
|
|
157
|
-
openapi: "3.1.0",
|
|
158
|
-
info: normalizeInfo(options),
|
|
159
|
-
servers: options?.servers ?? [],
|
|
160
|
-
paths: {},
|
|
161
|
-
};
|
|
162
|
-
let needsSecurityScheme = false;
|
|
163
|
-
for (const endpoint of endpoints) {
|
|
164
|
-
if (endpoint.metadata.visibility && endpoint.metadata.visibility !== "public") {
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
const path = endpoint.metadata.path || "/";
|
|
168
|
-
const method = endpoint.method.toLowerCase();
|
|
169
|
-
const pathItem = ((_a = document.paths)[path] ?? (_a[path] = {}));
|
|
170
|
-
const operation = toOperation(endpoint, "Response");
|
|
171
|
-
if (endpoint.metadata.requiresAuth) {
|
|
172
|
-
needsSecurityScheme = true;
|
|
173
|
-
}
|
|
174
|
-
pathItem[method] = operation;
|
|
175
|
-
}
|
|
176
|
-
if (needsSecurityScheme) {
|
|
177
|
-
document.components = {
|
|
178
|
-
...(document.components ?? {}),
|
|
179
|
-
securitySchemes: {
|
|
180
|
-
ApiKeyAuth: {
|
|
181
|
-
type: "apiKey",
|
|
182
|
-
name: "Authorization",
|
|
183
|
-
in: "header",
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
return document;
|
|
189
|
-
};
|
package/dist/queries.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { AuthContext, ServeQueriesMap } from "./types.js";
|
|
2
|
-
export declare const defineQueries: <TContext extends Record<string, unknown> = Record<string, unknown>, TAuth extends AuthContext = AuthContext, const TQueries extends ServeQueriesMap<TContext, TAuth> = ServeQueriesMap<TContext, TAuth>>(queries: TQueries) => TQueries;
|
|
3
|
-
//# sourceMappingURL=queries.d.ts.map
|
package/dist/queries.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE/D,eAAO,MAAM,aAAa,GACxB,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClE,KAAK,SAAS,WAAW,GAAG,WAAW,EACvC,KAAK,CAAC,QAAQ,SAAS,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,EAE1F,SAAS,QAAQ,KAChB,QAAmB,CAAC"}
|
package/dist/queries.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const defineQueries = (queries) => queries;
|
package/dist/query.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { ZodTypeAny } from "zod";
|
|
2
|
-
import type { AuthContext, SchemaOutput, ServeQueryConfig } from "./types.js";
|
|
3
|
-
export declare const defineQuery: <TInputSchema extends ZodTypeAny | undefined = undefined, TOutputSchema extends ZodTypeAny = ZodTypeAny, TContext extends Record<string, unknown> = Record<string, unknown>, TAuth extends AuthContext = AuthContext, TResult = SchemaOutput<TOutputSchema>>(definition: ServeQueryConfig<TInputSchema, TOutputSchema, TContext, TAuth, TResult>) => ServeQueryConfig<TInputSchema, TOutputSchema, TContext, TAuth, TResult>;
|
|
4
|
-
//# sourceMappingURL=query.d.ts.map
|
package/dist/query.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAEtC,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9E,eAAO,MAAM,WAAW,GACtB,YAAY,SAAS,UAAU,GAAG,SAAS,GAAG,SAAS,EACvD,aAAa,SAAS,UAAU,GAAG,UAAU,EAC7C,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClE,KAAK,SAAS,WAAW,GAAG,WAAW,EACvC,OAAO,GAAG,YAAY,CAAC,aAAa,CAAC,EAErC,YAAY,gBAAgB,CAAC,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,KAClF,gBAAgB,CAAC,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAe,CAAC"}
|
package/dist/query.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const defineQuery = (definition) => definition;
|
package/dist/router.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { EndpointRegistry, HttpMethod, ServeEndpoint } from "./types.js";
|
|
2
|
-
export declare const normalizeRoutePath: (path: string) => string;
|
|
3
|
-
export declare const applyBasePath: (basePath: string, path: string) => string;
|
|
4
|
-
export declare class ServeRouter implements EndpointRegistry {
|
|
5
|
-
private readonly basePath;
|
|
6
|
-
private routes;
|
|
7
|
-
constructor(basePath?: string);
|
|
8
|
-
list(): ServeEndpoint<any, any, any, any, any>[];
|
|
9
|
-
register(endpoint: ServeEndpoint<any, any, any, any>): void;
|
|
10
|
-
match(method: HttpMethod, path: string): ServeEndpoint<any, any, any, any, any> | null;
|
|
11
|
-
markRoutesRequireAuth(): void;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=router.d.ts.map
|
package/dist/router.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAI9E,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,WAG9C,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,UAAU,MAAM,EAAE,MAAM,MAAM,WAM3D,CAAC;AAEF,qBAAa,WAAY,YAAW,gBAAgB;IAGtC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAFrC,OAAO,CAAC,MAAM,CAA2C;gBAE5B,QAAQ,SAAK;IAE1C,IAAI;IAIJ,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IAuBpD,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM;IAStC,qBAAqB;CAetB"}
|
package/dist/router.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const trimSlashes = (value) => value.replace(/^\/+|\/+$/g, "");
|
|
2
|
-
export const normalizeRoutePath = (path) => {
|
|
3
|
-
const trimmed = trimSlashes(path || "/");
|
|
4
|
-
return `/${trimmed}`.replace(/\/+/g, "/").replace(/\/$/, trimmed ? "" : "/");
|
|
5
|
-
};
|
|
6
|
-
export const applyBasePath = (basePath, path) => {
|
|
7
|
-
const parts = [trimSlashes(basePath ?? ""), trimSlashes(path)]
|
|
8
|
-
.filter(Boolean)
|
|
9
|
-
.join("/");
|
|
10
|
-
const combined = parts ? `/${parts}` : "/";
|
|
11
|
-
return combined.replace(/\/+/g, "/").replace(/\/$/, combined === "/" ? "/" : "");
|
|
12
|
-
};
|
|
13
|
-
export class ServeRouter {
|
|
14
|
-
constructor(basePath = "") {
|
|
15
|
-
this.basePath = basePath;
|
|
16
|
-
this.routes = [];
|
|
17
|
-
}
|
|
18
|
-
list() {
|
|
19
|
-
return [...this.routes];
|
|
20
|
-
}
|
|
21
|
-
register(endpoint) {
|
|
22
|
-
const path = endpoint.metadata.path || "/";
|
|
23
|
-
const normalizedPath = applyBasePath(this.basePath, path);
|
|
24
|
-
const method = endpoint.method;
|
|
25
|
-
const existing = this.routes.find((route) => route.metadata.path === normalizedPath && route.method === method);
|
|
26
|
-
if (existing) {
|
|
27
|
-
throw new Error(`Route already registered for ${method} ${normalizedPath}`);
|
|
28
|
-
}
|
|
29
|
-
this.routes.push({
|
|
30
|
-
...endpoint,
|
|
31
|
-
metadata: {
|
|
32
|
-
...endpoint.metadata,
|
|
33
|
-
path: normalizedPath,
|
|
34
|
-
method,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
match(method, path) {
|
|
39
|
-
const normalizedPath = normalizeRoutePath(path);
|
|
40
|
-
return (this.routes.find((route) => route.method === method && route.metadata.path === normalizedPath) ?? null);
|
|
41
|
-
}
|
|
42
|
-
markRoutesRequireAuth() {
|
|
43
|
-
this.routes = this.routes.map((route) => {
|
|
44
|
-
if (route.metadata.requiresAuth === false) {
|
|
45
|
-
return route;
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
...route,
|
|
49
|
-
metadata: {
|
|
50
|
-
...route.metadata,
|
|
51
|
-
requiresAuth: true,
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
package/dist/sdk-generator.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sdk-generator.d.ts","sourceRoot":"","sources":["../src/sdk-generator.ts"],"names":[],"mappings":"AAuHA,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAuBD,eAAO,MAAM,iBAAiB,GAAU,SAAS,kBAAkB,kBAalE,CAAC"}
|