@arvin-shu/microcode-datasource-types
Advanced tools
+1
-1
| { | ||
| "name": "@arvin-shu/microcode-datasource-types", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
| import { IDataSourceRuntimeContext, RuntimeOptionsConfig } from './data-source-runtime'; | ||
| export type RequestHandler<T = unknown> = (options: RuntimeOptionsConfig, context?: IDataSourceRuntimeContext) => Promise<T>; | ||
| export type UrlParamsHandler<T = unknown> = (context?: IDataSourceRuntimeContext) => Promise<T>; | ||
| export type RequestHandlersMap<T = unknown> = Record<string, RequestHandler<T>>; | ||
| export type CustomRequestHandler<T = unknown> = (options: RuntimeOptionsConfig, context?: IDataSourceRuntimeContext) => Promise<T>; |
| export {}; | ||
| //# sourceMappingURL=data-source-handlers.js.map |
| {"version":3,"file":"data-source-handlers.js","sourceRoot":"","sources":["data-source-handlers.ts"],"names":[],"mappings":""} |
| import { CompositeValue, JSExpression, JSFunction, JSONObject } from './value-type'; | ||
| export interface InterpretDataSource { | ||
| list: InterpretDataSourceConfig[]; | ||
| dataHandler?: JSFunction; | ||
| } | ||
| 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; | ||
| api?: string | JSExpression; | ||
| params?: JSONObject | JSExpression; | ||
| method?: string | JSExpression; | ||
| isCors?: boolean | JSExpression; | ||
| timeout?: number | JSExpression; | ||
| headers?: JSONObject | JSExpression; | ||
| [option: string]: CompositeValue; | ||
| }; | ||
| [otherKey: string]: CompositeValue; | ||
| } |
| export {}; | ||
| //# sourceMappingURL=data-source-interpret.js.map |
| {"version":3,"file":"data-source-interpret.js","sourceRoot":"","sources":["data-source-interpret.ts"],"names":[],"mappings":""} |
| import { IRuntimeDataSource } from './data-source'; | ||
| import { CustomRequestHandler } from './data-source-handlers'; | ||
| export interface RuntimeDataSource { | ||
| list: RuntimeDataSourceConfig[]; | ||
| dataHandler?: (dataSourceMap: DataSourceMap) => void; | ||
| } | ||
| export interface IDataSourceRuntimeContext<TState = Record<string, unknown>> { | ||
| state: TState; | ||
| setState(state: TState): void; | ||
| forceUpdate(): void; | ||
| } | ||
| export type RuntimeOptions = () => RuntimeOptionsConfig; | ||
| export interface RuntimeDataSourceConfig { | ||
| id: string; | ||
| /** | ||
| * 是否为初始数据 | ||
| */ | ||
| isInit?: boolean; | ||
| /** | ||
| * 是否需要串行执行 | ||
| */ | ||
| isSync?: boolean; | ||
| /** | ||
| * 数据请求类型 | ||
| */ | ||
| type?: string; | ||
| /** | ||
| * 单个数据结果请求参数处理函数 | ||
| */ | ||
| willFetch?: WillFetch; | ||
| /** | ||
| * 本次请求是否可以正常请求 | ||
| * @param options | ||
| * @returns | ||
| */ | ||
| shouldFetch?: (options: RuntimeOptionsConfig) => boolean; | ||
| /** | ||
| * 自定义扩展的外部请求处理器 | ||
| */ | ||
| requestHandler?: CustomRequestHandler; | ||
| /** | ||
| * request 成功后的回调函数 | ||
| */ | ||
| dataHandler?: DataHandler; | ||
| /** | ||
| * request 失败后的回调函数 | ||
| */ | ||
| errorHandler?: ErrorHandler; | ||
| /** | ||
| * 请求参数 | ||
| */ | ||
| options?: RuntimeOptions; | ||
| [otherKey: string]: unknown; | ||
| } | ||
| export type ErrorHandler = (err: unknown) => Promise<any>; | ||
| export type WillFetch = (options: RuntimeOptionsConfig) => Promise<RuntimeOptionsConfig> | RuntimeOptionsConfig; | ||
| export interface RuntimeOptionsConfig { | ||
| uri: string; | ||
| api?: string; | ||
| params?: Record<string, unknown>; | ||
| method?: string; | ||
| isCors?: boolean; | ||
| timeout?: number; | ||
| headers?: Record<string, unknown>; | ||
| [option: string]: unknown; | ||
| } | ||
| export type DataHandler = <T>(response: { | ||
| data: T; | ||
| [index: string]: unknown; | ||
| }) => Promise<T | undefined>; | ||
| export type DataSourceMap = Record<string, IRuntimeDataSource>; |
| export {}; | ||
| //# sourceMappingURL=data-source-runtime.js.map |
| {"version":3,"file":"data-source-runtime.js","sourceRoot":"","sources":["data-source-runtime.ts"],"names":[],"mappings":""} |
| /** | ||
| * 运行时的数据源(对外暴露的接口) | ||
| */ | ||
| export interface IRuntimeDataSource<TParams = unknown, TResultData = unknown> { | ||
| /** 当前状态(initial/loading/loaded/error) */ | ||
| readonly status: RuntimeDataSourceStatus; | ||
| /** 加载成功时的数据 */ | ||
| readonly data?: TResultData; | ||
| /** 加载出错的时候的错误信息 */ | ||
| readonly error?: Error; | ||
| /** 当前是否正在加载中 */ | ||
| readonly isLoading?: boolean; | ||
| /** | ||
| * 加载数据 (无论是否曾经加载过) | ||
| * 注意:若提供 params,则会和默认配置的参数做浅合并;否则会使用默认配置的参数。 | ||
| */ | ||
| load(params?: TParams): Promise<TResultData | void>; | ||
| } | ||
| /** 数据源的状态 */ | ||
| export declare enum RuntimeDataSourceStatus { | ||
| /** 初始状态,尚未加载 */ | ||
| Initial = "init", | ||
| /** 正在加载 */ | ||
| Loading = "loading", | ||
| /** 已加载(无错误) */ | ||
| Loaded = "loaded", | ||
| /** 加载出错了 */ | ||
| Error = "error" | ||
| } |
| /** 数据源的状态 */ | ||
| export var RuntimeDataSourceStatus; | ||
| (function (RuntimeDataSourceStatus) { | ||
| /** 初始状态,尚未加载 */ | ||
| RuntimeDataSourceStatus["Initial"] = "init"; | ||
| /** 正在加载 */ | ||
| RuntimeDataSourceStatus["Loading"] = "loading"; | ||
| /** 已加载(无错误) */ | ||
| RuntimeDataSourceStatus["Loaded"] = "loaded"; | ||
| /** 加载出错了 */ | ||
| RuntimeDataSourceStatus["Error"] = "error"; | ||
| })(RuntimeDataSourceStatus || (RuntimeDataSourceStatus = {})); | ||
| //# sourceMappingURL=data-source.js.map |
| {"version":3,"file":"data-source.js","sourceRoot":"","sources":["data-source.ts"],"names":[],"mappings":"AAuBA,aAAa;AACb,MAAM,CAAN,IAAY,uBAYX;AAZD,WAAY,uBAAuB;IAClC,gBAAgB;IAChB,2CAAgB,CAAA;IAEhB,WAAW;IACX,8CAAmB,CAAA;IAEnB,eAAe;IACf,4CAAiB,CAAA;IAEjB,YAAY;IACZ,0CAAe,CAAA;AAChB,CAAC,EAZW,uBAAuB,KAAvB,uBAAuB,QAYlC"} |
| import { DataHandler } from './data-source-runtime'; | ||
| export type ExtraConfig = { | ||
| defaultDataHandler?: DataHandler; | ||
| }; |
| export {}; | ||
| //# sourceMappingURL=extra-config.js.map |
| {"version":3,"file":"extra-config.js","sourceRoot":"","sources":["extra-config.ts"],"names":[],"mappings":""} |
| export * from './data-source-interpret'; | ||
| export * from './data-source-runtime'; | ||
| export * from './data-source-handlers'; | ||
| export * from './extra-config'; | ||
| export * from './data-source'; | ||
| export * from './value-type'; |
| export * from './data-source-interpret'; | ||
| export * from './data-source-runtime'; | ||
| export * from './data-source-handlers'; | ||
| export * from './extra-config'; | ||
| export * from './data-source'; | ||
| export * from './value-type'; | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"} |
| export interface JSExpression { | ||
| type: 'JSExpression'; | ||
| /** | ||
| * 表达式的字符串表示形式 | ||
| */ | ||
| value: string; | ||
| /** | ||
| * 可选的模拟值,用于测试或占位 | ||
| */ | ||
| mock?: any; | ||
| /** | ||
| * 编译后的源码,便于调试和分析 | ||
| */ | ||
| compiled?: string; | ||
| } | ||
| export interface JSFunction { | ||
| type: 'JSFunction'; | ||
| /** | ||
| * 函数的字符串表示形式 | ||
| */ | ||
| value: string; | ||
| } | ||
| /** | ||
| * 事件函数类型接口,表示一个可以被调用的事件处理函数 | ||
| */ | ||
| export interface JSFunction { | ||
| type: 'JSFunction'; | ||
| /** | ||
| * 函数的定义,可以是函数声明或直接的函数表达式 | ||
| */ | ||
| value: string; | ||
| /** | ||
| * 编译后的源码,便于调试和分析 | ||
| */ | ||
| compiled?: string; | ||
| } | ||
| export interface JSFunction { | ||
| type: 'JSFunction'; | ||
| /** | ||
| * 函数的字符串表示形式 | ||
| */ | ||
| value: string; | ||
| /** | ||
| * 可选的模拟值,用于测试或占位 | ||
| */ | ||
| mock?: any; | ||
| /** | ||
| * 额外的扩展属性,可以包含如 extType、events 等信息 | ||
| */ | ||
| [key: string]: any; | ||
| } | ||
| export type JSONValue = boolean | string | number | null | undefined | JSONArray | JSONObject; | ||
| export type JSONArray = JSONValue[]; | ||
| export interface JSONObject { | ||
| [key: string]: JSONValue; | ||
| } | ||
| export type CompositeValue = JSONValue | JSExpression | JSFunction | CompositeArray | CompositeObject; | ||
| export type CompositeArray = CompositeValue[]; | ||
| export interface CompositeObject { | ||
| [key: string]: CompositeValue; | ||
| } |
| export {}; | ||
| //# sourceMappingURL=value-type.js.map |
| {"version":3,"file":"value-type.js","sourceRoot":"","sources":["value-type.ts"],"names":[],"mappings":""} |
24263
-25.71%50
-29.58%703
-24.33%