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.7 to 0.0.8

1

dist/language/FullyQualifiedName.d.ts
import { AstNode } from './ast';
export declare function isFullyQualifiedName(identifier: string): boolean;
export declare function assertFullyQualifiedName(fullyQualifiedName: string): void;

@@ -3,0 +4,0 @@ /**

7

dist/language/FullyQualifiedName.js

@@ -10,5 +10,8 @@ "use strict";

var predicates_1 = require("./predicates");
function isFullyQualifiedName(identifier) {
return predicates_1.isPrimitiveTypeName(identifier) || getBaseTypeName(identifier).lastIndexOf('.') >= 0;
}
exports.isFullyQualifiedName = isFullyQualifiedName;
function assertFullyQualifiedName(fullyQualifiedName) {
invariant_1.default(getBaseTypeName(fullyQualifiedName).lastIndexOf('.') >= 0
|| predicates_1.isPrimitiveTypeName(fullyQualifiedName), "\"" + fullyQualifiedName + "\" is not a valid fully qualified name. "
invariant_1.default(isFullyQualifiedName(fullyQualifiedName), "\"" + fullyQualifiedName + "\" is not a valid fully qualified name. "
+ 'A fully qualified name may be the name of a primitive type, '

@@ -15,0 +18,0 @@ + 'or a string consisting of a package name followed by the base '

@@ -40,3 +40,3 @@ import { FullyQualifiedName } from '../../language';

readonly values: ApiBuilderEnumValue[];
readonly attributes: ReadonlyArray<ApiBuilderAttributeConfig>;
readonly attributes: readonly ApiBuilderAttributeConfig[];
readonly isDeprecated: boolean;

@@ -43,0 +43,0 @@ readonly deprecationReason: string | undefined;

@@ -33,3 +33,3 @@ import { ApiBuilderAttributeConfig } from './ApiBuilderAttribute';

*/
readonly attributes: ReadonlyArray<ApiBuilderAttributeConfig> | undefined;
readonly attributes: readonly ApiBuilderAttributeConfig[] | undefined;
/**

@@ -36,0 +36,0 @@ * This property holds whether this enum value is deprecated.

@@ -29,3 +29,3 @@ import { ApiBuilderAttributeConfig } from './ApiBuilderAttribute';

readonly maximum: number | undefined;
readonly attributes: ReadonlyArray<ApiBuilderAttributeConfig>;
readonly attributes: readonly ApiBuilderAttributeConfig[];
readonly isDeprecated: boolean;

@@ -32,0 +32,0 @@ readonly deprecationReason: string | undefined;

@@ -46,8 +46,8 @@ import { ApiBuilderDeprecationConfig } from './ApiBuilderDeprecation';

readonly type: import("./ApiBuilderType").ApiBuilderType;
readonly headers: ReadonlyArray<ApiBuilderHeaderConfig> | undefined;
readonly headers: readonly ApiBuilderHeaderConfig[] | undefined;
readonly description: string | undefined;
readonly isDeprecated: boolean;
readonly deprecationReason: string | undefined;
readonly attributes: ReadonlyArray<ApiBuilderAttributeConfig>;
readonly attributes: readonly ApiBuilderAttributeConfig[];
}
export {};

@@ -80,6 +80,12 @@ import { ApiBuilderAttributeConfig } from './ApiBuilderAttribute';

readonly unions: ApiBuilderUnion[];
readonly typesByFullName: Record<string, ApiBuilderModel | ApiBuilderEnum | ApiBuilderUnion>;
readonly typesByShortName: Record<string, ApiBuilderModel | ApiBuilderEnum | ApiBuilderUnion>;
readonly resources: ApiBuilderResource[];
readonly baseUrl: string | undefined;
/**
* Returns the type matching the specified identifier, or `undefined` otherwise.
* @param typeName
*/
findTypeByName(typeName: string): ApiBuilderEnum | ApiBuilderModel | ApiBuilderUnion | undefined;
toString(): string;
}

