-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllms-code.txt
More file actions
358 lines (321 loc) · 11.2 KB
/
llms-code.txt
File metadata and controls
358 lines (321 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
// packages/api/src/api-services.ts
@mixcore/api implementation:
<<<CONTENT>>>
import type { ApiServiceConfig } from '@mixcore/shared';
import type { ApiResult, RestApiResult } from '@mixcore/shared';
export type { ApiResult, RestApiResult };
/**
* ApiService
* Framework-agnostic, TypeScript-native API client for Mixcore
*
* @remarks
* Refactored from legacy AngularJS service. All SPA dependencies removed.
* Configuration is injected via constructor.
*/
export type ApiServiceHook = {
onRequest?: (req: RequestInit & { url: string }) => void | Promise<void>;
onResponse?: (res: Response, req: RequestInit & { url: string }) => void | Promise<void>;
};
export class ApiService implements ApiService {
private config: ApiServiceConfig;
private hooks: ApiServiceHook[] = [];
constructor(config: ApiServiceConfig) {
this.config = config;
}
/**
* Register a request/response hook
*/
use(hook: ApiServiceHook) {
this.hooks.push(hook);
}
/**
* Generic GET request (returns ApiResult)
*/
async get(endpoint: string, params?: Record<string, any>): Promise<ApiResult> {
const url = new URL(endpoint, this.config.apiBaseUrl);
if (params) {
Object.entries(params).forEach(([k, v]) => url.searchParams.append(k, String(v)));
}
const req: RequestInit & { url: string } = {
url: url.toString(),
headers: this.config.apiKey ? { 'Authorization': `Bearer ${this.config.apiKey}` } : undefined,
};
for (const hook of this.hooks) if (hook.onRequest) await hook.onRequest(req);
try {
const res = await fetch(req.url, req);
for (const hook of this.hooks) if (hook.onResponse) await hook.onResponse(res, req);
const data = await res.json().catch(() => undefined);
if (!res.ok) {
return { isSucceed: false, data, errors: [res.statusText], status: res.status };
}
return { isSucceed: true, data, status: res.status };
} catch (err) {
return { isSucceed: false, errors: [(err as Error).message] };
}
}
/**
* Generic POST request (returns ApiResult, supports JSON or FormData)
*/
async post(endpoint: string, data: any, options?: { isFormData?: boolean }): Promise<ApiResult> {
const url = new URL(endpoint, this.config.apiBaseUrl);
let body: any = data;
let headers: Record<string, string> = {};
if (options?.isFormData) {
// Let browser set Content-Type for FormData
body = data;
} else {
body = JSON.stringify(data);
headers['Content-Type'] = 'application/json';
}
if (this.config.apiKey) headers['Authorization'] = `Bearer ${this.config.apiKey}`;
const req: RequestInit & { url: string } = {
url: url.toString(),
method: 'POST',
headers,
body,
};
for (const hook of this.hooks) if (hook.onRequest) await hook.onRequest(req);
const res = await fetch(req.url, req);
for (const hook of this.hooks) if (hook.onResponse) await hook.onResponse(res, req);
const respData = await res.json().catch(() => undefined);
if (!res.ok) {
return { isSucceed: false, data: respData, errors: [res.statusText], status: res.status };
}
return { isSucceed: true, data: respData, status: res.status };
}
/**
* Generic DELETE request (returns ApiResult)
*/
async delete(endpoint: string): Promise<ApiResult> {
const url = new URL(endpoint, this.config.apiBaseUrl);
const req: RequestInit & { url: string } = {
url: url.toString(),
method: 'DELETE',
headers: this.config.apiKey ? { 'Authorization': `Bearer ${this.config.apiKey}` } : undefined,
};
for (const hook of this.hooks) if (hook.onRequest) await hook.onRequest(req);
try {
const res = await fetch(req.url, req);
for (const hook of this.hooks) if (hook.onResponse) await hook.onResponse(res, req);
const data = await res.json().catch(() => undefined);
if (!res.ok) {
return { isSucceed: false, data, errors: [res.statusText], status: res.status };
}
return { isSucceed: true, data, status: res.status };
} catch (err) {
return { isSucceed: false, errors: [(err as Error).message] };
}
}
}
<<<END>>>
// packages/base/src/base-service.ts
@mixcore/base implementation:
<<<CONTENT>>>
/**
* BaseService
* Abstract base class for Mixcore SDK services
*
* @remarks
* Refactored from legacy AngularJS service. All SPA dependencies removed.
* Configuration is injected via constructor.
*/
export interface BaseServiceConfig {
apiBaseUrl: string;
apiKey?: string;
[key: string]: any;
}
export abstract class BaseService {
protected config: BaseServiceConfig;
constructor(config: BaseServiceConfig) {
this.config = config;
}
/**
* Abstract method for error handling
* @param error - Error object
*/
abstract handleError(error: any): void;
}
<<<END>>>
// packages/config/src/configuration-services.ts
@mixcore/config implementation:
<<<CONTENT>>>
import { ApiService, ApiServiceConfig } from '@mixcore/shared';
/**
* ConfigurationServices
* TypeScript-native, framework-agnostic service for configuration management.
* Migrated and refactored from legacy AngularJS ConfigurationService.
*/
export interface ConfigurationUpload {
file: File;
folder?: string;
title?: string;
description?: string;
}
export class ConfigurationServices {
private api: ApiService;
private readonly prefixUrl: string = '/configuration';
constructor(api: ApiService) {
this.api = api;
}
/**
* Uploads a configuration file.
* @param configurationFile - The configuration file and metadata
* @returns API result
*/
async uploadConfiguration(configurationFile: ConfigurationUpload): Promise<any> {
if (!configurationFile.file) {
throw new Error('No file provided');
}
const formData = new FormData();
formData.append(configurationFile.file.name, configurationFile.file);
if (configurationFile.folder) formData.append('fileFolder', configurationFile.folder);
if (configurationFile.title) formData.append('title', configurationFile.title);
if (configurationFile.description) formData.append('description', configurationFile.description);
const req = {
url: this.prefixUrl + '/upload',
method: 'POST',
body: formData,
headers: {},
};
// Use fetch directly for FormData, bypassing ApiService's JSON logic
const url = new URL(req.url, this.api['config'].apiBaseUrl).toString();
const res = await fetch(url, {
method: 'POST',
body: formData,
// Let browser set Content-Type for FormData
headers: this.api['config'].apiKey ? { 'Authorization': `Bearer ${this.api['config'].apiKey}` } : undefined,
});
if (!res.ok) throw new Error(`Upload failed: ${res.status} ${res.statusText}`);
return res.json();
}
}
<<<END>>>
// packages/database/src/mix-database-data-rest-portal-service.ts
@mixcore/database implementation:
<<<CONTENT>>>
import type { ApiService } from '@mixcore/api';
import type { ApiResult } from '@mixcore/api';
/**
* MixDatabaseDataRestPortalService
* TypeScript-native, framework-agnostic service for Mixcore database data portal operations.
* Migrated and refactored from legacy AngularJS RestMixDatabaseDataPortalService.
*/
export class MixDatabaseDataRestPortalService {
private api: ApiService;
private readonly prefixUrl: string = '/mix-database-data/portal';
constructor(api: ApiService) {
this.api = api;
}
/**
* Saves additional data for a Mixcore database. Returns ApiResult.
*/
async saveAdditionalData(objData: any): Promise<ApiResult> {
const endpoint = `${this.prefixUrl}/save-additional-data`;
return this.api.post(endpoint, objData);
}
/**
* Gets additional data for a Mixcore database. Returns ApiResult.
*/
async getAdditionalData(data?: any): Promise<ApiResult> {
let endpoint = `${this.prefixUrl}/additional-data`;
if (data && typeof data === 'object' && Object.keys(data).length > 0) {
const params = new URLSearchParams(data).toString();
endpoint += `?${params}`;
}
return this.api.get(endpoint);
}
/**
* Initializes data for a Mixcore database by name. Returns ApiResult.
*/
async initData(mixDatabaseName: string): Promise<ApiResult> {
if (!mixDatabaseName) {
return { isSucceed: false, errors: ['Missing mixDatabaseName'] };
}
const endpoint = `${this.prefixUrl}/init/${mixDatabaseName}`;
return this.api.get(endpoint);
}
/**
* Exports data for a Mixcore database. Returns ApiResult.
*/
async export(objData?: any): Promise<ApiResult> {
let endpoint = `${this.prefixUrl}/export`;
if (objData && typeof objData === 'object' && Object.keys(objData).length > 0) {
const params = new URLSearchParams(objData).toString();
endpoint += `?${params}`;
}
return this.api.get(endpoint);
}
/**
* Imports data for a Mixcore database. Returns ApiResult.
*/
async import(mixDatabaseName: string, file: File): Promise<ApiResult> {
if (!mixDatabaseName) {
return { isSucceed: false, errors: ['Missing mixDatabaseName'] };
}
if (!file) {
return { isSucceed: false, errors: ['Missing file'] };
}
const endpoint = `${this.prefixUrl}/import-data/${mixDatabaseName}`;
if (!mixDatabaseName) {
return { isSucceed: false, errors: ['Missing mixDatabaseName'] };
}
if (!file) {
return { isSucceed: false, errors: ['Missing file'] };
}
const formData = new FormData();
formData.append('file', file);
return this.api.post(endpoint, formData, { isFormData: true });
}
/**
* Migrates data for a Mixcore database. Returns ApiResult.
*/
async migrate(mixDatabaseId: string): Promise<ApiResult> {
if (!mixDatabaseId) {
return { isSucceed: false, errors: ['Missing mixDatabaseId'] };
}
const endpoint = `${this.prefixUrl}/migrate-data/${mixDatabaseId}`;
return this.api.get(endpoint);
}
}
<<<END>>>
// packages/file/src/file-services.ts
@mixcore/file implementation:
<<<CONTENT>>>
import type { ApiService, FileServices } from '@mixcore/shared';
export class FileServicesPortal implements FileServices {
private api: ApiService;
private prefixUrl = '/file/';
constructor(api: ApiService) {
this.api = api;
}
async getFile(folder: string, filename: string) {
const url = `${this.prefixUrl}details?folder=${encodeURIComponent(folder)}&filename=${encodeURIComponent(filename)}`;
return this.api.get(url);
}
async initFile(type: string) {
return this.api.get(`${this.prefixUrl}init/${encodeURIComponent(type)}`);
}
async getFiles(request: any) {
return this.api.post(`${this.prefixUrl}list`, request);
}
async removeFile(fullPath: string) {
return this.api.get(`${this.prefixUrl}delete/?fullPath=${encodeURIComponent(fullPath)}`);
}
async saveFile(file: any) {
return this.api.post(`${this.prefixUrl}save`, file);
}
async uploadFile(file: File, folder: string) {
const url = `${this.prefixUrl}upload-file`;
const formData = new FormData();
formData.append('folder', folder);
formData.append('file', file);
// Use fetch directly for multipart/form-data
const res = await fetch(url, {
method: 'POST',
body: formData,
});
if (!res.ok) throw new Error(`UPLOAD ${url}: ${res.status} ${res.statusText}`);
return res.json();
}
}
<<<END>>>