mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 01:21:58 +00:00
feat: split datasource types
This commit is contained in:
parent
a24787870a
commit
fd80698df1
@ -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"
|
||||
},
|
||||
|
||||
@ -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<string, unknown>) {
|
||||
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,
|
||||
|
||||
@ -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"
|
||||
},
|
||||
|
||||
@ -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) => {
|
||||
|
||||
@ -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"
|
||||
},
|
||||
|
||||
@ -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<T = unknown>(
|
||||
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<T>({
|
||||
config,
|
||||
|
||||
@ -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"
|
||||
},
|
||||
|
||||
@ -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';
|
||||
|
||||
|
||||
@ -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"
|
||||
},
|
||||
|
||||
@ -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<T = unknown>(
|
||||
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<T>({
|
||||
config,
|
||||
...options,
|
||||
|
||||
@ -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"
|
||||
},
|
||||
|
||||
@ -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<T = unknown>(
|
||||
searchString: string | T = '',
|
||||
|
||||
3
packages/types-datasource/.eslintignore
Normal file
3
packages/types-datasource/.eslintignore
Normal file
@ -0,0 +1,3 @@
|
||||
lib
|
||||
es
|
||||
node_modules
|
||||
7
packages/types-datasource/.eslintrc.js
Normal file
7
packages/types-datasource/.eslintrc.js
Normal file
@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
extends: '../../.eslintrc',
|
||||
rules: {
|
||||
'@typescript-eslint/member-ordering': 0,
|
||||
indent: 0,
|
||||
},
|
||||
};
|
||||
6
packages/types-datasource/.prettierrc.js
Normal file
6
packages/types-datasource/.prettierrc.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
printWidth: 80,
|
||||
singleQuote: true,
|
||||
trailingComma: 'all',
|
||||
tabSize: 2,
|
||||
};
|
||||
22
packages/types-datasource/package.json
Normal file
22
packages/types-datasource/package.json
Normal file
@ -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"
|
||||
}
|
||||
}
|
||||
4
packages/types-datasource/src/index.ts
Normal file
4
packages/types-datasource/src/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export * from './data-source';
|
||||
export * from './data-source-handlers';
|
||||
export * from './data-source-interpret';
|
||||
export * from './data-source-runtime';
|
||||
91
packages/types-datasource/src/value-type.ts
Normal file
91
packages/types-datasource/src/value-type.ts
Normal file
@ -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';
|
||||
}
|
||||
7
packages/types-datasource/tsconfig.json
Normal file
7
packages/types-datasource/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "es"
|
||||
},
|
||||
"include": ["./src/"]
|
||||
}
|
||||
@ -14,6 +14,7 @@
|
||||
"test:snapshot": "ava --update-snapshots"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ali/lowcode-datasource-types": "^1.0.0",
|
||||
"power-di": "^2.2.4",
|
||||
"react": "^16"
|
||||
},
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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';
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user