yaxa-svelte 2.1.0 → 2.3.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 +73 -14
- package/dist/server/endpoint/endpoint.test.d.ts +1 -0
- package/dist/server/endpoint/endpoint.test.js +364 -0
- package/dist/server/endpoint/guards.d.ts +57 -0
- package/dist/server/endpoint/guards.js +153 -0
- package/dist/server/endpoint/index.d.ts +14 -0
- package/dist/server/endpoint/index.js +242 -0
- package/dist/server/endpoint/problem.d.ts +26 -0
- package/dist/server/endpoint/problem.js +62 -0
- package/dist/server/endpoint/types.d.ts +151 -0
- package/dist/server/endpoint/types.js +1 -0
- package/dist/server/endpoint/validate.d.ts +21 -0
- package/dist/server/endpoint/validate.js +128 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js +4 -0
- package/dist/server/openapi/generator.d.ts +5 -0
- package/dist/server/openapi/generator.js +317 -0
- package/dist/server/openapi/handler.d.ts +7 -0
- package/dist/server/openapi/handler.js +117 -0
- package/dist/server/openapi/index.d.ts +5 -0
- package/dist/server/openapi/index.js +4 -0
- package/dist/server/openapi/openapi.test.d.ts +1 -0
- package/dist/server/openapi/openapi.test.js +219 -0
- package/dist/server/openapi/registry.d.ts +35 -0
- package/dist/server/openapi/registry.js +51 -0
- package/dist/server/openapi/schema.d.ts +4 -0
- package/dist/server/openapi/schema.js +59 -0
- package/dist/server/openapi/types.d.ts +127 -0
- package/dist/server/openapi/types.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { EndpointLike, EndpointMap } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Route & Endpoint Registry for OpenAPI discovery and introspection.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ApiRegistry {
|
|
6
|
+
private endpoints;
|
|
7
|
+
/**
|
|
8
|
+
* Registers endpoints for a given path.
|
|
9
|
+
* @param path SvelteKit route path (e.g. '/api/projects' or '/api/projects/[id]')
|
|
10
|
+
* @param methods Map of HTTP methods to handlers or yaxaEndpoint configs
|
|
11
|
+
*/
|
|
12
|
+
register(path: string, methods: Record<string, EndpointLike>): this;
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves all registered endpoints.
|
|
15
|
+
*/
|
|
16
|
+
getEndpoints(): EndpointMap;
|
|
17
|
+
/**
|
|
18
|
+
* Clears registered endpoints (useful in testing).
|
|
19
|
+
*/
|
|
20
|
+
clear(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Normalizes SvelteKit path parameters to OpenAPI format:
|
|
23
|
+
* '/api/projects/[id]' -> '/api/projects/{id}'
|
|
24
|
+
* '/api/teams/[orgSlug]/members/[userId]' -> '/api/teams/{orgSlug}/members/{userId}'
|
|
25
|
+
*/
|
|
26
|
+
normalizePath(path: string): string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Global singleton API registry for zero-config route registration.
|
|
30
|
+
*/
|
|
31
|
+
export declare const globalApiRegistry: ApiRegistry;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new isolated API registry instance.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createApiRegistry(): ApiRegistry;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route & Endpoint Registry for OpenAPI discovery and introspection.
|
|
3
|
+
*/
|
|
4
|
+
export class ApiRegistry {
|
|
5
|
+
endpoints = {};
|
|
6
|
+
/**
|
|
7
|
+
* Registers endpoints for a given path.
|
|
8
|
+
* @param path SvelteKit route path (e.g. '/api/projects' or '/api/projects/[id]')
|
|
9
|
+
* @param methods Map of HTTP methods to handlers or yaxaEndpoint configs
|
|
10
|
+
*/
|
|
11
|
+
register(path, methods) {
|
|
12
|
+
const normalizedPath = this.normalizePath(path);
|
|
13
|
+
if (!this.endpoints[normalizedPath]) {
|
|
14
|
+
this.endpoints[normalizedPath] = {};
|
|
15
|
+
}
|
|
16
|
+
for (const [method, handler] of Object.entries(methods)) {
|
|
17
|
+
this.endpoints[normalizedPath][method.toUpperCase()] = handler;
|
|
18
|
+
}
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves all registered endpoints.
|
|
23
|
+
*/
|
|
24
|
+
getEndpoints() {
|
|
25
|
+
return this.endpoints;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Clears registered endpoints (useful in testing).
|
|
29
|
+
*/
|
|
30
|
+
clear() {
|
|
31
|
+
this.endpoints = {};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Normalizes SvelteKit path parameters to OpenAPI format:
|
|
35
|
+
* '/api/projects/[id]' -> '/api/projects/{id}'
|
|
36
|
+
* '/api/teams/[orgSlug]/members/[userId]' -> '/api/teams/{orgSlug}/members/{userId}'
|
|
37
|
+
*/
|
|
38
|
+
normalizePath(path) {
|
|
39
|
+
return path.replace(/\[\.\.\.(\w+)\]/g, '{$1}').replace(/\[(\w+)\]/g, '{$1}');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Global singleton API registry for zero-config route registration.
|
|
44
|
+
*/
|
|
45
|
+
export const globalApiRegistry = new ApiRegistry();
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new isolated API registry instance.
|
|
48
|
+
*/
|
|
49
|
+
export function createApiRegistry() {
|
|
50
|
+
return new ApiRegistry();
|
|
51
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a Zod or Standard Schema validator into a compliant OpenAPI 3.1 JSON Schema.
|
|
4
|
+
*/
|
|
5
|
+
export function convertToJsonSchema(validator) {
|
|
6
|
+
if (!validator) {
|
|
7
|
+
return { type: 'object' };
|
|
8
|
+
}
|
|
9
|
+
// 1. Zod native JSON schema converter
|
|
10
|
+
if (typeof z?.toJSONSchema === 'function') {
|
|
11
|
+
try {
|
|
12
|
+
const jsonSchema = z.toJSONSchema(validator);
|
|
13
|
+
if (jsonSchema && typeof jsonSchema === 'object') {
|
|
14
|
+
const cleanSchema = { ...jsonSchema };
|
|
15
|
+
delete cleanSchema.$schema;
|
|
16
|
+
return cleanSchema;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// Fall through to other strategies
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// 2. Check if validator has built-in jsonSchema method/property
|
|
24
|
+
if (typeof validator.jsonSchema === 'function') {
|
|
25
|
+
try {
|
|
26
|
+
const res = validator.jsonSchema();
|
|
27
|
+
const cleanSchema = { ...res };
|
|
28
|
+
delete cleanSchema.$schema;
|
|
29
|
+
return cleanSchema;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// Fall through
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (typeof validator.jsonSchema === 'object' && validator.jsonSchema !== null) {
|
|
36
|
+
const cleanSchema = { ...validator.jsonSchema };
|
|
37
|
+
delete cleanSchema.$schema;
|
|
38
|
+
return cleanSchema;
|
|
39
|
+
}
|
|
40
|
+
// 3. Heuristic for common object schema shapes
|
|
41
|
+
if (typeof validator === 'object' && validator !== null) {
|
|
42
|
+
if ('shape' in validator && typeof validator.shape === 'object') {
|
|
43
|
+
const properties = {};
|
|
44
|
+
const required = [];
|
|
45
|
+
for (const [key, val] of Object.entries(validator.shape)) {
|
|
46
|
+
properties[key] = convertToJsonSchema(val);
|
|
47
|
+
if (!val?.isOptional?.()) {
|
|
48
|
+
required.push(key);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
type: 'object',
|
|
53
|
+
properties,
|
|
54
|
+
...(required.length > 0 ? { required } : {})
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return { type: 'string' };
|
|
59
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { RequestHandler } from '@sveltejs/kit';
|
|
2
|
+
import type { YaxaEndpointConfig } from '../endpoint/types';
|
|
3
|
+
/**
|
|
4
|
+
* OpenAPI 3.1 Parameter Object
|
|
5
|
+
*/
|
|
6
|
+
export interface OpenApiParameter {
|
|
7
|
+
name: string;
|
|
8
|
+
in: 'query' | 'header' | 'path' | 'cookie';
|
|
9
|
+
description?: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
deprecated?: boolean;
|
|
12
|
+
schema?: Record<string, any>;
|
|
13
|
+
example?: any;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* OpenAPI 3.1 Request Body Object
|
|
17
|
+
*/
|
|
18
|
+
export interface OpenApiRequestBody {
|
|
19
|
+
description?: string;
|
|
20
|
+
required?: boolean;
|
|
21
|
+
content: {
|
|
22
|
+
[mediaType: string]: {
|
|
23
|
+
schema?: Record<string, any>;
|
|
24
|
+
example?: any;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* OpenAPI 3.1 Response Object
|
|
30
|
+
*/
|
|
31
|
+
export interface OpenApiResponse {
|
|
32
|
+
description: string;
|
|
33
|
+
headers?: Record<string, any>;
|
|
34
|
+
content?: {
|
|
35
|
+
[mediaType: string]: {
|
|
36
|
+
schema?: Record<string, any>;
|
|
37
|
+
example?: any;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* OpenAPI 3.1 Operation Object
|
|
43
|
+
*/
|
|
44
|
+
export interface OpenApiOperation {
|
|
45
|
+
summary?: string;
|
|
46
|
+
description?: string;
|
|
47
|
+
operationId?: string;
|
|
48
|
+
tags?: string[];
|
|
49
|
+
parameters?: OpenApiParameter[];
|
|
50
|
+
requestBody?: OpenApiRequestBody;
|
|
51
|
+
responses: Record<string, OpenApiResponse>;
|
|
52
|
+
deprecated?: boolean;
|
|
53
|
+
security?: Array<Record<string, string[]>>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* OpenAPI 3.1 Specification Object
|
|
57
|
+
*/
|
|
58
|
+
export interface OpenApiSpec31 {
|
|
59
|
+
openapi: '3.1.0';
|
|
60
|
+
info: {
|
|
61
|
+
title: string;
|
|
62
|
+
version: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
termsOfService?: string;
|
|
65
|
+
contact?: {
|
|
66
|
+
name?: string;
|
|
67
|
+
url?: string;
|
|
68
|
+
email?: string;
|
|
69
|
+
};
|
|
70
|
+
license?: {
|
|
71
|
+
name: string;
|
|
72
|
+
url?: string;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
servers?: Array<{
|
|
76
|
+
url: string;
|
|
77
|
+
description?: string;
|
|
78
|
+
}>;
|
|
79
|
+
paths: {
|
|
80
|
+
[path: string]: {
|
|
81
|
+
[method: string]: OpenApiOperation;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
components?: {
|
|
85
|
+
schemas?: Record<string, any>;
|
|
86
|
+
securitySchemes?: Record<string, any>;
|
|
87
|
+
responses?: Record<string, OpenApiResponse>;
|
|
88
|
+
parameters?: Record<string, OpenApiParameter>;
|
|
89
|
+
};
|
|
90
|
+
tags?: Array<{
|
|
91
|
+
name: string;
|
|
92
|
+
description?: string;
|
|
93
|
+
}>;
|
|
94
|
+
}
|
|
95
|
+
export type EndpointLike = (RequestHandler & {
|
|
96
|
+
_yaxaConfig?: YaxaEndpointConfig;
|
|
97
|
+
}) | YaxaEndpointConfig;
|
|
98
|
+
export type EndpointMap = Record<string, Record<string, EndpointLike>>;
|
|
99
|
+
export interface GenerateOpenApiOptions {
|
|
100
|
+
title?: string;
|
|
101
|
+
version?: string;
|
|
102
|
+
description?: string;
|
|
103
|
+
servers?: Array<{
|
|
104
|
+
url: string;
|
|
105
|
+
description?: string;
|
|
106
|
+
}>;
|
|
107
|
+
endpoints?: EndpointMap;
|
|
108
|
+
registry?: any;
|
|
109
|
+
}
|
|
110
|
+
export type ApiDocsTheme = 'scalar' | 'swagger' | 'redoc';
|
|
111
|
+
export interface ApiDocsOptions extends GenerateOpenApiOptions {
|
|
112
|
+
/**
|
|
113
|
+
* Interactive UI theme:
|
|
114
|
+
* - 'scalar' (default): Modern, dark-mode native, high contrast developer reference.
|
|
115
|
+
* - 'swagger': Classic Swagger UI with interactive Try-It-Out console.
|
|
116
|
+
* - 'redoc': Clean 3-panel technical documentation format.
|
|
117
|
+
*/
|
|
118
|
+
theme?: ApiDocsTheme;
|
|
119
|
+
/**
|
|
120
|
+
* Mount path of documentation endpoint (default: '/api/docs').
|
|
121
|
+
*/
|
|
122
|
+
docsPath?: string;
|
|
123
|
+
/**
|
|
124
|
+
* CDN version/URL overrides if needed.
|
|
125
|
+
*/
|
|
126
|
+
cdnUrl?: string;
|
|
127
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yaxa-svelte",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "The Intuitive Svelte UI Library — Nuxt UI v4 equivalent for SvelteKit 2 & 3 & Svelte 5 with automated SEO, dynamic OpenGraph cards, sitemaps, robots.txt, and Tailwind CSS v4.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://yaxa.vercel.app",
|