@decaf-ts/for-couchdb 0.12.0 → 0.13.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.
Files changed (50) hide show
  1. package/lib/cjs/index.cjs +1 -1
  2. package/lib/esm/index.js +1 -1
  3. package/lib/types/adapter.d.cts +2 -2
  4. package/lib/types/adapter.d.mts +2 -2
  5. package/lib/types/decorators.d.cts +1 -1
  6. package/lib/types/decorators.d.mts +1 -1
  7. package/lib/types/index.d.cts +12 -12
  8. package/lib/types/index.d.mts +12 -12
  9. package/lib/types/indexes/generator.d.cts +1 -1
  10. package/lib/types/indexes/generator.d.mts +1 -1
  11. package/lib/types/indexes/index.d.cts +1 -1
  12. package/lib/types/indexes/index.d.mts +1 -1
  13. package/lib/types/query/Paginator.d.cts +2 -2
  14. package/lib/types/query/Paginator.d.mts +2 -2
  15. package/lib/types/query/Statement.d.cts +3 -3
  16. package/lib/types/query/Statement.d.mts +3 -3
  17. package/lib/types/query/constants.d.cts +1 -1
  18. package/lib/types/query/constants.d.mts +1 -1
  19. package/lib/types/query/index.d.cts +4 -4
  20. package/lib/types/query/index.d.mts +4 -4
  21. package/lib/types/query/translate.d.cts +1 -1
  22. package/lib/types/query/translate.d.mts +1 -1
  23. package/lib/types/repository.d.cts +1 -1
  24. package/lib/types/repository.d.mts +1 -1
  25. package/lib/types/utils.d.cts +1 -1
  26. package/lib/types/utils.d.mts +1 -1
  27. package/lib/types/views/generator.d.cts +2 -2
  28. package/lib/types/views/generator.d.mts +2 -2
  29. package/lib/types/views/index.d.cts +2 -2
  30. package/lib/types/views/index.d.mts +2 -2
  31. package/package.json +1 -1
  32. package/lib/types/adapter.d.ts +0 -296
  33. package/lib/types/constants.d.ts +0 -42
  34. package/lib/types/decorators.d.ts +0 -8
  35. package/lib/types/errors.d.ts +0 -21
  36. package/lib/types/index.d.ts +0 -28
  37. package/lib/types/indexes/generator.d.ts +0 -51
  38. package/lib/types/indexes/index.d.ts +0 -1
  39. package/lib/types/metadata.d.ts +0 -4
  40. package/lib/types/query/Paginator.d.ts +0 -105
  41. package/lib/types/query/Statement.d.ts +0 -195
  42. package/lib/types/query/constants.d.ts +0 -47
  43. package/lib/types/query/index.d.ts +0 -4
  44. package/lib/types/query/translate.d.ts +0 -34
  45. package/lib/types/repository.d.ts +0 -39
  46. package/lib/types/types.d.ts +0 -166
  47. package/lib/types/utils.d.ts +0 -112
  48. package/lib/types/views/generator.d.ts +0 -13
  49. package/lib/types/views/index.d.ts +0 -2
  50. package/lib/types/views/types.d.ts +0 -30
