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

apibuilder-js

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apibuilder-js - npm Package Compare versions

Comparing version 0.0.12 to 0.0.13

39

dist/type/definition.d.ts

@@ -119,2 +119,17 @@ import { FullyQualifiedName } from '../language';

get deprecationReason(): string | undefined;
/**
* Returns a list of unions where this type is present as a union type.
*/
get unions(): ApiBuilderUnion[];
/**
* Returns name for the type discriminator field when this type is present
* as a union type for one or more unions.
*/
get discriminator(): string | undefined;
/**
* Returns the string to use in the discriminator field to identify this type
* when present as a union type for one more unions.
*/
get discriminatorValue(): string | undefined;
isSame(type: ApiBuilderType): boolean;
toString(): string;

@@ -326,4 +341,22 @@ }

get isDeprecated(): boolean;
/**
* Returns a list of unions where this type is present as a union type.
*/
get unions(): ApiBuilderUnion[];
/**
* Returns name for the type discriminator field when this type is present
* as a union type for one or more unions.
*/
get discriminator(): string | undefined;
/**
* Returns the string to use in the discriminator field to identify this type
* when present as a union type for one more unions.
*/
get discriminatorValue(): string | undefined;
get description(): string | undefined;
get fields(): ApiBuilderField[];
/**
* Returns whether the specified type is the same as this model type.
*/
isSame(type: ApiBuilderType): boolean;
toString(): string;

@@ -379,3 +412,3 @@ }

*/
getResponseTypeByCode(responseCode: number, useDefault?: boolean): ApiBuilderArray | ApiBuilderPrimitiveType | ApiBuilderMap | ApiBuilderModel | ApiBuilderEnum | ApiBuilderUnion | undefined;
getResponseTypeByCode(responseCode: number, useDefault?: boolean): ApiBuilderEnum | ApiBuilderArray | ApiBuilderMap | ApiBuilderModel | ApiBuilderPrimitiveType | ApiBuilderUnion | undefined;
}

