@lovrabet/sdk 1.1.6 → 1.1.7-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ export { AuthManager } from './auth-manager';
2
+ export { OpenApiAuth } from './openapi-auth';
3
+ export type { AuthHeaders, OpenApiAuthConfig } from '../types';
@@ -73,7 +73,7 @@ export declare class LovrabetClient implements ILovrabetClient {
73
73
  * 2. 支持按索引快速获取第一个模型,便于演示和快速开发
74
74
  * 3. 作为 models.xxx 语法糖的底层实现
75
75
  */
76
- getModel(indexOrName: number | string): import("../models/base-model").BaseModel;
76
+ getModel(indexOrName: number | string): import("../types").BaseModelMethods;
77
77
  /**
78
78
  * 检查当前是否为 OpenAPI 模式
79
79
  * 为什么提供这个方法:
@@ -18,9 +18,9 @@ export declare class HttpClient {
18
18
  * 通用的fetch请求方法(用于PUT/DELETE等没有专门优化函数的方法)
19
19
  */
20
20
  private makeRequest;
21
- get<T = any>(url: string, params?: Record<string, any>, options?: RequestInit): Promise<T>;
22
- post<T = any>(url: string, data?: any, options?: RequestInit): Promise<T>;
23
- put<T = any>(url: string, data?: any, options?: RequestInit): Promise<T>;
24
- delete<T = any>(url: string, options?: RequestInit): Promise<T>;
25
- request<T = any>(method: 'GET' | 'POST' | 'PUT' | 'DELETE', url: string, data?: any, options?: RequestInit): Promise<T>;
21
+ get<T = any>(url: string, params?: Record<string, any>, options?: RequestInit, datasetCode?: string): Promise<T>;
22
+ post<T = any>(url: string, data?: any, options?: RequestInit, datasetCode?: string): Promise<T>;
23
+ put<T = any>(url: string, data?: any, options?: RequestInit, datasetCode?: string): Promise<T>;
24
+ delete<T = any>(url: string, options?: RequestInit, datasetCode?: string): Promise<T>;
25
+ request<T = any>(method: 'GET' | 'POST' | 'PUT' | 'DELETE', url: string, data?: any, options?: RequestInit, datasetCode?: string): Promise<T>;
26
26
  }
@@ -0,0 +1,26 @@
1
+ import type { BaseModelMethods, ListParams, ListResponse, ModelConfig, ClientConfig } from '../types';
2
+ import type { HttpClient } from '../http/http-client';
3
+ /**
4
+ * 抽象基础模型类
5
+ * 定义所有模型的通用接口和基础实现
6
+ */
7
+ export declare abstract class AbstractBaseModel implements BaseModelMethods {
8
+ protected modelName: string;
9
+ protected httpClient: HttpClient;
10
+ protected config: ModelConfig;
11
+ protected appCode: string;
12
+ protected globalConfig: ClientConfig;
13
+ constructor(modelName: string, httpClient: HttpClient, globalConfig: ClientConfig);
14
+ private resolveModelConfig;
15
+ protected abstract getApiPath(method: string): string;
16
+ protected abstract buildRequestBody(method: string, data: any): any;
17
+ getList<T = any>(params?: ListParams): Promise<ListResponse<T>>;
18
+ getOne<T = any>(id: string | number): Promise<T>;
19
+ create<T = any>(data: Record<string, any>): Promise<T>;
20
+ update<T = any>(id: string | number, data: Record<string, any>): Promise<T>;
21
+ delete(id: string | number): Promise<void>;
22
+ getDatasetList<T = any>(): Promise<T[]>;
23
+ private isOpenApiMode;
24
+ getConfig(): ModelConfig;
25
+ getModelName(): string;
26
+ }
@@ -0,0 +1,6 @@
1
+ export { AbstractBaseModel } from './abstract-base-model';
2
+ export { OpenApiModel } from './openapi-model';
3
+ export { WebApiModel } from './webapi-model';
4
+ export { ModelFactory } from './model-factory';
5
+ export { ModelManager } from './model-manager';
6
+ export type { BaseModelMethods, ModelManager as IModelManager } from '../types';
@@ -0,0 +1,20 @@
1
+ import type { BaseModelMethods, ClientConfig } from '../types';
2
+ import type { HttpClient } from '../http/http-client';
3
+ /**
4
+ * 模型工厂类
5
+ * 根据配置决定创建 OpenAPI 或 WebAPI 模型实例
6
+ */
7
+ export declare class ModelFactory {
8
+ /**
9
+ * 创建模型实例
10
+ */
11
+ static createModel(modelName: string, httpClient: HttpClient, globalConfig: ClientConfig): BaseModelMethods;
12
+ /**
13
+ * 判断是否为 OpenAPI 模式
14
+ */
15
+ private static isOpenApiMode;
16
+ /**
17
+ * 获取当前模式名称(用于调试)
18
+ */
19
+ static getModeName(config: ClientConfig): 'OpenAPI' | 'WebAPI';
20
+ }
@@ -1,6 +1,5 @@
1
- import type { ModelManager as IModelManager, ClientConfig } from '../types';
1
+ import type { ModelManager as IModelManager, ClientConfig, BaseModelMethods } from '../types';
2
2
  import type { HttpClient } from '../http/http-client';
