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

@superfaceai/parser

Package Overview
Dependencies
Maintainers
3
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@superfaceai/parser - npm Package Compare versions

Comparing version 0.0.23 to 0.0.24-beta.0

dist/common/document/index.d.ts

6

CHANGELOG.md

@@ -11,4 +11,2 @@ # Changelog

## [0.0.23] - 2021-10-18
## [0.0.23-beta.0] - 2021-10-18
### Added

@@ -34,4 +32,2 @@ - Profile example parsing

## [0.0.20-beta.0] - 2021-08-03
## [0.0.19] - 2021-07-14

@@ -41,3 +37,2 @@

## [0.0.18-beta.0] - 2021-06-07
### Added

@@ -162,3 +157,2 @@ - Added an explicit hint to ShorthandPropertyAssignment Jessie construct error

## [0.0.4-beta3] - 2020-10-26
### Added

@@ -165,0 +159,0 @@ - `SyntaxError` category

18

dist/common/document/interfaces.d.ts

@@ -0,13 +1,3 @@

import { VersionRange } from './version';
/**
* Structure representing semver version tag.
*/
export declare type DocumentVersion = {
major: number;
minor?: number;
/** Patch version cannot appear without minor version. */
patch?: number;
/** Label can appear even without major and minor version. */
label?: string;
};
/**
* Generic structure that covers both partial profile and partial map ids.

@@ -21,6 +11,6 @@ */

