@decaf-ts/for-pouch 0.7.0 → 0.8.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.
- package/lib/cjs/index.cjs +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/types/PouchRepository.d.cts +1 -1
- package/lib/types/PouchRepository.d.mts +1 -1
- package/lib/types/adapter.d.cts +2 -2
- package/lib/types/adapter.d.mts +2 -2
- package/lib/types/index.d.cts +5 -5
- package/lib/types/index.d.mts +5 -5
- package/package.json +1 -1
- package/lib/types/PouchRepository.d.ts +0 -15
- package/lib/types/adapter.d.ts +0 -427
- package/lib/types/constants.d.ts +0 -15
- package/lib/types/index.d.ts +0 -23
- package/lib/types/types.d.ts +0 -41
package/lib/cjs/index.cjs
CHANGED
|
@@ -34,7 +34,7 @@ __exportStar(require("./adapter.cjs"), exports);
|
|
|
34
34
|
* @const VERSION
|
|
35
35
|
* @memberOf module:for-pouch
|
|
36
36
|
*/
|
|
37
|
-
exports.VERSION = "0.
|
|
37
|
+
exports.VERSION = "0.7.0";
|
|
38
38
|
/**
|
|
39
39
|
* @description Package version identifier
|
|
40
40
|
* @summary Stores the current version of the for-pouch package
|
package/lib/esm/index.js
CHANGED
|
@@ -17,7 +17,7 @@ export * from "./adapter.js";
|
|
|
17
17
|
* @const VERSION
|
|
18
18
|
* @memberOf module:for-pouch
|
|
19
19
|
*/
|
|
20
|
-
export const VERSION = "0.
|
|
20
|
+
export const VERSION = "0.7.0";
|
|
21
21
|
/**
|
|
22
22
|
* @description Package version identifier
|
|
23
23
|
* @summary Stores the current version of the for-pouch package
|
|
@@ -2,7 +2,7 @@ import { Model } from "@decaf-ts/decorator-validation";
|
|
|
2
2
|
import { CouchDBRepository } from "@decaf-ts/for-couchdb";
|
|
3
3
|
import { ContextOf, FlagsOf } from "@decaf-ts/core";
|
|
4
4
|
import { Constructor } from "@decaf-ts/decoration";
|
|
5
|
-
import { PouchAdapter } from "./adapter.
|
|
5
|
+
import { PouchAdapter } from "./adapter.d.cts";
|
|
6
6
|
/**
|
|
7
7
|
* @description Repository implementation for PouchDB-backed models
|
|
8
8
|
* @summary Extends the CouchDBRepository with PouchAdapter-specific overrides so the repository can be proxied with the correct flags.
|
|
@@ -2,7 +2,7 @@ import { Model } from "@decaf-ts/decorator-validation";
|
|
|
2
2
|
import { CouchDBRepository } from "@decaf-ts/for-couchdb";
|
|
3
3
|
import { ContextOf, FlagsOf } from "@decaf-ts/core";
|
|
4
4
|
import { Constructor } from "@decaf-ts/decoration";
|
|
5
|
-
import { PouchAdapter } from "./adapter.
|
|
5
|
+
import { PouchAdapter } from "./adapter.d.mts";
|
|
6
6
|
/**
|
|
7
7
|
* @description Repository implementation for PouchDB-backed models
|
|
8
8
|
* @summary Extends the CouchDBRepository with PouchAdapter-specific overrides so the repository can be proxied with the correct flags.
|
package/lib/types/adapter.d.cts
CHANGED
|
@@ -4,8 +4,8 @@ import { BaseError, OperationKeys, PrimaryKeyType } from "@decaf-ts/db-decorator
|
|
|
4
4
|
import { Adapter, Context, ContextOf, ContextualArgs, RelationsMetadata, Repository } from "@decaf-ts/core";
|
|
5
5
|
import Database = PouchDB.Database;
|
|
6
6
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
7
|
-
import { PouchConfig, PouchFlags } from "./types.
|
|
8
|
-
import { PouchRepository } from "./PouchRepository.
|
|
7
|
+
import { PouchConfig, PouchFlags } from "./types.d.cts";
|
|
8
|
+
import { PouchRepository } from "./PouchRepository.d.cts";
|
|
9
9
|
import { Constructor } from "@decaf-ts/decoration";
|
|
10
10
|
/**
|
|
11
11
|
* @description Sets the creator ID on a model during creation or update operations
|
package/lib/types/adapter.d.mts
CHANGED
|
@@ -4,8 +4,8 @@ import { BaseError, OperationKeys, PrimaryKeyType } from "@decaf-ts/db-decorator
|
|
|
4
4
|
import { Adapter, Context, ContextOf, ContextualArgs, RelationsMetadata, Repository } from "@decaf-ts/core";
|
|
5
5
|
import Database = PouchDB.Database;
|
|
6
6
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
7
|
-
import { PouchConfig, PouchFlags } from "./types.
|
|
8
|
-
import { PouchRepository } from "./PouchRepository.
|
|
7
|
+
import { PouchConfig, PouchFlags } from "./types.d.mts";
|
|
8
|
+
import { PouchRepository } from "./PouchRepository.d.mts";
|
|
9
9
|
import { Constructor } from "@decaf-ts/decoration";
|
|
10
10
|
/**
|
|
11
11
|
* @description Sets the creator ID on a model during creation or update operations
|
package/lib/types/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from "./constants.
|
|
2
|
-
export * from "./PouchRepository.
|
|
3
|
-
export * from "./types.
|
|
4
|
-
export * from "./adapter.
|
|
1
|
+
export * from "./constants.d.cts";
|
|
2
|
+
export * from "./PouchRepository.d.cts";
|
|
3
|
+
export * from "./types.d.cts";
|
|
4
|
+
export * from "./adapter.d.cts";
|
|
5
5
|
/**
|
|
6
6
|
* @description A TypeScript adapter for PouchDB integration
|
|
7
7
|
* @summary Provides a repository-pattern implementation backed by PouchDB, exposing the {@link PouchAdapter} to interface with databases, the {@link PouchRepository} for typed data access, configuration {@link module:for-pouch|constants} like {@link PouchFlavour} and {@link DefaultLocalStoragePath}, and related {@link module:for-pouch|types}. This module wires up decorators on load to support created/updated-by fields.
|
|
@@ -13,7 +13,7 @@ export * from "./adapter.cjs";
|
|
|
13
13
|
* @const VERSION
|
|
14
14
|
* @memberOf module:for-pouch
|
|
15
15
|
*/
|
|
16
|
-
export declare const VERSION = "0.
|
|
16
|
+
export declare const VERSION = "0.7.0";
|
|
17
17
|
/**
|
|
18
18
|
* @description Package version identifier
|
|
19
19
|
* @summary Stores the current version of the for-pouch package
|
package/lib/types/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from "./constants.
|
|
2
|
-
export * from "./PouchRepository.
|
|
3
|
-
export * from "./types.
|
|
4
|
-
export * from "./adapter.
|
|
1
|
+
export * from "./constants.d.mts";
|
|
2
|
+
export * from "./PouchRepository.d.mts";
|
|
3
|
+
export * from "./types.d.mts";
|
|
4
|
+
export * from "./adapter.d.mts";
|
|
5
5
|
/**
|
|
6
6
|
* @description A TypeScript adapter for PouchDB integration
|
|
7
7
|
* @summary Provides a repository-pattern implementation backed by PouchDB, exposing the {@link PouchAdapter} to interface with databases, the {@link PouchRepository} for typed data access, configuration {@link module:for-pouch|constants} like {@link PouchFlavour} and {@link DefaultLocalStoragePath}, and related {@link module:for-pouch|types}. This module wires up decorators on load to support created/updated-by fields.
|
|
@@ -13,7 +13,7 @@ export * from "./adapter.js";
|
|
|
13
13
|
* @const VERSION
|
|
14
14
|
* @memberOf module:for-pouch
|
|
15
15
|
*/
|
|
16
|
-
export declare const VERSION = "0.
|
|
16
|
+
export declare const VERSION = "0.7.0";
|
|
17
17
|
/**
|
|
18
18
|
* @description Package version identifier
|
|
19
19
|
* @summary Stores the current version of the for-pouch package
|
package/package.json
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
-
import { CouchDBRepository } from "@decaf-ts/for-couchdb";
|
|
3
|
-
import { ContextOf, FlagsOf } from "@decaf-ts/core";
|
|
4
|
-
import { Constructor } from "@decaf-ts/decoration";
|
|
5
|
-
import { PouchAdapter } from "./adapter";
|
|
6
|
-
/**
|
|
7
|
-
* @description Repository implementation for PouchDB-backed models
|
|
8
|
-
* @summary Extends the CouchDBRepository with PouchAdapter-specific overrides so the repository can be proxied with the correct flags.
|
|
9
|
-
* @template M - Model type managed by this repository
|
|
10
|
-
* @memberOf module:for-pouch
|
|
11
|
-
*/
|
|
12
|
-
export declare class PouchRepository<M extends Model> extends CouchDBRepository<M, PouchAdapter> {
|
|
13
|
-
constructor(adapter: PouchAdapter, model: Constructor<M>, force?: boolean);
|
|
14
|
-
override(flags: Partial<FlagsOf<ContextOf<PouchAdapter>>>): this;
|
|
15
|
-
}
|
package/lib/types/adapter.d.ts
DELETED
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import { CouchDBAdapter, MangoQuery, ViewResponse } from "@decaf-ts/for-couchdb";
|
|
3
|
-
import { BaseError, OperationKeys, PrimaryKeyType } from "@decaf-ts/db-decorators";
|
|
4
|
-
import { Adapter, Context, ContextOf, ContextualArgs, RelationsMetadata, Repository } from "@decaf-ts/core";
|
|
5
|
-
import Database = PouchDB.Database;
|
|
6
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
7
|
-
import { PouchConfig, PouchFlags } from "./types";
|
|
8
|
-
import { PouchRepository } from "./PouchRepository";
|
|
9
|
-
import { Constructor } from "@decaf-ts/decoration";
|
|
10
|
-
/**
|
|
11
|
-
* @description Sets the creator ID on a model during creation or update operations
|
|
12
|
-
* @summary This function is used as a decorator handler to automatically set the creator ID field on a model
|
|
13
|
-
* when it's being created or updated. It extracts the UUID from the context and assigns it to the specified key.
|
|
14
|
-
* @template M - The model type that extends Model
|
|
15
|
-
* @template R - The repository type that extends PouchRepository<M>
|
|
16
|
-
* @template V - The relations metadata type that extends RelationsMetadata
|
|
17
|
-
* @param {R} this - The repository instance
|
|
18
|
-
* @param {Context<PouchFlags>} context - The operation context containing flags
|
|
19
|
-
* @param {V} data - The relations metadata
|
|
20
|
-
* @param key - The property key to set on the model
|
|
21
|
-
* @param {M} model - The model instance to modify
|
|
22
|
-
* @return {Promise<void>} A promise that resolves when the operation is complete
|
|
23
|
-
* @function createdByOnPouchCreateUpdate
|
|
24
|
-
* @memberOf module:for-pouch
|
|
25
|
-
*/
|
|
26
|
-
export declare function createdByOnPouchCreateUpdate<M extends Model, R extends PouchRepository<M>, V extends RelationsMetadata>(this: R, context: ContextOf<R>, data: V, key: keyof M, model: M): Promise<void>;
|
|
27
|
-
/**
|
|
28
|
-
* @description PouchDB implementation of the CouchDBAdapter
|
|
29
|
-
* @summary Concrete adapter that bridges the generic CouchDBAdapter to a PouchDB backend. It supports CRUD (single and bulk), indexing and Mango queries, and wires flavour-specific decorations.
|
|
30
|
-
* @template PouchFlags - The flags specific to PouchDB operations
|
|
31
|
-
* @template Context<PouchFlags> - The context type with PouchDB flags
|
|
32
|
-
* @param {PouchConfig} config - Adapter configuration (remote credentials or local storage path, db name, plugins)
|
|
33
|
-
* @param {string} [alias] - Optional alias for the database
|
|
34
|
-
* @class PouchAdapter
|
|
35
|
-
* @example
|
|
36
|
-
* ```typescript
|
|
37
|
-
* import { PouchAdapter } from '@decaf-ts/for-pouch';
|
|
38
|
-
*
|
|
39
|
-
* // Create a PouchAdapter with config
|
|
40
|
-
* const adapter = new PouchAdapter({
|
|
41
|
-
* protocol: 'http',
|
|
42
|
-
* host: 'localhost:5984',
|
|
43
|
-
* user: 'admin',
|
|
44
|
-
* password: 'secret',
|
|
45
|
-
* dbName: 'my-database',
|
|
46
|
-
* plugins: []
|
|
47
|
-
* });
|
|
48
|
-
*
|
|
49
|
-
* // Or use local storage
|
|
50
|
-
* const localAdapter = new PouchAdapter({
|
|
51
|
-
* protocol: 'http', // ignored for local
|
|
52
|
-
* dbName: 'local-db',
|
|
53
|
-
* storagePath: 'local_dbs',
|
|
54
|
-
* plugins: []
|
|
55
|
-
* });
|
|
56
|
-
*
|
|
57
|
-
* // Use the adapter for database operations
|
|
58
|
-
* const result = await adapter.read('users', 'user-123');
|
|
59
|
-
* ```
|
|
60
|
-
* @mermaid
|
|
61
|
-
* sequenceDiagram
|
|
62
|
-
* participant Client
|
|
63
|
-
* participant PouchAdapter
|
|
64
|
-
* participant PouchDB
|
|
65
|
-
* participant CouchDB
|
|
66
|
-
*
|
|
67
|
-
* Client->>PouchAdapter: new PouchAdapter(config, alias?)
|
|
68
|
-
* PouchAdapter->>CouchDBAdapter: super(config, PouchFlavour, alias)
|
|
69
|
-
*
|
|
70
|
-
* Client->>PouchAdapter: create(table, id, model)
|
|
71
|
-
* PouchAdapter->>PouchDB: put(model)
|
|
72
|
-
* PouchDB->>CouchDB: HTTP PUT
|
|
73
|
-
* CouchDB-->>PouchDB: Response
|
|
74
|
-
* PouchDB-->>PouchAdapter: Response
|
|
75
|
-
* PouchAdapter-->>Client: Updated model
|
|
76
|
-
*
|
|
77
|
-
* Client->>PouchAdapter: read(table, id)
|
|
78
|
-
* PouchAdapter->>PouchDB: get(id)
|
|
79
|
-
* PouchDB->>CouchDB: HTTP GET
|
|
80
|
-
* CouchDB-->>PouchDB: Document
|
|
81
|
-
* PouchDB-->>PouchAdapter: Document
|
|
82
|
-
* PouchAdapter-->>Client: Model
|
|
83
|
-
*/
|
|
84
|
-
export declare class PouchAdapter extends CouchDBAdapter<PouchConfig, Database, Context<PouchFlags>> {
|
|
85
|
-
constructor(config: PouchConfig, alias?: string);
|
|
86
|
-
private _adminClient?;
|
|
87
|
-
private _pluginsRegistered;
|
|
88
|
-
private registerPlugins;
|
|
89
|
-
private buildClient;
|
|
90
|
-
protected getAdminClient(): Database;
|
|
91
|
-
/**
|
|
92
|
-
* @description Lazily initializes and returns the underlying PouchDB client
|
|
93
|
-
* @summary Loads required PouchDB plugins once, builds the connection URL or local storage path from config, and caches the Database instance for reuse. Throws InternalError if client creation fails.
|
|
94
|
-
* @return {Database} A PouchDB Database instance ready to perform operations
|
|
95
|
-
* @mermaid
|
|
96
|
-
* sequenceDiagram
|
|
97
|
-
* participant Caller
|
|
98
|
-
* participant PouchAdapter
|
|
99
|
-
* participant PouchDB
|
|
100
|
-
* Caller->>PouchAdapter: getClient()
|
|
101
|
-
* alt client not initialized
|
|
102
|
-
* PouchAdapter->>PouchAdapter: register plugins
|
|
103
|
-
* PouchAdapter->>PouchDB: new PouchDB(url or path)
|
|
104
|
-
* alt creation fails
|
|
105
|
-
* PouchDB-->>PouchAdapter: Error
|
|
106
|
-
* PouchAdapter-->>Caller: throws InternalError
|
|
107
|
-
* else success
|
|
108
|
-
* PouchDB-->>PouchAdapter: Database
|
|
109
|
-
* PouchAdapter-->>Caller: cached client
|
|
110
|
-
* end
|
|
111
|
-
* else client initialized
|
|
112
|
-
* PouchAdapter-->>Caller: cached client
|
|
113
|
-
* end
|
|
114
|
-
*/
|
|
115
|
-
getClient(): Database;
|
|
116
|
-
/**
|
|
117
|
-
* @description Generates operation flags for PouchDB operations
|
|
118
|
-
* @summary Creates a set of flags for a specific operation, including a UUID for identification.
|
|
119
|
-
* This method extracts the user ID from the database URL or generates a random UUID if not available.
|
|
120
|
-
* @template M - The model type that extends Model
|
|
121
|
-
* @param {OperationKeys} operation - The operation key (create, read, update, delete)
|
|
122
|
-
* @param {Constructor<M>} model - The model constructor
|
|
123
|
-
* @param {Partial<PouchFlags>} flags - Partial flags to be merged
|
|
124
|
-
* @return {Promise<PouchFlags>} The complete set of flags for the operation
|
|
125
|
-
*/
|
|
126
|
-
protected flags<M extends Model>(operation: OperationKeys, model: Constructor<M>, flags: Partial<PouchFlags>, ...args: any[]): Promise<PouchFlags>;
|
|
127
|
-
repository<R extends Repository<any, Adapter<PouchConfig, Database, MangoQuery, Context<PouchFlags>>>>(): Constructor<R>;
|
|
128
|
-
/**
|
|
129
|
-
* @description Creates database indexes for the given models
|
|
130
|
-
* @summary Generates and creates indexes in the PouchDB database based on the provided model constructors.
|
|
131
|
-
* This method uses the generateIndexes utility to create index definitions and then creates them in the database.
|
|
132
|
-
* @template M - The model type that extends Model
|
|
133
|
-
* @param models - The model constructors to create indexes for
|
|
134
|
-
* @return {Promise<void>} A promise that resolves when all indexes are created
|
|
135
|
-
*/
|
|
136
|
-
protected index<M extends Model>(...models: Constructor<M>[]): Promise<void>;
|
|
137
|
-
/**
|
|
138
|
-
* @description Creates a new document in the database
|
|
139
|
-
* @summary Inserts a new document into the PouchDB database using the put operation.
|
|
140
|
-
* This method handles error parsing and ensures the operation was successful.
|
|
141
|
-
* @param {string} tableName - The name of the table/collection
|
|
142
|
-
* @param {string|number} id - The document ID
|
|
143
|
-
* @param {Record<string, any>} model - The document data to insert
|
|
144
|
-
* @return {Promise<Record<string, any>>} A promise that resolves to the created document with metadata
|
|
145
|
-
* @mermaid
|
|
146
|
-
* sequenceDiagram
|
|
147
|
-
* participant Client
|
|
148
|
-
* participant PouchAdapter
|
|
149
|
-
* participant PouchDB
|
|
150
|
-
*
|
|
151
|
-
* Client->>PouchAdapter: create(tableName, id, model)
|
|
152
|
-
* PouchAdapter->>PouchDB: put(model)
|
|
153
|
-
* alt Success
|
|
154
|
-
* PouchDB-->>PouchAdapter: Response with ok=true
|
|
155
|
-
* PouchAdapter->>PouchAdapter: assignMetadata(model, response.rev)
|
|
156
|
-
* PouchAdapter-->>Client: Updated model with metadata
|
|
157
|
-
* else Error
|
|
158
|
-
* PouchDB-->>PouchAdapter: Error
|
|
159
|
-
* PouchAdapter->>PouchAdapter: parseError(e)
|
|
160
|
-
* PouchAdapter-->>Client: Throws error
|
|
161
|
-
* end
|
|
162
|
-
*/
|
|
163
|
-
create<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<Context<PouchFlags>>): Promise<Record<string, any>>;
|
|
164
|
-
/**
|
|
165
|
-
* @description Creates multiple documents in the database in a single operation
|
|
166
|
-
* @summary Inserts multiple documents into the PouchDB database using the bulkDocs operation.
|
|
167
|
-
* This method handles error parsing and ensures all operations were successful.
|
|
168
|
-
* @param {string} tableName - The name of the table/collection
|
|
169
|
-
* @param {string[]|number[]} ids - The document IDs
|
|
170
|
-
* @param models - The document data to insert
|
|
171
|
-
* @return A promise that resolves to the created documents with metadata
|
|
172
|
-
* @mermaid
|
|
173
|
-
* sequenceDiagram
|
|
174
|
-
* participant Client
|
|
175
|
-
* participant PouchAdapter
|
|
176
|
-
* participant PouchDB
|
|
177
|
-
*
|
|
178
|
-
* Client->>PouchAdapter: createAll(tableName, ids, models)
|
|
179
|
-
* PouchAdapter->>PouchDB: bulkDocs(models)
|
|
180
|
-
* alt Success
|
|
181
|
-
* PouchDB-->>PouchAdapter: Array of responses with ok=true
|
|
182
|
-
* PouchAdapter->>PouchAdapter: assignMultipleMetadata(models, revs)
|
|
183
|
-
* PouchAdapter-->>Client: Updated models with metadata
|
|
184
|
-
* else Error
|
|
185
|
-
* PouchDB-->>PouchAdapter: Array with errors
|
|
186
|
-
* PouchAdapter->>PouchAdapter: Check for errors
|
|
187
|
-
* PouchAdapter-->>Client: Throws InternalError
|
|
188
|
-
* end
|
|
189
|
-
*/
|
|
190
|
-
createAll<M extends Model>(tableName: Constructor<M>, ids: PrimaryKeyType[], models: Record<string, any>[], ...args: ContextualArgs<Context<PouchFlags>>): Promise<Record<string, any>[]>;
|
|
191
|
-
/**
|
|
192
|
-
* @description Retrieves a document from the database by ID
|
|
193
|
-
* @summary Fetches a document from the PouchDB database using the get operation.
|
|
194
|
-
* This method generates the document ID based on the table name and ID, then retrieves the document.
|
|
195
|
-
* @param {string} tableName - The name of the table/collection
|
|
196
|
-
* @param {string|number} id - The document ID
|
|
197
|
-
* @return {Promise<Record<string, any>>} A promise that resolves to the retrieved document with metadata
|
|
198
|
-
* @mermaid
|
|
199
|
-
* sequenceDiagram
|
|
200
|
-
* participant Client
|
|
201
|
-
* participant PouchAdapter
|
|
202
|
-
* participant PouchDB
|
|
203
|
-
*
|
|
204
|
-
* Client->>PouchAdapter: read(tableName, id)
|
|
205
|
-
* PouchAdapter->>PouchAdapter: generateId(tableName, id)
|
|
206
|
-
* PouchAdapter->>PouchDB: get(_id)
|
|
207
|
-
* alt Success
|
|
208
|
-
* PouchDB-->>PouchAdapter: Document
|
|
209
|
-
* PouchAdapter->>PouchAdapter: assignMetadata(record, record._rev)
|
|
210
|
-
* PouchAdapter-->>Client: Document with metadata
|
|
211
|
-
* else Error
|
|
212
|
-
* PouchDB-->>PouchAdapter: Error
|
|
213
|
-
* PouchAdapter->>PouchAdapter: parseError(e)
|
|
214
|
-
* PouchAdapter-->>Client: Throws error
|
|
215
|
-
* end
|
|
216
|
-
*/
|
|
217
|
-
read<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<Context<PouchFlags>>): Promise<Record<string, any>>;
|
|
218
|
-
/**
|
|
219
|
-
* @description Retrieves multiple documents from the database by their IDs
|
|
220
|
-
* @summary Fetches multiple documents from the PouchDB database using the bulkGet operation.
|
|
221
|
-
* This method generates document IDs based on the table name and IDs, then retrieves the documents.
|
|
222
|
-
* @param {string} tableName - The name of the table/collection
|
|
223
|
-
* @param {Array<string|number|bigint>} ids - The document IDs
|
|
224
|
-
* @return A promise that resolves to the retrieved documents with metadata
|
|
225
|
-
* @mermaid
|
|
226
|
-
* sequenceDiagram
|
|
227
|
-
* participant Client
|
|
228
|
-
* participant PouchAdapter
|
|
229
|
-
* participant PouchDB
|
|
230
|
-
*
|
|
231
|
-
* Client->>PouchAdapter: readAll(tableName, ids)
|
|
232
|
-
* PouchAdapter->>PouchAdapter: Map ids to generateId(tableName, id)
|
|
233
|
-
* PouchAdapter->>PouchDB: bulkGet({docs})
|
|
234
|
-
* alt Success
|
|
235
|
-
* PouchDB-->>PouchAdapter: BulkGetResponse
|
|
236
|
-
* PouchAdapter->>PouchAdapter: Process results
|
|
237
|
-
* PouchAdapter->>PouchAdapter: assignMetadata for each doc
|
|
238
|
-
* PouchAdapter-->>Client: Documents with metadata
|
|
239
|
-
* else Error
|
|
240
|
-
* PouchAdapter->>PouchAdapter: parseError(error)
|
|
241
|
-
* PouchAdapter-->>Client: Throws error
|
|
242
|
-
* end
|
|
243
|
-
*/
|
|
244
|
-
readAll<M extends Model>(tableName: Constructor<M>, ids: (string | number | bigint)[], ...args: ContextualArgs<Context<PouchFlags>>): Promise<Record<string, any>[]>;
|
|
245
|
-
/**
|
|
246
|
-
* @description Updates an existing document in the database
|
|
247
|
-
* @summary Updates a document in the PouchDB database using the put operation.
|
|
248
|
-
* This method handles error parsing and ensures the operation was successful.
|
|
249
|
-
* @param {string} tableName - The name of the table/collection
|
|
250
|
-
* @param {string|number} id - The document ID
|
|
251
|
-
* @param {Record<string, any>} model - The updated document data
|
|
252
|
-
* @return {Promise<Record<string, any>>} A promise that resolves to the updated document with metadata
|
|
253
|
-
* @mermaid
|
|
254
|
-
* sequenceDiagram
|
|
255
|
-
* participant Client
|
|
256
|
-
* participant PouchAdapter
|
|
257
|
-
* participant PouchDB
|
|
258
|
-
*
|
|
259
|
-
* Client->>PouchAdapter: update(tableName, id, model)
|
|
260
|
-
* PouchAdapter->>PouchDB: put(model)
|
|
261
|
-
* alt Success
|
|
262
|
-
* PouchDB-->>PouchAdapter: Response with ok=true
|
|
263
|
-
* PouchAdapter->>PouchAdapter: assignMetadata(model, response.rev)
|
|
264
|
-
* PouchAdapter-->>Client: Updated model with metadata
|
|
265
|
-
* else Error
|
|
266
|
-
* PouchDB-->>PouchAdapter: Error
|
|
267
|
-
* PouchAdapter->>PouchAdapter: parseError(e)
|
|
268
|
-
* PouchAdapter-->>Client: Throws error
|
|
269
|
-
* end
|
|
270
|
-
*/
|
|
271
|
-
update<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<Context<PouchFlags>>): Promise<Record<string, any>>;
|
|
272
|
-
/**
|
|
273
|
-
* @description Updates multiple documents in the database in a single operation
|
|
274
|
-
* @summary Updates multiple documents in the PouchDB database using the bulkDocs operation.
|
|
275
|
-
* This method handles error parsing and ensures all operations were successful.
|
|
276
|
-
* @param {string} tableName - The name of the table/collection
|
|
277
|
-
* @param {string[]|number[]} ids - The document IDs
|
|
278
|
-
* @param models - The updated document data
|
|
279
|
-
* @return A promise that resolves to the updated documents with metadata
|
|
280
|
-
* @mermaid
|
|
281
|
-
* sequenceDiagram
|
|
282
|
-
* participant Client
|
|
283
|
-
* participant PouchAdapter
|
|
284
|
-
* participant PouchDB
|
|
285
|
-
*
|
|
286
|
-
* Client->>PouchAdapter: updateAll(tableName, ids, models)
|
|
287
|
-
* PouchAdapter->>PouchDB: bulkDocs(models)
|
|
288
|
-
* alt Success
|
|
289
|
-
* PouchDB-->>PouchAdapter: Array of responses with ok=true
|
|
290
|
-
* PouchAdapter->>PouchAdapter: assignMultipleMetadata(models, revs)
|
|
291
|
-
* PouchAdapter-->>Client: Updated models with metadata
|
|
292
|
-
* else Error
|
|
293
|
-
* PouchDB-->>PouchAdapter: Array with errors
|
|
294
|
-
* PouchAdapter->>PouchAdapter: Check for errors
|
|
295
|
-
* PouchAdapter-->>Client: Throws InternalError
|
|
296
|
-
* end
|
|
297
|
-
*/
|
|
298
|
-
updateAll<M extends Model>(tableName: Constructor<M>, ids: PrimaryKeyType[], models: Record<string, any>[], ...args: ContextualArgs<Context<PouchFlags>>): Promise<Record<string, any>[]>;
|
|
299
|
-
/**
|
|
300
|
-
* @description Deletes a document from the database by ID
|
|
301
|
-
* @summary Removes a document from the PouchDB database using the remove operation.
|
|
302
|
-
* This method first retrieves the document to get its revision, then deletes it.
|
|
303
|
-
* @param {string} tableName - The name of the table/collection
|
|
304
|
-
* @param {string|number} id - The document ID
|
|
305
|
-
* @return {Promise<Record<string, any>>} A promise that resolves to the deleted document with metadata
|
|
306
|
-
* @mermaid
|
|
307
|
-
* sequenceDiagram
|
|
308
|
-
* participant Client
|
|
309
|
-
* participant PouchAdapter
|
|
310
|
-
* participant PouchDB
|
|
311
|
-
*
|
|
312
|
-
* Client->>PouchAdapter: delete(tableName, id)
|
|
313
|
-
* PouchAdapter->>PouchAdapter: generateId(tableName, id)
|
|
314
|
-
* PouchAdapter->>PouchDB: get(_id)
|
|
315
|
-
* PouchDB-->>PouchAdapter: Document with _rev
|
|
316
|
-
* PouchAdapter->>PouchDB: remove(_id, record._rev)
|
|
317
|
-
* alt Success
|
|
318
|
-
* PouchDB-->>PouchAdapter: Success response
|
|
319
|
-
* PouchAdapter->>PouchAdapter: assignMetadata(record, record._rev)
|
|
320
|
-
* PouchAdapter-->>Client: Deleted document with metadata
|
|
321
|
-
* else Error
|
|
322
|
-
* PouchDB-->>PouchAdapter: Error
|
|
323
|
-
* PouchAdapter->>PouchAdapter: parseError(e)
|
|
324
|
-
* PouchAdapter-->>Client: Throws error
|
|
325
|
-
* end
|
|
326
|
-
*/
|
|
327
|
-
delete<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<Context<PouchFlags>>): Promise<Record<string, any>>;
|
|
328
|
-
/**
|
|
329
|
-
* @description Deletes multiple documents from the database by their IDs
|
|
330
|
-
* @summary Removes multiple documents from the PouchDB database in a single operation.
|
|
331
|
-
* This method first retrieves all documents to get their revisions, then marks them as deleted.
|
|
332
|
-
* @param {string} tableName - The name of the table/collection
|
|
333
|
-
* @param {Array<string|number|bigint>} ids - The document IDs
|
|
334
|
-
* @return A promise that resolves to the deleted documents with metadata
|
|
335
|
-
* @mermaid
|
|
336
|
-
* sequenceDiagram
|
|
337
|
-
* participant Client
|
|
338
|
-
* participant PouchAdapter
|
|
339
|
-
* participant PouchDB
|
|
340
|
-
*
|
|
341
|
-
* Client->>PouchAdapter: deleteAll(tableName, ids)
|
|
342
|
-
* PouchAdapter->>PouchAdapter: Map ids to generateId(tableName, id)
|
|
343
|
-
* PouchAdapter->>PouchDB: bulkGet({docs})
|
|
344
|
-
* PouchDB-->>PouchAdapter: BulkGetResponse with documents
|
|
345
|
-
* PouchAdapter->>PouchAdapter: Mark documents as deleted
|
|
346
|
-
* PouchAdapter->>PouchDB: bulkDocs(marked documents)
|
|
347
|
-
* alt Success
|
|
348
|
-
* PouchDB-->>PouchAdapter: Success responses
|
|
349
|
-
* PouchAdapter->>PouchAdapter: Process results
|
|
350
|
-
* PouchAdapter->>PouchAdapter: assignMetadata for each doc
|
|
351
|
-
* PouchAdapter-->>Client: Deleted documents with metadata
|
|
352
|
-
* else Error
|
|
353
|
-
* PouchAdapter->>PouchAdapter: Check for errors
|
|
354
|
-
* PouchAdapter-->>Client: Throws InternalError
|
|
355
|
-
* end
|
|
356
|
-
*/
|
|
357
|
-
deleteAll<M extends Model>(tableName: Constructor<M>, ids: (string | number | bigint)[], ...args: ContextualArgs<Context<PouchFlags>>): Promise<Record<string, any>[]>;
|
|
358
|
-
/**
|
|
359
|
-
* @description Executes a raw Mango query against the database
|
|
360
|
-
* @summary Runs a Mango query and optionally returns only the documents array or the entire response
|
|
361
|
-
* @template V - The return value type
|
|
362
|
-
* @param {MangoQuery} rawInput - The Mango query to execute
|
|
363
|
-
* @param {boolean} [docsOnly=true] - Whether to return only the documents array
|
|
364
|
-
* @return {Promise<V>} A promise resolving the query result
|
|
365
|
-
*/
|
|
366
|
-
raw<V>(rawInput: MangoQuery, docsOnly?: boolean, ...args: ContextualArgs<Context<PouchFlags>>): Promise<V>;
|
|
367
|
-
view<R>(ddoc: string, viewName: string, options: Record<string, any>, ..._args: ContextualArgs<Context<PouchFlags>>): Promise<ViewResponse<R>>;
|
|
368
|
-
/**
|
|
369
|
-
* @description Parses and converts errors from PouchDB to application-specific errors
|
|
370
|
-
* @summary Converts PouchDB errors to the application's error hierarchy.
|
|
371
|
-
* This instance method delegates to the static parseError method.
|
|
372
|
-
* @param {Error|string} err - The error object or message to parse
|
|
373
|
-
* @param {string} [reason] - Optional reason for the error
|
|
374
|
-
* @return {BaseError} The converted error object
|
|
375
|
-
*/
|
|
376
|
-
parseError<E extends BaseError>(err: Error | string, reason?: string): E;
|
|
377
|
-
/**
|
|
378
|
-
* @description Static method to parse and convert errors from PouchDB to application-specific errors
|
|
379
|
-
* @summary Converts PouchDB errors to the application's error hierarchy based on error codes and messages.
|
|
380
|
-
* This method analyzes the error type, status code, or message to determine the appropriate error class.
|
|
381
|
-
* @param {Error|string} err - The error object or message to parse
|
|
382
|
-
* @param {string} [reason] - Optional reason for the error
|
|
383
|
-
* @return {BaseError} The converted error object
|
|
384
|
-
* @mermaid
|
|
385
|
-
* sequenceDiagram
|
|
386
|
-
* participant Caller
|
|
387
|
-
* participant PouchAdapter
|
|
388
|
-
*
|
|
389
|
-
* Caller->>PouchAdapter: parseError(err, reason)
|
|
390
|
-
* alt err is BaseError
|
|
391
|
-
* PouchAdapter-->>Caller: Return err as is
|
|
392
|
-
* else err is string
|
|
393
|
-
* alt contains "already exist" or "update conflict"
|
|
394
|
-
* PouchAdapter-->>Caller: ConflictError
|
|
395
|
-
* else contains "missing" or "deleted"
|
|
396
|
-
* PouchAdapter-->>Caller: NotFoundError
|
|
397
|
-
* end
|
|
398
|
-
* else err has status/statusCode/code
|
|
399
|
-
* Note over PouchAdapter: Extract code and reason
|
|
400
|
-
* else
|
|
401
|
-
* Note over PouchAdapter: Use err.message as code
|
|
402
|
-
* end
|
|
403
|
-
*
|
|
404
|
-
* Note over PouchAdapter: Switch on code
|
|
405
|
-
* alt code is 401, 412, or 409
|
|
406
|
-
* PouchAdapter->>ErrorTypes: ConflictError
|
|
407
|
-
* else code is 404
|
|
408
|
-
* PouchAdapter->>ErrorTypes: NotFoundError
|
|
409
|
-
* else code is 400
|
|
410
|
-
* alt code contains "No index exists"
|
|
411
|
-
* PouchAdapter->>ErrorTypes: IndexError
|
|
412
|
-
* else
|
|
413
|
-
* PouchAdapter->>ErrorTypes: InternalError
|
|
414
|
-
* else code contains "ECONNREFUSED"
|
|
415
|
-
* PouchAdapter->>ErrorTypes: ConnectionError
|
|
416
|
-
* else
|
|
417
|
-
* PouchAdapter->>ErrorTypes: InternalError
|
|
418
|
-
* end
|
|
419
|
-
*/
|
|
420
|
-
static parseError<E extends BaseError>(err: Error | string, reason?: string): E;
|
|
421
|
-
/**
|
|
422
|
-
* @description Sets up decorations for PouchDB-specific model properties
|
|
423
|
-
* @summary Configures decorators for createdBy and updatedBy fields in models.
|
|
424
|
-
* This method defines how these fields should be automatically populated during create and update operations.
|
|
425
|
-
*/
|
|
426
|
-
static decoration(): void;
|
|
427
|
-
}
|
package/lib/types/constants.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description Identifier for PouchDB flavor in the decorator system
|
|
3
|
-
* @summary A string constant that identifies the PouchDB implementation in the decorator system.
|
|
4
|
-
* This is used to target decorators specifically for PouchDB adapters.
|
|
5
|
-
* @const PouchFlavour
|
|
6
|
-
* @memberOf module:for-pouch
|
|
7
|
-
*/
|
|
8
|
-
export declare const PouchFlavour = "pouch";
|
|
9
|
-
/**
|
|
10
|
-
* @description Default relative path where local PouchDB databases are stored
|
|
11
|
-
* @summary Used when creating a local PouchDB instance without a remote host; combined with dbName to form the filesystem path.
|
|
12
|
-
* @const DefaultLocalStoragePath
|
|
13
|
-
* @memberOf module:for-pouch
|
|
14
|
-
*/
|
|
15
|
-
export declare const DefaultLocalStoragePath = "local_dbs";
|
package/lib/types/index.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export * from "./constants";
|
|
2
|
-
export * from "./PouchRepository";
|
|
3
|
-
export * from "./types";
|
|
4
|
-
export * from "./adapter";
|
|
5
|
-
/**
|
|
6
|
-
* @description A TypeScript adapter for PouchDB integration
|
|
7
|
-
* @summary Provides a repository-pattern implementation backed by PouchDB, exposing the {@link PouchAdapter} to interface with databases, the {@link PouchRepository} for typed data access, configuration {@link module:for-pouch|constants} like {@link PouchFlavour} and {@link DefaultLocalStoragePath}, and related {@link module:for-pouch|types}. This module wires up decorators on load to support created/updated-by fields.
|
|
8
|
-
* @module for-pouch
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* @description Package version identifier
|
|
12
|
-
* @summary Stores the current version of the for-pouch package
|
|
13
|
-
* @const VERSION
|
|
14
|
-
* @memberOf module:for-pouch
|
|
15
|
-
*/
|
|
16
|
-
export declare const VERSION = "0.6.0";
|
|
17
|
-
/**
|
|
18
|
-
* @description Package version identifier
|
|
19
|
-
* @summary Stores the current version of the for-pouch package
|
|
20
|
-
* @const VERSION
|
|
21
|
-
* @memberOf module:for-pouch
|
|
22
|
-
*/
|
|
23
|
-
export declare const PACKAGE_NAME = "@decaf-ts/for-pouch";
|
package/lib/types/types.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { AdapterFlags } from "@decaf-ts/core";
|
|
2
|
-
/**
|
|
3
|
-
* @description Flags specific to PouchDB repository operations
|
|
4
|
-
* @summary Extends the base repository flags with PouchDB-specific properties.
|
|
5
|
-
* These flags are used to pass additional information during repository operations.
|
|
6
|
-
* @interface PouchFlags
|
|
7
|
-
* @memberOf module:for-pouch
|
|
8
|
-
*/
|
|
9
|
-
export interface PouchFlags extends AdapterFlags {
|
|
10
|
-
/**
|
|
11
|
-
* @description Unique identifier for the current user or operation
|
|
12
|
-
*/
|
|
13
|
-
UUID: string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* @description Configuration options for initializing a PouchDB adapter
|
|
17
|
-
* @summary Defines connection credentials, local storage options, database name, and a list of PouchDB plugins to register before client creation.
|
|
18
|
-
* @template
|
|
19
|
-
* @property {string} [user] - Username for remote HTTP/S connections
|
|
20
|
-
* @property {string} [password] - Password for remote HTTP/S connections
|
|
21
|
-
* @property {string} [host] - Host (and optional port) of the remote CouchDB-compatible server
|
|
22
|
-
* @property {("http"|"https")} [protocol] - Network protocol to use when connecting remotely
|
|
23
|
-
* @property {number} [port] - Optional explicit port number; if provided may be part of host instead
|
|
24
|
-
* @property {string} dbName - Database name used in the URL or local path
|
|
25
|
-
* @property {string} [storagePath] - Relative base path for local databases; defaults to {@link DefaultLocalStoragePath}
|
|
26
|
-
* @property {any[]} plugins - List of PouchDB plugins (modules) to register with the client
|
|
27
|
-
* @typeDef PouchConfig
|
|
28
|
-
* @memberOf module:for-pouch
|
|
29
|
-
*/
|
|
30
|
-
export type PouchConfig = {
|
|
31
|
-
user?: string;
|
|
32
|
-
password?: string;
|
|
33
|
-
adminUser?: string;
|
|
34
|
-
adminPassword?: string;
|
|
35
|
-
host?: string;
|
|
36
|
-
protocol?: "http" | "https";
|
|
37
|
-
port?: number;
|
|
38
|
-
dbName: string;
|
|
39
|
-
storagePath?: string;
|
|
40
|
-
plugins: any[];
|
|
41
|
-
};
|