3
- import { BaseModel } from './base-model';
4
3
  export declare class ModelManager implements IModelManager {
5
4
  private httpClient;
6
5
  private config;
@@ -14,5 +13,5 @@ export declare class ModelManager implements IModelManager {
14
13
  datasetCode: string;
15
14
  }): void;
16
15
  list(): string[];
17
- get(indexOrName: number | string): BaseModel;
16
+ get(indexOrName: number | string): BaseModelMethods;
18
17
  }
@@ -0,0 +1,15 @@
1
+ import { AbstractBaseModel } from './abstract-base-model';
2
+ /**
3
+ * OpenAPI 模型实现
4
+ * 处理 OpenAPI 模式下的 URL 生成和请求体构建
5
+ */
6
+ export declare class OpenApiModel extends AbstractBaseModel {
7
+ /**
8
+ * OpenAPI 模式的 URL 生成策略
9
+ */
10
+ protected getApiPath(sdkMethod: string): string;
11
+ /**
12
+ * OpenAPI 模式的请求体构建策略
13
+ */
14
+ protected buildRequestBody(method: string, data: any): any;
15
+ }
@@ -0,0 +1,15 @@
1
+ import { AbstractBaseModel } from './abstract-base-model';
2
+ /**
3
+ * WebAPI 模型实现
4
+ * 处理 WebAPI 模式下的 URL 生成和请求体构建
5
+ */
6
+ export declare class WebApiModel extends AbstractBaseModel {
7
+ /**
8
+ * WebAPI 模式的 URL 生成策略
9
+ */
10
+ protected getApiPath(sdkMethod: string): string;
11
+ /**
12
+ * WebAPI 模式的请求体构建策略
13
+ */
14
+ protected buildRequestBody(method: string, data: any): any;
15
+ }
@@ -173,6 +173,13 @@ export interface BaseModelMethods {
173
173
  * @returns Promise<void>
174
174
  */
175
175
  delete(id: string | number): Promise<void>;
176
+ /**
177
+ * 获取数据集列表
178
+ * @template T 返回数据的类型
179
+ * @returns 返回数据集列表
180
+ * @description 获取当前应用下的所有数据集列表,主要用于 OpenAPI 模式
181
+ */
182
+ getDatasetList<T = any>(): Promise<T[]>;
176
183
  }
177
184
  /**
178
185
  * 模型管理器接口
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovrabet/sdk",
3
- "version": "1.1.6",
3
+ "version": "1.1.7-beta.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,6 +14,16 @@
14
14
  "type": "module",
15
15
  "scripts": {
16
16
  "build": "rm -rf dist && bun build index.ts --outdir=dist --target=browser --format=esm && javascript-obfuscator dist --output dist && npm run types",
17
+ "build:dev": "rm -rf dist && bun build index.ts --outdir=dist --target=browser --format=esm && npm run types",
18
+ "dev": "npm run build:dev",
19
+ "start": "npm run watch",
20
+ "watch": "npm run build:dev && npm run watch:files",
21
+ "watch:files": "chokidar \"src/**/*.ts\" \"index.ts\" -c \"npm run build:dev\"",
22
+ "test": "vitest",
23
+ "test:run": "vitest run",
24
+ "test:ui": "vitest --ui",
25
+ "test:coverage": "vitest run --coverage",
26
+ "test:watch": "vitest watch",
17
27
  "types": "npx tsc --emitDeclarationOnly --declaration --outDir dist index.ts",
18
28
  "beta-release": "bun run build && sh scripts/update-beta-version.sh && git push && git push origin --tag && bun publish",
19
29
  "release": "bun run build && bun pm version patch && git push && git push origin --tag && bun publish"
@@ -23,7 +33,11 @@
23
33
  ],
24
34
  "devDependencies": {
25
35
  "@types/bun": "latest",
26
- "javascript-obfuscator": "^4.1.1"
36
+ "javascript-obfuscator": "^4.1.1",
37
+ "chokidar-cli": "^3.0.0",
38
+ "vitest": "^2.1.8",
39
+ "@vitest/ui": "^2.1.8",
40
+ "c8": "^10.1.2"
27
41
  },
28
42
  "peerDependencies": {
29
43
  "typescript": "^5"
@@ -1,20 +0,0 @@
1
- import type { BaseModelMethods, ListParams, ListResponse, ClientConfig, ModelConfig } from '../types';
2
- import type { HttpClient } from '../http/http-client';
3
- export declare class BaseModel implements BaseModelMethods {
4
- private modelName;
5
- private httpClient;
6
- private config;
7
- private appCode;
8
- private globalConfig;
9
- constructor(modelName: string, httpClient: HttpClient, globalConfig: ClientConfig);
10
- private resolveModelConfig;
11
- private isOpenApiMode;
12
- private getApiPath;
13
- getList<T = any>(params?: ListParams): Promise<ListResponse<T>>;
14
- getOne<T = any>(id: string | number): Promise<T>;
15
- create<T = any>(data: Record<string, any>): Promise<T>;
16
- update<T = any>(id: string | number, data: Record<string, any>): Promise<T>;
17
- delete(id: string | number): Promise<void>;
18
- getConfig(): ModelConfig;
19
- getModelName(): string;
20
- }