@decaf-ts/for-couchdb 0.4.3 → 0.4.5
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/dist/for-couchdb.cjs +1 -1
- package/dist/for-couchdb.cjs.map +1 -1
- package/dist/for-couchdb.js +1 -1
- package/dist/for-couchdb.js.map +1 -1
- package/lib/adapter.cjs +77 -37
- package/lib/adapter.d.ts +50 -22
- package/lib/adapter.js.map +1 -1
- package/lib/esm/adapter.d.ts +50 -22
- package/lib/esm/adapter.js +70 -30
- package/lib/esm/adapter.js.map +1 -1
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +2 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/indexes/generator.js +4 -3
- package/lib/esm/indexes/generator.js.map +1 -1
- package/lib/esm/query/Paginator.d.ts +1 -1
- package/lib/esm/query/Paginator.js +4 -3
- package/lib/esm/query/Paginator.js.map +1 -1
- package/lib/esm/query/Statement.d.ts +6 -5
- package/lib/esm/query/Statement.js +8 -7
- package/lib/esm/query/Statement.js.map +1 -1
- package/lib/esm/repository.d.ts +39 -0
- package/lib/esm/repository.js +147 -0
- package/lib/esm/repository.js.map +1 -0
- package/lib/esm/sequences/Sequence.d.ts +19 -18
- package/lib/esm/sequences/Sequence.js +33 -28
- package/lib/esm/sequences/Sequence.js.map +1 -1
- package/lib/index.cjs +2 -2
- package/lib/index.d.ts +2 -2
- package/lib/index.js.map +1 -1
- package/lib/indexes/generator.cjs +3 -2
- package/lib/indexes/generator.js.map +1 -1
- package/lib/query/Paginator.cjs +4 -3
- package/lib/query/Paginator.d.ts +1 -1
- package/lib/query/Paginator.js.map +1 -1
- package/lib/query/Statement.cjs +7 -6
- package/lib/query/Statement.d.ts +6 -5
- package/lib/query/Statement.js.map +1 -1
- package/lib/repository.cjs +151 -0
- package/lib/repository.d.ts +39 -0
- package/lib/repository.js.map +1 -0
- package/lib/sequences/Sequence.cjs +31 -26
- package/lib/sequences/Sequence.d.ts +19 -18
- package/lib/sequences/Sequence.js.map +1 -1
- package/package.json +1 -2
- package/lib/esm/interfaces/CouchDBRepository.d.ts +0 -16
- package/lib/esm/interfaces/CouchDBRepository.js +0 -2
- package/lib/esm/interfaces/CouchDBRepository.js.map +0 -1
- package/lib/esm/interfaces/index.d.ts +0 -1
- package/lib/esm/interfaces/index.js +0 -2
- package/lib/esm/interfaces/index.js.map +0 -1
- package/lib/interfaces/CouchDBRepository.cjs +0 -3
- package/lib/interfaces/CouchDBRepository.d.ts +0 -16
- package/lib/interfaces/CouchDBRepository.js.map +0 -1
- package/lib/interfaces/index.cjs +0 -18
- package/lib/interfaces/index.d.ts +0 -1
- package/lib/interfaces/index.js.map +0 -1
package/lib/adapter.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Adapter, Sequence, type SequenceOptions } from "@decaf-ts/core";
|
|
2
|
-
import { BaseError
|
|
2
|
+
import { BaseError } from "@decaf-ts/db-decorators";
|
|
3
|
+
import type { Context, PrimaryKeyType } from "@decaf-ts/db-decorators";
|
|
3
4
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
4
|
-
import { MangoQuery } from "./types";
|
|
5
|
+
import { type MangoQuery } from "./types";
|
|
5
6
|
import { CouchDBStatement } from "./query";
|
|
6
|
-
import {
|
|
7
|
+
import { MaybeContextualArg } from "@decaf-ts/core";
|
|
8
|
+
import type { Constructor } from "@decaf-ts/decoration";
|
|
9
|
+
import { Repository } from "@decaf-ts/core";
|
|
7
10
|
/**
|
|
8
11
|
* @description Abstract adapter for CouchDB database operations
|
|
9
12
|
* @summary Provides a base implementation for CouchDB database operations, including CRUD operations, sequence management, and error handling
|
|
@@ -47,15 +50,15 @@ import { Constructor } from "@decaf-ts/decoration";
|
|
|
47
50
|
* }
|
|
48
51
|
* }
|
|
49
52
|
*/
|
|
50
|
-
export declare abstract class CouchDBAdapter<
|
|
51
|
-
protected constructor(scope:
|
|
53
|
+
export declare abstract class CouchDBAdapter<CONF, CONN, C extends Context<any>> extends Adapter<CONF, CONN, MangoQuery, C> {
|
|
54
|
+
protected constructor(scope: CONF, flavour: string, alias?: string);
|
|
52
55
|
/**
|
|
53
56
|
* @description Creates a new CouchDB statement for querying
|
|
54
57
|
* @summary Factory method that creates a new CouchDBStatement instance for building queries
|
|
55
58
|
* @template M - The model type
|
|
56
59
|
* @return {CouchDBStatement<M, any>} A new CouchDBStatement instance
|
|
57
60
|
*/
|
|
58
|
-
Statement<M extends Model>(): CouchDBStatement<M, any>;
|
|
61
|
+
Statement<M extends Model>(): CouchDBStatement<M, Adapter<CONF, CONN, MangoQuery, C>, any>;
|
|
59
62
|
/**
|
|
60
63
|
* @description Creates a new CouchDB sequence
|
|
61
64
|
* @summary Factory method that creates a new CouchDBSequence instance for managing sequences
|
|
@@ -69,6 +72,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
69
72
|
* @return {Promise<void>} A promise that resolves when initialization is complete
|
|
70
73
|
*/
|
|
71
74
|
initialize(): Promise<void>;
|
|
75
|
+
repository<R extends Repository<any, Adapter<CONF, CONN, MangoQuery, C>>>(): Constructor<R>;
|
|
72
76
|
/**
|
|
73
77
|
* @description Creates indexes for the given models
|
|
74
78
|
* @summary Abstract method that must be implemented to create database indexes for the specified models
|
|
@@ -79,13 +83,14 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
79
83
|
protected abstract index<M extends Model>(...models: Constructor<M>[]): Promise<void>;
|
|
80
84
|
/**
|
|
81
85
|
* @description Executes a raw Mango query against the database
|
|
82
|
-
* @summary Abstract method that must be implemented to execute raw Mango queries
|
|
86
|
+
* @summary Abstract method that must be implemented to execute raw Mango queries. Implementations may treat the first
|
|
87
|
+
* additional argument as a boolean `docsOnly` flag before the contextual arguments provided by repositories.
|
|
83
88
|
* @template R - The result type
|
|
84
89
|
* @param {MangoQuery} rawInput - The raw Mango query to execute
|
|
85
|
-
* @param {
|
|
90
|
+
* @param {...MaybeContextualArg<C>} args - Optional `docsOnly` flag followed by contextual arguments
|
|
86
91
|
* @return {Promise<R>} A promise that resolves to the query result
|
|
87
92
|
*/
|
|
88
|
-
abstract raw<R>(rawInput: MangoQuery,
|
|
93
|
+
abstract raw<R>(rawInput: MangoQuery, ...args: MaybeContextualArg<C>): Promise<R>;
|
|
89
94
|
/**
|
|
90
95
|
* @description Assigns metadata to a model
|
|
91
96
|
* @summary Adds revision metadata to a model as a non-enumerable property
|
|
@@ -110,7 +115,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
110
115
|
* @param {Record<string, any>} model - The model to prepare
|
|
111
116
|
* @return A tuple containing the tableName, id, and prepared record
|
|
112
117
|
*/
|
|
113
|
-
protected createPrefix(
|
|
118
|
+
protected createPrefix<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: MaybeContextualArg<C>): [Constructor<M>, PrimaryKeyType, Record<string, any>, ...any[], Context];
|
|
114
119
|
/**
|
|
115
120
|
* @description Creates a new record in the database
|
|
116
121
|
* @summary Abstract method that must be implemented to create a new record
|
|
@@ -120,7 +125,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
120
125
|
* @param {...any[]} args - Additional arguments
|
|
121
126
|
* @return {Promise<Record<string, any>>} A promise that resolves to the created record
|
|
122
127
|
*/
|
|
123
|
-
abstract create(tableName:
|
|
128
|
+
abstract create<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: MaybeContextualArg<C>): Promise<Record<string, any>>;
|
|
124
129
|
/**
|
|
125
130
|
* @description Prepares multiple records for creation
|
|
126
131
|
* @summary Adds necessary CouchDB fields to multiple records before creation
|
|
@@ -130,7 +135,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
130
135
|
* @return A tuple containing the tableName, ids, and prepared records
|
|
131
136
|
* @throws {InternalError} If ids and models arrays have different lengths
|
|
132
137
|
*/
|
|
133
|
-
protected createAllPrefix(
|
|
138
|
+
protected createAllPrefix<M extends Model>(clazz: Constructor<M>, ids: string[] | number[], models: Record<string, any>[], ...args: MaybeContextualArg<C>): any[];
|
|
134
139
|
/**
|
|
135
140
|
* @description Reads a record from the database
|
|
136
141
|
* @summary Abstract method that must be implemented to read a record
|
|
@@ -139,7 +144,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
139
144
|
* @param {...any[]} args - Additional arguments
|
|
140
145
|
* @return {Promise<Record<string, any>>} A promise that resolves to the read record
|
|
141
146
|
*/
|
|
142
|
-
abstract read(tableName:
|
|
147
|
+
abstract read<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, ...args: MaybeContextualArg<C>): Promise<Record<string, any>>;
|
|
143
148
|
/**
|
|
144
149
|
* @description Prepares a record for update
|
|
145
150
|
* @summary Adds necessary CouchDB fields to a record before update
|
|
@@ -150,7 +155,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
150
155
|
* @return A tuple containing the tableName, id, and prepared record
|
|
151
156
|
* @throws {InternalError} If no revision number is found in the model
|
|
152
157
|
*/
|
|
153
|
-
updatePrefix(
|
|
158
|
+
updatePrefix<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: MaybeContextualArg<C>): any[];
|
|
154
159
|
/**
|
|
155
160
|
* @description Updates a record in the database
|
|
156
161
|
* @summary Abstract method that must be implemented to update a record
|
|
@@ -160,7 +165,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
160
165
|
* @param {any[]} args - Additional arguments
|
|
161
166
|
* @return A promise that resolves to the updated record
|
|
162
167
|
*/
|
|
163
|
-
abstract update(tableName:
|
|
168
|
+
abstract update<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: MaybeContextualArg<C>): Promise<Record<string, any>>;
|
|
164
169
|
/**
|
|
165
170
|
* @description Prepares multiple records for update
|
|
166
171
|
* @summary Adds necessary CouchDB fields to multiple records before update
|
|
@@ -170,16 +175,16 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
170
175
|
* @return A tuple containing the tableName, ids, and prepared records
|
|
171
176
|
* @throws {InternalError} If ids and models arrays have different lengths or if no revision number is found in a model
|
|
172
177
|
*/
|
|
173
|
-
protected updateAllPrefix(
|
|
178
|
+
protected updateAllPrefix<M extends Model>(clazz: Constructor<M>, ids: PrimaryKeyType[], models: Record<string, any>[], ...args: MaybeContextualArg<C>): any[];
|
|
174
179
|
/**
|
|
175
180
|
* @description Deletes a record from the database
|
|
176
181
|
* @summary Abstract method that must be implemented to delete a record
|
|
177
|
-
* @param {
|
|
178
|
-
* @param {
|
|
182
|
+
* @param {Constructor<M>} tableName - The name of the table
|
|
183
|
+
* @param {PrimaryKeyType} id - The ID of the record
|
|
179
184
|
* @param {any[]} args - Additional arguments
|
|
180
185
|
* @return A promise that resolves to the deleted record
|
|
181
186
|
*/
|
|
182
|
-
abstract delete(tableName:
|
|
187
|
+
abstract delete<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, ...args: MaybeContextualArg<C>): Promise<Record<string, any>>;
|
|
183
188
|
/**
|
|
184
189
|
* @description Generates a CouchDB document ID
|
|
185
190
|
* @summary Combines the table name and ID to create a CouchDB document ID
|
|
@@ -187,7 +192,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
187
192
|
* @param {string|number} id - The ID of the record
|
|
188
193
|
* @return {string} The generated CouchDB document ID
|
|
189
194
|
*/
|
|
190
|
-
protected generateId(tableName: string, id:
|
|
195
|
+
protected generateId(tableName: string, id: PrimaryKeyType): string;
|
|
191
196
|
/**
|
|
192
197
|
* @description Parses an error and converts it to a BaseError
|
|
193
198
|
* @summary Converts various error types to appropriate BaseError subtypes
|
|
@@ -195,7 +200,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
195
200
|
* @param {string} [reason] - Optional reason for the error
|
|
196
201
|
* @return {BaseError} The parsed error as a BaseError
|
|
197
202
|
*/
|
|
198
|
-
parseError(err: Error | string, reason?: string):
|
|
203
|
+
parseError<E extends BaseError>(err: Error | string, reason?: string): E;
|
|
199
204
|
/**
|
|
200
205
|
* @description Checks if an attribute is reserved
|
|
201
206
|
* @summary Determines if an attribute name is reserved in CouchDB
|
|
@@ -259,5 +264,28 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
259
264
|
* ErrorTypes-->>Caller: InternalError
|
|
260
265
|
* end
|
|
261
266
|
*/
|
|
262
|
-
protected static parseError(err: Error | string, reason?: string):
|
|
267
|
+
protected static parseError<E extends BaseError>(err: Error | string, reason?: string): E;
|
|
268
|
+
/**
|
|
269
|
+
* @description Sets metadata on a model instance.
|
|
270
|
+
* @summary Attaches metadata to a model instance using a non-enumerable property.
|
|
271
|
+
* @template M - The model type that extends Model.
|
|
272
|
+
* @param {M} model - The model instance.
|
|
273
|
+
* @param {any} metadata - The metadata to attach to the model.
|
|
274
|
+
*/
|
|
275
|
+
static setMetadata<M extends Model>(model: M, metadata: any): void;
|
|
276
|
+
/**
|
|
277
|
+
* @description Gets metadata from a model instance.
|
|
278
|
+
* @summary Retrieves previously attached metadata from a model instance.
|
|
279
|
+
* @template M - The model type that extends Model.
|
|
280
|
+
* @param {M} model - The model instance.
|
|
281
|
+
* @return {any} The metadata or undefined if not found.
|
|
282
|
+
*/
|
|
283
|
+
static getMetadata<M extends Model>(model: M): any;
|
|
284
|
+
/**
|
|
285
|
+
* @description Removes metadata from a model instance.
|
|
286
|
+
* @summary Deletes the metadata property from a model instance.
|
|
287
|
+
* @template M - The model type that extends Model.
|
|
288
|
+
* @param {M} model - The model instance.
|
|
289
|
+
*/
|
|
290
|
+
static removeMetadata<M extends Model>(model: M): void;
|
|
263
291
|
}
|
package/lib/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAMwB;AACxB,+CAA8D;AAC9D,2DAMiC;AAEjC,uDAAuD;AACvD,yEAAuD;AACvD,yCAAsC;AAEtC,6CAA2C;AAG3C,+CAA0C;AAC1C,iDAAiD;AAGjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAsB,cAIpB,SAAQ,cAAkC;IAC1C,YAAsB,KAAW,EAAE,OAAe,EAAE,KAAc;QAChE,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QAC7B,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YACvE,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;YACpB,IAAA,4BAAY,EAAC,IAAI,EAAE,CAAC,EAAG,IAAY,CAAC,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IAEH,SAAS;QAKP,OAAO,IAAI,wBAAgB,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IAEG,AAAN,KAAK,CAAC,QAAQ,CAAC,OAAwB;QACrC,OAAO,IAAI,0BAAe,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACM,KAAK,CAAC,UAAU;QACvB,MAAM,aAAa,GAAG,cAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACnD,OAAO,IAAI,CAAC,KAA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IAAI;YACd,KAAK,EAAE,QAAQ;SAChB,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,CAAkB,KAAQ;QAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAChD,KAAK,EACL,sBAAe,CAAC,QAAQ,CACzB,CAAC;QACF,OAAO,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACnD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAkB,KAAQ;QAC7C,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAChD,KAAK,EACL,sBAAe,CAAC,QAAQ,CACzB,CAAC;QACF,IAAI,UAAU;YAAE,OAAQ,KAAa,CAAC,sBAAe,CAAC,QAAQ,CAAC,CAAC;IAClE,CAAC;CACF;AAtdD,wCAsdC;AAlcC;IADC,IAAA,eAAK,GAAE;;;oCACsB,wBAAgB;+CAM7C;AASK;IADL,IAAA,eAAK,GAAE;;;;8CAGP;AAmDS;IADT,IAAA,eAAK,GAAE;;;;oDAQP;AAUS;IADT,IAAA,eAAK,GAAE;;;;4DAUP;AAWS;IADT,IAAA,eAAK,GAAE;;;;kDAcP;AA4BS;IADT,IAAA,eAAK,GAAE;;;;qDAmBP;AA2BD;IADC,IAAA,eAAK,GAAE;;;;kDAoBP;AA4BS;IADT,IAAA,eAAK,GAAE;;;;qDAyBP"}
|
package/lib/esm/adapter.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Adapter, Sequence, type SequenceOptions } from "@decaf-ts/core";
|
|
2
|
-
import { BaseError
|
|
2
|
+
import { BaseError } from "@decaf-ts/db-decorators";
|
|
3
|
+
import type { Context, PrimaryKeyType } from "@decaf-ts/db-decorators";
|
|
3
4
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
4
|
-
import { MangoQuery } from "./types";
|
|
5
|
+
import { type MangoQuery } from "./types";
|
|
5
6
|
import { CouchDBStatement } from "./query";
|
|
6
|
-
import {
|
|
7
|
+
import { MaybeContextualArg } from "@decaf-ts/core";
|
|
8
|
+
import type { Constructor } from "@decaf-ts/decoration";
|
|
9
|
+
import { Repository } from "@decaf-ts/core";
|
|
7
10
|
/**
|
|
8
11
|
* @description Abstract adapter for CouchDB database operations
|
|
9
12
|
* @summary Provides a base implementation for CouchDB database operations, including CRUD operations, sequence management, and error handling
|
|
@@ -47,15 +50,15 @@ import { Constructor } from "@decaf-ts/decoration";
|
|
|
47
50
|
* }
|
|
48
51
|
* }
|
|
49
52
|
*/
|
|
50
|
-
export declare abstract class CouchDBAdapter<
|
|
51
|
-
protected constructor(scope:
|
|
53
|
+
export declare abstract class CouchDBAdapter<CONF, CONN, C extends Context<any>> extends Adapter<CONF, CONN, MangoQuery, C> {
|
|
54
|
+
protected constructor(scope: CONF, flavour: string, alias?: string);
|
|
52
55
|
/**
|
|
53
56
|
* @description Creates a new CouchDB statement for querying
|
|
54
57
|
* @summary Factory method that creates a new CouchDBStatement instance for building queries
|
|
55
58
|
* @template M - The model type
|
|
56
59
|
* @return {CouchDBStatement<M, any>} A new CouchDBStatement instance
|
|
57
60
|
*/
|
|
58
|
-
Statement<M extends Model>(): CouchDBStatement<M, any>;
|
|
61
|
+
Statement<M extends Model>(): CouchDBStatement<M, Adapter<CONF, CONN, MangoQuery, C>, any>;
|
|
59
62
|
/**
|
|
60
63
|
* @description Creates a new CouchDB sequence
|
|
61
64
|
* @summary Factory method that creates a new CouchDBSequence instance for managing sequences
|
|
@@ -69,6 +72,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
69
72
|
* @return {Promise<void>} A promise that resolves when initialization is complete
|
|
70
73
|
*/
|
|
71
74
|
initialize(): Promise<void>;
|
|
75
|
+
repository<R extends Repository<any, Adapter<CONF, CONN, MangoQuery, C>>>(): Constructor<R>;
|
|
72
76
|
/**
|
|
73
77
|
* @description Creates indexes for the given models
|
|
74
78
|
* @summary Abstract method that must be implemented to create database indexes for the specified models
|
|
@@ -79,13 +83,14 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
79
83
|
protected abstract index<M extends Model>(...models: Constructor<M>[]): Promise<void>;
|
|
80
84
|
/**
|
|
81
85
|
* @description Executes a raw Mango query against the database
|
|
82
|
-
* @summary Abstract method that must be implemented to execute raw Mango queries
|
|
86
|
+
* @summary Abstract method that must be implemented to execute raw Mango queries. Implementations may treat the first
|
|
87
|
+
* additional argument as a boolean `docsOnly` flag before the contextual arguments provided by repositories.
|
|
83
88
|
* @template R - The result type
|
|
84
89
|
* @param {MangoQuery} rawInput - The raw Mango query to execute
|
|
85
|
-
* @param {
|
|
90
|
+
* @param {...MaybeContextualArg<C>} args - Optional `docsOnly` flag followed by contextual arguments
|
|
86
91
|
* @return {Promise<R>} A promise that resolves to the query result
|
|
87
92
|
*/
|
|
88
|
-
abstract raw<R>(rawInput: MangoQuery,
|
|
93
|
+
abstract raw<R>(rawInput: MangoQuery, ...args: MaybeContextualArg<C>): Promise<R>;
|
|
89
94
|
/**
|
|
90
95
|
* @description Assigns metadata to a model
|
|
91
96
|
* @summary Adds revision metadata to a model as a non-enumerable property
|
|
@@ -110,7 +115,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
110
115
|
* @param {Record<string, any>} model - The model to prepare
|
|
111
116
|
* @return A tuple containing the tableName, id, and prepared record
|
|
112
117
|
*/
|
|
113
|
-
protected createPrefix(
|
|
118
|
+
protected createPrefix<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: MaybeContextualArg<C>): [Constructor<M>, PrimaryKeyType, Record<string, any>, ...any[], Context];
|
|
114
119
|
/**
|
|
115
120
|
* @description Creates a new record in the database
|
|
116
121
|
* @summary Abstract method that must be implemented to create a new record
|
|
@@ -120,7 +125,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
120
125
|
* @param {...any[]} args - Additional arguments
|
|
121
126
|
* @return {Promise<Record<string, any>>} A promise that resolves to the created record
|
|
122
127
|
*/
|
|
123
|
-
abstract create(tableName:
|
|
128
|
+
abstract create<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: MaybeContextualArg<C>): Promise<Record<string, any>>;
|
|
124
129
|
/**
|
|
125
130
|
* @description Prepares multiple records for creation
|
|
126
131
|
* @summary Adds necessary CouchDB fields to multiple records before creation
|
|
@@ -130,7 +135,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
130
135
|
* @return A tuple containing the tableName, ids, and prepared records
|
|
131
136
|
* @throws {InternalError} If ids and models arrays have different lengths
|
|
132
137
|
*/
|
|
133
|
-
protected createAllPrefix(
|
|
138
|
+
protected createAllPrefix<M extends Model>(clazz: Constructor<M>, ids: string[] | number[], models: Record<string, any>[], ...args: MaybeContextualArg<C>): any[];
|
|
134
139
|
/**
|
|
135
140
|
* @description Reads a record from the database
|
|
136
141
|
* @summary Abstract method that must be implemented to read a record
|
|
@@ -139,7 +144,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
139
144
|
* @param {...any[]} args - Additional arguments
|
|
140
145
|
* @return {Promise<Record<string, any>>} A promise that resolves to the read record
|
|
141
146
|
*/
|
|
142
|
-
abstract read(tableName:
|
|
147
|
+
abstract read<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, ...args: MaybeContextualArg<C>): Promise<Record<string, any>>;
|
|
143
148
|
/**
|
|
144
149
|
* @description Prepares a record for update
|
|
145
150
|
* @summary Adds necessary CouchDB fields to a record before update
|
|
@@ -150,7 +155,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
150
155
|
* @return A tuple containing the tableName, id, and prepared record
|
|
151
156
|
* @throws {InternalError} If no revision number is found in the model
|
|
152
157
|
*/
|
|
153
|
-
updatePrefix(
|
|
158
|
+
updatePrefix<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: MaybeContextualArg<C>): any[];
|
|
154
159
|
/**
|
|
155
160
|
* @description Updates a record in the database
|
|
156
161
|
* @summary Abstract method that must be implemented to update a record
|
|
@@ -160,7 +165,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
160
165
|
* @param {any[]} args - Additional arguments
|
|
161
166
|
* @return A promise that resolves to the updated record
|
|
162
167
|
*/
|
|
163
|
-
abstract update(tableName:
|
|
168
|
+
abstract update<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: MaybeContextualArg<C>): Promise<Record<string, any>>;
|
|
164
169
|
/**
|
|
165
170
|
* @description Prepares multiple records for update
|
|
166
171
|
* @summary Adds necessary CouchDB fields to multiple records before update
|
|
@@ -170,16 +175,16 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
170
175
|
* @return A tuple containing the tableName, ids, and prepared records
|
|
171
176
|
* @throws {InternalError} If ids and models arrays have different lengths or if no revision number is found in a model
|
|
172
177
|
*/
|
|
173
|
-
protected updateAllPrefix(
|
|
178
|
+
protected updateAllPrefix<M extends Model>(clazz: Constructor<M>, ids: PrimaryKeyType[], models: Record<string, any>[], ...args: MaybeContextualArg<C>): any[];
|
|
174
179
|
/**
|
|
175
180
|
* @description Deletes a record from the database
|
|
176
181
|
* @summary Abstract method that must be implemented to delete a record
|
|
177
|
-
* @param {
|
|
178
|
-
* @param {
|
|
182
|
+
* @param {Constructor<M>} tableName - The name of the table
|
|
183
|
+
* @param {PrimaryKeyType} id - The ID of the record
|
|
179
184
|
* @param {any[]} args - Additional arguments
|
|
180
185
|
* @return A promise that resolves to the deleted record
|
|
181
186
|
*/
|
|
182
|
-
abstract delete(tableName:
|
|
187
|
+
abstract delete<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, ...args: MaybeContextualArg<C>): Promise<Record<string, any>>;
|
|
183
188
|
/**
|
|
184
189
|
* @description Generates a CouchDB document ID
|
|
185
190
|
* @summary Combines the table name and ID to create a CouchDB document ID
|
|
@@ -187,7 +192,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
187
192
|
* @param {string|number} id - The ID of the record
|
|
188
193
|
* @return {string} The generated CouchDB document ID
|
|
189
194
|
*/
|
|
190
|
-
protected generateId(tableName: string, id:
|
|
195
|
+
protected generateId(tableName: string, id: PrimaryKeyType): string;
|
|
191
196
|
/**
|
|
192
197
|
* @description Parses an error and converts it to a BaseError
|
|
193
198
|
* @summary Converts various error types to appropriate BaseError subtypes
|
|
@@ -195,7 +200,7 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
195
200
|
* @param {string} [reason] - Optional reason for the error
|
|
196
201
|
* @return {BaseError} The parsed error as a BaseError
|
|
197
202
|
*/
|
|
198
|
-
parseError(err: Error | string, reason?: string):
|
|
203
|
+
parseError<E extends BaseError>(err: Error | string, reason?: string): E;
|
|
199
204
|
/**
|
|
200
205
|
* @description Checks if an attribute is reserved
|
|
201
206
|
* @summary Determines if an attribute name is reserved in CouchDB
|
|
@@ -259,5 +264,28 @@ export declare abstract class CouchDBAdapter<Y, CONN, F extends RepositoryFlags,
|
|
|
259
264
|
* ErrorTypes-->>Caller: InternalError
|
|
260
265
|
* end
|
|
261
266
|
*/
|
|
262
|
-
protected static parseError(err: Error | string, reason?: string):
|
|
267
|
+
protected static parseError<E extends BaseError>(err: Error | string, reason?: string): E;
|
|
268
|
+
/**
|
|
269
|
+
* @description Sets metadata on a model instance.
|
|
270
|
+
* @summary Attaches metadata to a model instance using a non-enumerable property.
|
|
271
|
+
* @template M - The model type that extends Model.
|
|
272
|
+
* @param {M} model - The model instance.
|
|
273
|
+
* @param {any} metadata - The metadata to attach to the model.
|
|
274
|
+
*/
|
|
275
|
+
static setMetadata<M extends Model>(model: M, metadata: any): void;
|
|
276
|
+
/**
|
|
277
|
+
* @description Gets metadata from a model instance.
|
|
278
|
+
* @summary Retrieves previously attached metadata from a model instance.
|
|
279
|
+
* @template M - The model type that extends Model.
|
|
280
|
+
* @param {M} model - The model instance.
|
|
281
|
+
* @return {any} The metadata or undefined if not found.
|
|
282
|
+
*/
|
|
283
|
+
static getMetadata<M extends Model>(model: M): any;
|
|
284
|
+
/**
|
|
285
|
+
* @description Removes metadata from a model instance.
|
|
286
|
+
* @summary Deletes the metadata property from a model instance.
|
|
287
|
+
* @template M - The model type that extends Model.
|
|
288
|
+
* @param {M} model - The model instance.
|
|
289
|
+
*/
|
|
290
|
+
static removeMetadata<M extends Model>(model: M): void;
|
|
263
291
|
}
|
package/lib/esm/adapter.js
CHANGED
|
@@ -7,13 +7,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { Adapter, PersistenceKeys, ConnectionError,
|
|
10
|
+
import { Adapter, PersistenceKeys, ConnectionError, } from "@decaf-ts/core";
|
|
11
11
|
import { CouchDBKeys, reservedAttributes } from "./constants.js";
|
|
12
12
|
import { BaseError, ConflictError, InternalError, NotFoundError, prefixMethod, } from "@decaf-ts/db-decorators";
|
|
13
13
|
import { CouchDBSequence } from "./sequences/Sequence.js";
|
|
14
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
14
15
|
import { IndexError } from "./errors.js";
|
|
15
16
|
import { CouchDBStatement } from "./query/index.js";
|
|
16
|
-
import { final } from "@decaf-ts/
|
|
17
|
+
import { final } from "@decaf-ts/logging";
|
|
18
|
+
import { CouchDBRepository } from "./repository.js";
|
|
17
19
|
/**
|
|
18
20
|
* @description Abstract adapter for CouchDB database operations
|
|
19
21
|
* @summary Provides a base implementation for CouchDB database operations, including CRUD operations, sequence management, and error handling
|
|
@@ -92,6 +94,9 @@ export class CouchDBAdapter extends Adapter {
|
|
|
92
94
|
const managedModels = Adapter.models(this.flavour);
|
|
93
95
|
return this.index(...managedModels);
|
|
94
96
|
}
|
|
97
|
+
repository() {
|
|
98
|
+
return CouchDBRepository;
|
|
99
|
+
}
|
|
95
100
|
/**
|
|
96
101
|
* @description Assigns metadata to a model
|
|
97
102
|
* @summary Adds revision metadata to a model as a non-enumerable property
|
|
@@ -100,12 +105,9 @@ export class CouchDBAdapter extends Adapter {
|
|
|
100
105
|
* @return {Record<string, any>} The model with metadata assigned
|
|
101
106
|
*/
|
|
102
107
|
assignMetadata(model, rev) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
writable: false,
|
|
107
|
-
value: rev,
|
|
108
|
-
});
|
|
108
|
+
if (!rev)
|
|
109
|
+
return model;
|
|
110
|
+
CouchDBAdapter.setMetadata(model, rev);
|
|
109
111
|
return model;
|
|
110
112
|
}
|
|
111
113
|
/**
|
|
@@ -117,7 +119,7 @@ export class CouchDBAdapter extends Adapter {
|
|
|
117
119
|
*/
|
|
118
120
|
assignMultipleMetadata(models, revs) {
|
|
119
121
|
models.forEach((m, i) => {
|
|
120
|
-
|
|
122
|
+
CouchDBAdapter.setMetadata(m, revs[i]);
|
|
121
123
|
return m;
|
|
122
124
|
});
|
|
123
125
|
return models;
|
|
@@ -130,14 +132,14 @@ export class CouchDBAdapter extends Adapter {
|
|
|
130
132
|
* @param {Record<string, any>} model - The model to prepare
|
|
131
133
|
* @return A tuple containing the tableName, id, and prepared record
|
|
132
134
|
*/
|
|
133
|
-
createPrefix(
|
|
134
|
-
|
|
135
|
-
|
|
135
|
+
createPrefix(clazz, id, model, ...args) {
|
|
136
|
+
const { ctxArgs } = this.logCtx(args, this.createPrefix);
|
|
137
|
+
const tableName = Model.tableName(clazz);
|
|
136
138
|
const record = {};
|
|
137
139
|
record[CouchDBKeys.TABLE] = tableName;
|
|
138
140
|
record[CouchDBKeys.ID] = this.generateId(tableName, id);
|
|
139
141
|
Object.assign(record, model);
|
|
140
|
-
return [
|
|
142
|
+
return [clazz, id, record, ...ctxArgs];
|
|
141
143
|
}
|
|
142
144
|
/**
|
|
143
145
|
* @description Prepares multiple records for creation
|
|
@@ -148,11 +150,11 @@ export class CouchDBAdapter extends Adapter {
|
|
|
148
150
|
* @return A tuple containing the tableName, ids, and prepared records
|
|
149
151
|
* @throws {InternalError} If ids and models arrays have different lengths
|
|
150
152
|
*/
|
|
151
|
-
createAllPrefix(
|
|
152
|
-
|
|
153
|
-
...args) {
|
|
153
|
+
createAllPrefix(clazz, ids, models, ...args) {
|
|
154
|
+
const tableName = Model.tableName(clazz);
|
|
154
155
|
if (ids.length !== models.length)
|
|
155
156
|
throw new InternalError("Ids and models must have the same length");
|
|
157
|
+
const { ctxArgs } = this.logCtx(args, this.createAllPrefix);
|
|
156
158
|
const records = ids.map((id, count) => {
|
|
157
159
|
const record = {};
|
|
158
160
|
record[CouchDBKeys.TABLE] = tableName;
|
|
@@ -160,7 +162,7 @@ export class CouchDBAdapter extends Adapter {
|
|
|
160
162
|
Object.assign(record, models[count]);
|
|
161
163
|
return record;
|
|
162
164
|
});
|
|
163
|
-
return [
|
|
165
|
+
return [clazz, ids, records, ...ctxArgs];
|
|
164
166
|
}
|
|
165
167
|
/**
|
|
166
168
|
* @description Prepares a record for update
|
|
@@ -172,9 +174,9 @@ export class CouchDBAdapter extends Adapter {
|
|
|
172
174
|
* @return A tuple containing the tableName, id, and prepared record
|
|
173
175
|
* @throws {InternalError} If no revision number is found in the model
|
|
174
176
|
*/
|
|
175
|
-
updatePrefix(
|
|
176
|
-
|
|
177
|
-
|
|
177
|
+
updatePrefix(clazz, id, model, ...args) {
|
|
178
|
+
const tableName = Model.tableName(clazz);
|
|
179
|
+
const { ctxArgs } = this.logCtx(args, this.updatePrefix);
|
|
178
180
|
const record = {};
|
|
179
181
|
record[CouchDBKeys.TABLE] = tableName;
|
|
180
182
|
record[CouchDBKeys.ID] = this.generateId(tableName, id);
|
|
@@ -183,7 +185,7 @@ export class CouchDBAdapter extends Adapter {
|
|
|
183
185
|
throw new InternalError(`No revision number found for record with id ${id}`);
|
|
184
186
|
Object.assign(record, model);
|
|
185
187
|
record[CouchDBKeys.REV] = rev;
|
|
186
|
-
return [
|
|
188
|
+
return [clazz, id, record, ...ctxArgs];
|
|
187
189
|
}
|
|
188
190
|
/**
|
|
189
191
|
* @description Prepares multiple records for update
|
|
@@ -194,11 +196,11 @@ export class CouchDBAdapter extends Adapter {
|
|
|
194
196
|
* @return A tuple containing the tableName, ids, and prepared records
|
|
195
197
|
* @throws {InternalError} If ids and models arrays have different lengths or if no revision number is found in a model
|
|
196
198
|
*/
|
|
197
|
-
updateAllPrefix(
|
|
198
|
-
|
|
199
|
-
...args) {
|
|
199
|
+
updateAllPrefix(clazz, ids, models, ...args) {
|
|
200
|
+
const tableName = Model.tableName(clazz);
|
|
200
201
|
if (ids.length !== models.length)
|
|
201
202
|
throw new InternalError("Ids and models must have the same length");
|
|
203
|
+
const { ctxArgs } = this.logCtx(args, this.updateAllPrefix);
|
|
202
204
|
const records = ids.map((id, count) => {
|
|
203
205
|
const record = {};
|
|
204
206
|
record[CouchDBKeys.TABLE] = tableName;
|
|
@@ -210,7 +212,7 @@ export class CouchDBAdapter extends Adapter {
|
|
|
210
212
|
record[CouchDBKeys.REV] = rev;
|
|
211
213
|
return record;
|
|
212
214
|
});
|
|
213
|
-
return [
|
|
215
|
+
return [clazz, ids, records, ...ctxArgs];
|
|
214
216
|
}
|
|
215
217
|
/**
|
|
216
218
|
* @description Generates a CouchDB document ID
|
|
@@ -336,6 +338,44 @@ export class CouchDBAdapter extends Adapter {
|
|
|
336
338
|
return new InternalError(err);
|
|
337
339
|
}
|
|
338
340
|
}
|
|
341
|
+
// TODO why do we need this?
|
|
342
|
+
/**
|
|
343
|
+
* @description Sets metadata on a model instance.
|
|
344
|
+
* @summary Attaches metadata to a model instance using a non-enumerable property.
|
|
345
|
+
* @template M - The model type that extends Model.
|
|
346
|
+
* @param {M} model - The model instance.
|
|
347
|
+
* @param {any} metadata - The metadata to attach to the model.
|
|
348
|
+
*/
|
|
349
|
+
static setMetadata(model, metadata) {
|
|
350
|
+
Object.defineProperty(model, PersistenceKeys.METADATA, {
|
|
351
|
+
enumerable: false,
|
|
352
|
+
configurable: true,
|
|
353
|
+
writable: true,
|
|
354
|
+
value: metadata,
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* @description Gets metadata from a model instance.
|
|
359
|
+
* @summary Retrieves previously attached metadata from a model instance.
|
|
360
|
+
* @template M - The model type that extends Model.
|
|
361
|
+
* @param {M} model - The model instance.
|
|
362
|
+
* @return {any} The metadata or undefined if not found.
|
|
363
|
+
*/
|
|
364
|
+
static getMetadata(model) {
|
|
365
|
+
const descriptor = Object.getOwnPropertyDescriptor(model, PersistenceKeys.METADATA);
|
|
366
|
+
return descriptor ? descriptor.value : undefined;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* @description Removes metadata from a model instance.
|
|
370
|
+
* @summary Deletes the metadata property from a model instance.
|
|
371
|
+
* @template M - The model type that extends Model.
|
|
372
|
+
* @param {M} model - The model instance.
|
|
373
|
+
*/
|
|
374
|
+
static removeMetadata(model) {
|
|
375
|
+
const descriptor = Object.getOwnPropertyDescriptor(model, PersistenceKeys.METADATA);
|
|
376
|
+
if (descriptor)
|
|
377
|
+
delete model[PersistenceKeys.METADATA];
|
|
378
|
+
}
|
|
339
379
|
}
|
|
340
380
|
__decorate([
|
|
341
381
|
final(),
|
|
@@ -364,25 +404,25 @@ __decorate([
|
|
|
364
404
|
__decorate([
|
|
365
405
|
final(),
|
|
366
406
|
__metadata("design:type", Function),
|
|
367
|
-
__metadata("design:paramtypes", [
|
|
368
|
-
__metadata("design:returntype",
|
|
407
|
+
__metadata("design:paramtypes", [Object, Object, Object, Object]),
|
|
408
|
+
__metadata("design:returntype", Array)
|
|
369
409
|
], CouchDBAdapter.prototype, "createPrefix", null);
|
|
370
410
|
__decorate([
|
|
371
411
|
final(),
|
|
372
412
|
__metadata("design:type", Function),
|
|
373
|
-
__metadata("design:paramtypes", [
|
|
413
|
+
__metadata("design:paramtypes", [Object, Array, Array, Object]),
|
|
374
414
|
__metadata("design:returntype", void 0)
|
|
375
415
|
], CouchDBAdapter.prototype, "createAllPrefix", null);
|
|
376
416
|
__decorate([
|
|
377
417
|
final(),
|
|
378
418
|
__metadata("design:type", Function),
|
|
379
|
-
__metadata("design:paramtypes", [
|
|
419
|
+
__metadata("design:paramtypes", [Object, Object, Object, Object]),
|
|
380
420
|
__metadata("design:returntype", void 0)
|
|
381
421
|
], CouchDBAdapter.prototype, "updatePrefix", null);
|
|
382
422
|
__decorate([
|
|
383
423
|
final(),
|
|
384
424
|
__metadata("design:type", Function),
|
|
385
|
-
__metadata("design:paramtypes", [
|
|
425
|
+
__metadata("design:paramtypes", [Object, Array, Array, Object]),
|
|
386
426
|
__metadata("design:returntype", void 0)
|
|
387
427
|
], CouchDBAdapter.prototype, "updateAllPrefix", null);
|
|
388
428
|
//# sourceMappingURL=adapter.js.map
|