Skip to content

Versions for API based Datasources #1103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6b54810
add version field to plugin definition.
goldants Aug 2, 2024
da3c0aa
refactor code and test with twilio plugin
goldants Aug 2, 2024
733591c
Add s3 spec version
goldants Aug 5, 2024
a3fc994
Add dynamo spec version
goldants Aug 5, 2024
f4a3592
Add firebase spec version
goldants Aug 5, 2024
7059b79
Add couchdb spec version
goldants Aug 5, 2024
10d5859
Add woocommerce spec version
goldants Aug 5, 2024
ceeec59
Add openai spec version
goldants Aug 5, 2024
df93bd8
Add gcstorage spec version
goldants Aug 5, 2024
70101b7
Add stripe spec version
goldants Aug 5, 2024
e3866a9
Add asana, circleci spec version
goldants Aug 5, 2024
cd4c117
Add front, github spec version
goldants Aug 5, 2024
222cf9c
Add huggingface, jira, onesignal spec version
goldants Aug 5, 2024
206e03c
Add cloudinary, datadog, lowcoder, notion, postmanecho, sendgrid spec…
goldants Aug 5, 2024
998625e
remove test code
goldants Aug 5, 2024
13212ef
backward compatibility when no version is selected
goldants Aug 6, 2024
3819c30
Merge branch 'dev' into feature/spec_version
goldants Aug 6, 2024
21bf504
resolve test issue
goldants Aug 6, 2024
c158d44
Merge branch 'dev' into feature/spec_version
goldants Aug 6, 2024
03688bf
add test case
goldants Aug 7, 2024
1ca3b02
Merge branch 'versions-for-datasources' into feature/spec_version
FalkWolsky Aug 9, 2024
15e33f0
Merge pull request #1078 from goldants/feature/spec_version
FalkWolsky Aug 9, 2024
b831451
Sorting Twilio into Versions
Aug 10, 2024
1a50316
Merge branch 'dev' into versions-for-datasources
FalkWolsky Aug 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add huggingface, jira, onesignal spec version
  • Loading branch information
