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

@userscripters/stackexchange-api-types

Package Overview
Dependencies
Maintainers
3
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@userscripters/stackexchange-api-types - npm Package Compare versions

Comparing version 3.3.0 to 3.4.0

10

generator/errors.ts

@@ -31,2 +31,3 @@ import type { NodeFactory } from "typescript";

* @param namespaceName namespace name
* @param globalNsName namespace name added to the UMD module
*/

@@ -38,3 +39,4 @@ export const generateErrors = async (

filePath: string,
namespaceName: string
namespaceName: string,
globalNsName: string
) => {

@@ -63,5 +65,7 @@ const document = await getDocument(base, path);

const ns = createNamespace(factory, "Errors", nodes, { exported: true });
const ns = createNamespace(factory, namespaceName, nodes, {
exported: true,
});
const global = addGlobalModifyingVersion(factory, namespaceName, [ns]);
const global = addGlobalModifyingVersion(factory, globalNsName, [ns]);

@@ -68,0 +72,0 @@ return printNodesToFile(

@@ -210,1 +210,27 @@ import type {

};
/**
* @summary creates a named import with a list of import specifiers
* @param f compiler factory to use
* @param specifier module specifier (reference)
* @param names list of import specifier names
*/
export const createNamedImport = (
f: NodeFactory,
specifier: string,
names: string[]
) => {
const specifiers = names.map((name) => {
return f.createImportSpecifier(
void -0,
typeof name === "string" ? f.createIdentifier(name) : name
);
});
return f.createImportDeclaration(
undefined,
undefined,
f.createImportClause(true, undefined, f.createNamedImports(specifiers)),
f.createStringLiteral(specifier)
);
};

@@ -11,5 +11,13 @@ import type { NodeFactory } from "typescript";

/**
* @summary adds a global-modifying version of the module
* @param factory compiler factory to use
* @param namespaceName namespace name
* @param globalNsName namespace name added to the UMD module
* @param filters array of filter names
*/
const addGlobalModifyingVersion = (
factory: NodeFactory,
namespaceName: string,
globalNsName: string,
filters: string[]

@@ -19,3 +27,3 @@ ) => {

const ns = createNamespace(factory, namespaceName, [union]);
const commonNS = createNamespace(factory, "StackExchangeAPI", [ns]);
const commonNS = createNamespace(factory, globalNsName, [ns]);
return createModuleDeclaration(factory, "global", [commonNS], {

@@ -35,2 +43,3 @@ isAmbient: true,

* @param namespaceName namespace name
* @param globalNsName namespace name added to the UMD module
*/

@@ -42,3 +51,4 @@ export const generateBuiltInFilters = async (

filePath: string,
namespaceName: string
namespaceName: string,
globalNsName: string
) => {

@@ -71,3 +81,8 @@ const document = await getDocument(base, path);

const global = addGlobalModifyingVersion(factory, namespaceName, filters);
const global = addGlobalModifyingVersion(
factory,
namespaceName,
globalNsName,
filters
);

@@ -74,0 +89,0 @@ return printNodesToFile(

@@ -31,30 +31,53 @@ import got from "got";

await generateResponseWrapper(
factory,
DOCS_BASE,
"/docs/wrapper",
`${TYPES_PATH}/wrapper.d.ts`,
typeNameSel,
typeFieldsSel,
typeReqSel,
unionRegex,
"Wrappers"
);
const generate = {
wrapper: true,
filters: true,
errors: true,
types: true,
};
await generateBuiltInFilters(
factory,
DOCS_BASE,
"/docs/filters",
`${TYPES_PATH}/filters.d.ts`,
"Filters"
);
if (generate.wrapper) {
await generateResponseWrapper(
factory,
DOCS_BASE,
"/docs/wrapper",
`${TYPES_PATH}/wrapper.d.ts`,
typeNameSel,
typeFieldsSel,
typeReqSel,
unionRegex,
"Wrappers"
);
}
await generateErrors(
factory,
DOCS_BASE,
"/docs/error-handling",
`${TYPES_PATH}/errors.d.ts`,
nsName
);
if (generate.filters) {
await generateBuiltInFilters(
factory,
DOCS_BASE,
"/docs/filters",
`${TYPES_PATH}/filters.d.ts`,
"Filters",
nsName
);
}
await generateTypes(factory, DOCS_BASE, `${TYPES_PATH}/types.d.ts`, nsName);
if (generate.errors) {
await generateErrors(
factory,
DOCS_BASE,
"/docs/error-handling",
`${TYPES_PATH}/errors.d.ts`,
"Errors",
nsName
);
}
if (generate.types) {
await generateTypes(
factory,
DOCS_BASE,
"/docs",
`${TYPES_PATH}/types.d.ts`,
nsName
);
}

@@ -8,2 +8,3 @@ import type {

TypeParameterDeclaration,
TypeReferenceNode,
} from "typescript";

@@ -92,3 +93,6 @@ import ts from "typescript";

exported?: boolean;
overrides?: Record<string, KeywordTypeNode | ArrayTypeNode>;
overrides?: Record<
string,
KeywordTypeNode | ArrayTypeNode | TypeReferenceNode
>;
parameters?: TypeParameterDeclaration[];

@@ -136,3 +140,10 @@ };

const override = overrides[fieldName];
return override ? createProperty(factory, fieldName, override) : field;
return override
? createProperty(
factory,
fieldName,
override,
!!field.questionToken
)
: field;
});

@@ -139,0 +150,0 @@

@@ -20,9 +20,13 @@ import type { NodeFactory, __String } from "typescript";

/**
* @summary generates API types
*/
export const generateTypes = async (
factory: NodeFactory,
base: string,
path: string,
filePath: string,
namespaceName: string
) => {
const document = await getDocument(base, "/docs", {
const document = await getDocument(base, path, {
hash: "docs",

@@ -29,0 +33,0 @@ parameters: { tab: "type" },

@@ -5,2 +5,3 @@ import type { NodeFactory } from "typescript";

createKeywordArray,
createNamedImport,
createNamespace,

@@ -11,3 +12,3 @@ createTypeParameter,

import { printNodesToFile } from "./printer.js";
import { getDocument } from "./utils.js";
import { getDocument, interleave } from "./utils.js";

@@ -58,2 +59,4 @@ /**

items: createKeywordArray(factory, typeParameterName),
error_name: factory.createTypeReferenceNode("Errors.Name"),
error_id: factory.createTypeReferenceNode("Errors.Code"),
},

@@ -65,2 +68,4 @@ parameters: [typeParameter],

const errImports = createNamedImport(factory, "./errors", ["Errors"]);
const namespace = createNamespace(factory, namespaceName, [wrapper], {

@@ -70,5 +75,8 @@ exported: true,

const nodes: ts.Node[] = [namespace];
const nodes: ts.Node[] = interleave(
[errImports, namespace],
factory.createIdentifier("\n")
);
return printNodesToFile(ts, nodes, filePath);
};

@@ -0,7 +1,9 @@

import type { Errors } from "./errors";
export namespace Wrappers {
export interface CommonWrapperObject<T extends object = object> {
backoff?: number;
error_id?: number;
error_id?: Errors.Code;
error_message?: string;
error_name?: string;
error_name?: Errors.Name;
has_more: boolean;

@@ -8,0 +10,0 @@ items: T[];

{
"name": "@userscripters/stackexchange-api-types",
"description": "Stack Exchange API types generator",
"version": "3.3.0",
"version": "3.4.0",
"author": {

@@ -6,0 +6,0 @@ "name": "Oleg Valter",

@@ -9,3 +9,3 @@

| License | [GPL-3.0-or-later](https://spdx.org/licenses/GPL-3.0-or-later) |
| Version | 3.3.0 |
| Version | 3.4.0 |

@@ -12,0 +12,0 @@ # Support

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