/** The optional trailing version after `@`. */
version?: DocumentVersion;
version?: VersionRange;
};
/** Information encoded in the profile id string. */
export declare type ProfileDocumentId = {
export declare type ProfileIdRange = {
/** Scope of the profile, if any. */

@@ -31,3 +21,3 @@ scope?: string;

/** Version of the profile. */
version: DocumentVersion;
version: VersionRange;
};

@@ -34,0 +24,0 @@ /** Information encoded in the map id string. */

@@ -1,2 +0,2 @@

import { DocumentId, DocumentVersion, MapDocumentId, ProfileDocumentId } from './interfaces';
import { DocumentId, MapDocumentId, ProfileIdRange } from './interfaces';
export declare type ParseResult<T> = {

@@ -10,9 +10,5 @@ kind: 'parsed';

/**
* Checks whether the identififer is a lowercase identififer as required for document ids in the spec.
* Parses a singular version number or returns undefined.
*/
export declare function isValidDocumentIdentifier(str: string): boolean;
/**
* Parses version in format `major.minor.patch-label`
*/
export declare function parseVersion(version: string): ParseResult<DocumentVersion>;
export declare function tryParseVersionNumber(str: string): number | undefined;
/** Parses document id.

@@ -24,3 +20,3 @@ *

/** Parses the id using `parseDocumentId`, checks that the `middle` is a valid `name`. */
export declare function parseProfileId(id: string): ParseResult<ProfileDocumentId>;
export declare function parseProfileId(id: string): ParseResult<ProfileIdRange>;
/**

@@ -27,0 +23,0 @@ * Parses version label in format `revN`

@@ -30,64 +30,17 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.parseMapId = exports.parseRevisionLabel = exports.parseProfileId = exports.parseDocumentId = exports.parseVersion = exports.isValidDocumentIdentifier = void 0;
var split_1 = require("../split");
var ID_NAME_RE = /^[a-z][a-z0-9_-]*$/;
exports.parseMapId = exports.parseRevisionLabel = exports.parseProfileId = exports.parseDocumentId = exports.tryParseVersionNumber = void 0;
var ast_1 = require("@superfaceai/ast");
var _1 = require(".");
/**
* Checks whether the identififer is a lowercase identififer as required for document ids in the spec.
*/
function isValidDocumentIdentifier(str) {
return ID_NAME_RE.test(str);
}
exports.isValidDocumentIdentifier = isValidDocumentIdentifier;
var VERSION_NUMBER_RE = /^[0-9]+$/;
/**
* Parses a singular version number or returns undefined.
*/
function parseVersionNumber(str) {
var value = str.trim();
if (!VERSION_NUMBER_RE.test(value)) {
function tryParseVersionNumber(str) {
try {
return ast_1.parseVersionNumber(str);
}
catch (error) {
return undefined;
}
return parseInt(value, 10);
}
/**
* Parses version in format `major.minor.patch-label`
*/
function parseVersion(version) {
var _a = __read(split_1.splitLimit(version, '-', 1), 2), restVersion = _a[0], label = _a[1];
var _b = __read(split_1.splitLimit(restVersion, '.', 2), 3), majorStr = _b[0], minorStr = _b[1], patchStr = _b[2];
var major = parseVersionNumber(majorStr);
if (major === undefined) {
return { kind: 'error', message: 'major component is not a valid number' };
}
var minor = undefined;
if (minorStr !== undefined) {
minor = parseVersionNumber(minorStr);
if (minor === undefined) {
return {
kind: 'error',
message: 'minor component is not a valid number',
};
}
}
var patch = undefined;
if (patchStr !== undefined) {
patch = parseVersionNumber(patchStr);
if (patch === undefined) {
return {
kind: 'error',
message: 'patch component is not a valid number',
};
}
}
return {
kind: 'parsed',
value: {
major: major,
minor: minor,
patch: patch,
label: label,
},
};
}
exports.parseVersion = parseVersion;
exports.tryParseVersionNumber = tryParseVersionNumber;
/** Parses document id.

@@ -101,9 +54,9 @@ *

var scope;
var _b = __read(split_1.splitLimit(id, '/', 1), 2), splitScope = _b[0], scopeRestId = _b[1];
var _b = __read(ast_1.splitLimit(id, '/', 1), 2), splitScope = _b[0], scopeRestId = _b[1];
if (scopeRestId !== undefined) {
scope = splitScope;
if (!isValidDocumentIdentifier(scope)) {
if (!ast_1.isValidDocumentName(scope)) {
return {
kind: 'error',
message: 'scope is not a valid lowercase identifier',
message: scope + " is not a valid lowercase identifier",
};

@@ -115,15 +68,9 @@ }

var parsedVersion;
var _c = __read(split_1.splitLimit(id, '@', 1), 2), versionRestId = _c[0], splitVersion = _c[1];
var _c = __read(ast_1.splitLimit(id, '@', 1), 2), versionRestId = _c[0], splitVersion = _c[1];
if (splitVersion !== undefined) {
parsedVersion = parseVersion(splitVersion);
if (parsedVersion.kind === 'error') {
return {
kind: 'error',
message: 'could not parse version: ' + parsedVersion.message,
};
}
parsedVersion = _1.VersionRange.fromString(splitVersion);
// strip the version
id = versionRestId;
}
var version = parsedVersion === null || parsedVersion === void 0 ? void 0 : parsedVersion.value;
var version = parsedVersion;
var middle = id.split('.');

@@ -133,3 +80,3 @@ try {

var m = middle_1_1.value;
if (!isValidDocumentIdentifier(m)) {
if (!ast_1.isValidDocumentName(m)) {
return {

@@ -200,3 +147,3 @@ kind: 'error',

value = value.slice(3);
var revision = parseVersionNumber(value);
var revision = tryParseVersionNumber(value);
if (revision === undefined) {

@@ -203,0 +150,0 @@ return {

@@ -1,3 +0,1 @@

export * from './document/interfaces';
export * from './document/parser';
export * from './split';
export * from './document';

@@ -13,5 +13,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./document/interfaces"), exports);
__exportStar(require("./document/parser"), exports);
__exportStar(require("./split"), exports);
__exportStar(require("./document"), exports);
//# sourceMappingURL=index.js.map

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

exports.MAYBE_CONTENT_TYPE = exports.MAP_DOCUMENT_FACTORY = exports.MAP_HEADER = exports.MAP_VARIANT = exports.ITERATION_ATOM = exports.CONDITION_ATOM = exports.JESSIE_EXPRESSION_FACTORY = exports.PRIMITIVE_LITERAL = void 0;
var ast_1 = require("@superfaceai/ast");
var parser_1 = require("../../../../common/document/parser");

@@ -130,3 +131,3 @@ var rule_1 = require("../../rule");

.andFollowedBy(rule_1.SyntaxRule.string().andThen(function (provider) {
if (!parser_1.isValidDocumentIdentifier(provider.data.string)) {
if (!ast_1.isValidDocumentName(provider.data.string)) {
return {

@@ -159,3 +160,3 @@ kind: 'nomatch',

.andFollowedBy(rule_1.SyntaxRule.string().andThen(function (variant) {
if (!parser_1.isValidDocumentIdentifier(variant.data.string)) {
if (!ast_1.isValidDocumentName(variant.data.string)) {
return {

@@ -162,0 +163,0 @@ kind: 'nomatch',

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

exports.PROFILE_DOCUMENT = exports.PROFILE_DOCUMENT_DEFINITION = exports.PROFILE_HEADER = exports.USECASE_DEFINITION = exports.NAMED_MODEL_DEFINITION = exports.NAMED_FIELD_DEFINITION = exports.FIELD_DEFINITION = exports.TYPE = exports.LIST_DEFINITION = exports.OBJECT_DEFINITION = exports.MODEL_TYPE_NAME = exports.ENUM_DEFINITION = exports.ENUM_VALUE = exports.PRIMITIVE_TYPE_NAME = void 0;
var __1 = require("../../../..");
var parser_1 = require("../../../../common/document/parser");

@@ -409,18 +410,19 @@ var rule_1 = require("../../rule");

var _a, _b;
var parseVersionResult = parser_1.parseVersion(version.data.string);
if (parseVersionResult.kind !== 'parsed') {
try {
var parsedVersion = __1.VersionRange.fromString(version.data.string);
return {
kind: 'match',
value: {
major: parsedVersion.major,
minor: (_a = parsedVersion.minor) !== null && _a !== void 0 ? _a : 0,
patch: (_b = parsedVersion.patch) !== null && _b !== void 0 ? _b : 0,
label: parsedVersion.label,
location: version.location,
span: version.span,
},
};
}
catch (error) {
return { kind: 'nomatch' };
}
var parsedVersion = parseVersionResult.value;
return {
kind: 'match',
value: {
major: parsedVersion.major,
minor: (_a = parsedVersion.minor) !== null && _a !== void 0 ? _a : 0,
patch: (_b = parsedVersion.patch) !== null && _b !== void 0 ? _b : 0,
label: parsedVersion.label,
location: version.location,
span: version.span,
},
};
}, 'semver version'))

@@ -427,0 +429,0 @@ .map(function (_a) {

{
"name": "@superfaceai/parser",
"version": "0.0.23",
"version": "0.0.24-beta.0",
"description": "Level 5 autonomous, self-driving API client, https://superface.ai",

@@ -46,3 +46,3 @@ "repository": "https://github.com/superfaceai/parser.git",

"dependencies": {
"@superfaceai/ast": ">=0.0.34",
"@superfaceai/ast": "0.0.35-beta.0",
"@types/debug": "^4.1.5",

@@ -49,0 +49,0 @@ "debug": "^4.3.1",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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