mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-06-13 00:09:20 +08:00
chore(data-source): 单独定义Core,避免循环引用
This commit is contained in:
parent
2bd86d2101
commit
cd50d36394
@ -38,7 +38,6 @@
|
|||||||
"lodash-es": "^4.17.21"
|
"lodash-es": "^4.17.21"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tmagic/core": "1.3.0-alpha.21",
|
|
||||||
"@types/events": "^3.0.0",
|
"@types/events": "^3.0.0",
|
||||||
"@types/lodash-es": "^4.17.4",
|
"@types/lodash-es": "^4.17.4",
|
||||||
"@types/node": "^15.12.4",
|
"@types/node": "^15.12.4",
|
||||||
|
@ -20,12 +20,11 @@ import EventEmitter from 'events';
|
|||||||
|
|
||||||
import { cloneDeep, template } from 'lodash-es';
|
import { cloneDeep, template } from 'lodash-es';
|
||||||
|
|
||||||
import type Core from '@tmagic/core';
|
|
||||||
import type { DataSourceSchema, Id, MNode } from '@tmagic/schema';
|
import type { DataSourceSchema, Id, MNode } from '@tmagic/schema';
|
||||||
import { compiledCond, compiledNode } from '@tmagic/utils';
|
import { compiledCond, compiledNode } from '@tmagic/utils';
|
||||||
|
|
||||||
import { DataSource, HttpDataSource } from './data-sources';
|
import { DataSource, HttpDataSource } from './data-sources';
|
||||||
import type { DataSourceManagerData, DataSourceManagerOptions, HttpDataSourceSchema } from './types';
|
import type { AppCore, DataSourceManagerData, DataSourceManagerOptions, HttpDataSourceSchema } from './types';
|
||||||
|
|
||||||
class DataSourceManager extends EventEmitter {
|
class DataSourceManager extends EventEmitter {
|
||||||
private static dataSourceClassMap = new Map<string, typeof DataSource>();
|
private static dataSourceClassMap = new Map<string, typeof DataSource>();
|
||||||
@ -38,7 +37,7 @@ class DataSourceManager extends EventEmitter {
|
|||||||
return DataSourceManager.dataSourceClassMap.get(type);
|
return DataSourceManager.dataSourceClassMap.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public app: Core;
|
public app: AppCore;
|
||||||
|
|
||||||
public dataSourceMap = new Map<string, DataSource>();
|
public dataSourceMap = new Map<string, DataSource>();
|
||||||
|
|
||||||
|
@ -17,10 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
import { cloneDeep } from 'lodash-es';
|
import { cloneDeep } from 'lodash-es';
|
||||||
|
|
||||||
import type Core from '@tmagic/core';
|
|
||||||
import { getDepNodeIds, getNodes, replaceChildNode } from '@tmagic/utils';
|
import { getDepNodeIds, getNodes, replaceChildNode } from '@tmagic/utils';
|
||||||
|
|
||||||
import DataSourceManager from './DataSourceManager';
|
import DataSourceManager from './DataSourceManager';
|
||||||
|
import type { AppCore } from './types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建数据源管理器
|
* 创建数据源管理器
|
||||||
@ -28,7 +28,7 @@ import DataSourceManager from './DataSourceManager';
|
|||||||
* @param httpDataSourceOptions http 数据源配置
|
* @param httpDataSourceOptions http 数据源配置
|
||||||
* @returns DataSourceManager
|
* @returns DataSourceManager
|
||||||
*/
|
*/
|
||||||
export const createDataSourceManager = (app: Core) => {
|
export const createDataSourceManager = (app: AppCore) => {
|
||||||
const { dsl, platform } = app;
|
const { dsl, platform } = app;
|
||||||
if (!dsl?.dataSources) return;
|
if (!dsl?.dataSources) return;
|
||||||
|
|
||||||
|
@ -17,10 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
import EventEmitter from 'events';
|
import EventEmitter from 'events';
|
||||||
|
|
||||||
import type Core from '@tmagic/core';
|
|
||||||
import type { CodeBlockContent, DataSchema } from '@tmagic/schema';
|
import type { CodeBlockContent, DataSchema } from '@tmagic/schema';
|
||||||
|
|
||||||
import type { DataSourceOptions } from '@data-source/types';
|
import type { AppCore, DataSourceOptions } from '@data-source/types';
|
||||||
import { getDefaultValueFromFields } from '@data-source/util';
|
import { getDefaultValueFromFields } from '@data-source/util';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,7 +34,7 @@ export default class DataSource extends EventEmitter {
|
|||||||
|
|
||||||
public data: Record<string, any> = {};
|
public data: Record<string, any> = {};
|
||||||
|
|
||||||
public app: Core;
|
public app: AppCore;
|
||||||
|
|
||||||
private fields: DataSchema[] = [];
|
private fields: DataSchema[] = [];
|
||||||
private methods: CodeBlockContent[] = [];
|
private methods: CodeBlockContent[] = [];
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
import type Core from '@tmagic/core';
|
import type { DataSourceSchema, MApp } from '@tmagic/schema';
|
||||||
import type { DataSourceSchema } from '@tmagic/schema';
|
|
||||||
|
export interface AppCore {
|
||||||
|
dsl?: MApp;
|
||||||
|
platform?: string;
|
||||||
|
jsEngine?: string;
|
||||||
|
request?: RequestFunction;
|
||||||
|
}
|
||||||
|
|
||||||
export interface DataSourceOptions {
|
export interface DataSourceOptions {
|
||||||
schema: DataSourceSchema;
|
schema: DataSourceSchema;
|
||||||
app: Core;
|
app: AppCore;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'post' | 'POST' | 'put' | 'PUT';
|
export type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'post' | 'POST' | 'put' | 'PUT';
|
||||||
@ -29,12 +35,12 @@ export interface HttpDataSourceSchema extends DataSourceSchema {
|
|||||||
|
|
||||||
export interface HttpDataSourceOptions {
|
export interface HttpDataSourceOptions {
|
||||||
schema: HttpDataSourceSchema;
|
schema: HttpDataSourceSchema;
|
||||||
app: Core;
|
app: AppCore;
|
||||||
request?: RequestFunction;
|
request?: RequestFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DataSourceManagerOptions {
|
export interface DataSourceManagerOptions {
|
||||||
app: Core;
|
app: AppCore;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DataSourceManagerData {
|
export interface DataSourceManagerData {
|
||||||
|
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@ -206,9 +206,6 @@ importers:
|
|||||||
specifier: ^4.17.21
|
specifier: ^4.17.21
|
||||||
version: 4.17.21
|
version: 4.17.21
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@tmagic/core':
|
|
||||||
specifier: 1.3.0-alpha.21
|
|
||||||
version: link:../core
|
|
||||||
'@types/events':
|
'@types/events':
|
||||||
specifier: ^3.0.0
|
specifier: ^3.0.0
|
||||||
version: 3.0.0
|
version: 3.0.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user