feat: split datasource types

This commit is contained in:
guokai.jgk 2020-11-05 19:30:31 +08:00
parent a24787870a
commit fd80698df1
26 changed files with 167 additions and 20 deletions

View File

@ -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"
},

View File

@ -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,

View File

@ -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"
},

View File

@ -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) => {

View File

@ -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"
},

View File

@ -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,

View File

@ -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"
},

View File

@ -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';

View File

@ -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"
},

View File

@ -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,

View File

@ -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"
},

View File

@ -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 = '',

View File

@ -0,0 +1,3 @@
lib
es
node_modules

View File

@ -0,0 +1,7 @@
module.exports = {
extends: '../../.eslintrc',
rules: {
'@typescript-eslint/member-ordering': 0,
indent: 0,
},
};

View File

@ -0,0 +1,6 @@
module.exports = {
printWidth: 80,
singleQuote: true,
trailingComma: 'all',
tabSize: 2,
};

View 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"
}
}

View File

@ -0,0 +1,4 @@
export * from './data-source';
export * from './data-source-handlers';
export * from './data-source-interpret';
export * from './data-source-runtime';

View 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;
/**
* extTypeevents
*/
[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';
}

View File

@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "es"
},
"include": ["./src/"]
}

View File

@ -14,6 +14,7 @@
"test:snapshot": "ava --update-snapshots"
},
"dependencies": {
"@ali/lowcode-datasource-types": "^1.0.0",
"power-di": "^2.2.4",
"react": "^16"
},

View File

@ -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';

View File

@ -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';