@objectql/driver-excel 0.2.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/CHANGELOG.md +70 -0
- package/EXAMPLE.md +198 -0
- package/LICENSE +21 -0
- package/README.md +653 -0
- package/dist/index.d.ts +215 -0
- package/dist/index.js +856 -0
- package/dist/index.js.map +1 -0
- package/jest.config.js +9 -0
- package/package.json +37 -0
- package/src/index.ts +960 -0
- package/test/index.test.ts +566 -0
- package/tsconfig.json +12 -0
- package/tsconfig.tsbuildinfo +1 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Excel Driver for ObjectQL (Production-Ready)
|
|
3
|
+
*
|
|
4
|
+
* A driver for ObjectQL that reads and writes data from Excel (.xlsx) files.
|
|
5
|
+
* Each worksheet in the Excel file represents an object type, with the first row
|
|
6
|
+
* containing column headers (field names) and subsequent rows containing data.
|
|
7
|
+
*
|
|
8
|
+
* ✅ Features:
|
|
9
|
+
* - Read data from Excel files
|
|
10
|
+
* - Write data back to Excel files
|
|
11
|
+
* - Multiple sheets support (one sheet per object type)
|
|
12
|
+
* - Full CRUD operations
|
|
13
|
+
* - Query support (filters, sorting, pagination)
|
|
14
|
+
* - Automatic data type handling
|
|
15
|
+
* - Secure: Uses ExcelJS (no known vulnerabilities)
|
|
16
|
+
*
|
|
17
|
+
* Use Cases:
|
|
18
|
+
* - Import/export data from Excel spreadsheets
|
|
19
|
+
* - Use Excel as a simple database for prototyping
|
|
20
|
+
* - Data migration from Excel to other databases
|
|
21
|
+
* - Generate reports in Excel format
|
|
22
|
+
*/
|
|
23
|
+
import { Driver } from '@objectql/types';
|
|
24
|
+
/**
|
|
25
|
+
* File storage mode for the Excel driver.
|
|
26
|
+
*/
|
|
27
|
+
export type FileStorageMode = 'single-file' | 'file-per-object';
|
|
28
|
+
/**
|
|
29
|
+
* Configuration options for the Excel driver.
|
|
30
|
+
*/
|
|
31
|
+
export interface ExcelDriverConfig {
|
|
32
|
+
/**
|
|
33
|
+
* Path to the Excel file or directory.
|
|
34
|
+
* - In 'single-file' mode: Path to a single .xlsx file
|
|
35
|
+
* - In 'file-per-object' mode: Path to a directory where object files are stored
|
|
36
|
+
*/
|
|
37
|
+
filePath: string;
|
|
38
|
+
/**
|
|
39
|
+
* File storage mode (default: 'single-file')
|
|
40
|
+
* - 'single-file': All object types stored as worksheets in one Excel file
|
|
41
|
+
* - 'file-per-object': Each object type stored in a separate Excel file
|
|
42
|
+
*/
|
|
43
|
+
fileStorageMode?: FileStorageMode;
|
|
44
|
+
/** Optional: Auto-save changes to file (default: true) */
|
|
45
|
+
autoSave?: boolean;
|
|
46
|
+
/** Optional: Create file if it doesn't exist (default: true) */
|
|
47
|
+
createIfMissing?: boolean;
|
|
48
|
+
/** Optional: Enable strict mode (throw on missing objects) */
|
|
49
|
+
strictMode?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Excel Driver Implementation
|
|
53
|
+
*
|
|
54
|
+
* Stores ObjectQL documents in Excel worksheets. Each object type is stored
|
|
55
|
+
* in a separate worksheet, with the first row containing column headers.
|
|
56
|
+
*
|
|
57
|
+
* Uses ExcelJS library for secure Excel file operations.
|
|
58
|
+
*/
|
|
59
|
+
export declare class ExcelDriver implements Driver {
|
|
60
|
+
private config;
|
|
61
|
+
private workbook;
|
|
62
|
+
private workbooks;
|
|
63
|
+
private data;
|
|
64
|
+
private idCounters;
|
|
65
|
+
private filePath;
|
|
66
|
+
private fileStorageMode;
|
|
67
|
+
constructor(config: ExcelDriverConfig);
|
|
68
|
+
/**
|
|
69
|
+
* Initialize the driver by loading the workbook from file.
|
|
70
|
+
* This must be called after construction before using the driver.
|
|
71
|
+
*/
|
|
72
|
+
init(): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Factory method to create and initialize the driver.
|
|
75
|
+
*/
|
|
76
|
+
static create(config: ExcelDriverConfig): Promise<ExcelDriver>;
|
|
77
|
+
/**
|
|
78
|
+
* Load workbook from file or create a new one.
|
|
79
|
+
* Handles both single-file and file-per-object modes.
|
|
80
|
+
*/
|
|
81
|
+
private loadWorkbook;
|
|
82
|
+
/**
|
|
83
|
+
* Load workbook in single-file mode (all objects in one Excel file).
|
|
84
|
+
*/
|
|
85
|
+
private loadSingleFileWorkbook;
|
|
86
|
+
/**
|
|
87
|
+
* Load workbooks in file-per-object mode (each object in separate Excel file).
|
|
88
|
+
*/
|
|
89
|
+
private loadFilePerObjectWorkbooks;
|
|
90
|
+
/**
|
|
91
|
+
* Load data from workbook into memory.
|
|
92
|
+
*
|
|
93
|
+
* Expected Excel format:
|
|
94
|
+
* - First row contains column headers (field names)
|
|
95
|
+
* - Subsequent rows contain data records
|
|
96
|
+
* - Each worksheet represents one object type
|
|
97
|
+
*/
|
|
98
|
+
private loadDataFromWorkbook;
|
|
99
|
+
/**
|
|
100
|
+
* Load data from a single worksheet into memory.
|
|
101
|
+
*/
|
|
102
|
+
private loadDataFromSingleWorksheet;
|
|
103
|
+
/**
|
|
104
|
+
* Update ID counter based on existing records.
|
|
105
|
+
*
|
|
106
|
+
* Attempts to extract counter from auto-generated IDs (format: objectName-timestamp-counter).
|
|
107
|
+
* If IDs don't follow this format, counter starts from existing record count.
|
|
108
|
+
*/
|
|
109
|
+
private updateIdCounter;
|
|
110
|
+
/**
|
|
111
|
+
* Save workbook to file.
|
|
112
|
+
*/
|
|
113
|
+
/**
|
|
114
|
+
* Save workbook to file.
|
|
115
|
+
* Handles both single-file and file-per-object modes.
|
|
116
|
+
*/
|
|
117
|
+
private saveWorkbook;
|
|
118
|
+
/**
|
|
119
|
+
* Save workbook in single-file mode.
|
|
120
|
+
*/
|
|
121
|
+
private saveSingleFileWorkbook;
|
|
122
|
+
/**
|
|
123
|
+
* Save workbook in file-per-object mode.
|
|
124
|
+
*/
|
|
125
|
+
private saveFilePerObjectWorkbook;
|
|
126
|
+
/**
|
|
127
|
+
* Sync in-memory data to workbook.
|
|
128
|
+
*
|
|
129
|
+
* Creates or updates a worksheet for the given object type.
|
|
130
|
+
*/
|
|
131
|
+
private syncToWorkbook;
|
|
132
|
+
/**
|
|
133
|
+
* Sync data to worksheet in single-file mode.
|
|
134
|
+
*/
|
|
135
|
+
private syncToSingleFileWorkbook;
|
|
136
|
+
/**
|
|
137
|
+
* Sync data to separate file in file-per-object mode.
|
|
138
|
+
*/
|
|
139
|
+
private syncToFilePerObjectWorkbook;
|
|
140
|
+
/**
|
|
141
|
+
* Find multiple records matching the query criteria.
|
|
142
|
+
*/
|
|
143
|
+
find(objectName: string, query?: any, options?: any): Promise<any[]>;
|
|
144
|
+
/**
|
|
145
|
+
* Find a single record by ID or query.
|
|
146
|
+
*/
|
|
147
|
+
findOne(objectName: string, id: string | number, query?: any, options?: any): Promise<any>;
|
|
148
|
+
/**
|
|
149
|
+
* Create a new record.
|
|
150
|
+
*/
|
|
151
|
+
create(objectName: string, data: any, options?: any): Promise<any>;
|
|
152
|
+
/**
|
|
153
|
+
* Update an existing record.
|
|
154
|
+
*/
|
|
155
|
+
update(objectName: string, id: string | number, data: any, options?: any): Promise<any>;
|
|
156
|
+
/**
|
|
157
|
+
* Delete a record.
|
|
158
|
+
*/
|
|
159
|
+
delete(objectName: string, id: string | number, options?: any): Promise<any>;
|
|
160
|
+
/**
|
|
161
|
+
* Count records matching filters.
|
|
162
|
+
*/
|
|
163
|
+
count(objectName: string, filters: any, options?: any): Promise<number>;
|
|
164
|
+
/**
|
|
165
|
+
* Get distinct values for a field.
|
|
166
|
+
*/
|
|
167
|
+
distinct(objectName: string, field: string, filters?: any, options?: any): Promise<any[]>;
|
|
168
|
+
/**
|
|
169
|
+
* Create multiple records at once.
|
|
170
|
+
*/
|
|
171
|
+
createMany(objectName: string, data: any[], options?: any): Promise<any>;
|
|
172
|
+
/**
|
|
173
|
+
* Update multiple records matching filters.
|
|
174
|
+
*/
|
|
175
|
+
updateMany(objectName: string, filters: any, data: any, options?: any): Promise<any>;
|
|
176
|
+
/**
|
|
177
|
+
* Delete multiple records matching filters.
|
|
178
|
+
*/
|
|
179
|
+
deleteMany(objectName: string, filters: any, options?: any): Promise<any>;
|
|
180
|
+
/**
|
|
181
|
+
* Manually save the workbook to file.
|
|
182
|
+
*/
|
|
183
|
+
/**
|
|
184
|
+
* Manually save the workbook to file.
|
|
185
|
+
*/
|
|
186
|
+
save(): Promise<void>;
|
|
187
|
+
/**
|
|
188
|
+
* Disconnect (flush any pending writes).
|
|
189
|
+
*/
|
|
190
|
+
disconnect(): Promise<void>;
|
|
191
|
+
/**
|
|
192
|
+
* Apply filters to an array of records (in-memory filtering).
|
|
193
|
+
*/
|
|
194
|
+
private applyFilters;
|
|
195
|
+
/**
|
|
196
|
+
* Check if a single record matches the filter conditions.
|
|
197
|
+
*/
|
|
198
|
+
private matchesFilters;
|
|
199
|
+
/**
|
|
200
|
+
* Evaluate a single filter condition.
|
|
201
|
+
*/
|
|
202
|
+
private evaluateCondition;
|
|
203
|
+
/**
|
|
204
|
+
* Apply sorting to an array of records.
|
|
205
|
+
*/
|
|
206
|
+
private applySort;
|
|
207
|
+
/**
|
|
208
|
+
* Project specific fields from a document.
|
|
209
|
+
*/
|
|
210
|
+
private projectFields;
|
|
211
|
+
/**
|
|
212
|
+
* Generate a unique ID for a record.
|
|
213
|
+
*/
|
|
214
|
+
private generateId;
|
|
215
|
+
}
|