@baasix/types 1.0.1
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 +242 -0
- package/dist/index.d.mts +2065 -0
- package/dist/index.d.ts +2065 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +43 -0
- package/src/auth.ts +281 -0
- package/src/cache.ts +66 -0
- package/src/common.ts +241 -0
- package/src/files.ts +191 -0
- package/src/index.ts +309 -0
- package/src/notification.ts +52 -0
- package/src/plugin.ts +711 -0
- package/src/query.ts +443 -0
- package/src/response.ts +71 -0
- package/src/schema.ts +343 -0
- package/src/spatial.ts +37 -0
- package/src/workflow.ts +146 -0
package/src/query.ts
ADDED
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query & Filter Types
|
|
3
|
+
* Shared across core, sdk, cli, and app packages
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Filter Types
|
|
8
|
+
// ============================================================================
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Filter operators supported by Baasix
|
|
12
|
+
* Also known as OperatorName in core (alias provided for backward compatibility)
|
|
13
|
+
*/
|
|
14
|
+
export type FilterOperator =
|
|
15
|
+
// Comparison
|
|
16
|
+
| "eq"
|
|
17
|
+
| "ne"
|
|
18
|
+
| "neq"
|
|
19
|
+
| "gt"
|
|
20
|
+
| "gte"
|
|
21
|
+
| "lt"
|
|
22
|
+
| "lte"
|
|
23
|
+
| "is"
|
|
24
|
+
| "not"
|
|
25
|
+
// Collection
|
|
26
|
+
| "in"
|
|
27
|
+
| "notIn"
|
|
28
|
+
| "nin"
|
|
29
|
+
// String patterns
|
|
30
|
+
| "like"
|
|
31
|
+
| "notLike"
|
|
32
|
+
| "iLike"
|
|
33
|
+
| "notILike"
|
|
34
|
+
| "ilike"
|
|
35
|
+
| "contains"
|
|
36
|
+
| "icontains"
|
|
37
|
+
| "ncontains"
|
|
38
|
+
| "startsWith"
|
|
39
|
+
| "startsWiths"
|
|
40
|
+
| "endsWith"
|
|
41
|
+
| "endsWiths"
|
|
42
|
+
| "nstartsWith"
|
|
43
|
+
| "nstartsWiths"
|
|
44
|
+
| "nendsWith"
|
|
45
|
+
| "nendsWiths"
|
|
46
|
+
| "regex"
|
|
47
|
+
// Range
|
|
48
|
+
| "between"
|
|
49
|
+
| "notBetween"
|
|
50
|
+
| "nbetween"
|
|
51
|
+
// Null/Empty
|
|
52
|
+
| "isNull"
|
|
53
|
+
| "isNotNull"
|
|
54
|
+
| "empty"
|
|
55
|
+
// Array (PostgreSQL)
|
|
56
|
+
| "arraycontains"
|
|
57
|
+
| "arraycontainsany"
|
|
58
|
+
| "arraycontained"
|
|
59
|
+
| "arrayoverlap"
|
|
60
|
+
| "arraylength"
|
|
61
|
+
| "arrayempty"
|
|
62
|
+
// JSONB
|
|
63
|
+
| "jsoncontains"
|
|
64
|
+
| "jsonbContains"
|
|
65
|
+
| "jsonbContainedBy"
|
|
66
|
+
| "jsonbNotContains"
|
|
67
|
+
| "jsonhaskey"
|
|
68
|
+
| "jsonbHasKey"
|
|
69
|
+
| "jsonhasanykeys"
|
|
70
|
+
| "jsonbHasAnyKeys"
|
|
71
|
+
| "jsonhasallkeys"
|
|
72
|
+
| "jsonbHasAllKeys"
|
|
73
|
+
| "jsonpath"
|
|
74
|
+
| "jsonbKeyEquals"
|
|
75
|
+
| "jsonbKeyNotEquals"
|
|
76
|
+
| "jsonbKeyGt"
|
|
77
|
+
| "jsonbKeyGte"
|
|
78
|
+
| "jsonbKeyLt"
|
|
79
|
+
| "jsonbKeyLte"
|
|
80
|
+
| "jsonbKeyIn"
|
|
81
|
+
| "jsonbKeyNotIn"
|
|
82
|
+
| "jsonbKeyLike"
|
|
83
|
+
| "jsonbKeyIsNull"
|
|
84
|
+
| "jsonbKeyIsNotNull"
|
|
85
|
+
| "jsonbPathExists"
|
|
86
|
+
| "jsonbPathMatch"
|
|
87
|
+
| "jsonbDeepValue"
|
|
88
|
+
| "jsonbArrayLength"
|
|
89
|
+
| "jsonbTypeOf"
|
|
90
|
+
// Geospatial (PostGIS)
|
|
91
|
+
| "within"
|
|
92
|
+
| "containsGEO"
|
|
93
|
+
| "contains"
|
|
94
|
+
| "intersects"
|
|
95
|
+
| "nIntersects"
|
|
96
|
+
| "dwithin"
|
|
97
|
+
| "overlaps";
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Operator name type (alias for FilterOperator)
|
|
101
|
+
* Used internally in core for the OPERATOR_MAP keys
|
|
102
|
+
* @see FilterOperator
|
|
103
|
+
*/
|
|
104
|
+
export type OperatorName = FilterOperator;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Filter value with operator
|
|
108
|
+
*/
|
|
109
|
+
export type FilterValue<T = unknown> =
|
|
110
|
+
| T
|
|
111
|
+
| { [K in FilterOperator]?: T | T[] }
|
|
112
|
+
| { cast?: string };
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Filter condition for a field
|
|
116
|
+
*/
|
|
117
|
+
export type FilterCondition = {
|
|
118
|
+
[field: string]: FilterValue | FilterCondition;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Logical filter operators
|
|
123
|
+
*/
|
|
124
|
+
export interface LogicalFilter {
|
|
125
|
+
AND?: (FilterCondition | LogicalFilter)[];
|
|
126
|
+
OR?: (FilterCondition | LogicalFilter)[];
|
|
127
|
+
NOT?: FilterCondition | LogicalFilter;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Complete filter type
|
|
132
|
+
*/
|
|
133
|
+
export type Filter = FilterCondition | LogicalFilter;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Filter object (used internally in core)
|
|
137
|
+
*/
|
|
138
|
+
export interface FilterObject {
|
|
139
|
+
field: string;
|
|
140
|
+
operator: FilterOperator;
|
|
141
|
+
value: unknown;
|
|
142
|
+
cast?: string;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ============================================================================
|
|
146
|
+
// Sort Types
|
|
147
|
+
// ============================================================================
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Sort direction
|
|
151
|
+
*/
|
|
152
|
+
export type SortDirection = "asc" | "desc" | "ASC" | "DESC";
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Sort configuration - supports multiple formats
|
|
156
|
+
*/
|
|
157
|
+
export type Sort =
|
|
158
|
+
| string
|
|
159
|
+
| string[]
|
|
160
|
+
| Record<string, SortDirection>
|
|
161
|
+
| { column: string; order: SortDirection }[]
|
|
162
|
+
| { field: string; order: SortDirection }[];
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Sort item (normalized)
|
|
166
|
+
*/
|
|
167
|
+
export interface SortItem {
|
|
168
|
+
field: string;
|
|
169
|
+
direction: SortDirection;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Sort object structure (Sequelize-style)
|
|
174
|
+
* Example: { name: 'ASC', createdAt: 'DESC' }
|
|
175
|
+
*/
|
|
176
|
+
export interface SortObject {
|
|
177
|
+
[field: string]: SortDirection;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ============================================================================
|
|
181
|
+
// Pagination Types
|
|
182
|
+
// ============================================================================
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Pagination options
|
|
186
|
+
*/
|
|
187
|
+
export interface PaginationOptions {
|
|
188
|
+
page?: number;
|
|
189
|
+
limit?: number;
|
|
190
|
+
offset?: number;
|
|
191
|
+
pageSize?: number;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Pagination metadata in response
|
|
196
|
+
*/
|
|
197
|
+
export interface PaginationMetadata {
|
|
198
|
+
total: number;
|
|
199
|
+
page: number;
|
|
200
|
+
pageSize: number;
|
|
201
|
+
pageCount: number;
|
|
202
|
+
hasNextPage: boolean;
|
|
203
|
+
hasPreviousPage: boolean;
|
|
204
|
+
/** @deprecated Use total instead */
|
|
205
|
+
totalCount?: number;
|
|
206
|
+
/** @deprecated Use pageCount instead */
|
|
207
|
+
totalPages?: number;
|
|
208
|
+
/** @deprecated Use pageSize instead */
|
|
209
|
+
limit?: number;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// ============================================================================
|
|
213
|
+
// Aggregation Types
|
|
214
|
+
// ============================================================================
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Aggregation function
|
|
218
|
+
*/
|
|
219
|
+
export type AggregateFunction =
|
|
220
|
+
| "count"
|
|
221
|
+
| "sum"
|
|
222
|
+
| "avg"
|
|
223
|
+
| "min"
|
|
224
|
+
| "max"
|
|
225
|
+
| "distinct"
|
|
226
|
+
| "array_agg";
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Aggregation configuration
|
|
230
|
+
*/
|
|
231
|
+
export interface AggregateConfig {
|
|
232
|
+
function: AggregateFunction;
|
|
233
|
+
field: string;
|
|
234
|
+
alias?: string;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Aggregate mapping (general form)
|
|
239
|
+
*/
|
|
240
|
+
export type Aggregate = Record<string, AggregateConfig | AggregateFunction>;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Aggregate result mapping (strict form - always uses AggregateConfig)
|
|
244
|
+
* Example: { totalUsers: { function: 'count', field: 'id' } }
|
|
245
|
+
*/
|
|
246
|
+
export interface AggregateMapping {
|
|
247
|
+
[alias: string]: AggregateConfig;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Date part for date extraction
|
|
252
|
+
*/
|
|
253
|
+
export type DatePart =
|
|
254
|
+
| "year"
|
|
255
|
+
| "month"
|
|
256
|
+
| "week"
|
|
257
|
+
| "day"
|
|
258
|
+
| "hour"
|
|
259
|
+
| "minute"
|
|
260
|
+
| "second"
|
|
261
|
+
| "dow"
|
|
262
|
+
| "isodow"
|
|
263
|
+
| "quarter";
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Date truncation precision
|
|
267
|
+
*/
|
|
268
|
+
export type DateTruncPrecision =
|
|
269
|
+
| "day"
|
|
270
|
+
| "week"
|
|
271
|
+
| "month"
|
|
272
|
+
| "year"
|
|
273
|
+
| "hour"
|
|
274
|
+
| "minute"
|
|
275
|
+
| "second";
|
|
276
|
+
|
|
277
|
+
// ============================================================================
|
|
278
|
+
// Query Parameters
|
|
279
|
+
// ============================================================================
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Query parameters for listing items
|
|
283
|
+
* Used by SDK, app, and can be extended by core for internal use
|
|
284
|
+
*/
|
|
285
|
+
export interface QueryParams<T = unknown> {
|
|
286
|
+
/**
|
|
287
|
+
* Fields to return
|
|
288
|
+
* @example ['*'], ['id', 'name'], ['*', 'author.*']
|
|
289
|
+
*/
|
|
290
|
+
fields?: string[];
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Filter conditions
|
|
294
|
+
*/
|
|
295
|
+
filter?: Filter;
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Sorting configuration
|
|
299
|
+
*/
|
|
300
|
+
sort?: Sort;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Number of items per page (-1 for all)
|
|
304
|
+
* @default 10
|
|
305
|
+
*/
|
|
306
|
+
limit?: number;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Page number (1-indexed)
|
|
310
|
+
* @default 1
|
|
311
|
+
*/
|
|
312
|
+
page?: number;
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Number of items to skip
|
|
316
|
+
*/
|
|
317
|
+
offset?: number;
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Full-text search query
|
|
321
|
+
*/
|
|
322
|
+
search?: string;
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Fields to search in
|
|
326
|
+
*/
|
|
327
|
+
searchFields?: string[];
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Sort results by search relevance
|
|
331
|
+
* @default false
|
|
332
|
+
*/
|
|
333
|
+
sortByRelevance?: boolean;
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Aggregation configuration
|
|
337
|
+
*/
|
|
338
|
+
aggregate?: Aggregate;
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Fields to group by (used with aggregate)
|
|
342
|
+
*/
|
|
343
|
+
groupBy?: string[];
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Include soft-deleted items
|
|
347
|
+
* @default false
|
|
348
|
+
*/
|
|
349
|
+
paranoid?: boolean;
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Filter conditions for related items (O2M/M2M)
|
|
353
|
+
*/
|
|
354
|
+
relConditions?: Record<string, Filter>;
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Additional metadata
|
|
358
|
+
*/
|
|
359
|
+
meta?: T;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Query options for read operations (alias for QueryParams)
|
|
364
|
+
* Core-compatible naming
|
|
365
|
+
*/
|
|
366
|
+
export type QueryOptions = QueryParams;
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Query context (used internally in core)
|
|
370
|
+
*/
|
|
371
|
+
export interface QueryContext {
|
|
372
|
+
collection: string;
|
|
373
|
+
filter?: Filter;
|
|
374
|
+
sort?: Sort;
|
|
375
|
+
fields?: string[];
|
|
376
|
+
limit?: number;
|
|
377
|
+
page?: number;
|
|
378
|
+
offset?: number;
|
|
379
|
+
aggregate?: Aggregate;
|
|
380
|
+
groupBy?: string[];
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// ============================================================================
|
|
384
|
+
// Report Query Types
|
|
385
|
+
// ============================================================================
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Report configuration
|
|
389
|
+
*/
|
|
390
|
+
export interface ReportConfig {
|
|
391
|
+
collection: string;
|
|
392
|
+
filter?: Record<string, unknown>;
|
|
393
|
+
groupBy?: string;
|
|
394
|
+
aggregate?: Record<string, unknown>;
|
|
395
|
+
dateRange?: {
|
|
396
|
+
start: string;
|
|
397
|
+
end: string;
|
|
398
|
+
field?: string;
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Report result
|
|
404
|
+
*/
|
|
405
|
+
export interface ReportResult {
|
|
406
|
+
data: Record<string, unknown>[];
|
|
407
|
+
summary?: Record<string, unknown>;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Report query parameters
|
|
412
|
+
*/
|
|
413
|
+
export interface ReportQuery {
|
|
414
|
+
fields?: string[];
|
|
415
|
+
filter?: Record<string, any>;
|
|
416
|
+
sort?: string[];
|
|
417
|
+
limit?: number;
|
|
418
|
+
page?: number;
|
|
419
|
+
aggregate?: Record<string, any>;
|
|
420
|
+
groupBy?: string[];
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// ============================================================================
|
|
424
|
+
// Stats Query Types
|
|
425
|
+
// ============================================================================
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Stats query
|
|
429
|
+
*/
|
|
430
|
+
export interface StatsQuery {
|
|
431
|
+
name: string;
|
|
432
|
+
query: Record<string, unknown>;
|
|
433
|
+
collection: string;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Stats result
|
|
438
|
+
*/
|
|
439
|
+
export interface StatsResult {
|
|
440
|
+
data: Record<string, unknown>;
|
|
441
|
+
totalStats: number;
|
|
442
|
+
successfulStats: number;
|
|
443
|
+
}
|
package/src/response.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response Types
|
|
3
|
+
* Shared across core, sdk, cli, and app packages
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// API Response Types
|
|
8
|
+
// ============================================================================
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Paginated response
|
|
12
|
+
*/
|
|
13
|
+
export interface PaginatedResponse<T> {
|
|
14
|
+
data: T[];
|
|
15
|
+
totalCount?: number;
|
|
16
|
+
page?: number;
|
|
17
|
+
limit?: number;
|
|
18
|
+
totalPages?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Single item response
|
|
23
|
+
*/
|
|
24
|
+
export interface SingleResponse<T> {
|
|
25
|
+
data: T;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Create/Update response
|
|
30
|
+
*/
|
|
31
|
+
export interface MutationResponse<T = string> {
|
|
32
|
+
data: T;
|
|
33
|
+
message?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Delete response
|
|
38
|
+
*/
|
|
39
|
+
export interface DeleteResponse {
|
|
40
|
+
data: { deleted: boolean; count?: number };
|
|
41
|
+
message?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Bulk operation response
|
|
46
|
+
*/
|
|
47
|
+
export interface BulkResponse<T = string[]> {
|
|
48
|
+
data: T;
|
|
49
|
+
message?: string;
|
|
50
|
+
errors?: Array<{ index: number; error: string }>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Read result (used internally in services)
|
|
55
|
+
*/
|
|
56
|
+
export interface ReadResult<T = any> {
|
|
57
|
+
data: T[];
|
|
58
|
+
totalCount: number;
|
|
59
|
+
page?: number;
|
|
60
|
+
limit?: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Error response
|
|
65
|
+
*/
|
|
66
|
+
export interface ErrorResponse {
|
|
67
|
+
error: string;
|
|
68
|
+
message: string;
|
|
69
|
+
status: number;
|
|
70
|
+
details?: unknown[];
|
|
71
|
+
}
|