From 2b9bcb5174466371663fa5496ccd93dc2e4dc7c4 Mon Sep 17 00:00:00 2001 From: "guokai.jgk" Date: Tue, 13 Oct 2020 17:06:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=20datasource-handler?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/datasource-engine/.eslintignore | 4 +- packages/datasource-engine/.eslintrc.js | 4 +- packages/datasource-engine/.prettierrc.js | 2 +- packages/datasource-engine/package.json | 7 +- .../src/core/RuntimeDataSourceItem.ts | 21 +-- .../datasource-engine/src/core/adapter.ts | 21 ++- .../src/core/reloadDataSourceFactory.ts | 16 +- .../datasource-engine/src/helpers/index.ts | 3 +- .../src/interpret/DataSourceEngineFactory.ts | 25 ++- .../runtime/RuntimeDataSourceEngineFactory.ts | 19 +- packages/datasource-engine/src/utils.ts | 40 +++-- .../test/_helpers/mock-context.ts | 11 +- .../_datasource-runtime.ts | 2 +- .../_datasource-schema.ts | 4 +- .../p0-0-simplest-defaults/_macro-abnormal.ts | 74 ++++---- .../p0-0-simplest-defaults/_macro-normal.ts | 110 ++++++------ .../_datasource-runtime.ts | 2 +- .../_datasource-schema.ts | 4 +- .../_macro-abnormal.ts | 140 +++++++-------- .../_macro-normal.ts | 132 +++++++------- .../p0-0-url-params/_datasource-runtime.ts | 2 +- .../p0-0-url-params/_datasource-schema.ts | 4 +- .../scenes/p0-0-url-params/_macro-normal.ts | 94 +++++----- .../_datasource-runtime.ts | 2 +- .../_datasource-schema.ts | 4 +- .../_macro-abnormal.ts | 114 ++++++------ .../_macro-normal.ts | 140 +++++++-------- .../_datasource-runtime.ts | 2 +- .../_datasource-schema.ts | 4 +- .../_macro-abnormal.ts | 84 ++++----- .../_macro-normal.ts | 110 ++++++------ .../_datasource-runtime.ts | 2 +- .../_datasource-schema.ts | 4 +- .../_macro-abnormal.ts | 114 ++++++------ .../_macro-normal.ts | 140 +++++++-------- .../_datasource-runtime.ts | 2 +- .../_datasource-schema.ts | 4 +- .../_macro-normal.ts | 164 +++++++++--------- .../datasource-fetch-handler/.eslintignore | 3 + .../.eslintrc.js | 2 +- .../.prettierrc.js | 2 +- .../package.json | 4 +- .../src/index.ts | 2 +- .../tsconfig.json | 21 ++- packages/datasource-handlers/.eslintignore | 1 - packages/datasource-handlers/lerna.json | 5 - packages/datasource-handlers/package.json | 9 - .../packages/fetch/es/index.d.ts | 2 - .../packages/fetch/es/index.js | 25 --- .../packages/fetch/tsconfig.json | 10 -- .../packages/mopen/es/index.d.ts | 5 - .../packages/mopen/es/index.js | 26 --- .../packages/mopen/tsconfig.json | 10 -- .../packages/mtop/es/index.d.ts | 6 - .../packages/mtop/es/index.js | 35 ---- .../packages/mtop/tsconfig.json | 10 -- .../packages/universalMtop/es/index.d.ts | 5 - .../packages/universalMtop/es/index.js | 23 --- .../packages/universalMtop/tsconfig.json | 10 -- .../packages/urlParams/es/index.d.ts | 2 - .../packages/urlParams/es/index.js | 21 --- .../packages/urlParams/tsconfig.json | 10 -- .../datasource-mopen-handler/.eslintignore | 3 + .../datasource-mopen-handler/.eslintrc.js | 7 + .../datasource-mopen-handler/.prettierrc.js | 4 + .../package.json | 4 +- .../src/index.ts | 2 +- .../datasource-mopen-handler/tsconfig.json | 70 ++++++++ .../datasource-mtop-handler/.eslintignore | 3 + packages/datasource-mtop-handler/.eslintrc.js | 7 + .../datasource-mtop-handler/.prettierrc.js | 4 + .../package.json | 4 +- .../src/index.ts | 2 +- .../src/typings.d.ts | 0 .../datasource-mtop-handler/tsconfig.json | 70 ++++++++ .../.eslintignore | 3 + .../.eslintrc.js | 7 + .../.prettierrc.js | 4 + .../package.json | 4 +- .../src/index.ts | 2 +- .../tsconfig.json | 70 ++++++++ .../.eslintignore | 3 + .../.eslintrc.js | 7 + .../.prettierrc.js | 0 .../package.json | 4 +- .../src/index.ts | 2 +- .../tsconfig.json | 70 ++++++++ packages/types/.eslintignore | 3 + packages/types/.eslintrc.js | 9 + packages/types/.prettierrc.js | 6 + packages/types/src/data-source-handlers.ts | 15 ++ packages/types/src/data-source-interpret.ts | 41 +++++ packages/types/src/data-source-runtime.ts | 53 ++++++ packages/types/src/data-source.ts | 73 ++++++-- packages/types/src/index.ts | 3 + packages/types/src/value-type.ts | 63 ++++++- 96 files changed, 1426 insertions(+), 1076 deletions(-) create mode 100644 packages/datasource-fetch-handler/.eslintignore rename packages/{datasource-handlers => datasource-fetch-handler}/.eslintrc.js (78%) rename packages/{datasource-handlers => datasource-fetch-handler}/.prettierrc.js (61%) rename packages/{datasource-handlers/packages/fetch => datasource-fetch-handler}/package.json (88%) rename packages/{datasource-handlers/packages/fetch => datasource-fetch-handler}/src/index.ts (90%) rename packages/{datasource-handlers => datasource-fetch-handler}/tsconfig.json (95%) delete mode 100644 packages/datasource-handlers/.eslintignore delete mode 100644 packages/datasource-handlers/lerna.json delete mode 100644 packages/datasource-handlers/package.json delete mode 100644 packages/datasource-handlers/packages/fetch/es/index.d.ts delete mode 100644 packages/datasource-handlers/packages/fetch/es/index.js delete mode 100644 packages/datasource-handlers/packages/fetch/tsconfig.json delete mode 100644 packages/datasource-handlers/packages/mopen/es/index.d.ts delete mode 100644 packages/datasource-handlers/packages/mopen/es/index.js delete mode 100644 packages/datasource-handlers/packages/mopen/tsconfig.json delete mode 100644 packages/datasource-handlers/packages/mtop/es/index.d.ts delete mode 100644 packages/datasource-handlers/packages/mtop/es/index.js delete mode 100644 packages/datasource-handlers/packages/mtop/tsconfig.json delete mode 100644 packages/datasource-handlers/packages/universalMtop/es/index.d.ts delete mode 100644 packages/datasource-handlers/packages/universalMtop/es/index.js delete mode 100644 packages/datasource-handlers/packages/universalMtop/tsconfig.json delete mode 100644 packages/datasource-handlers/packages/urlParams/es/index.d.ts delete mode 100644 packages/datasource-handlers/packages/urlParams/es/index.js delete mode 100644 packages/datasource-handlers/packages/urlParams/tsconfig.json create mode 100644 packages/datasource-mopen-handler/.eslintignore create mode 100644 packages/datasource-mopen-handler/.eslintrc.js create mode 100644 packages/datasource-mopen-handler/.prettierrc.js rename packages/{datasource-handlers/packages/mopen => datasource-mopen-handler}/package.json (89%) rename packages/{datasource-handlers/packages/mopen => datasource-mopen-handler}/src/index.ts (93%) create mode 100644 packages/datasource-mopen-handler/tsconfig.json create mode 100644 packages/datasource-mtop-handler/.eslintignore create mode 100644 packages/datasource-mtop-handler/.eslintrc.js create mode 100644 packages/datasource-mtop-handler/.prettierrc.js rename packages/{datasource-handlers/packages/mtop => datasource-mtop-handler}/package.json (88%) rename packages/{datasource-handlers/packages/mtop => datasource-mtop-handler}/src/index.ts (93%) rename packages/{datasource-handlers/packages/mtop => datasource-mtop-handler}/src/typings.d.ts (100%) create mode 100644 packages/datasource-mtop-handler/tsconfig.json create mode 100644 packages/datasource-universal-mtop-handler/.eslintignore create mode 100644 packages/datasource-universal-mtop-handler/.eslintrc.js create mode 100644 packages/datasource-universal-mtop-handler/.prettierrc.js rename packages/{datasource-handlers/packages/universalMtop => datasource-universal-mtop-handler}/package.json (89%) rename packages/{datasource-handlers/packages/universalMtop => datasource-universal-mtop-handler}/src/index.ts (92%) create mode 100644 packages/datasource-universal-mtop-handler/tsconfig.json create mode 100644 packages/datasource-url-params-handler/.eslintignore create mode 100644 packages/datasource-url-params-handler/.eslintrc.js create mode 100644 packages/datasource-url-params-handler/.prettierrc.js rename packages/{datasource-handlers/packages/urlParams => datasource-url-params-handler}/package.json (88%) rename packages/{datasource-handlers/packages/urlParams => datasource-url-params-handler}/src/index.ts (85%) create mode 100644 packages/datasource-url-params-handler/tsconfig.json create mode 100644 packages/types/.eslintignore create mode 100644 packages/types/.eslintrc.js create mode 100644 packages/types/.prettierrc.js create mode 100644 packages/types/src/data-source-handlers.ts create mode 100644 packages/types/src/data-source-interpret.ts create mode 100644 packages/types/src/data-source-runtime.ts diff --git a/packages/datasource-engine/.eslintignore b/packages/datasource-engine/.eslintignore index 30bc16279..fecb7c26d 100644 --- a/packages/datasource-engine/.eslintignore +++ b/packages/datasource-engine/.eslintignore @@ -1 +1,3 @@ -/node_modules \ No newline at end of file +/node_modules +/es +/lib \ No newline at end of file diff --git a/packages/datasource-engine/.eslintrc.js b/packages/datasource-engine/.eslintrc.js index b33327802..8c13fcaf4 100644 --- a/packages/datasource-engine/.eslintrc.js +++ b/packages/datasource-engine/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { - extends: '../../.eslintrc.js', + extends: '../../.eslintrc', rules: { '@typescript-eslint/no-parameter-properties': 1, - 'no-param-reassign': 0 + 'no-param-reassign': 0, }, }; diff --git a/packages/datasource-engine/.prettierrc.js b/packages/datasource-engine/.prettierrc.js index d2db80ead..de2f53cdf 100644 --- a/packages/datasource-engine/.prettierrc.js +++ b/packages/datasource-engine/.prettierrc.js @@ -1,4 +1,4 @@ module.exports = { singleQuote: true, - trailingComma: 'always', + trailingComma: 'all', }; diff --git a/packages/datasource-engine/package.json b/packages/datasource-engine/package.json index 99c775919..6479c7c0b 100644 --- a/packages/datasource-engine/package.json +++ b/packages/datasource-engine/package.json @@ -15,15 +15,10 @@ }, "typings": "dist/index.d.ts", "dependencies": { - "@ali/build-success-types": "^0.1.2-alpha.35", + "@ali/lowcode-types": "^0.8.13", "typescript": "^3.9.7" }, "devDependencies": { - "@ali/datasource-engine-universal-mtop-handler": "1.0.0-alpha.2", - "@ali/datasource-engine-url-params-handler": "^1.0.0-alpha.3", - "@ali/lowcode-datasource-http-handler": "^1.0.0-alpha.1", - "@ali/lowcode-datasource-url-params-handler": "^1.0.0-alpha.3", - "@ali/ng-lc-types": "^1.0.0-r2009222d5o6k8r8", "@ava/babel": "^1.0.1", "@types/sinon": "^9.0.5", "ava": "3.11.1", diff --git a/packages/datasource-engine/src/core/RuntimeDataSourceItem.ts b/packages/datasource-engine/src/core/RuntimeDataSourceItem.ts index b2dff9bb1..d4184707a 100644 --- a/packages/datasource-engine/src/core/RuntimeDataSourceItem.ts +++ b/packages/datasource-engine/src/core/RuntimeDataSourceItem.ts @@ -1,12 +1,13 @@ +/* eslint-disable @typescript-eslint/indent */ import { + IDataSourceRuntimeContext, IRuntimeDataSource, + RequestHandler, RuntimeDataSourceConfig, RuntimeDataSourceStatus, - IRuntimeContext, - RequestHandler, RuntimeOptionsConfig, UrlParamsHandler, -} from '@ali/build-success-types'; +} from '@ali/lowcode-types'; class RuntimeDataSourceItem< TParams extends Record = Record, @@ -21,19 +22,19 @@ class RuntimeDataSourceItem< private _dataSourceConfig: RuntimeDataSourceConfig; private _request: - | RequestHandler<{ data: TResultData }> - | UrlParamsHandler; + | RequestHandler<{ data: TResultData }> + | UrlParamsHandler; - private _context: IRuntimeContext; + private _context: IDataSourceRuntimeContext; private _options?: RuntimeOptionsConfig; constructor( dataSourceConfig: RuntimeDataSourceConfig, request: - | RequestHandler<{ data: TResultData }> - | UrlParamsHandler, - context: IRuntimeContext, + | RequestHandler<{ data: TResultData }> + | UrlParamsHandler, + context: IDataSourceRuntimeContext, ) { this._dataSourceConfig = dataSourceConfig; this._request = request; @@ -52,7 +53,7 @@ class RuntimeDataSourceItem< return this._status; } - public async load(params?: TParams) { + async load(params?: TParams) { if (!this._dataSourceConfig) return; // 考虑没有绑定对应的 handler 的情况 if (!this._request) { diff --git a/packages/datasource-engine/src/core/adapter.ts b/packages/datasource-engine/src/core/adapter.ts index b1274b6ae..41a476bc7 100644 --- a/packages/datasource-engine/src/core/adapter.ts +++ b/packages/datasource-engine/src/core/adapter.ts @@ -7,16 +7,19 @@ import { } from './../utils'; // 将不同渠道给的 schema 转为 runtime 需要的类型 -import { - DataSource, - IPageContext, - DataSourceConfig, - RuntimeDataSourceConfig, - DataSourceMap, -} from '@ali/build-success-types'; import { defaultDataHandler, defaultWillFetch } from '../helpers'; +import { + DataSourceMap, + IDataSourceRuntimeContext, + InterpretDataSource, + InterpretDataSourceConfig, + RuntimeDataSourceConfig, +} from '@ali/lowcode-types'; -const adapt2Runtime = (dataSource: DataSource, context: IPageContext) => { +const adapt2Runtime = ( + dataSource: InterpretDataSource, + context: IDataSourceRuntimeContext, +) => { const { list: interpretConfigList, dataHandler: interpretDataHandler, @@ -34,7 +37,7 @@ const adapt2Runtime = (dataSource: DataSource, context: IPageContext) => { }; } const list: RuntimeDataSourceConfig[] = interpretConfigList.map( - (el: DataSourceConfig) => { + (el: InterpretDataSourceConfig) => { return { id: el.id, isInit: diff --git a/packages/datasource-engine/src/core/reloadDataSourceFactory.ts b/packages/datasource-engine/src/core/reloadDataSourceFactory.ts index ac8776341..8433d0d0a 100644 --- a/packages/datasource-engine/src/core/reloadDataSourceFactory.ts +++ b/packages/datasource-engine/src/core/reloadDataSourceFactory.ts @@ -1,8 +1,8 @@ import { - RuntimeDataSource, DataSourceMap, + RuntimeDataSource, RuntimeDataSourceConfig, -} from '@ali/build-success-types'; +} from '@ali/lowcode-types'; export const reloadDataSourceFactory = ( dataSource: RuntimeDataSource, @@ -14,7 +14,8 @@ export const reloadDataSourceFactory = ( // 单独处理 urlParams 类型的 dataSource.list .filter( - (el: RuntimeDataSourceConfig) => el.type === 'urlParams' && + (el: RuntimeDataSourceConfig) => + el.type === 'urlParams' && (typeof el.isInit === 'boolean' ? el.isInit : true), ) .forEach((el: RuntimeDataSourceConfig) => { @@ -50,13 +51,8 @@ export const reloadDataSourceFactory = ( ds.isInit && ds.isSync ) { - // TODO: 我理解这个异常也应该吃掉的,待确认 - try { - // eslint-disable-next-line no-await-in-loop - await dataSourceMap[ds.id].load(); - } catch (e) { - console.error(e); - } + // eslint-disable-next-line no-await-in-loop + await dataSourceMap[ds.id].load(); } } diff --git a/packages/datasource-engine/src/helpers/index.ts b/packages/datasource-engine/src/helpers/index.ts index d13e747f6..71565b434 100644 --- a/packages/datasource-engine/src/helpers/index.ts +++ b/packages/datasource-engine/src/helpers/index.ts @@ -1,5 +1,6 @@ -import { DataHandler } from '@ali/build-success-types'; +import { DataHandler } from '@ali/lowcode-types'; +// eslint-disable-next-line @typescript-eslint/no-empty-function function noop() {} // 默认的 dataSourceItem 的 dataHandler diff --git a/packages/datasource-engine/src/interpret/DataSourceEngineFactory.ts b/packages/datasource-engine/src/interpret/DataSourceEngineFactory.ts index a31a5a095..4adcf1f82 100644 --- a/packages/datasource-engine/src/interpret/DataSourceEngineFactory.ts +++ b/packages/datasource-engine/src/interpret/DataSourceEngineFactory.ts @@ -1,15 +1,14 @@ -import { - IRuntimeContext, - IRuntimeDataSource, - DataSource, - RuntimeDataSourceConfig, - RuntimeDataSource, - RequestHandlersMap, -} from '@ali/build-success-types'; - import { adapt2Runtime } from '../core/adapter'; import { RuntimeDataSourceItem } from '../core/RuntimeDataSourceItem'; import { reloadDataSourceFactory } from '../core/reloadDataSourceFactory'; +import { + IDataSourceRuntimeContext, + InterpretDataSource, + IRuntimeDataSource, + RequestHandlersMap, + RuntimeDataSource, + RuntimeDataSourceConfig, +} from '@ali/lowcode-types'; // TODO: requestConfig mtop 默认的请求 config 怎么处理? /** @@ -18,13 +17,11 @@ import { reloadDataSourceFactory } from '../core/reloadDataSourceFactory'; */ export default ( - dataSource: DataSource, - context: IRuntimeContext, + dataSource: InterpretDataSource, + context: IDataSourceRuntimeContext, extraConfig: { requestHandlersMap: RequestHandlersMap<{ data: unknown }>; - } = { - requestHandlersMap: {}, - }, + } = { requestHandlersMap: {} }, ) => { const { requestHandlersMap } = extraConfig; diff --git a/packages/datasource-engine/src/runtime/RuntimeDataSourceEngineFactory.ts b/packages/datasource-engine/src/runtime/RuntimeDataSourceEngineFactory.ts index 2a98f1a14..d504054c3 100644 --- a/packages/datasource-engine/src/runtime/RuntimeDataSourceEngineFactory.ts +++ b/packages/datasource-engine/src/runtime/RuntimeDataSourceEngineFactory.ts @@ -1,11 +1,12 @@ +/* eslint-disable @typescript-eslint/indent */ /* eslint-disable no-nested-ternary */ import { - IRuntimeContext, IRuntimeDataSource, + IDataSourceRuntimeContext, + RequestHandlersMap, RuntimeDataSourceConfig, RuntimeDataSource, - RequestHandlersMap, -} from '@ali/build-success-types'; +} from '@ali/lowcode-types'; import { RuntimeDataSourceItem } from '../core'; import { reloadDataSourceFactory } from '../core/reloadDataSourceFactory'; @@ -22,24 +23,22 @@ import { */ export default ( dataSource: RuntimeDataSource, - context: IRuntimeContext, + context: IDataSourceRuntimeContext, extraConfig: { requestHandlersMap: RequestHandlersMap<{ data: unknown }>; - } = { - requestHandlersMap: {}, - }, + } = { requestHandlersMap: {} }, ) => { const { requestHandlersMap } = extraConfig; // TODO: 对于出码类型,需要做一层数据兼容,给一些必要的值设置默认值,先兜底几个必要的 - dataSource.list.forEach((ds) => { + dataSource.list.forEach(ds => { ds.isInit = ds.isInit || true; ds.isSync = ds.isSync || false; ds.shouldFetch = !ds.shouldFetch ? defaultShouldFetch : typeof ds.shouldFetch === 'function' - ? ds.shouldFetch.bind(context) - : ds.shouldFetch; + ? ds.shouldFetch.bind(context) + : ds.shouldFetch; ds.willFetch = ds.willFetch ? ds.willFetch.bind(context) : defaultWillFetch; ds.dataHandler = ds.dataHandler ? ds.dataHandler.bind(context) diff --git a/packages/datasource-engine/src/utils.ts b/packages/datasource-engine/src/utils.ts index f39171e96..b31076f28 100644 --- a/packages/datasource-engine/src/utils.ts +++ b/packages/datasource-engine/src/utils.ts @@ -1,16 +1,20 @@ /* eslint-disable no-new-func */ + import { - JSExpression, - IRuntimeContext, CompositeValue, + IDataSourceRuntimeContext, + InterpretDataSourceConfig, + isJSExpression, + isJSFunction, + JSExpression, JSFunction, JSONObject, - isJSExpression, - DataSourceConfig, - isJSFunction, -} from '@ali/build-success-types'; +} from '@ali/lowcode-types'; -export const transformExpression = (code: string, context: IRuntimeContext) => { +export const transformExpression = ( + code: string, + context: IDataSourceRuntimeContext, +) => { try { return new Function(`return (${code})`).call(context); } catch (error) { @@ -20,7 +24,10 @@ export const transformExpression = (code: string, context: IRuntimeContext) => { } }; -export const transformFunction = (code: string, context: IRuntimeContext) => { +export const transformFunction = ( + code: string, + context: IDataSourceRuntimeContext, +) => { try { return new Function(`return (${code})`).call(context).bind(context); } catch (error) { @@ -36,12 +43,13 @@ export const transformBoolStr = (str: string) => { export const getRuntimeJsValue = ( value: JSExpression | JSFunction, - context: IRuntimeContext, + context: IDataSourceRuntimeContext, ) => { if (!['JSExpression', 'JSFunction'].includes(value.type)) { console.error(`translate error, value is ${JSON.stringify(value)}`); return ''; } + // TODO: 类型修复 const code = value.compiled || value.value; return value.type === 'JSFunction' ? transformFunction(code, context) @@ -66,7 +74,7 @@ export const getRuntimeBaseValue = (type: string, value: any) => { export const getRuntimeValueFromConfig = ( type: string, value: CompositeValue, - context: IRuntimeContext, + context: IDataSourceRuntimeContext, ) => { if (!value) return undefined; if (isJSExpression(value) || isJSFunction(value)) { @@ -77,7 +85,7 @@ export const getRuntimeValueFromConfig = ( export const buildJsonObj = ( params: JSONObject | JSExpression, - context: IRuntimeContext, + context: IDataSourceRuntimeContext, ) => { const result: Record = {}; if (isJSExpression(params)) { @@ -96,8 +104,8 @@ export const buildJsonObj = ( }; export const buildShouldFetch = ( - ds: DataSourceConfig, - context: IRuntimeContext, + ds: InterpretDataSourceConfig, + context: IDataSourceRuntimeContext, ) => { if (!ds.options || !ds.shouldFetch) { return true; // 默认为 true @@ -110,12 +118,12 @@ export const buildShouldFetch = ( }; export const buildOptions = ( - ds: DataSourceConfig, - context: IRuntimeContext, + ds: InterpretDataSourceConfig, + context: IDataSourceRuntimeContext, ) => { const { options } = ds; if (!options) return undefined; - return function () { + return function() { return { uri: getRuntimeValueFromConfig('string', options.uri, context), params: options.params ? buildJsonObj(options.params, context) : {}, diff --git a/packages/datasource-engine/test/_helpers/mock-context.ts b/packages/datasource-engine/test/_helpers/mock-context.ts index f602489de..7b62f29b7 100644 --- a/packages/datasource-engine/test/_helpers/mock-context.ts +++ b/packages/datasource-engine/test/_helpers/mock-context.ts @@ -1,13 +1,16 @@ -import { IDataSourceEngine, IRuntimeContext } from '@ali/build-success-types'; +import { + IDataSourceRuntimeContext, + IDataSourceEngine +} from '@ali/lowcode-types'; -export class MockContext> - implements IRuntimeContext { +export class MockContext = Record> + implements IDataSourceRuntimeContext { private _dataSourceEngine: IDataSourceEngine; public constructor( private _state: TState, private _createDataSourceEngine: ( - context: IRuntimeContext + context: IDataSourceRuntimeContext ) => IDataSourceEngine, private _customMethods: Record any> = {} ) { diff --git a/packages/datasource-engine/test/scenes/p0-0-simplest-defaults/_datasource-runtime.ts b/packages/datasource-engine/test/scenes/p0-0-simplest-defaults/_datasource-runtime.ts index ccb41e1f0..58002ead2 100644 --- a/packages/datasource-engine/test/scenes/p0-0-simplest-defaults/_datasource-runtime.ts +++ b/packages/datasource-engine/test/scenes/p0-0-simplest-defaults/_datasource-runtime.ts @@ -1,4 +1,4 @@ -import { RuntimeDataSource } from '@ali/build-success-types'; +import { RuntimeDataSource } from '@ali/lowcode-types'; // 这里仅仅是数据源部分的: // @see: https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5 diff --git a/packages/datasource-engine/test/scenes/p0-0-simplest-defaults/_datasource-schema.ts b/packages/datasource-engine/test/scenes/p0-0-simplest-defaults/_datasource-schema.ts index 7218c7864..848a85687 100644 --- a/packages/datasource-engine/test/scenes/p0-0-simplest-defaults/_datasource-schema.ts +++ b/packages/datasource-engine/test/scenes/p0-0-simplest-defaults/_datasource-schema.ts @@ -1,8 +1,8 @@ -import { DataSource } from '@ali/build-success-types'; +import { InterpretDataSource } from '@ali/lowcode-types'; // 这里仅仅是数据源部分的 schema: // @see: https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5 -export const DATA_SOURCE_SCHEMA: DataSource = { +export const DATA_SOURCE_SCHEMA: InterpretDataSource = { list: [ { id: 'user', diff --git a/packages/datasource-engine/test/scenes/p0-0-simplest-defaults/_macro-abnormal.ts b/packages/datasource-engine/test/scenes/p0-0-simplest-defaults/_macro-abnormal.ts index 4a2297aa0..78c0f5cb2 100644 --- a/packages/datasource-engine/test/scenes/p0-0-simplest-defaults/_macro-abnormal.ts +++ b/packages/datasource-engine/test/scenes/p0-0-simplest-defaults/_macro-abnormal.ts @@ -1,10 +1,10 @@ import { - DataSource, + InterpretDataSource, IDataSourceEngine, - IRuntimeContext, + IDataSourceRuntimeContext, RuntimeDataSource, RuntimeDataSourceStatus, -} from '@ali/build-success-types'; +} from '@ali/lowcode-types'; import sinon from 'sinon'; import { delay, MockContext } from '../../_helpers'; @@ -17,56 +17,56 @@ export const abnormalScene: Macro<[ { create: ( dataSource: any, - ctx: IRuntimeContext, + ctx: IDataSourceRuntimeContext, options: any ) => IDataSourceEngine; - dataSource: RuntimeDataSource | DataSource; + dataSource: RuntimeDataSource | InterpretDataSource; } ]> = async ( t: ExecutionContext<{ clock: SinonFakeTimers }>, { create, dataSource }, -) => { - const { clock } = t.context; - const ERROR_MSG = 'test error'; - const fetchHandler = sinon.fake(async () => { - await delay(100); - throw new Error(ERROR_MSG); - }); + ) => { + const { clock } = t.context; + const ERROR_MSG = 'test error'; + const fetchHandler = sinon.fake(async () => { + await delay(100); + throw new Error(ERROR_MSG); + }); - const context = new MockContext>({}, (ctx) => create(dataSource, ctx, { - requestHandlersMap: { - fetch: fetchHandler, - }, - })); + const context = new MockContext>({}, (ctx) => create(dataSource, ctx, { + requestHandlersMap: { + fetch: fetchHandler, + }, + })); - const setState = sinon.spy(context, 'setState'); + const setState = sinon.spy(context, 'setState'); - // 一开始应该是初始状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); + // 一开始应该是初始状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); - const loading = context.reloadDataSource(); + const loading = context.reloadDataSource(); - await clock.tickAsync(50); + await clock.tickAsync(50); - // 中间应该有 loading 态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); + // 中间应该有 loading 态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); - await Promise.all([clock.runAllAsync(), loading]); + await Promise.all([clock.runAllAsync(), loading]); - // 最后应该失败了,error 状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Error); + // 最后应该失败了,error 状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Error); - // 检查数据源的数据 - t.deepEqual(context.dataSourceMap.user.data, undefined); - t.not(context.dataSourceMap.user.error, undefined); - t.regex(context.dataSourceMap.user.error!.message, new RegExp(ERROR_MSG)); + // 检查数据源的数据 + t.deepEqual(context.dataSourceMap.user.data, undefined); + t.not(context.dataSourceMap.user.error, undefined); + t.regex(context.dataSourceMap.user.error!.message, new RegExp(ERROR_MSG)); - // 检查状态数据 - t.assert(setState.notCalled); - t.deepEqual(context.state.user, undefined); + // 检查状态数据 + t.assert(setState.notCalled); + t.deepEqual(context.state.user, undefined); - // fetchHandler 不应该被调 - t.assert(fetchHandler.calledOnce); -}; + // fetchHandler 不应该被调 + t.assert(fetchHandler.calledOnce); + }; abnormalScene.title = (providedTitle) => providedTitle || 'abnormal scene'; diff --git a/packages/datasource-engine/test/scenes/p0-0-simplest-defaults/_macro-normal.ts b/packages/datasource-engine/test/scenes/p0-0-simplest-defaults/_macro-normal.ts index 7115ab1eb..9d2a7e353 100644 --- a/packages/datasource-engine/test/scenes/p0-0-simplest-defaults/_macro-normal.ts +++ b/packages/datasource-engine/test/scenes/p0-0-simplest-defaults/_macro-normal.ts @@ -1,10 +1,10 @@ import { - DataSource, + InterpretDataSource, IDataSourceEngine, - IRuntimeContext, + IDataSourceRuntimeContext, RuntimeDataSource, RuntimeDataSourceStatus, -} from '@ali/build-success-types'; +} from '@ali/lowcode-types'; import sinon from 'sinon'; import { delay, MockContext } from '../../_helpers'; @@ -17,65 +17,65 @@ export const normalScene: Macro<[ { create: ( dataSource: any, - ctx: IRuntimeContext, + ctx: IDataSourceRuntimeContext, options: any ) => IDataSourceEngine; - dataSource: RuntimeDataSource | DataSource; + dataSource: RuntimeDataSource | InterpretDataSource; } ]> = async ( t: ExecutionContext<{ clock: SinonFakeTimers }>, { create, dataSource }, -) => { - const { clock } = t.context; + ) => { + const { clock } = t.context; - const USER_DATA = { - name: 'Alice', - age: 18, + const USER_DATA = { + name: 'Alice', + age: 18, + }; + + const fetchHandler = sinon.fake(async () => { + await delay(100); + return { data: USER_DATA }; + }); + + const context = new MockContext>({}, (ctx) => create(dataSource, ctx, { + requestHandlersMap: { + fetch: fetchHandler, + }, + })); + + const setState = sinon.spy(context, 'setState'); + + // 一开始应该是初始状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); + + const loading = context.reloadDataSource(); + + await clock.tickAsync(50); + + // 中间应该有 loading 态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); + + await Promise.all([clock.runAllAsync(), loading]); + + // 最后应该成功了,loaded 状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loaded); + + // 检查数据源的数据 + t.deepEqual(context.dataSourceMap.user.data, USER_DATA); + t.deepEqual(context.dataSourceMap.user.error, undefined); + + // 检查状态数据 + t.assert(setState.calledOnce); + t.deepEqual(context.state.user, USER_DATA); + + // fetchHandler 应该被调用了一次 + t.assert(fetchHandler.calledOnce); + + const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; + const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; + // 检查调用参数 + t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); }; - const fetchHandler = sinon.fake(async () => { - await delay(100); - return { data: USER_DATA }; - }); - - const context = new MockContext>({}, (ctx) => create(dataSource, ctx, { - requestHandlersMap: { - fetch: fetchHandler, - }, - })); - - const setState = sinon.spy(context, 'setState'); - - // 一开始应该是初始状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); - - const loading = context.reloadDataSource(); - - await clock.tickAsync(50); - - // 中间应该有 loading 态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); - - await Promise.all([clock.runAllAsync(), loading]); - - // 最后应该成功了,loaded 状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loaded); - - // 检查数据源的数据 - t.deepEqual(context.dataSourceMap.user.data, USER_DATA); - t.deepEqual(context.dataSourceMap.user.error, undefined); - - // 检查状态数据 - t.assert(setState.calledOnce); - t.deepEqual(context.state.user, USER_DATA); - - // fetchHandler 应该被调用了一次 - t.assert(fetchHandler.calledOnce); - - const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; - const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; - // 检查调用参数 - t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); -}; - normalScene.title = (providedTitle) => providedTitle || 'normal scene'; diff --git a/packages/datasource-engine/test/scenes/p0-0-sync-datasources-dealt-in-serial/_datasource-runtime.ts b/packages/datasource-engine/test/scenes/p0-0-sync-datasources-dealt-in-serial/_datasource-runtime.ts index 09e244a38..c5fe1194c 100644 --- a/packages/datasource-engine/test/scenes/p0-0-sync-datasources-dealt-in-serial/_datasource-runtime.ts +++ b/packages/datasource-engine/test/scenes/p0-0-sync-datasources-dealt-in-serial/_datasource-runtime.ts @@ -1,4 +1,4 @@ -import { RuntimeDataSource } from '@ali/build-success-types'; +import { RuntimeDataSource } from '@ali/lowcode-types'; // 这里仅仅是数据源部分的: // @see: https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5 diff --git a/packages/datasource-engine/test/scenes/p0-0-sync-datasources-dealt-in-serial/_datasource-schema.ts b/packages/datasource-engine/test/scenes/p0-0-sync-datasources-dealt-in-serial/_datasource-schema.ts index e4e549ece..2c75c180a 100644 --- a/packages/datasource-engine/test/scenes/p0-0-sync-datasources-dealt-in-serial/_datasource-schema.ts +++ b/packages/datasource-engine/test/scenes/p0-0-sync-datasources-dealt-in-serial/_datasource-schema.ts @@ -1,8 +1,8 @@ -import { DataSource } from '@ali/build-success-types'; +import { InterpretDataSource } from '@ali/lowcode-types'; // 这里仅仅是数据源部分的 schema: // @see: https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5 -export const DATA_SOURCE_SCHEMA: DataSource = { +export const DATA_SOURCE_SCHEMA: InterpretDataSource = { list: [ { id: 'user', diff --git a/packages/datasource-engine/test/scenes/p0-0-sync-datasources-dealt-in-serial/_macro-abnormal.ts b/packages/datasource-engine/test/scenes/p0-0-sync-datasources-dealt-in-serial/_macro-abnormal.ts index fc0aaa0b3..f81db6b49 100644 --- a/packages/datasource-engine/test/scenes/p0-0-sync-datasources-dealt-in-serial/_macro-abnormal.ts +++ b/packages/datasource-engine/test/scenes/p0-0-sync-datasources-dealt-in-serial/_macro-abnormal.ts @@ -1,10 +1,10 @@ import { - DataSource, + InterpretDataSource, IDataSourceEngine, - IRuntimeContext, + IDataSourceRuntimeContext, RuntimeDataSource, RuntimeDataSourceStatus, -} from '@ali/build-success-types'; +} from '@ali/lowcode-types'; import sinon from 'sinon'; import { bindRuntimeContext, delay, MockContext } from '../../_helpers'; @@ -17,80 +17,80 @@ export const abnormalScene: Macro<[ { create: ( dataSource: any, - ctx: IRuntimeContext, + ctx: IDataSourceRuntimeContext, options: any ) => IDataSourceEngine; - dataSource: RuntimeDataSource | DataSource; + dataSource: RuntimeDataSource | InterpretDataSource; } ]> = async ( t: ExecutionContext<{ clock: SinonFakeTimers }>, { create, dataSource }, -) => { - const { clock } = t.context; + ) => { + const { clock } = t.context; - const USER_DATA = { - id: 9527, - name: 'Alice', + const USER_DATA = { + id: 9527, + name: 'Alice', + }; + const ERROR_MSG = 'test error'; + const fetchHandler = sinon.fake(async ({ uri }) => { + await delay(100); + if (/user/.test(uri)) { + return { data: USER_DATA }; + } else { + throw new Error(ERROR_MSG); + } + }); + + const context = new MockContext>({}, (ctx) => create(bindRuntimeContext(dataSource, ctx), ctx, { + requestHandlersMap: { + fetch: fetchHandler, + }, + })); + + const setState = sinon.spy(context, 'setState'); + + // 一开始应该是初始状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); + t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Initial); + + const loading = context.reloadDataSource(); + + await clock.tickAsync(50); + + // 中间应该有 loading 态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); + + await clock.tickAsync(50); + + t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Loading); + + await Promise.all([clock.runAllAsync(), loading]); + + // 最后 user 应该成功了,loaded + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loaded); + // 最后 orders 应该失败了,error 状态 + t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Error); + + // 检查数据源的数据 + t.deepEqual(context.dataSourceMap.user.data, USER_DATA); + t.is(context.dataSourceMap.user.error, undefined); + t.deepEqual(context.dataSourceMap.orders.data, undefined); + t.not(context.dataSourceMap.orders.error, undefined); + t.regex(context.dataSourceMap.orders.error!.message, new RegExp(ERROR_MSG)); + + // 检查状态数据 + t.assert(setState.calledOnce); + t.deepEqual(context.state.user, USER_DATA); + t.is(context.state.orders, undefined); + + // fetchHandler 应该被调用了2次 + t.assert(fetchHandler.calledTwice); + + const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; + const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; + // 检查调用参数 + t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); }; - const ERROR_MSG = 'test error'; - const fetchHandler = sinon.fake(async ({ uri }) => { - await delay(100); - if (/user/.test(uri)) { - return { data: USER_DATA }; - } else { - throw new Error(ERROR_MSG); - } - }); - - const context = new MockContext>({}, (ctx) => create(bindRuntimeContext(dataSource, ctx), ctx, { - requestHandlersMap: { - fetch: fetchHandler, - }, - })); - - const setState = sinon.spy(context, 'setState'); - - // 一开始应该是初始状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); - t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Initial); - - const loading = context.reloadDataSource(); - - await clock.tickAsync(50); - - // 中间应该有 loading 态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); - - await clock.tickAsync(50); - - t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Loading); - - await Promise.all([clock.runAllAsync(), loading]); - - // 最后 user 应该成功了,loaded - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loaded); - // 最后 orders 应该失败了,error 状态 - t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Error); - - // 检查数据源的数据 - t.deepEqual(context.dataSourceMap.user.data, USER_DATA); - t.is(context.dataSourceMap.user.error, undefined); - t.deepEqual(context.dataSourceMap.orders.data, undefined); - t.not(context.dataSourceMap.orders.error, undefined); - t.regex(context.dataSourceMap.orders.error!.message, new RegExp(ERROR_MSG)); - - // 检查状态数据 - t.assert(setState.calledOnce); - t.deepEqual(context.state.user, USER_DATA); - t.is(context.state.orders, undefined); - - // fetchHandler 应该被调用了2次 - t.assert(fetchHandler.calledTwice); - - const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; - const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; - // 检查调用参数 - t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); -}; abnormalScene.title = (providedTitle) => providedTitle || 'abnormal scene'; diff --git a/packages/datasource-engine/test/scenes/p0-0-sync-datasources-dealt-in-serial/_macro-normal.ts b/packages/datasource-engine/test/scenes/p0-0-sync-datasources-dealt-in-serial/_macro-normal.ts index 2587c08b3..c6a95c672 100644 --- a/packages/datasource-engine/test/scenes/p0-0-sync-datasources-dealt-in-serial/_macro-normal.ts +++ b/packages/datasource-engine/test/scenes/p0-0-sync-datasources-dealt-in-serial/_macro-normal.ts @@ -1,10 +1,10 @@ import { - DataSource, + InterpretDataSource, IDataSourceEngine, - IRuntimeContext, + IDataSourceRuntimeContext, RuntimeDataSource, RuntimeDataSourceStatus, -} from '@ali/build-success-types'; +} from '@ali/lowcode-types'; import sinon from 'sinon'; import { bindRuntimeContext, delay, MockContext } from '../../_helpers'; @@ -17,76 +17,76 @@ export const normalScene: Macro<[ { create: ( dataSource: any, - ctx: IRuntimeContext, + ctx: IDataSourceRuntimeContext, options: any ) => IDataSourceEngine; - dataSource: RuntimeDataSource | DataSource; + dataSource: RuntimeDataSource | InterpretDataSource; } ]> = async ( t: ExecutionContext<{ clock: SinonFakeTimers }>, { create, dataSource }, -) => { - const { clock } = t.context; + ) => { + const { clock } = t.context; - const USER_DATA = { - id: 9527, - name: 'Alice', + const USER_DATA = { + id: 9527, + name: 'Alice', + }; + + const ORDERS_DATA = [{ id: 123 }, { id: 456 }]; + + const fetchHandler = sinon.fake(async ({ uri }) => { + await delay(100); + return { data: /user/.test(uri) ? USER_DATA : ORDERS_DATA }; + }); + + const context = new MockContext>({}, (ctx) => create(bindRuntimeContext(dataSource, ctx), ctx, { + requestHandlersMap: { + fetch: fetchHandler, + }, + })); + + const setState = sinon.spy(context, 'setState'); + + // 一开始应该是初始状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); + t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Initial); + + const loading = context.reloadDataSource(); + + await clock.tickAsync(50); + + // 中间应该有 loading 态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); + + await clock.tickAsync(50); + + t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Loading); + + await Promise.all([clock.runAllAsync(), loading]); + + // 最后应该成功了,loaded 状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loaded); + t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Loaded); + + // 检查数据源的数据 + t.deepEqual(context.dataSourceMap.user.data, USER_DATA); + t.deepEqual(context.dataSourceMap.user.error, undefined); + t.deepEqual(context.dataSourceMap.orders.data, ORDERS_DATA); + t.deepEqual(context.dataSourceMap.orders.error, undefined); + + // 检查状态数据 + t.assert(setState.calledTwice); + t.deepEqual(context.state.user, USER_DATA); + t.deepEqual(context.state.orders, ORDERS_DATA); + + // fetchHandler 应该被调用了2次 + t.assert(fetchHandler.calledTwice); + + // 检查调用参数 + const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; + const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; + t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); }; - const ORDERS_DATA = [{ id: 123 }, { id: 456 }]; - - const fetchHandler = sinon.fake(async ({ uri }) => { - await delay(100); - return { data: /user/.test(uri) ? USER_DATA : ORDERS_DATA }; - }); - - const context = new MockContext>({}, (ctx) => create(bindRuntimeContext(dataSource, ctx), ctx, { - requestHandlersMap: { - fetch: fetchHandler, - }, - })); - - const setState = sinon.spy(context, 'setState'); - - // 一开始应该是初始状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); - t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Initial); - - const loading = context.reloadDataSource(); - - await clock.tickAsync(50); - - // 中间应该有 loading 态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); - - await clock.tickAsync(50); - - t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Loading); - - await Promise.all([clock.runAllAsync(), loading]); - - // 最后应该成功了,loaded 状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loaded); - t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Loaded); - - // 检查数据源的数据 - t.deepEqual(context.dataSourceMap.user.data, USER_DATA); - t.deepEqual(context.dataSourceMap.user.error, undefined); - t.deepEqual(context.dataSourceMap.orders.data, ORDERS_DATA); - t.deepEqual(context.dataSourceMap.orders.error, undefined); - - // 检查状态数据 - t.assert(setState.calledTwice); - t.deepEqual(context.state.user, USER_DATA); - t.deepEqual(context.state.orders, ORDERS_DATA); - - // fetchHandler 应该被调用了2次 - t.assert(fetchHandler.calledTwice); - - // 检查调用参数 - const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; - const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; - t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); -}; - normalScene.title = (providedTitle) => providedTitle || 'normal scene'; diff --git a/packages/datasource-engine/test/scenes/p0-0-url-params/_datasource-runtime.ts b/packages/datasource-engine/test/scenes/p0-0-url-params/_datasource-runtime.ts index 2f58b64e0..09b060b49 100644 --- a/packages/datasource-engine/test/scenes/p0-0-url-params/_datasource-runtime.ts +++ b/packages/datasource-engine/test/scenes/p0-0-url-params/_datasource-runtime.ts @@ -1,4 +1,4 @@ -import { RuntimeDataSource } from '@ali/build-success-types'; +import { RuntimeDataSource } from '@ali/lowcode-types'; // 这里仅仅是数据源部分的: // @see: https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5 diff --git a/packages/datasource-engine/test/scenes/p0-0-url-params/_datasource-schema.ts b/packages/datasource-engine/test/scenes/p0-0-url-params/_datasource-schema.ts index 9b00b9300..20fcb2154 100644 --- a/packages/datasource-engine/test/scenes/p0-0-url-params/_datasource-schema.ts +++ b/packages/datasource-engine/test/scenes/p0-0-url-params/_datasource-schema.ts @@ -1,8 +1,8 @@ -import { DataSource } from '@ali/build-success-types'; +import { InterpretDataSource } from '@ali/lowcode-types'; // 这里仅仅是数据源部分的 schema: // @see: https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5 -export const DATA_SOURCE_SCHEMA: DataSource = { +export const DATA_SOURCE_SCHEMA: InterpretDataSource = { list: [ { id: 'urlParams', diff --git a/packages/datasource-engine/test/scenes/p0-0-url-params/_macro-normal.ts b/packages/datasource-engine/test/scenes/p0-0-url-params/_macro-normal.ts index 4b0b9bc06..0156af315 100644 --- a/packages/datasource-engine/test/scenes/p0-0-url-params/_macro-normal.ts +++ b/packages/datasource-engine/test/scenes/p0-0-url-params/_macro-normal.ts @@ -1,10 +1,10 @@ import { - DataSource, + InterpretDataSource, IDataSourceEngine, - IRuntimeContext, + IDataSourceRuntimeContext, RuntimeDataSource, RuntimeDataSourceStatus, -} from '@ali/build-success-types'; +} from '@ali/lowcode-types'; import sinon from 'sinon'; import { MockContext } from '../../_helpers'; @@ -16,57 +16,57 @@ export const normalScene: Macro<[ { create: ( dataSource: any, - ctx: IRuntimeContext, + ctx: IDataSourceRuntimeContext, options: any ) => IDataSourceEngine; - dataSource: RuntimeDataSource | DataSource; + dataSource: RuntimeDataSource | InterpretDataSource; } ]> = async ( t: ExecutionContext<{ clock: SinonFakeTimers }>, { create, dataSource }, -) => { - const { clock } = t.context; + ) => { + const { clock } = t.context; - const URL_PARAMS = { - name: 'Alice', - age: '18', + const URL_PARAMS = { + name: 'Alice', + age: '18', + }; + + const urlParamsHandler = sinon.fake(async () => { + return URL_PARAMS; // TODO: 别的都是返回的套了一层 data 的,但是 urlParams 的为啥不一样? + }); + + const context = new MockContext>({}, (ctx) => create(dataSource, ctx, { + requestHandlersMap: { + urlParams: urlParamsHandler, + }, + })); + + const setState = sinon.spy(context, 'setState'); + + // 一开始应该是初始状态 + t.is(context.dataSourceMap.urlParams.status, RuntimeDataSourceStatus.Initial); + + const loading = context.reloadDataSource(); + + await Promise.all([clock.runAllAsync(), loading]); + + // 最后应该成功了,loaded 状态 + t.is(context.dataSourceMap.urlParams.status, RuntimeDataSourceStatus.Loaded); + + // 检查数据源的数据 + t.deepEqual(context.dataSourceMap.urlParams.data, URL_PARAMS); + t.deepEqual(context.dataSourceMap.urlParams.error, undefined); + + // 检查状态数据 + t.assert(setState.calledOnce); + t.deepEqual(context.state.urlParams, URL_PARAMS); + + // fetchHandler 应该被调用了一次 + t.assert(urlParamsHandler.calledOnce); + + // 检查调用参数 url 没有 options + t.deepEqual(urlParamsHandler.firstCall.args, [context]); }; - const urlParamsHandler = sinon.fake(async () => { - return URL_PARAMS; // TODO: 别的都是返回的套了一层 data 的,但是 urlParams 的为啥不一样? - }); - - const context = new MockContext>({}, (ctx) => create(dataSource, ctx, { - requestHandlersMap: { - urlParams: urlParamsHandler, - }, - })); - - const setState = sinon.spy(context, 'setState'); - - // 一开始应该是初始状态 - t.is(context.dataSourceMap.urlParams.status, RuntimeDataSourceStatus.Initial); - - const loading = context.reloadDataSource(); - - await Promise.all([clock.runAllAsync(), loading]); - - // 最后应该成功了,loaded 状态 - t.is(context.dataSourceMap.urlParams.status, RuntimeDataSourceStatus.Loaded); - - // 检查数据源的数据 - t.deepEqual(context.dataSourceMap.urlParams.data, URL_PARAMS); - t.deepEqual(context.dataSourceMap.urlParams.error, undefined); - - // 检查状态数据 - t.assert(setState.calledOnce); - t.deepEqual(context.state.urlParams, URL_PARAMS); - - // fetchHandler 应该被调用了一次 - t.assert(urlParamsHandler.calledOnce); - - // 检查调用参数 url 没有 options - t.deepEqual(urlParamsHandler.firstCall.args, [context]); -}; - normalScene.title = (providedTitle) => providedTitle || 'normal scene'; diff --git a/packages/datasource-engine/test/scenes/p0-1-custom-response-status/_datasource-runtime.ts b/packages/datasource-engine/test/scenes/p0-1-custom-response-status/_datasource-runtime.ts index 756adeb83..4b06ca7b8 100644 --- a/packages/datasource-engine/test/scenes/p0-1-custom-response-status/_datasource-runtime.ts +++ b/packages/datasource-engine/test/scenes/p0-1-custom-response-status/_datasource-runtime.ts @@ -1,4 +1,4 @@ -import { RuntimeDataSource } from '@ali/build-success-types'; +import { RuntimeDataSource } from '@ali/lowcode-types'; // 这里仅仅是数据源部分的: // @see: https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5 diff --git a/packages/datasource-engine/test/scenes/p0-1-custom-response-status/_datasource-schema.ts b/packages/datasource-engine/test/scenes/p0-1-custom-response-status/_datasource-schema.ts index 111cf641f..2352df683 100644 --- a/packages/datasource-engine/test/scenes/p0-1-custom-response-status/_datasource-schema.ts +++ b/packages/datasource-engine/test/scenes/p0-1-custom-response-status/_datasource-schema.ts @@ -1,8 +1,8 @@ -import { DataSource } from '@ali/build-success-types'; +import { InterpretDataSource } from '@ali/lowcode-types'; // 这里仅仅是数据源部分的 schema: // @see: https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5 -export const DATA_SOURCE_SCHEMA: DataSource = { +export const DATA_SOURCE_SCHEMA: InterpretDataSource = { list: [ { id: 'user', diff --git a/packages/datasource-engine/test/scenes/p0-1-custom-response-status/_macro-abnormal.ts b/packages/datasource-engine/test/scenes/p0-1-custom-response-status/_macro-abnormal.ts index 757aaba6e..a07619bd4 100644 --- a/packages/datasource-engine/test/scenes/p0-1-custom-response-status/_macro-abnormal.ts +++ b/packages/datasource-engine/test/scenes/p0-1-custom-response-status/_macro-abnormal.ts @@ -1,10 +1,10 @@ import { - DataSource, + InterpretDataSource, IDataSourceEngine, - IRuntimeContext, + IDataSourceRuntimeContext, RuntimeDataSource, RuntimeDataSourceStatus, -} from '@ali/build-success-types'; +} from '@ali/lowcode-types'; import sinon from 'sinon'; import { bindRuntimeContext, delay, MockContext } from '../../_helpers'; @@ -17,79 +17,79 @@ export const abnormalScene: Macro<[ { create: ( dataSource: any, - ctx: IRuntimeContext, + ctx: IDataSourceRuntimeContext, options: any ) => IDataSourceEngine; - dataSource: RuntimeDataSource | DataSource; + dataSource: RuntimeDataSource | InterpretDataSource; } ]> = async ( t: ExecutionContext<{ clock: SinonFakeTimers }>, { create, dataSource }, -) => { - const { clock } = t.context; - const ERROR_MSG = 'test error'; - const fetchHandler = sinon.fake(async () => { - await delay(100); - return { - data: { - success: false, - message: ERROR_MSG, - code: 'E_FOO', + ) => { + const { clock } = t.context; + const ERROR_MSG = 'test error'; + const fetchHandler = sinon.fake(async () => { + await delay(100); + return { + data: { + success: false, + message: ERROR_MSG, + code: 'E_FOO', + }, + }; + }); + + const context = new MockContext>( + {}, + (ctx) => create(bindRuntimeContext(dataSource, ctx), ctx, { + requestHandlersMap: { + fetch: fetchHandler, + }, + }), + { + recordError() { }, }, - }; - }); + ); - const context = new MockContext>( - {}, - (ctx) => create(bindRuntimeContext(dataSource, ctx), ctx, { - requestHandlersMap: { - fetch: fetchHandler, - }, - }), - { - recordError() {}, - }, - ); + const setState = sinon.spy(context, 'setState'); + const recordError = sinon.spy(context, 'recordError'); - const setState = sinon.spy(context, 'setState'); - const recordError = sinon.spy(context, 'recordError'); + // 一开始应该是初始状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); - // 一开始应该是初始状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); + const loading = context.reloadDataSource(); - const loading = context.reloadDataSource(); + await clock.tickAsync(50); - await clock.tickAsync(50); + // 中间应该有 loading 态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); - // 中间应该有 loading 态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); + await Promise.all([clock.runAllAsync(), loading]); - await Promise.all([clock.runAllAsync(), loading]); + // 最后应该失败了,error 状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Error); - // 最后应该失败了,error 状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Error); + // 检查数据源的数据 + t.deepEqual(context.dataSourceMap.user.data, undefined); + t.not(context.dataSourceMap.user.error, undefined); - // 检查数据源的数据 - t.deepEqual(context.dataSourceMap.user.data, undefined); - t.not(context.dataSourceMap.user.error, undefined); + t.regex(context.dataSourceMap.user.error!.message, new RegExp(ERROR_MSG)); - t.regex(context.dataSourceMap.user.error!.message, new RegExp(ERROR_MSG)); + // 检查状态数据 + t.assert(setState.notCalled); + t.deepEqual(context.state.user, undefined); - // 检查状态数据 - t.assert(setState.notCalled); - t.deepEqual(context.state.user, undefined); + // fetchHandler 应该被调用了一次 + t.assert(fetchHandler.calledOnce); - // fetchHandler 应该被调用了一次 - t.assert(fetchHandler.calledOnce); + // 检查调用参数 + const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; + const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; + t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); - // 检查调用参数 - const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; - const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; - t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); - - // 埋点应该也会被调用 - t.assert(recordError.calledOnce); - t.snapshot(recordError.firstCall.args); -}; + // 埋点应该也会被调用 + t.assert(recordError.calledOnce); + t.snapshot(recordError.firstCall.args); + }; abnormalScene.title = (providedTitle) => providedTitle || 'abnormal scene'; diff --git a/packages/datasource-engine/test/scenes/p0-1-custom-response-status/_macro-normal.ts b/packages/datasource-engine/test/scenes/p0-1-custom-response-status/_macro-normal.ts index d00fa39d9..8774ef200 100644 --- a/packages/datasource-engine/test/scenes/p0-1-custom-response-status/_macro-normal.ts +++ b/packages/datasource-engine/test/scenes/p0-1-custom-response-status/_macro-normal.ts @@ -1,10 +1,10 @@ import { - DataSource, + InterpretDataSource, IDataSourceEngine, - IRuntimeContext, + IDataSourceRuntimeContext, RuntimeDataSource, RuntimeDataSourceStatus, -} from '@ali/build-success-types'; +} from '@ali/lowcode-types'; import sinon from 'sinon'; import { bindRuntimeContext, delay, MockContext } from '../../_helpers'; @@ -17,80 +17,80 @@ export const normalScene: Macro<[ { create: ( dataSource: any, - ctx: IRuntimeContext, + ctx: IDataSourceRuntimeContext, options: any ) => IDataSourceEngine; - dataSource: RuntimeDataSource | DataSource; + dataSource: RuntimeDataSource | InterpretDataSource; } ]> = async ( t: ExecutionContext<{ clock: SinonFakeTimers }>, { create, dataSource }, -) => { - const { clock } = t.context; + ) => { + const { clock } = t.context; - const USER_DATA = { - name: 'Alice', - age: 18, + const USER_DATA = { + name: 'Alice', + age: 18, + }; + + const fetchHandler = sinon.fake(async () => { + await delay(100); + return { + data: { + success: true, + data: USER_DATA, + }, + }; + }); + + const context = new MockContext>( + {}, + (ctx) => create(bindRuntimeContext(dataSource, ctx), ctx, { + requestHandlersMap: { + fetch: fetchHandler, + }, + }), + { + recordError() { }, + }, + ); + + const setState = sinon.spy(context, 'setState'); + const recordError = sinon.spy(context, 'recordError'); + + // 一开始应该是初始状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); + + const loading = context.reloadDataSource(); + + await clock.tickAsync(50); + + // 中间应该有 loading 态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); + + await Promise.all([clock.runAllAsync(), loading]); + + // 最后应该成功了,loaded 状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loaded); + + // 检查数据源的数据 + t.deepEqual(context.dataSourceMap.user.data, USER_DATA); + t.deepEqual(context.dataSourceMap.user.error, undefined); + + // 检查状态数据 + t.assert(setState.calledOnce); + t.deepEqual(context.state.user, USER_DATA); + + // fetchHandler 应该被调用了一次 + t.assert(fetchHandler.calledOnce); + + // 检查调用参数 + const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; + const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; + t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); + + // 埋点不应该被调用 + t.assert(recordError.notCalled); }; - const fetchHandler = sinon.fake(async () => { - await delay(100); - return { - data: { - success: true, - data: USER_DATA, - }, - }; - }); - - const context = new MockContext>( - {}, - (ctx) => create(bindRuntimeContext(dataSource, ctx), ctx, { - requestHandlersMap: { - fetch: fetchHandler, - }, - }), - { - recordError() {}, - }, - ); - - const setState = sinon.spy(context, 'setState'); - const recordError = sinon.spy(context, 'recordError'); - - // 一开始应该是初始状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); - - const loading = context.reloadDataSource(); - - await clock.tickAsync(50); - - // 中间应该有 loading 态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); - - await Promise.all([clock.runAllAsync(), loading]); - - // 最后应该成功了,loaded 状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loaded); - - // 检查数据源的数据 - t.deepEqual(context.dataSourceMap.user.data, USER_DATA); - t.deepEqual(context.dataSourceMap.user.error, undefined); - - // 检查状态数据 - t.assert(setState.calledOnce); - t.deepEqual(context.state.user, USER_DATA); - - // fetchHandler 应该被调用了一次 - t.assert(fetchHandler.calledOnce); - - // 检查调用参数 - const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; - const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; - t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); - - // 埋点不应该被调用 - t.assert(recordError.notCalled); -}; - normalScene.title = (providedTitle) => providedTitle || 'normal scene'; diff --git a/packages/datasource-engine/test/scenes/p0-1-data-handler-can-eat-errors/_datasource-runtime.ts b/packages/datasource-engine/test/scenes/p0-1-data-handler-can-eat-errors/_datasource-runtime.ts index 2608841e1..d9ac8d6d0 100644 --- a/packages/datasource-engine/test/scenes/p0-1-data-handler-can-eat-errors/_datasource-runtime.ts +++ b/packages/datasource-engine/test/scenes/p0-1-data-handler-can-eat-errors/_datasource-runtime.ts @@ -1,4 +1,4 @@ -import { RuntimeDataSource } from '@ali/build-success-types'; +import { RuntimeDataSource } from '@ali/lowcode-types'; export const DEFAULT_USER_DATA = { id: 0, name: 'guest' }; // 返回一个兜底的数据 diff --git a/packages/datasource-engine/test/scenes/p0-1-data-handler-can-eat-errors/_datasource-schema.ts b/packages/datasource-engine/test/scenes/p0-1-data-handler-can-eat-errors/_datasource-schema.ts index b9b44cc6a..1b33622a9 100644 --- a/packages/datasource-engine/test/scenes/p0-1-data-handler-can-eat-errors/_datasource-schema.ts +++ b/packages/datasource-engine/test/scenes/p0-1-data-handler-can-eat-errors/_datasource-schema.ts @@ -1,8 +1,8 @@ -import { DataSource } from '@ali/build-success-types'; +import { InterpretDataSource } from '@ali/lowcode-types'; // 这里仅仅是数据源部分的 schema: // @see: https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5 -export const DATA_SOURCE_SCHEMA: DataSource = { +export const DATA_SOURCE_SCHEMA: InterpretDataSource = { list: [ { id: 'user', diff --git a/packages/datasource-engine/test/scenes/p0-1-data-handler-can-eat-errors/_macro-abnormal.ts b/packages/datasource-engine/test/scenes/p0-1-data-handler-can-eat-errors/_macro-abnormal.ts index 1c1e5d800..4b5a2237e 100644 --- a/packages/datasource-engine/test/scenes/p0-1-data-handler-can-eat-errors/_macro-abnormal.ts +++ b/packages/datasource-engine/test/scenes/p0-1-data-handler-can-eat-errors/_macro-abnormal.ts @@ -1,10 +1,10 @@ import { - DataSource, + InterpretDataSource, IDataSourceEngine, - IRuntimeContext, + IDataSourceRuntimeContext, RuntimeDataSource, RuntimeDataSourceStatus, -} from '@ali/build-success-types'; +} from '@ali/lowcode-types'; import sinon from 'sinon'; import { delay, MockContext } from '../../_helpers'; @@ -17,62 +17,62 @@ export const abnormalScene: Macro<[ { create: ( dataSource: any, - ctx: IRuntimeContext, + ctx: IDataSourceRuntimeContext, options: any ) => IDataSourceEngine; - dataSource: RuntimeDataSource | DataSource; + dataSource: RuntimeDataSource | InterpretDataSource; } ]> = async ( t: ExecutionContext<{ clock: SinonFakeTimers }>, { create, dataSource }, -) => { - const { clock } = t.context; - const ERROR_MSG = 'test error'; - const fetchHandler = sinon.fake(async () => { - await delay(100); - throw new Error(ERROR_MSG); - }); + ) => { + const { clock } = t.context; + const ERROR_MSG = 'test error'; + const fetchHandler = sinon.fake(async () => { + await delay(100); + throw new Error(ERROR_MSG); + }); - const context = new MockContext>({}, (ctx) => create(dataSource, ctx, { - requestHandlersMap: { - fetch: fetchHandler, - }, - })); + const context = new MockContext>({}, (ctx) => create(dataSource, ctx, { + requestHandlersMap: { + fetch: fetchHandler, + }, + })); - const setState = sinon.spy(context, 'setState'); + const setState = sinon.spy(context, 'setState'); - // 一开始应该是初始状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); + // 一开始应该是初始状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); - const loading = context.reloadDataSource(); + const loading = context.reloadDataSource(); - await clock.tickAsync(50); + await clock.tickAsync(50); - // 中间应该有 loading 态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); + // 中间应该有 loading 态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); - await Promise.all([clock.runAllAsync(), loading]); + await Promise.all([clock.runAllAsync(), loading]); - // 注意 error 是会被吃掉了,还是 loaded 状态 - // FIXME: 根据协议内容,dataHandler 返回的结果是需要抛出错误的,那么 fetchHandler 的错误难道不需要处理? - // TODO: 提案:request 如果挂了,不应该需要走 dataHandler 了,没有意义 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Error); + // 注意 error 是会被吃掉了,还是 loaded 状态 + // FIXME: 根据协议内容,dataHandler 返回的结果是需要抛出错误的,那么 fetchHandler 的错误难道不需要处理? + // TODO: 提案:request 如果挂了,不应该需要走 dataHandler 了,没有意义 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Error); - // 检查数据源的数据 - t.deepEqual(context.dataSourceMap.user.data, undefined); - t.not(context.dataSourceMap.user.error, undefined); - t.regex(context.dataSourceMap.user.error!.message, new RegExp(ERROR_MSG)); + // 检查数据源的数据 + t.deepEqual(context.dataSourceMap.user.data, undefined); + t.not(context.dataSourceMap.user.error, undefined); + t.regex(context.dataSourceMap.user.error!.message, new RegExp(ERROR_MSG)); - // 检查状态数据 - t.assert(setState.notCalled); + // 检查状态数据 + t.assert(setState.notCalled); - // fetchHandler 应该没调 - t.assert.skip(fetchHandler.notCalled); + // fetchHandler 应该没调 + t.assert.skip(fetchHandler.notCalled); - // 检查调用参数 - const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; - const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; - t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); -}; + // 检查调用参数 + const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; + const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; + t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); + }; abnormalScene.title = (providedTitle) => providedTitle || 'abnormal scene'; diff --git a/packages/datasource-engine/test/scenes/p0-1-data-handler-can-eat-errors/_macro-normal.ts b/packages/datasource-engine/test/scenes/p0-1-data-handler-can-eat-errors/_macro-normal.ts index 78aa87c61..c8484c434 100644 --- a/packages/datasource-engine/test/scenes/p0-1-data-handler-can-eat-errors/_macro-normal.ts +++ b/packages/datasource-engine/test/scenes/p0-1-data-handler-can-eat-errors/_macro-normal.ts @@ -1,10 +1,10 @@ import { - DataSource, + InterpretDataSource, IDataSourceEngine, - IRuntimeContext, + IDataSourceRuntimeContext, RuntimeDataSource, RuntimeDataSourceStatus, -} from '@ali/build-success-types'; +} from '@ali/lowcode-types'; import sinon from 'sinon'; import { delay, MockContext } from '../../_helpers'; @@ -17,65 +17,65 @@ export const normalScene: Macro<[ { create: ( dataSource: any, - ctx: IRuntimeContext, + ctx: IDataSourceRuntimeContext, options: any ) => IDataSourceEngine; - dataSource: RuntimeDataSource | DataSource; + dataSource: RuntimeDataSource | InterpretDataSource; } ]> = async ( t: ExecutionContext<{ clock: SinonFakeTimers }>, { create, dataSource }, -) => { - const { clock } = t.context; + ) => { + const { clock } = t.context; - const USER_DATA = { - name: 'Alice', - age: 18, + const USER_DATA = { + name: 'Alice', + age: 18, + }; + + const fetchHandler = sinon.fake(async () => { + await delay(100); + return { data: USER_DATA }; + }); + + const context = new MockContext>({}, (ctx) => create(dataSource, ctx, { + requestHandlersMap: { + fetch: fetchHandler, + }, + })); + + const setState = sinon.spy(context, 'setState'); + + // 一开始应该是初始状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); + + const loading = context.reloadDataSource(); + + await clock.tickAsync(50); + + // 中间应该有 loading 态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); + + await Promise.all([clock.runAllAsync(), loading]); + + // 最后应该成功了,loaded 状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loaded); + + // 检查数据源的数据 + t.deepEqual(context.dataSourceMap.user.data, USER_DATA); + t.deepEqual(context.dataSourceMap.user.error, undefined); + + // 检查状态数据 + t.assert(setState.calledOnce); + t.deepEqual(context.state.user, USER_DATA); + + // fetchHandler 应该被调用了一次 + t.assert(fetchHandler.calledOnce); + + // 检查调用参数 + const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; + const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; + t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); }; - const fetchHandler = sinon.fake(async () => { - await delay(100); - return { data: USER_DATA }; - }); - - const context = new MockContext>({}, (ctx) => create(dataSource, ctx, { - requestHandlersMap: { - fetch: fetchHandler, - }, - })); - - const setState = sinon.spy(context, 'setState'); - - // 一开始应该是初始状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); - - const loading = context.reloadDataSource(); - - await clock.tickAsync(50); - - // 中间应该有 loading 态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); - - await Promise.all([clock.runAllAsync(), loading]); - - // 最后应该成功了,loaded 状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loaded); - - // 检查数据源的数据 - t.deepEqual(context.dataSourceMap.user.data, USER_DATA); - t.deepEqual(context.dataSourceMap.user.error, undefined); - - // 检查状态数据 - t.assert(setState.calledOnce); - t.deepEqual(context.state.user, USER_DATA); - - // fetchHandler 应该被调用了一次 - t.assert(fetchHandler.calledOnce); - - // 检查调用参数 - const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; - const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; - t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); -}; - normalScene.title = (providedTitle) => providedTitle || 'normal scene'; diff --git a/packages/datasource-engine/test/scenes/p1-0-data-handler-returns-promise/_datasource-runtime.ts b/packages/datasource-engine/test/scenes/p1-0-data-handler-returns-promise/_datasource-runtime.ts index 5dc07956a..19d35f910 100644 --- a/packages/datasource-engine/test/scenes/p1-0-data-handler-returns-promise/_datasource-runtime.ts +++ b/packages/datasource-engine/test/scenes/p1-0-data-handler-returns-promise/_datasource-runtime.ts @@ -1,4 +1,4 @@ -import { RuntimeDataSource } from '@ali/build-success-types'; +import { RuntimeDataSource } from '@ali/lowcode-types'; // 这里仅仅是数据源部分的: // @see: https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5 diff --git a/packages/datasource-engine/test/scenes/p1-0-data-handler-returns-promise/_datasource-schema.ts b/packages/datasource-engine/test/scenes/p1-0-data-handler-returns-promise/_datasource-schema.ts index f35743828..f163ea6c2 100644 --- a/packages/datasource-engine/test/scenes/p1-0-data-handler-returns-promise/_datasource-schema.ts +++ b/packages/datasource-engine/test/scenes/p1-0-data-handler-returns-promise/_datasource-schema.ts @@ -1,8 +1,8 @@ -import { DataSource } from '@ali/build-success-types'; +import { InterpretDataSource } from '@ali/lowcode-types'; // 这里仅仅是数据源部分的 schema: // @see: https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5 -export const DATA_SOURCE_SCHEMA: DataSource = { +export const DATA_SOURCE_SCHEMA: InterpretDataSource = { list: [ { id: 'user', diff --git a/packages/datasource-engine/test/scenes/p1-0-data-handler-returns-promise/_macro-abnormal.ts b/packages/datasource-engine/test/scenes/p1-0-data-handler-returns-promise/_macro-abnormal.ts index 757aaba6e..a07619bd4 100644 --- a/packages/datasource-engine/test/scenes/p1-0-data-handler-returns-promise/_macro-abnormal.ts +++ b/packages/datasource-engine/test/scenes/p1-0-data-handler-returns-promise/_macro-abnormal.ts @@ -1,10 +1,10 @@ import { - DataSource, + InterpretDataSource, IDataSourceEngine, - IRuntimeContext, + IDataSourceRuntimeContext, RuntimeDataSource, RuntimeDataSourceStatus, -} from '@ali/build-success-types'; +} from '@ali/lowcode-types'; import sinon from 'sinon'; import { bindRuntimeContext, delay, MockContext } from '../../_helpers'; @@ -17,79 +17,79 @@ export const abnormalScene: Macro<[ { create: ( dataSource: any, - ctx: IRuntimeContext, + ctx: IDataSourceRuntimeContext, options: any ) => IDataSourceEngine; - dataSource: RuntimeDataSource | DataSource; + dataSource: RuntimeDataSource | InterpretDataSource; } ]> = async ( t: ExecutionContext<{ clock: SinonFakeTimers }>, { create, dataSource }, -) => { - const { clock } = t.context; - const ERROR_MSG = 'test error'; - const fetchHandler = sinon.fake(async () => { - await delay(100); - return { - data: { - success: false, - message: ERROR_MSG, - code: 'E_FOO', + ) => { + const { clock } = t.context; + const ERROR_MSG = 'test error'; + const fetchHandler = sinon.fake(async () => { + await delay(100); + return { + data: { + success: false, + message: ERROR_MSG, + code: 'E_FOO', + }, + }; + }); + + const context = new MockContext>( + {}, + (ctx) => create(bindRuntimeContext(dataSource, ctx), ctx, { + requestHandlersMap: { + fetch: fetchHandler, + }, + }), + { + recordError() { }, }, - }; - }); + ); - const context = new MockContext>( - {}, - (ctx) => create(bindRuntimeContext(dataSource, ctx), ctx, { - requestHandlersMap: { - fetch: fetchHandler, - }, - }), - { - recordError() {}, - }, - ); + const setState = sinon.spy(context, 'setState'); + const recordError = sinon.spy(context, 'recordError'); - const setState = sinon.spy(context, 'setState'); - const recordError = sinon.spy(context, 'recordError'); + // 一开始应该是初始状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); - // 一开始应该是初始状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); + const loading = context.reloadDataSource(); - const loading = context.reloadDataSource(); + await clock.tickAsync(50); - await clock.tickAsync(50); + // 中间应该有 loading 态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); - // 中间应该有 loading 态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); + await Promise.all([clock.runAllAsync(), loading]); - await Promise.all([clock.runAllAsync(), loading]); + // 最后应该失败了,error 状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Error); - // 最后应该失败了,error 状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Error); + // 检查数据源的数据 + t.deepEqual(context.dataSourceMap.user.data, undefined); + t.not(context.dataSourceMap.user.error, undefined); - // 检查数据源的数据 - t.deepEqual(context.dataSourceMap.user.data, undefined); - t.not(context.dataSourceMap.user.error, undefined); + t.regex(context.dataSourceMap.user.error!.message, new RegExp(ERROR_MSG)); - t.regex(context.dataSourceMap.user.error!.message, new RegExp(ERROR_MSG)); + // 检查状态数据 + t.assert(setState.notCalled); + t.deepEqual(context.state.user, undefined); - // 检查状态数据 - t.assert(setState.notCalled); - t.deepEqual(context.state.user, undefined); + // fetchHandler 应该被调用了一次 + t.assert(fetchHandler.calledOnce); - // fetchHandler 应该被调用了一次 - t.assert(fetchHandler.calledOnce); + // 检查调用参数 + const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; + const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; + t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); - // 检查调用参数 - const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; - const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; - t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); - - // 埋点应该也会被调用 - t.assert(recordError.calledOnce); - t.snapshot(recordError.firstCall.args); -}; + // 埋点应该也会被调用 + t.assert(recordError.calledOnce); + t.snapshot(recordError.firstCall.args); + }; abnormalScene.title = (providedTitle) => providedTitle || 'abnormal scene'; diff --git a/packages/datasource-engine/test/scenes/p1-0-data-handler-returns-promise/_macro-normal.ts b/packages/datasource-engine/test/scenes/p1-0-data-handler-returns-promise/_macro-normal.ts index d00fa39d9..8774ef200 100644 --- a/packages/datasource-engine/test/scenes/p1-0-data-handler-returns-promise/_macro-normal.ts +++ b/packages/datasource-engine/test/scenes/p1-0-data-handler-returns-promise/_macro-normal.ts @@ -1,10 +1,10 @@ import { - DataSource, + InterpretDataSource, IDataSourceEngine, - IRuntimeContext, + IDataSourceRuntimeContext, RuntimeDataSource, RuntimeDataSourceStatus, -} from '@ali/build-success-types'; +} from '@ali/lowcode-types'; import sinon from 'sinon'; import { bindRuntimeContext, delay, MockContext } from '../../_helpers'; @@ -17,80 +17,80 @@ export const normalScene: Macro<[ { create: ( dataSource: any, - ctx: IRuntimeContext, + ctx: IDataSourceRuntimeContext, options: any ) => IDataSourceEngine; - dataSource: RuntimeDataSource | DataSource; + dataSource: RuntimeDataSource | InterpretDataSource; } ]> = async ( t: ExecutionContext<{ clock: SinonFakeTimers }>, { create, dataSource }, -) => { - const { clock } = t.context; + ) => { + const { clock } = t.context; - const USER_DATA = { - name: 'Alice', - age: 18, + const USER_DATA = { + name: 'Alice', + age: 18, + }; + + const fetchHandler = sinon.fake(async () => { + await delay(100); + return { + data: { + success: true, + data: USER_DATA, + }, + }; + }); + + const context = new MockContext>( + {}, + (ctx) => create(bindRuntimeContext(dataSource, ctx), ctx, { + requestHandlersMap: { + fetch: fetchHandler, + }, + }), + { + recordError() { }, + }, + ); + + const setState = sinon.spy(context, 'setState'); + const recordError = sinon.spy(context, 'recordError'); + + // 一开始应该是初始状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); + + const loading = context.reloadDataSource(); + + await clock.tickAsync(50); + + // 中间应该有 loading 态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); + + await Promise.all([clock.runAllAsync(), loading]); + + // 最后应该成功了,loaded 状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loaded); + + // 检查数据源的数据 + t.deepEqual(context.dataSourceMap.user.data, USER_DATA); + t.deepEqual(context.dataSourceMap.user.error, undefined); + + // 检查状态数据 + t.assert(setState.calledOnce); + t.deepEqual(context.state.user, USER_DATA); + + // fetchHandler 应该被调用了一次 + t.assert(fetchHandler.calledOnce); + + // 检查调用参数 + const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; + const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; + t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); + + // 埋点不应该被调用 + t.assert(recordError.notCalled); }; - const fetchHandler = sinon.fake(async () => { - await delay(100); - return { - data: { - success: true, - data: USER_DATA, - }, - }; - }); - - const context = new MockContext>( - {}, - (ctx) => create(bindRuntimeContext(dataSource, ctx), ctx, { - requestHandlersMap: { - fetch: fetchHandler, - }, - }), - { - recordError() {}, - }, - ); - - const setState = sinon.spy(context, 'setState'); - const recordError = sinon.spy(context, 'recordError'); - - // 一开始应该是初始状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); - - const loading = context.reloadDataSource(); - - await clock.tickAsync(50); - - // 中间应该有 loading 态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); - - await Promise.all([clock.runAllAsync(), loading]); - - // 最后应该成功了,loaded 状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loaded); - - // 检查数据源的数据 - t.deepEqual(context.dataSourceMap.user.data, USER_DATA); - t.deepEqual(context.dataSourceMap.user.error, undefined); - - // 检查状态数据 - t.assert(setState.calledOnce); - t.deepEqual(context.state.user, USER_DATA); - - // fetchHandler 应该被调用了一次 - t.assert(fetchHandler.calledOnce); - - // 检查调用参数 - const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; - const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; - t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); - - // 埋点不应该被调用 - t.assert(recordError.notCalled); -}; - normalScene.title = (providedTitle) => providedTitle || 'normal scene'; diff --git a/packages/datasource-engine/test/scenes/p1-1-shouldfetch-control-request/_datasource-runtime.ts b/packages/datasource-engine/test/scenes/p1-1-shouldfetch-control-request/_datasource-runtime.ts index 2085535c6..49d30425e 100644 --- a/packages/datasource-engine/test/scenes/p1-1-shouldfetch-control-request/_datasource-runtime.ts +++ b/packages/datasource-engine/test/scenes/p1-1-shouldfetch-control-request/_datasource-runtime.ts @@ -1,4 +1,4 @@ -import { RuntimeDataSource } from '@ali/build-success-types'; +import { RuntimeDataSource } from '@ali/lowcode-types'; // 这里仅仅是数据源部分的: // @see: https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5 diff --git a/packages/datasource-engine/test/scenes/p1-1-shouldfetch-control-request/_datasource-schema.ts b/packages/datasource-engine/test/scenes/p1-1-shouldfetch-control-request/_datasource-schema.ts index e333f485a..4032c9a35 100644 --- a/packages/datasource-engine/test/scenes/p1-1-shouldfetch-control-request/_datasource-schema.ts +++ b/packages/datasource-engine/test/scenes/p1-1-shouldfetch-control-request/_datasource-schema.ts @@ -1,8 +1,8 @@ -import { DataSource } from '@ali/build-success-types'; +import { InterpretDataSource } from '@ali/lowcode-types'; // 这里仅仅是数据源部分的 schema: // @see: https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5 -export const DATA_SOURCE_SCHEMA: DataSource = { +export const DATA_SOURCE_SCHEMA: InterpretDataSource = { list: [ { id: 'user', diff --git a/packages/datasource-engine/test/scenes/p1-1-shouldfetch-control-request/_macro-normal.ts b/packages/datasource-engine/test/scenes/p1-1-shouldfetch-control-request/_macro-normal.ts index 4289a6d89..a12e0a48c 100644 --- a/packages/datasource-engine/test/scenes/p1-1-shouldfetch-control-request/_macro-normal.ts +++ b/packages/datasource-engine/test/scenes/p1-1-shouldfetch-control-request/_macro-normal.ts @@ -1,10 +1,10 @@ import { - DataSource, + InterpretDataSource, IDataSourceEngine, - IRuntimeContext, + IDataSourceRuntimeContext, RuntimeDataSource, RuntimeDataSourceStatus, -} from '@ali/build-success-types'; +} from '@ali/lowcode-types'; import sinon from 'sinon'; import { bindRuntimeContext, delay, MockContext } from '../../_helpers'; @@ -17,92 +17,92 @@ export const normalScene: Macro<[ { create: ( dataSource: any, - ctx: IRuntimeContext, + ctx: IDataSourceRuntimeContext, options: any ) => IDataSourceEngine; - dataSource: RuntimeDataSource | DataSource; + dataSource: RuntimeDataSource | InterpretDataSource; } ]> = async ( t: ExecutionContext<{ clock: SinonFakeTimers }>, { create, dataSource }, -) => { - const { clock } = t.context; - const ORDERS_ERROR_MSG = - 'the orders request should not fetch, please check the condition'; + ) => { + const { clock } = t.context; + const ORDERS_ERROR_MSG = + 'the orders request should not fetch, please check the condition'; - const USER_DATA = { - name: 'Alice', - age: 18, + const USER_DATA = { + name: 'Alice', + age: 18, + }; + + const fetchHandler = sinon.fake(async () => { + await delay(100); + return { + data: USER_DATA, + }; + }); + + const context = new MockContext>( + {}, + (ctx) => create(bindRuntimeContext(dataSource, ctx), ctx, { + requestHandlersMap: { + fetch: fetchHandler, + }, + }), + { + recordError() { }, + }, + ); + + const setState = sinon.spy(context, 'setState'); + // const recordError = sinon.spy(context, 'recordError'); + + // 一开始应该是初始状态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); + t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Initial); + + const loading = context.reloadDataSource(); + + await clock.tickAsync(50); + + // 中间应该有 loading 态 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); + + await clock.tickAsync(50); + + // 中间应该有 loading 态 + t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Error); + + await Promise.all([clock.runAllAsync(), loading]); + + // 最后 user 成功, orders 失败 + t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loaded); + t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Error); + + // 检查数据源的数据 + t.deepEqual(context.dataSourceMap.user.data, USER_DATA); + t.is(context.dataSourceMap.user.error, undefined); + t.regex( + context.dataSourceMap.orders.error!.message, + new RegExp(ORDERS_ERROR_MSG), + ); + + // 检查状态数据 + t.assert(setState.calledOnce); + t.deepEqual(context.state.user, USER_DATA); + + // fetchHandler 应该被调用了 1 次 + t.assert(fetchHandler.calledOnce); + + // 检查调用参数 + + const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; + const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; + t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); + + // // 埋点应该也会被调用 + // t.assert(recordError.calledOnce); + // t.snapshot(recordError.firstCall.args); }; - const fetchHandler = sinon.fake(async () => { - await delay(100); - return { - data: USER_DATA, - }; - }); - - const context = new MockContext>( - {}, - (ctx) => create(bindRuntimeContext(dataSource, ctx), ctx, { - requestHandlersMap: { - fetch: fetchHandler, - }, - }), - { - recordError() {}, - }, - ); - - const setState = sinon.spy(context, 'setState'); - // const recordError = sinon.spy(context, 'recordError'); - - // 一开始应该是初始状态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Initial); - t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Initial); - - const loading = context.reloadDataSource(); - - await clock.tickAsync(50); - - // 中间应该有 loading 态 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loading); - - await clock.tickAsync(50); - - // 中间应该有 loading 态 - t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Error); - - await Promise.all([clock.runAllAsync(), loading]); - - // 最后 user 成功, orders 失败 - t.is(context.dataSourceMap.user.status, RuntimeDataSourceStatus.Loaded); - t.is(context.dataSourceMap.orders.status, RuntimeDataSourceStatus.Error); - - // 检查数据源的数据 - t.deepEqual(context.dataSourceMap.user.data, USER_DATA); - t.is(context.dataSourceMap.user.error, undefined); - t.regex( - context.dataSourceMap.orders.error!.message, - new RegExp(ORDERS_ERROR_MSG), - ); - - // 检查状态数据 - t.assert(setState.calledOnce); - t.deepEqual(context.state.user, USER_DATA); - - // fetchHandler 应该被调用了 1 次 - t.assert(fetchHandler.calledOnce); - - // 检查调用参数 - - const firstListItemOptions = DATA_SOURCE_SCHEMA.list[0].options; - const fetchHandlerCallArgs = fetchHandler.firstCall.args[0]; - t.is(firstListItemOptions.uri, fetchHandlerCallArgs.uri); - - // // 埋点应该也会被调用 - // t.assert(recordError.calledOnce); - // t.snapshot(recordError.firstCall.args); -}; - normalScene.title = (providedTitle) => providedTitle || 'normal scene'; diff --git a/packages/datasource-fetch-handler/.eslintignore b/packages/datasource-fetch-handler/.eslintignore new file mode 100644 index 000000000..fecb7c26d --- /dev/null +++ b/packages/datasource-fetch-handler/.eslintignore @@ -0,0 +1,3 @@ +/node_modules +/es +/lib \ No newline at end of file diff --git a/packages/datasource-handlers/.eslintrc.js b/packages/datasource-fetch-handler/.eslintrc.js similarity index 78% rename from packages/datasource-handlers/.eslintrc.js rename to packages/datasource-fetch-handler/.eslintrc.js index e19c549ba..8c13fcaf4 100644 --- a/packages/datasource-handlers/.eslintrc.js +++ b/packages/datasource-fetch-handler/.eslintrc.js @@ -1,5 +1,5 @@ module.exports = { - extends: '../../.eslintrc.js', + extends: '../../.eslintrc', rules: { '@typescript-eslint/no-parameter-properties': 1, 'no-param-reassign': 0, diff --git a/packages/datasource-handlers/.prettierrc.js b/packages/datasource-fetch-handler/.prettierrc.js similarity index 61% rename from packages/datasource-handlers/.prettierrc.js rename to packages/datasource-fetch-handler/.prettierrc.js index d2db80ead..de2f53cdf 100644 --- a/packages/datasource-handlers/.prettierrc.js +++ b/packages/datasource-fetch-handler/.prettierrc.js @@ -1,4 +1,4 @@ module.exports = { singleQuote: true, - trailingComma: 'always', + trailingComma: 'all', }; diff --git a/packages/datasource-handlers/packages/fetch/package.json b/packages/datasource-fetch-handler/package.json similarity index 88% rename from packages/datasource-handlers/packages/fetch/package.json rename to packages/datasource-fetch-handler/package.json index ad28decb4..8dbc63a6f 100644 --- a/packages/datasource-handlers/packages/fetch/package.json +++ b/packages/datasource-fetch-handler/package.json @@ -16,12 +16,10 @@ "prepublishOnly": "npm run build" }, "dependencies": { + "@ali/lowcode-types": "^1.0.10", "typescript": "^3.9.7", "universal-request": "^2.2.0" }, - "devDependencies": { - "@ali/build-success-types": "^0.1.2-alpha.35" - }, "publishConfig": { "registry": "https://registry.npm.alibaba-inc.com" }, diff --git a/packages/datasource-handlers/packages/fetch/src/index.ts b/packages/datasource-fetch-handler/src/index.ts similarity index 90% rename from packages/datasource-handlers/packages/fetch/src/index.ts rename to packages/datasource-fetch-handler/src/index.ts index d59fc0a8d..2bb5df893 100644 --- a/packages/datasource-handlers/packages/fetch/src/index.ts +++ b/packages/datasource-fetch-handler/src/index.ts @@ -1,4 +1,4 @@ -import { RuntimeOptionsConfig } from '@ali/build-success-types'; +import { RuntimeOptionsConfig } from '@ali/lowcode-types'; import request from 'universal-request'; import { RequestOptions, AsObject } from 'universal-request/lib/types'; diff --git a/packages/datasource-handlers/tsconfig.json b/packages/datasource-fetch-handler/tsconfig.json similarity index 95% rename from packages/datasource-handlers/tsconfig.json rename to packages/datasource-fetch-handler/tsconfig.json index 68d4e6bb3..ecd74d9e2 100644 --- a/packages/datasource-handlers/tsconfig.json +++ b/packages/datasource-fetch-handler/tsconfig.json @@ -1,10 +1,16 @@ { "compilerOptions": { + "outDir": "es", + "target": "es6", + "module": "esnext", /* Basic Options */ // "incremental": true, /* Enable incremental compilation */ // "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, // "module": "esnext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, - "lib": ["ESNext", "DOM"] /* Specify library files to be included in the compilation. */, + "lib": [ + "ESNext", + "DOM" + ] /* Specify library files to be included in the compilation. */, // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ @@ -21,7 +27,6 @@ // "importHelpers": true, /* Import emit helpers from 'tslib'. */ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ - /* Strict Type-Checking Options */ "strict": true /* Enable all strict type-checking options. */, // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ @@ -31,13 +36,11 @@ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ - /* Additional Checks */ // "noUnusedLocals": true, /* Report errors on unused locals. */ // "noUnusedParameters": true, /* Report errors on unused parameters. */ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - /* Module Resolution Options */ "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ @@ -49,19 +52,19 @@ "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - /* Source Map Options */ // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ - /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - /* Advanced Options */ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, - "skipLibCheck": true + "skipLibCheck": true, + "include": [ + "src/**/*" + ] } -} +} \ No newline at end of file diff --git a/packages/datasource-handlers/.eslintignore b/packages/datasource-handlers/.eslintignore deleted file mode 100644 index 096746c14..000000000 --- a/packages/datasource-handlers/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -/node_modules/ \ No newline at end of file diff --git a/packages/datasource-handlers/lerna.json b/packages/datasource-handlers/lerna.json deleted file mode 100644 index b9933894c..000000000 --- a/packages/datasource-handlers/lerna.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "packages": ["packages/*"], - "version": "independent", - "npmClient": "yarn" -} diff --git a/packages/datasource-handlers/package.json b/packages/datasource-handlers/package.json deleted file mode 100644 index 43cea9f9d..000000000 --- a/packages/datasource-handlers/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "@ali/lowcode-datasource-handlers", - "version": "1.0.0", - "main": "index.js", - "license": "MIT", - "devDependencies": { - "lerna": "^3.22.0" - } -} diff --git a/packages/datasource-handlers/packages/fetch/es/index.d.ts b/packages/datasource-handlers/packages/fetch/es/index.d.ts deleted file mode 100644 index 443ad0dd1..000000000 --- a/packages/datasource-handlers/packages/fetch/es/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { RuntimeOptionsConfig } from '@ali/build-success-types'; -export declare function createFetchHandler(config?: unknown): (options: RuntimeOptionsConfig) => Promise; diff --git a/packages/datasource-handlers/packages/fetch/es/index.js b/packages/datasource-handlers/packages/fetch/es/index.js deleted file mode 100644 index 0b4d6e5ba..000000000 --- a/packages/datasource-handlers/packages/fetch/es/index.js +++ /dev/null @@ -1,25 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import request from 'universal-request'; -// config 留着扩展 -export function createFetchHandler(config) { - return function (options) { - return __awaiter(this, void 0, void 0, function* () { - const requestConfig = Object.assign(Object.assign({}, options), { url: options.uri, method: options.method, data: options.params, headers: options.headers }); - try { - const response = yield request(requestConfig); - return response; - } - catch (error) { - throw error; - } - }); - }; -} diff --git a/packages/datasource-handlers/packages/fetch/tsconfig.json b/packages/datasource-handlers/packages/fetch/tsconfig.json deleted file mode 100644 index 268731175..000000000 --- a/packages/datasource-handlers/packages/fetch/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "es", - "target": "es6", - "module": "esnext" - }, - - "include": ["src/**/*"] -} diff --git a/packages/datasource-handlers/packages/mopen/es/index.d.ts b/packages/datasource-handlers/packages/mopen/es/index.d.ts deleted file mode 100644 index 17039d9f2..000000000 --- a/packages/datasource-handlers/packages/mopen/es/index.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { MopenClientConfig } from '@ali/mirror-io-client-mopen'; -import { RuntimeOptionsConfig } from '@ali/build-success-types'; -export declare function createMopenHandler(config?: MopenClientConfig): (options: RuntimeOptionsConfig) => Promise<{ - data: T; -}>; diff --git a/packages/datasource-handlers/packages/mopen/es/index.js b/packages/datasource-handlers/packages/mopen/es/index.js deleted file mode 100644 index 967facd1d..000000000 --- a/packages/datasource-handlers/packages/mopen/es/index.js +++ /dev/null @@ -1,26 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import { MopenClient, MOPEN_APPKEY_XSPACE_PRE_ONLINE, MOPEN_DOMAIN_TAOBAO_PRE_ONLINE, } from '@ali/mirror-io-client-mopen'; -export function createMopenHandler(config = { - mtopDomain: MOPEN_DOMAIN_TAOBAO_PRE_ONLINE, - appKey: MOPEN_APPKEY_XSPACE_PRE_ONLINE, -}) { - return function (options) { - return __awaiter(this, void 0, void 0, function* () { - try { - const { data, response } = yield MopenClient.request(Object.assign(Object.assign({ config }, options), { api: options.uri, v: options.v, data: options.params, type: options.method || 'get', dataType: options.dataType || 'json', timeout: options.timeout, headers: options.headers })); - return Object.assign(Object.assign({}, response), { data }); - } - catch (error) { - throw error; - } - }); - }; -} diff --git a/packages/datasource-handlers/packages/mopen/tsconfig.json b/packages/datasource-handlers/packages/mopen/tsconfig.json deleted file mode 100644 index 268731175..000000000 --- a/packages/datasource-handlers/packages/mopen/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "es", - "target": "es6", - "module": "esnext" - }, - - "include": ["src/**/*"] -} diff --git a/packages/datasource-handlers/packages/mtop/es/index.d.ts b/packages/datasource-handlers/packages/mtop/es/index.d.ts deleted file mode 100644 index c30b6a50a..000000000 --- a/packages/datasource-handlers/packages/mtop/es/index.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { RuntimeOptionsConfig } from '@ali/build-success-types'; -export declare type Method = 'get' | 'post' | 'GET' | 'POST'; -export declare type DataType = 'jsonp' | 'json' | 'originaljsonp'; -export declare function createMtopHandler(config?: MTopConfig): (options: RuntimeOptionsConfig) => Promise<{ - data: T; -}>; diff --git a/packages/datasource-handlers/packages/mtop/es/index.js b/packages/datasource-handlers/packages/mtop/es/index.js deleted file mode 100644 index fed789e22..000000000 --- a/packages/datasource-handlers/packages/mtop/es/index.js +++ /dev/null @@ -1,35 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import mtopRequest from '@ali/universal-mtop'; -// 考虑一下 mtop 类型的问题,官方没有提供 ts 文件 -export function createMtopHandler(config) { - if (config && Object.keys(config).length > 0) { - Object.keys(config).forEach((key) => mtopRequest.config(key, config[key])); - } - return function (options) { - return __awaiter(this, void 0, void 0, function* () { - try { - const response = yield mtopRequest.request({ - api: options.uri, - v: options.v || '1.0', - data: options.params, - type: options.method || 'get', - dataType: options.dataType || 'json', - timeout: options.timeout, - headers: options.headers, - }); - return response; - } - catch (error) { - throw error; - } - }); - }; -} diff --git a/packages/datasource-handlers/packages/mtop/tsconfig.json b/packages/datasource-handlers/packages/mtop/tsconfig.json deleted file mode 100644 index 268731175..000000000 --- a/packages/datasource-handlers/packages/mtop/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "es", - "target": "es6", - "module": "esnext" - }, - - "include": ["src/**/*"] -} diff --git a/packages/datasource-handlers/packages/universalMtop/es/index.d.ts b/packages/datasource-handlers/packages/universalMtop/es/index.d.ts deleted file mode 100644 index 2a16eb3e9..000000000 --- a/packages/datasource-handlers/packages/universalMtop/es/index.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { UniversalMtopClientConfig } from '@ali/mirror-io-client-universal-mtop'; -import { RuntimeOptionsConfig } from '@ali/build-success-types'; -export declare function createMopenHandler(config?: UniversalMtopClientConfig): (options: RuntimeOptionsConfig) => Promise<{ - data: T; -}>; diff --git a/packages/datasource-handlers/packages/universalMtop/es/index.js b/packages/datasource-handlers/packages/universalMtop/es/index.js deleted file mode 100644 index 718adf31b..000000000 --- a/packages/datasource-handlers/packages/universalMtop/es/index.js +++ /dev/null @@ -1,23 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import { UniversalMtopClient, } from '@ali/mirror-io-client-universal-mtop'; -export function createMopenHandler(config) { - return function (options) { - return __awaiter(this, void 0, void 0, function* () { - try { - const { data, response } = yield UniversalMtopClient.request(Object.assign(Object.assign({ config }, options), { api: options.uri, v: options.v, data: options.params, type: options.method || 'get', dataType: options.dataType || 'json', timeout: options.timeout, headers: options.headers })); - return Object.assign(Object.assign({}, response), { data }); - } - catch (error) { - throw error; - } - }); - }; -} diff --git a/packages/datasource-handlers/packages/universalMtop/tsconfig.json b/packages/datasource-handlers/packages/universalMtop/tsconfig.json deleted file mode 100644 index 268731175..000000000 --- a/packages/datasource-handlers/packages/universalMtop/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "es", - "target": "es6", - "module": "esnext" - }, - - "include": ["src/**/*"] -} diff --git a/packages/datasource-handlers/packages/urlParams/es/index.d.ts b/packages/datasource-handlers/packages/urlParams/es/index.d.ts deleted file mode 100644 index f16cb44c3..000000000 --- a/packages/datasource-handlers/packages/urlParams/es/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { UrlParamsHandler } from '@ali/build-success-types'; -export declare function createUrlParamsHandler(searchString?: string | T): UrlParamsHandler; diff --git a/packages/datasource-handlers/packages/urlParams/es/index.js b/packages/datasource-handlers/packages/urlParams/es/index.js deleted file mode 100644 index 84a9451ef..000000000 --- a/packages/datasource-handlers/packages/urlParams/es/index.js +++ /dev/null @@ -1,21 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import qs from 'query-string'; -export function createUrlParamsHandler(searchString = '') { - return function () { - return __awaiter(this, void 0, void 0, function* () { - if (typeof searchString === 'string') { - const params = qs.parse(searchString); - return params; - } - return searchString; - }); - }; -} diff --git a/packages/datasource-handlers/packages/urlParams/tsconfig.json b/packages/datasource-handlers/packages/urlParams/tsconfig.json deleted file mode 100644 index 268731175..000000000 --- a/packages/datasource-handlers/packages/urlParams/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "es", - "target": "es6", - "module": "esnext" - }, - - "include": ["src/**/*"] -} diff --git a/packages/datasource-mopen-handler/.eslintignore b/packages/datasource-mopen-handler/.eslintignore new file mode 100644 index 000000000..fecb7c26d --- /dev/null +++ b/packages/datasource-mopen-handler/.eslintignore @@ -0,0 +1,3 @@ +/node_modules +/es +/lib \ No newline at end of file diff --git a/packages/datasource-mopen-handler/.eslintrc.js b/packages/datasource-mopen-handler/.eslintrc.js new file mode 100644 index 000000000..8c13fcaf4 --- /dev/null +++ b/packages/datasource-mopen-handler/.eslintrc.js @@ -0,0 +1,7 @@ +module.exports = { + extends: '../../.eslintrc', + rules: { + '@typescript-eslint/no-parameter-properties': 1, + 'no-param-reassign': 0, + }, +}; diff --git a/packages/datasource-mopen-handler/.prettierrc.js b/packages/datasource-mopen-handler/.prettierrc.js new file mode 100644 index 000000000..de2f53cdf --- /dev/null +++ b/packages/datasource-mopen-handler/.prettierrc.js @@ -0,0 +1,4 @@ +module.exports = { + singleQuote: true, + trailingComma: 'all', +}; diff --git a/packages/datasource-handlers/packages/mopen/package.json b/packages/datasource-mopen-handler/package.json similarity index 89% rename from packages/datasource-handlers/packages/mopen/package.json rename to packages/datasource-mopen-handler/package.json index 87ff98947..7c60a774a 100644 --- a/packages/datasource-handlers/packages/mopen/package.json +++ b/packages/datasource-mopen-handler/package.json @@ -15,10 +15,8 @@ "build": "npm run clean && tsc && tsc --outDir ./lib --module commonjs ", "prepublishOnly": "npm run build" }, - "devDependencies": { - "@ali/build-success-types": "^0.1.2-alpha.35" - }, "dependencies": { + "@ali/lowcode-types": "^1.0.10", "@ali/mirror-io-client-mopen": "1.0.0-beta.16", "typescript": "^3.9.7" }, diff --git a/packages/datasource-handlers/packages/mopen/src/index.ts b/packages/datasource-mopen-handler/src/index.ts similarity index 93% rename from packages/datasource-handlers/packages/mopen/src/index.ts rename to packages/datasource-mopen-handler/src/index.ts index 9367fbb4f..6fc4fb287 100644 --- a/packages/datasource-handlers/packages/mopen/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/build-success-types'; +import { RuntimeOptionsConfig } from '@ali/lowcode-types'; type Method = 'get' | 'post' | 'GET' | 'POST'; diff --git a/packages/datasource-mopen-handler/tsconfig.json b/packages/datasource-mopen-handler/tsconfig.json new file mode 100644 index 000000000..ecd74d9e2 --- /dev/null +++ b/packages/datasource-mopen-handler/tsconfig.json @@ -0,0 +1,70 @@ +{ + "compilerOptions": { + "outDir": "es", + "target": "es6", + "module": "esnext", + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + // "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, + // "module": "esnext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, + "lib": [ + "ESNext", + "DOM" + ] /* Specify library files to be included in the compilation. */, + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + "declaration": true /* Generates corresponding '.d.ts' file. */, + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + // "outDir": "es" /* Redirect output structure to the directory. */, + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + /* Strict Type-Checking Options */ + "strict": true /* Enable all strict type-checking options. */, + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + /* Module Resolution Options */ + "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + /* Advanced Options */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, + "skipLibCheck": true, + "include": [ + "src/**/*" + ] + } +} \ No newline at end of file diff --git a/packages/datasource-mtop-handler/.eslintignore b/packages/datasource-mtop-handler/.eslintignore new file mode 100644 index 000000000..fecb7c26d --- /dev/null +++ b/packages/datasource-mtop-handler/.eslintignore @@ -0,0 +1,3 @@ +/node_modules +/es +/lib \ No newline at end of file diff --git a/packages/datasource-mtop-handler/.eslintrc.js b/packages/datasource-mtop-handler/.eslintrc.js new file mode 100644 index 000000000..8c13fcaf4 --- /dev/null +++ b/packages/datasource-mtop-handler/.eslintrc.js @@ -0,0 +1,7 @@ +module.exports = { + extends: '../../.eslintrc', + rules: { + '@typescript-eslint/no-parameter-properties': 1, + 'no-param-reassign': 0, + }, +}; diff --git a/packages/datasource-mtop-handler/.prettierrc.js b/packages/datasource-mtop-handler/.prettierrc.js new file mode 100644 index 000000000..de2f53cdf --- /dev/null +++ b/packages/datasource-mtop-handler/.prettierrc.js @@ -0,0 +1,4 @@ +module.exports = { + singleQuote: true, + trailingComma: 'all', +}; diff --git a/packages/datasource-handlers/packages/mtop/package.json b/packages/datasource-mtop-handler/package.json similarity index 88% rename from packages/datasource-handlers/packages/mtop/package.json rename to packages/datasource-mtop-handler/package.json index d0f0288c7..2143f71eb 100644 --- a/packages/datasource-handlers/packages/mtop/package.json +++ b/packages/datasource-mtop-handler/package.json @@ -15,10 +15,8 @@ "build": "npm run clean && tsc && tsc --outDir ./lib --module commonjs ", "prepublishOnly": "npm run build" }, - "devDependencies": { - "@ali/build-success-types": "^0.1.2-alpha.35" - }, "dependencies": { + "@ali/lowcode-types": "^1.0.10", "@ali/universal-mtop": "^5.1.9", "typescript": "^3.9.7" }, diff --git a/packages/datasource-handlers/packages/mtop/src/index.ts b/packages/datasource-mtop-handler/src/index.ts similarity index 93% rename from packages/datasource-handlers/packages/mtop/src/index.ts rename to packages/datasource-mtop-handler/src/index.ts index 0c01cdd64..2527dda5c 100644 --- a/packages/datasource-handlers/packages/mtop/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/build-success-types'; +import { RuntimeOptionsConfig } from '@ali/lowcode-types'; export type Method = 'get' | 'post' | 'GET' | 'POST'; diff --git a/packages/datasource-handlers/packages/mtop/src/typings.d.ts b/packages/datasource-mtop-handler/src/typings.d.ts similarity index 100% rename from packages/datasource-handlers/packages/mtop/src/typings.d.ts rename to packages/datasource-mtop-handler/src/typings.d.ts diff --git a/packages/datasource-mtop-handler/tsconfig.json b/packages/datasource-mtop-handler/tsconfig.json new file mode 100644 index 000000000..ecd74d9e2 --- /dev/null +++ b/packages/datasource-mtop-handler/tsconfig.json @@ -0,0 +1,70 @@ +{ + "compilerOptions": { + "outDir": "es", + "target": "es6", + "module": "esnext", + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + // "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, + // "module": "esnext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, + "lib": [ + "ESNext", + "DOM" + ] /* Specify library files to be included in the compilation. */, + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + "declaration": true /* Generates corresponding '.d.ts' file. */, + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + // "outDir": "es" /* Redirect output structure to the directory. */, + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + /* Strict Type-Checking Options */ + "strict": true /* Enable all strict type-checking options. */, + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + /* Module Resolution Options */ + "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + /* Advanced Options */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, + "skipLibCheck": true, + "include": [ + "src/**/*" + ] + } +} \ No newline at end of file diff --git a/packages/datasource-universal-mtop-handler/.eslintignore b/packages/datasource-universal-mtop-handler/.eslintignore new file mode 100644 index 000000000..fecb7c26d --- /dev/null +++ b/packages/datasource-universal-mtop-handler/.eslintignore @@ -0,0 +1,3 @@ +/node_modules +/es +/lib \ No newline at end of file diff --git a/packages/datasource-universal-mtop-handler/.eslintrc.js b/packages/datasource-universal-mtop-handler/.eslintrc.js new file mode 100644 index 000000000..8c13fcaf4 --- /dev/null +++ b/packages/datasource-universal-mtop-handler/.eslintrc.js @@ -0,0 +1,7 @@ +module.exports = { + extends: '../../.eslintrc', + rules: { + '@typescript-eslint/no-parameter-properties': 1, + 'no-param-reassign': 0, + }, +}; diff --git a/packages/datasource-universal-mtop-handler/.prettierrc.js b/packages/datasource-universal-mtop-handler/.prettierrc.js new file mode 100644 index 000000000..de2f53cdf --- /dev/null +++ b/packages/datasource-universal-mtop-handler/.prettierrc.js @@ -0,0 +1,4 @@ +module.exports = { + singleQuote: true, + trailingComma: 'all', +}; diff --git a/packages/datasource-handlers/packages/universalMtop/package.json b/packages/datasource-universal-mtop-handler/package.json similarity index 89% rename from packages/datasource-handlers/packages/universalMtop/package.json rename to packages/datasource-universal-mtop-handler/package.json index 75c9f216f..bcb45d028 100644 --- a/packages/datasource-handlers/packages/universalMtop/package.json +++ b/packages/datasource-universal-mtop-handler/package.json @@ -15,10 +15,8 @@ "build": "npm run clean && tsc && tsc --outDir ./lib --module commonjs ", "prepublishOnly": "npm run build" }, - "devDependencies": { - "@ali/build-success-types": "^0.1.2-alpha.27" - }, "dependencies": { + "@ali/lowcode-types": "^1.0.10", "@ali/mirror-io-client-universal-mtop": "1.0.0-beta.16", "typescript": "^3.9.7" }, diff --git a/packages/datasource-handlers/packages/universalMtop/src/index.ts b/packages/datasource-universal-mtop-handler/src/index.ts similarity index 92% rename from packages/datasource-handlers/packages/universalMtop/src/index.ts rename to packages/datasource-universal-mtop-handler/src/index.ts index f44d9eebd..81cad731d 100644 --- a/packages/datasource-handlers/packages/universalMtop/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/build-success-types'; +import { RuntimeOptionsConfig } from '@ali/lowcode-types'; type Method = 'get' | 'post' | 'GET' | 'POST'; diff --git a/packages/datasource-universal-mtop-handler/tsconfig.json b/packages/datasource-universal-mtop-handler/tsconfig.json new file mode 100644 index 000000000..ecd74d9e2 --- /dev/null +++ b/packages/datasource-universal-mtop-handler/tsconfig.json @@ -0,0 +1,70 @@ +{ + "compilerOptions": { + "outDir": "es", + "target": "es6", + "module": "esnext", + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + // "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, + // "module": "esnext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, + "lib": [ + "ESNext", + "DOM" + ] /* Specify library files to be included in the compilation. */, + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + "declaration": true /* Generates corresponding '.d.ts' file. */, + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + // "outDir": "es" /* Redirect output structure to the directory. */, + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + /* Strict Type-Checking Options */ + "strict": true /* Enable all strict type-checking options. */, + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + /* Module Resolution Options */ + "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + /* Advanced Options */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, + "skipLibCheck": true, + "include": [ + "src/**/*" + ] + } +} \ No newline at end of file diff --git a/packages/datasource-url-params-handler/.eslintignore b/packages/datasource-url-params-handler/.eslintignore new file mode 100644 index 000000000..fecb7c26d --- /dev/null +++ b/packages/datasource-url-params-handler/.eslintignore @@ -0,0 +1,3 @@ +/node_modules +/es +/lib \ No newline at end of file diff --git a/packages/datasource-url-params-handler/.eslintrc.js b/packages/datasource-url-params-handler/.eslintrc.js new file mode 100644 index 000000000..8c13fcaf4 --- /dev/null +++ b/packages/datasource-url-params-handler/.eslintrc.js @@ -0,0 +1,7 @@ +module.exports = { + extends: '../../.eslintrc', + rules: { + '@typescript-eslint/no-parameter-properties': 1, + 'no-param-reassign': 0, + }, +}; diff --git a/packages/datasource-url-params-handler/.prettierrc.js b/packages/datasource-url-params-handler/.prettierrc.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/datasource-handlers/packages/urlParams/package.json b/packages/datasource-url-params-handler/package.json similarity index 88% rename from packages/datasource-handlers/packages/urlParams/package.json rename to packages/datasource-url-params-handler/package.json index 41ee2e618..869648b15 100644 --- a/packages/datasource-handlers/packages/urlParams/package.json +++ b/packages/datasource-url-params-handler/package.json @@ -15,10 +15,8 @@ "build": "npm run clean && tsc && tsc --outDir ./lib --module commonjs ", "prepublishOnly": "npm run build" }, - "devDependencies": { - "@ali/build-success-types": "^0.1.2-alpha.31" - }, "dependencies": { + "@ali/lowcode-types": "^1.0.10", "query-string": "^6.13.1", "typescript": "^3.9.7" }, diff --git a/packages/datasource-handlers/packages/urlParams/src/index.ts b/packages/datasource-url-params-handler/src/index.ts similarity index 85% rename from packages/datasource-handlers/packages/urlParams/src/index.ts rename to packages/datasource-url-params-handler/src/index.ts index c0c4a8836..db4761fc0 100644 --- a/packages/datasource-handlers/packages/urlParams/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/build-success-types'; +import { UrlParamsHandler } from '@ali/lowcode-types'; export function createUrlParamsHandler( searchString: string | T = '', diff --git a/packages/datasource-url-params-handler/tsconfig.json b/packages/datasource-url-params-handler/tsconfig.json new file mode 100644 index 000000000..ecd74d9e2 --- /dev/null +++ b/packages/datasource-url-params-handler/tsconfig.json @@ -0,0 +1,70 @@ +{ + "compilerOptions": { + "outDir": "es", + "target": "es6", + "module": "esnext", + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + // "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, + // "module": "esnext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, + "lib": [ + "ESNext", + "DOM" + ] /* Specify library files to be included in the compilation. */, + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + "declaration": true /* Generates corresponding '.d.ts' file. */, + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + // "outDir": "es" /* Redirect output structure to the directory. */, + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + /* Strict Type-Checking Options */ + "strict": true /* Enable all strict type-checking options. */, + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + /* Module Resolution Options */ + "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + /* Advanced Options */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, + "skipLibCheck": true, + "include": [ + "src/**/*" + ] + } +} \ No newline at end of file diff --git a/packages/types/.eslintignore b/packages/types/.eslintignore new file mode 100644 index 000000000..a218a6cce --- /dev/null +++ b/packages/types/.eslintignore @@ -0,0 +1,3 @@ +lib +es +node_modules \ No newline at end of file diff --git a/packages/types/.eslintrc.js b/packages/types/.eslintrc.js new file mode 100644 index 000000000..3c65aade8 --- /dev/null +++ b/packages/types/.eslintrc.js @@ -0,0 +1,9 @@ +module.exports = { + extends: '../../.eslintrc', + rules: { + '@typescript-eslint/no-parameter-properties': 1, + 'no-param-reassign': 0, + '@typescript-eslint/member-ordering': 0, + indent: 0, + }, +}; diff --git a/packages/types/.prettierrc.js b/packages/types/.prettierrc.js new file mode 100644 index 000000000..092b67059 --- /dev/null +++ b/packages/types/.prettierrc.js @@ -0,0 +1,6 @@ +module.exports = { + printWidth: 80, + singleQuote: true, + trailingComma: 'all', + tabSize: 2, +}; diff --git a/packages/types/src/data-source-handlers.ts b/packages/types/src/data-source-handlers.ts new file mode 100644 index 000000000..2e054b4e8 --- /dev/null +++ b/packages/types/src/data-source-handlers.ts @@ -0,0 +1,15 @@ +import { + IDataSourceRuntimeContext, + RuntimeOptionsConfig, +} from './data-source-runtime'; + +export type RequestHandler = ( + options: RuntimeOptionsConfig, + context: IDataSourceRuntimeContext +) => Promise; + +export type UrlParamsHandler = ( + context?: IDataSourceRuntimeContext +) => Promise; + +export type RequestHandlersMap = Record>; diff --git a/packages/types/src/data-source-interpret.ts b/packages/types/src/data-source-interpret.ts new file mode 100644 index 000000000..be28117f7 --- /dev/null +++ b/packages/types/src/data-source-interpret.ts @@ -0,0 +1,41 @@ +import { + CompositeValue, + JSExpression, + JSFunction, + JSONObject, +} from './value-type'; + +/** + * 数据源对象 + * @see https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5 + */ +export interface InterpretDataSource { + list: InterpretDataSourceConfig[]; + dataHandler?: JSFunction; +} + +/** + * 数据源对象 + * @see https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5 + */ +export interface InterpretDataSourceConfig { + id: string; + isInit?: boolean | JSExpression; + isSync?: boolean | JSExpression; + type?: string; + requestHandler?: JSFunction; + dataHandler?: JSFunction; + errorHandler?: JSFunction; + willFetch?: JSFunction; + shouldFetch?: JSFunction; + options?: { + uri: string | JSExpression; + params?: JSONObject | JSExpression; + method?: string | JSExpression; + isCors?: boolean | JSExpression; + timeout?: number | JSExpression; + headers?: JSONObject | JSExpression; + [option: string]: CompositeValue; + }; + [otherKey: string]: CompositeValue; +} diff --git a/packages/types/src/data-source-runtime.ts b/packages/types/src/data-source-runtime.ts new file mode 100644 index 000000000..eb27dab61 --- /dev/null +++ b/packages/types/src/data-source-runtime.ts @@ -0,0 +1,53 @@ +import { IRuntimeDataSource } from './data-source'; + +// 先定义运行模式的类型 +export interface RuntimeDataSource { + list: RuntimeDataSourceConfig[]; + // TODO: dataMap 格式不对要处理 + dataHandler?: (dataMap: DataSourceMap) => void; +} + +export type DataSourceMap = Record; + +export interface RuntimeDataSourceConfig { + id: string; + isInit?: boolean; + isSync?: boolean; + type?: string; + willFetch?: () => void; + shouldFetch?: () => boolean; + requestHandler?: () => void; // TODO: 待定 + dataHandler?: DataHandler; + errorHandler?: ErrorHandler; + options?: RuntimeOptions; + [otherKey: string]: unknown; +} + +export type DataHandler = (response: { + data: T; + [index: string]: unknown; +}) => Promise; + +export type ErrorHandler = (err: unknown) => Promise; + +export type RuntimeOptions = () => RuntimeOptionsConfig; + +export interface RuntimeOptionsConfig { + uri: string; + params?: Record; + method?: string; + isCors?: boolean; + timeout?: number; + headers?: Record; + [option: string]: unknown; +} + +// 可以采用 react 的 state,但是需要注意必须提供同步的 setState 功能 +export interface IDataSourceRuntimeContext< + TState extends Record = Record + > { + /** 当前数据源的内容 */ + state: TState; + /** 设置状态(浅合并) */ + setState(state: Partial): void; +} diff --git a/packages/types/src/data-source.ts b/packages/types/src/data-source.ts index 79bca2e91..77d8c6d56 100644 --- a/packages/types/src/data-source.ts +++ b/packages/types/src/data-source.ts @@ -1,16 +1,65 @@ -import { CompositeValue } from './value-type'; +import { RequestHandlersMap } from './data-source-handlers'; +import { + IDataSourceRuntimeContext, + RuntimeDataSource, +} from './data-source-runtime'; -export interface DataSourceConfig { - id: string; - isInit: boolean; - type: string; - options: { - uri: string; - [option: string]: CompositeValue; - }; - [otherKey: string]: CompositeValue; +/** 数据源的状态 */ +export enum RuntimeDataSourceStatus { + /** 初始状态,尚未加载 */ + Initial = 'init', + + /** 正在加载 */ + Loading = 'loading', + + /** 已加载(无错误) */ + Loaded = 'loaded', + + /** 加载出错了 */ + Error = 'error', } -export interface DataSource { - items: DataSourceConfig[]; +/** + * 运行时的数据源(对外暴露的接口) + * @see https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#Jwgj5 + */ +export interface IRuntimeDataSource { + /** 当前状态(initial/loading/loaded/error) */ + readonly status: RuntimeDataSourceStatus; + + /** 加载成功时的数据 */ + readonly data?: TResultData; + + /** 加载出错的时候的错误信息 */ + readonly error?: Error; + + /** + * 加载数据 (无论是否曾经加载过) + * 注意:若提供 params,则会和默认配置的参数做浅合并;否则会使用默认配置的参数。 + */ + load(params?: TParams): Promise; +} + +/** + * DataSourceEngineFactory + * 用来定义 engine 的工厂函数类型 + */ +export interface IRuntimeDataSourceEngineFactory { + create( + dataSource: RuntimeDataSource, + context: IDataSourceRuntimeContext, + extraConfig?: { + requestHandlersMap: RequestHandlersMap; + [key: string]: any; + } + ): IDataSourceEngine; +} + +// create 返回的 DataSourceEngine 定义 +export interface IDataSourceEngine { + /** 数据源, key 是数据源的 ID */ + dataSourceMap: Record; + + /** 重新加载所有的数据源 */ + reloadDataSource(): Promise; } diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index d8f66a46c..4889f5e8f 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -1,4 +1,7 @@ export * from './data-source'; +export * from './data-source-handlers'; +export * from './data-source-interpret'; +export * from './data-source-runtime'; export * from './editor'; export * from './field-config'; export * from './i18n'; diff --git a/packages/types/src/value-type.ts b/packages/types/src/value-type.ts index 6e5083c0a..353033605 100644 --- a/packages/types/src/value-type.ts +++ b/packages/types/src/value-type.ts @@ -11,6 +11,44 @@ export interface JSExpression { * 模拟值 */ mock?: any; +} + +// 函数 +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 */ @@ -18,7 +56,6 @@ export interface JSExpression { } export interface JSSlot { - name?: string; type: 'JSSlot'; title?: string; // 函数的入参 @@ -32,28 +69,44 @@ export interface JSBlock { } // JSON 基本类型 -export type JSONValue = boolean | string | number | null | undefined | JSONArray | JSONObject; +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 | JSSlot | CompositeArray | CompositeObject; +export type CompositeValue = + | JSONValue + | JSExpression + | JSFunction + | JSSlot + | 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'; +} + export function isJSSlot(data: any): data is JSSlot { return data && data.type === 'JSSlot'; } export function isJSBlock(data: any): data is JSBlock { - return data && data.type === 'JSBlock' + return data && data.type === 'JSBlock'; }