-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexport-service.ts
More file actions
212 lines (191 loc) · 5.54 KB
/
Copy pathexport-service.ts
File metadata and controls
212 lines (191 loc) · 5.54 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
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
/**
* IExportService - Data Export Service Contract
*
* Defines the interface for streaming data export, import validation,
* template management, and scheduled export operations in ObjectStack.
* Concrete implementations (in-memory, database-backed, etc.)
* should implement this interface.
*
* Follows Dependency Inversion Principle - plugins depend on this interface,
* not on concrete export service implementations.
*
* Aligned with CoreServiceName 'export' in core-services.zod.ts.
*/
import type {
ExportFormat,
ExportJobStatus,
ExportJobProgress,
ExportJobSummary,
ExportImportTemplate,
ScheduledExport,
} from '../api/export.zod';
// ==========================================
// Export Job Types
// ==========================================
/**
* Input for creating a new export job.
*/
export interface CreateExportJobInput {
/** Object name to export */
object: string;
/** Export file format */
format?: ExportFormat;
/** Specific fields to include (omit for all fields) */
fields?: string[];
/** Filter criteria for records to export */
filter?: Record<string, unknown>;
/** Sort order for exported records */
sort?: Array<{ field: string; direction?: 'asc' | 'desc' }>;
/** Maximum number of records to export */
limit?: number;
/** Include header row (CSV/XLSX) */
includeHeaders?: boolean;
/** Character encoding */
encoding?: string;
/** Export template ID for predefined field mappings */
templateId?: string;
}
/**
* Result of creating an export job.
*/
export interface CreateExportJobResult {
/** Export job ID */
jobId: string;
/** Initial job status */
status: ExportJobStatus;
/** Estimated total records */
estimatedRecords?: number;
/** Job creation timestamp (ISO 8601) */
createdAt: string;
}
/**
* Download link info for a completed export job.
*/
export interface ExportJobDownload {
/** Export job ID */
jobId: string;
/** Presigned download URL */
downloadUrl: string;
/** Suggested file name */
fileName: string;
/** File size in bytes */
fileSize: number;
/** Export file format */
format: ExportFormat;
/** Download URL expiration timestamp (ISO 8601) */
expiresAt: string;
/** File checksum (SHA-256) */
checksum?: string;
}
/**
* Options for listing export jobs.
*/
export interface ListExportJobsOptions {
/** Filter by object name */
object?: string;
/** Filter by job status */
status?: ExportJobStatus;
/** Maximum number of jobs to return */
limit?: number;
/** Pagination cursor */
cursor?: string;
}
/**
* Paginated list of export jobs.
*/
export interface ExportJobListResult {
/** Export job summaries */
jobs: ExportJobSummary[];
/** Cursor for the next page */
nextCursor?: string;
/** Whether more jobs are available */
hasMore: boolean;
}
/**
* Input for scheduling a recurring export.
*/
export interface ScheduleExportInput {
/** Schedule name (snake_case) */
name: string;
/** Human-readable label */
label?: string;
/** Object name to export */
object: string;
/** Export file format */
format?: ExportFormat;
/** Fields to include */
fields?: string[];
/** Record filter criteria */
filter?: Record<string, unknown>;
/** Export template ID */
templateId?: string;
/** Schedule timing configuration */
schedule: {
cronExpression: string;
timezone?: string;
};
/** Export delivery configuration */
delivery: {
method: 'email' | 'storage' | 'webhook';
recipients?: string[];
storagePath?: string;
webhookUrl?: string;
};
}
// ==========================================
// Service Interface
// ==========================================
export interface IExportService {
// ---- Export Jobs ----
/**
* Create a new export job.
* @param input - Export job configuration
* @returns The created export job with tracking info
*/
createExportJob(input: CreateExportJobInput): Promise<CreateExportJobResult>;
/**
* Get the progress/status of an export job.
* @param jobId - Export job ID
* @returns Export job progress, or null if not found
*/
getExportJobProgress(jobId: string): Promise<ExportJobProgress | null>;
/**
* Get the download link for a completed export job.
* @param jobId - Export job ID
* @returns Download link info, or null if not available
*/
getExportJobDownload(jobId: string): Promise<ExportJobDownload | null>;
/**
* Cancel an in-progress export job.
* @param jobId - Export job ID
* @returns Whether the job was successfully cancelled
*/
cancelExportJob(jobId: string): Promise<boolean>;
/**
* List export jobs with optional filtering and pagination.
* @param options - Filter and pagination options
* @returns Paginated list of export jobs
*/
listExportJobs(options?: ListExportJobsOptions): Promise<ExportJobListResult>;
// ---- Scheduled Exports ----
/**
* Create a scheduled recurring export.
* @param input - Schedule configuration
* @returns The created scheduled export
*/
scheduleExport(input: ScheduleExportInput): Promise<ScheduledExport>;
// ---- Templates (optional) ----
/**
* Get an export/import template by ID.
* @param templateId - Template ID
* @returns The template, or null if not found
*/
getTemplate?(templateId: string): Promise<ExportImportTemplate | null>;
/**
* List available export/import templates.
* @param object - Optional object filter
* @returns Array of templates
*/
listTemplates?(object?: string): Promise<ExportImportTemplate[]>;
}