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
refactor code and test with twilio plugin
  • Loading branch information
Thomasr committed Aug 2, 2024
commit da3c0aa0d661c95dc1d377cb158c2c5f1970395c
37 changes: 37 additions & 0 deletions server/node-service/src/common/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import yaml from "yaml";
import fs from "fs";
import { MultiOpenApiSpecItem } from "../plugins/openApi/parse";
import path from "path";
import { appendTags } from "../plugins/openApi/util";
import _ from "lodash";

export function kvToRecord(
kvs: { key: string; value: string }[],
Expand Down Expand Up @@ -85,3 +89,36 @@ export function safeJsonStringify(data: any) {
return null;
}
}

export function specsToOptions(specs: any) {
return Object.keys(specs).map(k => ({value: k, label: k}));
}

function genTagFromFileName(name: string) {
const fileName = name.replace(/\.yaml|twilio_|\.json/g, "");
const parts = fileName.split("_");
return parts.reduce((a, b) => {
if (/v\d+/.test(b)) {
return `${a}(${b})`;
}
return a + _.upperFirst(b);
}, "");
}

export function dirToSpecList(specDir: string) {
const specList: MultiOpenApiSpecItem[] = [];

const start = performance.now();
const specFiles = fs.readdirSync(specDir);
specFiles.forEach((specFile) => {
const spec = readYaml(path.join(specDir, specFile));
const tag = genTagFromFileName(specFile);
appendTags(spec, tag);
specList.push({
id: tag,
spec,
});
});
logger.info("spec list loaded %s, duration: %d ms",specDir, performance.now() - start);
return specList;
}
18 changes: 6 additions & 12 deletions server/node-service/src/plugins/asana/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readYaml } from "../../common/util";
import { readYaml, specsToOptions } from "../../common/util";
import _ from "lodash";
import path from "path";
import { OpenAPIV3, OpenAPI } from "openapi-types";
Expand All @@ -8,7 +8,10 @@ import { parseOpenApi, ParseOpenApiOptions } from "../openApi/parse";


const spec = readYaml(path.join(__dirname, "./asana.spec.yaml"));

const specs = {
"v1.0": spec,
"v2.0": spec,
}

const dataSourceConfig = {
type: "dataSource",
Expand All @@ -30,16 +33,7 @@ const dataSourceConfig = {
type: "select",
tooltip: "Version of the spec file.",
placeholder: "v1.0",
options: [
{
value: "v1.0",
label: "v1.0",
},
{
value: "v2.0",
label: "v2.0",
}
]
options: specsToOptions(specs)
},
]
} as const;
Expand Down
16 changes: 6 additions & 10 deletions server/node-service/src/plugins/circleCi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { runOpenApi } from "../openApi";
import { parseOpenApi, ParseOpenApiOptions } from "../openApi/parse";

import spec from "./circleCi.spec.json";
import { specsToOptions } from "../../common/util";
const specs = {
"v1.0": spec,
"v2.0": spec,
}

const dataSourceConfig = {
type: "dataSource",
Expand All @@ -22,16 +27,7 @@ const dataSourceConfig = {
type: "select",
tooltip: "Version of the spec file.",
placeholder: "v1.0",
options: [
{
value: "v1.0",
label: "v1.0",
},
{
value: "v2.0",
label: "v2.0",
}
]
options: specsToOptions(specs)
},
],
} as const;
Expand Down
18 changes: 7 additions & 11 deletions server/node-service/src/plugins/cloudinary/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readYaml } from "../../common/util";
import { readYaml, specsToOptions } from "../../common/util";
import _ from "lodash";
import path from "path";
import { OpenAPI } from "openapi-types";
Expand All @@ -14,7 +14,12 @@ const specList = [
{ spec: adminApiSpec, id: "admin" },
{ spec: uploadApiSpec, id: "upload" },
];
const specs = {
"v1.0": specList,
"v2.0": specList,
}

