This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from superfaceai/feature/play-command
Feature/play command
- Loading branch information
Showing
28 changed files
with
2,421 additions
and
851 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
**/package-lock.json | ||
**/*.ast.json | ||
**/*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
profile = "https://example.com/pubs" | ||
provider = "https://example.com/pubs/Noop" | ||
|
||
map PubOpeningHours { | ||
return map result [] | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@superfaceai:registry=https://npm.pkg.github.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "valid", | ||
"private": true, | ||
"dependencies": { | ||
"@superfaceai/sdk": "^0.0.3" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
profile = "https://example.com/pubs" | ||
provider = "https://example.com/pubs/Noop" | ||
|
||
map PubOpeningHours { | ||
return map result [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as fs from 'fs'; | ||
import { promisify, inspect } from 'util'; | ||
import { Provider } from '@superfaceai/sdk'; | ||
|
||
const readFile = promisify(fs.readFile); | ||
|
||
async function main() { | ||
const profileAst = JSON.parse( | ||
await readFile('valid.supr.ast.json', { encoding: 'utf-8' }) | ||
); | ||
const mapAst = JSON.parse( | ||
await readFile('valid.noop.suma.ast.json', { encoding: 'utf-8' }) | ||
); | ||
|
||
const provider = new Provider( | ||
profileAst, mapAst, | ||
'PubOpeningHours' | ||
); | ||
|
||
const boundProvider = await provider.bind( | ||
{ | ||
// TODO: Add your auth keys here | ||
} | ||
); | ||
|
||
const result = await boundProvider.perform( | ||
{ | ||
city: "Praha", | ||
nameRegex: "Diego" | ||
} | ||
); | ||
|
||
console.log( | ||
"pubs/Noop result:", | ||
inspect(result, { | ||
depth: 5, | ||
colors: true | ||
}) | ||
); | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
profile = "https://example.com/pubs" | ||
provider = "https://example.com/pubs/OSM" | ||
|
||
map PubOpeningHours { | ||
http POST "/api/interpreter" { | ||
request "application/x-www-form-urlencoded" { | ||
body { | ||
data = call BuildQuery(city = input.city, nameRegex = input.nameRegex) | ||
} | ||
} | ||
|
||
response 200 { | ||
return map error if (body.remarks && body.remarks.includes('Query timed out')) "TIMEOUT" | ||
|
||
return map result body.elements.map( | ||
node => { | ||
return { | ||
name: node.tags.name, | ||
openingHours: node.tags.opening_hours | ||
} | ||
} | ||
) | ||
} | ||
} | ||
} | ||
|
||
operation BuildQuery { | ||
regexLine = input.nameRegex ? `node._["name"~"${input.nameRegex}", i];` : ''; | ||
query = (`[out:json][timeout:10]; | ||
area[boundary=administrative][admin_level=8][name="${input.city}"]; | ||
node[amenity="pub"][opening_hours](area); | ||
${regexLine} | ||
|
||
out;`); | ||
|
||
return query; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as fs from 'fs'; | ||
import { promisify, inspect } from 'util'; | ||
import { Provider } from '@superfaceai/sdk'; | ||
|
||
const readFile = promisify(fs.readFile); | ||
|
||
async function main() { | ||
const profileAst = JSON.parse( | ||
await readFile('valid.supr.ast.json', { encoding: 'utf-8' }) | ||
); | ||
const mapAst = JSON.parse( | ||
await readFile('valid.osm.suma.ast.json', { encoding: 'utf-8' }) | ||
); | ||
|
||
const provider = new Provider(profileAst, mapAst, 'https://overpass-api.de'); | ||
|
||
const boundProvider = await provider.bind({ | ||
// TODO: Add your auth keys here | ||
// No keys are needed for OSM | ||
}); | ||
|
||
const result = await boundProvider.perform('PubOpeningHours', { | ||
city: 'Praha', | ||
nameRegex: 'Diego', | ||
}); | ||
|
||
console.log( | ||
'pubs/OSM result:', | ||
inspect(result, { | ||
depth: 5, | ||
colors: true, | ||
}) | ||
); | ||
} | ||
|
||
main(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
profile = "https://example.com/pubs" | ||
|
||
""" | ||
List pub opening hours | ||
""" | ||
usecase PubOpeningHours { | ||
input { | ||
city! string! | ||
nameRegex string! | ||
} | ||
|
||
result [{ name string, openingHours string }] | ||
|
||
error PubOpeningHoursError | ||
} | ||
|
||
model PubOpeningHoursError enum { | ||
TIMEOUT | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,14 @@ | |
"main": "dist/index.js", | ||
"repository": "[email protected]:superfaceai/cli.git", | ||
"author": "Superface Team", | ||
"private": true, | ||
"private": false, | ||
"bin": { | ||
"superface": "./bin/superface", | ||
"sf": "./bin/superface" | ||
"superface": "bin/superface", | ||
"sf": "bin/superface" | ||
}, | ||
"files": [ | ||
"./bin/" | ||
"bin/", | ||
"dist/" | ||
], | ||
"scripts": { | ||
"build": "tsc -p tsconfig.release.json --outDir dist", | ||
|
@@ -23,15 +24,18 @@ | |
"prepush": "yarn test && yarn lint && yarn format" | ||
}, | ||
"devDependencies": { | ||
"@types/debug": "^4.1.5", | ||
"@types/inquirer": "^7.3.1", | ||
"@types/jest": "^26.0.15", | ||
"@types/rimraf": "^3.0.0", | ||
"@typescript-eslint/eslint-plugin": "^4.7.0", | ||
"@typescript-eslint/parser": "^4.7.0", | ||
"eslint": "^7.13.0", | ||
"eslint-config-prettier": "^6.15.0", | ||
"eslint-import-resolver-typescript": "^2.3.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-jest": "^24.1.2", | ||
"eslint-plugin-simple-import-sort": "^5.0.3", | ||
"eslint-plugin-simple-import-sort": "^6.0.1", | ||
"jest": "^26.6.3", | ||
"prettier": "^2.1.2", | ||
"stdout-stderr": "TheEdward162/stdout-stderr#fb3e22a", | ||
|
@@ -41,7 +45,12 @@ | |
"dependencies": { | ||
"@oclif/command": "^1.8.0", | ||
"@oclif/config": "^1.17.0", | ||
"@superfaceai/parser": "0.0.6" | ||
"@superfaceai/parser": "0.0.6", | ||
"chalk": "^4.1.0", | ||
"debug": "^4.3.1", | ||
"inquirer": "^7.3.3", | ||
"inquirer-file-tree-selection-prompt": "^1.0.7", | ||
"rimraf": "^3.0.2" | ||
}, | ||
"oclif": { | ||
"commands": "./dist/commands", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.