Thomasr committed Aug 5, 2024
commit 222cf9c9264ceaf39623cb3f5de1f598075491f5
8 changes: 4 additions & 4 deletions server/node-service/src/plugins/did/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const parseOptions: ParseOpenApiOptions = {

type DataSourceConfigType = ConfigToType<typeof dataSourceConfig>;

let queryConfig: QueryConfig | undefined;
let queryConfig: any = {};

const didPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
id: "did",
Expand All @@ -60,9 +60,9 @@ const didPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
category: "api",
dataSourceConfig,
queryConfig: async (data) => {
if (!queryConfig) {
if (!queryConfig[data.specVersion as keyof typeof queryConfig]) {
const { actions, categories } = await parseMultiOpenApi(specs[data.specVersion as keyof typeof specs], parseOptions);
queryConfig = {
queryConfig[data.specVersion as keyof typeof queryConfig] = {
type: "query",
label: "Action",
categories: {
Expand All @@ -72,7 +72,7 @@ const didPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
actions,
};
}
return queryConfig;
return queryConfig[data.specVersion as keyof typeof queryConfig];
},
run: function (actionData, dataSourceConfig): Promise<any> {
const runApiDsConfig = {
Expand Down
7 changes: 3 additions & 4 deletions server/node-service/src/plugins/huggingFaceEndpoint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import spec from "./huggingFace.spec.json";
import { specsToOptions } from "../../common/util";
const specs = {
"v1.0": spec,
"v2.0": spec,
}

const dataSourceConfig = {
Expand Down Expand Up @@ -55,9 +54,9 @@ const huggingFacePlugin: DataSourcePlugin<any, DataSourceConfigType> = {
icon: "huggingFace.svg",
category: "api",
dataSourceConfig,
queryConfig: async () => {
queryConfig: async (data) => {
const { actions, categories } = await parseOpenApi(
spec as unknown as OpenAPI.Document,
specs[data.specVersion as keyof typeof specs] as unknown as OpenAPI.Document,
parseOptions
);
return {
Expand All @@ -77,7 +76,7 @@ const huggingFacePlugin: DataSourcePlugin<any, DataSourceConfigType> = {
dynamicParamsConfig: dataSourceConfig,
specVersion: dataSourceConfig.specVersion,
};
return runOpenApi(actionData, runApiDsConfig, spec as unknown as OpenAPIV3.Document);
return runOpenApi(actionData, runApiDsConfig, specs[dataSourceConfig.specVersion as keyof typeof specs] as unknown as OpenAPIV3.Document);
},
};

Expand Down
43 changes: 28 additions & 15 deletions server/node-service/src/plugins/huggingFaceInference/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import _ from "lodash";
import { ConfigToType, DataSourcePlugin } from "lowcoder-sdk/dataSource";

const dataSourceConfig = {
type: "dataSource",
params: [
{
type: "password",
key: "token",
label: "Access Token",
rules: [{ required: true }],
tooltip:
"You can get an Access Token [in your profile setting page](https://huggingface.co/settings/tokens)",
},
],
} as const;
import { specsToOptions } from "../../common/util";

const queryConfig = {
type: "query",
Expand Down Expand Up @@ -42,6 +29,30 @@ const queryConfig = {
},
],
} as const;
const specs = {
"v1.0": queryConfig
}
const dataSourceConfig = {
type: "dataSource",
params: [
{
type: "password",
key: "token",
label: "Access Token",
rules: [{ required: true }],
tooltip:
"You can get an Access Token [in your profile setting page](https://huggingface.co/settings/tokens)",
},
{
label: "Spec Version",
key: "specVersion",
type: "select",
tooltip: "Version of the spec file.",
placeholder: "v1.0",
options: specsToOptions(specs)
},
],
} as const;

type DataSourceConfigType = ConfigToType<typeof dataSourceConfig>;
type ActionConfigType = ConfigToType<typeof queryConfig>;
Expand All @@ -52,7 +63,9 @@ const huggingFaceInferencePlugin: DataSourcePlugin<ActionConfigType, DataSourceC
icon: "huggingFace.svg",
category: "api",
dataSourceConfig,
queryConfig,
queryConfig: async (data) => {
return specs[data.specVersion as keyof typeof specs];
},
run: async (actionData, dataSourceConfig) => {
const response = await fetch(
`https://api-inference.huggingface.co/models/${actionData.model}`,
Expand Down
15 changes: 7 additions & 8 deletions server/node-service/src/plugins/jira/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { specsToOptions } from "../../common/util";
const specJson = readFileSync(path.join(__dirname, "./jira.spec.json")).toString();
const specs = {
"v1.0": specJson,
"v2.0": specJson,
}
//TODO: Thomas

Expand Down Expand Up @@ -64,18 +63,18 @@ const parseOptions: ParseOpenApiOptions = {

type DataSourceConfigType = ConfigToType<typeof dataSourceConfig>;

let queryConfig: QueryConfig;
let queryConfig: any = {};

const jiraPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
id: "jira",
name: "Jira",
icon: "jira.svg",
category: "api",
dataSourceConfig,
queryConfig: async () => {
if (!queryConfig) {
const { actions, categories } = await parseOpenApi(JSON.parse(specJson), parseOptions);
queryConfig = {
queryConfig: async (data) => {
if (!queryConfig[data.specVersion as keyof typeof queryConfig]) {
const { actions, categories } = await parseOpenApi(JSON.parse(specs[data.specVersion as keyof typeof specs]), parseOptions);
queryConfig[data.specVersion as keyof typeof queryConfig] = {
type: "query",
label: "Action",
categories: {
Expand All @@ -85,10 +84,10 @@ const jiraPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
actions,
};
}
return queryConfig;
return queryConfig[data.specVersion as keyof typeof queryConfig];
},
run: function (actionData, dataSourceConfig): Promise<any> {
const spec = JSON.parse(specJson);
const spec = JSON.parse(specs[dataSourceConfig.specVersion as keyof typeof specs]);
const runApiDsConfig = {
url: "",
serverURL: dataSourceConfig.serverUrl,
Expand Down
7 changes: 3 additions & 4 deletions server/node-service/src/plugins/oneSignal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import spec from "./oneSignal.spec.json";
import { specsToOptions } from "../../common/util";
const specs = {
"v1.0": spec,
"v2.0": spec,
}

const dataSourceConfig = {
Expand Down Expand Up @@ -53,9 +52,9 @@ const oneSignalPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
icon: "oneSignal.svg",
category: "api",
dataSourceConfig,
queryConfig: async () => {
queryConfig: async (data) => {
const { actions, categories } = await parseOpenApi(
spec as unknown as OpenAPI.Document,
specs[data.specVersion as keyof typeof specs] as unknown as OpenAPI.Document,
parseOptions
);
return {
Expand All @@ -75,7 +74,7 @@ const oneSignalPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
dynamicParamsConfig: dataSourceConfig,
specVersion: dataSourceConfig.specVersion,
};
return runOpenApi(actionData, runApiDsConfig, spec as OpenAPIV3.Document);
return runOpenApi(actionData, runApiDsConfig, specs[dataSourceConfig.specVersion as keyof typeof specs] as OpenAPIV3.Document);
},
};

Expand Down
11 changes: 5 additions & 6 deletions server/node-service/src/plugins/twilio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const parseOptions: ParseOpenApiOptions = {
},
};

let queryConfig: QueryConfig;
let queryConfig: any = {};

type DataSourceConfigType = ConfigToType<typeof dataSourceConfig>;

Expand All @@ -56,10 +56,9 @@ const twilioPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
dataSourceConfig,

queryConfig: async (data) => {
console.log(data.specVersion);
// if (!queryConfig) {
if (!queryConfig[data.specVersion as keyof typeof queryConfig]) {
const { actions, categories } = await parseMultiOpenApi(specs[data.specVersion as keyof typeof specs], parseOptions);
queryConfig = {
queryConfig[data.specVersion as keyof typeof queryConfig] = {
type: "query",
label: "Action",
categories: {
Expand All @@ -68,8 +67,8 @@ const twilioPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
},
actions,
};
// }
return queryConfig;
}
return queryConfig[data.specVersion as keyof typeof queryConfig];
},

run: function (actionData, dataSourceConfig): Promise<any> {
Expand Down