@@ -536,4 +569,4 @@ export interface ApiBuilderOrganizationConfig {

get unions(): ApiBuilderUnion[];
get typesByFullName(): Record<string, ApiBuilderModel | ApiBuilderEnum | ApiBuilderUnion>;
get typesByShortName(): Record<string, ApiBuilderModel | ApiBuilderEnum | ApiBuilderUnion>;
get typesByFullName(): Record<string, ApiBuilderEnum | ApiBuilderModel | ApiBuilderUnion>;
get typesByShortName(): Record<string, ApiBuilderEnum | ApiBuilderModel | ApiBuilderUnion>;
get resources(): ApiBuilderResource[];

@@ -540,0 +573,0 @@ get baseUrl(): string | undefined;

@@ -10,2 +10,3 @@ "use strict";

var language_1 = require("../language");
var predicates_1 = require("./predicates");
function findTypeByName(types, name) {

@@ -177,2 +178,64 @@ return types.find(lodash_1.overSome([

});
Object.defineProperty(ApiBuilderEnum.prototype, "unions", {
/**
* Returns a list of unions where this type is present as a union type.
*/
get: function () {
var _this = this;
return this.service.unions.filter(function (union) {
return union.types.some(function (unionType) {
return _this.isSame(unionType.type);
});
});
},
enumerable: true,
configurable: true
});
Object.defineProperty(ApiBuilderEnum.prototype, "discriminator", {
/**
* Returns name for the type discriminator field when this type is present
* as a union type for one or more unions.
*/
get: function () {
var discriminators = this.unions.map(function (union) {
return union.discriminator;
}).filter(function (discriminator, index, self) {
return self.indexOf(discriminator) === index;
});
if (discriminators.length > 1) {
throw new Error('Name for the type discriminator field must be the same across all unions');
}
return discriminators.length ? discriminators[0] : undefined;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ApiBuilderEnum.prototype, "discriminatorValue", {
/**
* Returns the string to use in the discriminator field to identify this type
* when present as a union type for one more unions.
*/
get: function () {
var _this = this;
var discriminatorValues = this.unions.reduce(function (self, union) {
return self.concat(union.types.filter(function (unionType) {
return _this.isSame(unionType.type);
}).map(function (unionType) {
return unionType.discriminatorValue;
}));
// tslint:disable-next-line: align
}, []).filter(function (value, index, self) {
return self.indexOf(value) === index;
});
if (discriminatorValues.length > 1) {
throw new Error('Discriminator value must the same across all union types');
}
return discriminatorValues.length ? discriminatorValues[0] : undefined;
},
enumerable: true,
configurable: true
});
ApiBuilderEnum.prototype.isSame = function (type) {
return predicates_1.isEnumType(type) && type.fullName === this.fullName;
};
ApiBuilderEnum.prototype.toString = function () {

@@ -588,2 +651,61 @@ return this.fullName;

});
Object.defineProperty(ApiBuilderModel.prototype, "unions", {
/**
* Returns a list of unions where this type is present as a union type.
*/
get: function () {
var _this = this;
return this.service.unions.filter(function (union) {
return union.types.some(function (unionType) {
return _this.isSame(unionType.type);
});
});
},
enumerable: true,
configurable: true
});
Object.defineProperty(ApiBuilderModel.prototype, "discriminator", {
/**
* Returns name for the type discriminator field when this type is present
* as a union type for one or more unions.
*/
get: function () {
var discriminators = this.unions.map(function (union) {
return union.discriminator;
}).filter(function (discriminator, index, self) {
return self.indexOf(discriminator) === index;
});
if (discriminators.length > 1) {
throw new Error('Name for the type discriminator field must be the same across all unions');
}
return discriminators.length ? discriminators[0] : undefined;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ApiBuilderModel.prototype, "discriminatorValue", {
/**
* Returns the string to use in the discriminator field to identify this type
* when present as a union type for one more unions.
*/
get: function () {
var _this = this;
var discriminatorValues = this.unions.reduce(function (self, union) {
return self.concat(union.types.filter(function (unionType) {
return _this.isSame(unionType.type);
}).map(function (unionType) {
return unionType.discriminatorValue;
}));
// tslint:disable-next-line: align
}, []).filter(function (value, index, self) {
return self.indexOf(value) === index;
});
if (discriminatorValues.length > 1) {
throw new Error('Discriminator value must the same across all union types');
}
return discriminatorValues.length ? discriminatorValues[0] : undefined;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ApiBuilderModel.prototype, "description", {

@@ -604,2 +726,8 @@ get: function () {

});
/**
* Returns whether the specified type is the same as this model type.
*/
ApiBuilderModel.prototype.isSame = function (type) {
return predicates_1.isModelType(type) && type.fullName === this.fullName;
};
ApiBuilderModel.prototype.toString = function () {

@@ -606,0 +734,0 @@ return this.fullName;

2

package.json
{
"name": "apibuilder-js",
"version": "0.0.12",
"version": "0.0.13",
"description": "A reference implementation of API Builder for JavaScript",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -6,2 +6,3 @@ import { camelCase, flatMap, map, matchesProperty, overSome, snakeCase, toUpper, upperFirst } from 'lodash';

import { astFromTypeName, FullyQualifiedName, typeFromAst } from '../language';
import { isModelType, isEnumType } from './predicates';

@@ -247,2 +248,58 @@ /**

/**
* Returns a list of unions where this type is present as a union type.
*/
get unions(): ApiBuilderUnion[] {
return this.service.unions.filter((union) => {
return union.types.some((unionType) => {
return this.isSame(unionType.type);
});
});
}
/**
* Returns name for the type discriminator field when this type is present
* as a union type for one or more unions.
*/
get discriminator() {
const discriminators = this.unions.map((union) => {
return union.discriminator;
}).filter((discriminator, index, self) => {
return self.indexOf(discriminator) === index;
});
if (discriminators.length > 1) {
throw new Error('Name for the type discriminator field must be the same across all unions');
}
return discriminators.length ? discriminators[0] : undefined;
}
/**
* Returns the string to use in the discriminator field to identify this type
* when present as a union type for one more unions.
*/
get discriminatorValue() {
const discriminatorValues = this.unions.reduce<string[]>((self, union) => {
return self.concat(union.types.filter((unionType) => {
return this.isSame(unionType.type);
}).map((unionType) => {
return unionType.discriminatorValue;
}));
// tslint:disable-next-line: align
}, []).filter((value, index, self) => {
return self.indexOf(value) === index;
});
if (discriminatorValues.length > 1) {
throw new Error('Discriminator value must the same across all union types');
}
return discriminatorValues.length ? discriminatorValues[0] : undefined;
}
public isSame(type: ApiBuilderType): boolean {
return isEnumType(type) && type.fullName === this.fullName;
}
public toString() {

@@ -695,2 +752,54 @@ return this.fullName;

/**
* Returns a list of unions where this type is present as a union type.
*/
get unions(): ApiBuilderUnion[] {
return this.service.unions.filter((union) => {
return union.types.some((unionType) => {
return this.isSame(unionType.type);
});
});
}
/**
* Returns name for the type discriminator field when this type is present
* as a union type for one or more unions.
*/
get discriminator() {
const discriminators = this.unions.map((union) => {
return union.discriminator;
}).filter((discriminator, index, self) => {
return self.indexOf(discriminator) === index;
});
if (discriminators.length > 1) {
throw new Error('Name for the type discriminator field must be the same across all unions');
}
return discriminators.length ? discriminators[0] : undefined;
}
/**
* Returns the string to use in the discriminator field to identify this type
* when present as a union type for one more unions.
*/
get discriminatorValue() {
const discriminatorValues = this.unions.reduce<string[]>((self, union) => {
return self.concat(union.types.filter((unionType) => {
return this.isSame(unionType.type);
}).map((unionType) => {
return unionType.discriminatorValue;
}));
// tslint:disable-next-line: align
}, []).filter((value, index, self) => {
return self.indexOf(value) === index;
});
if (discriminatorValues.length > 1) {
throw new Error('Discriminator value must the same across all union types');
}
return discriminatorValues.length ? discriminatorValues[0] : undefined;
}
get description() {

@@ -704,2 +813,9 @@ return this.config.description;

/**
* Returns whether the specified type is the same as this model type.
*/
public isSame(type: ApiBuilderType): boolean {
return isModelType(type) && type.fullName === this.fullName;
}
public toString() {

@@ -706,0 +822,0 @@ return this.fullName;

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