Socket
Socket
Sign inDemoInstall

conjure-typescript

Package Overview
Dependencies
178
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.9.0 to 4.10.0

13

lib/commands/generate/typeGenerator.d.ts

@@ -23,5 +23,14 @@ /**

* ```
* export type EnumExample = "ONE" | "TWO";
* export const EnumExample = { ONE: "ONE" as "ONE", TWO: "TWO" as "TWO" };
* export namespace EnumExample {
* export type ONE = "ONE";
* export type TWO = "TWO";
*
* export const ONE = "ONE" as "ONE";
* export const TWO = "TWO" as "TWO";
* }
* export type EnumExample = keyof typeof EnumExample;
* ```
*
* We do not use TypeScript Enums because they can not be assigned to an equivalent enum, making interop across
* libraries more difficult
*/

@@ -28,0 +37,0 @@ export declare function generateEnum(definition: IEnumDefinition, simpleAst: SimpleAst): Promise<void>;

40

lib/commands/generate/typeGenerator.js

@@ -81,20 +81,44 @@ "use strict";

* ```
* export type EnumExample = "ONE" | "TWO";
* export const EnumExample = { ONE: "ONE" as "ONE", TWO: "TWO" as "TWO" };
* export namespace EnumExample {
* export type ONE = "ONE";
* export type TWO = "TWO";
*
* export const ONE = "ONE" as "ONE";
* export const TWO = "TWO" as "TWO";
* }
* export type EnumExample = keyof typeof EnumExample;
* ```
*
* We do not use TypeScript Enums because they can not be assigned to an equivalent enum, making interop across
* libraries more difficult
*/
function generateEnum(definition, simpleAst) {
return __awaiter(this, void 0, void 0, function () {
var sourceFile;
var sourceFile, namespaceDefinition;
return __generator(this, function (_a) {
sourceFile = simpleAst.createSourceFile(definition.typeName);
sourceFile.addEnum({
docs: definition.docs != null ? [{ description: definition.docs }] : undefined,
namespaceDefinition = sourceFile.addNamespace({
isExported: true,
members: definition.values.map(function (enumValue) { return ({
name: definition.typeName.name,
typeAliases: definition.values.map(function (enumValue) { return ({
isExported: true,
name: enumValue.value,
type: utils_1.doubleQuote(enumValue.value),
docs: utils_1.addDeprecatedToDocs(enumValue),
name: enumValue.value,
value: enumValue.value,
}); }),
bodyText: function (writer) {
definition.values.forEach(function (_a) {
var value = _a.value;
var quotedValue = utils_1.doubleQuote(value);
writer.writeLine("export const " + value + " = " + quotedValue + " as " + quotedValue + ";");
});
},
});
if (definition.docs != null) {
namespaceDefinition.addJsDoc(definition.docs);
}
sourceFile.addTypeAlias({
isExported: true,
name: definition.typeName.name,
type: "keyof typeof " + definition.typeName.name,
});

@@ -101,0 +125,0 @@ sourceFile.formatText();

{
"name": "conjure-typescript",
"version": "4.9.0",
"version": "4.10.0",
"description": "A conjure generator for Typescript",

@@ -5,0 +5,0 @@ "bin": {

@@ -53,5 +53,14 @@ /**

* ```
* export type EnumExample = "ONE" | "TWO";
* export const EnumExample = { ONE: "ONE" as "ONE", TWO: "TWO" as "TWO" };
* export namespace EnumExample {
* export type ONE = "ONE";
* export type TWO = "TWO";
*
* export const ONE = "ONE" as "ONE";
* export const TWO = "TWO" as "TWO";
* }
* export type EnumExample = keyof typeof EnumExample;
* ```
*
* We do not use TypeScript Enums because they can not be assigned to an equivalent enum, making interop across
* libraries more difficult
*/

@@ -61,11 +70,26 @@ export async function generateEnum(definition: IEnumDefinition, simpleAst: SimpleAst): Promise<void> {

sourceFile.addEnum({
docs: definition.docs != null ? [{ description: definition.docs }] : undefined,
const namespaceDefinition = sourceFile.addNamespace({
isExported: true,
members: definition.values.map(enumValue => ({
name: definition.typeName.name,
typeAliases: definition.values.map(enumValue => ({
isExported: true,
name: enumValue.value,
type: doubleQuote(enumValue.value),
docs: addDeprecatedToDocs(enumValue),
name: enumValue.value,
value: enumValue.value,
})),
bodyText: writer => {
definition.values.forEach(({ value }) => {
const quotedValue = doubleQuote(value);
writer.writeLine(`export const ${value} = ${quotedValue} as ${quotedValue};`);
});
},
});
if (definition.docs != null) {
namespaceDefinition.addJsDoc(definition.docs);
}
sourceFile.addTypeAlias({
isExported: true,
name: definition.typeName.name,
type: `keyof typeof ${definition.typeName.name}`,
});

@@ -72,0 +96,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc