From fd80698df14a3d8c6d7dc65f8a16477f5c1aad31 Mon Sep 17 00:00:00 2001 From: "guokai.jgk" Date: Thu, 5 Nov 2020 19:30:31 +0800 Subject: [PATCH] feat: split datasource types --- .../datasource-fetch-handler/package.json | 2 +- .../datasource-fetch-handler/src/index.ts | 5 +- .../datasource-jsonp-handler/package.json | 2 +- .../datasource-jsonp-handler/src/index.ts | 2 +- .../datasource-mopen-handler/package.json | 2 +- .../datasource-mopen-handler/src/index.ts | 3 +- packages/datasource-mtop-handler/package.json | 2 +- packages/datasource-mtop-handler/src/index.ts | 2 +- .../package.json | 2 +- .../src/index.ts | 5 +- .../package.json | 2 +- .../src/index.ts | 2 +- packages/types-datasource/.eslintignore | 3 + packages/types-datasource/.eslintrc.js | 7 ++ packages/types-datasource/.prettierrc.js | 6 ++ packages/types-datasource/package.json | 22 +++++ .../src/data-source-handlers.ts | 0 .../src/data-source-interpret.ts | 0 .../src/data-source-runtime.ts | 0 .../src/data-source.ts | 0 packages/types-datasource/src/index.ts | 4 + packages/types-datasource/src/value-type.ts | 91 +++++++++++++++++++ packages/types-datasource/tsconfig.json | 7 ++ packages/types/package.json | 1 + packages/types/src/index.ts | 5 +- packages/types/src/schema.ts | 10 +- 26 files changed, 167 insertions(+), 20 deletions(-) create mode 100644 packages/types-datasource/.eslintignore create mode 100644 packages/types-datasource/.eslintrc.js create mode 100644 packages/types-datasource/.prettierrc.js create mode 100644 packages/types-datasource/package.json rename packages/{types => types-datasource}/src/data-source-handlers.ts (100%) rename packages/{types => types-datasource}/src/data-source-interpret.ts (100%) rename packages/{types => types-datasource}/src/data-source-runtime.ts (100%) rename packages/{types => types-datasource}/src/data-source.ts (100%) create mode 100644 packages/types-datasource/src/index.ts create mode 100644 packages/types-datasource/src/value-type.ts create mode 100644 packages/types-datasource/tsconfig.json diff --git a/packages/datasource-fetch-handler/package.json b/packages/datasource-fetch-handler/package.json index a713fee09..2bd11b358 100644 --- a/packages/datasource-fetch-handler/package.json +++ b/packages/datasource-fetch-handler/package.json @@ -16,7 +16,7 @@ "prepublishOnly": "npm run build" }, "dependencies": { - "@ali/lowcode-types": "1.0.13-alpha.1", + "@ali/lowcode-datasource-types": "^1.0.0", "typescript": "^3.9.7", "universal-request": "^2.2.0" }, diff --git a/packages/datasource-fetch-handler/src/index.ts b/packages/datasource-fetch-handler/src/index.ts index 2bb5df893..95e0d0491 100644 --- a/packages/datasource-fetch-handler/src/index.ts +++ b/packages/datasource-fetch-handler/src/index.ts @@ -1,11 +1,12 @@ -import { RuntimeOptionsConfig } from '@ali/lowcode-types'; +import { RuntimeOptionsConfig } from '@ali/lowcode-datasource-types'; import request from 'universal-request'; import { RequestOptions, AsObject } from 'universal-request/lib/types'; // config 留着扩展 export function createFetchHandler(config?: Record) { - return async function (options: RuntimeOptionsConfig) { + // eslint-disable-next-line space-before-function-paren + return async function(options: RuntimeOptionsConfig) { const requestConfig: RequestOptions = { ...options, url: options.uri, diff --git a/packages/datasource-jsonp-handler/package.json b/packages/datasource-jsonp-handler/package.json index b61402fed..c98507b90 100644 --- a/packages/datasource-jsonp-handler/package.json +++ b/packages/datasource-jsonp-handler/package.json @@ -16,7 +16,7 @@ "prepublishOnly": "npm run build" }, "dependencies": { - "@ali/lowcode-types": "1.0.13-alpha.1", + "@ali/lowcode-datasource-types": "^1.0.0", "jsonp": "^0.2.1", "typescript": "^3.9.7" }, diff --git a/packages/datasource-jsonp-handler/src/index.ts b/packages/datasource-jsonp-handler/src/index.ts index ca2d58bf8..de3882513 100644 --- a/packages/datasource-jsonp-handler/src/index.ts +++ b/packages/datasource-jsonp-handler/src/index.ts @@ -1,4 +1,4 @@ -import { RuntimeOptionsConfig } from '@ali/lowcode-types'; +import { RuntimeOptionsConfig } from '@ali/lowcode-datasource-types'; import jsonp from 'jsonp'; const handleJsonpFetch = (url: string, param: string, name: string) => { diff --git a/packages/datasource-mopen-handler/package.json b/packages/datasource-mopen-handler/package.json index 8bd090c0c..6ebca92a1 100644 --- a/packages/datasource-mopen-handler/package.json +++ b/packages/datasource-mopen-handler/package.json @@ -16,7 +16,7 @@ "prepublishOnly": "npm run build" }, "dependencies": { - "@ali/lowcode-types": "^1.0.16", + "@ali/lowcode-datasource-types": "^1.0.0", "@ali/mirror-io-client-mopen": "1.0.0-beta.16", "typescript": "^3.9.7" }, diff --git a/packages/datasource-mopen-handler/src/index.ts b/packages/datasource-mopen-handler/src/index.ts index 20fa4d2cc..beed626e0 100644 --- a/packages/datasource-mopen-handler/src/index.ts +++ b/packages/datasource-mopen-handler/src/index.ts @@ -4,7 +4,7 @@ import { MOPEN_APPKEY_XSPACE_PRE_ONLINE, MOPEN_DOMAIN_TAOBAO_PRE_ONLINE, } from '@ali/mirror-io-client-mopen'; -import { RuntimeOptionsConfig } from '@ali/lowcode-types'; +import { RuntimeOptionsConfig } from '@ali/lowcode-datasource-types'; type Method = 'get' | 'post' | 'GET' | 'POST'; @@ -16,6 +16,7 @@ export function createMopenHandler( appKey: MOPEN_APPKEY_XSPACE_PRE_ONLINE, }, ) { + // eslint-disable-next-line space-before-function-paren return async function(options: RuntimeOptionsConfig): Promise<{ data: T }> { const { data, response } = await MopenClient.request({ config, diff --git a/packages/datasource-mtop-handler/package.json b/packages/datasource-mtop-handler/package.json index 0c8d1eb31..1bfede478 100644 --- a/packages/datasource-mtop-handler/package.json +++ b/packages/datasource-mtop-handler/package.json @@ -16,7 +16,7 @@ "prepublishOnly": "npm run build" }, "dependencies": { - "@ali/lowcode-types": "1.0.13-alpha.1", + "@ali/lowcode-datasource-types": "^1.0.0", "@ali/universal-mtop": "^5.1.9", "typescript": "^3.9.7" }, diff --git a/packages/datasource-mtop-handler/src/index.ts b/packages/datasource-mtop-handler/src/index.ts index a582076da..a508f394e 100644 --- a/packages/datasource-mtop-handler/src/index.ts +++ b/packages/datasource-mtop-handler/src/index.ts @@ -1,6 +1,6 @@ import mtopRequest from '@ali/universal-mtop'; -import { RuntimeOptionsConfig } from '@ali/lowcode-types'; +import { RuntimeOptionsConfig } from '@ali/lowcode-datasource-types'; export type Method = 'get' | 'post' | 'GET' | 'POST'; diff --git a/packages/datasource-universal-mtop-handler/package.json b/packages/datasource-universal-mtop-handler/package.json index bbb6f879f..727cbb299 100644 --- a/packages/datasource-universal-mtop-handler/package.json +++ b/packages/datasource-universal-mtop-handler/package.json @@ -16,7 +16,7 @@ "prepublishOnly": "npm run build" }, "dependencies": { - "@ali/lowcode-types": "^1.0.16", + "@ali/lowcode-datasource-types": "^1.0.0", "@ali/mirror-io-client-universal-mtop": "1.0.0-beta.16", "typescript": "^3.9.7" }, diff --git a/packages/datasource-universal-mtop-handler/src/index.ts b/packages/datasource-universal-mtop-handler/src/index.ts index 81cad731d..09138fcbe 100644 --- a/packages/datasource-universal-mtop-handler/src/index.ts +++ b/packages/datasource-universal-mtop-handler/src/index.ts @@ -3,7 +3,7 @@ import { UniversalMtopClientConfig, } from '@ali/mirror-io-client-universal-mtop'; -import { RuntimeOptionsConfig } from '@ali/lowcode-types'; +import { RuntimeOptionsConfig } from '@ali/lowcode-datasource-types'; type Method = 'get' | 'post' | 'GET' | 'POST'; @@ -12,7 +12,8 @@ type DataType = 'jsonp' | 'json' | 'originaljsonp'; export function createMopenHandler( config?: UniversalMtopClientConfig, ) { - return async function (options: RuntimeOptionsConfig): Promise<{ data: T }> { + // eslint-disable-next-line space-before-function-paren + return async function(options: RuntimeOptionsConfig): Promise<{ data: T }> { const { data, response } = await UniversalMtopClient.request({ config, ...options, diff --git a/packages/datasource-url-params-handler/package.json b/packages/datasource-url-params-handler/package.json index 61c6fb292..e77926ba0 100644 --- a/packages/datasource-url-params-handler/package.json +++ b/packages/datasource-url-params-handler/package.json @@ -16,7 +16,7 @@ "prepublishOnly": "npm run build" }, "dependencies": { - "@ali/lowcode-types": "^1.0.16", + "@ali/lowcode-datasource-types": "^1.0.0", "query-string": "^6.13.1", "typescript": "^3.9.7" }, diff --git a/packages/datasource-url-params-handler/src/index.ts b/packages/datasource-url-params-handler/src/index.ts index 589f2d2c8..3b2fb8ee6 100644 --- a/packages/datasource-url-params-handler/src/index.ts +++ b/packages/datasource-url-params-handler/src/index.ts @@ -1,5 +1,5 @@ import qs from 'query-string'; -import { UrlParamsHandler } from '@ali/lowcode-types'; +import { UrlParamsHandler } from '@ali/lowcode-datasource-types'; export function createUrlParamsHandler( searchString: string | T = '', diff --git a/packages/types-datasource/.eslintignore b/packages/types-datasource/.eslintignore new file mode 100644 index 000000000..a218a6cce --- /dev/null +++ b/packages/types-datasource/.eslintignore @@ -0,0 +1,3 @@ +lib +es +node_modules \ No newline at end of file diff --git a/packages/types-datasource/.eslintrc.js b/packages/types-datasource/.eslintrc.js new file mode 100644 index 000000000..f7538bcee --- /dev/null +++ b/packages/types-datasource/.eslintrc.js @@ -0,0 +1,7 @@ +module.exports = { + extends: '../../.eslintrc', + rules: { + '@typescript-eslint/member-ordering': 0, + indent: 0, + }, +}; diff --git a/packages/types-datasource/.prettierrc.js b/packages/types-datasource/.prettierrc.js new file mode 100644 index 000000000..092b67059 --- /dev/null +++ b/packages/types-datasource/.prettierrc.js @@ -0,0 +1,6 @@ +module.exports = { + printWidth: 80, + singleQuote: true, + trailingComma: 'all', + tabSize: 2, +}; diff --git a/packages/types-datasource/package.json b/packages/types-datasource/package.json new file mode 100644 index 000000000..52c922430 --- /dev/null +++ b/packages/types-datasource/package.json @@ -0,0 +1,22 @@ +{ + "name": "@ali/lowcode-datasource-types", + "version": "1.0.0", + "main": "lib/index.js", + "module": "es/index.js", + "typings": "es/index.d.ts", + "files": [ + "src", + "lib", + "es" + ], + "scripts": { + "dev": "tsc --watch", + "clean": "rm -rf es lib", + "build": "npm run clean && tsc && tsc --outDir ./lib --module commonjs ", + "prepublishOnly": "npm run build" + }, + "dependencies": {}, + "publishConfig": { + "registry": "https://registry.npm.alibaba-inc.com" + } +} diff --git a/packages/types/src/data-source-handlers.ts b/packages/types-datasource/src/data-source-handlers.ts similarity index 100% rename from packages/types/src/data-source-handlers.ts rename to packages/types-datasource/src/data-source-handlers.ts diff --git a/packages/types/src/data-source-interpret.ts b/packages/types-datasource/src/data-source-interpret.ts similarity index 100% rename from packages/types/src/data-source-interpret.ts rename to packages/types-datasource/src/data-source-interpret.ts diff --git a/packages/types/src/data-source-runtime.ts b/packages/types-datasource/src/data-source-runtime.ts similarity index 100% rename from packages/types/src/data-source-runtime.ts rename to packages/types-datasource/src/data-source-runtime.ts diff --git a/packages/types/src/data-source.ts b/packages/types-datasource/src/data-source.ts similarity index 100% rename from packages/types/src/data-source.ts rename to packages/types-datasource/src/data-source.ts diff --git a/packages/types-datasource/src/index.ts b/packages/types-datasource/src/index.ts new file mode 100644 index 000000000..f7f9d21d3 --- /dev/null +++ b/packages/types-datasource/src/index.ts @@ -0,0 +1,4 @@ +export * from './data-source'; +export * from './data-source-handlers'; +export * from './data-source-interpret'; +export * from './data-source-runtime'; diff --git a/packages/types-datasource/src/value-type.ts b/packages/types-datasource/src/value-type.ts new file mode 100644 index 000000000..bb959b498 --- /dev/null +++ b/packages/types-datasource/src/value-type.ts @@ -0,0 +1,91 @@ +// 表达式 +export interface JSExpression { + type: 'JSExpression'; + /** + * 表达式字符串 + */ + value: string; + /** + * 模拟值 + */ + mock?: any; + /** 源码 */ + compiled?: string; +} + +// 函数 +export interface JSFunction { + type: 'JSFunction'; + /** + * 表达式字符串 + */ + value: string; +} + +/** + * 事件函数类型 + * @see https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#feHTW + */ +export interface JSFunction { + type: 'JSFunction'; + + /** + * 函数定义,或直接函数表达式 + */ + value: string; + + /** 源码 */ + compiled?: string; +} + +// 函数 +export interface JSFunction { + type: 'JSFunction'; + /** + * 函数字符串 + */ + value: string; + /** + * 模拟值 + */ + mock?: any; + /** + * 额外扩展属性,如 extType、events + */ + [key: string]: any; +} + +// JSON 基本类型 +export type JSONValue = + | boolean + | string + | number + | null + | undefined + | JSONArray + | JSONObject; +export type JSONArray = JSONValue[]; +export interface JSONObject { + [key: string]: JSONValue; +} + +// 复合类型 +export type CompositeValue = + | JSONValue + | JSExpression + | JSFunction + // | JSSlot // 后续这里应该要再提取一个 base types + | CompositeArray + | CompositeObject; +export type CompositeArray = CompositeValue[]; +export interface CompositeObject { + [key: string]: CompositeValue; +} + +export function isJSExpression(data: any): data is JSExpression { + return data && data.type === 'JSExpression'; +} + +export function isJSFunction(x: any): x is JSFunction { + return typeof x === 'object' && x && x.type === 'JSFunction'; +} diff --git a/packages/types-datasource/tsconfig.json b/packages/types-datasource/tsconfig.json new file mode 100644 index 000000000..af012d64b --- /dev/null +++ b/packages/types-datasource/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "es" + }, + "include": ["./src/"] +} diff --git a/packages/types/package.json b/packages/types/package.json index 0381c0135..31e4f24ea 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -14,6 +14,7 @@ "test:snapshot": "ava --update-snapshots" }, "dependencies": { + "@ali/lowcode-datasource-types": "^1.0.0", "power-di": "^2.2.4", "react": "^16" }, diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 6649f4336..64db05263 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -1,7 +1,4 @@ -export * from './data-source'; -export * from './data-source-handlers'; -export * from './data-source-interpret'; -export * from './data-source-runtime'; +export * from '@ali/lowcode-datasource-types'; export * from './editor'; export * from './field-config'; export * from './i18n'; diff --git a/packages/types/src/schema.ts b/packages/types/src/schema.ts index 54fa734ff..97df0921e 100644 --- a/packages/types/src/schema.ts +++ b/packages/types/src/schema.ts @@ -1,6 +1,12 @@ +import { InterpretDataSource as DataSource } from '@ali/lowcode-datasource-types'; import { ComponentsMap } from './npm'; -import { CompositeValue, JSExpression, JSFunction, CompositeObject, JSONObject } from './value-type'; -import { InterpretDataSource as DataSource } from './data-source-interpret'; +import { + CompositeValue, + JSExpression, + JSFunction, + CompositeObject, + JSONObject, +} from './value-type'; import { I18nMap } from './i18n'; import { UtilsMap } from './utils';