@userscripters/stackexchange-api-types
Advanced tools
Comparing version 3.2.1 to 3.2.2
@@ -66,2 +66,39 @@ import type { | ||
export type ModuleDeclarationOptions = { | ||
exported?: boolean; | ||
isAmbient?: boolean; | ||
isNamespace?: boolean; | ||
}; | ||
/** | ||
* @summary creates a module declaration | ||
* @param f compiler factory to use | ||
* @param name identifier to create the module with | ||
* @param statements statements to make up the body | ||
* @param options configuration | ||
*/ | ||
export const createModuleDeclaration = ( | ||
f: NodeFactory, | ||
name: string | Identifier, | ||
statements: Statement[], | ||
{ | ||
exported = false, | ||
isNamespace = false, | ||
isAmbient = false, | ||
}: ModuleDeclarationOptions = {} | ||
) => { | ||
const modifiers: Modifier[] = []; | ||
if (exported) modifiers.push(f.createModifier(ts.SyntaxKind.ExportKeyword)); | ||
if (isAmbient) | ||
modifiers.push(f.createModifier(ts.SyntaxKind.DeclareKeyword)); | ||
return f.createModuleDeclaration( | ||
undefined, | ||
modifiers, | ||
typeof name === "string" ? f.createIdentifier(name) : name, | ||
f.createModuleBlock(statements), | ||
isNamespace ? ts.NodeFlags.Namespace : void 0 | ||
); | ||
}; | ||
export type NamespaceOptions = { | ||
@@ -76,3 +113,3 @@ exported?: boolean; | ||
* @param name identifier to create the namespace with | ||
* @param statements statements to go | ||
* @param statements statements to make up the body | ||
* @param options configuration | ||
@@ -89,9 +126,6 @@ */ | ||
return f.createModuleDeclaration( | ||
undefined, | ||
modifiers, | ||
typeof name === "string" ? f.createIdentifier(name) : name, | ||
f.createModuleBlock(statements), | ||
ts.NodeFlags.Namespace | ||
); | ||
return createModuleDeclaration(f, name, statements, { | ||
exported, | ||
isNamespace: true, | ||
}); | ||
}; | ||
@@ -98,0 +132,0 @@ |
import type { NodeFactory } from "typescript"; | ||
import ts from "typescript"; | ||
import { createNamespace, createStringUnion } from "./factories.js"; | ||
import { | ||
createModuleDeclaration, | ||
createNamespace, | ||
createStringUnion, | ||
} from "./factories.js"; | ||
import { printNodesToFile } from "./printer.js"; | ||
import { getDocument, normalizeFilterName } from "./utils.js"; | ||
const addGlobalModifyingVersion = ( | ||
factory: NodeFactory, | ||
namespaceName: string, | ||
filters: string[] | ||
) => { | ||
const union = createStringUnion(factory, "BuiltIn", filters); | ||
const ns = createNamespace(factory, namespaceName, [union]); | ||
const commonNS = createNamespace(factory, "StackExchangeAPI", [ns]); | ||
return createModuleDeclaration(factory, "global", [commonNS], { | ||
isAmbient: true, | ||
}); | ||
}; | ||
/** | ||
@@ -41,11 +58,17 @@ * @see https://api.stackexchange.com/docs/filters | ||
const filtersEnum = createStringUnion(factory, "BuiltIn", filters, { | ||
const union = createStringUnion(factory, "BuiltIn", filters, { | ||
exported: true, | ||
}); | ||
const namespace = createNamespace(factory, namespaceName, [filtersEnum], { | ||
const ns = createNamespace(factory, namespaceName, [union], { | ||
exported: true, | ||
}); | ||
return printNodesToFile(ts, [namespace], filePath); | ||
const global = addGlobalModifyingVersion(factory, namespaceName, filters); | ||
return printNodesToFile( | ||
ts, | ||
[ns, factory.createIdentifier("\n"), global], | ||
filePath | ||
); | ||
}; |
@@ -1,2 +0,2 @@ | ||
import F from "./lib/filters"; | ||
import "./lib/filters"; | ||
import { Wrappers } from "./lib/wrapper"; | ||
@@ -7,9 +7,7 @@ | ||
export import CommonWrapperObject = Wrappers.CommonWrapperObject; | ||
export import Filters = F.Filters; | ||
} | ||
} | ||
export * from "./lib/filters"; | ||
export * from "./lib/types"; | ||
export * from "./lib/wrapper"; | ||
export as namespace StackExchangeAPI; |
export namespace Filters { | ||
export type BuiltIn = "default" | "withbody" | "default" | "none" | "total"; | ||
} | ||
declare module global { | ||
namespace StackExchangeAPI { | ||
namespace Filters { | ||
type BuiltIn = "default" | "withbody" | "default" | "none" | "total"; | ||
} | ||
} | ||
} |
{ | ||
"name": "@userscripters/stackexchange-api-types", | ||
"description": "Stack Exchange API types generator", | ||
"version": "3.2.1", | ||
"version": "3.2.2", | ||
"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.2.1 | | ||
| Version | 3.2.2 | | ||
@@ -12,0 +12,0 @@ # Support |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47505
1275