//TODO: Thomas
const dataSourceConfig = {
type: "dataSource",
params: [
Expand All @@ -38,16 +43,7 @@ const dataSourceConfig = {
type: "select",
tooltip: "Version of the spec file.",
placeholder: "v1.0",
options: [
{
value: "v1.0",
label: "v1.0",
},
{
value: "v2.0",
label: "v2.0",
}
]
options: specsToOptions(specs)
},
],
} as const;
Expand Down
17 changes: 6 additions & 11 deletions server/node-service/src/plugins/couchdb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { ConfigToType, DataSourcePlugin } from "lowcoder-sdk/dataSource";
import { runOpenApi } from "../openApi";
import { defaultParseOpenApiOptions, parseOpenApi, ParseOpenApiOptions } from "../openApi/parse";
import spec from "./CouchDB-3.1.1-resolved.json";

import { specsToOptions } from "../../common/util";
const specs = {
"v1.0": spec,
"v2.0": spec,
}
const dataSourceConfig = {
type: "dataSource",
params: [
Expand Down Expand Up @@ -44,16 +48,7 @@ const dataSourceConfig = {
type: "select",
tooltip: "Version of the spec file.",
placeholder: "v1.0",
options: [
{
value: "v1.0",
label: "v1.0",
},
{
value: "v2.0",
label: "v2.0",
}
]
options: specsToOptions(specs)
},
],
} as const;
Expand Down
17 changes: 6 additions & 11 deletions server/node-service/src/plugins/datadog/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readYaml } from "../../common/util";
import { readYaml, specsToOptions } from "../../common/util";
import _ from "lodash";
import path from "path";
import { OpenAPIV3, OpenAPI } from "openapi-types";
Expand All @@ -7,6 +7,10 @@ import { runOpenApi } from "../openApi";
import { parseOpenApi, ParseOpenApiOptions } from "../openApi/parse";

const spec = readYaml(path.join(__dirname, "./datadog.spec.yaml"));
const specs = {
"v1.0": spec,
"v2.0": spec,
}

const dataSourceConfig = {
type: "dataSource",
Expand All @@ -33,16 +37,7 @@ const dataSourceConfig = {
type: "select",
tooltip: "Version of the spec file.",
placeholder: "v1.0",
options: [
{
value: "v1.0",
label: "v1.0",
},
{
value: "v2.0",
label: "v2.0",
}
]
options: specsToOptions(specs)
},
],
} as const;
Expand Down
43 changes: 11 additions & 32 deletions server/node-service/src/plugins/did/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
import { readYaml } from "../../common/util";
import { dirToSpecList, specsToOptions } from "../../common/util";
import _ from "lodash";
import path from "path";
import { OpenAPIV3, OpenAPI } from "openapi-types";
import { QueryConfig, ConfigToType, DataSourcePlugin } from "lowcoder-sdk/dataSource";
import { OpenAPI } from "openapi-types";
import { ConfigToType, DataSourcePlugin, QueryConfig } from "lowcoder-sdk/dataSource";
import { runOpenApi } from "../openApi";
import { MultiOpenApiSpecItem, parseMultiOpenApi, ParseOpenApiOptions } from "../openApi/parse";
import { appendTags } from "../../plugins/openApi/util";
import { readdirSync } from "fs";
import { parseMultiOpenApi, ParseOpenApiOptions } from "../openApi/parse";

const specList: MultiOpenApiSpecItem[] = [];
const specFiles = readdirSync(path.join(__dirname, "./did.spec"));
const start = performance.now();
specFiles.forEach((specFile) => {
const spec = readYaml(path.join(__dirname, "./did.spec", specFile));
const tag = _.upperFirst(specFile.replace(".json", ""));
appendTags(spec, tag);
specList.push({
spec,
id: tag,
});
});
logger.info("did spec list loaded, duration: %d ms", performance.now() - start);
const specs = {
"v1.0": dirToSpecList(path.join(__dirname, "./did.spec")),
}

