Skip to content

Commit de4fb81

Browse files
authored
Merge pull request #277 from cyyeh/add-extension-api-caller
add extension-api-caller
2 parents 72b1b7f + 0b50604 commit de4fb81

File tree

18 files changed

+542
-6
lines changed

18 files changed

+542
-6
lines changed

labs/playground1/Makefile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
# start vulcan server (default goal)
55
start: build test-data/moma.db ../../node_modules
6-
@vulcan start
6+
@vulcan start --watch
77

88
# build the required packages
99
build: pkg-core pkg-build pkg-serve pkg-catalog-server pkg-cli pkg-extension-driver-duckdb \
1010
pkg-extension-authenticator-canner pkg-extension-driver-canner \
1111
pkg-extension-driver-clickhouse pkg-extension-driver-bq \
12-
pkg-extension-huggingface
12+
pkg-extension-huggingface pkg-extension-api-caller
1313

1414

1515
# build for core pakge
@@ -65,7 +65,7 @@ pkg-extension-driver-canner: ../../node_modules
6565
mkdir -p ./labs/playground1/node_modules/@vulcan-sql; \
6666
rm -rf ./labs/playground1/node_modules/@vulcan-sql/extension-driver-canner; \
6767
cp -R ./dist/packages/extension-driver-canner ./labs/playground1/node_modules/@vulcan-sql; \
68-
68+
6969
pkg-extension-driver-clickhouse: ../../node_modules
7070
@cd ../..; \
7171
yarn nx build extension-driver-clickhouse; \
@@ -89,8 +89,12 @@ pkg-extension-huggingface: ../../node_modules
8989
cp -R ./dist/packages/extension-huggingface ./labs/playground1/node_modules/@vulcan-sql; \
9090
cp -R ./packages/extension-huggingface/node_modules ./labs/playground1
9191

92-
93-
92+
pkg-extension-api-caller: ../../node_modules
93+
@cd ../..; \
94+
yarn nx build extension-api-caller; \
95+
mkdir -p ./labs/playground1/node_modules/@vulcan-sql; \
96+
rm -rf ./labs/playground1/node_modules/@vulcan-sql/extension-api-caller; \
97+
cp -R ./dist/packages/extension-api-caller ./labs/playground1/node_modules/@vulcan-sql
9498