@@ -106,2 +106,42 @@ "use strict";

});
Object.defineProperty(ApiBuilderService.prototype, "typesByFullName", {
get: function () {
var typesByFullName = {};
this.enums.forEach(function (enumeration) {
typesByFullName[enumeration.fullName] = enumeration;
});
this.models.forEach(function (model) {
typesByFullName[model.fullName] = model;
});
this.unions.forEach(function (union) {
typesByFullName[union.fullName] = union;
});
Object.defineProperty(this, 'typesByFullName', {
value: typesByFullName,
});
return typesByFullName;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ApiBuilderService.prototype, "typesByShortName", {
get: function () {
var typesByShortName = {};
this.enums.forEach(function (enumeration) {
typesByShortName[enumeration.shortName] = enumeration;
});
this.models.forEach(function (model) {
typesByShortName[model.shortName] = model;
});
this.unions.forEach(function (union) {
typesByShortName[union.shortName] = union;
});
Object.defineProperty(this, 'typesByShortName', {
value: typesByShortName,
});
return typesByShortName;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ApiBuilderService.prototype, "resources", {

@@ -124,7 +164,13 @@ get: function () {

});
/**
* Returns the type matching the specified identifier, or `undefined` otherwise.
* @param typeName
*/
ApiBuilderService.prototype.findTypeByName = function (typeName) {
// By definition, a field or union type whose name is not fully qualified
// implies the type is defined internally, that is such type is not
// imported. In order to honor this rule, this utility will scan for
// internal types matching the provided name before scanning imported types.
if (this.typesByFullName[typeName] != null) {
return this.typesByFullName[typeName];
}
if (this.typesByShortName[typeName] != null) {
return this.typesByShortName[typeName];
}
var predicate = lodash_1.overSome([

@@ -134,6 +180,3 @@ lodash_1.matchesProperty('shortName', typeName),

]);
return (this.enums.find(predicate)
|| this.models.find(predicate)
|| this.unions.find(predicate)
|| lodash_1.flatMap(this.imports, 'enums').find(predicate)
return (lodash_1.flatMap(this.imports, 'enums').find(predicate)
|| lodash_1.flatMap(this.imports, 'models').find(predicate)

@@ -140,0 +183,0 @@ || lodash_1.flatMap(this.imports, 'unions').find(predicate));

@@ -35,4 +35,4 @@ import { ApiBuilderAttributeConfig } from './ApiBuilderAttribute';

readonly types: ApiBuilderUnionType[];
readonly attributes: ReadonlyArray<ApiBuilderAttributeConfig>;
readonly attributes: readonly ApiBuilderAttributeConfig[];
toString(): string;
}

@@ -28,3 +28,3 @@ import { ApiBuilderAttributeConfig } from './ApiBuilderAttribute';

readonly deprecation: ApiBuilderDeprecationConfig | undefined;
readonly attributes: ReadonlyArray<ApiBuilderAttributeConfig>;
readonly attributes: readonly ApiBuilderAttributeConfig[];
readonly default: boolean | undefined;

@@ -31,0 +31,0 @@ readonly discriminatorValue: string;

{
"name": "apibuilder-js",
"version": "0.0.7",
"version": "0.0.8",
"description": "A reference implementation of API Builder for JavaScript",

@@ -32,20 +32,20 @@ "main": "dist/index.js",

"invariant": "^2.2.4",
"lodash": "^4.17.11",
"pluralize": "^7.0.0"
"lodash": "^4.17.15",
"pluralize": "^8.0.0"
},
"devDependencies": {
"@types/faker": "^4.1.4",
"@types/invariant": "^2.2.29",
"@types/jest": "^23.3.10",
"@types/lodash": "^4.14.119",
"@types/node": "^10.12.12",
"@types/faker": "^4.1.5",
"@types/invariant": "^2.2.30",
"@types/jest": "^24.0.18",
"@types/lodash": "^4.14.141",
"@types/node": "^10.14.19",
"@types/pluralize": "0.0.29",
"faker": "^4.1.0",
"jest": "^23.6.0",
"jest": "^24.9.0",
"npm-run-all": "^4.1.5",
"ts-jest": "^23.10.5",
"tslint": "^5.11.0",
"tslint-config-airbnb": "^5.11.1",
"typescript": "^3.2.2"
"ts-jest": "^24.1.0",
"tslint": "^5.20.0",
"tslint-config-airbnb": "^5.11.2",
"typescript": "^3.6.3"
}
}

@@ -6,6 +6,9 @@ import invariant from 'invariant';

export function isFullyQualifiedName(identifier: string) {
return isPrimitiveTypeName(identifier) || getBaseTypeName(identifier).lastIndexOf('.') >= 0;
}
export function assertFullyQualifiedName(fullyQualifiedName: string) {
invariant(
getBaseTypeName(fullyQualifiedName).lastIndexOf('.') >= 0
|| isPrimitiveTypeName(fullyQualifiedName),
isFullyQualifiedName(fullyQualifiedName),
`"${fullyQualifiedName}" is not a valid fully qualified name. `

@@ -12,0 +15,0 @@ + 'A fully qualified name may be the name of a primitive type, '

@@ -134,2 +134,46 @@ import { flatMap, matchesProperty, overSome } from 'lodash';

get typesByFullName() {
const typesByFullName: Record<string, ApiBuilderEnum | ApiBuilderModel | ApiBuilderUnion> = {};
this.enums.forEach((enumeration) => {
typesByFullName[enumeration.fullName] = enumeration;
});
this.models.forEach((model) => {
typesByFullName[model.fullName] = model;
});
this.unions.forEach((union) => {
typesByFullName[union.fullName] = union;
});
Object.defineProperty(this, 'typesByFullName', {
value: typesByFullName,
});
return typesByFullName;
}
get typesByShortName() {
const typesByShortName: Record<string, ApiBuilderEnum | ApiBuilderModel | ApiBuilderUnion> = {};
this.enums.forEach((enumeration) => {
typesByShortName[enumeration.shortName] = enumeration;
});
this.models.forEach((model) => {
typesByShortName[model.shortName] = model;
});
this.unions.forEach((union) => {
typesByShortName[union.shortName] = union;
});
Object.defineProperty(this, 'typesByShortName', {
value: typesByShortName,
});
return typesByShortName;
}
get resources() {

@@ -145,7 +189,17 @@ const resources = this.config.resources.map(resource => new ApiBuilderResource(resource, this));

public findTypeByName(typeName: string): ApiBuilderEnum | ApiBuilderModel | ApiBuilderUnion | undefined {
// By definition, a field or union type whose name is not fully qualified
// implies the type is defined internally, that is such type is not
// imported. In order to honor this rule, this utility will scan for
// internal types matching the provided name before scanning imported types.
/**
* Returns the type matching the specified identifier, or `undefined` otherwise.
* @param typeName
*/
public findTypeByName(
typeName: string,
): ApiBuilderEnum | ApiBuilderModel | ApiBuilderUnion | undefined {
if (this.typesByFullName[typeName] != null) {
return this.typesByFullName[typeName];
}
if (this.typesByShortName[typeName] != null) {
return this.typesByShortName[typeName];
}
const predicate = overSome([

@@ -157,6 +211,3 @@ matchesProperty('shortName', typeName),

return (
this.enums.find(predicate)
|| this.models.find(predicate)
|| this.unions.find(predicate)
|| flatMap(this.imports, 'enums').find(predicate)
flatMap(this.imports, 'enums').find(predicate)
|| flatMap(this.imports, 'models').find(predicate)

@@ -163,0 +214,0 @@ || flatMap(this.imports, 'unions').find(predicate)

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