@decaf-ts/for-couchdb 0.3.1 → 0.3.2

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 (61) hide show
  1. package/LICENSE.md +646 -144
  2. package/README.md +371 -1
  3. package/dist/for-couchdb.cjs +733 -24
  4. package/dist/for-couchdb.esm.cjs +733 -24
  5. package/lib/adapter.cjs +186 -1
  6. package/lib/adapter.d.ts +234 -0
  7. package/lib/constants.cjs +29 -1
  8. package/lib/constants.d.ts +28 -0
  9. package/lib/errors.cjs +18 -1
  10. package/lib/errors.d.ts +17 -0
  11. package/lib/esm/adapter.d.ts +234 -0
  12. package/lib/esm/adapter.js +186 -1
  13. package/lib/esm/constants.d.ts +28 -0
  14. package/lib/esm/constants.js +29 -1
  15. package/lib/esm/errors.d.ts +17 -0
  16. package/lib/esm/errors.js +18 -1
  17. package/lib/esm/index.d.ts +6 -13
  18. package/lib/esm/index.js +7 -14
  19. package/lib/esm/indexes/generator.d.ts +47 -0
  20. package/lib/esm/indexes/generator.js +58 -1
  21. package/lib/esm/interfaces/CouchDBRepository.d.ts +10 -0
  22. package/lib/esm/interfaces/CouchDBRepository.js +1 -1
  23. package/lib/esm/model/CouchDBSequence.d.ts +19 -0
  24. package/lib/esm/model/CouchDBSequence.js +12 -1
  25. package/lib/esm/query/Paginator.d.ts +111 -0
  26. package/lib/esm/query/Paginator.js +117 -8
  27. package/lib/esm/query/Statement.d.ts +134 -0
  28. package/lib/esm/query/Statement.js +143 -1
  29. package/lib/esm/query/constants.d.ts +42 -0
  30. package/lib/esm/query/constants.js +43 -1
  31. package/lib/esm/query/translate.d.ts +31 -0
  32. package/lib/esm/query/translate.js +32 -1
  33. package/lib/esm/sequences/Sequence.d.ts +0 -2
  34. package/lib/esm/sequences/Sequence.js +2 -4
  35. package/lib/esm/types.d.ts +55 -12
  36. package/lib/esm/types.js +1 -1
  37. package/lib/esm/utils.d.ts +105 -0
  38. package/lib/esm/utils.js +106 -1
  39. package/lib/index.cjs +7 -14
  40. package/lib/index.d.ts +6 -13
  41. package/lib/indexes/generator.cjs +58 -1
  42. package/lib/indexes/generator.d.ts +47 -0
  43. package/lib/interfaces/CouchDBRepository.cjs +1 -1
  44. package/lib/interfaces/CouchDBRepository.d.ts +10 -0
  45. package/lib/model/CouchDBSequence.cjs +12 -1
  46. package/lib/model/CouchDBSequence.d.ts +19 -0
  47. package/lib/query/Paginator.cjs +117 -8
  48. package/lib/query/Paginator.d.ts +111 -0
  49. package/lib/query/Statement.cjs +143 -1
  50. package/lib/query/Statement.d.ts +134 -0
  51. package/lib/query/constants.cjs +43 -1
  52. package/lib/query/constants.d.ts +42 -0
  53. package/lib/query/translate.cjs +32 -1
  54. package/lib/query/translate.d.ts +31 -0
  55. package/lib/sequences/Sequence.cjs +2 -4
  56. package/lib/sequences/Sequence.d.ts +0 -2
  57. package/lib/types.cjs +1 -1
  58. package/lib/types.d.ts +55 -12
  59. package/lib/utils.cjs +106 -1
  60. package/lib/utils.d.ts +105 -0
  61. package/package.json +2 -2
package/lib/constants.cjs CHANGED
@@ -1,7 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CouchDBKeys = exports.reservedAttributes = void 0;
4
+ /**
5
+ * @description Regular expression to identify reserved attributes in CouchDB
6
+ * @summary Matches any attribute that starts with an underscore
7
+ * @const reservedAttributes
8
+ * @memberOf module:for-couchdb
9
+ */
4
10
  exports.reservedAttributes = /^_.*$/g;
