@userscripters/stackexchange-api-types
Advanced tools
Comparing version 3.2.4 to 3.3.0
@@ -171,3 +171,3 @@ import type { | ||
export type StringUnionOptions = { | ||
export type PrimitiveUnionOptions = { | ||
exported?: boolean; | ||
@@ -177,3 +177,3 @@ }; | ||
/** | ||
* @summary creates a string union node | ||
* @summary creates a union node with primitive members | ||
* @param f compiler factory to use | ||
@@ -183,7 +183,7 @@ * @param name identifier of the enum | ||
*/ | ||
export const createStringUnion = ( | ||
export const createUnionOfPrimitives = ( | ||
f: NodeFactory, | ||
name: string | Identifier, | ||
members: string[], | ||
{ exported = false }: StringUnionOptions = {} | ||
members: (string | number | boolean | bigint)[], | ||
{ exported = false }: PrimitiveUnionOptions = {} | ||
) => { | ||
@@ -193,5 +193,11 @@ const modifiers: Modifier[] = []; | ||
const hs = new Map(); | ||
hs.set("string", (v: string) => f.createStringLiteral(v)); | ||
hs.set("number", (v: number) => f.createNumericLiteral(v)); | ||
hs.set("boolean", (v: boolean) => (v ? f.createTrue() : f.createFalse())); | ||
hs.set("bigint", (v: ts.PseudoBigInt) => f.createBigIntLiteral(v)); | ||
const union = f.createUnionTypeNode( | ||
members.map((type) => | ||
f.createLiteralTypeNode(f.createStringLiteral(type)) | ||
f.createLiteralTypeNode(hs.get(typeof type)(type)) | ||
) | ||
@@ -198,0 +204,0 @@ ); |
@@ -6,3 +6,3 @@ import type { NodeFactory } from "typescript"; | ||
createNamespace, | ||
createStringUnion, | ||
createUnionOfPrimitives, | ||
} from "./factories.js"; | ||
@@ -17,3 +17,3 @@ import { printNodesToFile } from "./printer.js"; | ||
) => { | ||
const union = createStringUnion(factory, "BuiltIn", filters); | ||
const union = createUnionOfPrimitives(factory, "BuiltIn", filters); | ||
const ns = createNamespace(factory, namespaceName, [union]); | ||
@@ -61,3 +61,3 @@ const commonNS = createNamespace(factory, "StackExchangeAPI", [ns]); | ||
const union = createStringUnion(factory, "BuiltIn", filters, { | ||
const union = createUnionOfPrimitives(factory, "BuiltIn", filters, { | ||
exported: true, | ||
@@ -64,0 +64,0 @@ }); |
import got from "got"; | ||
import { generateErrors } from "./errors.js"; | ||
import { generateBuiltInFilters } from "./filters.js"; | ||
@@ -50,2 +51,10 @@ import { generateTypes } from "./types.js"; | ||
await generateErrors( | ||
factory, | ||
DOCS_BASE, | ||
"/docs/error-handling", | ||
`${TYPES_PATH}/errors.d.ts`, | ||
nsName | ||
); | ||
await generateTypes(factory, DOCS_BASE, `${TYPES_PATH}/types.d.ts`, nsName); |
@@ -0,1 +1,2 @@ | ||
import "./lib/errors"; | ||
import "./lib/filters"; | ||
@@ -2,0 +3,0 @@ import "./lib/types"; |
{ | ||
"name": "@userscripters/stackexchange-api-types", | ||
"description": "Stack Exchange API types generator", | ||
"version": "3.2.4", | ||
"version": "3.3.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.2.4 | | ||
| Version | 3.3.0 | | ||
@@ -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
74539
27
1994