9599
# build and install for cli pakge
96100
pkg-cli: ../../node_modules
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
select
22
*
33
from "artists"
4-
where
4+
where
55
ConstituentID = {{ context.params.id }}
6+
{% if contex.params.begin_date %}
7+
and BeginDate = {{ context.params.begin_date }}
8+
{% endif %}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": ["../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
}
17+
]
18+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# extension-api-caller
2+
3+
Allow to call APIs from other sources for VulcanSQL, provided by [Canner](https://canner.io/).
4+
5+
## Installation
6+
7+
1. Install the package:
8+
9+
```bash
10+
npm i @vulcan-sql/extension-api-caller
11+
```
12+
13+
2. Update your `vulcan.yaml` file to enable the extension:
14+
15+
```yaml
16+
extensions:
17+
api: '@vulcan-sql/extension-api-caller'
18+
```
19+
20+
## Usage
21+
22+
To pass the path parameters:
23+
24+
```sql
25+
{% set a_variable_you_can_define = { "path": { "id": 1 } } %}
26+
SELECT {{ a_variable_you_can_define | rest_api(url='https://dummyjson.com/products/:id') }}
27+
```
28+
29+
To pass the query parameters:
30+
31+
```sql
32+
{% set a_variable_you_can_define = { "query": { "q": "phone" } } %}
33+
SELECT {{ a_variable_you_can_define | rest_api(url='https://dummyjson.com/products/search') }}
34+
```
35+
36+
To issue the POST request:
37+
38+
```sql
39+
{% set a_variable_you_can_define = { "body": { "title": "BMW Pencil" } } %}
40+
SELECT {{ a_variable_you_can_define | rest_api(url='https://dummyjson.com/products/add', method='POST') }}
41+
```
42+
43+
To pass the headers and multiple fields:
44+
45+
```sql
46+
{% set a_variable_you_can_define = { "headers": { "Content-Type": "application/json" }, "body": { "title": "BMW Pencil" } } %}
47+
SELECT {{ a_variable_you_can_define | rest_api(url='https://dummyjson.com/products/add', method='POST') }}
48+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
displayName: 'extension-api-caller',
3+
preset: '../../jest.preset.ts',
4+
testEnvironment: 'node',
5+
globals: {
6+
'ts-jest': {
7+
tsconfig: '<rootDir>/tsconfig.spec.json',
8+
},
9+
},
10+
transform: {
11+
'^.+\\.[tj]s$': 'ts-jest',
12+
},
13+
moduleFileExtensions: ['ts', 'js', 'html'],
14+
coverageDirectory: '../../coverage/packages/extension-api-caller',
15+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@vulcan-sql/extension-api-caller",
3+
"description": "Calling APIs to get data from other sources",
4+
"version": "0.8.1",
5+
"type": "commonjs",
6+
"publishConfig": {
7+
"access": "public"
8+
},
9+
"keywords": [
10+
"vulcan",
11+
"vulcan-sql",
12+
"data",
13+
"sql",
14+
"database",
15+
"data-warehouse",
16+
"data-lake",
17+
"api-builder",
18+
"api"
19+
],
20+
"repository": {
21+
"type": "git",
22+
"url": "https://github.com/Canner/vulcan.git"
23+
},
24+
"license": "Apache-2.0",
25+
"peerDependencies": {
26+
"@vulcan-sql/core": "^0.8.0"
27+
}
28+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"root": "packages/extension-api-caller",
3+
"sourceRoot": "packages/extension-api-caller/src",
4+
"targets": {
5+
"build": {
6+
"executor": "@nrwl/workspace:run-commands",
7+
"options": {
8+
"command": "yarn ts-node ./tools/scripts/replaceAlias.ts extension-api-caller"
9+
},
10+
"dependsOn": [
11+
{
12+
"projects": "self",
13+
"target": "tsc"
14+
},
15+
{
16+
"projects": "self",
17+
"target": "install-dependencies"
18+
}
19+
]
20+
},
21+
"tsc": {
22+
"executor": "@nrwl/js:tsc",
23+
"outputs": ["{options.outputPath}"],
24+
"options": {
25+
"outputPath": "dist/packages/extension-api-caller",
26+
"main": "packages/extension-api-caller/src/index.ts",
27+
"tsConfig": "packages/extension-api-caller/tsconfig.lib.json",
28+
"assets": ["packages/extension-api-caller/*.md"],
29+
"buildableProjectDepsInPackageJsonType": "dependencies"
30+
},
31+
"dependsOn": [
32+
{
33+
"projects": "dependencies",
34+
"target": "build"
35+
},
36+
{
37+
"projects": "self",
38+
"target": "install-dependencies"
39+
}
40+
]
41+
},
42+
"lint": {
43+
"executor": "@nrwl/linter:eslint",
44+
"outputs": ["{options.outputFile}"],
45+
"options": {
46+
"lintFilePatterns": ["packages/extension-api-caller/**/*.ts"]
47+
}
48+
},
49+
"test": {
50+
"executor": "@nrwl/jest:jest",
51+
"outputs": ["coverage/packages/extension-api-caller"],
52+
"options": {
53+
"jestConfig": "packages/extension-api-caller/jest.config.ts",
54+
"passWithNoTests": true
55+
},
56+
"dependsOn": [
57+
{
58+
"projects": "self",
59+
"target": "install-dependencies"
60+
}
61+
]
62+
},
63+
"publish": {
64+
"executor": "@nrwl/workspace:run-commands",
65+
"options": {
66+
"command": "node ../../../tools/scripts/publish.mjs {args.tag} {args.version}",
67+
"cwd": "dist/packages/extension-api-caller"
68+
},
69+
"dependsOn": [
70+
{
71+
"projects": "self",
72+
"target": "build"
73+
}
74+
]
75+
},
76+
"install-dependencies": {
77+
"executor": "@nrwl/workspace:run-commands",
78+
"options": {
79+
"command": "yarn",
80+
"cwd": "packages/extension-api-caller"
81+
}
82+
}
83+
},
84+
"tags": []
85+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Alias the Builder and Runner from the package and export them to prevent Extension loader loading the same Builder and Runner class when creating multiple Functional Filters or Tags.
2+
import {
3+
Builder as RestApiFilterBuilder,
4+
Runner as RestApiFilterRunner,
5+
} from './lib/filters/restApiCaller';
6+
7+
export default [
8+
RestApiFilterBuilder,
9+
RestApiFilterRunner,
10+
];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './restApiCaller';

0 commit comments

Comments
 (0)