11
+ /**
12
+ * @description Key constants used in CouchDB operations
13
+ * @summary Collection of string constants for CouchDB document properties and operations
14
+ * @typedef {Object} CouchDBKeysType
15
+ * @property {string} SEPARATOR - Separator used for combining table name and ID
16
+ * @property {string} ID - CouchDB document ID field
17
+ * @property {string} REV - CouchDB document revision field
18
+ * @property {string} DELETED - CouchDB deleted document marker
19
+ * @property {string} TABLE - Table name marker
20
+ * @property {string} SEQUENCE - Sequence marker
21
+ * @property {string} DDOC - Design document marker
22
+ * @property {string} NATIVE - Native marker
23
+ * @property {string} INDEX - Index marker
24
+ * @memberOf module:for-couchdb
25
+ */
26
+ /**
27
+ * @description Key constants used in CouchDB operations
28
+ * @summary Collection of string constants for CouchDB document properties and operations
29
+ * @const CouchDBKeys
30
+ * @type {CouchDBKeysType}
31
+ * @memberOf module:for-couchdb
32
+ */
5
33
  exports.CouchDBKeys = {
6
34
  SEPARATOR: "__",
7
35
  ID: "_id",
@@ -13,4 +41,4 @@ exports.CouchDBKeys = {
13
41
  NATIVE: "__native",
14
42
  INDEX: "index",
15
43
  };
16
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RhbnRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2NvbnN0YW50cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBYSxRQUFBLGtCQUFrQixHQUFHLFFBQVEsQ0FBQztBQUU5QixRQUFBLFdBQVcsR0FBRztJQUN6QixTQUFTLEVBQUUsSUFBSTtJQUNmLEVBQUUsRUFBRSxLQUFLO0lBQ1QsR0FBRyxFQUFFLE1BQU07SUFDWCxPQUFPLEVBQUUsVUFBVTtJQUNuQixLQUFLLEVBQUUsU0FBUztJQUNoQixRQUFRLEVBQUUsWUFBWTtJQUN0QixJQUFJLEVBQUUsTUFBTTtJQUNaLE1BQU0sRUFBRSxVQUFVO0lBQ2xCLEtBQUssRUFBRSxPQUFPO0NBQ2YsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBjb25zdCByZXNlcnZlZEF0dHJpYnV0ZXMgPSAvXl8uKiQvZztcblxuZXhwb3J0IGNvbnN0IENvdWNoREJLZXlzID0ge1xuICBTRVBBUkFUT1I6IFwiX19cIixcbiAgSUQ6IFwiX2lkXCIsXG4gIFJFVjogXCJfcmV2XCIsXG4gIERFTEVURUQ6IFwiX2RlbGV0ZWRcIixcbiAgVEFCTEU6IFw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HMgdXNlZCBpbiBDb3VjaERCIG9wZXJhdGlvbnNcbiAqIEBzdW1tYXJ5IENvbGxlY3Rpb24gb2Ygc3RyaW5nIGNvbnN0YW50cyBmb3IgQ291Y2hEQiBkb2N1bWVudCBwcm9wZXJ0aWVzIGFuZCBvcGVyYXRpb25zXG4gKiBAY29uc3QgQ291Y2hEQktleXNcbiAqIEB0eXBlIHtDb3VjaERCS2V5c1R5cGV9XG4gKiBAbWVtYmVyT2YgbW9kdWxlOmZvci1jb3VjaGRiXG4gKi9cbmV4cG9ydCBjb25zdCBDb3VjaERCS2V5cyA9IHtcbiAgU0VQQVJBVE9SOiBcIl9fXCIsXG4gIElEOiBcIl9pZFwiLFxuICBSRVY6IFwiX3JldlwiLFxuICBERUxFVEVEOiBcIl9kZWxldGVkXCIsXG4gIFRBQkxFOiBcIj8/dGFibGVcIixcbiAgU0VRVUVOQ0U6IFwiPz9zZXF1ZW5jZVwiLFxuICBERE9DOiBcImRkb2NcIixcbiAgTkFUSVZFOiBcIl9fbmF0aXZlXCIsXG4gIElOREVYOiBcImluZGV4XCIsXG59O1xuIl19
@@ -1,4 +1,32 @@
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
+ */
1
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
+ */
2
30
  export declare const CouchDBKeys: {
3
31
  SEPARATOR: string;
4
32
  ID: string;
package/lib/errors.cjs CHANGED
@@ -2,10 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IndexError = void 0;
4
4
  const db_decorators_1 = require("@decaf-ts/db-decorators");
5
+ /**
6
+ * @description Error thrown when there is an issue with CouchDB indexes
7
+ * @summary Represents an error related to CouchDB index operations
8
+ * @param {string|Error} msg - The error message or Error object
9
+ * @class
10
+ * @category Errors
11
+ * @example
12
+ * // Example of using IndexError
13
+ * try {
14
+ * // Some code that might throw an index error
15
+ * throw new IndexError("Index not found");
16
+ * } catch (error) {
17
+ * if (error instanceof IndexError) {
18
+ * console.error("Index error occurred:", error.message);
19
+ * }
20
+ * }
21
+ */
5
22
  class IndexError extends db_decorators_1.BaseError {
6
23
  constructor(msg) {
7
24
  super(IndexError.name, msg, 404);
8
25
  }
9
26
  }
10
27
  exports.IndexError = IndexError;
11
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3JzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2Vycm9ycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSwyREFBb0Q7QUFFcEQsTUFBYSxVQUFXLFNBQVEseUJBQVM7SUFDdkMsWUFBWSxHQUFtQjtRQUM3QixLQUFLLENBQUMsVUFBVSxDQUFDLElBQUksRUFBRSxHQUFHLEVBQUUsR0FBRyxDQUFDLENBQUM7SUFDbkMsQ0FBQztDQUNGO0FBSkQsZ0NBSUMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBCYXNlRXJyb3IgfSBmcm9tIFwiQGRl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uICogLy8gRXhhbXBsZSBvZiB1c2luZyBJbmRleEVycm9yXG4gKiB0cnkge1xuICogICAvLyBTb21lIGNvZGUgdGhhdCBtaWdodCB0aHJvdyBhbiBpbmRleCBlcnJvclxuICogICB0aHJvdyBuZXcgSW5kZXhFcnJvcihcIkluZGV4IG5vdCBmb3VuZFwiKTtcbiAqIH0gY2F0Y2ggKGVycm9yKSB7XG4gKiAgIGlmIChlcnJvciBpbnN0YW5jZW9mIEluZGV4RXJyb3IpIHtcbiAqICAgICBjb25zb2xlLmVycm9yKFwiSW5kZXggZXJyb3Igb2NjdXJyZWQ6XCIsIGVycm9yLm1lc3NhZ2UpO1xuICogICB9XG4gKiB9XG4gKi9cbmV4cG9ydCBjbGFzcyBJbmRleEVycm9yIGV4dGVuZHMgQmFzZUVycm9yIHtcbiAgY29uc3RydWN0b3IobXNnOiBzdHJpbmcgfCBFcnJvcikge1xuICAgIHN1cGVyKEluZGV4RXJyb3IubmFtZSwgbXNnLCA0MDQpO1xuICB9XG59XG4iXX0=
package/lib/errors.d.ts CHANGED
@@ -1,4 +1,21 @@
1
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
+ */
2
19
  export declare class IndexError extends BaseError {
3
20
  constructor(msg: string | Error);
4
21
  }
@@ -4,25 +4,259 @@ import "reflect-metadata";
4
4
  import { Constructor, Model } from "@decaf-ts/decorator-validation";
5
5
  import { MangoQuery } from "./types";
6
6
  import { CouchDBStatement } from "./query";
7
+ /**
8
+ * @description Abstract adapter for CouchDB database operations
9
+ * @summary Provides a base implementation for CouchDB database operations, including CRUD operations, sequence management, and error handling
10
+ * @template Y - The scope type
11
+ * @template F - The repository flags type
12
+ * @template C - The context type
13
+ * @param {Y} scope - The scope for the adapter
14
+ * @param {string} flavour - The flavour of the adapter
15
+ * @param {string} [alias] - Optional alias for the adapter
16
+ * @class
17
+ * @example
18
+ * // Example of extending CouchDBAdapter
19
+ * class MyCouchDBAdapter extends CouchDBAdapter<MyScope, MyFlags, MyContext> {
20
+ * constructor(scope: MyScope) {
21
+ * super(scope, 'my-couchdb', 'my-alias');
22
+ * }
23
+ *
24
+ * // Implement abstract methods
25
+ * async index<M extends Model>(...models: Constructor<M>[]): Promise<void> {
26
+ * // Implementation
27
+ * }
28
+ *
29
+ * async raw<R>(rawInput: MangoQuery, docsOnly: boolean): Promise<R> {
30
+ * // Implementation
31
+ * }
32
+ *
33
+ * async create(tableName: string, id: string | number, model: Record<string, any>, ...args: any[]): Promise<Record<string, any>> {
34
+ * // Implementation
35
+ * }
36
+ *
37
+ * async read(tableName: string, id: string | number, ...args: any[]): Promise<Record<string, any>> {
38
+ * // Implementation
39
+ * }
40
+ *
41
+ * async update(tableName: string, id: string | number, model: Record<string, any>, ...args: any[]): Promise<Record<string, any>> {
42
+ * // Implementation
43
+ * }
44
+ *
45
+ * async delete(tableName: string, id: string | number, ...args: any[]): Promise<Record<string, any>> {
46
+ * // Implementation
47
+ * }
48
+ * }
49
+ */
7
50
  export declare abstract class CouchDBAdapter<Y, F extends RepositoryFlags, C extends Context<F>> extends Adapter<Y, MangoQuery, F, C> {
8
51
  protected constructor(scope: Y, flavour: string, alias?: string);
52
+ /**
53
+ * @description Creates a new CouchDB statement for querying
54
+ * @summary Factory method that creates a new CouchDBStatement instance for building queries
55
+ * @template M - The model type
56
+ * @return {CouchDBStatement<M, any>} A new CouchDBStatement instance
57
+ */
9
58
  Statement<M extends Model>(): CouchDBStatement<M, any>;
59
+ /**
60
+ * @description Creates a new CouchDB sequence
61
+ * @summary Factory method that creates a new CouchDBSequence instance for managing sequences
62
+ * @param {SequenceOptions} options - The options for the sequence
63
+ * @return {Promise<Sequence>} A promise that resolves to a new Sequence instance
64
+ */
10
65
  Sequence(options: SequenceOptions): Promise<Sequence>;
66
+ /**
67
+ * @description Initializes the adapter by creating indexes for all managed models
68
+ * @summary Sets up the necessary database indexes for all models managed by this adapter
69
+ * @return {Promise<void>} A promise that resolves when initialization is complete
70
+ */
11
71
  initialize(): Promise<void>;
72
+ /**
73
+ * @description Creates indexes for the given models
74
+ * @summary Abstract method that must be implemented to create database indexes for the specified models
75
+ * @template M - The model type
76
+ * @param {...Constructor<M>} models - The model constructors to create indexes for
77
+ * @return {Promise<void>} A promise that resolves when all indexes are created
78
+ */
12
79
  protected abstract index<M extends Model>(...models: Constructor<M>[]): Promise<void>;
80
+ /**
81
+ * @description Executes a raw Mango query against the database
82
+ * @summary Abstract method that must be implemented to execute raw Mango queries
83
+ * @template R - The result type
84
+ * @param {MangoQuery} rawInput - The raw Mango query to execute
85
+ * @param {boolean} docsOnly - Whether to return only the documents or the full response
86
+ * @return {Promise<R>} A promise that resolves to the query result
87
+ */
13
88
  abstract raw<R>(rawInput: MangoQuery, docsOnly: boolean): Promise<R>;
89
+ /**
90
+ * @description Assigns metadata to a model
91
+ * @summary Adds revision metadata to a model as a non-enumerable property
92
+ * @param {Record<string, any>} model - The model to assign metadata to
93
+ * @param {string} rev - The revision string to assign
94
+ * @return {Record<string, any>} The model with metadata assigned
95
+ */
14
96
  protected assignMetadata(model: Record<string, any>, rev: string): Record<string, any>;
97
+ /**
98
+ * @description Assigns metadata to multiple models
99
+ * @summary Adds revision metadata to multiple models as non-enumerable properties
100
+ * @param models - The models to assign metadata to
101
+ * @param {string[]} revs - The revision strings to assign
102
+ * @return The models with metadata assigned
103
+ */
15
104
  protected assignMultipleMetadata(models: Record<string, any>[], revs: string[]): Record<string, any>[];
105
+ /**
106
+ * @description Prepares a record for creation
107
+ * @summary Adds necessary CouchDB fields to a record before creation
108
+ * @param {string} tableName - The name of the table
109
+ * @param {string|number} id - The ID of the record
110
+ * @param {Record<string, any>} model - The model to prepare
111
+ * @return A tuple containing the tableName, id, and prepared record
112
+ */
16
113
  protected createPrefix(tableName: string, id: string | number, model: Record<string, any>): (string | number | Record<string, any>)[];
114
+ /**
115
+ * @description Creates a new record in the database
116
+ * @summary Abstract method that must be implemented to create a new record
117
+ * @param {string} tableName - The name of the table
118
+ * @param {string|number} id - The ID of the record
119
+ * @param {Record<string, any>} model - The model to create
120
+ * @param {...any[]} args - Additional arguments
121
+ * @return {Promise<Record<string, any>>} A promise that resolves to the created record
122
+ */
17
123
  abstract create(tableName: string, id: string | number, model: Record<string, any>, ...args: any[]): Promise<Record<string, any>>;
124
+ /**
125
+ * @description Prepares multiple records for creation
126
+ * @summary Adds necessary CouchDB fields to multiple records before creation
127
+ * @param {string} tableName - The name of the table
128
+ * @param {string[]|number[]} ids - The IDs of the records
129
+ * @param models - The models to prepare
130
+ * @return A tuple containing the tableName, ids, and prepared records
131
+ * @throws {InternalError} If ids and models arrays have different lengths
132
+ */
18
133
  protected createAllPrefix(tableName: string, ids: string[] | number[], models: Record<string, any>[]): (string | string[] | number[] | Record<string, any>[])[];
134
+ /**
135
+ * @description Reads a record from the database
136
+ * @summary Abstract method that must be implemented to read a record
137
+ * @param {string} tableName - The name of the table
138
+ * @param {string|number} id - The ID of the record
139
+ * @param {...any[]} args - Additional arguments
140
+ * @return {Promise<Record<string, any>>} A promise that resolves to the read record
141
+ */
19
142
  abstract read(tableName: string, id: string | number, ...args: any[]): Promise<Record<string, any>>;
143
+ /**
144
+ * @description Prepares a record for update
145
+ * @summary Adds necessary CouchDB fields to a record before update
146
+ * @param {string} tableName - The name of the table
147
+ * @param {string|number} id - The ID of the record
148
+ * @param model - The model to prepare
149
+ * @return A tuple containing the tableName, id, and prepared record
150
+ * @throws {InternalError} If no revision number is found in the model
151
+ */
20
152
  updatePrefix(tableName: string, id: string | number, model: Record<string, any>): (string | number | Record<string, any>)[];
153
+ /**
154
+ * @description Updates a record in the database
155
+ * @summary Abstract method that must be implemented to update a record
156
+ * @param {string} tableName - The name of the table
157
+ * @param {string|number} id - The ID of the record
158
+ * @param {Record<string, any>} model - The model to update
159
+ * @param {any[]} args - Additional arguments
160
+ * @return A promise that resolves to the updated record
161
+ */
21
162
  abstract update(tableName: string, id: string | number, model: Record<string, any>, ...args: any[]): Promise<Record<string, any>>;
163
+ /**
164
+ * @description Prepares multiple records for update
165
+ * @summary Adds necessary CouchDB fields to multiple records before update
166
+ * @param {string} tableName - The name of the table
167
+ * @param {string[]|number[]} ids - The IDs of the records
168
+ * @param models - The models to prepare
169
+ * @return A tuple containing the tableName, ids, and prepared records
170
+ * @throws {InternalError} If ids and models arrays have different lengths or if no revision number is found in a model
171
+ */
22
172
  protected updateAllPrefix(tableName: string, ids: string[] | number[], models: Record<string, any>[]): (string | string[] | number[] | Record<string, any>[])[];
173
+ /**
174
+ * @description Deletes a record from the database
175
+ * @summary Abstract method that must be implemented to delete a record
176
+ * @param {string} tableName - The name of the table
177
+ * @param {string|number} id - The ID of the record
178
+ * @param {any[]} args - Additional arguments
179
+ * @return A promise that resolves to the deleted record
180
+ */
23
181
  abstract delete(tableName: string, id: string | number, ...args: any[]): Promise<Record<string, any>>;
182
+ /**
183
+ * @description Generates a CouchDB document ID
184
+ * @summary Combines the table name and ID to create a CouchDB document ID
185
+ * @param {string} tableName - The name of the table
186
+ * @param {string|number} id - The ID of the record
187
+ * @return {string} The generated CouchDB document ID
188
+ */
24
189
  protected generateId(tableName: string, id: string | number): string;
190
+ /**
191
+ * @description Parses an error and converts it to a BaseError
192
+ * @summary Converts various error types to appropriate BaseError subtypes
193
+ * @param {Error|string} err - The error to parse
194
+ * @param {string} [reason] - Optional reason for the error
195
+ * @return {BaseError} The parsed error as a BaseError
196
+ */
25
197
  parseError(err: Error | string, reason?: string): BaseError;
198
+ /**
199
+ * @description Checks if an attribute is reserved
200
+ * @summary Determines if an attribute name is reserved in CouchDB
201
+ * @param {string} attr - The attribute name to check
202
+ * @return {boolean} True if the attribute is reserved, false otherwise
203
+ */
26
204
  protected isReserved(attr: string): boolean;
205
+ /**
206
+ * @description Static method to parse an error and convert it to a BaseError
207
+ * @summary Converts various error types to appropriate BaseError subtypes based on error codes and messages
208
+ * @param {Error|string} err - The error to parse
209
+ * @param {string} [reason] - Optional reason for the error
210
+ * @return {BaseError} The parsed error as a BaseError
211
+ * @mermaid
212
+ * sequenceDiagram
213
+ * participant Caller
214
+ * participant parseError
215
+ * participant ErrorTypes
216
+ *
217
+ * Caller->>parseError: err, reason
218
+ * Note over parseError: Check if err is already a BaseError
219
+ * alt err is BaseError
220
+ * parseError-->>Caller: return err
221
+ * else err is string
222
+ * Note over parseError: Extract code from string
223
+ * alt code matches "already exist|update conflict"
224
+ * parseError->>ErrorTypes: new ConflictError(code)
225
+ * ErrorTypes-->>Caller: ConflictError
226
+ * else code matches "missing|deleted"
227
+ * parseError->>ErrorTypes: new NotFoundError(code)
228
+ * ErrorTypes-->>Caller: NotFoundError
229
+ * end
230
+ * else err has code property
231
+ * Note over parseError: Extract code and reason
232
+ * else err has statusCode property
233
+ * Note over parseError: Extract code and reason
234
+ * else
235
+ * Note over parseError: Use err.message as code
236
+ * end
237
+ *
238
+ * Note over parseError: Switch on code
239
+ * alt code is 401, 412, or 409
240
+ * parseError->>ErrorTypes: new ConflictError(reason)
241
+ * ErrorTypes-->>Caller: ConflictError
242
+ * else code is 404
243
+ * parseError->>ErrorTypes: new NotFoundError(reason)
244
+ * ErrorTypes-->>Caller: NotFoundError
245
+ * else code is 400
246
+ * alt code matches "No index exists"
247
+ * parseError->>ErrorTypes: new IndexError(err)
248
+ * ErrorTypes-->>Caller: IndexError
249
+ * else
250
+ * parseError->>ErrorTypes: new InternalError(err)
251
+ * ErrorTypes-->>Caller: InternalError
252
+ * end
253
+ * else code matches "ECONNREFUSED"
254
+ * parseError->>ErrorTypes: new ConnectionError(err)
255
+ * ErrorTypes-->>Caller: ConnectionError
256
+ * else
257
+ * parseError->>ErrorTypes: new InternalError(err)
258
+ * ErrorTypes-->>Caller: InternalError
259
+ * end
260
+ */
27
261
  protected static parseError(err: Error | string, reason?: string): BaseError;
28
262
  }