@scalar/workspace-store 0.5.2 → 0.7.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/CHANGELOG.md +31 -0
- package/README.md +94 -7
- package/dist/client.d.ts +11713 -11143
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +27 -2
- package/dist/client.js.map +2 -2
- package/dist/helpers/json-path-utils.d.ts +1 -1
- package/dist/helpers/json-path-utils.d.ts.map +1 -1
- package/dist/helpers/json-path-utils.js.map +2 -2
- package/dist/helpers/merge-object.d.ts +23 -0
- package/dist/helpers/merge-object.d.ts.map +1 -0
- package/dist/helpers/merge-object.js +20 -0
- package/dist/helpers/merge-object.js.map +7 -0
- package/dist/helpers/proxy.d.ts.map +1 -1
- package/dist/helpers/proxy.js +5 -2
- package/dist/helpers/proxy.js.map +2 -2
- package/dist/schemas/reference-config/appearance.d.ts +13 -0
- package/dist/schemas/reference-config/appearance.d.ts.map +1 -0
- package/dist/schemas/reference-config/appearance.js +26 -0
- package/dist/schemas/reference-config/appearance.js.map +7 -0
- package/dist/schemas/reference-config/features.d.ts +15 -0
- package/dist/schemas/reference-config/features.d.ts.map +1 -0
- package/dist/schemas/reference-config/features.js +30 -0
- package/dist/schemas/reference-config/features.js.map +7 -0
- package/dist/schemas/reference-config/index.d.ts +53 -0
- package/dist/schemas/reference-config/index.d.ts.map +1 -0
- package/dist/schemas/reference-config/index.js +66 -0
- package/dist/schemas/reference-config/index.js.map +7 -0
- package/dist/schemas/reference-config/meta.d.ts +12 -0
- package/dist/schemas/reference-config/meta.d.ts.map +1 -0
- package/dist/schemas/reference-config/meta.js +24 -0
- package/dist/schemas/reference-config/meta.js.map +7 -0
- package/dist/schemas/reference-config/routing.d.ts +8 -0
- package/dist/schemas/reference-config/routing.d.ts.map +1 -0
- package/dist/schemas/reference-config/routing.js +16 -0
- package/dist/schemas/reference-config/routing.js.map +7 -0
- package/dist/schemas/reference-config/settings.d.ts +8 -0
- package/dist/schemas/reference-config/settings.d.ts.map +1 -0
- package/dist/schemas/reference-config/settings.js +16 -0
- package/dist/schemas/reference-config/settings.js.map +7 -0
- package/dist/schemas/v3.1/strict/components.d.ts +167 -40
- package/dist/schemas/v3.1/strict/components.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/header.d.ts +2 -0
- package/dist/schemas/v3.1/strict/header.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/media-header-encoding.d.ts +6 -0
- package/dist/schemas/v3.1/strict/media-header-encoding.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/media-type.d.ts +1 -0
- package/dist/schemas/v3.1/strict/media-type.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/oauth-flow.d.ts +73 -2
- package/dist/schemas/v3.1/strict/oauth-flow.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/oauth-flow.js +44 -7
- package/dist/schemas/v3.1/strict/oauth-flow.js.map +2 -2
- package/dist/schemas/v3.1/strict/oauthflows.d.ts +11 -10
- package/dist/schemas/v3.1/strict/oauthflows.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/oauthflows.js +11 -8
- package/dist/schemas/v3.1/strict/oauthflows.js.map +2 -2
- package/dist/schemas/v3.1/strict/operation.d.ts +11 -2
- package/dist/schemas/v3.1/strict/operation.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/parameter.d.ts +11 -5
- package/dist/schemas/v3.1/strict/parameter.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/parameter.js +1 -1
- package/dist/schemas/v3.1/strict/parameter.js.map +2 -2
- package/dist/schemas/v3.1/strict/path-item.d.ts +5 -2
- package/dist/schemas/v3.1/strict/path-item.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/path-operations.d.ts +158 -32
- package/dist/schemas/v3.1/strict/path-operations.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/paths.d.ts +71 -14
- package/dist/schemas/v3.1/strict/paths.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/request-body.d.ts +2 -0
- package/dist/schemas/v3.1/strict/request-body.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/response.d.ts +4 -0
- package/dist/schemas/v3.1/strict/response.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/responses.d.ts +4 -0
- package/dist/schemas/v3.1/strict/responses.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/schema.d.ts +6 -1
- package/dist/schemas/v3.1/strict/schema.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/schema.js +7 -2
- package/dist/schemas/v3.1/strict/schema.js.map +2 -2
- package/dist/schemas/v3.1/strict/security-scheme.d.ts +22 -20
- package/dist/schemas/v3.1/strict/security-scheme.d.ts.map +1 -1
- package/dist/schemas/v3.1/type-guard.d.ts +5 -0
- package/dist/schemas/v3.1/type-guard.d.ts.map +1 -1
- package/dist/schemas/v3.1/type-guard.js +1 -3
- package/dist/schemas/v3.1/type-guard.js.map +2 -2
- package/dist/server.d.ts +687 -651
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +52 -49
- package/dist/server.js.map +2 -2
- package/dist/types.d.ts +57 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +7 -0
- package/package.json +19 -7
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAG/E,OAAO,EAAoB,KAAK,uBAAuB,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAG/E,OAAO,EAAoB,KAAK,uBAAuB,EAAE,MAAM,cAAc,CAAA;AAC7E,OAAO,EAAE,UAA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CAAE,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,uBAkC3G;AAsCD;;GAEG;AACH,wBAAsB,0BAA0B,CAAC,cAAc,EAAE,0BAA0B;IAmGvF;;;;;;;;;;;OAWG;;IAwCH;;;;;;;;;;OAUG;;mBApJc,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG;YAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,cAAc,EAAE,CAAA;SAAE,CAAC;;;;;;IAwJzG;;;;;;;;;;;;;;;;;OAiBG;mBACY,MAAM;IAGrB;;;;;;;;;OASG;yBA9G6B,sBAAsB;GAiHzD"}
|
package/dist/server.js
CHANGED
|
@@ -4,9 +4,10 @@ import fs from "node:fs/promises";
|
|
|
4
4
|
import { cwd } from "node:process";
|
|
5
5
|
import { createNavigation } from "./navigation/index.js";
|
|
6
6
|
import { extensions } from "./schemas/extensions.js";
|
|
7
|
-
import { coerceValue } from "./schemas/typebox-coerce.js";
|
|
8
7
|
import { OpenAPIDocumentSchema } from "./schemas/v3.1/strict/openapi-document.js";
|
|
9
8
|
import { keyOf } from "./helpers/general.js";
|
|
9
|
+
import { fetchUrls, readFiles } from "@scalar/openapi-parser/plugins";
|
|
10
|
+
import { coerceValue } from "./schemas/typebox-coerce.js";
|
|
10
11
|
const DEFAULT_ASSETS_FOLDER = "assets";
|
|
11
12
|
const WORKSPACE_FILE_NAME = "scalar-workspace.json";
|
|
12
13
|
const httpMethods = /* @__PURE__ */ new Set(["get", "put", "post", "delete", "options", "head", "patch", "trace"]);
|
|
@@ -75,30 +76,52 @@ function externalizePathReferences(document, meta) {
|
|
|
75
76
|
});
|
|
76
77
|
return result;
|
|
77
78
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
79
|
+
async function loadDocument(workspaceDocument) {
|
|
80
|
+
if ("url" in workspaceDocument) {
|
|
81
|
+
return fetchUrls().exec(workspaceDocument.url);
|
|
82
|
+
}
|
|
83
|
+
if ("path" in workspaceDocument) {
|
|
84
|
+
return readFiles().exec(workspaceDocument.path);
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
ok: true,
|
|
88
|
+
data: workspaceDocument.document
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
async function createServerWorkspaceStore(workspaceProps) {
|
|
91
92
|
const workspace = {
|
|
92
93
|
...workspaceProps.meta,
|
|
93
|
-
documents:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
documents: {}
|
|
95
|
+
};
|
|
96
|
+
const assets = {};
|
|
97
|
+
const addDocumentSync = (document, meta) => {
|
|
98
|
+
const { name, ...documentMeta } = meta;
|
|
99
|
+
const documentV3 = coerceValue(OpenAPIDocumentSchema, upgrade(document).specification);
|
|
100
|
+
assets[meta.name] = {
|
|
101
|
+
components: documentV3.components,
|
|
102
|
+
operations: documentV3.paths && escapePaths(filterHttpMethodsOnly(documentV3.paths))
|
|
103
|
+
};
|
|
104
|
+
const options = workspaceProps.mode === "ssr" ? { mode: workspaceProps.mode, name, baseUrl: workspaceProps.baseUrl } : { mode: workspaceProps.mode, name, directory: workspaceProps.directory ?? DEFAULT_ASSETS_FOLDER };
|
|
105
|
+
const components = externalizeComponentReferences(documentV3, options);
|
|
106
|
+
const paths = externalizePathReferences(documentV3, options);
|
|
107
|
+
const { entries } = createNavigation(documentV3, workspaceProps.config ?? {});
|
|
108
|
+
workspace.documents[meta.name] = {
|
|
109
|
+
...documentMeta,
|
|
110
|
+
...documentV3,
|
|
111
|
+
components,
|
|
112
|
+
paths,
|
|
113
|
+
[extensions.document.navigation]: entries
|
|
114
|
+
};
|
|
101
115
|
};
|
|
116
|
+
const addDocument = async (input) => {
|
|
117
|
+
const document = await loadDocument(input);
|
|
118
|
+
if (!document.ok) {
|
|
119
|
+
console.warn(`Failed to load document "${input.name}`);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
addDocumentSync(document.data, { name: input.name, ...input.meta });
|
|
123
|
+
};
|
|
124
|
+
await Promise.all(workspaceProps.documents.map(addDocument));
|
|
102
125
|
return {
|
|
103
126
|
/**
|
|
104
127
|
* Generates workspace chunks by writing components and operations to the filesystem.
|
|
@@ -176,36 +199,16 @@ function createServerWorkspaceStore(workspaceProps) {
|
|
|
176
199
|
return getValueByPath(assets, parseJsonPointer(pointer));
|
|
177
200
|
},
|
|
178
201
|
/**
|
|
179
|
-
* Adds a new document to the workspace.
|
|
202
|
+
* Adds a new document to the workspace asynchronously.
|
|
180
203
|
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
* - Added to the workspace with its metadata
|
|
204
|
+
* This function:
|
|
205
|
+
* 1. Loads the document using the provided input
|
|
206
|
+
* 2. Checks if the document loaded successfully
|
|
207
|
+
* 3. If successful, adds the document to the workspace using addDocumentSync
|
|
186
208
|
*
|
|
187
|
-
* @param
|
|
188
|
-
* @param meta - Document metadata including required name and optional settings
|
|
209
|
+
* @param input - The document input containing the document source and metadata
|
|
189
210
|
*/
|
|
190
|
-
addDocument
|
|
191
|
-
const { name, ...documentMeta } = meta;
|
|
192
|
-
const documentV3 = coerceValue(OpenAPIDocumentSchema, upgrade(document).specification);
|
|
193
|
-
assets[meta.name] = {
|
|
194
|
-
components: documentV3.components,
|
|
195
|
-
operations: documentV3.paths && escapePaths(filterHttpMethodsOnly(documentV3.paths))
|
|
196
|
-
};
|
|
197
|
-
const options = workspaceProps.mode === "ssr" ? { mode: workspaceProps.mode, name, baseUrl: workspaceProps.baseUrl } : { mode: workspaceProps.mode, name, directory: workspaceProps.directory ?? DEFAULT_ASSETS_FOLDER };
|
|
198
|
-
const components = externalizeComponentReferences(documentV3, options);
|
|
199
|
-
const paths = externalizePathReferences(documentV3, options);
|
|
200
|
-
const { entries } = createNavigation(documentV3, workspaceProps.config ?? {});
|
|
201
|
-
workspace.documents[meta.name] = {
|
|
202
|
-
...documentMeta,
|
|
203
|
-
...documentV3,
|
|
204
|
-
components,
|
|
205
|
-
paths,
|
|
206
|
-
[extensions.document.navigation]: entries
|
|
207
|
-
};
|
|
208
|
-
}
|
|
211
|
+
addDocument
|
|
209
212
|
};
|
|
210
213
|
}
|
|
211
214
|
export {
|
package/dist/server.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/server.ts"],
|
|
4
|
-
"sourcesContent": ["import { escapeJsonPointer, upgrade } from '@scalar/openapi-parser'\nimport { getValueByPath, parseJsonPointer } from './helpers/json-path-utils'\nimport type { WorkspaceDocumentMeta, WorkspaceMeta } from './schemas/workspace'\nimport fs from 'node:fs/promises'\nimport { cwd } from 'node:process'\nimport { createNavigation, type createNavigationOptions } from '@/navigation'\nimport { extensions } from '@/schemas/extensions'\nimport { coerceValue } from '@/schemas/typebox-coerce'\nimport { OpenAPIDocumentSchema, type OpenApiDocument } from '@/schemas/v3.1/strict/openapi-document'\nimport type { PathsObject } from '@/schemas/v3.1/strict/paths'\nimport { keyOf } from '@/helpers/general'\nimport type { ComponentsObject } from '@/schemas/v3.1/strict/components'\nimport type { OperationObject } from '@/schemas/v3.1/strict/path-operations'\n\nconst DEFAULT_ASSETS_FOLDER = 'assets'\nexport const WORKSPACE_FILE_NAME = 'scalar-workspace.json'\n\n// TODO: support input document from different sources\ntype CreateServerWorkspaceStoreBase = {\n documents: {\n name: string\n document: Record<string, unknown> | string\n meta?: WorkspaceDocumentMeta\n }[]\n meta?: WorkspaceMeta\n config?: createNavigationOptions\n}\ntype CreateServerWorkspaceStore =\n | ({\n directory?: string\n mode: 'static'\n } & CreateServerWorkspaceStoreBase)\n | ({\n baseUrl: string\n mode: 'ssr'\n } & CreateServerWorkspaceStoreBase)\n\nconst httpMethods = new Set(['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'])\n\n/**\n * Filters an OpenAPI PathsObject to only include standard HTTP methods.\n * Removes any vendor extensions or other non-HTTP properties.\n *\n * @param paths - The OpenAPI PathsObject to filter\n * @returns A new PathsObject containing only standard HTTP methods\n *\n * @example\n * Input: {\n * \"/users\": {\n * \"get\": {...},\n * \"x-custom\": {...},\n * \"post\": {...}\n * }\n * }\n * Output: {\n * \"/users\": {\n * \"get\": {...},\n * \"post\": {...}\n * }\n * }\n */\nexport function filterHttpMethodsOnly(paths: PathsObject) {\n const result: Record<string, Record<string, OperationObject>> = {}\n\n // Todo: skip extension properties\n for (const [path, methods] of Object.entries(paths)) {\n if (!methods) {\n continue\n }\n\n const filteredMethods: Record<string, any> = {}\n\n for (const [method, operation] of Object.entries(methods)) {\n if (httpMethods.has(method.toLowerCase())) {\n filteredMethods[method] = operation\n }\n }\n\n if (Object.keys(filteredMethods).length > 0) {\n result[path] = filteredMethods\n }\n }\n\n return result\n}\n\n/**\n * Escapes path keys in an OpenAPI PathsObject to be JSON Pointer compatible.\n * This is necessary because OpenAPI paths can contain characters that need to be escaped\n * when used as JSON Pointer references (like '/' and '~').\n *\n * @example\n * Input: { \"/users/{id}\": { ... } }\n * Output: { \"/users~1{id}\": { ... } }\n */\nexport function escapePaths(paths: Record<string, Record<string, OperationObject>>) {\n const result: Record<string, Record<string, OperationObject>> = {}\n Object.keys(paths).forEach((path) => {\n result[escapeJsonPointer(path)] = paths[path]\n })\n\n return result\n}\n\n/**\n * Externalizes components by turning them into refs.\n */\nexport function externalizeComponentReferences(\n document: OpenApiDocument,\n meta: { mode: 'ssr'; name: string; baseUrl: string } | { mode: 'static'; name: string; directory: string },\n) {\n const result: Record<string, any> = {}\n\n if (!document.components) {\n return result\n }\n\n Object.entries(document.components).forEach(([type, component]) => {\n if (!component || typeof component !== 'object') {\n return result\n }\n\n result[type] = {}\n Object.keys(component).forEach((name) => {\n const ref =\n meta.mode === 'ssr'\n ? `${meta.baseUrl}/${meta.name}/components/${type}/${name}#`\n : `./chunks/${meta.name}/components/${type}/${name}.json#`\n\n result[type][name] = { '$ref': ref, $global: true }\n })\n })\n\n return result\n}\n\n/**\n * Externalizes paths operations by turning them into refs.\n */\nexport function externalizePathReferences(\n document: OpenApiDocument,\n meta: { mode: 'ssr'; name: string; baseUrl: string } | { mode: 'static'; name: string; directory: string },\n) {\n const result: Record<string, any> = {}\n\n if (!document.paths) {\n return result\n }\n\n Object.entries(document.paths).forEach(([path, pathItem]) => {\n if (!pathItem || typeof pathItem !== 'object') {\n return result\n }\n\n const pathItemRecord = pathItem as Record<string, unknown>\n\n result[path] = {}\n\n const escapedPath = escapeJsonPointer(path)\n\n keyOf(pathItemRecord).forEach((type) => {\n if (httpMethods.has(type)) {\n const ref =\n meta.mode === 'ssr'\n ? `${meta.baseUrl}/${meta.name}/operations/${escapedPath}/${type}#`\n : `./chunks/${meta.name}/operations/${escapedPath}/${type}.json#`\n\n result[path][type] = { '$ref': ref, $global: true }\n } else {\n result[path][type] = pathItemRecord[type]\n }\n })\n })\n\n return result\n}\n\n/**\n * Create server state workspace store\n */\nexport function createServerWorkspaceStore(workspaceProps: CreateServerWorkspaceStore) {\n const documents = workspaceProps.documents.map((el) => {\n const document = upgrade(el.document).specification\n\n const castedDocument = coerceValue(OpenAPIDocumentSchema, document)\n\n return { ...el, document: castedDocument }\n })\n\n /**\n * A map of document chunks that can be loaded asynchronously by the client.\n * Each document is split into components and operations to enable lazy loading.\n * The keys are document names and values contain the components and operations\n * for that document.\n */\n const assets = documents.reduce<\n Record<string, { components?: ComponentsObject; operations?: Record<string, Record<string, OperationObject>> }>\n >((acc, { name, document }) => {\n acc[name] = {\n components: document.components,\n operations: document.paths && escapePaths(filterHttpMethodsOnly(document.paths)),\n }\n return acc\n }, {})\n\n /**\n * Base workspace document containing essential metadata and document references.\n *\n * This workspace document provides the minimal information needed for initial rendering.\n * All components and path operations are replaced with references to enable lazy loading.\n *\n * In SSR mode, references point to API endpoints.\n * In static mode, references point to filesystem chunks.\n */\n const workspace = {\n ...workspaceProps.meta,\n documents: documents.reduce<Record<string, Record<string, unknown>>>((acc, { name, document, meta }) => {\n const options =\n workspaceProps.mode === 'ssr'\n ? { mode: workspaceProps.mode, name, baseUrl: workspaceProps.baseUrl }\n : { mode: workspaceProps.mode, name, directory: workspaceProps.directory ?? DEFAULT_ASSETS_FOLDER }\n\n // Transform the original document by setting all the components and paths operations on refs\n const components = externalizeComponentReferences(document, options)\n const paths = externalizePathReferences(document, options)\n\n // Here we create the sidebar\n const { entries } = createNavigation(document, workspaceProps.config ?? {})\n\n acc[name] = { ...meta, ...document, components, paths, [extensions.document.navigation]: entries }\n return acc\n }, {}),\n }\n\n return {\n /**\n * Generates workspace chunks by writing components and operations to the filesystem.\n *\n * This method is only available in static mode. It creates a directory structure containing:\n * - A workspace file with metadata and document references\n * - Component chunks split by type (schemas, parameters, etc)\n * - Operation chunks split by path and HTTP method\n *\n * The generated workspace references will be relative file paths pointing to these chunks.\n *\n * @throws {Error} If called when mode is not 'static'\n */\n generateWorkspaceChunks: async () => {\n if (workspaceProps.mode !== 'static') {\n throw 'Mode has to be set to `static` to generate filesystem workspace chunks'\n }\n\n // Write the workspace document\n const basePath = `${cwd()}/${workspaceProps.directory ?? DEFAULT_ASSETS_FOLDER}`\n await fs.mkdir(basePath, { recursive: true })\n\n // Write the workspace contents on the file system\n await fs.writeFile(`${basePath}/${WORKSPACE_FILE_NAME}`, JSON.stringify(workspace))\n\n // Write the chunks\n for (const [name, { components, operations }] of Object.entries(assets)) {\n // Write the components chunks\n if (components) {\n for (const [type, component] of Object.entries(components as Record<string, Record<string, unknown>>)) {\n const componentPath = `${basePath}/chunks/${name}/components/${type}`\n await fs.mkdir(componentPath, { recursive: true })\n\n for (const [key, value] of Object.entries(component)) {\n await fs.writeFile(`${componentPath}/${key}.json`, JSON.stringify(value))\n }\n }\n }\n\n // Write the operations chunks\n if (operations) {\n for (const [path, methods] of Object.entries(operations)) {\n const operationPath = `${basePath}/chunks/${name}/operations/${path}`\n await fs.mkdir(operationPath, { recursive: true })\n\n for (const [method, operation] of Object.entries(methods)) {\n await fs.writeFile(`${operationPath}/${method}.json`, JSON.stringify(operation))\n }\n }\n }\n }\n },\n /**\n * Returns the workspace document containing metadata and all sparse documents.\n *\n * The workspace document includes:\n * - Global workspace metadata (theme, active document, etc)\n * - Document metadata and sparse document\n * - In SSR mode: References point to in-memory chunks\n * - In static mode: References point to filesystem chunks\n *\n * @returns The complete workspace document\n */\n getWorkspace: () => {\n return workspace\n },\n /**\n * Retrieves a chunk of data from the workspace using a JSON Pointer\n *\n * A JSON Pointer is a string that references a specific location in a JSON document.\n * Only components and operations chunks can be retrieved.\n *\n * @example\n * ```ts\n * // Get a component\n * get('#/document-name/components/schemas/User')\n *\n * // Get an operation\n * get('#/document-name/operations/pets/get')\n * ```\n *\n * @param pointer - The JSON Pointer string to locate the chunk\n * @returns The chunk data if found, undefined otherwise\n */\n get: (pointer: string) => {\n return getValueByPath(assets, parseJsonPointer(pointer))\n },\n /**\n * Adds a new document to the workspace.\n *\n * The document will be:\n * - Upgraded to OpenAPI 3.1 if needed\n * - Split into components and operations chunks\n * - Have its references externalized based on the workspace mode\n * - Added to the workspace with its metadata\n *\n * @param document - The OpenAPI document to add\n * @param meta - Document metadata including required name and optional settings\n */\n addDocument: (document: Record<string, unknown>, meta: { name: string } & WorkspaceDocumentMeta) => {\n const { name, ...documentMeta } = meta\n\n const documentV3 = coerceValue(OpenAPIDocumentSchema, upgrade(document).specification)\n\n // add the assets\n assets[meta.name] = {\n components: documentV3.components,\n operations: documentV3.paths && escapePaths(filterHttpMethodsOnly(documentV3.paths)),\n }\n\n const options =\n workspaceProps.mode === 'ssr'\n ? { mode: workspaceProps.mode, name, baseUrl: workspaceProps.baseUrl }\n : { mode: workspaceProps.mode, name, directory: workspaceProps.directory ?? DEFAULT_ASSETS_FOLDER }\n\n const components = externalizeComponentReferences(documentV3, options)\n const paths = externalizePathReferences(documentV3, options)\n\n // Build the sidebar entries\n const { entries } = createNavigation(documentV3, workspaceProps.config ?? {})\n\n // The document is now a minimal version with externalized references to components and operations.\n // These references will be resolved asynchronously when needed through the workspace's get() method.\n workspace.documents[meta.name] = {\n ...documentMeta,\n ...documentV3,\n components,\n paths,\n [extensions.document.navigation]: entries,\n }\n },\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,mBAAmB,eAAe;AAC3C,SAAS,gBAAgB,wBAAwB;AAEjD,OAAO,QAAQ;AACf,SAAS,WAAW;AACpB,SAAS,wBAAsD;AAC/D,SAAS,kBAAkB;AAC3B,SAAS,
|
|
4
|
+
"sourcesContent": ["import { escapeJsonPointer, upgrade } from '@scalar/openapi-parser'\nimport { getValueByPath, parseJsonPointer } from './helpers/json-path-utils'\nimport type { WorkspaceDocumentMeta, WorkspaceMeta } from './schemas/workspace'\nimport fs from 'node:fs/promises'\nimport { cwd } from 'node:process'\nimport { createNavigation, type createNavigationOptions } from '@/navigation'\nimport { extensions } from '@/schemas/extensions'\nimport { OpenAPIDocumentSchema, type OpenApiDocument } from '@/schemas/v3.1/strict/openapi-document'\nimport type { PathsObject } from '@/schemas/v3.1/strict/paths'\nimport { keyOf } from '@/helpers/general'\nimport type { OperationObject } from '@/schemas/v3.1/strict/path-operations'\nimport { fetchUrls, readFiles } from '@scalar/openapi-parser/plugins'\nimport { coerceValue } from '@/schemas/typebox-coerce'\nimport type { ComponentsObject } from '@/schemas/v3.1/strict/components'\nimport type { TraversedEntry } from '@/navigation/types'\n\nconst DEFAULT_ASSETS_FOLDER = 'assets'\nexport const WORKSPACE_FILE_NAME = 'scalar-workspace.json'\n\ntype WorkspaceDocumentMetaInput = {\n name: string\n meta?: WorkspaceDocumentMeta\n}\n\ntype UrlDoc = { url: string } & WorkspaceDocumentMetaInput\ntype FileDoc = { path: string } & WorkspaceDocumentMetaInput\ntype ObjectDoc = { document: Record<string, unknown> } & WorkspaceDocumentMetaInput\n\ntype WorkspaceDocumentInput = UrlDoc | ObjectDoc | FileDoc\n\ntype CreateServerWorkspaceStoreBase = {\n documents: WorkspaceDocumentInput[]\n meta?: WorkspaceMeta\n config?: createNavigationOptions\n}\ntype CreateServerWorkspaceStore =\n | ({\n directory?: string\n mode: 'static'\n } & CreateServerWorkspaceStoreBase)\n | ({\n baseUrl: string\n mode: 'ssr'\n } & CreateServerWorkspaceStoreBase)\n\nconst httpMethods = new Set(['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'])\n\n/**\n * Filters an OpenAPI PathsObject to only include standard HTTP methods.\n * Removes any vendor extensions or other non-HTTP properties.\n *\n * @param paths - The OpenAPI PathsObject to filter\n * @returns A new PathsObject containing only standard HTTP methods\n *\n * @example\n * Input: {\n * \"/users\": {\n * \"get\": {...},\n * \"x-custom\": {...},\n * \"post\": {...}\n * }\n * }\n * Output: {\n * \"/users\": {\n * \"get\": {...},\n * \"post\": {...}\n * }\n * }\n */\nexport function filterHttpMethodsOnly(paths: PathsObject) {\n const result: Record<string, Record<string, OperationObject>> = {}\n\n // Todo: skip extension properties\n for (const [path, methods] of Object.entries(paths)) {\n if (!methods) {\n continue\n }\n\n const filteredMethods: Record<string, any> = {}\n\n for (const [method, operation] of Object.entries(methods)) {\n if (httpMethods.has(method.toLowerCase())) {\n filteredMethods[method] = operation\n }\n }\n\n if (Object.keys(filteredMethods).length > 0) {\n result[path] = filteredMethods\n }\n }\n\n return result\n}\n\n/**\n * Escapes path keys in an OpenAPI PathsObject to be JSON Pointer compatible.\n * This is necessary because OpenAPI paths can contain characters that need to be escaped\n * when used as JSON Pointer references (like '/' and '~').\n *\n * @example\n * Input: { \"/users/{id}\": { ... } }\n * Output: { \"/users~1{id}\": { ... } }\n */\nexport function escapePaths(paths: Record<string, Record<string, OperationObject>>) {\n const result: Record<string, Record<string, OperationObject>> = {}\n Object.keys(paths).forEach((path) => {\n result[escapeJsonPointer(path)] = paths[path]\n })\n\n return result\n}\n\n/**\n * Externalizes components by turning them into refs.\n */\nexport function externalizeComponentReferences(\n document: OpenApiDocument,\n meta: { mode: 'ssr'; name: string; baseUrl: string } | { mode: 'static'; name: string; directory: string },\n) {\n const result: Record<string, any> = {}\n\n if (!document.components) {\n return result\n }\n\n Object.entries(document.components).forEach(([type, component]) => {\n if (!component || typeof component !== 'object') {\n return result\n }\n\n result[type] = {}\n Object.keys(component).forEach((name) => {\n const ref =\n meta.mode === 'ssr'\n ? `${meta.baseUrl}/${meta.name}/components/${type}/${name}#`\n : `./chunks/${meta.name}/components/${type}/${name}.json#`\n\n result[type][name] = { '$ref': ref, $global: true }\n })\n })\n\n return result\n}\n\n/**\n * Externalizes paths operations by turning them into refs.\n */\nexport function externalizePathReferences(\n document: OpenApiDocument,\n meta: { mode: 'ssr'; name: string; baseUrl: string } | { mode: 'static'; name: string; directory: string },\n) {\n const result: Record<string, any> = {}\n\n if (!document.paths) {\n return result\n }\n\n Object.entries(document.paths).forEach(([path, pathItem]) => {\n if (!pathItem || typeof pathItem !== 'object') {\n return result\n }\n\n const pathItemRecord = pathItem as Record<string, unknown>\n\n result[path] = {}\n\n const escapedPath = escapeJsonPointer(path)\n\n keyOf(pathItemRecord).forEach((type) => {\n if (httpMethods.has(type)) {\n const ref =\n meta.mode === 'ssr'\n ? `${meta.baseUrl}/${meta.name}/operations/${escapedPath}/${type}#`\n : `./chunks/${meta.name}/operations/${escapedPath}/${type}.json#`\n\n result[path][type] = { '$ref': ref, $global: true }\n } else {\n result[path][type] = pathItemRecord[type]\n }\n })\n })\n\n return result\n}\n\n/**\n * Resolves a workspace document from various input sources (URL, local file, or direct document object).\n *\n * @param workspaceDocument - The document input to resolve, which can be:\n * - A URL to fetch the document from\n * - A local file path to read the document from\n * - A direct document object\n * @returns A promise that resolves to an object containing:\n * - ok: boolean indicating if the resolution was successful\n * - data: The resolved document data\n *\n * @example\n * // Resolve from URL\n * const urlDoc = await loadDocument({ name: 'api', url: 'https://api.example.com/openapi.json' })\n *\n * // Resolve direct document\n * const directDoc = await loadDocument({\n * name: 'inline',\n * document: { openapi: '3.0.0', paths: {} }\n * })\n */\nasync function loadDocument(workspaceDocument: WorkspaceDocumentInput) {\n if ('url' in workspaceDocument) {\n return fetchUrls().exec(workspaceDocument.url)\n }\n\n if ('path' in workspaceDocument) {\n return readFiles().exec(workspaceDocument.path)\n }\n\n return {\n ok: true as const,\n data: workspaceDocument.document,\n }\n}\n\n/**\n * Create server state workspace store\n */\nexport async function createServerWorkspaceStore(workspaceProps: CreateServerWorkspaceStore) {\n /**\n * Base workspace document containing essential metadata and document references.\n *\n * This workspace document provides the minimal information needed for initial rendering.\n * All components and path operations are replaced with references to enable lazy loading.\n *\n * In SSR mode, references point to API endpoints.\n * In static mode, references point to filesystem chunks.\n */\n const workspace = {\n ...workspaceProps.meta,\n documents: {} as Record<string, OpenApiDocument & { [extensions.document.navigation]: TraversedEntry[] }>,\n }\n\n /**\n * A map of document chunks that can be loaded asynchronously by the client.\n * Each document is split into components and operations to enable lazy loading.\n * The keys are document names and values contain the components and operations\n * for that document.\n */\n const assets = {} as Record<\n string,\n { components?: ComponentsObject; operations?: Record<string, Record<string, OperationObject>> }\n >\n\n /**\n * Adds a new document to the workspace.\n *\n * This function processes an OpenAPI document by:\n * 1. Converting it to OpenAPI 3.1 format if needed\n * 2. Separating it into reusable components and path operations\n * 3. Externalizing references based on the workspace mode (SSR or static)\n * 4. Adding the processed document to the workspace with its metadata\n *\n * The resulting document contains minimal information with externalized references\n * that will be resolved on-demand through the workspace's get() method.\n *\n * @param document - The OpenAPI document to process and add\n * @param meta - Document metadata containing the required name and optional settings\n */\n const addDocumentSync = (document: Record<string, unknown>, meta: { name: string } & WorkspaceDocumentMeta) => {\n const { name, ...documentMeta } = meta\n\n const documentV3 = coerceValue(OpenAPIDocumentSchema, upgrade(document).specification)\n\n // add the assets\n assets[meta.name] = {\n components: documentV3.components,\n operations: documentV3.paths && escapePaths(filterHttpMethodsOnly(documentV3.paths)),\n }\n\n const options =\n workspaceProps.mode === 'ssr'\n ? { mode: workspaceProps.mode, name, baseUrl: workspaceProps.baseUrl }\n : { mode: workspaceProps.mode, name, directory: workspaceProps.directory ?? DEFAULT_ASSETS_FOLDER }\n\n const components = externalizeComponentReferences(documentV3, options)\n const paths = externalizePathReferences(documentV3, options)\n\n // Build the sidebar entries\n const { entries } = createNavigation(documentV3, workspaceProps.config ?? {})\n\n // The document is now a minimal version with externalized references to components and operations.\n // These references will be resolved asynchronously when needed through the workspace's get() method.\n workspace.documents[meta.name] = {\n ...documentMeta,\n ...documentV3,\n components,\n paths,\n [extensions.document.navigation]: entries,\n }\n }\n\n /**\n * Adds a new document to the workspace asynchronously.\n *\n * This function:\n * 1. Loads the document using the provided input\n * 2. Checks if the document loaded successfully\n * 3. If successful, adds the document to the workspace using addDocumentSync\n *\n * @param input - The document input containing the document source and metadata\n */\n const addDocument = async (input: WorkspaceDocumentInput) => {\n const document = await loadDocument(input)\n\n if (!document.ok) {\n console.warn(`Failed to load document \"${input.name}`)\n return\n }\n\n addDocumentSync(document.data as Record<string, unknown>, { name: input.name, ...input.meta })\n }\n\n // Load and process all initial documents in parallel\n await Promise.all(workspaceProps.documents.map(addDocument))\n\n return {\n /**\n * Generates workspace chunks by writing components and operations to the filesystem.\n *\n * This method is only available in static mode. It creates a directory structure containing:\n * - A workspace file with metadata and document references\n * - Component chunks split by type (schemas, parameters, etc)\n * - Operation chunks split by path and HTTP method\n *\n * The generated workspace references will be relative file paths pointing to these chunks.\n *\n * @throws {Error} If called when mode is not 'static'\n */\n generateWorkspaceChunks: async () => {\n if (workspaceProps.mode !== 'static') {\n throw 'Mode has to be set to `static` to generate filesystem workspace chunks'\n }\n\n // Write the workspace document\n const basePath = `${cwd()}/${workspaceProps.directory ?? DEFAULT_ASSETS_FOLDER}`\n await fs.mkdir(basePath, { recursive: true })\n\n // Write the workspace contents on the file system\n await fs.writeFile(`${basePath}/${WORKSPACE_FILE_NAME}`, JSON.stringify(workspace))\n\n // Write the chunks\n for (const [name, { components, operations }] of Object.entries(assets)) {\n // Write the components chunks\n if (components) {\n for (const [type, component] of Object.entries(components as Record<string, Record<string, unknown>>)) {\n const componentPath = `${basePath}/chunks/${name}/components/${type}`\n await fs.mkdir(componentPath, { recursive: true })\n\n for (const [key, value] of Object.entries(component)) {\n await fs.writeFile(`${componentPath}/${key}.json`, JSON.stringify(value))\n }\n }\n }\n\n // Write the operations chunks\n if (operations) {\n for (const [path, methods] of Object.entries(operations)) {\n const operationPath = `${basePath}/chunks/${name}/operations/${path}`\n await fs.mkdir(operationPath, { recursive: true })\n\n for (const [method, operation] of Object.entries(methods)) {\n await fs.writeFile(`${operationPath}/${method}.json`, JSON.stringify(operation))\n }\n }\n }\n }\n },\n /**\n * Returns the workspace document containing metadata and all sparse documents.\n *\n * The workspace document includes:\n * - Global workspace metadata (theme, active document, etc)\n * - Document metadata and sparse document\n * - In SSR mode: References point to in-memory chunks\n * - In static mode: References point to filesystem chunks\n *\n * @returns The complete workspace document\n */\n getWorkspace: () => {\n return workspace\n },\n /**\n * Retrieves a chunk of data from the workspace using a JSON Pointer\n *\n * A JSON Pointer is a string that references a specific location in a JSON document.\n * Only components and operations chunks can be retrieved.\n *\n * @example\n * ```ts\n * // Get a component\n * get('#/document-name/components/schemas/User')\n *\n * // Get an operation\n * get('#/document-name/operations/pets/get')\n * ```\n *\n * @param pointer - The JSON Pointer string to locate the chunk\n * @returns The chunk data if found, undefined otherwise\n */\n get: (pointer: string) => {\n return getValueByPath(assets, parseJsonPointer(pointer))\n },\n /**\n * Adds a new document to the workspace asynchronously.\n *\n * This function:\n * 1. Loads the document using the provided input\n * 2. Checks if the document loaded successfully\n * 3. If successful, adds the document to the workspace using addDocumentSync\n *\n * @param input - The document input containing the document source and metadata\n */\n addDocument,\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,mBAAmB,eAAe;AAC3C,SAAS,gBAAg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F;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAYA,cAAc,MAAM;AAClB,aAAO;AAAA,IACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAmBA,KAAK,CAAC,YAAoB;AACxB,aAAO,eAAe,QAAQ,iBAAiB,OAAO,CAAC;AAAA,IACzD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWA;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies a type transformation to a given type T based on the Transform parameter.
|
|
3
|
+
*
|
|
4
|
+
* This utility type supports common TypeScript transformations:
|
|
5
|
+
* - 'NonNullable': Removes null and undefined from the type
|
|
6
|
+
* - 'Partial': Makes all properties optional
|
|
7
|
+
* - 'Required': Makes all properties required
|
|
8
|
+
* - 'Readonly': Makes all properties readonly
|
|
9
|
+
*
|
|
10
|
+
* If no valid transformation is provided, returns the original type unchanged.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The type to transform
|
|
13
|
+
* @template Transform - The transformation to apply ('NonNullable' | 'Partial' | 'Required' | 'Readonly')
|
|
14
|
+
*/
|
|
15
|
+
type ApplyTransform<T, Transform> = Transform extends 'NonNullable' ? NonNullable<T> : Transform extends 'Partial' ? Partial<T> : Transform extends 'Required' ? Required<T> : Transform extends 'Readonly' ? Readonly<T> : T;
|
|
16
|
+
/**
|
|
17
|
+
* Recursively applies a type transformation to all levels of a nested type structure.
|
|
18
|
+
*
|
|
19
|
+
* This utility type traverses through complex nested types and applies the specified transformation
|
|
20
|
+
* at each level. It handles:
|
|
21
|
+
* - Functions: Returns the function type unchanged (no transformation applied)
|
|
22
|
+
* - Arrays: Recursively transforms each element in the array
|
|
23
|
+
* - Objects: Recursively transforms each property value in the object
|
|
24
|
+
* - Primitives: Applies the transformation directly using ApplyTransform
|
|
25
|
+
*
|
|
26
|
+
* The transformation is applied using the ApplyTransform utility, which supports:
|
|
27
|
+
* 'NonNullable', 'Partial', 'Required', and 'Readonly' transformations.
|
|
28
|
+
*
|
|
29
|
+
* @template T - The type to recursively transform
|
|
30
|
+
* @template Transform - The transformation to apply at each level
|
|
31
|
+
* @example
|
|
32
|
+
* // Make all properties in a nested object optional
|
|
33
|
+
* type OptionalNested = DeepTransform<{ a: { b: string } }, 'Partial'>
|
|
34
|
+
* // Result: { a?: { b?: string } }
|
|
35
|
+
*/
|
|
36
|
+
export type DeepTransform<T, Transform> = T extends (...args: any[]) => any ? T : T extends Array<infer U> ? Array<DeepTransform<U, Transform>> : T extends object ? {
|
|
37
|
+
[K in keyof T]-?: DeepTransform<ApplyTransform<NonNullable<T[K]>, Transform>, Transform>;
|
|
38
|
+
} : ApplyTransform<NonNullable<T>, Transform>;
|
|
39
|
+
/**
|
|
40
|
+
* Converts a readonly array type to a mutable array type.
|
|
41
|
+
*
|
|
42
|
+
* This utility type removes the readonly modifier from all elements in an array type,
|
|
43
|
+
* allowing the array to be modified. It's useful when you need to work with mutable
|
|
44
|
+
* versions of readonly arrays in TypeScript.
|
|
45
|
+
*
|
|
46
|
+
* @template T - The readonly array type to convert to mutable
|
|
47
|
+
* @example
|
|
48
|
+
* // Convert a readonly array to mutable
|
|
49
|
+
* type ReadonlyNumbers = readonly number[]
|
|
50
|
+
* type MutableNumbers = MutableArray<ReadonlyNumbers>
|
|
51
|
+
* // Result: number[]
|
|
52
|
+
*/
|
|
53
|
+
export type MutableArray<T extends readonly any[]> = {
|
|
54
|
+
-readonly [k in keyof T]: T[k];
|
|
55
|
+
};
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,KAAK,cAAc,CAAC,CAAC,EAAE,SAAS,IAAI,SAAS,SAAS,aAAa,GAC/D,WAAW,CAAC,CAAC,CAAC,GACd,SAAS,SAAS,SAAS,GACzB,OAAO,CAAC,CAAC,CAAC,GACV,SAAS,SAAS,UAAU,GAC1B,QAAQ,CAAC,CAAC,CAAC,GACX,SAAS,SAAS,UAAU,GAC1B,QAAQ,CAAC,CAAC,CAAC,GAEX,CAAC,CAAA;AAEX;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,SAAS,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GACvE,CAAC,GACD,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GACtB,KAAK,CAAC,aAAa,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,GAClC,CAAC,SAAS,MAAM,GACd;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,SAAS,CAAC;CAAE,GAC5F,cAAc,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAA;AAEjD;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,SAAS,GAAG,EAAE,IAAI;IACnD,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAC/B,CAAA"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"openapi",
|
|
17
17
|
"scalar"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.
|
|
19
|
+
"version": "0.7.0",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -32,6 +32,16 @@
|
|
|
32
32
|
"types": "./dist/schemas.d.ts",
|
|
33
33
|
"default": "./dist/schemas.js"
|
|
34
34
|
},
|
|
35
|
+
"./schemas/v3.1/*": {
|
|
36
|
+
"import": "./dist/schemas/v3.1/*.js",
|
|
37
|
+
"types": "./dist/schemas/v3.1/*.d.ts",
|
|
38
|
+
"default": "./dist/schemas/v3.1/*.js"
|
|
39
|
+
},
|
|
40
|
+
"./schemas/v3.1/strict/*": {
|
|
41
|
+
"import": "./dist/schemas/v3.1/strict/*.js",
|
|
42
|
+
"types": "./dist/schemas/v3.1/strict/*.d.ts",
|
|
43
|
+
"default": "./dist/schemas/v3.1/strict/*.js"
|
|
44
|
+
},
|
|
35
45
|
"./server": {
|
|
36
46
|
"import": "./dist/server.js",
|
|
37
47
|
"types": "./dist/server.d.ts",
|
|
@@ -43,16 +53,17 @@
|
|
|
43
53
|
"CHANGELOG.md"
|
|
44
54
|
],
|
|
45
55
|
"dependencies": {
|
|
46
|
-
"@sinclair/typebox": "0.34.
|
|
56
|
+
"@sinclair/typebox": "0.34.37",
|
|
47
57
|
"github-slugger": "^2.0.0",
|
|
48
58
|
"vue": "^3.5.12",
|
|
49
|
-
"@scalar/helpers": "0.0.4",
|
|
50
|
-
"@scalar/openapi-parser": "0.18.0",
|
|
51
59
|
"@scalar/code-highlight": "0.1.4",
|
|
52
|
-
"@scalar/
|
|
60
|
+
"@scalar/helpers": "0.0.5",
|
|
61
|
+
"@scalar/openapi-types": "0.3.4",
|
|
62
|
+
"@scalar/openapi-parser": "0.18.0",
|
|
63
|
+
"@scalar/types": "0.2.5"
|
|
53
64
|
},
|
|
54
65
|
"devDependencies": {
|
|
55
|
-
"@google-cloud/storage": "7.
|
|
66
|
+
"@google-cloud/storage": "7.16.0",
|
|
56
67
|
"fastify": "^5.3.3",
|
|
57
68
|
"vite": "5.4.19",
|
|
58
69
|
"vitest": "^1.6.0",
|
|
@@ -67,6 +78,7 @@
|
|
|
67
78
|
"lint:fix": "eslint . --fix",
|
|
68
79
|
"test": "vitest",
|
|
69
80
|
"types:build": "scalar-types-build",
|
|
70
|
-
"types:check": "scalar-types-check"
|
|
81
|
+
"types:check": "scalar-types-check",
|
|
82
|
+
"generate-json-schemas": "vite-node ./scripts/generate-json-schemas.ts"
|
|
71
83
|
}
|
|
72
84
|
}
|