diff --git a/CHANGELOG.md b/CHANGELOG.md index 92db0a3..7218b77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- removed `typescript-is` and replaced it with `ajv` validation +- `isProfileDocumentNode` and `isMapDocumentNode` do full schema validation ## [1.1.0] - 2022-01-19 ### Added diff --git a/package.json b/package.json index d2bf031..6a961cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@superfaceai/ast", - "version": "1.1.1-beta.0", + "version": "1.2.0-rc.0", "description": "Superface profile and map language ASTs, https://superface.ai", "main": "dist/index.js", "source": "src/index.ts", diff --git a/src/interfaces/ast/map-ast.utils.ts b/src/interfaces/ast/map-ast.utils.ts index 3f65bf2..16ab8ba 100644 --- a/src/interfaces/ast/map-ast.utils.ts +++ b/src/interfaces/ast/map-ast.utils.ts @@ -27,6 +27,16 @@ const assertMapDocument: Assert = prepareAssert( 'map-ast' ); +export const isMapDocumentNode = (node: unknown): node is MapDocumentNode => { + try { + assertMapDocument(node); + + return true; + } catch { + return false; + } +}; + // We don't need to do JSON Schema validation on these, as they should be already validated export const isAssignmentNode = (node: MapASTNode): node is AssignmentNode => node.kind === 'Assignment'; @@ -55,8 +65,6 @@ export const isJessieExpressionNode = ( export const isMapDefinitionNode = ( node: MapASTNode ): node is MapDefinitionNode => node.kind === 'MapDefinition'; -export const isMapDocumentNode = (node: MapASTNode): node is MapDocumentNode => - node.kind === 'MapDocument'; export const isMapHeaderNode = (node: MapASTNode): node is MapHeaderNode => node.kind === 'MapHeader'; export const isObjectLiteralNode = ( diff --git a/src/interfaces/ast/profile-ast.utils.ts b/src/interfaces/ast/profile-ast.utils.ts index 89689f2..6c691fa 100644 --- a/src/interfaces/ast/profile-ast.utils.ts +++ b/src/interfaces/ast/profile-ast.utils.ts @@ -35,6 +35,18 @@ const assertProfileDocument: Assert = prepareAssert( 'profile-ast' ); +export const isProfileDocumentNode = ( + node: unknown +): node is ProfileDocumentNode => { + try { + assertProfileDocument(node); + + return true; + } catch { + return false; + } +}; + // We don't need to do JSON Schema validation on these, as they should be already validated export const isEnumDefinitionNode = ( node: ProfileASTNode @@ -65,9 +77,6 @@ export const isObjectDefinitionNode = ( export const isPrimitiveTypeNameNode = ( node: ProfileASTNode ): node is PrimitiveTypeNameNode => node.kind === 'PrimitiveTypeName'; -export const isProfileDocumentNode = ( - node: ProfileASTNode -): node is ProfileDocumentNode => node.kind === 'ProfileDocument'; export const isProfileHeaderNode = ( node: ProfileASTNode ): node is ProfileHeaderNode => node.kind === 'ProfileHeader';