Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@scalar/openapi-parser

Package Overview
Dependencies
Maintainers
8
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@scalar/openapi-parser - npm Package Compare versions

Comparing version 0.8.1 to 0.8.2

dist/utils/openapi/actions/details.d.ts

6

CHANGELOG.md
# @scalar/openapi-parser
## 0.8.2
### Patch Changes
- 6bb85a5: feat: `openapi()` returns dynamic types based on the chained commands
## 0.8.1

@@ -4,0 +10,0 @@

2

dist/index.js

@@ -1,1 +0,1 @@

export{ERRORS,OpenApiSpecifications,OpenApiVersions}from"./configuration/index.js";export{Validator,jsonSchemaVersions}from"./lib/Validator/Validator.js";export{resolveReferences}from"./utils/resolveReferences.js";export{dereference}from"./utils/dereference.js";export{details}from"./utils/details.js";export{escapeJsonPointer}from"./utils/escapeJsonPointer.js";export{filter}from"./utils/filter.js";export{getEntrypoint}from"./utils/getEntrypoint.js";export{getListOfReferences}from"./utils/getListOfReferences.js";export{getSegmentsFromPath}from"./utils/getSegmentsFromPath.js";export{isFilesystem}from"./utils/isFilesystem.js";export{isJson}from"./utils/isJson.js";export{isObject}from"./utils/isObject.js";export{isYaml}from"./utils/isYaml.js";export{load}from"./utils/load/load.js";export{normalize}from"./utils/normalize.js";export{openapi}from"./utils/openapi.js";export{toJson}from"./utils/toJson.js";export{toYaml}from"./utils/toYaml.js";export{transformErrors}from"./utils/transformErrors.js";export{traverse}from"./utils/traverse.js";export{unescapeJsonPointer}from"./utils/unescapeJsonPointer.js";export{upgrade}from"./utils/upgrade.js";export{upgradeFromThreeToThreeOne}from"./utils/upgradeFromThreeToThreeOne.js";export{upgradeFromTwoToThree}from"./utils/upgradeFromTwoToThree.js";export{validate}from"./utils/validate.js";
export{ERRORS,OpenApiSpecifications,OpenApiVersions}from"./configuration/index.js";export{Validator,jsonSchemaVersions}from"./lib/Validator/Validator.js";export{resolveReferences}from"./utils/resolveReferences.js";export{dereference}from"./utils/dereference.js";export{details}from"./utils/details.js";export{escapeJsonPointer}from"./utils/escapeJsonPointer.js";export{filter}from"./utils/filter.js";export{getEntrypoint}from"./utils/getEntrypoint.js";export{getListOfReferences}from"./utils/getListOfReferences.js";export{getSegmentsFromPath}from"./utils/getSegmentsFromPath.js";export{isFilesystem}from"./utils/isFilesystem.js";export{isJson}from"./utils/isJson.js";export{isObject}from"./utils/isObject.js";export{isYaml}from"./utils/isYaml.js";export{load}from"./utils/load/load.js";export{normalize}from"./utils/normalize.js";export{openapi}from"./utils/openapi/openapi.js";export{toJson}from"./utils/toJson.js";export{toYaml}from"./utils/toYaml.js";export{transformErrors}from"./utils/transformErrors.js";export{traverse}from"./utils/traverse.js";export{unescapeJsonPointer}from"./utils/unescapeJsonPointer.js";export{upgrade}from"./utils/upgrade.js";export{upgradeFromThreeToThreeOne}from"./utils/upgradeFromThreeToThreeOne.js";export{upgradeFromTwoToThree}from"./utils/upgradeFromTwoToThree.js";export{validate}from"./utils/validate.js";

@@ -13,3 +13,3 @@ import Ajv04 from 'ajv-draft-04';

