@fjell/core 4.4.72 → 4.4.74
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 +6 -6
- package/dist/AItemService.d.ts +1 -1
- package/dist/Coordinate.d.ts +1 -6
- package/dist/event/emitter.d.ts +1 -2
- package/dist/event/events.d.ts +1 -2
- package/dist/event/matching.d.ts +1 -1
- package/dist/event/subscription.d.ts +1 -2
- package/dist/index.d.ts +7 -20
- package/dist/index.js +980 -1008
- package/dist/item/IFactory.d.ts +1 -2
- package/dist/item/IQFactory.d.ts +1 -1
- package/dist/item/IQUtils.d.ts +1 -2
- package/dist/item/IUtils.d.ts +1 -7
- package/dist/key/KUtils.d.ts +3 -3
- package/dist/operations/OperationContext.d.ts +1 -1
- package/dist/operations/index.d.ts +1 -0
- package/dist/operations/wrappers/createActionWrapper.d.ts +1 -3
- package/dist/operations/wrappers/createAllActionWrapper.d.ts +1 -3
- package/dist/operations/wrappers/createAllFacetWrapper.d.ts +1 -2
- package/dist/operations/wrappers/createAllWrapper.d.ts +1 -3
- package/dist/operations/wrappers/createCreateWrapper.d.ts +1 -3
- package/dist/operations/wrappers/createFacetWrapper.d.ts +1 -2
- package/dist/operations/wrappers/createFindOneWrapper.d.ts +1 -3
- package/dist/operations/wrappers/createFindWrapper.d.ts +1 -3
- package/dist/operations/wrappers/createGetWrapper.d.ts +1 -3
- package/dist/operations/wrappers/createOneWrapper.d.ts +1 -3
- package/dist/operations/wrappers/createRemoveWrapper.d.ts +1 -3
- package/dist/operations/wrappers/createUpdateWrapper.d.ts +1 -3
- package/dist/operations/wrappers/createUpsertWrapper.d.ts +1 -3
- package/dist/operations/wrappers/types.d.ts +1 -1
- package/package.json +4 -7
- package/dist/item/ItemQuery.d.ts +0 -62
- package/dist/items.d.ts +0 -74
- package/dist/keys.d.ts +0 -66
- package/dist/operations/Operations.d.ts +0 -530
- package/dist/operations/contained.d.ts +0 -65
- package/dist/operations/methods.d.ts +0 -204
- package/dist/operations/primary.d.ts +0 -57
- package/dist/operations/specialized.d.ts +0 -41
- package/dist/validation/ItemValidator.d.ts +0 -43
- package/dist/validation/KeyValidator.d.ts +0 -56
- package/dist/validation/LocationValidator.d.ts +0 -39
- package/dist/validation/QueryValidator.d.ts +0 -57
- package/dist/validation/index.d.ts +0 -17
- package/dist/validation/index.js +0 -592
- package/dist/validation/schema.d.ts +0 -23
- package/dist/validation/types.d.ts +0 -69
|
@@ -1,530 +0,0 @@
|
|
|
1
|
-
import { Item } from "../items";
|
|
2
|
-
import { ComKey, LocKeyArray, PriKey } from "../keys";
|
|
3
|
-
import { ItemQuery } from "../item/ItemQuery";
|
|
4
|
-
/**
|
|
5
|
-
* Standard operation parameters type
|
|
6
|
-
*/
|
|
7
|
-
export type OperationParams = Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>;
|
|
8
|
-
/**
|
|
9
|
-
* Type for affected keys returned by actions
|
|
10
|
-
*/
|
|
11
|
-
export type AffectedKeys = Array<PriKey<any> | ComKey<any, any, any, any, any, any> | LocKeyArray<any, any, any, any, any>>;
|
|
12
|
-
/**
|
|
13
|
-
* Options for create operation
|
|
14
|
-
*/
|
|
15
|
-
export type CreateOptions<S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> = {
|
|
16
|
-
key: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>;
|
|
17
|
-
locations?: never;
|
|
18
|
-
} | {
|
|
19
|
-
key?: never;
|
|
20
|
-
locations: LocKeyArray<L1, L2, L3, L4, L5>;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Base options for pagination operations (all() and find()).
|
|
24
|
-
*
|
|
25
|
-
* Contains the common pagination parameters shared by both operations.
|
|
26
|
-
*
|
|
27
|
-
* @public
|
|
28
|
-
*/
|
|
29
|
-
export interface PaginationOptions {
|
|
30
|
-
/**
|
|
31
|
-
* Maximum number of items to return.
|
|
32
|
-
*
|
|
33
|
-
* - Must be a positive integer (>= 1)
|
|
34
|
-
* - When not provided, returns all matching items
|
|
35
|
-
* - Takes precedence over query.limit when both are specified
|
|
36
|
-
*/
|
|
37
|
-
limit?: number;
|
|
38
|
-
/**
|
|
39
|
-
* Number of items to skip before returning results.
|
|
40
|
-
*
|
|
41
|
-
* - Must be a non-negative integer (>= 0)
|
|
42
|
-
* - Defaults to 0 when not provided
|
|
43
|
-
* - Takes precedence over query.offset when both are specified
|
|
44
|
-
*/
|
|
45
|
-
offset?: number;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Options for the all() operation with pagination support.
|
|
49
|
-
*
|
|
50
|
-
* When provided, these options take precedence over any limit/offset
|
|
51
|
-
* specified in the ItemQuery.
|
|
52
|
-
*
|
|
53
|
-
* @public
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```typescript
|
|
57
|
-
* // Fetch first 50 items
|
|
58
|
-
* const result = await operations.all(query, [], { limit: 50, offset: 0 });
|
|
59
|
-
*
|
|
60
|
-
* // Fetch next page
|
|
61
|
-
* const nextPage = await operations.all(query, [], { limit: 50, offset: 50 });
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
export interface AllOptions extends PaginationOptions {
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Options for the find() operation with pagination support.
|
|
68
|
-
*
|
|
69
|
-
* When provided, these options take precedence over any limit/offset
|
|
70
|
-
* passed to finder functions.
|
|
71
|
-
*
|
|
72
|
-
* @public
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```typescript
|
|
76
|
-
* // Find with pagination
|
|
77
|
-
* const findResult = await operations.find('byEmail', { email: 'test@example.com' }, [], { limit: 10 });
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
export interface FindOptions extends PaginationOptions {
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Metadata about the pagination state for an all() operation.
|
|
84
|
-
*
|
|
85
|
-
* This metadata enables proper pagination UI and logic by providing
|
|
86
|
-
* the total count of matching items before limit/offset are applied.
|
|
87
|
-
*
|
|
88
|
-
* @public
|
|
89
|
-
*/
|
|
90
|
-
export interface PaginationMetadata {
|
|
91
|
-
/**
|
|
92
|
-
* Total count of items matching the query BEFORE limit/offset applied.
|
|
93
|
-
*
|
|
94
|
-
* This represents the complete result set size and is used to:
|
|
95
|
-
* - Display "Showing X of Y results"
|
|
96
|
-
* - Calculate total pages
|
|
97
|
-
* - Determine if more items exist
|
|
98
|
-
*/
|
|
99
|
-
total: number;
|
|
100
|
-
/**
|
|
101
|
-
* Number of items actually returned in this response.
|
|
102
|
-
*
|
|
103
|
-
* This equals `items.length` and is provided for convenience.
|
|
104
|
-
* When offset + returned < total, more items exist.
|
|
105
|
-
*/
|
|
106
|
-
returned: number;
|
|
107
|
-
/**
|
|
108
|
-
* The limit that was applied, if any.
|
|
109
|
-
*
|
|
110
|
-
* - Undefined when no limit was applied
|
|
111
|
-
* - Reflects the effective limit (options.limit ?? query.limit)
|
|
112
|
-
*/
|
|
113
|
-
limit?: number;
|
|
114
|
-
/**
|
|
115
|
-
* The offset that was applied.
|
|
116
|
-
*
|
|
117
|
-
* - 0 when no offset was applied
|
|
118
|
-
* - Reflects the effective offset (options.offset ?? query.offset ?? 0)
|
|
119
|
-
*/
|
|
120
|
-
offset: number;
|
|
121
|
-
/**
|
|
122
|
-
* Convenience field indicating whether more items exist beyond this page.
|
|
123
|
-
*
|
|
124
|
-
* Calculated as: `offset + returned < total`
|
|
125
|
-
*
|
|
126
|
-
* Useful for:
|
|
127
|
-
* - "Load More" buttons
|
|
128
|
-
* - Infinite scroll implementations
|
|
129
|
-
* - "Next Page" button state
|
|
130
|
-
*/
|
|
131
|
-
hasMore: boolean;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Base result structure for paginated operations.
|
|
135
|
-
*
|
|
136
|
-
* This structure provides both the items and metadata needed for
|
|
137
|
-
* implementing proper pagination in applications.
|
|
138
|
-
*
|
|
139
|
-
* @template T - The item type being returned
|
|
140
|
-
*
|
|
141
|
-
* @public
|
|
142
|
-
*/
|
|
143
|
-
export interface OperationResult<T> {
|
|
144
|
-
/**
|
|
145
|
-
* Array of items matching the query, with limit/offset applied.
|
|
146
|
-
*/
|
|
147
|
-
items: T[];
|
|
148
|
-
/**
|
|
149
|
-
* Pagination metadata for the result set.
|
|
150
|
-
*/
|
|
151
|
-
metadata: PaginationMetadata;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Result structure for the all() operation with pagination support.
|
|
155
|
-
*
|
|
156
|
-
* This structure provides both the items and metadata needed for
|
|
157
|
-
* implementing proper pagination in applications.
|
|
158
|
-
*
|
|
159
|
-
* @template T - The item type being returned
|
|
160
|
-
*
|
|
161
|
-
* @public
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* ```typescript
|
|
165
|
-
* const result = await operations.all(query, [], { limit: 50, offset: 0 });
|
|
166
|
-
*
|
|
167
|
-
* console.log(`Showing ${result.metadata.returned} of ${result.metadata.total}`);
|
|
168
|
-
* // "Showing 50 of 1234"
|
|
169
|
-
*
|
|
170
|
-
* if (result.metadata.hasMore) {
|
|
171
|
-
* // Load next page
|
|
172
|
-
* }
|
|
173
|
-
* ```
|
|
174
|
-
*/
|
|
175
|
-
export interface AllOperationResult<T> extends OperationResult<T> {
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Result structure for the find() operation with pagination support.
|
|
179
|
-
*
|
|
180
|
-
* This structure provides both the items and metadata needed for
|
|
181
|
-
* implementing proper pagination in find operations.
|
|
182
|
-
*
|
|
183
|
-
* @template T - The item type being returned
|
|
184
|
-
*
|
|
185
|
-
* @public
|
|
186
|
-
*
|
|
187
|
-
* @example
|
|
188
|
-
* ```typescript
|
|
189
|
-
* const result = await operations.find('byEmail', { email: 'test@example.com' }, [], { limit: 10 });
|
|
190
|
-
*
|
|
191
|
-
* console.log(`Found ${result.metadata.returned} of ${result.metadata.total} results`);
|
|
192
|
-
* // "Found 10 of 25 results"
|
|
193
|
-
*
|
|
194
|
-
* if (result.metadata.hasMore) {
|
|
195
|
-
* // Load next page
|
|
196
|
-
* }
|
|
197
|
-
* ```
|
|
198
|
-
*/
|
|
199
|
-
export interface FindOperationResult<T> extends OperationResult<T> {
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Options for update operations across all Fjell libraries.
|
|
203
|
-
*
|
|
204
|
-
* These options provide explicit control over update behavior,
|
|
205
|
-
* with safe defaults that prevent accidental data loss.
|
|
206
|
-
*
|
|
207
|
-
* @public
|
|
208
|
-
*/
|
|
209
|
-
export interface UpdateOptions {
|
|
210
|
-
/**
|
|
211
|
-
* Controls whether the update replaces the entire document/record or merges with existing data.
|
|
212
|
-
*
|
|
213
|
-
* **Default: `false` (merge/partial update)**
|
|
214
|
-
*
|
|
215
|
-
* When `false` (default):
|
|
216
|
-
* - Only the specified fields are updated
|
|
217
|
-
* - All other existing fields are preserved
|
|
218
|
-
* - Safe for partial updates
|
|
219
|
-
* - Recommended for most use cases
|
|
220
|
-
*
|
|
221
|
-
* When `true`:
|
|
222
|
-
* - The entire document/record is replaced with the provided data
|
|
223
|
-
* - Any fields not included in the update payload are DELETED
|
|
224
|
-
* - Use with extreme caution
|
|
225
|
-
* - Logs warning before operation (in implementations)
|
|
226
|
-
*
|
|
227
|
-
* ⚠️ **WARNING**: Setting `replace: true` can lead to permanent data loss.
|
|
228
|
-
* Always verify that your update payload contains ALL fields you want to preserve.
|
|
229
|
-
*
|
|
230
|
-
* @default false
|
|
231
|
-
*
|
|
232
|
-
* @example Merge update (default - safe)
|
|
233
|
-
* ```typescript
|
|
234
|
-
* // Existing: { id: '123', name: 'John', email: 'john@example.com', status: 'active' }
|
|
235
|
-
* await operations.update(
|
|
236
|
-
* { kt: 'user', pk: '123' },
|
|
237
|
-
* { status: 'inactive' }
|
|
238
|
-
* );
|
|
239
|
-
* // Result: { id: '123', name: 'John', email: 'john@example.com', status: 'inactive' }
|
|
240
|
-
* // ✅ All fields preserved except status
|
|
241
|
-
* ```
|
|
242
|
-
*
|
|
243
|
-
* @example Full replacement (use with caution)
|
|
244
|
-
* ```typescript
|
|
245
|
-
* // Existing: { id: '123', name: 'John', email: 'john@example.com', status: 'active' }
|
|
246
|
-
* await operations.update(
|
|
247
|
-
* { kt: 'user', pk: '123' },
|
|
248
|
-
* { status: 'inactive' },
|
|
249
|
-
* { replace: true }
|
|
250
|
-
* );
|
|
251
|
-
* // Result: { status: 'inactive' }
|
|
252
|
-
* // ❌ name and email are DELETED!
|
|
253
|
-
* ```
|
|
254
|
-
*/
|
|
255
|
-
replace?: boolean;
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Core Operations interface for Item-based data access.
|
|
259
|
-
* This interface defines the standard contract for all fjell libraries
|
|
260
|
-
* that operate on Items.
|
|
261
|
-
*
|
|
262
|
-
* @template V - The Item type
|
|
263
|
-
* @template S - The primary key type
|
|
264
|
-
* @template L1-L5 - Location key types (optional, for contained items)
|
|
265
|
-
*
|
|
266
|
-
* @example
|
|
267
|
-
* ```typescript
|
|
268
|
-
* // Primary item operations
|
|
269
|
-
* const userOps: Operations<User, 'user'> = ...;
|
|
270
|
-
* const users = await userOps.all();
|
|
271
|
-
*
|
|
272
|
-
* // Contained item operations
|
|
273
|
-
* const commentOps: Operations<Comment, 'comment', 'post'> = ...;
|
|
274
|
-
* const comments = await commentOps.all({}, [{kt: 'post', lk: 'post-123'}]);
|
|
275
|
-
* ```
|
|
276
|
-
*/
|
|
277
|
-
export interface Operations<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> {
|
|
278
|
-
/**
|
|
279
|
-
* Retrieves all items matching the query with optional pagination.
|
|
280
|
-
*
|
|
281
|
-
* @param query - Optional query to filter items (may include limit/offset for backwards compatibility)
|
|
282
|
-
* @param locations - Optional location hierarchy to scope the query
|
|
283
|
-
* @param options - Optional pagination options (takes precedence over query limit/offset)
|
|
284
|
-
* @returns Result containing items and pagination metadata
|
|
285
|
-
*
|
|
286
|
-
* @example Get all items
|
|
287
|
-
* ```typescript
|
|
288
|
-
* const result = await operations.all();
|
|
289
|
-
* // result.items = all items
|
|
290
|
-
* // result.metadata.total = items.length
|
|
291
|
-
* ```
|
|
292
|
-
*
|
|
293
|
-
* @example Get paginated items
|
|
294
|
-
* ```typescript
|
|
295
|
-
* const result = await operations.all({}, [], { limit: 50, offset: 0 });
|
|
296
|
-
* // result.items = first 50 items
|
|
297
|
-
* // result.metadata.total = total matching count
|
|
298
|
-
* // result.metadata.hasMore = true if more exist
|
|
299
|
-
* ```
|
|
300
|
-
*
|
|
301
|
-
* @example Get items in specific location with pagination
|
|
302
|
-
* ```typescript
|
|
303
|
-
* const result = await operations.all(
|
|
304
|
-
* {},
|
|
305
|
-
* [{kt: 'post', lk: 'post-123'}],
|
|
306
|
-
* { limit: 20, offset: 0 }
|
|
307
|
-
* );
|
|
308
|
-
* ```
|
|
309
|
-
*/
|
|
310
|
-
all(query?: ItemQuery, locations?: LocKeyArray<L1, L2, L3, L4, L5> | [], options?: AllOptions): Promise<AllOperationResult<V>>;
|
|
311
|
-
/**
|
|
312
|
-
* Retrieves the first item matching the query.
|
|
313
|
-
*
|
|
314
|
-
* @param query - Optional query to filter items
|
|
315
|
-
* @param locations - Optional location hierarchy to scope the query
|
|
316
|
-
* @returns Single item or null if not found
|
|
317
|
-
*/
|
|
318
|
-
one(query?: ItemQuery, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []): Promise<V | null>;
|
|
319
|
-
/**
|
|
320
|
-
* Creates a new item.
|
|
321
|
-
*
|
|
322
|
-
* @param item - Partial item properties for creation
|
|
323
|
-
* @param options - Optional key or locations for the new item
|
|
324
|
-
* @returns The created item
|
|
325
|
-
*
|
|
326
|
-
* @example
|
|
327
|
-
* ```typescript
|
|
328
|
-
* // Create with auto-generated key
|
|
329
|
-
* const user = await operations.create({ name: 'Alice' });
|
|
330
|
-
*
|
|
331
|
-
* // Create with specific key
|
|
332
|
-
* const user = await operations.create(
|
|
333
|
-
* { name: 'Alice' },
|
|
334
|
-
* { key: { kt: 'user', pk: 'alice-123' } }
|
|
335
|
-
* );
|
|
336
|
-
*
|
|
337
|
-
* // Create in specific location
|
|
338
|
-
* const comment = await operations.create(
|
|
339
|
-
* { text: 'Great post!' },
|
|
340
|
-
* { locations: [{kt: 'post', lk: 'post-123'}] }
|
|
341
|
-
* );
|
|
342
|
-
* ```
|
|
343
|
-
*/
|
|
344
|
-
create(item: Partial<Item<S, L1, L2, L3, L4, L5>>, options?: CreateOptions<S, L1, L2, L3, L4, L5>): Promise<V>;
|
|
345
|
-
/**
|
|
346
|
-
* Retrieves a single item by its key.
|
|
347
|
-
*
|
|
348
|
-
* @param key - Primary or composite key
|
|
349
|
-
* @returns The item or null if not found
|
|
350
|
-
*
|
|
351
|
-
* @example
|
|
352
|
-
* ```typescript
|
|
353
|
-
* // Get by primary key
|
|
354
|
-
* const user = await operations.get({ kt: 'user', pk: 'user-123' });
|
|
355
|
-
*
|
|
356
|
-
* // Get by composite key
|
|
357
|
-
* const comment = await operations.get({
|
|
358
|
-
* kt: 'comment',
|
|
359
|
-
* pk: 'comment-456',
|
|
360
|
-
* loc: [{kt: 'post', lk: 'post-123'}]
|
|
361
|
-
* });
|
|
362
|
-
* ```
|
|
363
|
-
*/
|
|
364
|
-
get(key: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>): Promise<V | null>;
|
|
365
|
-
/**
|
|
366
|
-
* Updates an existing item.
|
|
367
|
-
*
|
|
368
|
-
* @param key - Primary or composite key
|
|
369
|
-
* @param item - Partial item properties to update
|
|
370
|
-
* @param options - Optional update options (controls merge vs replace behavior)
|
|
371
|
-
* @returns The updated item
|
|
372
|
-
*
|
|
373
|
-
* @example Merge update (default - safe)
|
|
374
|
-
* ```typescript
|
|
375
|
-
* await operations.update(key, { status: 'active' });
|
|
376
|
-
* // Merges with existing data, preserves other fields
|
|
377
|
-
* ```
|
|
378
|
-
*
|
|
379
|
-
* @example Replace update (dangerous)
|
|
380
|
-
* ```typescript
|
|
381
|
-
* await operations.update(key, { status: 'active' }, { replace: true });
|
|
382
|
-
* // Replaces entire document, deletes unspecified fields
|
|
383
|
-
* ```
|
|
384
|
-
*/
|
|
385
|
-
update(key: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>, item: Partial<Item<S, L1, L2, L3, L4, L5>>, options?: UpdateOptions): Promise<V>;
|
|
386
|
-
/**
|
|
387
|
-
* Updates an item if it exists, creates it if it doesn't.
|
|
388
|
-
*
|
|
389
|
-
* @param key - Primary or composite key
|
|
390
|
-
* @param item - Partial item properties
|
|
391
|
-
* @param locations - Optional locations for creation
|
|
392
|
-
* @param options - Optional update options (used only if item exists, ignored for creation)
|
|
393
|
-
* @returns The upserted item
|
|
394
|
-
*/
|
|
395
|
-
upsert(key: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>, item: Partial<Item<S, L1, L2, L3, L4, L5>>, locations?: LocKeyArray<L1, L2, L3, L4, L5>, options?: UpdateOptions): Promise<V>;
|
|
396
|
-
/**
|
|
397
|
-
* Removes an item.
|
|
398
|
-
*
|
|
399
|
-
* @param key - Primary or composite key
|
|
400
|
-
* @returns The removed item or void
|
|
401
|
-
*/
|
|
402
|
-
remove(key: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>): Promise<V | void>;
|
|
403
|
-
/**
|
|
404
|
-
* Executes a finder method by name with optional pagination support.
|
|
405
|
-
*
|
|
406
|
-
* Supports hybrid pagination approach:
|
|
407
|
-
* - If finder returns FindOperationResult<V>, uses it directly (opt-in)
|
|
408
|
-
* - If finder returns V[], framework applies post-processing pagination
|
|
409
|
-
*
|
|
410
|
-
* @param finder - Name of the finder method
|
|
411
|
-
* @param params - Parameters for the finder
|
|
412
|
-
* @param locations - Optional location hierarchy to scope the query
|
|
413
|
-
* @param options - Optional pagination options (limit, offset)
|
|
414
|
-
* @returns Result containing items and pagination metadata
|
|
415
|
-
*
|
|
416
|
-
* @example
|
|
417
|
-
* ```typescript
|
|
418
|
-
* // Find users by email (no pagination)
|
|
419
|
-
* const result = await operations.find('byEmail', { email: 'alice@example.com' });
|
|
420
|
-
* const users = result.items;
|
|
421
|
-
*
|
|
422
|
-
* // Find with pagination
|
|
423
|
-
* const result = await operations.find(
|
|
424
|
-
* 'byAuthor',
|
|
425
|
-
* { author: 'alice' },
|
|
426
|
-
* [{kt: 'post', lk: 'post-123'}],
|
|
427
|
-
* { limit: 10, offset: 0 }
|
|
428
|
-
* );
|
|
429
|
-
* const comments = result.items;
|
|
430
|
-
* const total = result.metadata.total;
|
|
431
|
-
* ```
|
|
432
|
-
*/
|
|
433
|
-
find(finder: string, params?: OperationParams, locations?: LocKeyArray<L1, L2, L3, L4, L5> | [], options?: FindOptions): Promise<FindOperationResult<V>>;
|
|
434
|
-
/**
|
|
435
|
-
* Executes a finder method and returns the first result.
|
|
436
|
-
*
|
|
437
|
-
* @param finder - Name of the finder method
|
|
438
|
-
* @param params - Parameters for the finder
|
|
439
|
-
* @param locations - Optional location hierarchy to scope the query
|
|
440
|
-
* @returns Single item or null
|
|
441
|
-
*/
|
|
442
|
-
findOne(finder: string, params?: OperationParams, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []): Promise<V | null>;
|
|
443
|
-
/**
|
|
444
|
-
* Executes an action on a specific item.
|
|
445
|
-
* Actions are operations that may have side effects or modify the item.
|
|
446
|
-
*
|
|
447
|
-
* @param key - Primary or composite key
|
|
448
|
-
* @param action - Name of the action
|
|
449
|
-
* @param params - Parameters for the action
|
|
450
|
-
* @returns Tuple of [updated item, affected keys for cache invalidation]
|
|
451
|
-
*
|
|
452
|
-
* @example
|
|
453
|
-
* ```typescript
|
|
454
|
-
* const [user, affectedKeys] = await operations.action(
|
|
455
|
-
* { kt: 'user', pk: 'user-123' },
|
|
456
|
-
* 'promote',
|
|
457
|
-
* { role: 'admin' }
|
|
458
|
-
* );
|
|
459
|
-
* ```
|
|
460
|
-
*/
|
|
461
|
-
action(key: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>, action: string, params?: OperationParams): Promise<[V, AffectedKeys]>;
|
|
462
|
-
/**
|
|
463
|
-
* Executes an action on all items matching criteria.
|
|
464
|
-
*
|
|
465
|
-
* @param action - Name of the action
|
|
466
|
-
* @param params - Parameters for the action
|
|
467
|
-
* @param locations - Optional location hierarchy to scope the action
|
|
468
|
-
* @returns Tuple of [updated items, affected keys for cache invalidation]
|
|
469
|
-
*/
|
|
470
|
-
allAction(action: string, params?: OperationParams, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []): Promise<[V[], AffectedKeys]>;
|
|
471
|
-
/**
|
|
472
|
-
* Executes a facet query on a specific item.
|
|
473
|
-
* Facets are read-only computed views of item data.
|
|
474
|
-
*
|
|
475
|
-
* @param key - Primary or composite key
|
|
476
|
-
* @param facet - Name of the facet
|
|
477
|
-
* @param params - Parameters for the facet
|
|
478
|
-
* @returns Facet result data
|
|
479
|
-
*
|
|
480
|
-
* @example
|
|
481
|
-
* ```typescript
|
|
482
|
-
* const stats = await operations.facet(
|
|
483
|
-
* { kt: 'user', pk: 'user-123' },
|
|
484
|
-
* 'statistics',
|
|
485
|
-
* { period: 'month' }
|
|
486
|
-
* );
|
|
487
|
-
* ```
|
|
488
|
-
*/
|
|
489
|
-
facet(key: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>, facet: string, params?: OperationParams): Promise<any>;
|
|
490
|
-
/**
|
|
491
|
-
* Executes a facet query on all items matching criteria.
|
|
492
|
-
* Facets are read-only computed views of item data.
|
|
493
|
-
*
|
|
494
|
-
* @param facet - Name of the facet
|
|
495
|
-
* @param params - Parameters for the facet
|
|
496
|
-
* @param locations - Optional location hierarchy to scope the query
|
|
497
|
-
* @returns Facet result data
|
|
498
|
-
*/
|
|
499
|
-
allFacet(facet: string, params?: OperationParams, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []): Promise<any>;
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Type guard to check if key is a PriKey
|
|
503
|
-
*
|
|
504
|
-
* @param key - Key to check
|
|
505
|
-
* @returns true if key is a PriKey
|
|
506
|
-
*
|
|
507
|
-
* @example
|
|
508
|
-
* ```typescript
|
|
509
|
-
* if (isPriKey(key)) {
|
|
510
|
-
* // key is PriKey<S>
|
|
511
|
-
* console.log(key.kt, key.pk);
|
|
512
|
-
* }
|
|
513
|
-
* ```
|
|
514
|
-
*/
|
|
515
|
-
export declare function isPriKey<S extends string>(key: PriKey<S> | ComKey<S, any, any, any, any, any>): key is PriKey<S>;
|
|
516
|
-
/**
|
|
517
|
-
* Type guard to check if key is a ComKey
|
|
518
|
-
*
|
|
519
|
-
* @param key - Key to check
|
|
520
|
-
* @returns true if key is a ComKey
|
|
521
|
-
*
|
|
522
|
-
* @example
|
|
523
|
-
* ```typescript
|
|
524
|
-
* if (isComKey(key)) {
|
|
525
|
-
* // key is ComKey<S, L1, L2, L3, L4, L5>
|
|
526
|
-
* console.log(key.kt, key.pk, key.loc);
|
|
527
|
-
* }
|
|
528
|
-
* ```
|
|
529
|
-
*/
|
|
530
|
-
export declare function isComKey<S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(key: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>): key is ComKey<S, L1, L2, L3, L4, L5>;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { Item } from "../items";
|
|
2
|
-
import { ComKey, LocKeyArray } from "../keys";
|
|
3
|
-
import { ItemQuery } from "../item/ItemQuery";
|
|
4
|
-
import { AffectedKeys, AllOperationResult, AllOptions, FindOperationResult, FindOptions, OperationParams, Operations } from "./Operations";
|
|
5
|
-
/**
|
|
6
|
-
* Contained Operations interface - specialized for contained (hierarchical) items only.
|
|
7
|
-
*
|
|
8
|
-
* This interface narrows the generic Operations interface to work exclusively
|
|
9
|
-
* with ComKey and requires locations for collection operations.
|
|
10
|
-
*
|
|
11
|
-
* Contained items exist within a location hierarchy and belong to parent items.
|
|
12
|
-
* Examples: Comments (in Posts), Annotations (in Documents), Tasks (in Projects)
|
|
13
|
-
*
|
|
14
|
-
* Use this for:
|
|
15
|
-
* - Libraries that store contained items
|
|
16
|
-
* - Caches for contained items
|
|
17
|
-
* - API clients for contained endpoints
|
|
18
|
-
* - Any operations that work with hierarchical data
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```typescript
|
|
22
|
-
* // Define a contained item type
|
|
23
|
-
* interface Comment extends Item<'comment', 'post'> {
|
|
24
|
-
* text: string;
|
|
25
|
-
* author: string;
|
|
26
|
-
* }
|
|
27
|
-
*
|
|
28
|
-
* // Create operations for contained items
|
|
29
|
-
* const commentOps: ContainedOperations<Comment, 'comment', 'post'> = createCommentOperations();
|
|
30
|
-
*
|
|
31
|
-
* // Only ComKey allowed - includes location hierarchy
|
|
32
|
-
* await commentOps.get({
|
|
33
|
-
* kt: 'comment',
|
|
34
|
-
* pk: '123',
|
|
35
|
-
* loc: [{ kt: 'post', lk: 'post-1' }]
|
|
36
|
-
* });
|
|
37
|
-
*
|
|
38
|
-
* await commentOps.update(
|
|
39
|
-
* { kt: 'comment', pk: '123', loc: [{ kt: 'post', lk: 'post-1' }] },
|
|
40
|
-
* { text: 'Updated comment' }
|
|
41
|
-
* );
|
|
42
|
-
*
|
|
43
|
-
* // Locations required on collection methods
|
|
44
|
-
* await commentOps.all({}, [{ kt: 'post', lk: 'post-1' }]);
|
|
45
|
-
* await commentOps.find('recent', {}, [{ kt: 'post', lk: 'post-1' }]);
|
|
46
|
-
* await commentOps.allAction('archive', {}, [{ kt: 'post', lk: 'post-1' }]);
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export interface ContainedOperations<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> extends Omit<Operations<V, S, L1, L2, L3, L4, L5>, 'get' | 'update' | 'remove' | 'upsert' | 'create' | 'action' | 'facet' | 'allAction' | 'allFacet' | 'all' | 'one' | 'find' | 'findOne'> {
|
|
50
|
-
all(query: ItemQuery | undefined, locations: LocKeyArray<L1, L2, L3, L4, L5> | [], allOptions?: AllOptions): Promise<AllOperationResult<V>>;
|
|
51
|
-
one(query: ItemQuery | undefined, locations: LocKeyArray<L1, L2, L3, L4, L5> | []): Promise<V | null>;
|
|
52
|
-
find(finder: string, params: OperationParams | undefined, locations: LocKeyArray<L1, L2, L3, L4, L5> | [], options?: FindOptions): Promise<FindOperationResult<V>>;
|
|
53
|
-
findOne(finder: string, params: OperationParams | undefined, locations: LocKeyArray<L1, L2, L3, L4, L5> | []): Promise<V | null>;
|
|
54
|
-
create(item: Partial<Item<S, L1, L2, L3, L4, L5>>, options?: {
|
|
55
|
-
locations?: LocKeyArray<L1, L2, L3, L4, L5>;
|
|
56
|
-
}): Promise<V>;
|
|
57
|
-
get(key: ComKey<S, L1, L2, L3, L4, L5>): Promise<V | null>;
|
|
58
|
-
update(key: ComKey<S, L1, L2, L3, L4, L5>, item: Partial<Item<S, L1, L2, L3, L4, L5>>): Promise<V>;
|
|
59
|
-
upsert(key: ComKey<S, L1, L2, L3, L4, L5>, item: Partial<Item<S, L1, L2, L3, L4, L5>>): Promise<V>;
|
|
60
|
-
remove(key: ComKey<S, L1, L2, L3, L4, L5>): Promise<V | void>;
|
|
61
|
-
action(key: ComKey<S, L1, L2, L3, L4, L5>, action: string, params?: OperationParams): Promise<[V, AffectedKeys]>;
|
|
62
|
-
allAction(action: string, params: OperationParams | undefined, locations: LocKeyArray<L1, L2, L3, L4, L5> | []): Promise<[V[], AffectedKeys]>;
|
|
63
|
-
facet(key: ComKey<S, L1, L2, L3, L4, L5>, facet: string, params?: OperationParams): Promise<any>;
|
|
64
|
-
allFacet(facet: string, params: OperationParams | undefined, locations: LocKeyArray<L1, L2, L3, L4, L5> | []): Promise<any>;
|
|
65
|
-
}
|