Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #260 from superfaceai/feat/update_ast_and_parser
Browse files Browse the repository at this point in the history
Update Parser and AST to parse examples with None
  • Loading branch information
freaz authored Feb 7, 2023
2 parents 0a8a70e + 3e8770e commit 4bfecd4
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 41 deletions.
4 changes: 2 additions & 2 deletions fixtures/compiled/strict.suma.ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -2187,12 +2187,12 @@
"astMetadata": {
"astVersion": {
"major": 1,
"minor": 2,
"minor": 3,
"patch": 0
},
"parserVersion": {
"major": 2,
"minor": 0,
"minor": 1,
"patch": 0
},
"sourceChecksum": "bfd83d45dcc6e3ce124163f9e2029574fe239a5c7dac6b71b1a6261b4342e68b"
Expand Down
4 changes: 2 additions & 2 deletions fixtures/compiled/strict.supr.ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -677,12 +677,12 @@
"astMetadata": {
"astVersion": {
"major": 1,
"minor": 2,
"minor": 3,
"patch": 0
},
"parserVersion": {
"major": 2,
"minor": 0,
"minor": 1,
"patch": 0
},
"sourceChecksum": "db2fa60e8a2a8a7bd4e1d97b62b39812934dbd4dca22cb2bbe14e7d067358380"
Expand Down
4 changes: 2 additions & 2 deletions fixtures/compiled/with-examples.supr.ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -919,12 +919,12 @@
"astMetadata": {
"astVersion": {
"major": 1,
"minor": 2,
"minor": 3,
"patch": 0
},
"parserVersion": {
"major": 2,
"minor": 0,
"minor": 1,
"patch": 0
},
"sourceChecksum": "a3e264134151db634ddedf45e2a40564f98048ef544c72de9363124398f6e404"
Expand Down
4 changes: 2 additions & 2 deletions fixtures/profiles/communication/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,12 @@
"astMetadata": {
"astVersion": {
"major": 1,
"minor": 2,
"minor": 3,
"patch": 0
},
"parserVersion": {
"major": 2,
"minor": 0,
"minor": 1,
"patch": 0
},
"sourceChecksum": "f6e540bf86a47d56bd2d7b174a0075790a89538c829ace2f8cd9d5a878067e59"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,12 @@
"astMetadata": {
"astVersion": {
"major": 1,
"minor": 2,
"minor": 3,
"patch": 0
},
"parserVersion": {
"major": 2,
"minor": 0,
"minor": 1,
"patch": 0
},
"sourceChecksum": "09467b07a5631fee772fb2bc2c64b9132a5f8eb9054e05a01b399c926754c9db"
Expand Down
4 changes: 2 additions & 2 deletions fixtures/profiles/starwars/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,12 @@
"astMetadata": {
"astVersion": {
"major": 1,
"minor": 2,
"minor": 3,
"patch": 0
},
"parserVersion": {
"major": 2,
"minor": 0,
"minor": 1,
"patch": 0
},
"sourceChecksum": "cd79073c266e2f7cf17c8a9f90f2dc6d678a1e05b07cb96d0544d2132c9aa20c"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,12 @@
"astMetadata": {
"astVersion": {
"major": 1,
"minor": 2,
"minor": 3,
"patch": 0
},
"parserVersion": {
"major": 2,
"minor": 0,
"minor": 1,
"patch": 0
},
"sourceChecksum": "9c486344c90653606885803b279bf85fc7253303f2aa81664f48d76990bcec8b"
Expand Down
4 changes: 2 additions & 2 deletions fixtures/profiles/starwars/maps/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -654,12 +654,12 @@
"astMetadata": {
"astVersion": {
"major": 1,
"minor": 2,
"minor": 3,
"patch": 0
},
"parserVersion": {
"major": 2,
"minor": 0,
"minor": 1,
"patch": 0
},
"sourceChecksum": "1ed288c0f2b9ae0d099a6c12d06e0183489ec58ec880f0ab62a15fba4eedc045"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,12 @@
"astMetadata": {
"astVersion": {
"major": 1,
"minor": 2,
"minor": 3,
"patch": 0
},
"parserVersion": {
"major": 2,
"minor": 0,
"minor": 1,
"patch": 0
},
"sourceChecksum": "d3129969bac23e221bf7311ae7ea4a61f1eab9f14a63ebe7cbb03fcb0f009265"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,12 @@
"astMetadata": {
"astVersion": {
"major": 1,
"minor": 2,
"minor": 3,
"patch": 0
},
"parserVersion": {
"major": 2,
"minor": 0,
"minor": 1,
"patch": 0
},
"sourceChecksum": "b6ec612a02624f1086c1a9606b3cc1b3164e64520694d719ee5ac0055a2f7472"
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
"@oclif/command": "^1.8.0",
"@oclif/config": "^1.17.0",
"@oclif/plugin-warn-if-update-available": "^1.7.0",
"@superfaceai/ast": "^1.2.0",
"@superfaceai/one-sdk": "^2.0.0",
"@superfaceai/parser": "^2.0.0",
"@superfaceai/ast": "^1.3.0",
"@superfaceai/one-sdk": "^2.3.0",
"@superfaceai/parser": "^2.1.0",
"@superfaceai/service-client": "^5.0.0",
"chalk": "^4.1.0",
"cross-fetch": "^3.1.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
parseListLiteral,
parseLiteralExample,
parseNoneLiteral,
parseObjectLiteral,
parsePrimitiveLiteral,
} from './parse';
Expand Down Expand Up @@ -303,4 +304,16 @@ describe('Parse example tree', () => {
});
});
});

describe('parseNoneLiteral', () => {
it('returns example none for ComlinkNoneLiteral', () => {
expect(
parseNoneLiteral({
kind: 'ComlinkNoneLiteral',
})
).toEqual({
kind: 'none',
});
});
});
});
15 changes: 15 additions & 0 deletions src/templates/prepared-map/usecase/example/example-tree/parse.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type {
ComlinkListLiteralNode,
ComlinkLiteralNode,
ComlinkNoneLiteralNode,
ComlinkObjectLiteralNode,
ComlinkPrimitiveLiteralNode,
} from '@superfaceai/ast';

import type {
ExampleArray,
ExampleNone,
ExampleObject,
ExampleScalar,
UseCaseExample,
Expand All @@ -27,6 +29,11 @@ export function parseObjectLiteral(
name: field.key.join('.'),
...parseListLiteral(field.value),
});
} else if (field.value.kind === 'ComlinkNoneLiteral') {
properties.push({
name: field.key.join('.'),
...parseNoneLiteral(field.value),
})
} else {
properties.push({
name: field.key.join('.'),
Expand All @@ -50,6 +57,12 @@ export function parseListLiteral(node: ComlinkListLiteralNode): ExampleArray {
};
}

export function parseNoneLiteral(_node: ComlinkNoneLiteralNode): ExampleNone {
return {
kind: 'none'
};
}

export function parsePrimitiveLiteral(
node: ComlinkPrimitiveLiteralNode
): ExampleScalar {
Expand All @@ -72,6 +85,8 @@ export function parseLiteralExample(
return parseObjectLiteral(exampleNode);
} else if (exampleNode.kind === 'ComlinkListLiteral') {
return parseListLiteral(exampleNode);
} else if (exampleNode.kind === 'ComlinkNoneLiteral') {
return parseNoneLiteral(exampleNode);
} else {
return parsePrimitiveLiteral(exampleNode);
}
Expand Down
9 changes: 7 additions & 2 deletions src/templates/prepared-map/usecase/example/usecase-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ export type ExampleObject = {
properties: ({ name: string } & (
| ExampleArray
| ExampleScalar
| ExampleNone
| ExampleObject
))[];
};

export type ExampleArray = {
kind: 'array';
items: (ExampleArray | ExampleObject | ExampleScalar)[];
items: (ExampleArray | ExampleObject | ExampleScalar | ExampleNone)[];
};

export type UseCaseExample = ExampleArray | ExampleObject | ExampleScalar;
export type ExampleNone = {
kind: 'none';
};

export type UseCaseExample = ExampleArray | ExampleObject | ExampleScalar | ExampleNone;
3 changes: 2 additions & 1 deletion src/templates/prepared-map/usecase/prepare-input-scalar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export function prepareExampleScalar(
if (
example.kind === 'boolean' ||
example.kind === 'number' ||
example.kind === 'string'
example.kind === 'string' ||
example.kind === 'none'
) {
return place;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ describe('Parse use case details', () => {
name: 'Foo',
inputExampleScalarName: 'input.field',
title: 'usecase title',
description: undefined,
error: {
modelType: 'Enum',
nonNull: false,
enumElements: [
{
title: undefined,
value: 404,
},
{
title: undefined,
value: 400,
},
],
Expand All @@ -56,6 +59,7 @@ describe('Parse use case details', () => {
{
fieldName: 'field',
required: false,
description: undefined,
model: {
nonNull: false,
modelType: 'Union',
Expand All @@ -75,6 +79,7 @@ describe('Parse use case details', () => {
},
{
fieldName: 'field',
description: undefined,
required: false,
model: {
modelType: 'Scalar',
Expand Down Expand Up @@ -136,7 +141,7 @@ describe('Parse use case details', () => {
name: 'field',
kind: 'boolean',
value: true,
},
}
],
},
result: {
Expand Down
28 changes: 14 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -742,32 +742,32 @@
dependencies:
"@sinonjs/commons" "^1.7.0"

"@superfaceai/ast@1.2.0", "@superfaceai/ast@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@superfaceai/ast/-/ast-1.2.0.tgz#f41823d550e0b0a05a8398be22a68b7b3912dde3"
integrity sha512-HMmdSUNzKuVgQ9g9YS/eiv3/CitSZks8eury8sAi2QbwT+n5f9SsVcmHxL2/QbkRCmlPpRqHJ6YSCqvBZ2fu1g==
"@superfaceai/ast@1.3.0", "@superfaceai/ast@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@superfaceai/ast/-/ast-1.3.0.tgz#15b8ef512616652478592b2469ba06303b713622"
integrity sha512-6zTaJKaZkR5kqk3axiE05FheRWYb0ykRSMy6quwrVn4fJmP/Z6KQ14KifqMtZTmWak+GsFPfun1n1reyGyHbJg==
dependencies:
ajv "^8.8.2"
ajv-formats "^2.1.1"

"@superfaceai/one-sdk@^2.0.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@superfaceai/one-sdk/-/one-sdk-2.2.0.tgz#8786dfab806e8812755b43d0fda1ae6891ed964d"
integrity sha512-EK60eGBfnfUnZrXpTbs67zctp+Uo7Fa8aMSdgYZnaK5YzhLcYQBLZiApjjtsmReoXWW9R21n2K7nwaC9vmxPHQ==
"@superfaceai/one-sdk@^2.3.0":
version "2.3.0"
resolved "https://registry.yarnpkg.com/@superfaceai/one-sdk/-/one-sdk-2.3.0.tgz#7de9de084f8e69dc7fefe0a9b1e7d6abb3a69be7"
integrity sha512-6B2EdxE//vkri9ZBv6f8fHMoItCDoCO7XqbNBqpcYAsm3wj+8B7vC7eWRhN1+z6YPww1VzFLFmorF9UMc7jRdg==
dependencies:
"@superfaceai/ast" "1.2.0"
"@superfaceai/ast" "1.3.0"
abort-controller "^3.0.0"
debug "^4.3.2"
form-data "^4.0.0"
node-fetch "^2"
vm2 "^3.9.7"

"@superfaceai/parser@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@superfaceai/parser/-/parser-2.0.0.tgz#d498486471dacac7a408d4fbbd5068aaa3ffc12c"
integrity sha512-gIWixVU/gbqIQ+QhomqKTHiddSzwEbo3+XkNRdAQ3L6qRaMJy5HFdFsZWiS45cNDwJNlqK2GF5JAPcmInlOucg==
"@superfaceai/parser@^2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@superfaceai/parser/-/parser-2.1.0.tgz#0ddaeac6c6f7caa18a1590f27c39736a8262dcb2"
integrity sha512-/sbjFcs4qUo5bJx+pX/N8XClnfkQjz68XGZ+w9gzPOObMNyg1pImAf+/bE9no4bkiGfFtph0VwYjmhAY33/yXQ==
dependencies:
"@superfaceai/ast" "^1.2.0"
"@superfaceai/ast" "^1.3.0"
"@types/debug" "^4.1.5"
debug "^4.3.3"
typescript "^4"
Expand Down

0 comments on commit 4bfecd4

Please sign in to comment.