export declare class Validator {
version: string;
version: '2.0' | '3.0' | '3.1';
static supportedVersions: ("2.0" | "3.0" | "3.1")[];

@@ -16,0 +16,0 @@ protected ajvValidators: Record<string, ((specification: AnyObject) => boolean) & {

import type { OpenAPI } from '@scalar/openapi-types';
import type { ERRORS, OpenApiVersion } from '../configuration/index.js';
/**
* Merge types with each other
*/
export type Merge<A, B> = A & Omit<B, keyof A>;
export type AnyObject = Record<string, any>;
/**
* JSON, YAML or object representation of an OpenAPI API definition
*/
export type AnyApiDefinitionFormat = string | AnyObject;
export type LoadResult = {
filesystem: Filesystem;
specification: AnyObject;
errors?: ErrorObject[];

@@ -11,3 +20,3 @@ };

specification?: OpenAPI.Document;
version?: string;
version?: OpenApiVersion;
errors?: ErrorObject[];

@@ -18,6 +27,6 @@ schema?: OpenAPI.Document;

specification: T;
version: string;
version: '3.1';
};
export type FilterResult = {
specification: OpenAPI.Document;
specification: AnyObject;
};

@@ -30,3 +39,3 @@ export type DetailsResult = {

export type DereferenceResult = {
version: string | undefined;
version?: OpenApiVersion;
specification?: OpenAPI.Document;

@@ -58,2 +67,6 @@ schema?: OpenAPI.Document;

};
/**
* Options, that can apply to all commands
*/
export type OpenApiOptions = ThrowOnErrorOption;
export type ThrowOnErrorOption = {

@@ -67,2 +80,58 @@ /**

};
declare global {
/**
* Available commands, can be extended dynamically
*/
interface Commands {
}
}
/**
* Input and a list of tasks to pipe the input through.
*/
export type Queue<T extends readonly Task[] = readonly Task[]> = {
/** The original input, can be a JSON or YAML string or an object */
input: AnyApiDefinitionFormat;
/** The current OpenAPI document, but as an object */
specification: AnyObject;
/** Global options */
options?: OpenApiOptions;
/** Queued tasks */
tasks: T;
};
/**
* Available tasks, populated from the global Commands interface
*/
export type Task = Commands[keyof Commands]['task'];
export type EmptyCommandChainResult = {
filesystem: Filesystem;
specification: AnyObject;
};
/**
* Command chain magic
*
* This type recursively builds a merged type based on the sequence of tasks.
*
* How it works:
* 1. It uses a conditional type with recursion to process the task array.
* 2. For each iteration:
* a. It extracts the first task (First) and the rest of the tasks (Rest).
* b. It checks if First is a valid Task and Rest is a Task array.
* c. If valid, it merges the Command type for the First task with the
* result of recursively processing the Rest of the tasks.
* 3. The recursion continues until the task array is empty.
* 4. When empty, it returns NonNullable<unknown> (equivalent to {}).
*
* Example:
* For tasks ['load', 'validate']:
* 1st iteration: Merge<Commands['load'], CommandChain<['validate']>>
* 2nd iteration: Merge<Commands['load'], Merge<Commands['validate'], NonNullable<unknown>>>
* Result: LoadResult & ValidateResult
*
* This type enables the API to correctly infer the return type based on
* the sequence of method calls in the fluent interface.
*/
export type CommandChain<T extends Task[]> = T extends [
infer First,
...infer Rest
] ? First extends Task ? Rest extends Task[] ? Merge<Commands[First['name']]['result'], CommandChain<Rest>> : never : never : EmptyCommandChainResult;
//# sourceMappingURL=index.d.ts.map

@@ -1,6 +0,7 @@

import type { AnyObject, DereferenceResult, Filesystem, ThrowOnErrorOption } from '../types';
import type { AnyApiDefinitionFormat, DereferenceResult, Filesystem, ThrowOnErrorOption } from '../types';
export type DereferenceOptions = ThrowOnErrorOption;
/**
* Validates an OpenAPI schema and resolves all references.
*/
export declare function dereference(value: string | AnyObject | Filesystem, options?: ThrowOnErrorOption): Promise<DereferenceResult>;
export declare function dereference(value: AnyApiDefinitionFormat | Filesystem, options?: DereferenceOptions): Promise<DereferenceResult>;
//# sourceMappingURL=dereference.d.ts.map

@@ -1,6 +0,7 @@

import type { AnyObject, FilterResult } from '../types';
import type { AnyApiDefinitionFormat, AnyObject, FilterResult } from '../types';
export type FilterCallback = (schema: AnyObject) => boolean;
/**
* Filter the specification based on the callback
*/
export declare function filter(specification: AnyObject, callback: (schema: AnyObject) => boolean): FilterResult;
export declare function filter(specification: AnyApiDefinitionFormat, callback: FilterCallback): FilterResult;
//# sourceMappingURL=filter.d.ts.map

@@ -1,6 +0,6 @@

import type { Filesystem } from '../types';
import type { Filesystem, FilesystemEntry } from '../types';
/**
* Return just the entrypoint of the filesystem.
*/
export declare function getEntrypoint(filesystem: Filesystem): import("../types").FilesystemEntry;
export declare function getEntrypoint(filesystem?: Filesystem): FilesystemEntry | undefined;
//# sourceMappingURL=getEntrypoint.d.ts.map

@@ -1,1 +0,1 @@

function n(n){return n.find((n=>n.isEntrypoint))}export{n as getEntrypoint};
function n(n){return n?.find((n=>n.isEntrypoint))}export{n as getEntrypoint};

@@ -15,3 +15,3 @@ export * from './dereference.js';

export * from './normalize.js';
export * from './openapi.js';
export * from './openapi';
export * from './resolveReferences.js';

@@ -18,0 +18,0 @@ export * from './toJson.js';

@@ -1,2 +0,2 @@

import type { Filesystem, LoadResult, ThrowOnErrorOption } from '../../types';
import type { AnyApiDefinitionFormat, Filesystem, LoadResult, ThrowOnErrorOption } from '../../types';
export type LoadPlugin = {

@@ -9,7 +9,17 @@ check: (value?: any) => boolean;

};
export declare function load(value: any, options?: {
export type LoadOptions = {
plugins?: LoadPlugin[];
filename?: string;
filesystem?: Filesystem;
} & ThrowOnErrorOption): Promise<LoadResult>;
} & ThrowOnErrorOption;
/**
* Loads an OpenAPI document, including any external references.
*
* This function handles loading content from various sources, normalizes the content,
* and recursively loads any external references found within the definition.
*
* It builds a filesystem representation of all loaded content and collects any errors
* encountered during the process.
*/
export declare function load(value: AnyApiDefinitionFormat, options?: LoadOptions): Promise<LoadResult>;
//# sourceMappingURL=load.d.ts.map

@@ -1,1 +0,1 @@

import{ERRORS as e}from"../../configuration/index.js";import{getEntrypoint as r}from"../getEntrypoint.js";import{getListOfReferences as s}from"../getListOfReferences.js";import{makeFilesystem as t}from"../makeFilesystem.js";import{normalize as n}from"../normalize.js";async function i(o,f){const m=[];if(f?.filesystem?.find((e=>e.filename===o)))return{filesystem:f.filesystem,errors:m};const l=f?.plugins?.find((e=>e.check(o)));let c;if(l)try{c=n(await l.get(o))}catch(r){if(f?.throwOnError)throw new Error(e.EXTERNAL_REFERENCE_NOT_FOUND.replace("%s",o));return m.push({code:"EXTERNAL_REFERENCE_NOT_FOUND",message:e.EXTERNAL_REFERENCE_NOT_FOUND.replace("%s",o)}),{filesystem:[],errors:m}}else c=n(o);if(void 0===c){if(f?.throwOnError)throw new Error("No content to load");return m.push({code:"NO_CONTENT",message:e.NO_CONTENT}),{filesystem:[],errors:m}}let E=t(c,{filename:f?.filename??null});const a=(f?.filename?E.find((e=>e.filename===f?.filename)):r(E)).references??s(c);if(0===a.length)return{filesystem:E,errors:m};for(const e of a){const r=f?.plugins?.find((r=>r.check(e)));if(!r)continue;const s=r.check(e)&&r.resolvePath?r.resolvePath(o,e):e;if(E.find((r=>r.filename===e)))continue;const{filesystem:t,errors:n}=await i(s,{...f,filename:e});m.push(...n),E=[...E,...t.map((e=>({...e,isEntrypoint:!1})))]}return{filesystem:E,errors:m}}export{i as load};
import{ERRORS as e}from"../../configuration/index.js";import{getEntrypoint as i}from"../getEntrypoint.js";import{getListOfReferences as r}from"../getListOfReferences.js";import{makeFilesystem as s}from"../makeFilesystem.js";import{normalize as t}from"../normalize.js";async function n(o,f){const c=[];if(f?.filesystem?.find((e=>e.filename===o)))return{specification:i(f.filesystem)?.specification,filesystem:f.filesystem,errors:c};const l=f?.plugins?.find((e=>e.check(o)));let a;if(l)try{a=t(await l.get(o))}catch(i){if(f?.throwOnError)throw new Error(e.EXTERNAL_REFERENCE_NOT_FOUND.replace("%s",o));return c.push({code:"EXTERNAL_REFERENCE_NOT_FOUND",message:e.EXTERNAL_REFERENCE_NOT_FOUND.replace("%s",o)}),{specification:null,filesystem:[],errors:c}}else a=t(o);if(void 0===a){if(f?.throwOnError)throw new Error("No content to load");return c.push({code:"NO_CONTENT",message:e.NO_CONTENT}),{specification:null,filesystem:[],errors:c}}let m=s(a,{filename:f?.filename??null});const E=(f?.filename?m.find((e=>e.filename===f?.filename)):i(m)).references??r(a);if(0===E.length)return{specification:i(m)?.specification,filesystem:m,errors:c};for(const e of E){const i=f?.plugins?.find((i=>i.check(e)));if(!i)continue;const r=i.check(e)&&i.resolvePath?i.resolvePath(o,e):e;if(m.find((i=>i.filename===e)))continue;const{filesystem:s,errors:t}=await n(r,{...f,filename:e});c.push(...t),m=[...m,...s.map((e=>({...e,isEntrypoint:!1})))]}return{specification:i(m)?.specification,filesystem:m,errors:c}}export{n as load};

@@ -6,3 +6,3 @@ import type { OpenAPIV3_1 } from '@scalar/openapi-types';

*/
export declare function upgrade(value: string | AnyObject | Filesystem, _options?: AnyObject): UpgradeResult<OpenAPIV3_1.Document>;
export declare function upgrade(value: string | AnyObject | Filesystem): UpgradeResult<OpenAPIV3_1.Document>;
//# sourceMappingURL=upgrade.d.ts.map

@@ -1,1 +0,1 @@

import{getEntrypoint as r}from"./getEntrypoint.js";import{makeFilesystem as e}from"./makeFilesystem.js";import{upgradeFromThreeToThreeOne as o}from"./upgradeFromThreeToThreeOne.js";import{upgradeFromTwoToThree as i}from"./upgradeFromTwoToThree.js";function t(t,m){return{specification:[i,o].reduce(((r,e)=>e(r)),r(e(t)).specification),version:"3.1"}}export{t as upgrade};
import{getEntrypoint as r}from"./getEntrypoint.js";import{makeFilesystem as e}from"./makeFilesystem.js";import{upgradeFromThreeToThreeOne as o}from"./upgradeFromThreeToThreeOne.js";import{upgradeFromTwoToThree as i}from"./upgradeFromTwoToThree.js";function t(t){return{specification:[i,o].reduce(((r,e)=>e(r)),r(e(t)).specification),version:"3.1"}}export{t as upgrade};
import type { AnyObject, Filesystem, ThrowOnErrorOption, ValidateResult } from '../types';
export type ValidateOptions = ThrowOnErrorOption;
/**
* Validates an OpenAPI schema.
*/
export declare function validate(value: string | AnyObject | Filesystem, options?: ThrowOnErrorOption): Promise<ValidateResult>;
export declare function validate(value: string | AnyObject | Filesystem, options?: ValidateOptions): Promise<ValidateResult>;
//# sourceMappingURL=validate.d.ts.map

@@ -20,3 +20,3 @@ {

],
"version": "0.8.1",
"version": "0.8.2",
"engines": {

@@ -67,3 +67,3 @@ "node": ">=18"

"tinybench": "^2.8.0",
"@scalar/openapi-types": "0.1.0"
"@scalar/openapi-types": "0.1.1"
},

@@ -70,0 +70,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc