Skip to content

Commit

Permalink
Merge pull request #8 from superindustries/feature/profile-parameter-…
Browse files Browse the repository at this point in the history
…validator

feat: Add ProfileParameterValidator
  • Loading branch information
TheEdward162 authored Aug 27, 2020
2 parents c3935cc + 15b7a5c commit 0a3e474
Show file tree
Hide file tree
Showing 9 changed files with 2,536 additions and 2,906 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@ module.exports = {
},
},
},
overrides: [{
files: '*.test.ts',
rules: {
'@typescript-eslint/no-explicit-any': 'off',
}
}],
};
29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,36 @@
"registry": "https://npm.pkg.github.com/"
},
"scripts": {
"build": "microbundle --tsconfig tsconfig.release.json",
"build_bundle": "microbundle --tsconfig tsconfig.release.json",
"build": "tsc -p tsconfig.release.json --outDir dist",
"watch": "yarn build --watch",
"clean": "rimraf dist/",
"prebuild": "yarn clean",
"test": "jest",
"lint": "eslint src/",
"format": "prettier -c src/",
"format:fix": "prettier --write src/"
"format:fix": "prettier --write src/",
"prepush": "yarn test && yarn lint && yarn format"
},
"devDependencies": {
"@types/jest": "^25.2.1",
"@typescript-eslint/eslint-plugin": "^2.33.0",
"@typescript-eslint/parser": "^2.33.0",
"eslint": "^7.0.0",
"@types/jest": "^26.0.10",
"@typescript-eslint/eslint-plugin": "^3.10.1",
"@typescript-eslint/parser": "^3.10.1",
"eslint": "^7.7.0",
"eslint-config-prettier": "^6.11.0",
"eslint-import-resolver-typescript": "^2.0.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jest": "^23.13.1",
"eslint-import-resolver-typescript": "^2.2.1",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^23.20.0",
"eslint-plugin-simple-import-sort": "^5.0.3",
"jest": "^26.0.1",
"microbundle": "^0.12.0",
"jest": "^26.4.2",
"mockttp": "^0.20.3",
"prettier": "^2.0.5",
"rimraf": "^3.0.2",
"ts-jest": "^26.1.0",
"typescript": "^3.9.6"
"ts-jest": "^26.3.0",
"typescript": "^4.0.2"
},
"dependencies": {
"@superindustries/language": "^0.0.10",
"@superindustries/language": "^0.0.12",
"cross-fetch": "^3.0.5",
"isomorphic-form-data": "^2.0.0",
"vm2": "^3.9.2"
Expand Down
2 changes: 1 addition & 1 deletion src/client/interpreter/Sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ export function evalScript(
`
);

return vm.run(`'use strict';${js}`);
return vm.run(`'use strict';${js}`) as string;
}
18 changes: 13 additions & 5 deletions src/internal/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,17 @@ const createUrl = (
const query = queryParameters(parameters.queryParameters);
const isRelative = /^\/[^/]/.test(inputUrl);

if (isRelative && !parameters.baseUrl) {
throw new Error('Relative URL specified, but base URL not provided!');
}
let url: string;

let url = isRelative ? `${parameters.baseUrl}${inputUrl}` : inputUrl;
if (isRelative) {
if (!parameters.baseUrl) {
throw new Error('Relative URL specified, but base URL not provided!');
} else {
url = `${parameters.baseUrl}${inputUrl}`;
}
} else {
url = inputUrl;
}

if (parameters.pathParameters) {
const pathParameters = Object.keys(parameters.pathParameters);
Expand Down Expand Up @@ -152,7 +158,9 @@ export const HttpClient = {
headers.append('Content-Type', FORMDATA_CONTENT);
params.body = formData(variablesToStrings(parameters.body));
} else {
throw new Error(`Unknown content type: ${parameters.contentType}`);
throw new Error(
`Unknown content type: ${parameters.contentType ?? ''}`
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/internal/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface ProfileProvider {
}

export interface PerformContext {
variables: object;
variables: Record<string, unknown>;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand Down
117 changes: 88 additions & 29 deletions src/internal/interpreter/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
import {
EnumDefinitionNode,
EnumValueNode,
EvalDefinitionNode,
FieldDefinitionNode,
HTTPOperationDefinitionNode,
IterationDefinitionNode,
JSExpressionNode,
ListDefinitionNode,
MapASTNode,
MapDefinitionNode,
MapDocumentNode,
MapExpressionDefinitionNode,
MapNode,
MapProfileIdNode,
ModelTypeNameNode,
NamedFieldDefinitionNode,
NamedModelDefinitionNode,
NetworkOperationDefinitionNode,
NonNullDefinitionNode,
ObjectDefinitionNode,
OperationCallDefinitionNode,
OperationDefinitionNode,
OutcomeDefinitionNode,
PrimitiveTypeNameNode,
ProfileASTNode,
ProfileDocumentNode,
ProfileIdNode,
ProfileNode,
ProviderNode,
StepDefinitionNode,
UnionDefinitionNode,
UseCaseDefinitionNode,
VariableExpressionDefinitionNode,
} from '@superindustries/language';

Expand All @@ -23,37 +39,80 @@ export type Variables = {
};

export interface MapVisitor {
visit(node: MapASTNode): Promise<unknown> | unknown;
visitEvalDefinitionNode(node: EvalDefinitionNode): Promise<unknown> | unknown;
visitHTTPOperationDefinitionNode(
node: HTTPOperationDefinitionNode
): Promise<unknown> | unknown;
visitIterationDefinitionNode(
node: IterationDefinitionNode
): Promise<unknown> | unknown;
visitJSExpressionNode(node: JSExpressionNode): Promise<unknown> | unknown;
visitMapDefinitionNode(node: MapDefinitionNode): Promise<unknown> | unknown;
visitMapDocumentNode(node: MapDocumentNode): Promise<unknown> | unknown;
visitMapExpressionDefinitionNode(
node: MapExpressionDefinitionNode
): Promise<unknown> | unknown;
visitMapNode(node: MapNode): Promise<unknown> | unknown;
visit(node: MapASTNode): unknown;
visitEvalDefinitionNode(node: EvalDefinitionNode): unknown;
visitHTTPOperationDefinitionNode(node: HTTPOperationDefinitionNode): unknown;
visitIterationDefinitionNode(node: IterationDefinitionNode): unknown;
visitJSExpressionNode(node: JSExpressionNode): unknown;
visitMapDefinitionNode(node: MapDefinitionNode): unknown;
visitMapDocumentNode(node: MapDocumentNode): unknown;
visitMapExpressionDefinitionNode(node: MapExpressionDefinitionNode): unknown;
visitMapNode(node: MapNode): unknown;
visitNetworkOperationDefinitionNode(
node: NetworkOperationDefinitionNode
): Promise<unknown> | unknown;
visitOperationCallDefinitionNode(
node: OperationCallDefinitionNode
): Promise<unknown> | unknown;
visitOperationDefinitionNode(
node: OperationDefinitionNode
): Promise<unknown> | unknown;
visitOutcomeDefinitionNode(
node: OutcomeDefinitionNode
): Promise<unknown> | unknown;
visitProfileIdNode(node: MapProfileIdNode): Promise<unknown> | unknown;
visitProviderNode(node: ProviderNode): Promise<unknown> | unknown;
visitStepDefinitionNode(node: StepDefinitionNode): Promise<unknown> | unknown;
): unknown;
visitOperationCallDefinitionNode(node: OperationCallDefinitionNode): unknown;
visitOperationDefinitionNode(node: OperationDefinitionNode): unknown;
visitOutcomeDefinitionNode(node: OutcomeDefinitionNode): unknown;
visitProfileIdNode(node: MapProfileIdNode): unknown;
visitProviderNode(node: ProviderNode): unknown;
visitStepDefinitionNode(node: StepDefinitionNode): unknown;
visitVariableExpressionDefinitionNode(
node: VariableExpressionDefinitionNode
): Promise<unknown> | unknown;
): unknown;
}

export interface ProfileVisitor {
visit(node: ProfileASTNode, ...parameters: unknown[]): unknown;
visitEnumDefinitionNode(
node: EnumDefinitionNode,
...parameters: unknown[]
): unknown;
visitEnumValueNode(node: EnumValueNode, ...parameters: unknown[]): unknown;
visitFieldDefinitionNode(
node: FieldDefinitionNode,
...parameters: unknown[]
): unknown;
visitListDefinitionNode(
node: ListDefinitionNode,
...parameters: unknown[]
): unknown;
visitModelTypeNameNode(
node: ModelTypeNameNode,
...parameters: unknown[]
): unknown;
visitNamedFieldDefinitionNode(
node: NamedFieldDefinitionNode,
...parameters: unknown[]
): unknown;
visitNamedModelDefinitionNode(
node: NamedModelDefinitionNode,
...parameters: unknown[]
): unknown;
visitNonNullDefinitionNode(
node: NonNullDefinitionNode,
...parameters: unknown[]
): unknown;
visitObjectDefinitionNode(
node: ObjectDefinitionNode,
...parameters: unknown[]
): unknown;
visitPrimitiveTypeNameNode(
node: PrimitiveTypeNameNode,
...parameters: unknown[]
): unknown;
visitProfileDocumentNode(
node: ProfileDocumentNode,
...parameters: unknown[]
): unknown;
visitProfileIdNode(node: ProfileIdNode, ...parameters: unknown[]): unknown;
visitProfileNode(node: ProfileNode, ...parameters: unknown[]): unknown;
visitUnionDefinitionNode(
node: UnionDefinitionNode,
...parameters: unknown[]
): unknown;
visitUseCaseDefinitionNode(
node: UseCaseDefinitionNode,
...parameters: unknown[]
): unknown;
}
Loading

0 comments on commit 0a3e474

Please sign in to comment.