@decaf-ts/for-pouch 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +390 -17
- package/dist/for-pouch.cjs +130 -46
- package/dist/for-pouch.esm.cjs +110 -44
- package/lib/adapter.cjs +135 -40
- package/lib/adapter.d.ts +48 -15
- package/lib/constants.cjs +9 -2
- package/lib/constants.d.ts +7 -0
- package/lib/esm/adapter.d.ts +48 -15
- package/lib/esm/adapter.js +101 -42
- package/lib/esm/constants.d.ts +7 -0
- package/lib/esm/constants.js +8 -1
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +3 -3
- package/lib/esm/types.d.ts +25 -0
- package/lib/esm/types.js +1 -1
- package/lib/index.cjs +3 -3
- package/lib/index.d.ts +2 -2
- package/lib/types.cjs +1 -1
- package/lib/types.d.ts +25 -0
- package/package.json +4 -1
package/lib/constants.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PouchFlavour = void 0;
|
|
3
|
+
exports.DefaultLocalStoragePath = exports.PouchFlavour = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @description Identifier for PouchDB flavor in the decorator system
|
|
6
6
|
* @summary A string constant that identifies the PouchDB implementation in the decorator system.
|
|
@@ -9,4 +9,11 @@ exports.PouchFlavour = void 0;
|
|
|
9
9
|
* @memberOf module:for-pouch
|
|
10
10
|
*/
|
|
11
11
|
exports.PouchFlavour = "pouch";
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* @description Default relative path where local PouchDB databases are stored
|
|
14
|
+
* @summary Used when creating a local PouchDB instance without a remote host; combined with dbName to form the filesystem path.
|
|
15
|
+
* @const DefaultLocalStoragePath
|
|
16
|
+
* @memberOf module:for-pouch
|
|
17
|
+
*/
|
|
18
|
+
exports.DefaultLocalStoragePath = "local_dbs";
|
|
19
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HBhdGguXG4gKiBAY29uc3QgRGVmYXVsdExvY2FsU3RvcmFnZVBhdGhcbiAqIEBtZW1iZXJPZiBtb2R1bGU6Zm9yLXBvdWNoXG4gKi9cbmV4cG9ydCBjb25zdCBEZWZhdWx0TG9jYWxTdG9yYWdlUGF0aCA9IFwibG9jYWxfZGJzXCI7XG4iXX0=
|
package/lib/constants.d.ts
CHANGED
|
@@ -6,3 +6,10 @@
|
|
|
6
6
|
* @memberOf module:for-pouch
|
|
7
7
|
*/
|
|
8
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/esm/adapter.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { BaseError, Context, OperationKeys } from "@decaf-ts/db-decorators";
|
|
|
4
4
|
import { RelationsMetadata } from "@decaf-ts/core";
|
|
5
5
|
import Database = PouchDB.Database;
|
|
6
6
|
import { Constructor, Model } from "@decaf-ts/decorator-validation";
|
|
7
|
-
import { PouchFlags } from "./types";
|
|
7
|
+
import { PouchConfig, PouchFlags } from "./types";
|
|
8
8
|
import { PouchRepository } from "./PouchRepository";
|
|
9
9
|
/**
|
|
10
10
|
* @description Sets the creator ID on a model during creation or update operations
|
|
@@ -25,25 +25,33 @@ import { PouchRepository } from "./PouchRepository";
|
|
|
25
25
|
export declare function createdByOnPouchCreateUpdate<M extends Model, R extends PouchRepository<M>, V extends RelationsMetadata>(this: R, context: Context<PouchFlags>, data: V, key: keyof M, model: M): Promise<void>;
|
|
26
26
|
/**
|
|
27
27
|
* @description PouchDB implementation of the CouchDBAdapter
|
|
28
|
-
* @summary
|
|
29
|
-
* It handles all database operations like create, read, update, delete (CRUD) for both
|
|
30
|
-
* single documents and bulk operations. It also provides methods for querying and indexing.
|
|
31
|
-
* @template Database - The PouchDB database type
|
|
28
|
+
* @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.
|
|
32
29
|
* @template PouchFlags - The flags specific to PouchDB operations
|
|
33
30
|
* @template Context<PouchFlags> - The context type with PouchDB flags
|
|
34
|
-
* @param {
|
|
31
|
+
* @param {PouchConfig} config - Adapter configuration (remote credentials or local storage path, db name, plugins)
|
|
35
32
|
* @param {string} [alias] - Optional alias for the database
|
|
36
33
|
* @class PouchAdapter
|
|
37
34
|
* @example
|
|
38
35
|
* ```typescript
|
|
39
|
-
* import PouchDB from 'pouchdb';
|
|
40
36
|
* import { PouchAdapter } from '@decaf-ts/for-pouch';
|
|
41
37
|
*
|
|
42
|
-
* // Create a
|
|
43
|
-
* const
|
|
38
|
+
* // Create a PouchAdapter with config
|
|
39
|
+
* const adapter = new PouchAdapter({
|
|
40
|
+
* protocol: 'http',
|
|
41
|
+
* host: 'localhost:5984',
|
|
42
|
+
* user: 'admin',
|
|
43
|
+
* password: 'secret',
|
|
44
|
+
* dbName: 'my-database',
|
|
45
|
+
* plugins: []
|
|
46
|
+
* });
|
|
44
47
|
*
|
|
45
|
-
* //
|
|
46
|
-
* const
|
|
48
|
+
* // Or use local storage
|
|
49
|
+
* const localAdapter = new PouchAdapter({
|
|
50
|
+
* protocol: 'http', // ignored for local
|
|
51
|
+
* dbName: 'local-db',
|
|
52
|
+
* storagePath: 'local_dbs',
|
|
53
|
+
* plugins: []
|
|
54
|
+
* });
|
|
47
55
|
*
|
|
48
56
|
* // Use the adapter for database operations
|
|
49
57
|
* const result = await adapter.read('users', 'user-123');
|
|
@@ -55,8 +63,8 @@ export declare function createdByOnPouchCreateUpdate<M extends Model, R extends
|
|
|
55
63
|
* participant PouchDB
|
|
56
64
|
* participant CouchDB
|
|
57
65
|
*
|
|
58
|
-
* Client->>PouchAdapter: new PouchAdapter(
|
|
59
|
-
* PouchAdapter->>CouchDBAdapter: super(
|
|
66
|
+
* Client->>PouchAdapter: new PouchAdapter(config, alias?)
|
|
67
|
+
* PouchAdapter->>CouchDBAdapter: super(config, PouchFlavour, alias)
|
|
60
68
|
*
|
|
61
69
|
* Client->>PouchAdapter: create(table, id, model)
|
|
62
70
|
* PouchAdapter->>PouchDB: put(model)
|
|
@@ -72,8 +80,33 @@ export declare function createdByOnPouchCreateUpdate<M extends Model, R extends
|
|
|
72
80
|
* PouchDB-->>PouchAdapter: Document
|
|
73
81
|
* PouchAdapter-->>Client: Model
|
|
74
82
|
*/
|
|
75
|
-
export declare class PouchAdapter extends CouchDBAdapter<Database, PouchFlags, Context<PouchFlags>> {
|
|
76
|
-
constructor(
|
|
83
|
+
export declare class PouchAdapter extends CouchDBAdapter<PouchConfig, Database, PouchFlags, Context<PouchFlags>> {
|
|
84
|
+
constructor(config: PouchConfig, alias?: string);
|
|
85
|
+
/**
|
|
86
|
+
* @description Lazily initializes and returns the underlying PouchDB client
|
|
87
|
+
* @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.
|
|
88
|
+
* @return {Database} A PouchDB Database instance ready to perform operations
|
|
89
|
+
* @mermaid
|
|
90
|
+
* sequenceDiagram
|
|
91
|
+
* participant Caller
|
|
92
|
+
* participant PouchAdapter
|
|
93
|
+
* participant PouchDB
|
|
94
|
+
* Caller->>PouchAdapter: getClient()
|
|
95
|
+
* alt client not initialized
|
|
96
|
+
* PouchAdapter->>PouchAdapter: register plugins
|
|
97
|
+
* PouchAdapter->>PouchDB: new PouchDB(url or path)
|
|
98
|
+
* alt creation fails
|
|
99
|
+
* PouchDB-->>PouchAdapter: Error
|
|
100
|
+
* PouchAdapter-->>Caller: throws InternalError
|
|
101
|
+
* else success
|
|
102
|
+
* PouchDB-->>PouchAdapter: Database
|
|
103
|
+
* PouchAdapter-->>Caller: cached client
|
|
104
|
+
* end
|
|
105
|
+
* else client initialized
|
|
106
|
+
* PouchAdapter-->>Caller: cached client
|
|
107
|
+
* end
|
|
108
|
+
*/
|
|
109
|
+
getClient(): Database;
|
|
77
110
|
/**
|
|
78
111
|
* @description Generates operation flags for PouchDB operations
|
|
79
112
|
* @summary Creates a set of flags for a specific operation, including a UUID for identification.
|