Files
datalive-design/src/schema/mutation/mutation-config.ts
T

71 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { DynamicExpression, RestRequest } from '../shared';
/**
* 数据变更核心配置引擎
*
* 【架构定位】:
*
* 这是一个多态联合类型 (Polymorphism Union Type)。
* 它决定了当前这个 `Mutation` 到底是通过什么“物理手段”去修改服务端状态的。
*
* 核心架构差异(与 QueryConfig 的对比):
*
* 坚决不允许存在 `MutationConfigByStatic`
* 因为修改一个内存里的死数据(Mock)是没有任何业务意义的,写操作必定伴随着网络 I/O 或数据库操作。
*/
export type MutationConfig =
| MutationConfigByRest
| MutationConfigByGraphql
| MutationConfigByDatabase
| MutationConfigByCode;
/**
* 1. RESTful 协议变更配置 (REST API)
*
* 占据了低代码数据变更 90% 以上场景的主力网络通信配置。
*/
export interface MutationConfigByRest {
type: 'rest';
/**
* HTTP 请求方法
*
* 引擎防呆指引:
* 既然是写操作(Mutation),绝大部分符合 REST 语义的设计必须是以下四种动词。
* 坚决不要在此处允许出现 GET 请求!
*/
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
/**
* 请求体配置
*
* 极其关键的双模逃生舱设计 (Dual-Mode Design)
* 它引入了定义在 `core/rest-request.ts` 中的 `RestRequest` 类型
* (`RestRequestByFixed | RestRequestByCode`)。
*
* 这是低代码平台处理极度复杂的表单提交数据组装(如从多个 Variables 里提取数据并加密)的终极战场。
*/
request: RestRequest;
/**
* 接口超时时间 (毫秒 ms)
*
* 变更操作(如上传大文件或复杂计算)往往比查询需要更长的超时容忍度。
* 如果启用,引擎应使用全局 DataSource 配置的超时,或默认的浏览器超时。
*/
timeout: {
enabled: boolean;
duration: number;
};
}
// TODO: GraphQL 变更配置,暂不实现
export interface MutationConfigByGraphql {
type: 'graphql';
}
// TODO: 数据库变更配置,暂不实现
export interface MutationConfigByDatabase {
type: 'database';
}
// TODO: 代码变更配置,暂不实现
export interface MutationConfigByCode extends DynamicExpression {}