@@ -1,296 +0,0 @@
1
- import { Adapter, AdapterFlags, Paginator, RawResult, ContextualArgs, PreparedModel } from "@decaf-ts/core";
2
- import { BaseError, type PrimaryKeyType } from "@decaf-ts/db-decorators";
3
- import { Model } from "@decaf-ts/decorator-validation";
4
- import { type MangoQuery, ViewResponse } from "./types";
5
- import { CouchDBStatement } from "./query";
6
- import { Context } from "@decaf-ts/core";
7
- import { type Constructor } from "@decaf-ts/decoration";
8
- import { Repository } from "@decaf-ts/core";
9
- /**
10
- * @description Abstract adapter for CouchDB database operations
11
- * @summary Provides a base implementation for CouchDB database operations, including CRUD operations, sequence management, and error handling
12
- * @template Y - The scope type
13
- * @template F - The repository flags type
14
- * @template C - The context type
15
- * @param {Y} scope - The scope for the adapter
16
- * @param {string} flavour - The flavour of the adapter
17
- * @param {string} [alias] - Optional alias for the adapter
18
- * @class
19
- * @example
20
- * // Example of extending CouchDBAdapter
21
- * class MyCouchDBAdapter extends CouchDBAdapter<MyScope, MyFlags, MyContext> {
22
- * constructor(scope: MyScope) {
23
- * super(scope, 'my-couchdb', 'my-alias');
24
- * }
25
- *
26
- * // Implement abstract methods
27
- * async index<M extends Model>(...models: Constructor<M>[]): Promise<void> {
28
- * // Implementation
29
- * }
30
- *
31
- * async raw<R>(rawInput: MangoQuery, docsOnly: boolean): Promise<R> {
32
- * // Implementation
33
- * }
34
- *
35
- * async create(tableName: string, id: string | number, model: Record<string, any>, ...args: any[]): Promise<Record<string, any>> {
36
- * // Implementation
37
- * }
38
- *
39
- * async read(tableName: string, id: string | number, ...args: any[]): Promise<Record<string, any>> {
40
- * // Implementation
41
- * }
42
- *
43
- * async update(tableName: string, id: string | number, model: Record<string, any>, ...args: any[]): Promise<Record<string, any>> {
44
- * // Implementation
45
- * }
46
- *
47
- * async delete(tableName: string, id: string | number, ...args: any[]): Promise<Record<string, any>> {
48
- * // Implementation
49
- * }
50
- * }
51
- */
52
- export declare abstract class CouchDBAdapter<CONF, CONN, C extends Context<any>> extends Adapter<CONF, CONN, MangoQuery, C> {
53
- protected constructor(scope: CONF, flavour: string, alias?: string);
54
- /**
55
- * @description Creates a new CouchDB statement for querying
56
- * @summary Factory method that creates a new CouchDBStatement instance for building queries
57
- * @template M - The model type
58
- * @return {CouchDBStatement<M, any>} A new CouchDBStatement instance
59
- */
60
- Statement<M extends Model>(overrides?: Partial<AdapterFlags>): CouchDBStatement<M, Adapter<CONF, CONN, MangoQuery, C>, any>;
61
- Paginator<M extends Model>(query: MangoQuery, size: number, clazz: Constructor<M>): Paginator<M, any, MangoQuery>;
62
- /**
63
- * @description Initializes the adapter by creating indexes for all managed models
64
- * @summary Sets up the necessary database indexes for all models managed by this adapter
65
- * @return {Promise<void>} A promise that resolves when initialization is complete
66
- */
67
- initialize(): Promise<void>;
68
- repository<R extends Repository<any, Adapter<CONF, CONN, MangoQuery, C>>>(): Constructor<R>;
69
- /**
70
- * @description Creates indexes for the given models
71
- * @summary Abstract method that must be implemented to create database indexes for the specified models
72
- * @template M - The model type
73
- * @param {...Constructor<M>} models - The model constructors to create indexes for
74
- * @return {Promise<void>} A promise that resolves when all indexes are created
75
- */
76
- protected abstract index<M extends Model>(...models: Constructor<M>[]): Promise<void>;
77
- /**
78
- * @description Executes a raw Mango query against the database
79
- * @summary Abstract method that must be implemented to execute raw Mango queries. Implementations may treat the first
80
- * additional argument as a boolean `docsOnly` flag before the contextual arguments provided by repositories.
81
- * @template R - The result type
82
- * @param {MangoQuery} rawInput - The raw Mango query to execute
83
- * @param {...MaybeContextualArg<C>} args - Optional `docsOnly` flag followed by contextual arguments
84
- * @return {Promise<R>} A promise that resolves to the query result
85
- */
86
- abstract raw<R, D extends boolean>(rawInput: MangoQuery, docsOnly: D, ...args: ContextualArgs<C>): Promise<RawResult<R, D>>;
87
- /**
88
- * @description Executes a CouchDB view query
89
- * @summary Invokes a design document view and returns its response
90
- * @template R - The view response type
91
- * @param {string} ddoc - Design document name
92
- * @param {string} view - View name
93
- * @param {Record<string, any>} options - Mango query options
94
- * @param {...ContextualArgs<C>} args - Optional contextual arguments
95
- * @return {Promise<ViewResponse<R>>} The view response
96
- */
97
- abstract view<R>(ddoc: string, view: string, options: Record<string, any>, ...args: ContextualArgs<C>): Promise<ViewResponse<R>>;
98
- /**
99
- * @description Assigns metadata to a model
100
- * @summary Adds revision metadata to a model as a non-enumerable property
101
- * @param {Record<string, any>} model - The model to assign metadata to
102
- * @param {string} rev - The revision string to assign
103
- * @return {Record<string, any>} The model with metadata assigned
104
- */
105
- protected assignMetadata(model: Record<string, any>, rev: string): Record<string, any>;
106
- /**
107
- * @description Assigns metadata to multiple models
108
- * @summary Adds revision metadata to multiple models as non-enumerable properties
109
- * @param models - The models to assign metadata to
110
- * @param {string[]} revs - The revision strings to assign
111
- * @return The models with metadata assigned
112
- */
113
- protected assignMultipleMetadata(models: Record<string, any>[], revs: string[]): Record<string, any>[];
114
- prepare<M extends Model>(model: M, ...args: ContextualArgs<C>): PreparedModel;
115
- /**
116
- * @description Prepares a record for creation
117
- * @summary Adds necessary CouchDB fields to a record before creation
118
- * @param {string} tableName - The name of the table
119
- * @param {string|number} id - The ID of the record
120
- * @param {Record<string, any>} model - The model to prepare
121
- * @return A tuple containing the tableName, id, and prepared record
122
- */
123
- protected createPrefix<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<C>): [Constructor<M>, PrimaryKeyType, Record<string, any>, ...any[], Context];
124
- /**
125
- * @description Creates a new record in the database
126
- * @summary Abstract method that must be implemented to create a new record
127
- * @param {string} tableName - The name of the table
128
- * @param {string|number} id - The ID of the record
129
- * @param {Record<string, any>} model - The model to create
130
- * @param {...any[]} args - Additional arguments
131
- * @return {Promise<Record<string, any>>} A promise that resolves to the created record
132
- */
133
- abstract create<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<C>): Promise<Record<string, any>>;
134
- /**
135
- * @description Prepares multiple records for creation
136
- * @summary Adds necessary CouchDB fields to multiple records before creation
137
- * @param {string} tableName - The name of the table
138
- * @param {string[]|number[]} ids - The IDs of the records
139
- * @param models - The models to prepare
140
- * @return A tuple containing the tableName, ids, and prepared records
141
- * @throws {InternalError} If ids and models arrays have different lengths
142
- */
143
- protected createAllPrefix<M extends Model>(clazz: Constructor<M>, ids: string[] | number[], models: Record<string, any>[], ...args: ContextualArgs<C>): any[];
144
- /**
145
- * @description Reads a record from the database
146
- * @summary Abstract method that must be implemented to read a record
147
- * @param {string} tableName - The name of the table
148
- * @param {string|number} id - The ID of the record
149
- * @param {...any[]} args - Additional arguments
150
- * @return {Promise<Record<string, any>>} A promise that resolves to the read record
151
- */
152
- abstract read<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<C>): Promise<Record<string, any>>;
153
- /**
154
- * @description Prepares a record for update
155
- * @summary Adds necessary CouchDB fields to a record before update
156
- * @param {string} tableName - The name of the table
157
- * @param {string|number} id - The ID of the record
158
- * @param model - The model to prepare
159
- * @param [args] - optional args for subclassing
160
- * @return A tuple containing the tableName, id, and prepared record
161
- * @throws {InternalError} If no revision number is found in the model
162
- */
163
- updatePrefix<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<C>): any[];
164
- /**
165
- * @description Updates a record in the database
166
- * @summary Abstract method that must be implemented to update a record
167
- * @param {string} tableName - The name of the table
168
- * @param {string|number} id - The ID of the record
169
- * @param {Record<string, any>} model - The model to update
170
- * @param {any[]} args - Additional arguments
171
- * @return A promise that resolves to the updated record
172
- */
173
- abstract update<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<C>): Promise<Record<string, any>>;
174
- /**
175
- * @description Prepares multiple records for update
176
- * @summary Adds necessary CouchDB fields to multiple records before update
177
- * @param {string} tableName - The name of the table
178
- * @param {string[]|number[]} ids - The IDs of the records
179
- * @param models - The models to prepare
180
- * @return A tuple containing the tableName, ids, and prepared records
181
- * @throws {InternalError} If ids and models arrays have different lengths or if no revision number is found in a model
182
- */
183
- protected updateAllPrefix<M extends Model>(clazz: Constructor<M>, ids: PrimaryKeyType[], models: Record<string, any>[], ...args: ContextualArgs<C>): any[];
184
- /**
185
- * @description Deletes a record from the database
186
- * @summary Abstract method that must be implemented to delete a record
187
- * @param {Constructor<M>} tableName - The name of the table
188
- * @param {PrimaryKeyType} id - The ID of the record
189
- * @param {any[]} args - Additional arguments
190
- * @return A promise that resolves to the deleted record
191
- */
192
- abstract delete<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<C>): Promise<Record<string, any>>;
193
- /**
194
- * @description Generates a CouchDB document ID
195
- * @summary Combines the table name and ID to create a CouchDB document ID
196
- * @param {string} tableName - The name of the table
197
- * @param {string|number} id - The ID of the record
198
- * @return {string} The generated CouchDB document ID
199
- */
200
- protected generateId(tableName: string, id: PrimaryKeyType): string;
201
- /**
202
- * @description Parses an error and converts it to a BaseError
203
- * @summary Converts various error types to appropriate BaseError subtypes
204
- * @param {Error|string} err - The error to parse
205
- * @param {string} [reason] - Optional reason for the error
206
- * @return {BaseError} The parsed error as a BaseError
207
- */
208
- parseError<E extends BaseError>(err: Error | string, reason?: string): E;
209
- /**
210
- * @description Checks if an attribute is reserved
211
- * @summary Determines if an attribute name is reserved in CouchDB
212
- * @param {string} attr - The attribute name to check
213
- * @return {boolean} True if the attribute is reserved, false otherwise
214
- */
215
- protected isReserved(attr: string): boolean;
216
- /**
217
- * @description Static method to parse an error and convert it to a BaseError
218
- * @summary Converts various error types to appropriate BaseError subtypes based on error codes and messages
219
- * @param {Error|string} err - The error to parse
220
- * @param {string} [reason] - Optional reason for the error
221
- * @return {BaseError} The parsed error as a BaseError
222
- * @mermaid
223
- * sequenceDiagram
224
- * participant Caller
225
- * participant parseError
226
- * participant ErrorTypes
227
- *
228
- * Caller->>parseError: err, reason
229
- * Note over parseError: Check if err is already a BaseError
230
- * alt err is BaseError
231
- * parseError-->>Caller: return err
232
- * else err is string
233
- * Note over parseError: Extract code from string
234
- * alt code matches "already exist|update conflict"
235
- * parseError->>ErrorTypes: new ConflictError(code)
236
- * ErrorTypes-->>Caller: ConflictError
237
- * else code matches "missing|deleted"
238
- * parseError->>ErrorTypes: new NotFoundError(code)
239
- * ErrorTypes-->>Caller: NotFoundError
240
- * end
241
- * else err has code property
242
- * Note over parseError: Extract code and reason
243
- * else err has statusCode property
244
- * Note over parseError: Extract code and reason
245
- * else
246
- * Note over parseError: Use err.message as code
247
- * end
248
- *
249
- * Note over parseError: Switch on code
250
- * alt code is 401, 412, or 409
251
- * parseError->>ErrorTypes: new ConflictError(reason)
252
- * ErrorTypes-->>Caller: ConflictError
253
- * else code is 404
254
- * parseError->>ErrorTypes: new NotFoundError(reason)
255
- * ErrorTypes-->>Caller: NotFoundError
256
- * else code is 400
257
- * alt code matches "No index exists"
258
- * parseError->>ErrorTypes: new IndexError(err)
259
- * ErrorTypes-->>Caller: IndexError
260
- * else
261
- * parseError->>ErrorTypes: new InternalError(err)
262
- * ErrorTypes-->>Caller: InternalError
263
- * end
264
- * else code matches "ECONNREFUSED"
265
- * parseError->>ErrorTypes: new ConnectionError(err)
266
- * ErrorTypes-->>Caller: ConnectionError
267
- * else
268
- * parseError->>ErrorTypes: new InternalError(err)
269
- * ErrorTypes-->>Caller: InternalError
270
- * end
271
- */
272
- protected static parseError<E extends BaseError>(err: Error | string, reason?: string): E;
273
- /**
274
- * @description Sets metadata on a model instance.
275
- * @summary Attaches metadata to a model instance using a non-enumerable property.
276
- * @template M - The model type that extends Model.
277
- * @param {M} model - The model instance.
278
- * @param {any} metadata - The metadata to attach to the model.
279
- */
280
- static setMetadata<M extends Model>(model: M, metadata: any): void;
281
- /**
282
- * @description Gets metadata from a model instance.
283
- * @summary Retrieves previously attached metadata from a model instance.
284
- * @template M - The model type that extends Model.
285
- * @param {M} model - The model instance.
286
- * @return {any} The metadata or undefined if not found.
287
- */
288
- static getMetadata<M extends Model>(model: M): any;
289
- /**
290
- * @description Removes metadata from a model instance.
291
- * @summary Deletes the metadata property from a model instance.
292
- * @template M - The model type that extends Model.
293
- * @param {M} model - The model instance.
294
- */
295
- static removeMetadata<M extends Model>(model: M): void;
296
- }
@@ -1,42 +0,0 @@
1
- /**
2
- * @description Regular expression to identify reserved attributes in CouchDB
3
- * @summary Matches any attribute that starts with an underscore
4
- * @const reservedAttributes
5
- * @memberOf module:for-couchdb
6
- */
7
- export declare const reservedAttributes: RegExp;
8
- /**
9
- * @description Key constants used in CouchDB operations
10
- * @summary Collection of string constants for CouchDB document properties and operations
11
- * @typedef {Object} CouchDBKeysType
12
- * @property {string} SEPARATOR - Separator used for combining table name and ID
13
- * @property {string} ID - CouchDB document ID field
14
- * @property {string} REV - CouchDB document revision field
15
- * @property {string} DELETED - CouchDB deleted document marker
16
- * @property {string} TABLE - Table name marker
17
- * @property {string} SEQUENCE - Sequence marker
18
- * @property {string} DDOC - Design document marker
19
- * @property {string} NATIVE - Native marker
20
- * @property {string} INDEX - Index marker
21
- * @memberOf module:for-couchdb
22
- */
23
- /**
24
- * @description Key constants used in CouchDB operations
25
- * @summary Collection of string constants for CouchDB document properties and operations
26
- * @const CouchDBKeys
27
- * @type {CouchDBKeysType}
28
- * @memberOf module:for-couchdb
29
- */
30
- export declare const CouchDBKeys: {
31
- SEPARATOR: string;
32
- ID: string;
33
- REV: string;
34
- DELETED: string;
35
- TABLE: string;
36
- SEQUENCE: string;
37
- DDOC: string;
38
- NATIVE: string;
39
- INDEX: string;
40
- /** @description Key for CouchDB view metadata */
41
- VIEW: string;
42
- };
@@ -1,8 +0,0 @@
1
- import { Condition } from "@decaf-ts/core";
2
- import { AggregateOptions, CouchDBViewOptions } from "./views/index";
3
- export declare function groupBy(compositionsOrOptions?: string[] | string | CouchDBViewOptions, nameOrOptions?: string | CouchDBViewOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
4
- export declare function count(valueOrCondition?: any | Condition<any> | AggregateOptions, options?: AggregateOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
5
- export declare function sum(conditionOrOptions?: Condition<any> | AggregateOptions, options?: AggregateOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
6
- export declare function max(conditionOrOptions?: Condition<any> | AggregateOptions, options?: AggregateOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
7
- export declare function min(conditionOrOptions?: Condition<any> | AggregateOptions, options?: AggregateOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
8
- export declare function distinct(conditionOrOptions?: Condition<any> | AggregateOptions, options?: AggregateOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
@@ -1,21 +0,0 @@
1
- import { BaseError } from "@decaf-ts/db-decorators";
2
- /**
3
- * @description Error thrown when there is an issue with CouchDB indexes
4
- * @summary Represents an error related to CouchDB index operations
5
- * @param {string|Error} msg - The error message or Error object
6
- * @class
7
- * @category Errors
8
- * @example
9
- * // Example of using IndexError
10
- * try {
11
- * // Some code that might throw an index error
12
- * throw new IndexError("Index not found");
13
- * } catch (error) {
14
- * if (error instanceof IndexError) {
15
- * console.error("Index error occurred:", error.message);
16
- * }
17
- * }
18
- */
19
- export declare class IndexError extends BaseError {
20
- constructor(msg: string | Error);
21
- }
@@ -1,28 +0,0 @@
1
- export * from "./indexes";
2
- export * from "./repository";
3
- export * from "./adapter";
4
- export * from "./constants";
5
- export * from "./errors";
6
- export * from "./metadata";
7
- export * from "./decorators";
8
- export * from "./types";
9
- export * from "./utils";
10
- export * from "./query";
11
- export * from "./views";
12
- /**
13
- * @description CouchDB adapter for Decaf.ts
14
- * @summary A TypeScript adapter for CouchDB database operations, providing a seamless integration with the Decaf.ts framework. This module includes classes, interfaces, and utilities for working with CouchDB databases, including support for Mango queries, document operations, and sequence management.
15
- * @module for-couchdb
16
- */
17
- /**
18
- * @description Stores the current package version
19
- * @summary The version string of the for-couchdb package
20
- * @const VERSION
21
- */
22
- export declare const VERSION = "0.11.0";
23
- /**
24
- * @description Stores the current package name
25
- * @summary The version string of the for-couchdb package
26
- * @const PACKAGE_NAME
27
- */
28
- export declare const PACKAGE_NAME = "@decaf-ts/for-couchdb";
@@ -1,51 +0,0 @@
1
- import { Model } from "@decaf-ts/decorator-validation";
2
- import { CreateIndexRequest } from "../types";
3
- import { Constructor } from "@decaf-ts/decoration";
4
- /**
5
- * @description Generates CouchDB index configurations for models
6
- * @summary Creates a set of CouchDB index configurations based on the metadata of the provided models
7
- * @template M - The model type that extends Model
8
- * @param models - Array of model constructors to generate indexes for
9
- * @return {CreateIndexRequest[]} Array of CouchDB index configurations
10
- * @function generateIndexes
11
- * @memberOf module:for-couchdb
12
- * @mermaid
13
- * sequenceDiagram
14
- * participant Caller
15
- * participant generateIndexes
16
- * participant generateIndexName
17
- * participant Repository
18
- *
19
- * Caller->>generateIndexes: models
20
- *
21
- * Note over generateIndexes: Create base table index
22
- * generateIndexes->>generateIndexName: [CouchDBKeys.TABLE]
23
- * generateIndexName-->>generateIndexes: tableName
24
- * generateIndexes->>generateIndexes: Create table index config
25
- *
26
- * loop For each model
27
- * generateIndexes->>Repository: Get indexes metadata
28
- * Repository-->>generateIndexes: index metadata
29
- *
30
- * loop For each index in metadata
31
- * Note over generateIndexes: Extract index properties
32
- * generateIndexes->>Repository: Get table name
33
- * Repository-->>generateIndexes: tableName
34
- *
35
- * Note over generateIndexes: Define nested generate function
36
- *
37
- * generateIndexes->>generateIndexes: Call generate() for default order
38
- * Note over generateIndexes: Create index name and config
39
- *
40
- * alt Has directions
41
- * loop For each direction
42
- * generateIndexes->>generateIndexes: Call generate(direction)
43
- * Note over generateIndexes: Create ordered index config
44
- * end
45
- * end
46
- * end
47
- * end
48
- *
49
- * generateIndexes-->>Caller: Array of index configurations
50
- */
51
- export declare function generateIndexes<M extends Model>(models: Constructor<M>[]): CreateIndexRequest[];
@@ -1 +0,0 @@
1
- export * from "./generator";
@@ -1,4 +0,0 @@
1
- import { Model } from "@decaf-ts/decorator-validation";
2
- export declare function setMetadata<M extends Model>(model: M, metadata: any): void;
3
- export declare function getMetadata<M extends Model>(model: M): any;
4
- export declare function removeMetadata<M extends Model>(model: M): void;
@@ -1,105 +0,0 @@
1
- import { MaybeContextualArg, Paginator } from "@decaf-ts/core";
2
- import { MangoQuery } from "../types";
3
- import { Model } from "@decaf-ts/decorator-validation";
4
- import { CouchDBAdapter } from "../adapter";
5
- import { Constructor } from "@decaf-ts/decoration";
6
- /**
7
- * @description Paginator for ConuchDB query results
8
- * @summary Implements pagination for CouchDB queries using bookmarks for efficient navigation through result sets
9
- * @template M - The model type that extends Model
10
- * @template R - The result type
11
- * @param {CouchDBAdapter<any, any, any>} adapter - The CouchDB adapter
12
- * @param {MangoQuery} query - The Mango query to paginate
13
- * @param {number} size - The page size
14
- * @param {Constructor<M>} clazz - The model constructor
15
- * @class CouchDBPaginator
16
- * @example
17
- * // Example of using CouchDBPaginator
18
- * const adapter = new MyCouchDBAdapter(scope);
19
- * const query = { selector: { type: "user" } };
20
- * const paginator = new CouchDBPaginator(adapter, query, 10, User);
21
- *
22
- * // Get the first page
23
- * const page1 = await paginator.page(1);
24
- *
25
- * // Get the next page
26
- * const page2 = await paginator.page(2);
27
- */
28
- export declare class CouchDBPaginator<M extends Model> extends Paginator<M, M[], MangoQuery> {
29
- /**
30
- * @description Creates a new CouchDBPaginator instance
31
- * @summary Initializes a paginator for CouchDB query results
32
- * @param {CouchDBAdapter<any, any, any, any>} adapter - The CouchDB adapter
33
- * @param {MangoQuery} query - The Mango query to paginate
34
- * @param {number} size - The page size
35
- * @param {Constructor<M>} clazz - The model constructor
36
- */
37
- constructor(adapter: CouchDBAdapter<any, any, any>, query: MangoQuery, size: number, clazz: Constructor<M>);
38
- /**
39
- * @description Prepares a query for pagination
40
- * @summary Modifies the raw query to include pagination parameters
41
- * @param {MangoQuery} rawStatement - The original Mango query
42
- * @return {MangoQuery} The prepared query with pagination parameters
43
- */
44
- protected prepare(rawStatement: MangoQuery): MangoQuery;
45
- /**
46
- * @description Retrieves a specific page of results
47
- * @summary Executes the query with pagination and processes the results
48
- * @param {number} [page=1] - The page number to retrieve
49
- * @return {Promise<R[]>} A promise that resolves to an array of results
50
- * @throws {PagingError} If trying to access a page other than the first without a bookmark, or if no class is defined
51
- * @mermaid
52
- * sequenceDiagram
53
- * participant Client
54
- * participant CouchDBPaginator
55
- * participant Adapter
56
- * participant CouchDB
57
- *
58
- * Client->>CouchDBPaginator: page(pageNumber)
59
- * Note over CouchDBPaginator: Clone statement
60
- * CouchDBPaginator->>CouchDBPaginator: validatePage(page)
61
- *
62
- * alt page !== 1
63
- * CouchDBPaginator->>CouchDBPaginator: Check bookmark
64
- * alt No bookmark
65
- * CouchDBPaginator-->>Client: Throw PagingError
66
- * else Has bookmark
67
- * CouchDBPaginator->>CouchDBPaginator: Add bookmark to statement
68
- * end
69
- * end
70
- *
71
- * CouchDBPaginator->>Adapter: raw(statement, false)
72
- * Adapter->>CouchDB: Execute query
73
- * CouchDB-->>Adapter: Return results
74
- * Adapter-->>CouchDBPaginator: Return MangoResponse
75
- *
76
- * Note over CouchDBPaginator: Process results
77
- *
78
- * alt Has warning
79
- * CouchDBPaginator->>CouchDBPaginator: Log warning
80
- * end
81
- *
82
- * CouchDBPaginator->>CouchDBPaginator: Check for clazz
83
- *
84
- * alt No clazz
85
- * CouchDBPaginator-->>Client: Throw PagingError
86
- * else Has clazz
87
- * CouchDBPaginator->>CouchDBPaginator: Find primary key
88
- *
89
- * alt Has fields in statement
90
- * CouchDBPaginator->>CouchDBPaginator: Use docs directly
91
- * else No fields
92
- * CouchDBPaginator->>CouchDBPaginator: Process each document
93
- * loop For each document
94
- * CouchDBPaginator->>CouchDBPaginator: Extract original ID
95
- * CouchDBPaginator->>Adapter: revert(doc, clazz, pkDef.id, parsedId)
96
- * end
97
- * end
98
- *
99
- * CouchDBPaginator->>CouchDBPaginator: Store bookmark
100
- * CouchDBPaginator->>CouchDBPaginator: Update currentPage
101
- * CouchDBPaginator-->>Client: Return results
102
- * end
103
- */
104
- page(page?: number | undefined, bookmark?: any, ...args: MaybeContextualArg<any>): Promise<M[]>;
105
- }