const dataSourceConfig = {
type: "dataSource",
Expand Down Expand Up @@ -50,16 +38,7 @@ const dataSourceConfig = {
type: "select",
tooltip: "Version of the spec file.",
placeholder: "v1.0",
options: [
{
value: "v1.0",
label: "v1.0",
},
{
value: "v2.0",
label: "v2.0",
}
]
options: specsToOptions(specs)
},
],
} as const;
Expand All @@ -80,9 +59,9 @@ const didPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
icon: "did.svg",
category: "api",
dataSourceConfig,
queryConfig: async () => {
queryConfig: async (data) => {
if (!queryConfig) {
const { actions, categories } = await parseMultiOpenApi(specList, parseOptions);
const { actions, categories } = await parseMultiOpenApi(specs[data.specVersion as keyof typeof specs], parseOptions);
queryConfig = {
type: "query",
label: "Action",
Expand All @@ -102,7 +81,7 @@ const didPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
dynamicParamsConfig: dataSourceConfig,
specVersion: dataSourceConfig.specVersion,
};
return runOpenApi(actionData, runApiDsConfig, specList);
return runOpenApi(actionData, runApiDsConfig, specs[dataSourceConfig.specVersion as keyof typeof specs]);
},
};

Expand Down
16 changes: 6 additions & 10 deletions server/node-service/src/plugins/front/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { runOpenApi } from "../openApi";
import { parseOpenApi, ParseOpenApiOptions } from "../openApi/parse";

import spec from "./front.spec.json";
import { specsToOptions } from "../../common/util";
const specs = {
"v1.0": spec,
"v2.0": spec,
}

const dataSourceConfig = {
type: "dataSource",
Expand All @@ -20,16 +25,7 @@ const dataSourceConfig = {
type: "select",
tooltip: "Version of the spec file.",
placeholder: "v1.0",
options: [
{
value: "v1.0",
label: "v1.0",
},
{
value: "v2.0",
label: "v2.0",
}
]
options: specsToOptions(specs)
},
],
} as const;
Expand Down
17 changes: 6 additions & 11 deletions server/node-service/src/plugins/github/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readYaml } from "../../common/util";
import { readYaml, specsToOptions } from "../../common/util";
import _ from "lodash";
import path from "path";
import { OpenAPIV3, OpenAPI } from "openapi-types";
Expand All @@ -8,6 +8,10 @@ import { parseOpenApi, ParseOpenApiOptions } from "../openApi/parse";
import SwaggerParser from "@apidevtools/swagger-parser";

const spec = readYaml(path.join(__dirname, "./github.spec.yaml"));
const specs = {
"v1.0": spec,
"v2.0": spec,
}

const dataSourceConfig = {
type: "dataSource",
Expand All @@ -33,16 +37,7 @@ const dataSourceConfig = {
type: "select",
tooltip: "Version of the spec file.",
placeholder: "v1.0",
options: [
{
value: "v1.0",
label: "v1.0",
},
{
value: "v2.0",
label: "v2.0",
}
]
options: specsToOptions(specs)
},
],
} as const;
Expand Down
16 changes: 6 additions & 10 deletions server/node-service/src/plugins/huggingFaceEndpoint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { runOpenApi } from "../openApi";
import { parseOpenApi, ParseOpenApiOptions } from "../openApi/parse";

import spec from "./huggingFace.spec.json";
import { specsToOptions } from "../../common/util";
const specs = {
"v1.0": spec,
"v2.0": spec,
}

const dataSourceConfig = {
type: "dataSource",
Expand All @@ -31,16 +36,7 @@ const dataSourceConfig = {
type: "select",
tooltip: "Version of the spec file.",
placeholder: "v1.0",
options: [
{
value: "v1.0",
label: "v1.0",
},
{
value: "v2.0",
label: "v2.0",
}
]
options: specsToOptions(specs)
},
],
} as const;
Expand Down
Loading
Loading