@mesh-sync/worker-backend-client 1.0.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.
- package/README.md +349 -0
- package/dist/client.d.ts +106 -0
- package/dist/client.js +151 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/types.d.ts +166 -0
- package/dist/types.js +17 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
# Worker Backend Client (TypeScript)
|
|
2
|
+
|
|
3
|
+
Auto-generated TypeScript client library for the Mesh-Sync worker-backend.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
### From npm (public registry)
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @mesh-sync/worker-backend-client
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### From GitHub Packages (Recommended for Private Access)
|
|
14
|
+
|
|
15
|
+
GitHub Packages provides package hosting with access control based on repository permissions.
|
|
16
|
+
|
|
17
|
+
**Prerequisites:**
|
|
18
|
+
- GitHub Personal Access Token (PAT) with `read:packages` scope
|
|
19
|
+
- Repository access (for private packages)
|
|
20
|
+
|
|
21
|
+
**Installation Steps:**
|
|
22
|
+
|
|
23
|
+
1. Create or update your `.npmrc` file in your project root:
|
|
24
|
+
|
|
25
|
+
```ini
|
|
26
|
+
@mesh-sync:registry=https://npm.pkg.github.com
|
|
27
|
+
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
2. Set your GitHub token as an environment variable:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
export GITHUB_TOKEN=your_github_personal_access_token
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
3. Install the package:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install @mesh-sync/worker-backend-client
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Access Control:** Only users with read access to the repository can install private packages from GitHub Packages.
|
|
43
|
+
|
|
44
|
+
**Generate GitHub PAT:**
|
|
45
|
+
1. Go to GitHub Settings → Developer settings → Personal access tokens → Tokens (classic)
|
|
46
|
+
2. Generate new token with `read:packages` scope
|
|
47
|
+
3. Copy the token and use it as `GITHUB_TOKEN`
|
|
48
|
+
|
|
49
|
+
### From a private npm registry
|
|
50
|
+
|
|
51
|
+
If you're using a private npm registry, configure your `.npmrc`:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
@mesh-sync:registry=https://your-registry.example.com
|
|
55
|
+
//your-registry.example.com/:_authToken=${NPM_TOKEN}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
### Basic Example
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { WorkerClient } from '@mesh-sync/worker-backend-client';
|
|
64
|
+
|
|
65
|
+
const client = new WorkerClient({
|
|
66
|
+
baseUrl: 'http://localhost:3000',
|
|
67
|
+
apiKey: process.env.API_KEY, // Optional
|
|
68
|
+
timeout: 30000 // Optional, default 30s
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Type-safe method call
|
|
72
|
+
const job = await client.fileDownloadRequest({
|
|
73
|
+
url: 'https://example.com/file.pdf',
|
|
74
|
+
destination: '/downloads/file.pdf'
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
console.log(`Job created: ${job.jobId}`);
|
|
78
|
+
|
|
79
|
+
// Check job status
|
|
80
|
+
const status = await client.getJobStatus(job.jobId);
|
|
81
|
+
console.log(`Job state: ${status.state}`);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Using Message Type Constants
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { WorkerClient, MessageTypes } from '@mesh-sync/worker-backend-client';
|
|
88
|
+
|
|
89
|
+
const client = new WorkerClient({
|
|
90
|
+
baseUrl: 'http://localhost:3000'
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Dynamic message type
|
|
94
|
+
await client.sendToQueue(MessageTypes.FILE_DOWNLOAD_REQUEST, {
|
|
95
|
+
url: 'https://example.com/file.pdf',
|
|
96
|
+
destination: '/downloads/file.pdf'
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Available Message Types
|
|
101
|
+
|
|
102
|
+
### file-download-request
|
|
103
|
+
|
|
104
|
+
**Description:** Handles file download requests.
|
|
105
|
+
|
|
106
|
+
**Method:** `client.fileDownloadRequest(data)`
|
|
107
|
+
|
|
108
|
+
**Payload Type:** `FileDownloadRequestMessage`
|
|
109
|
+
|
|
110
|
+
**Fields:**
|
|
111
|
+
- `modelId` (string) [✓]: The unique identifier for the model to be downloaded.
|
|
112
|
+
- `storageLocation` (object) [✓]: The storage location of the model.
|
|
113
|
+
|
|
114
|
+
### model-discovery-folder-processed-event
|
|
115
|
+
|
|
116
|
+
**Description:** Handles model discovery folder processed events.
|
|
117
|
+
|
|
118
|
+
**Method:** `client.modelDiscoveryFolderProcessedEvent(data)`
|
|
119
|
+
|
|
120
|
+
**Payload Type:** `ModelDiscoveryFolderProcessedEventMessage`
|
|
121
|
+
|
|
122
|
+
**Fields:**
|
|
123
|
+
- `connectionId` (string) [✓]: The unique identifier for the connection.
|
|
124
|
+
- `folderPath` (string) [✓]: The path to the processed folder.
|
|
125
|
+
- `discoveredFiles` (array) [✓]: A list of files discovered in the folder.
|
|
126
|
+
- `folderSignature` (object) [✗]: A signature representing the state of the folder.
|
|
127
|
+
- `processedAt` (string) [✓]: The timestamp when the folder was processed.
|
|
128
|
+
- `statistics` (object) [✓]: Statistics about the processed folder.
|
|
129
|
+
|
|
130
|
+
### model-discovery-scan-found-event
|
|
131
|
+
|
|
132
|
+
**Description:** Handles model discovery scan found events.
|
|
133
|
+
|
|
134
|
+
**Method:** `client.modelDiscoveryScanFoundEvent(data)`
|
|
135
|
+
|
|
136
|
+
**Payload Type:** `ModelDiscoveryScanFoundEventMessage`
|
|
137
|
+
|
|
138
|
+
**Fields:**
|
|
139
|
+
- `modelId` (string) [✓]: The unique identifier for the model.
|
|
140
|
+
- `name` (string) [✓]: The name of the model.
|
|
141
|
+
- `fileName` (string) [✓]: The name of the model file.
|
|
142
|
+
- `description` (string) [✓]: A description of the model.
|
|
143
|
+
- `fileTypes` (array) [✓]: An array of file types associated with the model.
|
|
144
|
+
- `size` (number) [✓]: The size of the model file in bytes.
|
|
145
|
+
- `storageLocation` (object) [✓]: The storage location of the model.
|
|
146
|
+
- `providerType` (string) [✓]: The type of the storage provider.
|
|
147
|
+
- `metadata` (object) [✓]: A flexible object for additional metadata.
|
|
148
|
+
|
|
149
|
+
### model-discovery-scan-progress-event
|
|
150
|
+
|
|
151
|
+
**Description:** Handles model discovery scan progress events.
|
|
152
|
+
|
|
153
|
+
**Method:** `client.modelDiscoveryScanProgressEvent(data)`
|
|
154
|
+
|
|
155
|
+
**Payload Type:** `ModelDiscoveryScanProgressEventMessage`
|
|
156
|
+
|
|
157
|
+
**Fields:**
|
|
158
|
+
- `payload` (object) [✓]: Contains the discovery scan progress details.
|
|
159
|
+
|
|
160
|
+
### model-discovery-scan-request
|
|
161
|
+
|
|
162
|
+
**Description:** Handles model discovery scan requests events.
|
|
163
|
+
|
|
164
|
+
**Method:** `client.modelDiscoveryScanRequest(data)`
|
|
165
|
+
|
|
166
|
+
**Payload Type:** `ModelDiscoveryScanRequestMessage`
|
|
167
|
+
|
|
168
|
+
**Fields:**
|
|
169
|
+
- `libraryId` (string) [✓]: The ID of the library to scan.
|
|
170
|
+
|
|
171
|
+
### model-metadata-generation-completed
|
|
172
|
+
|
|
173
|
+
**Description:** Handles model metadata generation completed.
|
|
174
|
+
|
|
175
|
+
**Method:** `client.modelMetadataGenerationCompleted(data)`
|
|
176
|
+
|
|
177
|
+
**Payload Type:** `ModelMetadataGenerationCompletedMessage`
|
|
178
|
+
|
|
179
|
+
**Fields:**
|
|
180
|
+
- `modelId` (string) [✗]: The unique identifier for the model.
|
|
181
|
+
- `metadata` (object) [✓]: The enriched metadata for the model.
|
|
182
|
+
|
|
183
|
+
### model-metadata-generation-request
|
|
184
|
+
|
|
185
|
+
**Description:** Handles model metadata generation requests.
|
|
186
|
+
|
|
187
|
+
**Method:** `client.modelMetadataGenerationRequest(data)`
|
|
188
|
+
|
|
189
|
+
**Payload Type:** `ModelMetadataGenerationRequestMessage`
|
|
190
|
+
|
|
191
|
+
**Fields:**
|
|
192
|
+
- `modelId` (string) [✓]: The unique identifier for the model.
|
|
193
|
+
- `storageConnectionId` (string) [✓]: The ID of the storage connection.
|
|
194
|
+
- `filePath` (string) [✓]: The path to the model file.
|
|
195
|
+
- `fileName` (string) [✓]: The name of the model file.
|
|
196
|
+
- `fileSize` (number) [✓]: The size of the model file in bytes.
|
|
197
|
+
- `fileLastModified` (string) [✓]: The last modified date of the model file.
|
|
198
|
+
- `storageProviderType` (string) [✓]: The type of the storage provider.
|
|
199
|
+
- `modelThumbnailUrl` (string) [✗]: The URL of the model thumbnail.
|
|
200
|
+
- `metamodel` (object) [✗]: The metamodel of the model.
|
|
201
|
+
|
|
202
|
+
### model-metamodel-detection-found
|
|
203
|
+
|
|
204
|
+
**Description:** Handles model metamodel detection found.
|
|
205
|
+
|
|
206
|
+
**Method:** `client.modelMetamodelDetectionFound(data)`
|
|
207
|
+
|
|
208
|
+
**Payload Type:** `ModelMetamodelDetectionFoundMessage`
|
|
209
|
+
|
|
210
|
+
**Fields:**
|
|
211
|
+
- `suggestions` (array) [✗]: List of metamodel suggestions.
|
|
212
|
+
|
|
213
|
+
### model-metamodel-detection-request
|
|
214
|
+
|
|
215
|
+
**Description:** Handles model metamodel detection requests.
|
|
216
|
+
|
|
217
|
+
**Method:** `client.modelMetamodelDetectionRequest(data)`
|
|
218
|
+
|
|
219
|
+
**Payload Type:** `ModelMetamodelDetectionRequestMessage`
|
|
220
|
+
|
|
221
|
+
**Fields:**
|
|
222
|
+
- `connectionId` (string) [✗]: The unique identifier for the storage connection.
|
|
223
|
+
- `folderPath` (string) [✗]: The path to the folder that was processed.
|
|
224
|
+
- `discoveredFiles` (array) [✗]: A list of files discovered in the folder.
|
|
225
|
+
- `folderSignature` (object) [✓]: A signature representing the state of the folder.
|
|
226
|
+
- `processedAt` (string) [✗]: The timestamp when the folder was processed.
|
|
227
|
+
- `statistics` (object) [✓]: Statistics about the processed folder.
|
|
228
|
+
|
|
229
|
+
### thumbnail-generation-completed
|
|
230
|
+
|
|
231
|
+
**Description:** Handles thumbnail generation completed.
|
|
232
|
+
|
|
233
|
+
**Method:** `client.thumbnailGenerationCompleted(data)`
|
|
234
|
+
|
|
235
|
+
**Payload Type:** `ThumbnailGenerationCompletedMessage`
|
|
236
|
+
|
|
237
|
+
**Fields:**
|
|
238
|
+
- `originalJobId` (string) [✓]: The ID of the original job that requested the thumbnail generation.
|
|
239
|
+
- `modelId` (string) [✓]: The ID of the model that the thumbnail was generated for.
|
|
240
|
+
- `status` (string) [✓]: The status of the thumbnail generation.
|
|
241
|
+
- `thumbnailPath` (string) [✗]: The path to the generated thumbnail.
|
|
242
|
+
- `errorMessage` (string) [✗]: An error message if the thumbnail generation failed.
|
|
243
|
+
- `storageLocation` (object) [✓]: The storage location of the model.
|
|
244
|
+
|
|
245
|
+
### thumbnail-generation-request
|
|
246
|
+
|
|
247
|
+
**Description:** Handles thumbnail generation requests.
|
|
248
|
+
|
|
249
|
+
**Method:** `client.thumbnailGenerationRequest(data)`
|
|
250
|
+
|
|
251
|
+
**Payload Type:** `ThumbnailGenerationRequestMessage`
|
|
252
|
+
|
|
253
|
+
**Fields:**
|
|
254
|
+
- `modelId` (string) [✓]: The unique identifier for the model requiring a thumbnail.
|
|
255
|
+
- `ownerId` (string) [✓]: The identifier of the user who owns the entity.
|
|
256
|
+
- `storageLocation` (object) [✓]: The storage location of the model.
|
|
257
|
+
- `previewType` (string) [✓]: The type of preview to generate, e.g., 'default', 'static', 'glb'.
|
|
258
|
+
|
|
259
|
+
## Configuration
|
|
260
|
+
|
|
261
|
+
### Environment Variables
|
|
262
|
+
|
|
263
|
+
- `WORKER_BACKEND_URL`: Base URL of the worker backend
|
|
264
|
+
- `WORKER_BACKEND_API_KEY`: Optional API key for authentication
|
|
265
|
+
- `GITHUB_TOKEN`: GitHub personal access token (for GitHub Packages installation)
|
|
266
|
+
- `NPM_TOKEN`: npm token (for private registry installation)
|
|
267
|
+
|
|
268
|
+
### Worker Client Options
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
interface WorkerClientConfig {
|
|
272
|
+
baseUrl: string; // Required: Worker backend URL
|
|
273
|
+
apiKey?: string; // Optional: API key for authentication
|
|
274
|
+
timeout?: number; // Optional: Request timeout in ms (default: 30000)
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## API Reference
|
|
279
|
+
|
|
280
|
+
### `WorkerClient`
|
|
281
|
+
|
|
282
|
+
#### Constructor
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
new WorkerClient(config: WorkerClientConfig)
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
#### Methods
|
|
289
|
+
|
|
290
|
+
- `sendToQueue(messageType: MessageType, payload: any): Promise<JobResponse>`
|
|
291
|
+
- Send a job to the queue with the specified message type
|
|
292
|
+
|
|
293
|
+
- `getJobStatus(jobId: string): Promise<JobStatus>`
|
|
294
|
+
- Get the current status of a job
|
|
295
|
+
|
|
296
|
+
- `fileDownloadRequest(data: FileDownloadRequestMessage): Promise<JobResponse>`
|
|
297
|
+
- Handles file download requests.
|
|
298
|
+
- `modelDiscoveryFolderProcessedEvent(data: ModelDiscoveryFolderProcessedEventMessage): Promise<JobResponse>`
|
|
299
|
+
- Handles model discovery folder processed events.
|
|
300
|
+
- `modelDiscoveryScanFoundEvent(data: ModelDiscoveryScanFoundEventMessage): Promise<JobResponse>`
|
|
301
|
+
- Handles model discovery scan found events.
|
|
302
|
+
- `modelDiscoveryScanProgressEvent(data: ModelDiscoveryScanProgressEventMessage): Promise<JobResponse>`
|
|
303
|
+
- Handles model discovery scan progress events.
|
|
304
|
+
- `modelDiscoveryScanRequest(data: ModelDiscoveryScanRequestMessage): Promise<JobResponse>`
|
|
305
|
+
- Handles model discovery scan requests events.
|
|
306
|
+
- `modelMetadataGenerationCompleted(data: ModelMetadataGenerationCompletedMessage): Promise<JobResponse>`
|
|
307
|
+
- Handles model metadata generation completed.
|
|
308
|
+
- `modelMetadataGenerationRequest(data: ModelMetadataGenerationRequestMessage): Promise<JobResponse>`
|
|
309
|
+
- Handles model metadata generation requests.
|
|
310
|
+
- `modelMetamodelDetectionFound(data: ModelMetamodelDetectionFoundMessage): Promise<JobResponse>`
|
|
311
|
+
- Handles model metamodel detection found.
|
|
312
|
+
- `modelMetamodelDetectionRequest(data: ModelMetamodelDetectionRequestMessage): Promise<JobResponse>`
|
|
313
|
+
- Handles model metamodel detection requests.
|
|
314
|
+
- `thumbnailGenerationCompleted(data: ThumbnailGenerationCompletedMessage): Promise<JobResponse>`
|
|
315
|
+
- Handles thumbnail generation completed.
|
|
316
|
+
- `thumbnailGenerationRequest(data: ThumbnailGenerationRequestMessage): Promise<JobResponse>`
|
|
317
|
+
- Handles thumbnail generation requests.
|
|
318
|
+
|
|
319
|
+
### Response Types
|
|
320
|
+
|
|
321
|
+
#### `JobResponse`
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
interface JobResponse {
|
|
325
|
+
success: boolean;
|
|
326
|
+
jobId: string;
|
|
327
|
+
messageName: string;
|
|
328
|
+
queue: string;
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
#### `JobStatus`
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
interface JobStatus {
|
|
336
|
+
jobId: string;
|
|
337
|
+
name: string;
|
|
338
|
+
queue: string;
|
|
339
|
+
state: 'waiting' | 'active' | 'completed' | 'failed' | 'delayed';
|
|
340
|
+
data: any;
|
|
341
|
+
returnvalue?: any;
|
|
342
|
+
progress?: number;
|
|
343
|
+
timestamp: number;
|
|
344
|
+
}
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
## License
|
|
348
|
+
|
|
349
|
+
ISC
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as types from './types.js';
|
|
2
|
+
export interface WorkerClientConfig {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface JobResponse {
|
|
8
|
+
success: boolean;
|
|
9
|
+
jobId: string;
|
|
10
|
+
messageName: string;
|
|
11
|
+
queue: string;
|
|
12
|
+
}
|
|
13
|
+
export interface JobStatus {
|
|
14
|
+
jobId: string;
|
|
15
|
+
name: string;
|
|
16
|
+
queue: string;
|
|
17
|
+
state: 'waiting' | 'active' | 'completed' | 'failed' | 'delayed';
|
|
18
|
+
data: any;
|
|
19
|
+
returnvalue?: any;
|
|
20
|
+
progress?: number;
|
|
21
|
+
timestamp: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* HTTP-based client for worker-backend
|
|
25
|
+
* Provides methods to enqueue jobs and check job status
|
|
26
|
+
*/
|
|
27
|
+
export declare class WorkerClient {
|
|
28
|
+
private baseUrl;
|
|
29
|
+
private apiKey?;
|
|
30
|
+
private timeout;
|
|
31
|
+
constructor(config: WorkerClientConfig);
|
|
32
|
+
/**
|
|
33
|
+
* Send a job to the queue
|
|
34
|
+
*/
|
|
35
|
+
sendToQueue(messageType: types.MessageType, payload: any): Promise<JobResponse>;
|
|
36
|
+
/**
|
|
37
|
+
* Get job status by job ID
|
|
38
|
+
*/
|
|
39
|
+
getJobStatus(jobId: string): Promise<JobStatus>;
|
|
40
|
+
/**
|
|
41
|
+
* Handles file download requests.
|
|
42
|
+
* @param data - The message payload
|
|
43
|
+
* @returns Job response with job ID
|
|
44
|
+
*/
|
|
45
|
+
fileDownloadRequest(data: types.FileDownloadRequestMessage): Promise<JobResponse>;
|
|
46
|
+
/**
|
|
47
|
+
* Handles model discovery folder processed events.
|
|
48
|
+
* @param data - The message payload
|
|
49
|
+
* @returns Job response with job ID
|
|
50
|
+
*/
|
|
51
|
+
modelDiscoveryFolderProcessedEvent(data: types.ModelDiscoveryFolderProcessedEventMessage): Promise<JobResponse>;
|
|
52
|
+
/**
|
|
53
|
+
* Handles model discovery scan found events.
|
|
54
|
+
* @param data - The message payload
|
|
55
|
+
* @returns Job response with job ID
|
|
56
|
+
*/
|
|
57
|
+
modelDiscoveryScanFoundEvent(data: types.ModelDiscoveryScanFoundEventMessage): Promise<JobResponse>;
|
|
58
|
+
/**
|
|
59
|
+
* Handles model discovery scan progress events.
|
|
60
|
+
* @param data - The message payload
|
|
61
|
+
* @returns Job response with job ID
|
|
62
|
+
*/
|
|
63
|
+
modelDiscoveryScanProgressEvent(data: types.ModelDiscoveryScanProgressEventMessage): Promise<JobResponse>;
|
|
64
|
+
/**
|
|
65
|
+
* Handles model discovery scan requests events.
|
|
66
|
+
* @param data - The message payload
|
|
67
|
+
* @returns Job response with job ID
|
|
68
|
+
*/
|
|
69
|
+
modelDiscoveryScanRequest(data: types.ModelDiscoveryScanRequestMessage): Promise<JobResponse>;
|
|
70
|
+
/**
|
|
71
|
+
* Handles model metadata generation completed.
|
|
72
|
+
* @param data - The message payload
|
|
73
|
+
* @returns Job response with job ID
|
|
74
|
+
*/
|
|
75
|
+
modelMetadataGenerationCompleted(data: types.ModelMetadataGenerationCompletedMessage): Promise<JobResponse>;
|
|
76
|
+
/**
|
|
77
|
+
* Handles model metadata generation requests.
|
|
78
|
+
* @param data - The message payload
|
|
79
|
+
* @returns Job response with job ID
|
|
80
|
+
*/
|
|
81
|
+
modelMetadataGenerationRequest(data: types.ModelMetadataGenerationRequestMessage): Promise<JobResponse>;
|
|
82
|
+
/**
|
|
83
|
+
* Handles model metamodel detection found.
|
|
84
|
+
* @param data - The message payload
|
|
85
|
+
* @returns Job response with job ID
|
|
86
|
+
*/
|
|
87
|
+
modelMetamodelDetectionFound(data: types.ModelMetamodelDetectionFoundMessage): Promise<JobResponse>;
|
|
88
|
+
/**
|
|
89
|
+
* Handles model metamodel detection requests.
|
|
90
|
+
* @param data - The message payload
|
|
91
|
+
* @returns Job response with job ID
|
|
92
|
+
*/
|
|
93
|
+
modelMetamodelDetectionRequest(data: types.ModelMetamodelDetectionRequestMessage): Promise<JobResponse>;
|
|
94
|
+
/**
|
|
95
|
+
* Handles thumbnail generation completed.
|
|
96
|
+
* @param data - The message payload
|
|
97
|
+
* @returns Job response with job ID
|
|
98
|
+
*/
|
|
99
|
+
thumbnailGenerationCompleted(data: types.ThumbnailGenerationCompletedMessage): Promise<JobResponse>;
|
|
100
|
+
/**
|
|
101
|
+
* Handles thumbnail generation requests.
|
|
102
|
+
* @param data - The message payload
|
|
103
|
+
* @returns Job response with job ID
|
|
104
|
+
*/
|
|
105
|
+
thumbnailGenerationRequest(data: types.ThumbnailGenerationRequestMessage): Promise<JobResponse>;
|
|
106
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import * as types from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* HTTP-based client for worker-backend
|
|
4
|
+
* Provides methods to enqueue jobs and check job status
|
|
5
|
+
*/
|
|
6
|
+
export class WorkerClient {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, '');
|
|
9
|
+
this.apiKey = config.apiKey;
|
|
10
|
+
this.timeout = config.timeout || 30000;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Send a job to the queue
|
|
14
|
+
*/
|
|
15
|
+
async sendToQueue(messageType, payload) {
|
|
16
|
+
const url = `${this.baseUrl}/api/jobs/${messageType}`;
|
|
17
|
+
const headers = {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
};
|
|
20
|
+
if (this.apiKey) {
|
|
21
|
+
headers['Authorization'] = `Bearer ${this.apiKey}`;
|
|
22
|
+
}
|
|
23
|
+
const controller = new AbortController();
|
|
24
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
25
|
+
try {
|
|
26
|
+
const response = await fetch(url, {
|
|
27
|
+
method: 'POST',
|
|
28
|
+
headers,
|
|
29
|
+
body: JSON.stringify(payload),
|
|
30
|
+
signal: controller.signal,
|
|
31
|
+
});
|
|
32
|
+
clearTimeout(timeoutId);
|
|
33
|
+
if (!response.ok) {
|
|
34
|
+
const error = await response.json().catch(() => ({ error: response.statusText }));
|
|
35
|
+
throw new Error(`HTTP ${response.status}: ${error.error || error.message || response.statusText}`);
|
|
36
|
+
}
|
|
37
|
+
return await response.json();
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
clearTimeout(timeoutId);
|
|
41
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
42
|
+
throw new Error('Request timeout');
|
|
43
|
+
}
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get job status by job ID
|
|
49
|
+
*/
|
|
50
|
+
async getJobStatus(jobId) {
|
|
51
|
+
const url = `${this.baseUrl}/api/jobs/${jobId}`;
|
|
52
|
+
const headers = {};
|
|
53
|
+
if (this.apiKey) {
|
|
54
|
+
headers['Authorization'] = `Bearer ${this.apiKey}`;
|
|
55
|
+
}
|
|
56
|
+
const response = await fetch(url, { headers });
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
const error = await response.json().catch(() => ({ error: response.statusText }));
|
|
59
|
+
throw new Error(`HTTP ${response.status}: ${error.error || error.message || response.statusText}`);
|
|
60
|
+
}
|
|
61
|
+
return await response.json();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Handles file download requests.
|
|
65
|
+
* @param data - The message payload
|
|
66
|
+
* @returns Job response with job ID
|
|
67
|
+
*/
|
|
68
|
+
async fileDownloadRequest(data) {
|
|
69
|
+
return this.sendToQueue(types.MessageTypes.FILE_DOWNLOAD_REQUEST, data);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Handles model discovery folder processed events.
|
|
73
|
+
* @param data - The message payload
|
|
74
|
+
* @returns Job response with job ID
|
|
75
|
+
*/
|
|
76
|
+
async modelDiscoveryFolderProcessedEvent(data) {
|
|
77
|
+
return this.sendToQueue(types.MessageTypes.MODEL_DISCOVERY_FOLDER_PROCESSED_EVENT, data);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Handles model discovery scan found events.
|
|
81
|
+
* @param data - The message payload
|
|
82
|
+
* @returns Job response with job ID
|
|
83
|
+
*/
|
|
84
|
+
async modelDiscoveryScanFoundEvent(data) {
|
|
85
|
+
return this.sendToQueue(types.MessageTypes.MODEL_DISCOVERY_SCAN_FOUND_EVENT, data);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Handles model discovery scan progress events.
|
|
89
|
+
* @param data - The message payload
|
|
90
|
+
* @returns Job response with job ID
|
|
91
|
+
*/
|
|
92
|
+
async modelDiscoveryScanProgressEvent(data) {
|
|
93
|
+
return this.sendToQueue(types.MessageTypes.MODEL_DISCOVERY_SCAN_PROGRESS_EVENT, data);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Handles model discovery scan requests events.
|
|
97
|
+
* @param data - The message payload
|
|
98
|
+
* @returns Job response with job ID
|
|
99
|
+
*/
|
|
100
|
+
async modelDiscoveryScanRequest(data) {
|
|
101
|
+
return this.sendToQueue(types.MessageTypes.MODEL_DISCOVERY_SCAN_REQUEST, data);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Handles model metadata generation completed.
|
|
105
|
+
* @param data - The message payload
|
|
106
|
+
* @returns Job response with job ID
|
|
107
|
+
*/
|
|
108
|
+
async modelMetadataGenerationCompleted(data) {
|
|
109
|
+
return this.sendToQueue(types.MessageTypes.MODEL_METADATA_GENERATION_COMPLETED, data);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Handles model metadata generation requests.
|
|
113
|
+
* @param data - The message payload
|
|
114
|
+
* @returns Job response with job ID
|
|
115
|
+
*/
|
|
116
|
+
async modelMetadataGenerationRequest(data) {
|
|
117
|
+
return this.sendToQueue(types.MessageTypes.MODEL_METADATA_GENERATION_REQUEST, data);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Handles model metamodel detection found.
|
|
121
|
+
* @param data - The message payload
|
|
122
|
+
* @returns Job response with job ID
|
|
123
|
+
*/
|
|
124
|
+
async modelMetamodelDetectionFound(data) {
|
|
125
|
+
return this.sendToQueue(types.MessageTypes.MODEL_METAMODEL_DETECTION_FOUND, data);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Handles model metamodel detection requests.
|
|
129
|
+
* @param data - The message payload
|
|
130
|
+
* @returns Job response with job ID
|
|
131
|
+
*/
|
|
132
|
+
async modelMetamodelDetectionRequest(data) {
|
|
133
|
+
return this.sendToQueue(types.MessageTypes.MODEL_METAMODEL_DETECTION_REQUEST, data);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Handles thumbnail generation completed.
|
|
137
|
+
* @param data - The message payload
|
|
138
|
+
* @returns Job response with job ID
|
|
139
|
+
*/
|
|
140
|
+
async thumbnailGenerationCompleted(data) {
|
|
141
|
+
return this.sendToQueue(types.MessageTypes.THUMBNAIL_GENERATION_COMPLETED, data);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Handles thumbnail generation requests.
|
|
145
|
+
* @param data - The message payload
|
|
146
|
+
* @returns Job response with job ID
|
|
147
|
+
*/
|
|
148
|
+
async thumbnailGenerationRequest(data) {
|
|
149
|
+
return this.sendToQueue(types.MessageTypes.THUMBNAIL_GENERATION_REQUEST, data);
|
|
150
|
+
}
|
|
151
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message type constants
|
|
3
|
+
*/
|
|
4
|
+
export declare const MessageTypes: {
|
|
5
|
+
readonly FILE_DOWNLOAD_REQUEST: "file-download-request";
|
|
6
|
+
readonly MODEL_DISCOVERY_FOLDER_PROCESSED_EVENT: "model-discovery-folder-processed-event";
|
|
7
|
+
readonly MODEL_DISCOVERY_SCAN_FOUND_EVENT: "model-discovery-scan-found-event";
|
|
8
|
+
readonly MODEL_DISCOVERY_SCAN_PROGRESS_EVENT: "model-discovery-scan-progress-event";
|
|
9
|
+
readonly MODEL_DISCOVERY_SCAN_REQUEST: "model-discovery-scan-request";
|
|
10
|
+
readonly MODEL_METADATA_GENERATION_COMPLETED: "model-metadata-generation-completed";
|
|
11
|
+
readonly MODEL_METADATA_GENERATION_REQUEST: "model-metadata-generation-request";
|
|
12
|
+
readonly MODEL_METAMODEL_DETECTION_FOUND: "model-metamodel-detection-found";
|
|
13
|
+
readonly MODEL_METAMODEL_DETECTION_REQUEST: "model-metamodel-detection-request";
|
|
14
|
+
readonly THUMBNAIL_GENERATION_COMPLETED: "thumbnail-generation-completed";
|
|
15
|
+
readonly THUMBNAIL_GENERATION_REQUEST: "thumbnail-generation-request";
|
|
16
|
+
};
|
|
17
|
+
export type MessageType = typeof MessageTypes[keyof typeof MessageTypes];
|
|
18
|
+
/**
|
|
19
|
+
* Handles file download requests.
|
|
20
|
+
*/
|
|
21
|
+
export interface FileDownloadRequestMessage {
|
|
22
|
+
/** The unique identifier for the model to be downloaded. */
|
|
23
|
+
modelId: string;
|
|
24
|
+
/** The storage location of the model. */
|
|
25
|
+
storageLocation: Record<string, any>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Handles model discovery folder processed events.
|
|
29
|
+
*/
|
|
30
|
+
export interface ModelDiscoveryFolderProcessedEventMessage {
|
|
31
|
+
/** The unique identifier for the connection. */
|
|
32
|
+
connectionId: string;
|
|
33
|
+
/** The path to the processed folder. */
|
|
34
|
+
folderPath: string;
|
|
35
|
+
/** A list of files discovered in the folder. */
|
|
36
|
+
discoveredFiles: any[];
|
|
37
|
+
/** A signature representing the state of the folder. */
|
|
38
|
+
folderSignature?: Record<string, any>;
|
|
39
|
+
/** The timestamp when the folder was processed. */
|
|
40
|
+
processedAt: string;
|
|
41
|
+
/** Statistics about the processed folder. */
|
|
42
|
+
statistics: Record<string, any>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Handles model discovery scan found events.
|
|
46
|
+
*/
|
|
47
|
+
export interface ModelDiscoveryScanFoundEventMessage {
|
|
48
|
+
/** The unique identifier for the model. */
|
|
49
|
+
modelId: string;
|
|
50
|
+
/** The name of the model. */
|
|
51
|
+
name: string;
|
|
52
|
+
/** The name of the model file. */
|
|
53
|
+
fileName: string;
|
|
54
|
+
/** A description of the model. */
|
|
55
|
+
description: string;
|
|
56
|
+
/** An array of file types associated with the model. */
|
|
57
|
+
fileTypes: any[];
|
|
58
|
+
/** The size of the model file in bytes. */
|
|
59
|
+
size: number;
|
|
60
|
+
/** The storage location of the model. */
|
|
61
|
+
storageLocation: Record<string, any>;
|
|
62
|
+
/** The type of the storage provider. */
|
|
63
|
+
providerType: string;
|
|
64
|
+
/** A flexible object for additional metadata. */
|
|
65
|
+
metadata: Record<string, any>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Handles model discovery scan progress events.
|
|
69
|
+
*/
|
|
70
|
+
export interface ModelDiscoveryScanProgressEventMessage {
|
|
71
|
+
/** Contains the discovery scan progress details. */
|
|
72
|
+
payload: Record<string, any>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Handles model discovery scan requests events.
|
|
76
|
+
*/
|
|
77
|
+
export interface ModelDiscoveryScanRequestMessage {
|
|
78
|
+
/** The ID of the library to scan. */
|
|
79
|
+
libraryId: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Handles model metadata generation completed.
|
|
83
|
+
*/
|
|
84
|
+
export interface ModelMetadataGenerationCompletedMessage {
|
|
85
|
+
/** The unique identifier for the model. */
|
|
86
|
+
modelId?: string;
|
|
87
|
+
/** The enriched metadata for the model. */
|
|
88
|
+
metadata: Record<string, any>;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Handles model metadata generation requests.
|
|
92
|
+
*/
|
|
93
|
+
export interface ModelMetadataGenerationRequestMessage {
|
|
94
|
+
/** The unique identifier for the model. */
|
|
95
|
+
modelId: string;
|
|
96
|
+
/** The ID of the storage connection. */
|
|
97
|
+
storageConnectionId: string;
|
|
98
|
+
/** The path to the model file. */
|
|
99
|
+
filePath: string;
|
|
100
|
+
/** The name of the model file. */
|
|
101
|
+
fileName: string;
|
|
102
|
+
/** The size of the model file in bytes. */
|
|
103
|
+
fileSize: number;
|
|
104
|
+
/** The last modified date of the model file. */
|
|
105
|
+
fileLastModified: string;
|
|
106
|
+
/** The type of the storage provider. */
|
|
107
|
+
storageProviderType: string;
|
|
108
|
+
/** The URL of the model thumbnail. */
|
|
109
|
+
modelThumbnailUrl?: string;
|
|
110
|
+
/** The metamodel of the model. */
|
|
111
|
+
metamodel?: Record<string, any>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Handles model metamodel detection found.
|
|
115
|
+
*/
|
|
116
|
+
export interface ModelMetamodelDetectionFoundMessage {
|
|
117
|
+
/** List of metamodel suggestions. */
|
|
118
|
+
suggestions?: any[];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Handles model metamodel detection requests.
|
|
122
|
+
*/
|
|
123
|
+
export interface ModelMetamodelDetectionRequestMessage {
|
|
124
|
+
/** The unique identifier for the storage connection. */
|
|
125
|
+
connectionId?: string;
|
|
126
|
+
/** The path to the folder that was processed. */
|
|
127
|
+
folderPath?: string;
|
|
128
|
+
/** A list of files discovered in the folder. */
|
|
129
|
+
discoveredFiles?: any[];
|
|
130
|
+
/** A signature representing the state of the folder. */
|
|
131
|
+
folderSignature: Record<string, any>;
|
|
132
|
+
/** The timestamp when the folder was processed. */
|
|
133
|
+
processedAt?: string;
|
|
134
|
+
/** Statistics about the processed folder. */
|
|
135
|
+
statistics: Record<string, any>;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Handles thumbnail generation completed.
|
|
139
|
+
*/
|
|
140
|
+
export interface ThumbnailGenerationCompletedMessage {
|
|
141
|
+
/** The ID of the original job that requested the thumbnail generation. */
|
|
142
|
+
originalJobId: string;
|
|
143
|
+
/** The ID of the model that the thumbnail was generated for. */
|
|
144
|
+
modelId: string;
|
|
145
|
+
/** The status of the thumbnail generation. */
|
|
146
|
+
status: string;
|
|
147
|
+
/** The path to the generated thumbnail. */
|
|
148
|
+
thumbnailPath?: string;
|
|
149
|
+
/** An error message if the thumbnail generation failed. */
|
|
150
|
+
errorMessage?: string;
|
|
151
|
+
/** The storage location of the model. */
|
|
152
|
+
storageLocation: Record<string, any>;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Handles thumbnail generation requests.
|
|
156
|
+
*/
|
|
157
|
+
export interface ThumbnailGenerationRequestMessage {
|
|
158
|
+
/** The unique identifier for the model requiring a thumbnail. */
|
|
159
|
+
modelId: string;
|
|
160
|
+
/** The identifier of the user who owns the entity. */
|
|
161
|
+
ownerId: string;
|
|
162
|
+
/** The storage location of the model. */
|
|
163
|
+
storageLocation: Record<string, any>;
|
|
164
|
+
/** The type of preview to generate, e.g., 'default', 'static', 'glb'. */
|
|
165
|
+
previewType: string;
|
|
166
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Auto-generated message types
|
|
2
|
+
/**
|
|
3
|
+
* Message type constants
|
|
4
|
+
*/
|
|
5
|
+
export const MessageTypes = {
|
|
6
|
+
FILE_DOWNLOAD_REQUEST: 'file-download-request',
|
|
7
|
+
MODEL_DISCOVERY_FOLDER_PROCESSED_EVENT: 'model-discovery-folder-processed-event',
|
|
8
|
+
MODEL_DISCOVERY_SCAN_FOUND_EVENT: 'model-discovery-scan-found-event',
|
|
9
|
+
MODEL_DISCOVERY_SCAN_PROGRESS_EVENT: 'model-discovery-scan-progress-event',
|
|
10
|
+
MODEL_DISCOVERY_SCAN_REQUEST: 'model-discovery-scan-request',
|
|
11
|
+
MODEL_METADATA_GENERATION_COMPLETED: 'model-metadata-generation-completed',
|
|
12
|
+
MODEL_METADATA_GENERATION_REQUEST: 'model-metadata-generation-request',
|
|
13
|
+
MODEL_METAMODEL_DETECTION_FOUND: 'model-metamodel-detection-found',
|
|
14
|
+
MODEL_METAMODEL_DETECTION_REQUEST: 'model-metamodel-detection-request',
|
|
15
|
+
THUMBNAIL_GENERATION_COMPLETED: 'thumbnail-generation-completed',
|
|
16
|
+
THUMBNAIL_GENERATION_REQUEST: 'thumbnail-generation-request',
|
|
17
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mesh-sync/worker-backend-client",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Auto-generated TypeScript client for worker-backend - provides type-safe methods for enqueueing jobs",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"prepublishOnly": "npm run build"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"keywords": [
|
|
17
|
+
"worker",
|
|
18
|
+
"job-queue",
|
|
19
|
+
"bullmq",
|
|
20
|
+
"client",
|
|
21
|
+
"typescript",
|
|
22
|
+
"mesh-sync"
|
|
23
|
+
],
|
|
24
|
+
"author": "Mesh-Sync",
|
|
25
|
+
"license": "ISC",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/Mesh-Sync/worker-backend.git",
|
|
29
|
+
"directory": "generated/typescript"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"typescript": "^5.9.3"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {}
|
|
38
|
+
}
|